MAVLinkDecoder.h 2.04 KB
Newer Older
lm's avatar
lm committed
1 2 3 4
#ifndef MAVLINKDECODER_H
#define MAVLINKDECODER_H

#include <QObject>
5 6
#include <QHash>

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

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
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
};

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

33 34
    void run();

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

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
46 47
    /** @brief Shift a timestamp in Unix time if necessary */
    quint64 getUnixTimeFromMs(int systemID, quint64 time);
lm's avatar
lm committed
48

49 50
    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
51 52
    QHash<int, mavlink_message_t> msgDict; ///< dictionary of all mavlink messages
    QHash<int, SystemData> sysDict; ///< dictionary of all systmes
53
    QThread* creationThread;                                ///< QThread on which the object is created
lm's avatar
lm committed
54 55 56
};

#endif // MAVLINKDECODER_H