MicrohardManager.h 5.16 KB
Newer Older
1 2
/****************************************************************************
 *
3
 *   (c) 2019 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
 *
 * 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 "MicrohardSettings.h"
#include "Fact.h"

#include <QTimer>
#include <QTime>

class AppSettings;
class QGCApplication;

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

    Q_PROPERTY(bool         connected           READ connected                                  NOTIFY connectedChanged)
    Q_PROPERTY(bool         linkConnected       READ linkConnected                              NOTIFY linkConnectedChanged)
    Q_PROPERTY(int          uplinkRSSI          READ uplinkRSSI                                 NOTIFY linkChanged)
    Q_PROPERTY(int          downlinkRSSI        READ downlinkRSSI                               NOTIFY linkChanged)
    Q_PROPERTY(QString      localIPAddr         READ localIPAddr                                NOTIFY localIPAddrChanged)
    Q_PROPERTY(QString      remoteIPAddr        READ remoteIPAddr                               NOTIFY remoteIPAddrChanged)
35 36
    Q_PROPERTY(QString      groundIPAddr        READ groundIPAddr                               NOTIFY groundIPAddrChanged)
    Q_PROPERTY(QString      airIPAddr           READ airIPAddr                                  NOTIFY airIPAddrChanged)
37
    Q_PROPERTY(QString      netMask             READ netMask                                    NOTIFY netMaskChanged)
38
    Q_PROPERTY(QString      configPassword      READ configPassword                             NOTIFY configPasswordChanged)
39
    Q_PROPERTY(QString      encryptionKey       READ encryptionKey                              NOTIFY encryptionKeyChanged)
40

41
    Q_INVOKABLE bool setIPSettings              (QString localIP, QString remoteIP, QString groundIP, QString airIP, QString netMask, QString cfgPassword, QString encyrptionKey);
42 43 44 45 46 47

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

    void        setToolbox                      (QGCToolbox* toolbox) override;

48 49
    bool        connected                       () { return _isConnected && _mhSettingsLoc && _mhSettingsLoc->loggedIn(); }
    bool        linkConnected                   () { return _linkConnected && _mhSettingsRem && _mhSettingsRem->loggedIn(); }
50 51 52 53
    int         uplinkRSSI                      () { return _downlinkRSSI; }
    int         downlinkRSSI                    () { return _uplinkRSSI; }
    QString     localIPAddr                     () { return _localIPAddr; }
    QString     remoteIPAddr                    () { return _remoteIPAddr; }
54 55
    QString     airIPAddr                       () { return _airIPAddr; }
    QString     groundIPAddr                    () { return _groundIPAddr; }
56
    QString     netMask                         () { return _netMask; }
57
    QString     configPassword                  () { return _configPassword; }
58
    QString     encryptionKey                   () { return _encryptionKey; }
59 60 61 62 63 64 65

signals:
    void    linkChanged                     ();
    void    linkConnectedChanged            ();
    void    connectedChanged                ();
    void    localIPAddrChanged              ();
    void    remoteIPAddrChanged             ();
66 67
    void    airIPAddrChanged                ();
    void    groundIPAddrChanged             ();
68
    void    netMaskChanged                  ();
69
    void    configPasswordChanged           ();
70
    void    encryptionKeyChanged            ();
71 72

private slots:
73 74 75 76
    void    _connectedLoc                   ();
    void    _rssiUpdatedLoc                 (int rssi);
    void    _connectedRem                   ();
    void    _rssiUpdatedRem                 (int rssi);
77 78
    void    _checkMicrohard                 ();
    void    _setEnabled                     ();
79 80
    void    _locTimeout                     ();
    void    _remTimeout                     ();
81 82 83 84 85 86 87 88 89

private:
    void    _close                          ();
    void    _reset                          ();
    FactMetaData *_createMetadata           (const char *name, QStringList enums);

private:
    bool                    _isConnected    = false;
    AppSettings*            _appSettings    = nullptr;
90 91
    MicrohardSettings*      _mhSettingsLoc  = nullptr;
    MicrohardSettings*      _mhSettingsRem  = nullptr;
92 93 94
    bool            _enabled                = true;
    bool            _linkConnected          = false;
    QTimer          _workTimer;
95 96
    QTimer          _locTimer;
    QTimer          _remTimer;
97 98 99 100
    int             _downlinkRSSI           = 0;
    int             _uplinkRSSI             = 0;
    QString         _localIPAddr;
    QString         _remoteIPAddr;
101 102
    QString         _groundIPAddr;
    QString         _airIPAddr;
103
    QString         _netMask;
104
    QString         _configPassword;
105
    QString         _encryptionKey;
106 107
    QTime           _timeoutTimer;
};