MAVLinkDecoder.h 1.97 KB
Newer Older
1
#pragma once
lm's avatar
lm committed
2
3

#include <QObject>
4
5
#include <QHash>

lm's avatar
lm committed
6
7
#include "MAVLinkProtocol.h"

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
struct SystemData {
    /**
     * @brief Holds mavlink system data
     */
    SystemData() :
        componentID(-1),
        componentMulti(false),
        onboardTimeOffset(0),
        onboardToGCSUnixTimeOffsetAndDelay(0),
        firstOnboardTime(0) {
    }
    int componentID;            ///< Multi component detection
    bool componentMulti;        ///< Multi components detected
    quint64 onboardTimeOffset;  ///< Offset of onboard time from Unix epoch (of the receiving GCS)
    qint64 onboardToGCSUnixTimeOffsetAndDelay; ///< Offset of onboard time and GCS Unix time
    quint64 firstOnboardTime;   ///< First seen onboard time
};

26
class MAVLinkDecoder : public QThread
lm's avatar
lm committed
27
28
29
{
    Q_OBJECT
public:
30
    MAVLinkDecoder(MAVLinkProtocol* protocol);
lm's avatar
lm committed
31

32
33
    void run();

lm's avatar
lm committed
34
35
signals:
    void textMessageReceived(int uasid, int componentid, int severity, const QString& text);
36
    void valueChanged(const int uasId, const QString& name, const QString& unit, const QVariant& value, const quint64 msec);
37
    void finish(); ///< Trigger a thread safe shutdown
lm's avatar
lm committed
38
39
40
41
42
43
44

public slots:
    /** @brief Receive one message from the protocol and decode it */
    void receiveMessage(LinkInterface* link,mavlink_message_t message);
protected:
    /** @brief Emit the value of one message field */
    void emitFieldValue(mavlink_message_t* msg, int fieldid, quint64 time);
pixhawk's avatar
pixhawk committed
45
46
    /** @brief Shift a timestamp in Unix time if necessary */
    quint64 getUnixTimeFromMs(int systemID, quint64 time);
lm's avatar
lm committed
47

48
49
    QMap<uint16_t, bool> messageFilter;                     ///< Message/field names not to emit
    QMap<uint16_t, bool> textMessageFilter;                 ///< Message/field names not to emit in text mode
50
51
    QHash<int, mavlink_message_t> msgDict; ///< dictionary of all mavlink messages
    QHash<int, SystemData> sysDict; ///< dictionary of all systmes
52
    QThread* creationThread;                                ///< QThread on which the object is created
lm's avatar
lm committed
53
54
};