APMParameterMetaData.h 2.54 KB
Newer Older
1 2 3 4 5 6 7 8 9
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

Don Gagne's avatar
Don Gagne committed
10

11 12
#ifndef APMParameterMetaData_H
#define APMParameterMetaData_H
Don Gagne's avatar
Don Gagne committed
13 14 15

#include <QObject>
#include <QMap>
16
#include <QPointer>
Don Gagne's avatar
Don Gagne committed
17 18 19
#include <QXmlStreamReader>
#include <QLoggingCategory>

20
#include "FactSystem.h"
21
#include "AutoPilotPlugin.h"
22
#include "Vehicle.h"
Don Gagne's avatar
Don Gagne committed
23

24 25 26
Q_DECLARE_LOGGING_CATEGORY(APMParameterMetaDataLog)
Q_DECLARE_LOGGING_CATEGORY(APMParameterMetaDataVerboseLog)

27 28 29
class APMFactMetaDataRaw
{
public:
30 31 32 33 34 35 36 37 38 39 40 41 42
    APMFactMetaDataRaw(void)
        : rebootRequired(false)
    { }

    QString name;
    QString group;
    QString shortDescription;
    QString longDescription;
    QString min;
    QString max;
    QString incrementSize;
    QString units;
    bool    rebootRequired;
43
    QList<QPair<QString, QString> > values;
44
    QList<QPair<QString, QString> > bitmask;
45 46
};

Don Gagne's avatar
Don Gagne committed
47 48 49

/// Collection of Parameter Facts for PX4 AutoPilot

50 51
typedef QMap<QString, APMFactMetaDataRaw*> ParameterNametoFactMetaDataMap;

52
class APMParameterMetaData : public QObject
Don Gagne's avatar
Don Gagne committed
53 54 55 56
{
    Q_OBJECT
    
public:
57
    APMParameterMetaData(void);
58

59
    void addMetaDataToFact(Fact* fact, MAV_TYPE vehicleType);
Don Gagne's avatar
Don Gagne committed
60
    void loadParameterFactMetaDataFile(const QString& metaDataFile);
61 62

    static void getParameterMetaDataVersionInfo(const QString& metaDataFile, int& majorVersion, int& minorVersion);
63

Don Gagne's avatar
Don Gagne committed
64
private:
65 66
    enum {
        XmlStateNone,
67 68 69
        XmlstateParamFileFound,
        XmlStateFoundVehicles,
        XmlStateFoundLibraries,
70 71 72 73 74
        XmlStateFoundParameters,
        XmlStateFoundVersion,
        XmlStateFoundGroup,
        XmlStateFoundParameter,
        XmlStateDone
75
    };    
Don Gagne's avatar
Don Gagne committed
76

77 78 79 80 81
    QVariant _stringToTypedVariant(const QString& string, FactMetaData::ValueType_t type, bool* convertOk);
    bool skipXMLBlock(QXmlStreamReader& xml, const QString& blockName);
    bool parseParameterAttributes(QXmlStreamReader& xml, APMFactMetaDataRaw *rawMetaData);
    void correctGroupMemberships(ParameterNametoFactMetaDataMap& parameterToFactMetaDataMap, QMap<QString,QStringList>& groupMembers);
    QString mavTypeToString(MAV_TYPE vehicleTypeEnum);
Don Gagne's avatar
Don Gagne committed
82

83 84
    bool _parameterMetaDataLoaded;   ///< true: parameter meta data already loaded
    QMap<QString, ParameterNametoFactMetaDataMap> _vehicleTypeToParametersMap; ///< Maps from a vehicle type to paramametertoFactMeta map>
Don Gagne's avatar
Don Gagne committed
85 86
};

87
#endif