17 changed files with 344 additions and 66 deletions
@ -0,0 +1,66 @@
@@ -0,0 +1,66 @@
|
||||
/****************************************************************************
|
||||
* |
||||
* (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. |
||||
* |
||||
****************************************************************************/ |
||||
|
||||
#include "AirMapAdvisories.h" |
||||
#include "AirMapManager.h" |
||||
|
||||
#define ADVISORY_UPDATE_DISTANCE 500 //-- 500m threshold for updates
|
||||
|
||||
using namespace airmap; |
||||
|
||||
AirMapAdvisories::AirMapAdvisories(AirMapSharedState& shared, QObject *parent) |
||||
: AirspaceAdvisoryProvider(parent) |
||||
, _valid(false) |
||||
, _shared(shared) |
||||
{ |
||||
} |
||||
|
||||
void |
||||
AirMapAdvisories::setROI(const QGeoCoordinate& center, double radiusMeters) |
||||
{ |
||||
//-- If first time or we've moved more than ADVISORY_UPDATE_DISTANCE, ask for updates.
|
||||
if(!_lastRoiCenter.isValid() || _lastRoiCenter.distanceTo(center) > ADVISORY_UPDATE_DISTANCE) { |
||||
_lastRoiCenter = center; |
||||
_requestAdvisories(center, radiusMeters); |
||||
} |
||||
} |
||||
|
||||
void |
||||
AirMapAdvisories::_requestAdvisories(const QGeoCoordinate& coordinate, double radiusMeters) |
||||
{ |
||||
qCDebug(AirMapManagerLog) << "Advisories Request"; |
||||
if (!_shared.client()) { |
||||
qCDebug(AirMapManagerLog) << "No AirMap client instance. Not updating Advisories"; |
||||
_valid = false; |
||||
emit advisoryChanged(); |
||||
return; |
||||
} |
||||
_advisories.clear(); |
||||
_valid = false; |
||||
Status::GetStatus::Parameters params; |
||||
params.longitude = coordinate.longitude(); |
||||
params.latitude = coordinate.latitude(); |
||||
params.weather = false; |
||||
params.buffer = radiusMeters; |
||||
_shared.client()->status().get_status_by_point(params, [this, coordinate](const Status::GetStatus::Result& result) { |
||||
if (result) { |
||||
qCDebug(AirMapManagerLog) << _advisories.size() << "Advisories Received"; |
||||
_advisories = result.value().advisories; |
||||
_advisory_color = result.value().advisory_color; |
||||
if(_advisories.size()) { |
||||
_valid = true; |
||||
qCDebug(AirMapManagerLog) << "Advisory Info: " << _advisories.size() << _advisories[0].airspace.name().data(); |
||||
} |
||||
} else { |
||||
qCDebug(AirMapManagerLog) << "Advisories Request Failed"; |
||||
_valid = false; |
||||
} |
||||
emit advisoryChanged(); |
||||
}); |
||||
} |
@ -0,0 +1,48 @@
@@ -0,0 +1,48 @@
|
||||
/****************************************************************************
|
||||
* |
||||
* (c) 2017 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. |
||||
* |
||||
****************************************************************************/ |
||||
|
||||
#pragma once |
||||
|
||||
#include "LifetimeChecker.h" |
||||
|
||||
#include "AirspaceAdvisoryProvider.h" |
||||
#include "AirMapSharedState.h" |
||||
|
||||
#include <QGeoCoordinate> |
||||
|
||||
#include "airmap/status.h" |
||||
|
||||
/**
|
||||
* @file AirMapAdvisories.h |
||||
* Advisory information provided by AirMap. |
||||
*/ |
||||
|
||||
class AirMapAdvisories : public AirspaceAdvisoryProvider, public LifetimeChecker |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
AirMapAdvisories (AirMapSharedState &shared, QObject *parent = nullptr); |
||||
|
||||
bool valid () override { return _valid; } |
||||
|
||||
void setROI (const QGeoCoordinate& center, double radiusMeters) override; |
||||
|
||||
signals: |
||||
void error (const QString& what, const QString& airmapdMessage, const QString& airmapdDetails); |
||||
|
||||
private: |
||||
void _requestAdvisories (const QGeoCoordinate& coordinate, double radiusMeters); |
||||
|
||||
private: |
||||
bool _valid; |
||||
AirMapSharedState& _shared; |
||||
QGeoCoordinate _lastRoiCenter; |
||||
airmap::Status::Color _advisory_color; |
||||
std::vector<airmap::Status::Advisory> _advisories; |
||||
}; |
@ -0,0 +1,15 @@
@@ -0,0 +1,15 @@
|
||||
/****************************************************************************
|
||||
* |
||||
* (c) 2017 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 "AirspaceAdvisoryProvider.h" |
||||
|
||||
AirspaceAdvisoryProvider::AirspaceAdvisoryProvider(QObject *parent) |
||||
: QObject(parent) |
||||
{ |
||||
} |
@ -0,0 +1,39 @@
@@ -0,0 +1,39 @@
|
||||
/****************************************************************************
|
||||
* |
||||
* (c) 2017 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. |
||||
* |
||||
****************************************************************************/ |
||||
|
||||
#pragma once |
||||
|
||||
/**
|
||||
* @file AirspaceAdvisoryProvider.h |
||||
* Weather information provided by the Airspace Managemement |
||||
*/ |
||||
|
||||
#include <QObject> |
||||
#include <QGeoCoordinate> |
||||
|
||||
class AirspaceAdvisoryProvider : public QObject |
||||
{ |
||||
Q_OBJECT |
||||
public: |
||||
AirspaceAdvisoryProvider (QObject *parent = nullptr); |
||||
virtual ~AirspaceAdvisoryProvider () {} |
||||
|
||||
Q_PROPERTY(bool valid READ valid NOTIFY advisoryChanged) |
||||
|
||||
virtual bool valid () = 0; ///< Current data is valid
|
||||
|
||||
/**
|
||||
* Set region of interest that should be queried. When finished, the advisoryChanged() signal will be emmited. |
||||
* @param center Center coordinate for ROI |
||||
*/ |
||||
virtual void setROI (const QGeoCoordinate& center, double radiusMeters) = 0; |
||||
|
||||
signals: |
||||
void advisoryChanged (); |
||||
}; |
Loading…
Reference in new issue