AirMapVehicleManager.cc 2.94 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.
 *
 ****************************************************************************/
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 17
#include "Vehicle.h"

18 19
//-----------------------------------------------------------------------------
AirMapVehicleManager::AirMapVehicleManager(AirMapSharedState& shared, const Vehicle& vehicle)
20 21 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);
}

32
//-----------------------------------------------------------------------------
33 34 35
void
AirMapVehicleManager::startTelemetryStream()
{
36 37 38 39 40 41 42
    AirMapFlightPlanManager* planMgr = (AirMapFlightPlanManager*)qgcApp()->toolbox()->airspaceManager()->flightPlan();
    if (!planMgr->flightID().isEmpty()) {
        //-- 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)";
43 44 45
    }
}

46
//-----------------------------------------------------------------------------
47 48 49 50 51 52
void
AirMapVehicleManager::stopTelemetryStream()
{
    _telemetry.stopTelemetryStream();
}

53
//-----------------------------------------------------------------------------
54
bool
55
AirMapVehicleManager::isTelemetryStreaming()
56 57 58 59
{
    return _telemetry.isTelemetryStreaming();
}

60
//-----------------------------------------------------------------------------
61 62 63
void
AirMapVehicleManager::endFlight()
{
64 65 66
    AirMapFlightPlanManager* planMgr = (AirMapFlightPlanManager*)qgcApp()->toolbox()->airspaceManager()->flightPlan();
    if (!planMgr->flightID().isEmpty()) {
        _flightManager.endFlight(planMgr->flightID());
67
    }
68 69 70
    _trafficMonitor.stop();
}

71
//-----------------------------------------------------------------------------
72 73 74 75
void
AirMapVehicleManager::vehicleMavlinkMessageReceived(const mavlink_message_t& message)
{
    if (isTelemetryStreaming()) {
76
        _telemetry.vehicleMessageReceived(message);
77 78
    }
}