MultiVehicleManager.h 5.87 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * 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)
dogmaphobic's avatar
dogmaphobic committed
46

47 48
    /// A disconnected vehicle used for offline editing. It will match the vehicle type specified in Settings.
    Q_PROPERTY(Vehicle*             offlineEditingVehicle           READ offlineEditingVehicle                                          CONSTANT)
Don Gagne's avatar
Don Gagne committed
49

50 51 52
    //-- The current vehicle's last known location
    Q_PROPERTY(QGeoCoordinate       lastKnownLocation               READ lastKnownLocation                                              NOTIFY lastKnownLocationChanged)

53
    // Methods
dogmaphobic's avatar
dogmaphobic committed
54

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

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

59
    // Property accessors
dogmaphobic's avatar
dogmaphobic committed
60

61
    bool activeVehicleAvailable(void) { return _activeVehicleAvailable; }
dogmaphobic's avatar
dogmaphobic committed
62

63
    bool parameterReadyVehicleAvailable(void) { return _parameterReadyVehicleAvailable; }
dogmaphobic's avatar
dogmaphobic committed
64

65 66
    Vehicle* activeVehicle(void) { return _activeVehicle; }
    void setActiveVehicle(Vehicle* vehicle);
dogmaphobic's avatar
dogmaphobic committed
67

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

70 71 72
    bool gcsHeartbeatEnabled(void) const { return _gcsHeartbeatEnabled; }
    void setGcsHeartbeatEnabled(bool gcsHeartBeatEnabled);

73 74
    Vehicle* offlineEditingVehicle(void) { return _offlineEditingVehicle; }

75 76 77 78 79 80
    /// Determines if the link is in use by a Vehicle
    ///     @param link Link to test against
    ///     @param skipVehicle Don't consider this Vehicle as part of the test
    /// @return true: link is in use by one or more Vehicles
    bool linkInUse(LinkInterface* link, Vehicle* skipVehicle);

81 82 83
    // Override from QGCTool
    virtual void setToolbox(QGCToolbox *toolbox);

84 85
    QGeoCoordinate lastKnownLocation    () { return _lastKnownLocation; }

86
signals:
87 88 89
    void vehicleAdded                   (Vehicle* vehicle);
    void vehicleRemoved                 (Vehicle* vehicle);
    void activeVehicleAvailableChanged  (bool activeVehicleAvailable);
90
    void parameterReadyVehicleAvailableChanged(bool parameterReadyVehicleAvailable);
91 92 93 94
    void activeVehicleChanged           (Vehicle* activeVehicle);
    void gcsHeartBeatEnabledChanged     (bool gcsHeartBeatEnabled);
    void lastKnownLocationChanged       ();
    void _deleteVehiclePhase2Signal     (void);
dogmaphobic's avatar
dogmaphobic committed
95

96
private slots:
97 98 99 100 101 102 103 104
    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
105

106 107
private:
    bool _vehicleExists(int vehicleId);
dogmaphobic's avatar
dogmaphobic committed
108

109 110 111
    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
112
    Vehicle*    _offlineEditingVehicle;             ///< Disconnected vechicle used for offline editing
dogmaphobic's avatar
dogmaphobic committed
113

Don Gagne's avatar
Don Gagne committed
114 115
    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
116

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

119
    QmlObjectListModel  _vehicles;
120

dogmaphobic's avatar
dogmaphobic committed
121 122 123
    FirmwarePluginManager*      _firmwarePluginManager;
    JoystickManager*            _joystickManager;
    MAVLinkProtocol*            _mavlinkProtocol;
124
    QGeoCoordinate              _lastKnownLocation;
dogmaphobic's avatar
dogmaphobic committed
125

126 127 128 129
    QTimer              _gcsHeartbeatTimer;             ///< Timer to emit heartbeats
    bool                _gcsHeartbeatEnabled;           ///< Enabled/disable heartbeat emission
    static const int    _gcsHeartbeatRateMSecs = 1000;  ///< Heartbeat rate
    static const char*  _gcsHeartbeatEnabledKey;
130 131 132
};

#endif