APMParameterMetaData.h 3.43 KB
Newer Older
Don Gagne's avatar
Don Gagne committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*=====================================================================
 
 QGroundControl Open Source Ground Control Station
 
 (c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 
 This file is part of the QGROUNDCONTROL project
 
 QGROUNDCONTROL is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
 
 QGROUNDCONTROL is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
 
 ======================================================================*/

24 25
#ifndef APMParameterMetaData_H
#define APMParameterMetaData_H
Don Gagne's avatar
Don Gagne committed
26 27 28

#include <QObject>
#include <QMap>
29
#include <QPointer>
Don Gagne's avatar
Don Gagne committed
30 31 32
#include <QXmlStreamReader>
#include <QLoggingCategory>

33
#include "FactSystem.h"
34
#include "AutoPilotPlugin.h"
35
#include "Vehicle.h"
Don Gagne's avatar
Don Gagne committed
36

37 38 39
class APMFactMetaDataRaw
{
public:
40 41 42 43 44 45 46 47 48 49 50 51 52
    APMFactMetaDataRaw(void)
        : rebootRequired(false)
    { }

    QString name;
    QString group;
    QString shortDescription;
    QString longDescription;
    QString min;
    QString max;
    QString incrementSize;
    QString units;
    bool    rebootRequired;
53
    QList<QPair<QString, QString> > values;
54
    QList<QPair<QString, QString> > bitmask;
55 56
};

Don Gagne's avatar
Don Gagne committed
57 58 59
/// @file
///     @author Don Gagne <don@thegagnes.com>

60
Q_DECLARE_LOGGING_CATEGORY(APMParameterMetaDataLog)
61
Q_DECLARE_LOGGING_CATEGORY(APMParameterMetaDataVerboseLog)
Don Gagne's avatar
Don Gagne committed
62 63 64

/// Collection of Parameter Facts for PX4 AutoPilot

65 66
typedef QMap<QString, APMFactMetaDataRaw*> ParameterNametoFactMetaDataMap;

67
class APMParameterMetaData : public QObject
Don Gagne's avatar
Don Gagne committed
68 69 70 71 72
{
    Q_OBJECT
    
public:
    /// @param uas Uas which this set of facts is associated with
73
    APMParameterMetaData(QObject* parent = NULL);
74 75

    /// Override from ParameterLoader
76
    virtual QString getDefaultComponentIdParam(void) const { return QString("SYSID_SW_TYPE"); }    
77
    
78
    // Overrides from ParameterLoader
79 80
    static void addMetaDataToFact(Fact* fact, MAV_TYPE vehicleType);
    static void addMetaDataToFacts(QVariantMap &facts, MAV_TYPE vehicleType);
81

Don Gagne's avatar
Don Gagne committed
82
private:
83 84
    enum {
        XmlStateNone,
85 86 87
        XmlstateParamFileFound,
        XmlStateFoundVehicles,
        XmlStateFoundLibraries,
88 89 90 91 92 93 94
        XmlStateFoundParameters,
        XmlStateFoundVersion,
        XmlStateFoundGroup,
        XmlStateFoundParameter,
        XmlStateDone
    };
    
Don Gagne's avatar
Don Gagne committed
95

96
    static void _loadParameterFactMetaData();
97
    static QVariant _stringToTypedVariant(const QString& string, FactMetaData::ValueType_t type, bool* convertOk);
98 99 100 101
    static bool skipXMLBlock(QXmlStreamReader& xml, const QString& blockName);
    static bool parseParameterAttributes(QXmlStreamReader& xml, APMFactMetaDataRaw *rawMetaData);
    static void correctGroupMemberships(ParameterNametoFactMetaDataMap& parameterToFactMetaDataMap, QMap<QString,QStringList>& groupMembers);
    static QString mavTypeToString(MAV_TYPE vehicleTypeEnum);
Don Gagne's avatar
Don Gagne committed
102

103
    static bool _parameterMetaDataLoaded;   ///< true: parameter meta data already loaded
104
    static QMap<QString, ParameterNametoFactMetaDataMap> _vehicleTypeToParametersMap; ///< Maps from a vehicle type to paramametertoFactMeta map>
Don Gagne's avatar
Don Gagne committed
105 106
};

107
#endif