APMParameterMetaData.h 3.36 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 49 50
class APMFactMetaDataRaw
{
public:
    QString                  name;
    QString                  group;
    QString                  shortDescription;
    QString                  longDescription;
    QString                  min;
    QString                  max;
    QString                  incrementSize;
    QString                  units;
    QList<QPair<QString, QString> > values;
};

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

54
Q_DECLARE_LOGGING_CATEGORY(APMParameterMetaDataLog)
Don Gagne's avatar
Don Gagne committed
55 56 57

/// Collection of Parameter Facts for PX4 AutoPilot

58 59
typedef QMap<QString, APMFactMetaDataRaw*> ParameterNametoFactMetaDataMap;

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

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

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

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

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

100
#endif