QGCUASParamManager.h 4.85 KB
Newer Older
1 2 3 4 5 6
#ifndef QGCUASPARAMMANAGER_H
#define QGCUASPARAMMANAGER_H

#include <QWidget>
#include <QMap>
#include <QTimer>
7
#include <QVariant>
8

9
#include "UASParameterDataModel.h"
10
#include "QGCUASParamManagerInterface.h"
11
#include "UASParameterCommsMgr.h"
12

tstellanova's avatar
tstellanova committed
13
//forward declarations
14
class QTextStream;
15 16
class UASInterface;

17
class QGCUASParamManager : public QGCUASParamManagerInterface
18 19 20
{
    Q_OBJECT
public:
21 22
    QGCUASParamManager(QObject* parent = 0);
    QGCUASParamManager* initWithUAS(UASInterface* uas);
23

tstellanova's avatar
tstellanova committed
24
    /** @brief Get the known, confirmed value of a parameter */
tstellanova's avatar
tstellanova committed
25
    virtual bool getParameterValue(int component, const QString& parameter, QVariant& value) const;
26

27 28 29
    /** @brief determine which component is the root component for the UAS and return its ID or 0 if unknown */
    virtual int getDefaultComponentId();

30 31 32 33 34 35 36
    /**
     * @brief Get a list of all component IDs using this parameter name
     * @param parameter The string encoding the parameter name
     * @return A list with all components using this parameter name. Can be empty.
     */
    virtual QList<int> getComponentForParam(const QString& parameter) const;

37 38 39
    /** @brief Provide tooltips / user-visible descriptions for parameters */
    virtual void setParamDescriptions(const QMap<QString,QString>& paramDescs);

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
    /**
     * @brief Count the pending parameters in the current transmission
     * @return The number of pending parameters
     */
    virtual int countPendingParams() {
        return paramDataModel.countPendingParams();
    }

    /**
     * @brief Count the number of onboard parameters
     * @return The number of onboard parameters
     */
    virtual int countOnboardParams() {
        return paramDataModel.countOnboardParams();
    }

tstellanova's avatar
tstellanova committed
56 57 58 59
    /** @brief Get the UAS of this widget
     * @return The MAV of this mgr. Unless the MAV object has been destroyed, this is never null.
     */
    UASInterface* getUAS();
tstellanova's avatar
tstellanova committed
60

61 62
    /** @return The data model managed by this class */
    virtual UASParameterDataModel* dataModel();
63 64 65
    
    /// @return true: first full set of parameters received
    virtual bool parametersReady(void) { return _parametersReady; }
66

tstellanova's avatar
tstellanova committed
67
protected:
68

tstellanova's avatar
tstellanova committed
69 70
    /** @brief Load parameter meta information from appropriate CSV file */
    virtual void loadParamMetaInfoCSV();
tstellanova's avatar
tstellanova committed
71

72
    void connectToModelAndComms();
73

tstellanova's avatar
tstellanova committed
74

75
signals:
76 77 78 79 80

    /** @brief We updated the parameter status message */
    void parameterStatusMsgUpdated(QString msg, int level);
    /** @brief We have received a complete list of all parameters onboard the MAV */
    void parameterListUpToDate();
81

82 83 84 85 86 87
    /** @brief We've received an update of a parameter's value */
    void parameterUpdated(int compId, QString paramName, QVariant value);

    /** @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);

88 89


90
public slots:
tstellanova's avatar
tstellanova committed
91 92 93
    /** @brief Send one parameter to the MAV: changes value in transient memory of MAV */
    virtual void setParameter(int component, QString parameterName, QVariant value);

94 95 96
    /** @brief Send all pending parameters to the MAV, for storage in transient (RAM) memory
     * @param persistAfterSend  If true, all parameters will be written to persistent storage as well
    */
97
    virtual void sendPendingParameters(bool persistAfterSend = false, bool forceSend = false);
98

tstellanova's avatar
tstellanova committed
99

100
    /** @brief Request list of parameters from MAV */
tstellanova's avatar
tstellanova committed
101
    virtual void requestParameterList();
102

103 104 105
    /** @brief Request a list of params onboard the MAV if the onboard param list we have is empty */
    virtual void requestParameterListIfEmpty();

106
    /** @brief queue a pending parameter for sending to the MAV */
107
    virtual void setPendingParam(int componentId,  const QString& key,  const QVariant& value, bool forceSend = false);
108

109 110 111
    /** @brief remove all params from the pending list */
    virtual void clearAllPendingParams();

tstellanova's avatar
tstellanova committed
112
    /** @brief Request a single parameter by name from the MAV */
113 114
    virtual void requestParameterUpdate(int component, const QString& parameter);

tstellanova's avatar
tstellanova committed
115

116 117 118 119 120 121 122 123 124
    virtual void writeOnboardParamsToStream(QTextStream &stream, const QString& uasName);
    virtual void readPendingParamsFromStream(QTextStream &stream);

    virtual void requestRcCalibrationParamsUpdate();

    /** @brief Copy the current parameters in volatile RAM to persistent storage (EEPROM/HDD) */
    virtual void copyVolatileParamsToPersistent();
    /** @brief Copy the parameters from persistent storage to volatile RAM  */
    virtual void copyPersistentParamsToVolatile();
125 126 127
    
private slots:
    void _parameterListUpToDate(void);
tstellanova's avatar
tstellanova committed
128

129
protected:
130

tstellanova's avatar
tstellanova committed
131
    // Parameter data model
tstellanova's avatar
tstellanova committed
132
    UASInterface*           mav;   ///< The MAV this manager is controlling
133
    UASParameterDataModel  paramDataModel;///< Shared data model of parameters
134
    UASParameterCommsMgr   paramCommsMgr; ///< Shared comms mgr for parameters
135 136
    
    bool _parametersReady;
137

138 139 140
};

#endif // QGCUASPARAMMANAGER_H