MicrohardManager.h 4.58 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 35
 *
 * 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)
    Q_PROPERTY(QString      netMask             READ netMask                                    NOTIFY netMaskChanged)
36
    Q_PROPERTY(QString      configPassword      READ configPassword                             NOTIFY configPasswordChanged)
37
    Q_PROPERTY(QString      encryptionKey       READ encryptionKey                              NOTIFY encryptionKeyChanged)
38

39
    Q_INVOKABLE bool setIPSettings              (QString localIP, QString remoteIP, QString netMask, QString cfgPassword, QString encyrptionKey);
40 41 42 43 44 45

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

    void        setToolbox                      (QGCToolbox* toolbox) override;

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

signals:
    void    linkChanged                     ();
    void    linkConnectedChanged            ();
    void    connectedChanged                ();
    void    localIPAddrChanged              ();
    void    remoteIPAddrChanged             ();
    void    netMaskChanged                  ();
63
    void    configPasswordChanged           ();
64
    void    encryptionKeyChanged            ();
65 66

private slots:
67 68 69 70
    void    _connectedLoc                   ();
    void    _rssiUpdatedLoc                 (int rssi);
    void    _connectedRem                   ();
    void    _rssiUpdatedRem                 (int rssi);
71 72
    void    _checkMicrohard                 ();
    void    _setEnabled                     ();
73 74
    void    _locTimeout                     ();
    void    _remTimeout                     ();
75 76 77 78 79 80 81 82 83

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

private:
    bool                    _isConnected    = false;
    AppSettings*            _appSettings    = nullptr;
84 85
    MicrohardSettings*      _mhSettingsLoc  = nullptr;
    MicrohardSettings*      _mhSettingsRem  = nullptr;
86 87 88
    bool            _enabled                = true;
    bool            _linkConnected          = false;
    QTimer          _workTimer;
89 90
    QTimer          _locTimer;
    QTimer          _remTimer;
91 92 93 94 95
    int             _downlinkRSSI           = 0;
    int             _uplinkRSSI             = 0;
    QString         _localIPAddr;
    QString         _remoteIPAddr;
    QString         _netMask;
96
    QString         _configPassword;
97
    QString         _encryptionKey;
98 99
    QTime           _timeoutTimer;
};