UASParameterCommsMgr.h 4.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
#ifndef UASPARAMETERCOMMSMGR_H
#define UASPARAMETERCOMMSMGR_H

#include <QObject>
#include <QMap>
#include <QTimer>
#include <QVariant>
#include <QVector>

class UASInterface;
class UASParameterDataModel;

tstellanova's avatar
tstellanova committed
13 14


15 16 17
class UASParameterCommsMgr : public QObject
{
    Q_OBJECT
tstellanova's avatar
tstellanova committed
18 19


20
public:
21 22 23
    explicit UASParameterCommsMgr(QObject *parent = 0);
    UASParameterCommsMgr* initWithUAS(UASInterface* model);///< Two-stage constructor

24 25
    ~UASParameterCommsMgr();

tstellanova's avatar
tstellanova committed
26 27 28 29 30 31 32
    typedef enum ParamCommsStatusLevel {
        ParamCommsStatusLevel_OK = 0,
        ParamCommsStatusLevel_Warning = 2,
        ParamCommsStatusLevel_Error = 4,
        ParamCommsStatusLevel_Count
    } ParamCommsStatusLevel_t;

33 34 35 36 37

protected:
    /** @brief Activate / deactivate parameter retransmission */
    virtual void setRetransmissionGuardEnabled(bool enabled);

tstellanova's avatar
tstellanova committed
38 39 40 41
    virtual void setParameterStatusMsg(const QString& msg, ParamCommsStatusLevel_t level=ParamCommsStatusLevel_OK);

    /** @brief Load settings that control eg retransmission timeouts */
    void loadParamCommsSettings();
42

43
    /** @brief clear transmissionMissingPackets and transmissionMissingWriteAckPackets */
tstellanova's avatar
tstellanova committed
44
    void clearRetransmissionLists(int& missingReadCount, int& missingWriteCount );
45 46

    void resendReadWriteRequests();
47
    void resetAfterListReceive();
48

49
    void emitPendingParameterCommit(int compId, const QString& key, QVariant& value);
50

51
signals:
52
    void commitPendingParameter(int component, QString parameter, QVariant value);
53
    void parameterChanged(int component, int parameterIndex, QVariant value);
tstellanova's avatar
tstellanova committed
54
    void parameterValueConfirmed(int uas, int component,int paramCount, int paramId, QString parameter, QVariant value);
55

tstellanova's avatar
tstellanova committed
56 57 58
    /** @brief We have received a complete list of all parameters onboard the MAV */
    void parameterListUpToDate();

59 60 61
    void parameterUpdateRequested(int component, const QString& parameter);
    void parameterUpdateRequestedById(int componentId, int paramId);

tstellanova's avatar
tstellanova committed
62
    /** @brief We updated the parameter status message */
63
    void parameterStatusMsgUpdated(QString msg, int level);
64 65

public slots:
tstellanova's avatar
tstellanova committed
66
    /** @brief  Iterate through all components, through all pending parameters and send them to UAS */
67
    virtual void sendPendingParameters(bool copyToPersistent = false);
tstellanova's avatar
tstellanova committed
68 69 70 71

    /** @brief  Write the current onboard parameters from transient RAM into persistent storage, e.g. EEPROM or harddisk */
    virtual void writeParamsToPersistentStorage();

72 73
    /** @brief Write one parameter to the MAV */
    virtual void setParameter(int component, QString parameterName, QVariant value);
tstellanova's avatar
tstellanova committed
74

75 76
    /** @brief Request list of parameters from MAV */
    virtual void requestParameterList();
77

78 79 80 81 82 83
    /** @brief Check for missing parameters */
    virtual void retransmissionGuardTick();

    /** @brief Request a single parameter update by name */
    virtual void requestParameterUpdate(int component, const QString& parameter);

84 85 86
    /** @brief Request an update of RC parameters */
    virtual void requestRcCalibrationParamsUpdate();

tstellanova's avatar
tstellanova committed
87 88
    virtual void receivedParameterUpdate(int uas, int compId, int paramCount, int paramId, QString paramName, QVariant value);

89 90 91 92 93 94 95 96
protected:

    UASInterface* mav;   ///< The MAV we're talking to

    UASParameterDataModel* paramDataModel;

    // Communications management
    QVector<bool> receivedParamsList; ///< Successfully received parameters
97
    QMap<int, QList<int>* > missingReadPackets; ///< Missing packets
98
    QMap<int, QMap<QString, QVariant>* > missingWriteAckPackets; ///< Missing write ACK packets
99 100 101
    bool transmissionListMode;       ///< Currently requesting list
    QMap<int, bool> transmissionListSizeKnown;  ///< List size initialized?
    bool transmissionActive;         ///< Missing packets, working on list?
102
    bool persistParamsAfterSend; ///< Copy all parameters to persistent storage after sending
103 104
    quint64 transmissionTimeout;     ///< Timeout
    QTimer retransmissionTimer;      ///< Timer handling parameter retransmission
105
    quint64 lastTimerReset;     ///< Last time the guard timer was reset, to prevent premature firing
106 107 108
    int retransmissionTimeout; ///< Retransmission request timeout, in milliseconds
    int rewriteTimeout; ///< Write request timeout, in milliseconds
    int retransmissionBurstRequestSize; ///< Number of packets requested for retransmission per burst
109
    quint64 listRecvTimeout;     ///< How long to wait for first parameter list response before re-requesting
110 111 112 113 114 115 116 117

    // Status
    QString parameterStatusMsg;

};
    

#endif // UASPARAMETERCOMMSMGR_H