refs #466 Added a weather service class for XBus.

This commit is contained in:
Mathew Sutcliffe
2015-09-22 20:12:21 +01:00
parent f757adbf5a
commit b489b888a3
8 changed files with 418 additions and 0 deletions

View File

@@ -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"

View File

@@ -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

View File

@@ -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<bool>(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);
}
}
}

View File

@@ -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

View File

@@ -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()

View File

@@ -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<CMenuItem> m_startServerMenuItems;

58
src/xbus/weather.cpp Normal file
View File

@@ -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 <QDebug>
namespace XBus
{
template <class T>
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 <class T>
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;
}
}
}

167
src/xbus/weather.h Normal file
View File

@@ -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 <QObject>
//! \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<xplane::data::sim::weather::use_real_weather_bool> m_useRealWeather;
DataRef<xplane::data::sim::weather::visibility_reported_m> m_visibilityM;
DataRef<xplane::data::sim::weather::rain_percent> m_precipRatio;
DataRef<xplane::data::sim::weather::thunderstorm_percent> m_cbRatio;
DataRef<xplane::data::sim::weather::wind_turbulence_percent> m_turbulenceRatio;
DataRef<xplane::data::sim::weather::temperature_sealevel_c> m_temperatureC;
DataRef<xplane::data::sim::weather::dewpoi_sealevel_c> m_dewPointC;
DataRef<xplane::data::sim::weather::barometer_sealevel_inhg> m_qnhInhg;
DataRef<xplane::data::sim::weather::runway_friction> m_runwayFriction;
struct
{
DataRef<xplane::data::sim::weather::cloud_base_msl_m_0> base;
DataRef<xplane::data::sim::weather::cloud_tops_msl_m_0> tops;
DataRef<xplane::data::sim::weather::cloud_type_0> type;
DataRef<xplane::data::sim::weather::cloud_coverage_0> coverage;
} m_cloudLayer0;
struct
{
DataRef<xplane::data::sim::weather::cloud_base_msl_m_1> base;
DataRef<xplane::data::sim::weather::cloud_tops_msl_m_1> tops;
DataRef<xplane::data::sim::weather::cloud_type_1> type;
DataRef<xplane::data::sim::weather::cloud_coverage_1> coverage;
} m_cloudLayer1;
struct
{
DataRef<xplane::data::sim::weather::cloud_base_msl_m_2> base;
DataRef<xplane::data::sim::weather::cloud_tops_msl_m_2> tops;
DataRef<xplane::data::sim::weather::cloud_type_2> type;
DataRef<xplane::data::sim::weather::cloud_coverage_2> coverage;
} m_cloudLayer2;
struct
{
DataRef<xplane::data::sim::weather::wind_altitude_msl_m_0> altitude;
DataRef<xplane::data::sim::weather::wind_direction_degt_0> direction;
DataRef<xplane::data::sim::weather::wind_speed_kt_0> speed;
DataRef<xplane::data::sim::weather::shear_direction_degt_0> shearDirection;
DataRef<xplane::data::sim::weather::shear_speed_kt_0> shearSpeed;
DataRef<xplane::data::sim::weather::turbulence_0> turbulence;
} m_windLayer0;
struct
{
DataRef<xplane::data::sim::weather::wind_altitude_msl_m_1> altitude;
DataRef<xplane::data::sim::weather::wind_direction_degt_1> direction;
DataRef<xplane::data::sim::weather::wind_speed_kt_1> speed;
DataRef<xplane::data::sim::weather::shear_direction_degt_1> shearDirection;
DataRef<xplane::data::sim::weather::shear_speed_kt_1> shearSpeed;
DataRef<xplane::data::sim::weather::turbulence_1> turbulence;
} m_windLayer1;
struct
{
DataRef<xplane::data::sim::weather::wind_altitude_msl_m_2> altitude;
DataRef<xplane::data::sim::weather::wind_direction_degt_2> direction;
DataRef<xplane::data::sim::weather::wind_speed_kt_2> speed;
DataRef<xplane::data::sim::weather::shear_direction_degt_2> shearDirection;
DataRef<xplane::data::sim::weather::shear_speed_kt_2> shearSpeed;
DataRef<xplane::data::sim::weather::turbulence_2> turbulence;
} m_windLayer2;
};
}
#endif // guard