UASParameterCommsMgr.h 4.98 KB
Newer Older
1 2 3 4 5 6 7 8
#ifndef UASPARAMETERCOMMSMGR_H
#define UASPARAMETERCOMMSMGR_H

#include <QObject>
#include <QMap>
#include <QTimer>
#include <QVariant>
#include <QVector>
9
#include <QLoggingCategory>
10 11 12 13

class UASInterface;
class UASParameterDataModel;

14
Q_DECLARE_LOGGING_CATEGORY(UASParameterCommsMgrLog)
tstellanova's avatar
tstellanova committed
15

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


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

25 26
    ~UASParameterCommsMgr();

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

34 35

protected:
36 37 38

    /** @brief activate the silence timer if there are unack'd reads or writes */
    virtual void updateSilenceTimer();
39

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

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

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

48 49 50 51 52 53
    /** @brief we are waiting for a response to this read param request */
    virtual void markReadParamWaiting(int compId, int paramId);

    /** @brief we are waiting for a response to this write param request */
    void markWriteParamWaiting(int compId, QString paramName, QVariant value);

54
    void resendReadWriteRequests();
55
    void resetAfterListReceive();
56

57
    void emitPendingParameterCommit(int compId, const QString& key, QVariant& value);
58

59
signals:
60
    void commitPendingParameter(int component, QString parameter, QVariant value);
61
    void parameterChanged(int component, int parameterIndex, QVariant value);
tstellanova's avatar
tstellanova committed
62
    void parameterValueConfirmed(int uas, int component,int paramCount, int paramId, QString parameter, QVariant value);
63

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

67 68 69
    void parameterUpdateRequested(int component, const QString& parameter);
    void parameterUpdateRequestedById(int componentId, int paramId);

tstellanova's avatar
tstellanova committed
70
    /** @brief We updated the parameter status message */
71
    void parameterStatusMsgUpdated(QString msg, int level);
72 73 74 75 76
    
    
    /// @brief We signal this to ourselves in order to get timer started/stopped on our own thread.
    void _startSilenceTimer(void);
    void _stopSilenceTimer(void);
77 78

public slots:
tstellanova's avatar
tstellanova committed
79
    /** @brief  Iterate through all components, through all pending parameters and send them to UAS */
80
    virtual void sendPendingParameters(bool copyToPersistent = false, bool forceSend = false);
tstellanova's avatar
tstellanova committed
81 82 83 84

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

85
    /** @brief Write one parameter to the MAV */
86
    virtual void setParameter(int component, QString parameterName, QVariant value, bool forceSend = false);
tstellanova's avatar
tstellanova committed
87

88 89
    /** @brief Request list of parameters from MAV */
    virtual void requestParameterList();
90

91 92
    /** @brief The max silence time expired */
    virtual void silenceTimerExpired();
93 94 95 96

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

97 98 99
    /** @brief Request an update of RC parameters */
    virtual void requestRcCalibrationParamsUpdate();

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

102 103
protected:

104 105 106 107

    QMap<int, int> knownParamListSize;///< The known param list size for each component, by component ID
    quint64 lastReceiveTime; ///< The last time we received anything from our partner
    quint64 lastSilenceTimerReset;
108 109
    UASInterface* mav;   ///< The MAV we're talking to

110 111
    int maxSilenceTimeout; ///< If nothing received within this period of time, abandon resends

112 113
    UASParameterDataModel* paramDataModel;

114
    bool persistParamsAfterSend; ///< Copy all parameters to persistent storage after sending
115 116 117 118 119 120 121
    QMap<int, QSet<int>*> readsWaiting; ///< All reads that have not yet been received, by component ID
    int retransmitBurstLimit; ///< Number of packets requested for retransmission per burst
    int silenceTimeout; ///< If nothing received within this period of time, start resends
    QTimer silenceTimer;      ///< Timer handling parameter retransmission
    bool transmissionListMode;       ///< Currently requesting list
    QMap<int, QMap<QString, QVariant>* > writesWaiting; ///< All writes that have not yet been ack'd, by component ID

122 123 124 125
private slots:
    /// @brief We signal this to ourselves in order to get timer started/stopped on our own thread.
    void _startSilenceTimerOnThisThread(void);
    void _stopSilenceTimerOnThisThread(void);
126 127 128
    
private:
    void _sendParamRequestListMsg(void);
129 130 131 132
};
    

#endif // UASPARAMETERCOMMSMGR_H