From 23eb283c19415136db8e9767561af6150253da84 Mon Sep 17 00:00:00 2001 From: Lars Toenning Date: Mon, 11 Oct 2021 19:17:46 +0100 Subject: [PATCH] Issue #96 [Flightgear] Get velocity data from Flightgear in fast update timer timeout --- .../flightgear/fgswiftbusserviceproxy.cpp | 23 +++++++ .../flightgear/fgswiftbusserviceproxy.h | 3 + .../flightgear/simulatorflightgear.cpp | 6 +- .../flightgear/simulatorflightgear.h | 65 ++++++++++--------- 4 files changed, 65 insertions(+), 32 deletions(-) diff --git a/src/plugins/simulator/flightgear/fgswiftbusserviceproxy.cpp b/src/plugins/simulator/flightgear/fgswiftbusserviceproxy.cpp index 34d163ece..3bcc29baa 100644 --- a/src/plugins/simulator/flightgear/fgswiftbusserviceproxy.cpp +++ b/src/plugins/simulator/flightgear/fgswiftbusserviceproxy.cpp @@ -43,6 +43,7 @@ namespace BlackSimPlugin::Flightgear void CFGSwiftBusServiceProxy::getOwnAircraftSituationData(FlightgearData *o_flightgearData) { + if (!o_flightgearData) { return; } QPointer myself(this); std::function callback = [ = ](QDBusPendingCallWatcher * watcher) { @@ -64,6 +65,28 @@ namespace BlackSimPlugin::Flightgear m_dbusInterface->callDBusAsync(QLatin1String("getOwnAircraftSituationData"), callback); } + void CFGSwiftBusServiceProxy::getOwnAircraftVelocityData(FlightgearData *o_flightgearData) + { + if (!o_flightgearData) { return; } + QPointer myself(this); + std::function callback = [ = ](QDBusPendingCallWatcher * watcher) + { + if (!myself) { return; } + QDBusPendingReply reply = *watcher; + if (!reply.isError()) + { + o_flightgearData->velocityXMs = reply.argumentAt<0>(); + o_flightgearData->velocityYMs = reply.argumentAt<1>(); + o_flightgearData->velocityZMs = reply.argumentAt<2>(); + o_flightgearData->pitchRateRadPerSec = reply.argumentAt<3>(); + o_flightgearData->rollRateRadPerSec = reply.argumentAt<4>(); + o_flightgearData->yawRateRadPerSec = reply.argumentAt<5>(); + } + watcher->deleteLater(); + }; + m_dbusInterface->callDBusAsync(QLatin1String("getOwnAircraftVelocityData"), callback); + } + void CFGSwiftBusServiceProxy::addTextMessage(const QString &text) { m_dbusInterface->callDBus(QLatin1String("addTextMessage"), text); diff --git a/src/plugins/simulator/flightgear/fgswiftbusserviceproxy.h b/src/plugins/simulator/flightgear/fgswiftbusserviceproxy.h index f379224b4..ccbc646f0 100644 --- a/src/plugins/simulator/flightgear/fgswiftbusserviceproxy.h +++ b/src/plugins/simulator/flightgear/fgswiftbusserviceproxy.h @@ -120,6 +120,9 @@ namespace BlackSimPlugin::Flightgear //! Get own aircraft situation data void getOwnAircraftSituationData(FlightgearData *o_flightgearData); + //! Get own aircraft velocity data + void getOwnAircraftVelocityData(FlightgearData *o_flightgearData); + //! Add a text message to the on-screen display void addTextMessage(const QString &text); diff --git a/src/plugins/simulator/flightgear/simulatorflightgear.cpp b/src/plugins/simulator/flightgear/simulatorflightgear.cpp index bc98cbd3e..0811c20f2 100644 --- a/src/plugins/simulator/flightgear/simulatorflightgear.cpp +++ b/src/plugins/simulator/flightgear/simulatorflightgear.cpp @@ -85,7 +85,7 @@ namespace namespace BlackSimPlugin::Flightgear { int FGSWIFTBUS_API_VERSION = -1; - QList incompatibleVersions = {}; + QList incompatibleVersions = {1,2}; CSimulatorFlightgear::CSimulatorFlightgear(const CSimulatorPluginInfo &info, IOwnAircraftProvider *ownAircraftProvider, IRemoteAircraftProvider *remoteAircraftProvider, @@ -199,6 +199,7 @@ namespace BlackSimPlugin::Flightgear if (!this->isShuttingDownOrDisconnected()) { m_serviceProxy->getOwnAircraftSituationData(&m_flightgearData); + m_serviceProxy->getOwnAircraftVelocityData(&m_flightgearData); m_serviceProxy->getCom1ActiveKhzAsync(&m_flightgearData.com1ActiveKhz); m_serviceProxy->getCom1StandbyKhzAsync(&m_flightgearData.com1StandbyKhz); m_serviceProxy->getCom2ActiveKhzAsync(&m_flightgearData.com2ActiveKhz); @@ -220,6 +221,9 @@ namespace BlackSimPlugin::Flightgear situation.setBank({ m_flightgearData.rollDeg, CAngleUnit::deg() }); situation.setGroundSpeed({ m_flightgearData.groundspeedKts, CSpeedUnit::kts() }); situation.setGroundElevation(CAltitude(m_flightgearData.groundElevation, CAltitude::MeanSeaLevel, CLengthUnit::m()), CAircraftSituation::FromProvider); + situation.setVelocity({ m_flightgearData.velocityXMs, m_flightgearData.velocityYMs, m_flightgearData.velocityZMs, + CSpeedUnit::m_s(), m_flightgearData.pitchRateRadPerSec, m_flightgearData.rollRateRadPerSec, m_flightgearData.yawRateRadPerSec, + CAngleUnit::rad(), CTimeUnit::s()}); // Updates // Do not update ICAO codes, as this overrides reverse lookups diff --git a/src/plugins/simulator/flightgear/simulatorflightgear.h b/src/plugins/simulator/flightgear/simulatorflightgear.h index fbb19b57e..770f62b45 100644 --- a/src/plugins/simulator/flightgear/simulatorflightgear.h +++ b/src/plugins/simulator/flightgear/simulatorflightgear.h @@ -73,34 +73,40 @@ namespace BlackSimPlugin::Flightgear { QString aircraftModelPath; //!< Aircraft model path QString aircraftIcaoCode; //!< Aircraft ICAO code - double latitudeDeg; //!< Longitude [deg] - double longitudeDeg; //!< Latitude [deg] - double altitudeFt; //!< Altitude [ft] - double groundspeedKts; //!< Ground speed [kts] - double pitchDeg; //!< Pitch [deg] - double rollDeg; //!< Roll [deg] - double trueHeadingDeg; //!< True heading [deg] - bool onGroundAll; //!< All wheels on ground? - int com1ActiveKhz; //!< COM1 active [kHz] - int com1StandbyKhz; //!< COM1 standby [kHz] - int com2ActiveKhz; //!< COM2 active [kHz] - int com2StandbyKhz; //!< COM2 standby [kHz] - int xpdrCode; //!< Transpondder code - int xpdrMode; //!< Transponder mode (off=0,stdby=1-2, >2 on) - bool xpdrIdent; //!< Is transponder in ident? - bool beaconLightsOn; //!< Beacon lights on? - bool landingLightsOn; //!< Landing lights on? - bool navLightsOn; //!< NAV lights on? - bool strobeLightsOn; //!< Strobe lights on? - bool taxiLightsOn; //!< Taxi lights on? - double flapsReployRatio; //!< Flaps deployment ratio [%] - double gearReployRatio; //!< Gear deployment ratio [%] + double latitudeDeg = 0; //!< Longitude [deg] + double longitudeDeg = 0; //!< Latitude [deg] + double altitudeFt = 0; //!< Altitude [ft] + double groundspeedKts = 0; //!< Ground speed [kts] + double pitchDeg = 0; //!< Pitch [deg] + double rollDeg = 0; //!< Roll [deg] + double trueHeadingDeg = 0; //!< True heading [deg] + double velocityXMs = 0; //!< x velocity [m/s] + double velocityYMs = 0; //!< y velocity [m/s] + double velocityZMs = 0; //!< z velocity [m/s] + double pitchRateRadPerSec = 0; //!< Pitch angular velocity [rad/s] + double rollRateRadPerSec = 0; //!< Roll angular velocity [rad/s] + double yawRateRadPerSec = 0; //!< Yaw angular velocity [rad/s] + bool onGroundAll = false; //!< All wheels on ground? + int com1ActiveKhz = 122800; //!< COM1 active [kHz] + int com1StandbyKhz = 122800; //!< COM1 standby [kHz] + int com2ActiveKhz = 122800; //!< COM2 active [kHz] + int com2StandbyKhz = 122800; //!< COM2 standby [kHz] + int xpdrCode = 2000; //!< Transpondder code + int xpdrMode = 0; //!< Transponder mode (off=0,stdby=1-2, >2 on) + bool xpdrIdent = false; //!< Is transponder in ident? + bool beaconLightsOn = false; //!< Beacon lights on? + bool landingLightsOn = false; //!< Landing lights on? + bool navLightsOn = false; //!< NAV lights on? + bool strobeLightsOn = false; //!< Strobe lights on? + bool taxiLightsOn = false; //!< Taxi lights on? + double flapsReployRatio = false; //!< Flaps deployment ratio [%] + double gearReployRatio = false; //!< Gear deployment ratio [%] QList enginesN1Percentage; //!< N1 per engine [%] - double speedBrakeRatio; //!< Speed break ratio [%] - double pressureAltitudeFt; //!< Pressure altitude [inhg] - double groundElevation; //!< Ground Elevation [m] - double volumeCom1; //!< Volume com1 [0..1] - double volumeCom2; //!< Volume com2 [0..1] + double speedBrakeRatio = 0; //!< Speed break ratio [%] + double pressureAltitudeFt = 0; //!< Pressure altitude [inhg] + double groundElevation = 0; //!< Ground Elevation [m] + double volumeCom1 = 1; //!< Volume com1 [0..1] + double volumeCom2 = 1; //!< Volume com2 [0..1] }; //! Flightgear ISimulator implementation @@ -241,10 +247,7 @@ namespace BlackSimPlugin::Flightgear //! Reset the Flightgear data void resetFlightgearData() { - m_flightgearData = { "", "", 0, 0, 0, 0, 0, 0, 0, false, 122800, 122800, 122800, 122800, 2000, 0, false, false, false, false, - false, false, 0, 0, {}, 0.0, 0.0, 0.0, 1.0, 1.0 - }; - + m_flightgearData = {}; } };