APMParameterMetaData.h 2.56 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
    APMFactMetaDataRaw(void)
        : rebootRequired(false)
    { }

    QString name;
35
    QString category;
36 37 38 39 40 41 42 43
    QString group;
    QString shortDescription;
    QString longDescription;
    QString min;
    QString max;
    QString incrementSize;
    QString units;
    bool    rebootRequired;
44
    QList<QPair<QString, QString> > values;
45
    QList<QPair<QString, QString> > bitmask;
46 47
};

Don Gagne's avatar
Don Gagne committed
48 49 50

/// Collection of Parameter Facts for PX4 AutoPilot

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

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

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

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

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

78 79 80 81 82
    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
83

84 85
    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
86 87
};

88
#endif