APMParameterMetaData.h 2.68 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9
 *
 * 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
class APMFactMetaDataRaw : public QObject
28
{
29
    Q_OBJECT
30
public:
31 32
    APMFactMetaDataRaw(QObject *parent = nullptr)
        : QObject(parent), rebootRequired(false)
33 34 35
    { }

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

Don Gagne's avatar
Don Gagne committed
49 50 51

/// Collection of Parameter Facts for PX4 AutoPilot

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

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

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

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

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

79 80 81 82 83
    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);
84
    QString _groupFromParameterName(const QString& name);
Don Gagne's avatar
Don Gagne committed
85

86 87
    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
88 89
};

90
#endif