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

10 11 12 13 14 15 16 17 18

/// @file
///     @author Don Gagne <don@thegagnes.com>

#ifndef MultiVehicleManager_H
#define MultiVehicleManager_H

#include "Vehicle.h"
#include "QGCMAVLink.h"
19
#include "QmlObjectListModel.h"
20
#include "QGCToolbox.h"
Don Gagne's avatar
Don Gagne committed
21
#include "QGCLoggingCategory.h"
22

23
class FirmwarePluginManager;
Jimmy Johnson's avatar
Jimmy Johnson committed
24
class FollowMe;
25 26 27 28
class JoystickManager;
class QGCApplication;
class MAVLinkProtocol;

Don Gagne's avatar
Don Gagne committed
29 30
Q_DECLARE_LOGGING_CATEGORY(MultiVehicleManagerLog)

31
class MultiVehicleManager : public QGCTool
32 33
{
    Q_OBJECT
dogmaphobic's avatar
dogmaphobic committed
34

35
public:
36
    MultiVehicleManager(QGCApplication* app, QGCToolbox* toolbox);
37

38 39
    Q_INVOKABLE void        saveSetting (const QString &key, const QString& value);
    Q_INVOKABLE QString     loadSetting (const QString &key, const QString& defaultValue);
dogmaphobic's avatar
dogmaphobic committed
40

41 42 43 44 45
    Q_PROPERTY(bool                 activeVehicleAvailable          READ activeVehicleAvailable                                         NOTIFY activeVehicleAvailableChanged)
    Q_PROPERTY(bool                 parameterReadyVehicleAvailable  READ parameterReadyVehicleAvailable                                 NOTIFY parameterReadyVehicleAvailableChanged)
    Q_PROPERTY(Vehicle*             activeVehicle                   READ activeVehicle                  WRITE setActiveVehicle          NOTIFY activeVehicleChanged)
    Q_PROPERTY(QmlObjectListModel*  vehicles                        READ vehicles                                                       CONSTANT)
    Q_PROPERTY(bool                 gcsHeartBeatEnabled             READ gcsHeartbeatEnabled            WRITE setGcsHeartbeatEnabled    NOTIFY gcsHeartBeatEnabledChanged)
46
    Q_PROPERTY(Vehicle*             offlineEditingVehicle           READ offlineEditingVehicle                                          CONSTANT)
47
    Q_PROPERTY(QGeoCoordinate       lastKnownLocation               READ lastKnownLocation                                              NOTIFY lastKnownLocationChanged) //< Current vehicles last know location
Don Gagne's avatar
Don Gagne committed
48

49
    // Methods
dogmaphobic's avatar
dogmaphobic committed
50

Don Gagne's avatar
Don Gagne committed
51
    Q_INVOKABLE Vehicle* getVehicleById(int vehicleId);
dogmaphobic's avatar
dogmaphobic committed
52

53
    UAS* activeUas(void) { return _activeVehicle ? _activeVehicle->uas() : nullptr; }
dogmaphobic's avatar
dogmaphobic committed
54

55
    // Property accessors
dogmaphobic's avatar
dogmaphobic committed
56

57
    bool activeVehicleAvailable(void) { return _activeVehicleAvailable; }
dogmaphobic's avatar
dogmaphobic committed
58

59
    bool parameterReadyVehicleAvailable(void) { return _parameterReadyVehicleAvailable; }
dogmaphobic's avatar
dogmaphobic committed
60

61 62
    Vehicle* activeVehicle(void) { return _activeVehicle; }
    void setActiveVehicle(Vehicle* vehicle);
dogmaphobic's avatar
dogmaphobic committed
63

64
    QmlObjectListModel* vehicles(void) { return &_vehicles; }
dogmaphobic's avatar
dogmaphobic committed
65

66 67 68
    bool gcsHeartbeatEnabled(void) const { return _gcsHeartbeatEnabled; }
    void setGcsHeartbeatEnabled(bool gcsHeartBeatEnabled);

69 70
    Vehicle* offlineEditingVehicle(void) { return _offlineEditingVehicle; }

71 72 73
    // Override from QGCTool
    virtual void setToolbox(QGCToolbox *toolbox);

74 75
    QGeoCoordinate lastKnownLocation    () { return _lastKnownLocation; }

76
signals:
77 78 79
    void vehicleAdded                   (Vehicle* vehicle);
    void vehicleRemoved                 (Vehicle* vehicle);
    void activeVehicleAvailableChanged  (bool activeVehicleAvailable);
80
    void parameterReadyVehicleAvailableChanged(bool parameterReadyVehicleAvailable);
81 82 83 84 85 86
    void activeVehicleChanged           (Vehicle* activeVehicle);
    void gcsHeartBeatEnabledChanged     (bool gcsHeartBeatEnabled);
    void lastKnownLocationChanged       ();
#ifndef DOXYGEN_SKIP
    void _deleteVehiclePhase2Signal     (void);
#endif
dogmaphobic's avatar
dogmaphobic committed
87

88
private slots:
89 90 91 92 93 94 95 96
    void _deleteVehiclePhase1           (Vehicle* vehicle);
    void _deleteVehiclePhase2           (void);
    void _setActiveVehiclePhase2        (void);
    void _vehicleParametersReadyChanged (bool parametersReady);
    void _sendGCSHeartbeat              (void);
    void _vehicleHeartbeatInfo          (LinkInterface* link, int vehicleId, int componentId, int vehicleFirmwareType, int vehicleType);
    void _requestProtocolVersion        (unsigned version);
    void _coordinateChanged             (QGeoCoordinate coordinate);
dogmaphobic's avatar
dogmaphobic committed
97

98 99
private:
    bool _vehicleExists(int vehicleId);
dogmaphobic's avatar
dogmaphobic committed
100

101 102 103
    bool        _activeVehicleAvailable;            ///< true: An active vehicle is available
    bool        _parameterReadyVehicleAvailable;    ///< true: An active vehicle with ready parameters is available
    Vehicle*    _activeVehicle;                     ///< Currently active vehicle from a ui perspective
104
    Vehicle*    _offlineEditingVehicle;             ///< Disconnected vechicle used for offline editing
dogmaphobic's avatar
dogmaphobic committed
105

Don Gagne's avatar
Don Gagne committed
106 107
    QList<Vehicle*> _vehiclesBeingDeleted;          ///< List of Vehicles being deleted in queued phases
    Vehicle*        _vehicleBeingSetActive;         ///< Vehicle being set active in queued phases
dogmaphobic's avatar
dogmaphobic committed
108

109
    QList<int>  _ignoreVehicleIds;          ///< List of vehicle id for which we ignore further communication
dogmaphobic's avatar
dogmaphobic committed
110

111
    QmlObjectListModel  _vehicles;
112

dogmaphobic's avatar
dogmaphobic committed
113 114 115
    FirmwarePluginManager*      _firmwarePluginManager;
    JoystickManager*            _joystickManager;
    MAVLinkProtocol*            _mavlinkProtocol;
116
    QGeoCoordinate              _lastKnownLocation;
dogmaphobic's avatar
dogmaphobic committed
117

118 119 120 121
    QTimer              _gcsHeartbeatTimer;             ///< Timer to emit heartbeats
    bool                _gcsHeartbeatEnabled;           ///< Enabled/disable heartbeat emission
    static const int    _gcsHeartbeatRateMSecs = 1000;  ///< Heartbeat rate
    static const char*  _gcsHeartbeatEnabledKey;
122 123 124
};

#endif