diff --git a/src/plugins/simulator/xplane/simulatorxplane.cpp b/src/plugins/simulator/xplane/simulatorxplane.cpp index 60f36d732..dec8001ff 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.cpp +++ b/src/plugins/simulator/xplane/simulatorxplane.cpp @@ -321,6 +321,7 @@ namespace BlackSimPlugin::XPlane m_serviceProxy->getOwnAircraftCom2DataAsync(&m_xplaneData); m_serviceProxy->getOwnAircraftXpdrAsync(&m_xplaneData); m_serviceProxy->getAllWheelsOnGroundAsync(&m_xplaneData.onGroundAll); + m_serviceProxy->getGroundElevationAsync(&m_xplaneData.groundElevation); CAircraftSituation situation; situation.setPosition({ m_xplaneData.latitudeDeg, m_xplaneData.longitudeDeg, 0 }); @@ -333,6 +334,8 @@ 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() }); + const CAltitude elevation { std::isnan(m_xplaneData.groundElevation) ? 0 : m_xplaneData.groundElevation, CAltitude::MeanSeaLevel, CLengthUnit::m() }; + situation.setGroundElevation(elevation, CAircraftSituation::FromProvider); 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()}); diff --git a/src/plugins/simulator/xplane/simulatorxplane.h b/src/plugins/simulator/xplane/simulatorxplane.h index e1d44ec0d..7bae0da72 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.h +++ b/src/plugins/simulator/xplane/simulatorxplane.h @@ -86,6 +86,7 @@ namespace BlackSimPlugin::XPlane double rollRadPerSec = 0; //!< Roll angular velocity [rad/s] double headingRadPerSec = 0; //!< Heading angular velocity [rad/s] bool onGroundAll = false; //!< All wheels on ground? + double groundElevation = 0; //!< Elevation of ground [m] int com1ActiveKhz = 122800; //!< COM1 active [kHz] int com1StandbyKhz = 122800; //!< COM1 standby [kHz] bool isCom1Receiving = true; //!< COM1 receiving diff --git a/src/plugins/simulator/xplane/xswiftbusserviceproxy.cpp b/src/plugins/simulator/xplane/xswiftbusserviceproxy.cpp index 8df075172..0563878dd 100644 --- a/src/plugins/simulator/xplane/xswiftbusserviceproxy.cpp +++ b/src/plugins/simulator/xplane/xswiftbusserviceproxy.cpp @@ -544,6 +544,16 @@ namespace BlackSimPlugin::XPlane m_dbusInterface->callDBusAsync(QLatin1String("getAllWheelsOnGround"), setterCallback(o_allWheels)); } + double CXSwiftBusServiceProxy::getGroundElevation() const + { + return m_dbusInterface->callDBusRet(QLatin1String("getGroundElevation")); + } + + void CXSwiftBusServiceProxy::getGroundElevationAsync(double* o_elevationM) + { + m_dbusInterface->callDBusAsync(QLatin1String("getGroundElevation"), setterCallback(o_elevationM)); + } + int CXSwiftBusServiceProxy::getCom1ActiveKhz() const { return m_dbusInterface->callDBusRet(QLatin1String("getCom1ActiveKhz")); diff --git a/src/plugins/simulator/xplane/xswiftbusserviceproxy.h b/src/plugins/simulator/xplane/xswiftbusserviceproxy.h index f3338f3ed..4a9a4306b 100644 --- a/src/plugins/simulator/xplane/xswiftbusserviceproxy.h +++ b/src/plugins/simulator/xplane/xswiftbusserviceproxy.h @@ -329,6 +329,12 @@ namespace BlackSimPlugin::XPlane void getAllWheelsOnGroundAsync(bool *o_allWheels); //! @} + //! Get elevation of ground under the plane (in meters) + //! @{ + double getGroundElevation() const; + void getGroundElevationAsync(double *o_elevationM); + //! @} + //! \copydoc XSwiftBus::CService::getCom1ActiveKhz //! @{ int getCom1ActiveKhz() const; diff --git a/src/xswiftbus/service.cpp b/src/xswiftbus/service.cpp index 286484ea3..392a15438 100644 --- a/src/xswiftbus/service.cpp +++ b/src/xswiftbus/service.cpp @@ -766,6 +766,13 @@ namespace XSwiftBus sendDBusReply(sender, serial, getAllWheelsOnGround()); }); } + else if (message.getMethodName() == "getGroundElevation") + { + queueDBusCall([ = ]() + { + sendDBusReply(sender, serial, getGroundElevation()); + }); + } else if (message.getMethodName() == "getCom1ActiveKhz") { queueDBusCall([ = ]() diff --git a/src/xswiftbus/service.h b/src/xswiftbus/service.h index 9d3b23165..fe7369f5d 100644 --- a/src/xswiftbus/service.h +++ b/src/xswiftbus/service.h @@ -19,6 +19,7 @@ #include "datarefs.h" #include "messages.h" #include "navdatareference.h" +#include "terrainprobe.h" #include #include #include @@ -174,6 +175,9 @@ namespace XSwiftBus //! Get whether all wheels are on the ground bool getAllWheelsOnGround() const { return m_onGroundAll.get(); } + //! Get elevation of ground under the plane in meters + double getGroundElevation() const { return m_terrainProbe.getElevation(m_latitude.get(), m_longitude.get(), m_elevation.get())[0]; } + //! COM Selection 6/7 //! @{ int getComSelection() const { return m_comAudioSelection.get(); } @@ -333,6 +337,7 @@ namespace XSwiftBus int m_disapperMessageWindowTimeMs = 5000; std::chrono::system_clock::time_point m_disappearMessageWindowTime; std::vector m_airports; + CTerrainProbe m_terrainProbe; void readAirportsDatabase(); std::vector findClosestAirports(int number, double latitude, double longitude); diff --git a/src/xswiftbus/terrainprobe.cpp b/src/xswiftbus/terrainprobe.cpp index 67173252c..9e244d9c5 100644 --- a/src/xswiftbus/terrainprobe.cpp +++ b/src/xswiftbus/terrainprobe.cpp @@ -18,6 +18,13 @@ namespace XSwiftBus CTerrainProbe::~CTerrainProbe() { XPLMDestroyProbe(m_ref); } + std::array CTerrainProbe::getElevation(double degreesLatitude, double degreesLongitude, double metersAltitude) const + { + static const std::string callsign = "myself"; + bool unused = false; + return getElevation(degreesLatitude, degreesLongitude, metersAltitude, callsign, unused); + } + std::array CTerrainProbe::getElevation(double degreesLatitude, double degreesLongitude, double metersAltitude, const std::string &callsign, bool &o_isWater) const { double x, y, z; diff --git a/src/xswiftbus/terrainprobe.h b/src/xswiftbus/terrainprobe.h index 8571337c3..5897e0985 100644 --- a/src/xswiftbus/terrainprobe.h +++ b/src/xswiftbus/terrainprobe.h @@ -36,7 +36,10 @@ namespace XSwiftBus //! Get the elevation in meters at the given point in OpenGL space. //! \note Due to the Earth's curvature, the OpenGL vertical axis may not be exactly perpendicular to the surface of the geoid. //! \return NaN if no ground was detected. + //! @{ + std::array getElevation(double degreesLatitude, double degreesLongitude, double metersAltitude) const; std::array getElevation(double degreesLatitude, double degreesLongitude, double metersAltitude, const std::string &callsign, bool &o_isWater) const; + //! @} private: XPLMProbeRef m_ref = nullptr;