MultiVehicleManager.h 5.25 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 37
    MultiVehicleManager(QGCApplication* app);

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
    // Methods
dogmaphobic's avatar
dogmaphobic committed
51

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

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

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

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

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

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

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

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

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

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

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

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

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

91
private slots:
92
    void _deleteVehiclePhase1(Vehicle* vehicle);
93 94
    void _deleteVehiclePhase2(void);
    void _setActiveVehiclePhase2(void);
95
    void _vehicleParametersReadyChanged(bool parametersReady);
96
    void _sendGCSHeartbeat(void);
97
    void _vehicleHeartbeatInfo(LinkInterface* link, int vehicleId, int componentId, int vehicleMavlinkVersion, int vehicleFirmwareType, int vehicleType);
dogmaphobic's avatar
dogmaphobic committed
98

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

102 103 104
    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
105
    Vehicle*    _offlineEditingVehicle;             ///< Disconnected vechicle used for offline editing
dogmaphobic's avatar
dogmaphobic committed
106

Don Gagne's avatar
Don Gagne committed
107 108
    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
109

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

112
    QmlObjectListModel  _vehicles;
113

dogmaphobic's avatar
dogmaphobic committed
114 115 116 117
    FirmwarePluginManager*      _firmwarePluginManager;
    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