OpalLink.h 3.48 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*=====================================================================

QGroundControl Open Source Ground Control Station

(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>

This file is part of the QGROUNDCONTROL project

    QGROUNDCONTROL is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    QGROUNDCONTROL is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

======================================================================*/

Bryan Godbolt's avatar
Bryan Godbolt committed
24
/**
pixhawk's avatar
pixhawk committed
25 26 27 28
 * @file
 *   @brief Connection to OpalRT
 *   @author Bryan Godbolt <godbolt@ualberta.ca>
 */
Bryan Godbolt's avatar
Bryan Godbolt committed
29

pixhawk's avatar
pixhawk committed
30 31
#ifndef OPALLINK_H
#define OPALLINK_H
Bryan Godbolt's avatar
Bryan Godbolt committed
32 33

#include <QMutex>
34 35
#include <QDebug>
#include <QMessageBox>
36 37 38 39
#include <QTimer>
#include <QQueue>
#include <QByteArray>
#include <QObject>
Bryan Godbolt's avatar
Bryan Godbolt committed
40 41 42 43

#include "LinkInterface.h"
#include "LinkManager.h"
#include "MG.h"
44 45 46
#include "mavlink.h"
#include "mavlink_types.h"
#include "configuration.h"
47

Bryan Godbolt's avatar
Bryan Godbolt committed
48
#include "errno.h"
49 50 51 52 53 54 55 56 57 58 59




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





60
#include "string.h"
Bryan Godbolt's avatar
Bryan Godbolt committed
61

62 63 64 65 66 67
/*
  Configuration info for the model
 */

#define NUM_OUTPUT_SIGNALS 6

pixhawk's avatar
pixhawk committed
68 69 70 71 72 73 74 75 76 77
/**
 * @brief Interface to OPAL-RT targets
 *
 * This is an interface to the Opal-RT hardware-in-the-loop (HIL) simulator.
 * 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>
 * @ref http://www.opal-rt.com/
 */
78 79
class OpalLink : public LinkInterface
{
Bryan Godbolt's avatar
Bryan Godbolt committed
80
    Q_OBJECT
81 82 83

public:
    OpalLink();
Bryan Godbolt's avatar
Bryan Godbolt committed
84 85 86 87 88 89 90 91 92 93 94 95 96
    /* Connection management */

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

    /* Connection characteristics */


    qint64 getNominalDataRate();
    bool isFullDuplex();
    int getLinkQuality();
    qint64 getTotalUpstream();
97
    qint64 getTotalDownstream();
Bryan Godbolt's avatar
Bryan Godbolt committed
98 99 100 101 102 103
    qint64 getCurrentUpstream();
    qint64 getMaxUpstream();
    qint64 getBitsSent();
    qint64 getBitsReceived();


Bryan Godbolt's avatar
Bryan Godbolt committed
104
    bool connect();
Bryan Godbolt's avatar
Bryan Godbolt committed
105 106


Bryan Godbolt's avatar
Bryan Godbolt committed
107
    bool disconnect();
Bryan Godbolt's avatar
Bryan Godbolt committed
108 109


Bryan Godbolt's avatar
Bryan Godbolt committed
110
    qint64 bytesAvailable();
Bryan Godbolt's avatar
Bryan Godbolt committed
111

112 113
    void run();

Bryan Godbolt's avatar
Bryan Godbolt committed
114 115 116
public slots:


Bryan Godbolt's avatar
Bryan Godbolt committed
117
    void writeBytes(const char *bytes, qint64 length);
Bryan Godbolt's avatar
Bryan Godbolt committed
118 119


120
    void readBytes();
Bryan Godbolt's avatar
Bryan Godbolt committed
121

122 123
    void heartbeat();

124 125
    void getSignals();

126 127 128 129
protected slots:

    void receiveMessage(mavlink_message_t message);

Bryan Godbolt's avatar
Bryan Godbolt committed
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145


protected:
    QString name;
    int id;
    bool connectState;

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

    QMutex statisticsMutex;
146
    QMutex receiveDataMutex;
147 148
    QString lastErrorMsg;
    void setLastErrorMsg();
149
    void displayErrorMsg();
Bryan Godbolt's avatar
Bryan Godbolt committed
150 151

    void setName(QString name);
152 153 154 155

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

    QTimer* getSignalsTimer;
    int getSignalsPeriod;

160 161 162 163 164 165 166
    QQueue<QByteArray>* receiveBuffer;
    QByteArray* sendBuffer;

    const int systemID;
    const int componentID;


167 168 169
};

#endif // OPALLINK_H