OpalLink.h 2.3 KB
Newer Older
1 2
#ifndef OPALLINK_H
#define OPALLINK_H
Bryan Godbolt's avatar
Bryan Godbolt committed
3 4 5 6 7 8 9 10
/**
  Connection to OpalRT.  This class receives MAVLink packets as if it is a true link, but it
  interprets the packets internally, and calls the appropriate api functions.

  \author Bryan Godbolt <godbolt@ualberta.ca>
*/

#include <QMutex>
11 12
#include <QDebug>
#include <QMessageBox>
13 14 15 16
#include <QTimer>
#include <QQueue>
#include <QByteArray>
#include <QObject>
Bryan Godbolt's avatar
Bryan Godbolt committed
17 18 19 20

#include "LinkInterface.h"
#include "LinkManager.h"
#include "MG.h"
21 22 23
#include "mavlink.h"
#include "mavlink_types.h"
#include "configuration.h"
24

Bryan Godbolt's avatar
Bryan Godbolt committed
25
#include "errno.h"
26 27 28 29 30 31 32 33 34 35 36




// FIXME
//#include "OpalApi.h"





37
#include "string.h"
Bryan Godbolt's avatar
Bryan Godbolt committed
38

39 40 41 42 43 44
/*
  Configuration info for the model
 */

#define NUM_OUTPUT_SIGNALS 6

45 46
class OpalLink : public LinkInterface
{
Bryan Godbolt's avatar
Bryan Godbolt committed
47
    Q_OBJECT
48 49 50

public:
    OpalLink();
Bryan Godbolt's avatar
Bryan Godbolt committed
51 52 53 54 55 56 57 58 59 60 61 62 63
    /* Connection management */

    int getId();
    QString getName();
    bool isConnected();

    /* Connection characteristics */


    qint64 getNominalDataRate();
    bool isFullDuplex();
    int getLinkQuality();
    qint64 getTotalUpstream();
64
    qint64 getTotalDownstream();
Bryan Godbolt's avatar
Bryan Godbolt committed
65 66 67 68 69 70
    qint64 getCurrentUpstream();
    qint64 getMaxUpstream();
    qint64 getBitsSent();
    qint64 getBitsReceived();


Bryan Godbolt's avatar
Bryan Godbolt committed
71
    bool connect();
Bryan Godbolt's avatar
Bryan Godbolt committed
72 73


Bryan Godbolt's avatar
Bryan Godbolt committed
74
    bool disconnect();
Bryan Godbolt's avatar
Bryan Godbolt committed
75 76


Bryan Godbolt's avatar
Bryan Godbolt committed
77
    qint64 bytesAvailable();
Bryan Godbolt's avatar
Bryan Godbolt committed
78

79 80
    void run();

Bryan Godbolt's avatar
Bryan Godbolt committed
81 82 83
public slots:


Bryan Godbolt's avatar
Bryan Godbolt committed
84
    void writeBytes(const char *bytes, qint64 length);
Bryan Godbolt's avatar
Bryan Godbolt committed
85 86


87
    void readBytes();
Bryan Godbolt's avatar
Bryan Godbolt committed
88

89 90
    void heartbeat();

91 92
    void getSignals();

93 94 95 96
protected slots:

    void receiveMessage(mavlink_message_t message);

Bryan Godbolt's avatar
Bryan Godbolt committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112


protected:
    QString name;
    int id;
    bool connectState;

    quint64 bitsSentTotal;
    quint64 bitsSentCurrent;
    quint64 bitsSentMax;
    quint64 bitsReceivedTotal;
    quint64 bitsReceivedCurrent;
    quint64 bitsReceivedMax;
    quint64 connectionStartTime;

    QMutex statisticsMutex;
113
    QMutex receiveDataMutex;
114 115
    QString lastErrorMsg;
    void setLastErrorMsg();
116
    void displayErrorMsg();
Bryan Godbolt's avatar
Bryan Godbolt committed
117 118

    void setName(QString name);
119 120 121 122

    QTimer* heartbeatTimer;    ///< Timer to emit heartbeats
    int heartbeatRate;         ///< Heartbeat rate, controls the timer interval
    bool m_heartbeatsEnabled;  ///< Enabled/disable heartbeat emission
123 124 125 126

    QTimer* getSignalsTimer;
    int getSignalsPeriod;

127 128 129 130 131 132 133
    QQueue<QByteArray>* receiveBuffer;
    QByteArray* sendBuffer;

    const int systemID;
    const int componentID;


134 135 136
};

#endif // OPALLINK_H