APMParameterMetaData.h 3.46 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 40 41 42 43 44 45 46 47 48
class APMFactMetaDataRaw
{
public:
    QString                  name;
    QString                  group;
    QString                  shortDescription;
    QString                  longDescription;
    QString                  min;
    QString                  max;
    QString                  incrementSize;
    QString                  units;
    QList<QPair<QString, QString> > values;
49
    QList<QPair<QString, QString> > bitmask;
50 51
};

Don Gagne's avatar
Don Gagne committed
52 53 54
/// @file
///     @author Don Gagne <don@thegagnes.com>

55
Q_DECLARE_LOGGING_CATEGORY(APMParameterMetaDataLog)
56
Q_DECLARE_LOGGING_CATEGORY(APMParameterMetaDataVerboseLog)
Don Gagne's avatar
Don Gagne committed
57 58 59

/// Collection of Parameter Facts for PX4 AutoPilot

60 61
typedef QMap<QString, APMFactMetaDataRaw*> ParameterNametoFactMetaDataMap;

62
class APMParameterMetaData : public QObject
Don Gagne's avatar
Don Gagne committed
63 64 65 66 67
{
    Q_OBJECT
    
public:
    /// @param uas Uas which this set of facts is associated with
68
    APMParameterMetaData(QObject* parent = NULL);
69 70

    /// Override from ParameterLoader
71
    virtual QString getDefaultComponentIdParam(void) const { return QString("SYSID_SW_TYPE"); }    
72
    
73
    // Overrides from ParameterLoader
74 75
    static void addMetaDataToFact(Fact* fact, MAV_TYPE vehicleType);
    static void addMetaDataToFacts(QVariantMap &facts, MAV_TYPE vehicleType);
76

Don Gagne's avatar
Don Gagne committed
77
private:
78 79
    enum {
        XmlStateNone,
80 81 82
        XmlstateParamFileFound,
        XmlStateFoundVehicles,
        XmlStateFoundLibraries,
83 84 85 86 87 88 89
        XmlStateFoundParameters,
        XmlStateFoundVersion,
        XmlStateFoundGroup,
        XmlStateFoundParameter,
        XmlStateDone
    };
    
Don Gagne's avatar
Don Gagne committed
90

91
    static void _loadParameterFactMetaData();
92
    static QVariant _stringToTypedVariant(const QString& string, FactMetaData::ValueType_t type, bool* convertOk);
93 94 95 96
    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
97

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

102
#endif