From c9b1647e7269671c1eec30e13d24690e300023cd Mon Sep 17 00:00:00 2001 From: Mathew Sutcliffe Date: Mon, 9 Jan 2017 18:49:09 +0000 Subject: [PATCH] refs #852 Extend xbus traffic service to maintain a CAircraftPartsList with onGround flags. --- src/plugins/simulator/xplane/simulatorxplane.cpp | 7 ++++--- src/plugins/simulator/xplane/xbustrafficproxy.cpp | 8 ++++---- src/plugins/simulator/xplane/xbustrafficproxy.h | 6 +++--- src/xbus/traffic.cpp | 14 ++++++++++++-- src/xbus/traffic.h | 6 ++++-- 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/plugins/simulator/xplane/simulatorxplane.cpp b/src/plugins/simulator/xplane/simulatorxplane.cpp index 10a469793..4ea4b5950 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.cpp +++ b/src/plugins/simulator/xplane/simulatorxplane.cpp @@ -521,9 +521,10 @@ namespace BlackSimPlugin void CSimulatorXPlane::ps_remoteProviderAddAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftParts &parts) { Q_ASSERT(isConnected()); - m_traffic->setPlaneSurfaces(callsign.asString(), true, 0, 0, 0, 0, 0, 0, 0, 0, 0, true, true, true, true, 0); // TODO landing gear, lights, control surfaces - m_traffic->setPlaneTransponder(callsign.asString(), 2000, true, false); // TODO transponder - Q_UNUSED(parts); // TODO + //! \fixme Parts currently not used by libxplanemp + m_traffic->addPlaneSurfaces(callsign.asString(), true, 0, 0, 0, 0, 0, 0, 0, 0, 0, true, true, true, true, 0, parts.isOnGround(), + parts.getAdjustedMSecsSinceEpoch() - QDateTime::currentMSecsSinceEpoch()); + m_traffic->setPlaneTransponder(callsign.asString(), 2000, true, false); } void CSimulatorXPlane::ps_remoteProviderRemovedAircraft(const CCallsign &callsign) diff --git a/src/plugins/simulator/xplane/xbustrafficproxy.cpp b/src/plugins/simulator/xplane/xbustrafficproxy.cpp index ea3f81fa1..738af5613 100644 --- a/src/plugins/simulator/xplane/xbustrafficproxy.cpp +++ b/src/plugins/simulator/xplane/xbustrafficproxy.cpp @@ -91,11 +91,11 @@ namespace BlackSimPlugin m_dbusInterface->callDBus(QLatin1String("addPlanePosition"), callsign, latitude, longitude, altitude, pitch, roll, heading, relativeTime); } - void CXBusTrafficProxy::setPlaneSurfaces(const QString &callsign, double gear, double flap, double spoiler, double speedBrake, double slat, double wingSweep, double thrust, - double elevator, double rudder, double aileron, bool landLight, bool beaconLight, bool strobeLight, bool navLight, int lightPattern) + void CXBusTrafficProxy::addPlaneSurfaces(const QString &callsign, double gear, double flap, double spoiler, double speedBrake, double slat, double wingSweep, double thrust, + double elevator, double rudder, double aileron, bool landLight, bool beaconLight, bool strobeLight, bool navLight, int lightPattern, bool onGround, qint64 relativeTime) { - m_dbusInterface->callDBus(QLatin1String("setPlaneSurfaces"), callsign, gear, flap, spoiler, speedBrake, slat, wingSweep, thrust, elevator, rudder, aileron, - landLight, beaconLight, strobeLight, navLight, lightPattern); + m_dbusInterface->callDBus(QLatin1String("addPlaneSurfaces"), callsign, gear, flap, spoiler, speedBrake, slat, wingSweep, thrust, elevator, rudder, aileron, + landLight, beaconLight, strobeLight, navLight, lightPattern, onGround, relativeTime); } void CXBusTrafficProxy::setPlaneTransponder(const QString &callsign, int code, bool modeC, bool ident) diff --git a/src/plugins/simulator/xplane/xbustrafficproxy.h b/src/plugins/simulator/xplane/xbustrafficproxy.h index 6dfd987b2..e1f355284 100644 --- a/src/plugins/simulator/xplane/xbustrafficproxy.h +++ b/src/plugins/simulator/xplane/xbustrafficproxy.h @@ -105,9 +105,9 @@ namespace BlackSimPlugin //! \copydoc XBus::CTraffic::addPlanePosition void addPlanePosition(const QString &callsign, double latitude, double longitude, double altitude, double pitch, double roll, double heading, qint64 relativeTime); - //! \copydoc XBus::CTraffic::setPlaneSurfaces - void setPlaneSurfaces(const QString &callsign, double gear, double flap, double spoiler, double speedBrake, double slat, double wingSweep, double thrust, - double elevator, double rudder, double aileron, bool landLight, bool beaconLight, bool strobeLight, bool navLight, int lightPattern); + //! \copydoc XBus::CTraffic::addPlaneSurfaces + void addPlaneSurfaces(const QString &callsign, double gear, double flap, double spoiler, double speedBrake, double slat, double wingSweep, double thrust, + double elevator, double rudder, double aileron, bool landLight, bool beaconLight, bool strobeLight, bool navLight, int lightPattern, bool onGround, qint64 relativeTime); //! \copydoc XBus::CTraffic::setPlaneTransponder void setPlaneTransponder(const QString &callsign, int code, bool modeC, bool ident); diff --git a/src/xbus/traffic.cpp b/src/xbus/traffic.cpp index c1a05f431..8dc4d8d14 100644 --- a/src/xbus/traffic.cpp +++ b/src/xbus/traffic.cpp @@ -249,8 +249,8 @@ namespace XBus } } - void CTraffic::setPlaneSurfaces(const QString &callsign, double gear, double flap, double spoiler, double speedBrake, double slat, double wingSweep, double thrust, - double elevator, double rudder, double aileron, bool landLight, bool beaconLight, bool strobeLight, bool navLight, int lightPattern) + void CTraffic::addPlaneSurfaces(const QString &callsign, double gear, double flap, double spoiler, double speedBrake, double slat, double wingSweep, double thrust, + double elevator, double rudder, double aileron, bool landLight, bool beaconLight, bool strobeLight, bool navLight, int lightPattern, bool onGround, qint64 relativeTime) { const auto plane = m_planesByCallsign.value(callsign, nullptr); if (plane) @@ -271,6 +271,16 @@ namespace XBus plane->surfaces.lights.strbLights = strobeLight; plane->surfaces.lights.navLights = navLight; plane->surfaces.lights.flashPattern = lightPattern; + + plane->parts.push_front({}); + plane->parts.front().setOnGround(onGround); + plane->parts.front().setMSecsSinceEpoch(relativeTime + QDateTime::currentMSecsSinceEpoch()); + + // remove outdated parts (but never remove the most recent one) + enum { maxAgeMs = BlackMisc::Simulation::IRemoteAircraftProvider::PartsPerCallsignMaxAgeInSeconds * 1000 }; // enum because MSVC constexpr bug + const auto predicate = [now = plane->parts.front().getMSecsSinceEpoch()](auto && p) { return p.getMSecsSinceEpoch() >= now - maxAgeMs; }; + const auto newEnd = std::find_if(plane->parts.rbegin(), plane->parts.rend(), predicate).base(); + plane->parts.erase(newEnd, plane->parts.end()); } } diff --git a/src/xbus/traffic.h b/src/xbus/traffic.h index b775e8ddf..3e921f463 100644 --- a/src/xbus/traffic.h +++ b/src/xbus/traffic.h @@ -14,6 +14,7 @@ #include "datarefs.h" #include "blackmisc/aviation/aircraftsituationlist.h" +#include "blackmisc/aviation/aircraftpartslist.h" #include #include #include @@ -105,8 +106,8 @@ namespace XBus void addPlanePosition(const QString &callsign, double latitude, double longitude, double altitude, double pitch, double roll, double heading, qint64 relativeTime); //! Set the flight control surfaces and lights of a traffic aircraft - void setPlaneSurfaces(const QString &callsign, double gear, double flap, double spoiler, double speedBrake, double slat, double wingSweep, double thrust, - double elevator, double rudder, double aileron, bool landLight, bool beaconLight, bool strobeLight, bool navLight, int lightPattern); + void addPlaneSurfaces(const QString &callsign, double gear, double flap, double spoiler, double speedBrake, double slat, double wingSweep, double thrust, + double elevator, double rudder, double aileron, bool landLight, bool beaconLight, bool strobeLight, bool navLight, int lightPattern, bool onGround, qint64 relativeTime); //! Set the transponder of a traffic aircraft void setPlaneTransponder(const QString &callsign, int code, bool modeC, bool ident); @@ -129,6 +130,7 @@ namespace XBus bool hasXpdr = false; char label[32] {}; BlackMisc::Aviation::CAircraftSituationList situations; + BlackMisc::Aviation::CAircraftPartsList parts; XPMPPlaneSurfaces_t surfaces; XPMPPlaneRadar_t xpdr; Plane(void *id_, QString callsign_, QString aircraftIcao_, QString airlineIcao_, QString livery_);