From 34250f32df473397575d774e0c4dc43dab6ac8f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beat=20K=C3=BCng?= Date: Fri, 10 Nov 2017 17:09:22 +0100 Subject: [PATCH] AirspaceManagement & AirMapManager: add weather request API --- src/MissionManager/AirMapManager.cc | 39 ++++++++++++++++++++++++ src/MissionManager/AirMapManager.h | 2 ++ src/MissionManager/AirspaceManagement.cc | 1 + src/MissionManager/AirspaceManagement.h | 23 ++++++++++++++ 4 files changed, 65 insertions(+) diff --git a/src/MissionManager/AirMapManager.cc b/src/MissionManager/AirMapManager.cc index c82995a72..c6677ebac 100644 --- a/src/MissionManager/AirMapManager.cc +++ b/src/MissionManager/AirMapManager.cc @@ -903,6 +903,45 @@ void AirMapManager::_error(const QString& what, const QString& airmapdMessage, c qCDebug(AirMapManagerLog) << "Caught error: "<status().get_status_by_point(params, [this, coordinate](const Status::GetStatus::Result& result) { + + if (result) { + + const Status::Weather& weather = result.value().weather; + WeatherInformation weatherUpdateInfo; + + weatherUpdateInfo.condition = QString::fromStdString(weather.condition); + weatherUpdateInfo.icon = QString::fromStdString(weather.icon); + weatherUpdateInfo.windHeading = weather.wind.heading; + weatherUpdateInfo.windSpeed = weather.wind.speed; + weatherUpdateInfo.windGusting = weather.wind.gusting; + weatherUpdateInfo.temperature = weather.temperature; + weatherUpdateInfo.humidity = weather.humidity; + weatherUpdateInfo.visibility = weather.visibility; + weatherUpdateInfo.precipitation = weather.precipitation; + emit weatherUpdate(true, coordinate, weatherUpdateInfo); + + } else { + // TODO: error handling + emit weatherUpdate(false, coordinate, WeatherInformation{}); + } + }); + +} + void AirMapManager::_settingsChanged() { qCDebug(AirMapManagerLog) << "AirMap settings changed"; diff --git a/src/MissionManager/AirMapManager.h b/src/MissionManager/AirMapManager.h index 02363352b..d341879eb 100644 --- a/src/MissionManager/AirMapManager.h +++ b/src/MissionManager/AirMapManager.h @@ -349,6 +349,8 @@ public: QString name() const override { return "AirMap"; } + void requestWeatherUpdate(const QGeoCoordinate& coordinate) override; + private slots: void _error(const QString& what, const QString& airmapdMessage, const QString& airmapdDetails); diff --git a/src/MissionManager/AirspaceManagement.cc b/src/MissionManager/AirspaceManagement.cc index ab43a785e..6b0aa1d9d 100644 --- a/src/MissionManager/AirspaceManagement.cc +++ b/src/MissionManager/AirspaceManagement.cc @@ -42,6 +42,7 @@ AirspaceManager::AirspaceManager(QGCApplication* app, QGCToolbox* toolbox) _roiUpdateTimer.setSingleShot(true); connect(&_roiUpdateTimer, &QTimer::timeout, this, &AirspaceManager::_updateToROI); qmlRegisterUncreatableType("QGroundControl", 1, 0, "AirspaceAuthorization", "Reference only"); + qRegisterMetaType(); } AirspaceManager::~AirspaceManager() diff --git a/src/MissionManager/AirspaceManagement.h b/src/MissionManager/AirspaceManagement.h index 9c3eb2b4e..1a17b6ec4 100644 --- a/src/MissionManager/AirspaceManagement.h +++ b/src/MissionManager/AirspaceManagement.h @@ -123,6 +123,20 @@ protected: class AirspaceManagerPerVehicle; class Vehicle; +struct WeatherInformation +{ + QString condition; ///< The overall weather condition. + QString icon; ///< The icon or class of icon that should be used for display purposes. + uint32_t windHeading = 0; ///< The heading in [°]. + uint32_t windSpeed = 0; ///< The speed in [°]. + uint32_t windGusting = 0; + int32_t temperature = 0; ///< The temperature in [°C]. + float humidity = 0.0; + uint32_t visibility = 0; ///< Visibility in [m]. + uint32_t precipitation = 0; ///< The probability of precipitation in [%]. +}; +Q_DECLARE_METATYPE(WeatherInformation); + /** * @class AirspaceManager * Base class for airspace management. There is one (global) instantiation of this @@ -161,6 +175,15 @@ public: */ virtual QString name() const = 0; + /** + * Request weather information update. When done, it will emit the weatherUpdate() signal. + * @param coordinate request update for this coordinate + */ + virtual void requestWeatherUpdate(const QGeoCoordinate& coordinate) = 0; + +signals: + void weatherUpdate(bool success, QGeoCoordinate coordinate, WeatherInformation weather); + private slots: void _restrictionsUpdated(bool success); -- GitLab