MultiVehicleManager.h 5.84 KB
Newer Older
1
/*=====================================================================
dogmaphobic's avatar
dogmaphobic committed
2

3
 QGroundControl Open Source Ground Control Station
dogmaphobic's avatar
dogmaphobic committed
4

5
 (c) 2009 - 2014 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
dogmaphobic's avatar
dogmaphobic committed
6

7
 This file is part of the QGROUNDCONTROL project
dogmaphobic's avatar
dogmaphobic committed
8

9 10 11 12
 QGROUNDCONTROL is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.
dogmaphobic's avatar
dogmaphobic committed
13

14 15 16 17
 QGROUNDCONTROL is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
dogmaphobic's avatar
dogmaphobic committed
18

19 20
 You should have received a copy of the GNU General Public License
 along with QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.
dogmaphobic's avatar
dogmaphobic committed
21

22 23 24 25 26 27 28 29 30 31
 ======================================================================*/

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

#ifndef MultiVehicleManager_H
#define MultiVehicleManager_H

#include "Vehicle.h"
#include "QGCMAVLink.h"
32
#include "QmlObjectListModel.h"
33
#include "QGCToolbox.h"
Don Gagne's avatar
Don Gagne committed
34
#include "QGCLoggingCategory.h"
35

36 37
class FirmwarePluginManager;
class AutoPilotPluginManager;
Jimmy Johnson's avatar
Jimmy Johnson committed
38
class FollowMe;
39 40 41 42
class JoystickManager;
class QGCApplication;
class MAVLinkProtocol;

Don Gagne's avatar
Don Gagne committed
43 44
Q_DECLARE_LOGGING_CATEGORY(MultiVehicleManagerLog)

45
class MultiVehicleManager : public QGCTool
46 47
{
    Q_OBJECT
dogmaphobic's avatar
dogmaphobic committed
48

49
public:
50 51
    MultiVehicleManager(QGCApplication* app);

52 53
    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
54

55 56 57 58 59
    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
60

Don Gagne's avatar
Don Gagne committed
61 62 63
    /// A disconnected vehicle is used to access FactGroup information for the Vehicle object when no active vehicle is available
    Q_PROPERTY(Vehicle*             disconnectedVehicle             MEMBER _disconnectedVehicle                                         CONSTANT)

64
    // Methods
dogmaphobic's avatar
dogmaphobic committed
65

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

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

70
    // Property accessors
dogmaphobic's avatar
dogmaphobic committed
71

72
    bool activeVehicleAvailable(void) { return _activeVehicleAvailable; }
dogmaphobic's avatar
dogmaphobic committed
73

74
    bool parameterReadyVehicleAvailable(void) { return _parameterReadyVehicleAvailable; }
dogmaphobic's avatar
dogmaphobic committed
75

76 77
    Vehicle* activeVehicle(void) { return _activeVehicle; }
    void setActiveVehicle(Vehicle* vehicle);
dogmaphobic's avatar
dogmaphobic committed
78

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

81 82 83
    bool gcsHeartbeatEnabled(void) const { return _gcsHeartbeatEnabled; }
    void setGcsHeartbeatEnabled(bool gcsHeartBeatEnabled);

84 85 86 87 88 89
    /// 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);

90 91 92
    // Override from QGCTool
    virtual void setToolbox(QGCToolbox *toolbox);

93 94 95 96 97 98
signals:
    void vehicleAdded(Vehicle* vehicle);
    void vehicleRemoved(Vehicle* vehicle);
    void activeVehicleAvailableChanged(bool activeVehicleAvailable);
    void parameterReadyVehicleAvailableChanged(bool parameterReadyVehicleAvailable);
    void activeVehicleChanged(Vehicle* activeVehicle);
99
    void gcsHeartBeatEnabledChanged(bool gcsHeartBeatEnabled);
dogmaphobic's avatar
dogmaphobic committed
100

101
    void _deleteVehiclePhase2Signal(void);
dogmaphobic's avatar
dogmaphobic committed
102

103
private slots:
104
    void _deleteVehiclePhase1(Vehicle* vehicle);
105 106
    void _deleteVehiclePhase2(void);
    void _setActiveVehiclePhase2(void);
107
    void _autopilotParametersReadyChanged(bool parametersReady);
108
    void _sendGCSHeartbeat(void);
109
    void _vehicleHeartbeatInfo(LinkInterface* link, int vehicleId, int vehicleMavlinkVersion, int vehicleFirmwareType, int vehicleType);
dogmaphobic's avatar
dogmaphobic committed
110

111 112
private:
    bool _vehicleExists(int vehicleId);
dogmaphobic's avatar
dogmaphobic committed
113

114 115 116
    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
117
    Vehicle*    _disconnectedVehicle;               ///< Disconnected vechicle for FactGroup access
dogmaphobic's avatar
dogmaphobic committed
118

Don Gagne's avatar
Don Gagne committed
119 120
    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
121

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

124
    QmlObjectListModel  _vehicles;
125

dogmaphobic's avatar
dogmaphobic committed
126 127 128 129 130
    FirmwarePluginManager*      _firmwarePluginManager;
    AutoPilotPluginManager*     _autopilotPluginManager;
    JoystickManager*            _joystickManager;
    MAVLinkProtocol*            _mavlinkProtocol;

131 132 133 134
    QTimer              _gcsHeartbeatTimer;             ///< Timer to emit heartbeats
    bool                _gcsHeartbeatEnabled;           ///< Enabled/disable heartbeat emission
    static const int    _gcsHeartbeatRateMSecs = 1000;  ///< Heartbeat rate
    static const char*  _gcsHeartbeatEnabledKey;
135 136 137
};

#endif