QGCHilLink.h 5.23 KB
Newer Older
1 2 3 4 5
#ifndef QGCHILLINK_H
#define QGCHILLINK_H

#include <QThread>
#include <QProcess>
6
#include "inttypes.h"
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

class QGCHilLink : public QThread
{
    Q_OBJECT
public:
    
    virtual bool isConnected() = 0;
    virtual qint64 bytesAvailable() = 0;
    virtual int getPort() const = 0;

    /**
     * @brief The human readable port name
     */
    virtual QString getName() = 0;

Lorenz Meier's avatar
Lorenz Meier committed
22 23 24 25 26 27
    /**
     * @brief Get remote host and port
     * @return string in format <host>:<port>
     */
    virtual QString getRemoteHost() = 0;

Lorenz Meier's avatar
Lorenz Meier committed
28 29 30 31 32 33 34 35 36 37 38 39
    /**
     * @brief Get the application name and version
     * @return A string containing a unique application name and compatibility version
     */
    virtual QString getVersion() = 0;

    /**
     * @brief Get index of currently selected airframe
     * @return -1 if default is selected, index else
     */
    virtual int getAirFrameIndex() = 0;

40 41 42 43 44 45
    /**
     * @brief Check if sensor level HIL is enabled
     * @return true if sensor HIL is enabled
     */
    virtual bool sensorHilEnabled() = 0;

46 47 48 49 50
public slots:
    virtual void setPort(int port) = 0;
    /** @brief Add a new host to broadcast messages to */
    virtual void setRemoteHost(const QString& host) = 0;
    /** @brief Send new control states to the simulation */
51
    virtual void updateControls(quint64 time, float rollAilerons, float pitchElevator, float yawRudder, float throttle, quint8 systemMode, quint8 navMode) = 0;
52
    virtual void processError(QProcess::ProcessError err) = 0;
Lorenz Meier's avatar
Lorenz Meier committed
53 54
    /** @brief Set the simulator version as text string */
    virtual void setVersion(const QString& version) = 0;
55 56
    /** @brief Enable sensor-level HIL (instead of state-level HIL) */
    virtual void enableSensorHIL(bool enable) = 0;
57

Lorenz Meier's avatar
Lorenz Meier committed
58 59
    virtual void selectAirframe(const QString& airframe) = 0;

60 61 62 63 64 65 66
    virtual void readBytes() = 0;
    /**
     * @brief Write a number of bytes to the interface.
     *
     * @param data Pointer to the data byte array
     * @param size The size of the bytes array
     **/
67 68 69 70 71
    void writeBytesSafe(const char* data, int length)
    {
        emit _invokeWriteBytes(QByteArray(data, length));
    }

72 73 74
    virtual bool connectSimulation() = 0;
    virtual bool disconnectSimulation() = 0;

75
private slots:
76
    virtual void _writeBytes(const QByteArray) = 0;
77

78 79 80
protected:
    virtual void setName(QString name) = 0;

81 82 83
    QGCHilLink() :
        QThread()
    {
84
        connect(this, &QGCHilLink::_invokeWriteBytes, this, &QGCHilLink::_writeBytes);
85 86
    }

87 88 89 90 91 92 93 94 95 96 97
signals:
    /**
     * @brief This signal is emitted instantly when the link is connected
     **/
    void simulationConnected();

    /**
     * @brief This signal is emitted instantly when the link is disconnected
     **/
    void simulationDisconnected();

98 99 100 101 102
    /**
     * @brief Thread safe signal to disconnect simulator from other threads
     **/
    void disconnectSim();

103 104 105 106 107
    /**
     * @brief This signal is emitted instantly when the link status changes
     **/
    void simulationConnected(bool connected);

Lorenz Meier's avatar
Lorenz Meier committed
108
    /** @brief State update from simulation */
Lorenz Meier's avatar
Lorenz Meier committed
109 110
    void hilStateChanged(quint64 time_us, float roll, float pitch, float yaw, float rollspeed,
                                          float pitchspeed, float yawspeed, double lat, double lon, double alt,
111
                                          float vx, float vy, float vz, float ind_airspeed, float true_airspeed, float xacc, float yacc, float zacc);
Lorenz Meier's avatar
Lorenz Meier committed
112

113 114 115 116 117
    void hilGroundTruthChanged(quint64 time_us, float roll, float pitch, float yaw, float rollspeed,
                              float pitchspeed, float yawspeed, double lat, double lon, double alt,
                              float vx, float vy, float vz, float ind_airspeed, float true_airspeed, float xacc, float yacc, float zacc);

    void sensorHilGpsChanged(quint64 time_us, double lat, double lon, double alt, int fix_type, float eph, float epv, float vel, float vn, float ve, float vd, float cog, int satellites);
Lorenz Meier's avatar
Lorenz Meier committed
118 119 120 121 122 123

    void sensorHilRawImuChanged(quint64 time_us, float xacc, float yacc, float zacc,
                                                  float xgyro, float ygyro, float zgyro,
                                                  float xmag, float ymag, float zmag,
                                                  float abs_pressure, float diff_pressure,
                                                  float pressure_alt, float temperature,
124
                                                  quint32 fields_updated);
125 126 127

    void sensorHilOpticalFlowChanged(quint64 time_us, qint16 flow_x, qint16 flow_y, float flow_comp_m_x,
                                     float flow_comp_m_y, quint8 quality, float ground_distance);
128
    
129 130 131 132 133
    /** @brief Remote host and port changed */
    void remoteChanged(const QString& hostPort);

    /** @brief Status text message from link */
    void statusMessage(const QString& message);
Lorenz Meier's avatar
Lorenz Meier committed
134 135 136 137 138 139

    /** @brief Airframe changed */
    void airframeChanged(const QString& airframe);

    /** @brief Selected sim version changed */
    void versionChanged(const QString& version);
140

141 142 143
    /** @brief Selected sim version changed */
    void versionChanged(const int version);

144 145
    /** @brief Sensor leve HIL state changed */
    void sensorHilChanged(bool enabled);
146 147 148

    /** @brief Helper signal to force execution on the correct thread */
    void _invokeWriteBytes(QByteArray);
149 150 151
};

#endif // QGCHILLINK_H