AirMapVehicleManager.cc 3.83 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9

10 11
#include "AirspaceFlightPlanProvider.h"
#include "AirMapFlightPlanManager.h"
12
#include "AirMapVehicleManager.h"
Gus Grubba's avatar
Gus Grubba committed
13
#include "AirMapManager.h"
14

15
#include "QGCApplication.h"
16
#include "Vehicle.h"
Gus Grubba's avatar
Gus Grubba committed
17 18
#include "QGCApplication.h"
#include "SettingsManager.h"
19

20 21
//-----------------------------------------------------------------------------
AirMapVehicleManager::AirMapVehicleManager(AirMapSharedState& shared, const Vehicle& vehicle)
22 23 24 25 26 27 28 29 30 31
    : 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);
Gus Grubba's avatar
Gus Grubba committed
32 33 34 35
    AirMapFlightPlanManager* planMgr = qobject_cast<AirMapFlightPlanManager*>(qgcApp()->toolbox()->airspaceManager()->flightPlan());
    if(planMgr) {
        connect(planMgr,      &AirMapFlightPlanManager::flightIDChanged,        this, &AirMapVehicleManager::_flightIDChanged);
    }
36 37
}

38
//-----------------------------------------------------------------------------
39 40 41
void
AirMapVehicleManager::startTelemetryStream()
{
Gus Grubba's avatar
Gus Grubba committed
42
    AirMapFlightPlanManager* planMgr = qobject_cast<AirMapFlightPlanManager*>(qgcApp()->toolbox()->airspaceManager()->flightPlan());
43
    if (!planMgr->flightID().isEmpty()) {
Gus Grubba's avatar
Gus Grubba committed
44 45 46 47 48 49
        //-- 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());
        }
50 51
    } else {
        qCDebug(AirMapManagerLog) << "AirMap telemetry stream not possible (No Flight ID)";
52 53 54
    }
}

55
//-----------------------------------------------------------------------------
56 57 58 59 60 61
void
AirMapVehicleManager::stopTelemetryStream()
{
    _telemetry.stopTelemetryStream();
}

62
//-----------------------------------------------------------------------------
63
bool
64
AirMapVehicleManager::isTelemetryStreaming()
65 66 67 68
{
    return _telemetry.isTelemetryStreaming();
}

69
//-----------------------------------------------------------------------------
70 71 72
void
AirMapVehicleManager::endFlight()
{
Gus Grubba's avatar
Gus Grubba committed
73
    AirMapFlightPlanManager* planMgr = qobject_cast<AirMapFlightPlanManager*>(qgcApp()->toolbox()->airspaceManager()->flightPlan());
74 75
    if (!planMgr->flightID().isEmpty()) {
        _flightManager.endFlight(planMgr->flightID());
76
    }
77 78 79
    _trafficMonitor.stop();
}

80
//-----------------------------------------------------------------------------
81 82 83 84
void
AirMapVehicleManager::vehicleMavlinkMessageReceived(const mavlink_message_t& message)
{
    if (isTelemetryStreaming()) {
85
        _telemetry.vehicleMessageReceived(message);
86 87
    }
}
Gus Grubba's avatar
Gus Grubba committed
88 89 90 91 92 93 94 95 96 97 98 99 100

//-----------------------------------------------------------------------------
void
AirMapVehicleManager::_flightIDChanged(QString flightID)
{
    qCDebug(AirMapManagerLog) << "Flight ID Changed:" << flightID;
    //-- Handle traffic monitor
    if(flightID.isEmpty()) {
        _trafficMonitor.stop();
    } else {
        _trafficMonitor.startConnection(flightID);
    }
}