From 3f57c66784ac9b14ab47037d3b761b2350f35856 Mon Sep 17 00:00:00 2001 From: Mat Sutcliffe Date: Mon, 11 Oct 2021 18:26:05 +0100 Subject: [PATCH] Issue #95 [XPlane] Get velocity data from xswiftbus in fast update timer timeout --- .../simulator/xplane/simulatorxplane.cpp | 4 + .../simulator/xplane/simulatorxplane.h | 6 ++ .../xplane/xswiftbusserviceproxy.cpp | 75 +++++++++++++++++++ .../simulator/xplane/xswiftbusserviceproxy.h | 39 ++++++++++ .../org.swift_project.xswiftbus.service.xml | 26 +++++++ src/xswiftbus/service.cpp | 63 ++++++++++++++++ src/xswiftbus/service.h | 20 +++++ 7 files changed, 233 insertions(+) diff --git a/src/plugins/simulator/xplane/simulatorxplane.cpp b/src/plugins/simulator/xplane/simulatorxplane.cpp index 579020632..60f36d732 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.cpp +++ b/src/plugins/simulator/xplane/simulatorxplane.cpp @@ -316,6 +316,7 @@ namespace BlackSimPlugin::XPlane m_fastTimerCalls++; m_serviceProxy->getOwnAircraftSituationDataAsync(&m_xplaneData); + m_serviceProxy->getOwnAircraftVelocityDataAsync(&m_xplaneData); m_serviceProxy->getOwnAircraftCom1DataAsync(&m_xplaneData); m_serviceProxy->getOwnAircraftCom2DataAsync(&m_xplaneData); m_serviceProxy->getOwnAircraftXpdrAsync(&m_xplaneData); @@ -332,6 +333,9 @@ namespace BlackSimPlugin::XPlane situation.setPitch({ m_xplaneData.pitchDeg, CAngleUnit::deg() }); situation.setBank({ m_xplaneData.rollDeg, CAngleUnit::deg() }); situation.setGroundSpeed({ m_xplaneData.groundspeedMs, CSpeedUnit::m_s() }); + situation.setVelocity({ m_xplaneData.localXVelocityMs, m_xplaneData.localYVelocityMs, m_xplaneData.localZVelocityMs, + CSpeedUnit::m_s(), m_xplaneData.pitchRadPerSec, m_xplaneData.rollRadPerSec, m_xplaneData.headingRadPerSec, + CAngleUnit::rad(), CTimeUnit::s()}); // Updates // Do not update ICAO codes, as this overrides reverse lookups diff --git a/src/plugins/simulator/xplane/simulatorxplane.h b/src/plugins/simulator/xplane/simulatorxplane.h index 792f072f9..e1d44ec0d 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.h +++ b/src/plugins/simulator/xplane/simulatorxplane.h @@ -79,6 +79,12 @@ namespace BlackSimPlugin::XPlane double pitchDeg = 0; //!< Pitch [deg] double rollDeg = 0; //!< Roll [deg] double trueHeadingDeg = 0; //!< True heading [deg] + double localXVelocityMs = 0; //!< Local x velocity [m/s] + double localYVelocityMs = 0; //!< Local y velocity [m/s] + double localZVelocityMs = 0; //!< Local z velocity [m/s] + double pitchRadPerSec = 0; //!< Pitch angular velocity [rad/s] + double rollRadPerSec = 0; //!< Roll angular velocity [rad/s] + double headingRadPerSec = 0; //!< Heading angular velocity [rad/s] bool onGroundAll = false; //!< All wheels on ground? int com1ActiveKhz = 122800; //!< COM1 active [kHz] int com1StandbyKhz = 122800; //!< COM1 standby [kHz] diff --git a/src/plugins/simulator/xplane/xswiftbusserviceproxy.cpp b/src/plugins/simulator/xplane/xswiftbusserviceproxy.cpp index 8a0629e5d..f0a5b5e71 100644 --- a/src/plugins/simulator/xplane/xswiftbusserviceproxy.cpp +++ b/src/plugins/simulator/xplane/xswiftbusserviceproxy.cpp @@ -75,6 +75,27 @@ namespace BlackSimPlugin::XPlane m_dbusInterface->callDBusAsync(QLatin1String("getOwnAircraftSituationData"), callback); } + void CXSwiftBusServiceProxy::getOwnAircraftVelocityDataAsync(XPlaneData *o_xplaneData) + { + if (!o_xplaneData) { return; } + QPointer myself(this); + std::function callback = [ = ](QDBusPendingCallWatcher * watcher) + { + if (!myself) { return; } + QDBusPendingReply reply = *watcher; + if (!reply.isError()) + { + o_xplaneData->localXVelocityMs = reply.argumentAt<0>(); + o_xplaneData->localYVelocityMs = reply.argumentAt<1>(); + o_xplaneData->localZVelocityMs = reply.argumentAt<2>(); + o_xplaneData->pitchRadPerSec = reply.argumentAt<3>(); + o_xplaneData->rollRadPerSec = reply.argumentAt<4>(); + o_xplaneData->headingRadPerSec = reply.argumentAt<5>(); + } + }; + m_dbusInterface->callDBusAsync(QLatin1String("getOwnAircraftVelocityData"), callback); + } + void CXSwiftBusServiceProxy::getOwnAircraftCom1DataAsync(XPlaneData *o_xplaneData) { if (!o_xplaneData) { return; } @@ -451,6 +472,60 @@ namespace BlackSimPlugin::XPlane m_dbusInterface->callDBusAsync(QLatin1String("getTrueHeadingDeg"), setterCallback(o_heading)); } + double CXSwiftBusServiceProxy::getLocalXVelocityMps() const + { + return m_dbusInterface->callDBusRet(QLatin1String("getLocalXVelocityMps")); + } + void CXSwiftBusServiceProxy::getLocalXVelocityMpsAsync(double *o_velocity) + { + m_dbusInterface->callDBusAsync(QLatin1String("getLocalXVelocityMps"), setterCallback(o_velocity)); + } + + double CXSwiftBusServiceProxy::getLocalYVelocityMps() const + { + return m_dbusInterface->callDBusRet(QLatin1String("getLocalYVelocityMps")); + } + void CXSwiftBusServiceProxy::getLocalYVelocityMpsAsync(double *o_velocity) + { + m_dbusInterface->callDBusAsync(QLatin1String("getLocalYVelocityMps"), setterCallback(o_velocity)); + } + + double CXSwiftBusServiceProxy::getLocalZVelocityMps() const + { + return m_dbusInterface->callDBusRet(QLatin1String("getLocalZVelocityMps")); + } + void CXSwiftBusServiceProxy::getLocalZVelocityMpsAsync(double *o_velocity) + { + m_dbusInterface->callDBusAsync(QLatin1String("getLocalZVelocityMps"), setterCallback(o_velocity)); + } + + double CXSwiftBusServiceProxy::getPitchRadPerSec() const + { + return m_dbusInterface->callDBusRet(QLatin1String("getPitchRadPerSec")); + } + void CXSwiftBusServiceProxy::getPitchRadPerSecAsync(double *o_radPerSec) + { + m_dbusInterface->callDBusAsync(QLatin1String("getPitchRadPerSec"), setterCallback(o_radPerSec)); + } + + double CXSwiftBusServiceProxy::getRollRadPerSec() const + { + return m_dbusInterface->callDBusRet(QLatin1String("getRollRadPerSec")); + } + void CXSwiftBusServiceProxy::getRollRadPerSecAsync(double *o_radPerSec) + { + m_dbusInterface->callDBusAsync(QLatin1String("getRollRadPerSec"), setterCallback(o_radPerSec)); + } + + double CXSwiftBusServiceProxy::getHeadingRadPerSec() const + { + return m_dbusInterface->callDBusRet(QLatin1String("getHeadingRadPerSec")); + } + void CXSwiftBusServiceProxy::getHeadingRadPerSecAsync(double *o_radPerSec) + { + m_dbusInterface->callDBusAsync(QLatin1String("getHeadingRadPerSec"), setterCallback(o_radPerSec)); + } + bool CXSwiftBusServiceProxy::getAnyWheelOnGround() const { return m_dbusInterface->callDBusRet(QLatin1String("getAnyWheelOnGround")); diff --git a/src/plugins/simulator/xplane/xswiftbusserviceproxy.h b/src/plugins/simulator/xplane/xswiftbusserviceproxy.h index e1836df7b..f3338f3ed 100644 --- a/src/plugins/simulator/xplane/xswiftbusserviceproxy.h +++ b/src/plugins/simulator/xplane/xswiftbusserviceproxy.h @@ -107,6 +107,9 @@ namespace BlackSimPlugin::XPlane //! Get own aircraft situation data void getOwnAircraftSituationDataAsync(BlackSimPlugin::XPlane::XPlaneData *o_xplaneData); + //! Get own aircraft velocity data + void getOwnAircraftVelocityDataAsync(BlackSimPlugin::XPlane::XPlaneData *o_xplaneData); + //! Get own aircraft COM1 data void getOwnAircraftCom1DataAsync(BlackSimPlugin::XPlane::XPlaneData *o_xplaneData); @@ -278,6 +281,42 @@ namespace BlackSimPlugin::XPlane void getTrueHeadingDegAsync(double *o_heading); //! @} + //! \copydoc XSwiftBus::CService::getLocalXVelocityMps + //! @{ + double getLocalXVelocityMps() const; + void getLocalXVelocityMpsAsync(double *o_velocity); + //! @} + + //! \copydoc XSwiftBus::CService::getLocalYVelocityMps + //! @{ + double getLocalYVelocityMps() const; + void getLocalYVelocityMpsAsync(double *o_velocity); + //! @} + + //! \copydoc XSwiftBus::CService::getLocalZVelocityMps + //! @{ + double getLocalZVelocityMps() const; + void getLocalZVelocityMpsAsync(double *o_velocity); + //! @} + + //! \copydoc XSwiftBus::CService::getPitchRadPerSec + //! @{ + double getPitchRadPerSec() const; + void getPitchRadPerSecAsync(double *o_radPerSec); + //! @} + + //! \copydoc XSwiftBus::CService::getRollRadPerSec + //! @{ + double getRollRadPerSec() const; + void getRollRadPerSecAsync(double *o_radPerSec); + //! @} + + //! \copydoc XSwiftBus::CService::getHeadingRadPerSec + //! @{ + double getHeadingRadPerSec() const; + void getHeadingRadPerSecAsync(double *o_radPerSec); + //! @} + //! Get whether any wheel is on the ground //! @{ bool getAnyWheelOnGround() const; diff --git a/src/xswiftbus/org.swift_project.xswiftbus.service.xml b/src/xswiftbus/org.swift_project.xswiftbus.service.xml index 3a86634d6..b7e571371 100644 --- a/src/xswiftbus/org.swift_project.xswiftbus.service.xml +++ b/src/xswiftbus/org.swift_project.xswiftbus.service.xml @@ -22,6 +22,14 @@ R"XML( + + + + + + + + @@ -137,6 +145,24 @@ R"XML( + + + + + + + + + + + + + + + + + + diff --git a/src/xswiftbus/service.cpp b/src/xswiftbus/service.cpp index 07cc4fb1b..286484ea3 100644 --- a/src/xswiftbus/service.cpp +++ b/src/xswiftbus/service.cpp @@ -396,6 +396,27 @@ namespace XSwiftBus sendDBusMessage(reply); }); } + else if (message.getMethodName() == "getOwnAircraftVelocityData") + { + queueDBusCall([ = ]() + { + const double velocityX = m_velocityX.get(); + const double velocityY = m_velocityY.get(); + const double velocityZ = m_velocityZ.get(); + const double pitchVelocity = m_pitchVelocity.get(); + const double rollVelocity = m_rollVelocity.get(); + const double headingVelocity = m_headingVelocity.get(); + CDBusMessage reply = CDBusMessage::createReply(sender, serial); + reply.beginArgumentWrite(); + reply.appendArgument(velocityX); + reply.appendArgument(velocityY); + reply.appendArgument(velocityZ); + reply.appendArgument(pitchVelocity); + reply.appendArgument(rollVelocity); + reply.appendArgument(headingVelocity); + sendDBusMessage(reply); + }); + } else if (message.getMethodName() == "getOwnAircraftCom1Data") { queueDBusCall([ = ]() @@ -689,6 +710,48 @@ namespace XSwiftBus sendDBusReply(sender, serial, getTrueHeadingDeg()); }); } + else if (message.getMethodName() == "getLocalXVelocityXMps") + { + queueDBusCall([ = ]() + { + sendDBusReply(sender, serial, getLocalXVelocityMps()); + }); + } + else if (message.getMethodName() == "getLocalYVelocityYMps") + { + queueDBusCall([ = ]() + { + sendDBusReply(sender, serial, getLocalYVelocityMps()); + }); + } + else if (message.getMethodName() == "getLocalZVelocityZMps") + { + queueDBusCall([ = ]() + { + sendDBusReply(sender, serial, getLocalZVelocityMps()); + }); + } + else if (message.getMethodName() == "getPitchRadPerSec") + { + queueDBusCall([ = ]() + { + sendDBusReply(sender, serial, getPitchRadPerSec()); + }); + } + else if (message.getMethodName() == "getRollRadPerSec") + { + queueDBusCall([ = ]() + { + sendDBusReply(sender, serial, getRollRadPerSec()); + }); + } + else if (message.getMethodName() == "getHeadingRadPerSec") + { + queueDBusCall([ = ]() + { + sendDBusReply(sender, serial, getHeadingRadPerSec()); + }); + } else if (message.getMethodName() == "getAnyWheelOnGround") { queueDBusCall([ = ]() diff --git a/src/xswiftbus/service.h b/src/xswiftbus/service.h index 34636a14e..9d3b23165 100644 --- a/src/xswiftbus/service.h +++ b/src/xswiftbus/service.h @@ -154,6 +154,20 @@ namespace XSwiftBus //! Get aircraft true heading in degrees double getTrueHeadingDeg() const { return m_heading.get(); } + //! Get aircraft local velocity in world coordinates meters per second + //! @{ + double getLocalXVelocityMps() const { return m_velocityX.get(); } + double getLocalYVelocityMps() const { return m_velocityY.get(); } + double getLocalZVelocityMps() const { return m_velocityZ.get(); } + //! @} + + //! Get aircraft angular velocity in radians per second + //! @{ + double getPitchRadPerSec() const { return m_pitchVelocity.get(); } + double getRollRadPerSec() const { return m_rollVelocity.get(); } + double getHeadingRadPerSec() const { return m_headingVelocity.get(); } + //! @} + //! Get whether any wheel is on the ground bool getAnyWheelOnGround() const { return m_onGroundAny.get(); } @@ -347,6 +361,12 @@ namespace XSwiftBus DataRef m_pitch; DataRef m_roll; DataRef m_heading; + DataRef m_velocityX; + DataRef m_velocityY; + DataRef m_velocityZ; + DataRef m_rollVelocity; + DataRef m_pitchVelocity; + DataRef m_headingVelocity; DataRef m_onGroundAny; DataRef m_onGroundAll; DataRef m_com1Active;