1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/****************************************************************************
*
* (c) 2009-2020 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.
*
****************************************************************************/
#include "AirspaceFlightPlanProvider.h"
#include "AirMapFlightPlanManager.h"
#include "AirMapVehicleManager.h"
#include "AirMapManager.h"
#include "QGCApplication.h"
#include "Vehicle.h"
#include "QGCApplication.h"
#include "SettingsManager.h"
//-----------------------------------------------------------------------------
AirMapVehicleManager::AirMapVehicleManager(AirMapSharedState& shared, const Vehicle& vehicle)
: AirspaceVehicleManager(vehicle)
, _shared(shared)
, _flightManager(shared)
, _telemetry(shared)
, _trafficMonitor(shared)
{
connect(&_flightManager, &AirMapFlightManager::error, this, &AirMapVehicleManager::error);
connect(&_telemetry, &AirMapTelemetry::error, this, &AirMapVehicleManager::error);
connect(&_trafficMonitor, &AirMapTrafficMonitor::error, this, &AirMapVehicleManager::error);
connect(&_trafficMonitor, &AirMapTrafficMonitor::trafficUpdate, this, &AirspaceVehicleManager::trafficUpdate);
AirMapFlightPlanManager* planMgr = qobject_cast<AirMapFlightPlanManager*>(qgcApp()->toolbox()->airspaceManager()->flightPlan());
if(planMgr) {
connect(planMgr, &AirMapFlightPlanManager::flightIDChanged, this, &AirMapVehicleManager::_flightIDChanged);
}
}
//-----------------------------------------------------------------------------
void
AirMapVehicleManager::startTelemetryStream()
{
AirMapFlightPlanManager* planMgr = qobject_cast<AirMapFlightPlanManager*>(qgcApp()->toolbox()->airspaceManager()->flightPlan());
if (!planMgr->flightID().isEmpty()) {
//-- Is telemetry enabled?
if(qgcApp()->toolbox()->settingsManager()->airMapSettings()->enableTelemetry()->rawValue().toBool()) {
//-- TODO: This will start telemetry using the current flight ID in memory (current flight in AirMapFlightPlanManager)
qCDebug(AirMapManagerLog) << "AirMap telemetry stream enabled";
_telemetry.startTelemetryStream(planMgr->flightID());
}
} else {
qCDebug(AirMapManagerLog) << "AirMap telemetry stream not possible (No Flight ID)";
}
}
//-----------------------------------------------------------------------------
void
AirMapVehicleManager::stopTelemetryStream()
{
_telemetry.stopTelemetryStream();
}
//-----------------------------------------------------------------------------
bool
AirMapVehicleManager::isTelemetryStreaming()
{
return _telemetry.isTelemetryStreaming();
}
//-----------------------------------------------------------------------------
void
AirMapVehicleManager::endFlight()
{
AirMapFlightPlanManager* planMgr = qobject_cast<AirMapFlightPlanManager*>(qgcApp()->toolbox()->airspaceManager()->flightPlan());
if (!planMgr->flightID().isEmpty()) {
_flightManager.endFlight(planMgr->flightID());
}
_trafficMonitor.stop();
}
//-----------------------------------------------------------------------------
void
AirMapVehicleManager::vehicleMavlinkMessageReceived(const mavlink_message_t& message)
{
if (isTelemetryStreaming()) {
_telemetry.vehicleMessageReceived(message);
}
}
//-----------------------------------------------------------------------------
void
AirMapVehicleManager::_flightIDChanged(QString flightID)
{
qCDebug(AirMapManagerLog) << "Flight ID Changed:" << flightID;
//-- Handle traffic monitor
if(flightID.isEmpty()) {
_trafficMonitor.stop();
} else {
_trafficMonitor.startConnection(flightID);
}
}