TaisyncManager.h 8.3 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9 10 11 12 13 14
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

#pragma once

#include "QGCToolbox.h"
#include "QGCLoggingCategory.h"
#include "TaisyncSettings.h"
15
#include "Fact.h"
16 17 18 19 20 21
#if defined(__ios__) || defined(__android__)
#include "TaisyncTelemetry.h"
#include "TaisyncVideoReceiver.h"
#endif

#include <QTimer>
Gus Grubba's avatar
Gus Grubba committed
22
#include <QTime>
23 24 25 26 27 28 29 30 31 32

class AppSettings;
class QGCApplication;

//-----------------------------------------------------------------------------
class TaisyncManager : public QGCTool
{
    Q_OBJECT
public:

33
    Q_PROPERTY(bool         connected           READ connected                                  NOTIFY connectedChanged)
Gus Grubba's avatar
Gus Grubba committed
34
    Q_PROPERTY(bool         linkConnected       READ linkConnected                              NOTIFY linkConnectedChanged)
Gus Grubba's avatar
Gus Grubba committed
35
    Q_PROPERTY(bool         needReboot          READ needReboot                                 NOTIFY needRebootChanged)
36 37 38
    Q_PROPERTY(QString      linkVidFormat       READ linkVidFormat                              NOTIFY linkChanged)
    Q_PROPERTY(int          uplinkRSSI          READ uplinkRSSI                                 NOTIFY linkChanged)
    Q_PROPERTY(int          downlinkRSSI        READ downlinkRSSI                               NOTIFY linkChanged)
Gus Grubba's avatar
Gus Grubba committed
39 40
    Q_PROPERTY(QString      serialNumber        READ serialNumber                               NOTIFY infoChanged)
    Q_PROPERTY(QString      fwVersion           READ fwVersion                                  NOTIFY infoChanged)
41 42
    Q_PROPERTY(Fact*        radioMode           READ radioMode                                  CONSTANT)
    Q_PROPERTY(Fact*        radioChannel        READ radioChannel                               CONSTANT)
Gus Grubba's avatar
Gus Grubba committed
43 44 45
    Q_PROPERTY(Fact*        videoOutput         READ videoOutput                                CONSTANT)
    Q_PROPERTY(Fact*        videoMode           READ videoMode                                  CONSTANT)
    Q_PROPERTY(Fact*        videoRate           READ videoRate                                  CONSTANT)
Gus Grubba's avatar
Gus Grubba committed
46 47 48 49 50 51 52 53 54
    Q_PROPERTY(QString      rtspURI             READ rtspURI                                    NOTIFY rtspURIChanged)
    Q_PROPERTY(QString      rtspAccount         READ rtspAccount                                NOTIFY rtspAccountChanged)
    Q_PROPERTY(QString      rtspPassword        READ rtspPassword                               NOTIFY rtspPasswordChanged)
    Q_PROPERTY(QString      localIPAddr         READ localIPAddr                                NOTIFY localIPAddrChanged)
    Q_PROPERTY(QString      remoteIPAddr        READ remoteIPAddr                               NOTIFY remoteIPAddrChanged)
    Q_PROPERTY(QString      netMask             READ netMask                                    NOTIFY netMaskChanged)

    Q_INVOKABLE bool setRTSPSettings            (QString uri, QString account, QString password);
    Q_INVOKABLE bool setIPSettings              (QString localIP, QString remoteIP, QString netMask);
55 56 57 58

    explicit TaisyncManager                 (QGCApplication* app, QGCToolbox* toolbox);
    ~TaisyncManager                         () override;

59
    void        setToolbox                      (QGCToolbox* toolbox) override;
60

61 62
    bool        connected                       () { return _isConnected; }
    bool        linkConnected                   () { return _linkConnected; }
Gus Grubba's avatar
Gus Grubba committed
63
    bool        needReboot                      () { return _needReboot; }
64 65 66 67 68
    QString     linkVidFormat                   () { return _linkVidFormat; }
    int         uplinkRSSI                      () { return _downlinkRSSI; }
    int         downlinkRSSI                    () { return _uplinkRSSI; }
    QString     serialNumber                    () { return _serialNumber; }
    QString     fwVersion                       () { return _fwVersion; }
69 70
    Fact*       radioMode                       () { return _radioMode; }
    Fact*       radioChannel                    () { return _radioChannel; }
Gus Grubba's avatar
Gus Grubba committed
71 72 73
    Fact*       videoOutput                     () { return _videoOutput; }
    Fact*       videoMode                       () { return _videoMode; }
    Fact*       videoRate                       () { return _videoRate; }
Gus Grubba's avatar
Gus Grubba committed
74 75 76 77 78 79
    QString     rtspURI                         () { return _rtspURI; }
    QString     rtspAccount                     () { return _rtspAccount; }
    QString     rtspPassword                    () { return _rtspPassword; }
    QString     localIPAddr                     () { return _localIPAddr; }
    QString     remoteIPAddr                    () { return _remoteIPAddr; }
    QString     netMask                         () { return _netMask; }
80 81 82

signals:
    void    linkChanged                     ();
Gus Grubba's avatar
Gus Grubba committed
83 84
    void    linkConnectedChanged            ();
    void    infoChanged                     ();
85
    void    connectedChanged                ();
86 87
    void    decodeIndexChanged              ();
    void    rateIndexChanged                ();
Gus Grubba's avatar
Gus Grubba committed
88 89 90 91 92 93
    void    rtspURIChanged                  ();
    void    rtspAccountChanged              ();
    void    rtspPasswordChanged             ();
    void    localIPAddrChanged              ();
    void    remoteIPAddrChanged             ();
    void    netMaskChanged                  ();
Gus Grubba's avatar
Gus Grubba committed
94
    void    needRebootChanged               ();
95 96 97

private slots:
    void    _connected                      ();
Gus Grubba's avatar
Gus Grubba committed
98
    void    _disconnected                   ();
99 100 101 102
    void    _checkTaisync                   ();
    void    _updateSettings                 (QByteArray jSonData);
    void    _setEnabled                     ();
    void    _setVideoEnabled                ();
103
    void    _radioSettingsChanged           (QVariant);
Gus Grubba's avatar
Gus Grubba committed
104
    void    _videoSettingsChanged           (QVariant);
Gus Grubba's avatar
Gus Grubba committed
105 106 107 108
#if defined(__ios__) || defined(__android__)
    void    _readUDPBytes                   ();
    void    _readTelemBytes                 (QByteArray bytesIn);
#endif
109

Gus Grubba's avatar
Gus Grubba committed
110 111 112
private:
    void    _close                          ();
    void    _reset                          ();
Gus Grubba's avatar
Gus Grubba committed
113
    void    _restoreVideoSettings           (Fact* setting);
Gus Grubba's avatar
Gus Grubba committed
114
    FactMetaData *_createMetadata           (const char *name, QStringList enums);
Gus Grubba's avatar
Gus Grubba committed
115

116 117 118
private:

    enum {
Gus Grubba's avatar
Gus Grubba committed
119 120 121 122 123 124 125
        REQ_LINK_STATUS         = 1,
        REQ_DEV_INFO            = 2,
        REQ_FREQ_SCAN           = 4,
        REQ_VIDEO_SETTINGS      = 8,
        REQ_RADIO_SETTINGS      = 16,
        REQ_RTSP_SETTINGS       = 32,
        REQ_IP_SETTINGS         = 64,
Gus Grubba's avatar
Gus Grubba committed
126
        REQ_ALL                 = 0xFFFFFFF,
127 128
    };

Gus Grubba's avatar
Gus Grubba committed
129
    uint32_t                _reqMask        = static_cast<uint32_t>(REQ_ALL);
130 131 132 133 134 135 136 137
    bool                    _running        = false;
    bool                    _isConnected    = false;
    AppSettings*            _appSettings    = nullptr;
    TaisyncManager*         _taiManager     = nullptr;
    TaisyncSettings*        _taiSettings    = nullptr;
#if defined(__ios__) || defined(__android__)
    TaisyncTelemetry*       _taiTelemetery  = nullptr;
    TaisyncVideoReceiver*   _taiVideo       = nullptr;
Gus Grubba's avatar
Gus Grubba committed
138
    QUdpSocket*             _telemetrySocket= nullptr;
139
#endif
140 141 142
    bool            _enableVideo            = true;
    bool            _enabled                = true;
    bool            _linkConnected          = false;
Gus Grubba's avatar
Gus Grubba committed
143
    bool            _needReboot             = false;
144 145 146 147 148 149 150 151 152 153 154 155
    QTimer          _workTimer;
    QString         _linkVidFormat;
    int             _downlinkRSSI           = 0;
    int             _uplinkRSSI             = 0;
    QStringList     _decodeList;
    int             _decodeIndex            = 0;
    QStringList     _rateList;
    int             _rateIndex              = 0;
    QString         _serialNumber;
    QString         _fwVersion;
    Fact*           _radioMode              = nullptr;
    Fact*           _radioChannel           = nullptr;
Gus Grubba's avatar
Gus Grubba committed
156 157 158 159 160 161
    Fact*           _videoOutput            = nullptr;
    Fact*           _videoMode              = nullptr;
    Fact*           _videoRate              = nullptr;
    QStringList     _radioModeList;
    QStringList     _videoOutputList;
    QStringList     _videoRateList;
Gus Grubba's avatar
Gus Grubba committed
162 163 164 165 166 167
    QString         _rtspURI;
    QString         _rtspAccount;
    QString         _rtspPassword;
    QString         _localIPAddr;
    QString         _remoteIPAddr;
    QString         _netMask;
Gus Grubba's avatar
Gus Grubba committed
168
    QTime           _timeoutTimer;
169
};