Removing weather module for FG

This commit is contained in:
Lars Toenning
2019-02-27 14:46:51 +01:00
committed by Mat Sutcliffe
parent 43563496aa
commit d4581a5b74
4 changed files with 3 additions and 310 deletions

View File

@@ -1,88 +0,0 @@
/* Copyright (C) 2019
* 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. 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 "fgswiftbusweatherproxy.h"
#include <QLatin1String>
class QDBusConnection;
#define XSWIFTBUS_SERVICENAME "org.swift-project.xswiftbus"
namespace BlackSimPlugin
{
namespace XPlane
{
CXSwiftBusWeatherProxy::CXSwiftBusWeatherProxy(QDBusConnection &connection, QObject *parent) : QObject(parent)
{
m_dbusInterface = new BlackMisc::CGenericDBusInterface(XSWIFTBUS_SERVICENAME, ObjectPath(), InterfaceName(), connection, this);
}
bool CXSwiftBusWeatherProxy::isUsingRealWeather() const
{
return m_dbusInterface->callDBusRet<bool>(QLatin1String("isUsingRealWeather"));
}
void CXSwiftBusWeatherProxy::setUseRealWeather(bool enable)
{
m_dbusInterface->callDBus(QLatin1String("setUseRealWeather"), enable);
}
void CXSwiftBusWeatherProxy::setVisibility(double visibilityM)
{
m_dbusInterface->callDBus(QLatin1String("setVisibility"), visibilityM);
}
void CXSwiftBusWeatherProxy::setTemperature(int degreesC)
{
m_dbusInterface->callDBus(QLatin1String("setTemperature"), degreesC);
}
void CXSwiftBusWeatherProxy::setDewPoint(int degreesC)
{
m_dbusInterface->callDBus(QLatin1String("setDewPoint"), degreesC);
}
void CXSwiftBusWeatherProxy::setQNH(double inHg)
{
m_dbusInterface->callDBus(QLatin1String("setQNH"), inHg);
}
void CXSwiftBusWeatherProxy::setPrecipitationRatio(double precipRatio)
{
m_dbusInterface->callDBus(QLatin1String("setPrecipitationRatio"), precipRatio);
}
void CXSwiftBusWeatherProxy::setThunderstormRatio(double cbRatio)
{
m_dbusInterface->callDBus(QLatin1String("setThunderstormRatio"), cbRatio);
}
void CXSwiftBusWeatherProxy::setTurbulenceRatio(double turbulenceRatio)
{
m_dbusInterface->callDBus(QLatin1String("setTurbulenceRatio"), turbulenceRatio);
}
void CXSwiftBusWeatherProxy::setRunwayFriction(int friction)
{
m_dbusInterface->callDBus(QLatin1String("setRunwayFriction"), friction);
}
void CXSwiftBusWeatherProxy::setCloudLayer(int layer, int baseM, int topsM, int type, int coverage)
{
m_dbusInterface->callDBus(QLatin1String("setCloudLayer"), layer, baseM, topsM, type, coverage);
}
void CXSwiftBusWeatherProxy::setWindLayer(int layer, int altitudeM, double directionDeg, int speedKt, int shearDirectionDeg, int shearSpeedKt, int turbulence)
{
m_dbusInterface->callDBus(QLatin1String("setWindLayer"), layer, altitudeM, directionDeg, speedKt, shearDirectionDeg, shearSpeedKt, turbulence);
}
}
}

View File

@@ -1,105 +0,0 @@
/* Copyright (C) 2019
* 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. 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.
*/
//! \file
#ifndef BLACKSIMPLUGIN_XSWIFTBUS_WEATHER_PROXY_H
#define BLACKSIMPLUGIN_XSWIFTBUS_WEATHER_PROXY_H
#include "blackmisc/genericdbusinterface.h"
#include <QObject>
#include <QString>
// clazy:excludeall=const-signal-or-slot
class QDBusConnection;
//! \cond PRIVATE
#define XSWIFTBUS_WEATHER_INTERFACENAME "org.swift_project.xswiftbus.weather"
#define XSWIFTBUS_WEATHER_OBJECTPATH "/xswiftbus/weather"
//! \endcond
namespace BlackSimPlugin
{
namespace XPlane
{
/*!
* Proxy object connected to a real XSwiftBus::CWeather object via DBus
*/
class CXSwiftBusWeatherProxy : public QObject
{
Q_OBJECT
public:
//! Service name
static const QString &InterfaceName()
{
static QString s(XSWIFTBUS_WEATHER_INTERFACENAME);
return s;
}
//! Service path
static const QString &ObjectPath()
{
static QString s(XSWIFTBUS_WEATHER_OBJECTPATH);
return s;
}
//! Constructor
CXSwiftBusWeatherProxy(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 XSwiftBus::CWeather::isUsingRealWeather
bool isUsingRealWeather() const;
//! \copydoc XSwiftBus::CWeather::setUseRealWeather
void setUseRealWeather(bool enable);
//! \copydoc XSwiftBus::CWeather::setVisibility
void setVisibility(double visibilityM);
//! \copydoc XSwiftBus::CWeather::setTemperature
void setTemperature(int degreesC);
//! \copydoc XSwiftBus::CWeather::setDewPoint
void setDewPoint(int degreesC);
//! \copydoc XSwiftBus::CWeather::setQNH
void setQNH(double inHg);
//! \copydoc XSwiftBus::CWeather::setPrecipitationRatio
void setPrecipitationRatio(double precipRatio);
//! \copydoc XSwiftBus::CWeather::setThunderstormRatio
void setThunderstormRatio(double cbRatio);
//! \copydoc XSwiftBus::CWeather::setTurbulenceRatio
void setTurbulenceRatio(double turbulenceRatio);
//! \copydoc XSwiftBus::CWeather::setRunwayFriction
void setRunwayFriction(int friction);
//! \copydoc XSwiftBus::CWeather::setCloudLayer
void setCloudLayer(int layer, int baseM, int topsM, int type, int coverage);
//! \copydoc XSwiftBus::CWeather::setWindLayer
void setWindLayer(int layer, int altitudeM, double directionDeg, int speedKt, int shearDirectionDeg, int shearSpeedKt, int turbulence);
};
}
}
#endif // guard

View File

@@ -10,7 +10,6 @@
#include "qcompilerdetection.h"
#include "fgswiftbusserviceproxy.h"
#include "fgswiftbustrafficproxy.h"
#include "fgswiftbusweatherproxy.h"
#include "blackcore/aircraftmatcher.h"
#include "blackmisc/simulation/aircraftmodel.h"
#include "blackmisc/simulation/simulatedaircraft.h"
@@ -253,21 +252,6 @@ namespace BlackSimPlugin
{
this->updateCockpit(com1, com2, transponder, identifier());
}
if (m_isWeatherActivated)
{
const auto currentPosition = CCoordinateGeodetic { situation.latitude(), situation.longitude() };
if (CWeatherScenario::isRealWeatherScenario(m_weatherScenarioSettings.get()))
{
if (m_lastWeatherPosition.isNull() ||
calculateGreatCircleDistance(m_lastWeatherPosition, currentPosition).value(CLengthUnit::mi()) > 20)
{
m_lastWeatherPosition = currentPosition;
const auto weatherGrid = CWeatherGrid { { "GLOB", currentPosition } };
requestWeatherGrid(weatherGrid, { this, &CSimulatorXPlane::injectWeatherGrid });
}
}
}
}
}
@@ -318,7 +302,7 @@ namespace BlackSimPlugin
bool CSimulatorXPlane::isConnected() const
{
return m_serviceProxy && m_trafficProxy && m_weatherProxy;
return m_serviceProxy && m_trafficProxy;
}
bool CSimulatorXPlane::connectTo()
@@ -340,12 +324,11 @@ namespace BlackSimPlugin
m_serviceProxy = new CXSwiftBusServiceProxy(m_dBusConnection, this);
m_trafficProxy = new CXSwiftBusTrafficProxy(m_dBusConnection, this);
m_weatherProxy = new CXSwiftBusWeatherProxy(m_dBusConnection, this);
bool s = m_dBusConnection.connect(QString(), DBUS_PATH_LOCAL, DBUS_INTERFACE_LOCAL,
"Disconnected", this, SLOT(serviceUnregistered()));
Q_ASSERT(s);
if (!m_serviceProxy->isValid() || !m_trafficProxy->isValid() || !m_weatherProxy->isValid())
if (!m_serviceProxy->isValid() || !m_trafficProxy->isValid())
{
this->disconnectFrom();
return false;
@@ -375,10 +358,8 @@ namespace BlackSimPlugin
if (m_watcher) { m_watcher->setConnection(m_dBusConnection); }
delete m_serviceProxy;
delete m_trafficProxy;
delete m_weatherProxy;
m_serviceProxy = nullptr;
m_trafficProxy = nullptr;
m_weatherProxy = nullptr;
this->emitSimulatorCombinedStatus();
return true;
}
@@ -390,10 +371,8 @@ namespace BlackSimPlugin
if (m_watcher) { m_watcher->setConnection(m_dBusConnection); }
delete m_serviceProxy;
delete m_trafficProxy;
delete m_weatherProxy;
m_serviceProxy = nullptr;
m_trafficProxy = nullptr;
m_weatherProxy = nullptr;
this->emitSimulatorCombinedStatus();
}
@@ -671,95 +650,6 @@ namespace BlackSimPlugin
return true;
}
void CSimulatorXPlane::injectWeatherGrid(const Weather::CWeatherGrid &weatherGrid)
{
Q_ASSERT(isConnected());
m_weatherProxy->setUseRealWeather(false);
//! TODO: find the closest
if (weatherGrid.isEmpty()) { return; }
const CGridPoint gridPoint = weatherGrid.front();
// todo: find the closest
auto visibilityLayers = gridPoint.getVisibilityLayers();
visibilityLayers.sortBy(&CVisibilityLayer::getBase);
const CVisibilityLayer visibilityLayer = visibilityLayers.frontOrDefault();
m_weatherProxy->setVisibility(visibilityLayer.getVisibility().value(CLengthUnit::m()));
CTemperatureLayerList temperatureLayers = gridPoint.getTemperatureLayers();
temperatureLayers.sortBy(&CTemperatureLayer::getLevel);
const CTemperatureLayer temperatureLayer = temperatureLayers.frontOrDefault();
m_weatherProxy->setTemperature(temperatureLayer.getTemperature().valueInteger(CTemperatureUnit::C()));
m_weatherProxy->setDewPoint(temperatureLayer.getDewPoint().valueInteger(CTemperatureUnit::C()));
m_weatherProxy->setQNH(gridPoint.getSurfacePressure().value(CPressureUnit::inHg()));
int layerNumber = 0;
CCloudLayerList cloudLayers = gridPoint.getCloudLayers();
auto numberOfLayers = cloudLayers.size();
// Fill cloud layers if less then 3
while (numberOfLayers < 3)
{
cloudLayers.push_back(CCloudLayer());
numberOfLayers++;
}
cloudLayers.sortBy(&CCloudLayer::getBase);
// todo: Instead of truncate, find the 3 vertical closest cloud layers
cloudLayers.truncate(3);
for (const auto &cloudLayer : as_const(cloudLayers))
{
const int base = cloudLayer.getBase().valueInteger(CLengthUnit::m());
const int top = cloudLayer.getTop().valueInteger(CLengthUnit::m());
int coverage = 0;
switch (cloudLayer.getCoverage())
{
case CCloudLayer::None: coverage = 0; break;
case CCloudLayer::Few: coverage = 2; break;
case CCloudLayer::Scattered: coverage = 3; break;
case CCloudLayer::Broken: coverage = 4; break;
case CCloudLayer::Overcast: coverage = 6; break;
default: coverage = 0; break;
}
// Clear = 0, High Cirrus = 1, Scattered = 2, Broken = 3, Overcast = 4, Stratus = 5
int type = 0;
switch (cloudLayer.getClouds())
{
case CCloudLayer::NoClouds: type = 0; break;
case CCloudLayer::Cirrus: type = 1; break;
case CCloudLayer::Stratus: type = 5; break;
default: type = 0; break;
}
m_weatherProxy->setCloudLayer(layerNumber, base, top, type, coverage);
layerNumber++;
}
layerNumber = 0;
CWindLayerList windLayers = gridPoint.getWindLayers();
numberOfLayers = windLayers.size();
// Fill cloud layers if less then 3
while (numberOfLayers < 3)
{
windLayers.push_back(CWindLayer());
numberOfLayers++;
}
windLayers.sortBy(&CWindLayer::getLevel);
// todo: Instead of truncate, find the 3 vertical closest cloud layers
windLayers.truncate(3);
for (const auto &windLayer : windLayers)
{
const int altitudeMeter = windLayer.getLevel().valueInteger(CLengthUnit::m());
const double directionDeg = windLayer.getDirection().value(CAngleUnit::deg());
const int speedKts = windLayer.getSpeed().valueInteger(CSpeedUnit::kts());
m_weatherProxy->setWindLayer(layerNumber, altitudeMeter, directionDeg, speedKts, 0, 0, 0);
layerNumber++;
}
m_weatherProxy->setPrecipitationRatio(cloudLayers.frontOrDefault().getPrecipitationRate());
m_weatherProxy->setThunderstormRatio(0.0);
}
void CSimulatorXPlane::updateRemoteAircraft()
{
Q_ASSERT_X(CThreadUtils::isCurrentThreadObjectThread(this), Q_FUNC_INFO, "thread");
@@ -1186,9 +1076,8 @@ namespace BlackSimPlugin
{
CXSwiftBusServiceProxy service(m_conn);
CXSwiftBusTrafficProxy traffic(m_conn);
CXSwiftBusWeatherProxy weather(m_conn);
bool result = service.isValid() && traffic.isValid() && weather.isValid();
bool result = service.isValid() && traffic.isValid();
if (! result) { return; }
if (!traffic.initialize())

View File

@@ -67,7 +67,6 @@ namespace BlackSimPlugin
{
class CXSwiftBusServiceProxy;
class CXSwiftBusTrafficProxy;
class CXSwiftBusWeatherProxy;
//! X-Plane data
struct XPlaneData
@@ -153,7 +152,6 @@ namespace BlackSimPlugin
virtual bool physicallyRemoveRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign) override;
virtual int physicallyRemoveAllRemoteAircraft() override;
virtual void clearAllRemoteAircraftData() override;
virtual void injectWeatherGrid(const BlackMisc::Weather::CWeatherGrid &weatherGrid) override;
virtual bool isPaused() const override
{
//! \todo XP: provide correct pause state
@@ -226,7 +224,6 @@ namespace BlackSimPlugin
QDBusServiceWatcher *m_watcher { nullptr };
CXSwiftBusServiceProxy *m_serviceProxy { nullptr };
CXSwiftBusTrafficProxy *m_trafficProxy { nullptr };
CXSwiftBusWeatherProxy *m_weatherProxy { nullptr };
QTimer m_fastTimer;
QTimer m_slowTimer;
QTimer m_airportUpdater;