MAVLinkSimulationLink.h 3.59 KB
Newer Older
pixhawk's avatar
pixhawk committed
1 2
/*=====================================================================

3
QGroundControl Open Source Ground Control Station
pixhawk's avatar
pixhawk committed
4

5
(c) 2009, 2010 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
pixhawk's avatar
pixhawk committed
6

7
This file is part of the QGROUNDCONTROL project
pixhawk's avatar
pixhawk committed
8

9
    QGROUNDCONTROL is free software: you can redistribute it and/or modify
pixhawk's avatar
pixhawk committed
10 11 12 13
    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.

14
    QGROUNDCONTROL is distributed in the hope that it will be useful,
pixhawk's avatar
pixhawk committed
15 16 17 18 19
    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
20
    along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
pixhawk's avatar
pixhawk committed
21 22 23 24 25

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

/**
 * @file
26
 *   @brief Definition of MAVLinkSimulationLink
pixhawk's avatar
pixhawk committed
27 28 29 30 31 32 33 34 35 36 37 38 39
 *
 *   @author Lorenz Meier <mavteam@student.ethz.ch>
 *
 */

#ifndef MAVLINKSIMULATIONLINK_H
#define MAVLINKSIMULATIONLINK_H

#include <QFile>
#include <QTimer>
#include <QTextStream>
#include <QQueue>
#include <QMutex>
lm's avatar
lm committed
40
#include <QMap>
pixhawk's avatar
pixhawk committed
41
#include <inttypes.h>
pixhawk's avatar
pixhawk committed
42
#include "QGCMAVLink.h"
lm's avatar
lm committed
43

pixhawk's avatar
pixhawk committed
44
#include "LinkInterface.h"
pixhawk's avatar
pixhawk committed
45 46 47

class MAVLinkSimulationLink : public LinkInterface
{
pixhawk's avatar
pixhawk committed
48
    Q_OBJECT
pixhawk's avatar
pixhawk committed
49
public:
pixhawk's avatar
pixhawk committed
50
    MAVLinkSimulationLink(QString readFile="", QString writeFile="", int rate=5);
pixhawk's avatar
pixhawk committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
    ~MAVLinkSimulationLink();
    bool isConnected();
    qint64 bytesAvailable();

    void run();

    bool connect();
    bool disconnect();

    /* Extensive statistics for scientific purposes */
    qint64 getNominalDataRate();
    qint64 getTotalUpstream();
    qint64 getShortTermUpstream();
    qint64 getCurrentUpstream();
    qint64 getMaxUpstream();
    qint64 getTotalDownstream();
    qint64 getShortTermDownstream();
    qint64 getCurrentDownstream();
    qint64 getMaxDownstream();
    qint64 getBitsSent();
    qint64 getBitsReceived();

    QString getName();
    int getId();
    int getBaudRate();
    int getBaudRateType();
    int getFlowType();
    int getParityType();
    int getDataBitsType();
    int getStopBitsType();

    int getLinkQuality();
    bool isFullDuplex();

public slots:
    void writeBytes(const char* data, qint64 size);
87
    void readBytes();
pixhawk's avatar
pixhawk committed
88
    virtual void mainloop();
89
    bool connectLink(bool connect);
90
    void connectLink();
pixhawk's avatar
pixhawk committed
91 92 93 94 95 96


protected:

    // UAS properties
    float roll, pitch, yaw;
97 98
    double x, y, z;
    double spX, spY, spZ, spYaw;
pixhawk's avatar
pixhawk committed
99 100 101 102 103
    int battery;

    QTimer* timer;
    /** File which contains the input data (simulated robot messages) **/
    QFile* simulationFile;
104
    QFile* mavlinkLogFile;
pixhawk's avatar
pixhawk committed
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
    QString simulationHeader;
    /** File where the commands sent by the groundstation are stored **/
    QFile* receiveFile;
    QTextStream stream;
    QTextStream* fileStream;
    QTextStream* outStream;
    /** Buffer which can be read from connected protocols through readBytes(). **/
    QMutex readyBufferMutex;
    bool _isConnected;
    quint64 rate;
    int maxTimeNoise;
    quint64 lastSent;

    int readyBytes;
    QQueue<uint8_t> readyBuffer;

    int id;
    QString name;
pixhawk's avatar
pixhawk committed
123
    qint64 timeOffset;
pixhawk's avatar
pixhawk committed
124
    mavlink_sys_status_t status;
lm's avatar
lm committed
125
    QMap<QString, float> onboardParams;
pixhawk's avatar
pixhawk committed
126

pixhawk's avatar
pixhawk committed
127 128
    void enqueue(uint8_t* stream, uint8_t* index, mavlink_message_t* msg);

129 130 131 132
    static const uint8_t systemId = 220;
    static const uint8_t componentId = 0;
    static const uint16_t version = 1000;

133
signals:
pixhawk's avatar
pixhawk committed
134
    void valueChanged(int uasId, QString curve, double value, quint64 usec);
pixhawk's avatar
pixhawk committed
135 136 137 138

};

#endif // MAVLINKSIMULATIONLINK_H