From b489b888a3928a02df46c7792a6085477e13e215 Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Tue, 22 Sep 2015 20:12:21 +0100 Subject: [PATCH] refs #466 Added a weather service class for XBus. --- .../simulator/xplane/simulator_xplane.cpp | 1 + .../simulator/xplane/simulator_xplane.h | 2 + .../simulator/xplane/xbus_weather_proxy.cpp | 86 +++++++++ .../simulator/xplane/xbus_weather_proxy.h | 99 +++++++++++ src/xbus/plugin.cpp | 3 + src/xbus/plugin.h | 2 + src/xbus/weather.cpp | 58 ++++++ src/xbus/weather.h | 167 ++++++++++++++++++ 8 files changed, 418 insertions(+) create mode 100644 src/plugins/simulator/xplane/xbus_weather_proxy.cpp create mode 100644 src/plugins/simulator/xplane/xbus_weather_proxy.h create mode 100644 src/xbus/weather.cpp create mode 100644 src/xbus/weather.h diff --git a/src/plugins/simulator/xplane/simulator_xplane.cpp b/src/plugins/simulator/xplane/simulator_xplane.cpp index af1033858..06099dd02 100644 --- a/src/plugins/simulator/xplane/simulator_xplane.cpp +++ b/src/plugins/simulator/xplane/simulator_xplane.cpp @@ -10,6 +10,7 @@ #include "simulator_xplane.h" #include "xbus_service_proxy.h" #include "xbus_traffic_proxy.h" +#include "xbus_weather_proxy.h" #include "blackmisc/logmessage.h" #include "blackmisc/blackmiscfreefunctions.h" #include "blackmisc/simulation/modelmappingsprovider.h" diff --git a/src/plugins/simulator/xplane/simulator_xplane.h b/src/plugins/simulator/xplane/simulator_xplane.h index 93cef9103..e7adfd8c3 100644 --- a/src/plugins/simulator/xplane/simulator_xplane.h +++ b/src/plugins/simulator/xplane/simulator_xplane.h @@ -27,6 +27,7 @@ namespace BlackSimPlugin { class CXBusServiceProxy; class CXBusTrafficProxy; + class CXBusWeatherProxy; //! X-Plane ISimulator implementation class CSimulatorXPlane : public BlackCore::CSimulatorCommon @@ -135,6 +136,7 @@ namespace BlackSimPlugin QDBusServiceWatcher *m_watcher { nullptr }; CXBusServiceProxy *m_service { nullptr }; CXBusTrafficProxy *m_traffic { nullptr }; + CXBusWeatherProxy *m_weather { nullptr }; QTimer *m_fastTimer { nullptr }; QTimer *m_slowTimer { nullptr }; BlackMisc::Aviation::CAirportList m_airportsInRange; //!< aiports in range of own aircraft diff --git a/src/plugins/simulator/xplane/xbus_weather_proxy.cpp b/src/plugins/simulator/xplane/xbus_weather_proxy.cpp new file mode 100644 index 000000000..99c5ea918 --- /dev/null +++ b/src/plugins/simulator/xplane/xbus_weather_proxy.cpp @@ -0,0 +1,86 @@ +/* Copyright (C) 2015 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "xbus_weather_proxy.h" +#include "blackcore/dbus_server.h" + +#define XBUS_SERVICENAME "org.swift-project.xbus" + +namespace BlackSimPlugin +{ + namespace XPlane + { + + CXBusWeatherProxy::CXBusWeatherProxy(QDBusConnection &connection, QObject *parent) : QObject(parent) + { + m_dbusInterface = new BlackMisc::CGenericDBusInterface(XBUS_SERVICENAME, ObjectPath(), InterfaceName(), connection, this); + } + + bool CXBusWeatherProxy::isUsingRealWeather() const + { + return m_dbusInterface->callDBusRet(QLatin1String("isUsingRealWeather")); + } + + void CXBusWeatherProxy::setUseRealWeather(bool enable) + { + m_dbusInterface->callDBus(QLatin1String("setUseRealWeather"), enable); + } + + void CXBusWeatherProxy::setVisibility(float visibilityM) + { + m_dbusInterface->callDBus(QLatin1String("setVisibility"), visibilityM); + } + + void CXBusWeatherProxy::setTemperature(int degreesC) + { + m_dbusInterface->callDBus(QLatin1String("setTemperature"), degreesC); + } + + void CXBusWeatherProxy::setDewPoint(int degreesC) + { + m_dbusInterface->callDBus(QLatin1String("setDewPoint"), degreesC); + } + + void CXBusWeatherProxy::setQNH(float inHg) + { + m_dbusInterface->callDBus(QLatin1String("setQNH"), inHg); + } + + void CXBusWeatherProxy::setPrecipitationRatio(float precipRatio) + { + m_dbusInterface->callDBus(QLatin1String("setPrecipitationRatio"), precipRatio); + } + + void CXBusWeatherProxy::setThunderstormRatio(float cbRatio) + { + m_dbusInterface->callDBus(QLatin1String("setThunderstormRatio"), cbRatio); + } + + void CXBusWeatherProxy::setTurbulenceRatio(float turbulenceRatio) + { + m_dbusInterface->callDBus(QLatin1String("setTurbulenceRatio"), turbulenceRatio); + } + + void CXBusWeatherProxy::setRunwayFriction(int friction) + { + m_dbusInterface->callDBus(QLatin1String("setRunwayFriction"), friction); + } + + void CXBusWeatherProxy::setCloudLayer(int layer, int base, int tops, int type, int coverage) + { + m_dbusInterface->callDBus(QLatin1String("setCloudLayer"), layer, base, tops, type, coverage); + } + + void CXBusWeatherProxy::setWindLayer(int layer, int altitude, float direction, int speed, int shearDirection, int shearSpeed, int turbulence) + { + m_dbusInterface->callDBus(QLatin1String("setWindLayer"), layer, altitude, direction, speed, shearDirection, shearSpeed, turbulence); + } + + } +} diff --git a/src/plugins/simulator/xplane/xbus_weather_proxy.h b/src/plugins/simulator/xplane/xbus_weather_proxy.h new file mode 100644 index 000000000..7c03e37b6 --- /dev/null +++ b/src/plugins/simulator/xplane/xbus_weather_proxy.h @@ -0,0 +1,99 @@ +/* Copyright (C) 2015 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#ifndef BLACKSIMPLUGIN_XBUS_WEATHER_PROXY_H +#define BLACKSIMPLUGIN_XBUS_WEATHER_PROXY_H + +//! \file + +#include "blackmisc/genericdbusinterface.h" + +//! \cond PRIVATE +#define XBUS_WEATHER_INTERFACENAME "org.swift_project.xbus.weather" +#define XBUS_WEATHER_OBJECTPATH "/xbus" +//! \endcond + +namespace BlackSimPlugin +{ + namespace XPlane + { + + /*! + * Proxy object connected to a real XBus::CWeather object via DBus + */ + class CXBusWeatherProxy : public QObject + { + Q_OBJECT + + public: + //! Service name + static const QString &InterfaceName() + { + static QString s(XBUS_WEATHER_INTERFACENAME); + return s; + } + + //! Service path + static const QString &ObjectPath() + { + static QString s(XBUS_WEATHER_OBJECTPATH); + return s; + } + + //! Constructor + CXBusWeatherProxy(QDBusConnection &connection, QObject *parent = nullptr); + + //! Does the remote object exist? + bool isValid() const { return m_dbusInterface->isValid(); } + + private: + BlackMisc::CGenericDBusInterface *m_dbusInterface = nullptr; + + public slots: + //! \copydoc XBus::CWeather::isUsingRealWeather + bool isUsingRealWeather() const; + + //! \copydoc XBus::CWeather::setUseRealWeather + void setUseRealWeather(bool enable); + + //! \copydoc XBus::CWeather::setVisibility + void setVisibility(float visibilityM); + + //! \copydoc XBus::CWeather::setTemperature + void setTemperature(int degreesC); + + //! \copydoc XBus::CWeather::setDewPoint + void setDewPoint(int degreesC); + + //! \copydoc XBus::CWeather::setQNH + void setQNH(float inHg); + + //! \copydoc XBus::CWeather::setPrecipitationRatio + void setPrecipitationRatio(float precipRatio); + + //! \copydoc XBus::CWeather::setThunderstormRatio + void setThunderstormRatio(float cbRatio); + + //! \copydoc XBus::CWeather::setTurbulenceRatio + void setTurbulenceRatio(float turbulenceRatio); + + //! \copydoc XBus::CWeather::setRunwayFriction + void setRunwayFriction(int friction); + + //! \copydoc XBus::CWeather::setCloudLayer + void setCloudLayer(int layer, int base, int tops, int type, int coverage); + + //! \copydoc XBus::CWeather::setWindLayer + void setWindLayer(int layer, int altitude, float direction, int speed, int shearDirection, int shearSpeed, int turbulence); + }; + + } +} + +#endif // guard diff --git a/src/xbus/plugin.cpp b/src/xbus/plugin.cpp index 31ba04d5b..b3a202466 100644 --- a/src/xbus/plugin.cpp +++ b/src/xbus/plugin.cpp @@ -6,6 +6,7 @@ #include "plugin.h" #include "service.h" #include "traffic.h" +#include "weather.h" namespace { inline QString xbusServiceName() { @@ -32,8 +33,10 @@ namespace XBus m_server = new BlackCore::CDBusServer(xbusServiceName(), address, this); m_service = new CService(this); m_traffic = new CTraffic(this); + m_weather = new CWeather(this); m_server->addObject(CService::ObjectPath(), m_service); m_server->addObject(CTraffic::ObjectPath(), m_traffic); + m_server->addObject(CWeather::ObjectPath(), m_weather); } void CPlugin::onAircraftModelChanged() diff --git a/src/xbus/plugin.h b/src/xbus/plugin.h index 2a45ef93f..945891e4b 100644 --- a/src/xbus/plugin.h +++ b/src/xbus/plugin.h @@ -29,6 +29,7 @@ namespace XBus { class CService; class CTraffic; + class CWeather; /*! * Main plugin class @@ -51,6 +52,7 @@ namespace XBus BlackCore::CDBusServer *m_server = nullptr; CService *m_service = nullptr; CTraffic *m_traffic = nullptr; + CWeather *m_weather = nullptr; CMenu m_menu; QVector m_startServerMenuItems; diff --git a/src/xbus/weather.cpp b/src/xbus/weather.cpp new file mode 100644 index 000000000..1db2ec641 --- /dev/null +++ b/src/xbus/weather.cpp @@ -0,0 +1,58 @@ +/* Copyright (C) 2015 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "weather.h" +#include + +namespace XBus +{ + + template + void setCloudLayerImpl(T &layer, int base, int tops, int type, int coverage) + { + layer.base.set(base); + layer.tops.set(tops); + layer.type.set(type); + layer.coverage.set(coverage); + } + + void CWeather::setCloudLayer(int layer, int base, int tops, int type, int coverage) + { + switch (layer) + { + case 0: setCloudLayerImpl(m_cloudLayer0, base, tops, type, coverage); break; + case 1: setCloudLayerImpl(m_cloudLayer1, base, tops, type, coverage); break; + case 2: setCloudLayerImpl(m_cloudLayer2, base, tops, type, coverage); break; + default: qDebug() << "Invalid cloud layer" << layer; break; + } + } + + template + void setWindLayerImpl(T &layer, int altitude, float direction, int speed, int shearDirection, int shearSpeed, int turbulence) + { + layer.altitude.set(altitude); + layer.direction.set(direction); + layer.speed.set(speed); + layer.shearDirection.set(shearDirection); + layer.shearSpeed.set(shearSpeed); + layer.turbulence.set(turbulence); + } + + void CWeather::setWindLayer(int layer, int altitude, float direction, int speed, int shearDirection, int shearSpeed, int turbulence) + { + switch (layer) + { + case 0: setWindLayerImpl(m_windLayer0, altitude, direction, speed, shearDirection, shearSpeed, turbulence); break; + case 1: setWindLayerImpl(m_windLayer1, altitude, direction, speed, shearDirection, shearSpeed, turbulence); break; + case 2: setWindLayerImpl(m_windLayer2, altitude, direction, speed, shearDirection, shearSpeed, turbulence); break; + default: qDebug() << "Invalid wind layer" << layer; break; + } + } + +} diff --git a/src/xbus/weather.h b/src/xbus/weather.h new file mode 100644 index 000000000..e1e6b739a --- /dev/null +++ b/src/xbus/weather.h @@ -0,0 +1,167 @@ +/* Copyright (C) 2015 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#ifndef BLACKSIM_XBUS_WEATHER_H +#define BLACKSIM_XBUS_WEATHER_H + +//! \file + +#ifndef NOMINMAX +#define NOMINMAX +#endif +#include "datarefs.h" +#include + +//! \cond PRIVATE +#define XBUS_WEATHER_INTERFACENAME "org.swift_project.xbus.weather" +#define XBUS_WEATHER_OBJECTPATH "/xbus" +//! \endcond + +namespace XBus +{ + + /*! + * XBus weather object which is accessible through DBus + */ + class CWeather : public QObject + { + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", XBUS_WEATHER_INTERFACENAME) + + public: + //! Constructor + CWeather(QObject *parent) : QObject(parent) {} + + //! DBus interface name + static const QString &InterfaceName() + { + static QString s(XBUS_WEATHER_INTERFACENAME); + return s; + } + + //! DBus object path + static const QString &ObjectPath() + { + static QString s(XBUS_WEATHER_OBJECTPATH); + return s; + } + + public slots: + //! True if the sim is using X-Plane built-in real weather source. + bool isUsingRealWeather() const { return m_useRealWeather.get(); } + + //! Set whether or not to use X-Plane built-in real weather source. + void setUseRealWeather(bool enable) { m_useRealWeather.set(enable ? 1 : 0); } + + //! Set reported visibility in meters. + void setVisibility(float visibilityM) { m_visibilityM.set(visibilityM); } + + //! Set temperature at sea level in degrees C. + void setTemperature(int degreesC) { m_temperatureC.set(degreesC); } + + //! Set dew point at sea level in degrees C. + void setDewPoint(int degreesC) { m_dewPointC.set(degreesC); } + + //! Set barometric pressure at sea level in inches of mercury. + void setQNH(float inHg) { m_qnhInhg.set(inHg); } + + //! Set amount of precipitation between 0 and 1. + void setPrecipitationRatio(float precipRatio) { m_precipRatio.set(precipRatio); } + + //! Set amount of thunderstorms between 0 and 1. + void setThunderstormRatio(float cbRatio) { m_cbRatio.set(cbRatio); } + + //! Set amount of turbulence between 0 and 1. + void setTurbulenceRatio(float turbulenceRatio) { m_turbulenceRatio.set(turbulenceRatio); } + + //! Set runway friction, 0=dry, 1=damp, 2=wet. + void setRunwayFriction(int friction) { m_runwayFriction.set(friction); } + + //! Set a cloud layer. + //! \param layer Layer 0, 1, or 2. + //! \param base Cloud base in meters above mean sea level. + //! \param tops Cloud tops in meters above mean sea level. + //! \param type Type of cloud: 0=clear, 1=cirrus, 2=scattered, 3=broken, 4=overcast, 5=stratus. + //! \param coverage Amount of sky covered [0,6]. + void setCloudLayer(int layer, int base, int tops, int type, int coverage); + + //! Set a wind layer. + //! \param layer Layer 0, 1, or 2. + //! \param altitude Altitude in middle of layer in meters above mean sea level. + //! \param direction Direction from which wind is blowing in degrees true. + //! \param speed Wind speed in knots. + //! \param shearDirection Direction from which wind shears blow in degrees true. + //! \param shearSpeed Wind speed gain in knots (e.g. speed=10 and shearSpeed=5 means speed varies between 10 and 15). + //! \param turbulence Amount of turbulence [0,10]. + void setWindLayer(int layer, int altitude, float direction, int speed, int shearDirection, int shearSpeed, int turbulence); + + private: + DataRef m_useRealWeather; + DataRef m_visibilityM; + DataRef m_precipRatio; + DataRef m_cbRatio; + DataRef m_turbulenceRatio; + DataRef m_temperatureC; + DataRef m_dewPointC; + DataRef m_qnhInhg; + DataRef m_runwayFriction; + struct + { + DataRef base; + DataRef tops; + DataRef type; + DataRef coverage; + } m_cloudLayer0; + struct + { + DataRef base; + DataRef tops; + DataRef type; + DataRef coverage; + } m_cloudLayer1; + struct + { + DataRef base; + DataRef tops; + DataRef type; + DataRef coverage; + } m_cloudLayer2; + struct + { + DataRef altitude; + DataRef direction; + DataRef speed; + DataRef shearDirection; + DataRef shearSpeed; + DataRef turbulence; + } m_windLayer0; + struct + { + DataRef altitude; + DataRef direction; + DataRef speed; + DataRef shearDirection; + DataRef shearSpeed; + DataRef turbulence; + } m_windLayer1; + struct + { + DataRef altitude; + DataRef direction; + DataRef speed; + DataRef shearDirection; + DataRef shearSpeed; + DataRef turbulence; + } m_windLayer2; + }; + +} + +#endif // guard +