AirMapVehicleManager.cc 2.92 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

#include "AirMapVehicleManager.h"
Gus Grubba's avatar
Gus Grubba committed
11
#include "AirMapManager.h"
12

13 14
#include "Vehicle.h"

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
AirMapVehicleManager::AirMapVehicleManager(AirMapSharedState& shared, const Vehicle& vehicle, QGCToolbox& toolbox)
    : AirspaceVehicleManager(vehicle)
    , _shared(shared)
    , _flightManager(shared)
    , _telemetry(shared)
    , _trafficMonitor(shared)
    , _toolbox(toolbox)
{
    connect(&_flightManager,  &AirMapFlightManager::flightPermitStatusChanged,  this, &AirMapVehicleManager::flightPermitStatusChanged);
    connect(&_flightManager,  &AirMapFlightManager::flightPermitStatusChanged,  this, &AirMapVehicleManager::_flightPermitStatusChanged);
    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);
}

void
AirMapVehicleManager::createFlight(const QList<MissionItem*>& missionItems)
{
    if (!_shared.client()) {
        qCDebug(AirMapManagerLog) << "No AirMap client instance. Will not create a flight";
        return;
    }
    _flightManager.createFlight(missionItems);
}

Gus Grubba's avatar
Gus Grubba committed
41
AirspaceFlightPlanProvider::PermitStatus
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
AirMapVehicleManager::flightPermitStatus() const
{
    return _flightManager.flightPermitStatus();
}

void
AirMapVehicleManager::startTelemetryStream()
{
    if (_flightManager.flightID() != "") {
        _telemetry.startTelemetryStream(_flightManager.flightID());
    }
}

void
AirMapVehicleManager::stopTelemetryStream()
{
    _telemetry.stopTelemetryStream();
}

bool
AirMapVehicleManager::isTelemetryStreaming() const
{
    return _telemetry.isTelemetryStreaming();
}

void
AirMapVehicleManager::endFlight()
{
    _flightManager.endFlight();
    _trafficMonitor.stop();
}

void
AirMapVehicleManager::vehicleMavlinkMessageReceived(const mavlink_message_t& message)
{
    if (isTelemetryStreaming()) {
        _telemetry.vehicleMavlinkMessageReceived(message);
    }
}

void
AirMapVehicleManager::_flightPermitStatusChanged()
{
    // activate traffic alerts
Gus Grubba's avatar
Gus Grubba committed
86
    if (_flightManager.flightPermitStatus() == AirspaceFlightPlanProvider::PermitAccepted) {
87 88 89 90 91 92
        qCDebug(AirMapManagerLog) << "Subscribing to Traffic Alerts";
        // since we already created the flight, we know that we have a valid login token
        _trafficMonitor.startConnection(_flightManager.flightID());
    }
}