Commit 34250f32 authored by Beat Küng's avatar Beat Küng

AirspaceManagement & AirMapManager: add weather request API

parent 0c575913
......@@ -903,6 +903,45 @@ void AirMapManager::_error(const QString& what, const QString& airmapdMessage, c
qCDebug(AirMapManagerLog) << "Caught error: "<<what<<", "<<airmapdMessage<<", "<<airmapdDetails;
}
void AirMapManager::requestWeatherUpdate(const QGeoCoordinate& coordinate)
{
if (!_shared.client()) {
qCDebug(AirMapManagerLog) << "No AirMap client instance. Not updating Weather information";
emit weatherUpdate(false, QGeoCoordinate{}, WeatherInformation{});
return;
}
Status::GetStatus::Parameters params;
params.longitude = coordinate.longitude();
params.latitude = coordinate.latitude();
params.weather = true;
_shared.client()->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";
......
......@@ -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);
......
......@@ -42,6 +42,7 @@ AirspaceManager::AirspaceManager(QGCApplication* app, QGCToolbox* toolbox)
_roiUpdateTimer.setSingleShot(true);
connect(&_roiUpdateTimer, &QTimer::timeout, this, &AirspaceManager::_updateToROI);
qmlRegisterUncreatableType<AirspaceAuthorization>("QGroundControl", 1, 0, "AirspaceAuthorization", "Reference only");
qRegisterMetaType<WeatherInformation>();
}
AirspaceManager::~AirspaceManager()
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment