UASParameterCommsMgr.h 4.23 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 21
public:
    explicit UASParameterCommsMgr(QObject *parent = 0, UASInterface* uas = NULL);
22 23
    ~UASParameterCommsMgr();

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

31 32 33 34 35

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

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

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

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

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

    void emitParameterChanged(int compId, const QString& key, QVariant& value);

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

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

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

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

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

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

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

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

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

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

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

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

87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
protected:

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

    UASParameterDataModel* paramDataModel;

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

    // Status
    QString parameterStatusMsg;

};
    

#endif // UASPARAMETERCOMMSMGR_H