MultiVehicleManager.h 5.24 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 24
class FirmwarePluginManager;
class AutoPilotPluginManager;
Jimmy Johnson's avatar
Jimmy Johnson committed
25
class FollowMe;
26 27 28 29
class JoystickManager;
class QGCApplication;
class MAVLinkProtocol;

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

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

36
public:
37 38
    MultiVehicleManager(QGCApplication* app);

39 40
    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
41

42 43 44 45 46
    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
47

48
    /// A disconnected vehicle is used to simulate vehicle information while no vehicle is connected.
Don Gagne's avatar
Don Gagne committed
49 50
    Q_PROPERTY(Vehicle*             disconnectedVehicle             MEMBER _disconnectedVehicle                                         CONSTANT)

51
    // Methods
dogmaphobic's avatar
dogmaphobic committed
52

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

55
    UAS* activeUas(void) { return _activeVehicle ? _activeVehicle->uas() : NULL; }
dogmaphobic's avatar
dogmaphobic committed
56

57
    // Property accessors
dogmaphobic's avatar
dogmaphobic committed
58

59
    bool activeVehicleAvailable(void) { return _activeVehicleAvailable; }
dogmaphobic's avatar
dogmaphobic committed
60

61
    bool parameterReadyVehicleAvailable(void) { return _parameterReadyVehicleAvailable; }
dogmaphobic's avatar
dogmaphobic committed
62

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

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

68 69 70
    bool gcsHeartbeatEnabled(void) const { return _gcsHeartbeatEnabled; }
    void setGcsHeartbeatEnabled(bool gcsHeartBeatEnabled);

71 72 73 74 75 76
    /// 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);

77 78 79
    // Override from QGCTool
    virtual void setToolbox(QGCToolbox *toolbox);

80 81 82 83 84 85
signals:
    void vehicleAdded(Vehicle* vehicle);
    void vehicleRemoved(Vehicle* vehicle);
    void activeVehicleAvailableChanged(bool activeVehicleAvailable);
    void parameterReadyVehicleAvailableChanged(bool parameterReadyVehicleAvailable);
    void activeVehicleChanged(Vehicle* activeVehicle);
86
    void gcsHeartBeatEnabledChanged(bool gcsHeartBeatEnabled);
dogmaphobic's avatar
dogmaphobic committed
87

88
    void _deleteVehiclePhase2Signal(void);
dogmaphobic's avatar
dogmaphobic committed
89

90
private slots:
91
    void _deleteVehiclePhase1(Vehicle* vehicle);
92 93
    void _deleteVehiclePhase2(void);
    void _setActiveVehiclePhase2(void);
94
    void _autopilotParametersReadyChanged(bool parametersReady);
95
    void _sendGCSHeartbeat(void);
96
    void _vehicleHeartbeatInfo(LinkInterface* link, int vehicleId, int vehicleMavlinkVersion, int vehicleFirmwareType, int vehicleType);
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
Don Gagne's avatar
Don Gagne committed
104
    Vehicle*    _disconnectedVehicle;               ///< Disconnected vechicle for FactGroup access
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 116 117
    FirmwarePluginManager*      _firmwarePluginManager;
    AutoPilotPluginManager*     _autopilotPluginManager;
    JoystickManager*            _joystickManager;
    MAVLinkProtocol*            _mavlinkProtocol;

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