UASParameterDataModel.h 5.31 KB
Newer Older
1 2 3 4 5 6 7
#ifndef UASPARAMETERDATAMODEL_H
#define UASPARAMETERDATAMODEL_H

#include <QMap>
#include <QObject>
#include <QVariant>

8 9
class QTextStream;

10 11 12 13 14 15 16
class UASParameterDataModel : public QObject
{
    Q_OBJECT
public:
    explicit UASParameterDataModel(QObject *parent = 0);
    

17 18 19 20 21 22 23 24 25 26 27 28 29 30
    //Parameter meta info
    bool isParamMinKnown(const QString& param) { return paramMin.contains(param); }
    virtual bool isValueLessThanParamMin(const QString& param, double dblVal);

    bool isParamMaxKnown(const QString& param) { return paramMax.contains(param); }
    virtual bool isValueGreaterThanParamMax(const QString& param, double dblVal);

    bool isParamDefaultKnown(const QString& param) { return paramDefault.contains(param); }
    double getParamMin(const QString& param) { return paramMin.value(param, 0.0f); }
    double getParamMax(const QString& param) { return paramMax.value(param, 0.0f); }
    double getParamDefault(const QString& param) { return paramDefault.value(param, 0.0f); }
    virtual QString getParamDescription(const QString& param) { return paramDescriptions.value(param, ""); }
    virtual void setParamDescriptions(const QMap<QString,QString>& paramInfo);

31 32 33
    /** @brief Get the default component ID for the UAS */
    virtual int getDefaultComponentId();

tstellanova's avatar
tstellanova committed
34 35 36 37 38
    //TODO make this method protected?
     /** @brief Ensure that the data model is aware of this component
      * @param compId Id of the component
      */
    virtual void addComponent(int compId);
39

40 41 42 43 44 45
    /**
     * @brief Return a list of all components for this parameter name
     * @param parameter The parameter string to search for
     * @return A list with all components, can be potentially empty
     */
    virtual QList<int> getComponentForOnboardParam(const QString& parameter) const;
46 47 48


    /** @brief clears every parameter for every loaded component */
49
    virtual void forgetAllOnboardParams();
50 51


52

53
    /** @brief add this parameter to pending list iff it has changed from onboard value
54
     * @return true if the parameter is now pending
55
    */
56 57
    virtual bool updatePendingParamWithValue(int componentId, const QString &key,  const QVariant &value);
    virtual void handleParamUpdate(int componentId, const QString& key, const QVariant& value);
58
    virtual bool getOnboardParamValue(int componentId, const QString& key, QVariant& value) const;
59

60 61
    virtual bool isParamChangePending(int componentId,const QString& key);

62
    QMap<QString , QVariant>* getPendingParamsForComponent(int componentId) {
63 64 65
        return pendingParameters.value(componentId);
    }

66
    QMap<QString , QVariant>* getOnboardParamsForComponent(int componentId) {
67 68
        return onboardParameters.value(componentId);
    }
69

70
    QMap<int, QMap<QString, QVariant>* >*  getAllPendingParams() {
71
       return &pendingParameters;
72 73
   }

74
    QMap<int, QMap<QString, QVariant>* >* getAllOnboardParams() {
75
       return &onboardParameters;
76 77
   }

78
    /** @brief return a count of all pending parameters */
79
    virtual int countPendingParams();
80

81 82
    /** @brief return a count of all onboard parameters we've received */
    virtual int countOnboardParams();
83

84 85
    virtual void writeOnboardParamsToStream(QTextStream &stream, const QString& uasName);
    virtual void readUpdateParamsFromStream(QTextStream &stream);
86 87

    virtual void loadParamMetaInfoFromStream(QTextStream& stream);
88

89 90
    void setUASID(int anId) {  this->uasId = anId; }

91
protected:
92
    /** @brief set the confirmed value of a parameter in the onboard params list */
93
    virtual void setOnboardParam(int componentId, const QString& key, const QVariant& value);
94

95 96 97
    /** @brief Save the parameter with a the type specified in the QVariant as fixed */
    void setParamWithTypeInMap(int compId, const QString& key, const QVariant &value, QMap<int, QMap<QString, QVariant>* >& map);

98
    /** @brief Write a new pending parameter value that may be eventually sent to the UAS */
99
    virtual void setPendingParam(int componentId,  const QString &key,  const QVariant& value);
100
    /** @brief remove a parameter from the pending list */
101
    virtual void removePendingParam(int compId, const QString &key);
102

103

104 105
signals:
    
tstellanova's avatar
tstellanova committed
106 107
    /** @brief We've received an update of a parameter's value */
    void parameterUpdated(int compId, QString paramName, QVariant value);
tstellanova's avatar
tstellanova committed
108

109 110 111
    /** @brief Notifies listeners that a param was added to or removed from the pending list */
    void pendingParamUpdate(int compId, const QString& paramName, QVariant value, bool isPending);

112 113
    void allPendingParamsCommitted(); ///< All pending params have been committed to the MAV

114 115
public slots:

116
    virtual void clearAllPendingParams();
117 118

protected:
119 120
    int             defaultComponentId; ///< Cached default component ID

121 122 123 124
    int     uasId; ///< The UAS / MAV to which this data model pertains
    QMap<int, QMap<QString, QVariant>* > pendingParameters; ///< Changed values that have not yet been transmitted to the UAS, by component ID
    QMap<int, QMap<QString, QVariant>* > onboardParameters; ///< All parameters confirmed to be stored onboard the UAS, by component ID

125 126 127 128 129 130 131 132
    // Tooltip data structures
    QMap<QString, QString> paramDescriptions; ///< Tooltip values

    // Min / Default / Max data structures
    QMap<QString, double> paramMin; ///< Minimum param values
    QMap<QString, double> paramDefault; ///< Default param values
    QMap<QString, double> paramMax; ///< Minimum param values

133 134 135 136
    
};

#endif // UASPARAMETERDATAMODEL_H