UASParameterDataModel.h 4.3 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);
    

tstellanova's avatar
tstellanova committed
17
    int getTotalOnboardParams() { return totalOnboardParameters; }
18 19 20 21 22 23 24 25 26 27 28 29 30 31
    //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);

tstellanova's avatar
tstellanova committed
32 33 34 35 36
    //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);
37

38
    /** @brief Write a new pending parameter value that may be eventually sent to the UAS */
39 40 41 42 43 44 45 46 47 48 49 50 51
    virtual void setPendingParameter(int componentId,  QString& key,  const QVariant& value);
    virtual void setOnboardParameter(int componentId, QString& key, const QVariant& value);

    /** @brief Save the onboard parameter with a the type specified in the QVariant as fixed */
    virtual void setOnboardParameterWithType(int componentId, QString& key, QVariant& value);

    /** @brief clears every parameter for every loaded component */
    virtual void forgetAllOnboardParameters();

    /**
     * @return true if the parameter has changed
    */
    virtual bool checkParameterChanged(int componentId, const QString& key,  const QVariant &value);
52 53


54 55 56 57
    /** @brief add this parameter to pending list iff it has changed from onboard value
     * @return true if the parameter has changed
    */
    virtual bool addPendingIfParameterChanged(int componentId, QString& key,  QVariant& value);
58

59 60 61 62

    virtual void handleParameterUpdate(int componentId, QString& key, QVariant& value);

    virtual bool getOnboardParameterValue(int componentId, const QString& key, QVariant& value) const;
63

64 65 66 67 68 69 70
    QMap<QString , QVariant>* getPendingParametersForComponent(int componentId) {
        return pendingParameters.value(componentId);
    }

    QMap<QString , QVariant>* getOnbardParametersForComponent(int componentId) {
        return onboardParameters.value(componentId);
    }
71 72 73 74 75 76 77 78 79 80

    QMap<int, QMap<QString, QVariant>* >  getPendingParameters() {
       return pendingParameters;
   }

    QMap<int, QMap<QString, QVariant>* > getOnboardParameters() {
       return onboardParameters;
   }


81 82 83 84
    virtual void writeOnboardParametersToStream(QTextStream &stream, const QString& uasName);
    virtual void readUpdateParametersFromStream(QTextStream &stream);

    virtual void loadParamMetaInfoFromStream(QTextStream& stream);
85

86 87 88 89
    void setUASID(int anId) {  this->uasId = anId; }

signals:
    
tstellanova's avatar
tstellanova committed
90 91
    void parameterUpdated(int compId, int paramId, QString paramName, QVariant value);

92 93 94 95 96 97 98
public slots:


protected:
    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
tstellanova's avatar
tstellanova committed
99
    int totalOnboardParameters;///< The known count of onboard parameters, may not match onboardParameters until all params are received
100

101 102 103 104 105 106 107 108
    // 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

109 110 111 112
    
};

#endif // UASPARAMETERDATAMODEL_H