Skip to content
OpalLink.h 2.31 KiB
Newer Older
#ifndef OPALLINK_H
#define OPALLINK_H
Bryan Godbolt's avatar
Bryan Godbolt committed
/**
  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>
#include <QDebug>
#include <QMessageBox>
#include <QTimer>
#include <QQueue>
#include <QByteArray>
#include <QObject>
Bryan Godbolt's avatar
Bryan Godbolt committed

#include "LinkInterface.h"
#include "LinkManager.h"
#include "MG.h"
#include "mavlink.h"
#include "mavlink_types.h"
#include "configuration.h"
Bryan Godbolt's avatar
Bryan Godbolt committed
#include "errno.h"
#include "OpalApi.h"
#include "string.h"
Bryan Godbolt's avatar
Bryan Godbolt committed

/*
  Configuration info for the model
 */

#define NUM_OUTPUT_SIGNALS 6

class OpalLink : public LinkInterface
{
Bryan Godbolt's avatar
Bryan Godbolt committed
    Q_OBJECT

public:
    OpalLink();
Bryan Godbolt's avatar
Bryan Godbolt committed
    /* Connection management */

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

    /* Connection characteristics */


    qint64 getNominalDataRate();
    bool isFullDuplex();
    int getLinkQuality();
    qint64 getTotalUpstream();
    qint64 getTotalDownstream();
Bryan Godbolt's avatar
Bryan Godbolt committed
    qint64 getCurrentUpstream();
    qint64 getMaxUpstream();
    qint64 getBitsSent();
    qint64 getBitsReceived();


Bryan Godbolt's avatar
Bryan Godbolt committed
    bool connect();
Bryan Godbolt's avatar
Bryan Godbolt committed
    bool disconnect();
Bryan Godbolt's avatar
Bryan Godbolt committed
    qint64 bytesAvailable();
Bryan Godbolt's avatar
Bryan Godbolt committed

Bryan Godbolt's avatar
Bryan Godbolt committed
public slots:


Bryan Godbolt's avatar
Bryan Godbolt committed
    void writeBytes(const char *bytes, qint64 length);
Bryan Godbolt's avatar
Bryan Godbolt committed
    void readBytes(char *bytes, qint64 maxLength);
Bryan Godbolt's avatar
Bryan Godbolt committed

    void heartbeat();

protected slots:

    void receiveMessage(mavlink_message_t message);

Bryan Godbolt's avatar
Bryan Godbolt committed


protected:
    QString name;
    int id;
    bool connectState;

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

    QMutex statisticsMutex;
    QMutex receiveDataMutex;
    QString lastErrorMsg;
    void setLastErrorMsg();
    void displayErrorMsg();
Bryan Godbolt's avatar
Bryan Godbolt committed

    void setName(QString name);

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

    QTimer* getSignalsTimer;
    int getSignalsPeriod;

    QQueue<QByteArray>* receiveBuffer;
    QByteArray* sendBuffer;

    const int systemID;
    const int componentID;


};

#endif // OPALLINK_H