refs #925 XP driver sends parts to xbus, and guesses gear and lights if parts not available.

This commit is contained in:
Mathew Sutcliffe
2017-03-31 23:44:13 +01:00
parent 1a6caece3e
commit 2f02cd30d9
3 changed files with 32 additions and 6 deletions

View File

@@ -527,7 +527,7 @@ namespace BlackSimPlugin
if (! isRemoteAircraftSupportingParts(situation.getCallsign()))
{
// if aircraft not supporting parts then guess (currently only onGround is guessed)
// if aircraft not supporting parts then guess the basics (onGround, gear, lights)
//! \todo not working for vtol
BlackMisc::Aviation::CAircraftParts parts;
parts.setMSecsSinceEpoch(situation.getMSecsSinceEpoch());
@@ -541,8 +541,17 @@ namespace BlackSimPlugin
if (nearestAirport != m_airportsInRange.cend() && situation.getAltitude() - nearestAirport->getElevation() < CLength(50, CLengthUnit::ft()))
{
parts.setOnGround(true);
parts.setGearDown(true);
}
}
if (situation.getAltitude() < CAltitude(10'000, CLengthUnit::ft()))
{
parts.setLights({ true, true, true, true, true, true, true, true });
}
else
{
parts.setLights({ true, false, false, true, true, true, true, true });
}
ps_remoteProviderAddAircraftParts(situation.getCallsign(), parts);
}
}
@@ -550,9 +559,11 @@ namespace BlackSimPlugin
void CSimulatorXPlane::ps_remoteProviderAddAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftParts &parts)
{
Q_ASSERT(isConnected());
//! \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->addPlaneSurfaces(callsign.asString(), parts.isGearDown() ? 1 : 0,
parts.getFlapsPercent() / 100.0, parts.isSpoilersOut() ? 1 : 0, parts.isSpoilersOut() ? 1 : 0, parts.getFlapsPercent() / 100.0,
0, parts.isAnyEngineOn() ? 0 : 0.75, 0, 0, 0,
parts.getLights().isLandingOn(), parts.getLights().isBeaconOn(), parts.getLights().isStrobeOn(), parts.getLights().isNavOn(),
0, parts.isOnGround(), parts.getAdjustedMSecsSinceEpoch() - QDateTime::currentMSecsSinceEpoch());
m_traffic->setPlaneTransponder(callsign.asString(), 2000, true, false);
}

View File

@@ -278,8 +278,7 @@ namespace XBus
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)
const auto surfaces = std::make_pair(relativeTime + QDateTime::currentMSecsSinceEpoch(), [ = ](Plane *plane)
{
plane->hasSurfaces = true;
plane->surfaces.gearPosition = gear;
@@ -297,6 +296,13 @@ namespace XBus
plane->surfaces.lights.strbLights = strobeLight;
plane->surfaces.lights.navLights = navLight;
plane->surfaces.lights.flashPattern = lightPattern;
});
const auto plane = m_planesByCallsign.value(callsign, nullptr);
if (plane)
{
if (plane->hasSurfaces) { plane->pendingSurfaces.push_back(surfaces); }
else { surfaces.second(plane); }
BlackMisc::Aviation::CAircraftParts parts;
parts.setOnGround(onGround);
@@ -372,6 +378,12 @@ namespace XBus
case xpmpDataType_Surfaces:
if (plane->hasSurfaces)
{
const auto currentTime = QDateTime::currentMSecsSinceEpoch();
while (! plane->pendingSurfaces.isEmpty() && plane->pendingSurfaces.front().first <= currentTime)
{
plane->pendingSurfaces.front().second(plane);
plane->pendingSurfaces.pop_front();
}
const auto io_surfaces = static_cast<XPMPPlaneSurfaces_t *>(io_data);
if (memcmpPayload(io_surfaces, &plane->surfaces))

View File

@@ -22,6 +22,8 @@
#include <QVector>
#include <QStringList>
#include "XPMPMultiplayer.h"
#include <functional>
#include <utility>
//! \cond PRIVATE
#define XBUS_TRAFFIC_INTERFACENAME "org.swift_project.xbus.traffic"
@@ -138,6 +140,7 @@ namespace XBus
CTerrainProbe terrainProbe;
BlackMisc::Simulation::CInterpolationHints hints();
XPMPPlaneSurfaces_t surfaces;
QVector<std::pair<qint64, std::function<void(Plane *)>>> pendingSurfaces;
XPMPPlaneRadar_t xpdr;
Plane(void *id_, QString callsign_, QString aircraftIcao_, QString airlineIcao_, QString livery_);
};