mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-03 07:35:48 +08:00
Group sending of all plane positions and surfaces into a single DBus call
This commit is contained in:
@@ -117,8 +117,23 @@ namespace BlackSimPlugin
|
||||
|
||||
bool CSimulatorXPlane::requestElevation(const ICoordinateGeodetic &reference, const CCallsign &callsign)
|
||||
{
|
||||
//! \todo KB 2018-04 implement a function fetching the probe value (async) and write it back to provider
|
||||
return ISimulator::requestElevation(reference, callsign);
|
||||
if (this->isShuttingDown()) { return false; }
|
||||
if (reference.isNull()) { return false; }
|
||||
|
||||
static const CAltitude alt(50000, CLengthUnit::ft());
|
||||
CCoordinateGeodetic pos(reference);
|
||||
pos.setGeodeticHeight(alt);
|
||||
|
||||
using namespace std::placeholders;
|
||||
auto callback = std::bind(&CSimulatorXPlane::callbackReceivedRequestedElevation, this, _1, _2);
|
||||
|
||||
// Request
|
||||
m_trafficProxy->getEelevationAtPosition(callsign,
|
||||
pos.latitude().value(CAngleUnit::deg()),
|
||||
pos.longitude().value(CAngleUnit::deg()),
|
||||
pos.geodeticHeight().value(CLengthUnit::m()),
|
||||
callback);
|
||||
return true;
|
||||
}
|
||||
|
||||
// convert xplane squawk mode to swift squawk mode
|
||||
@@ -246,6 +261,7 @@ namespace BlackSimPlugin
|
||||
connect(m_trafficProxy, &CXSwiftBusTrafficProxy::simFrame, this, &CSimulatorXPlane::updateRemoteAircraft);
|
||||
connect(m_trafficProxy, &CXSwiftBusTrafficProxy::remoteAircraftData, this, &CSimulatorXPlane::updateRemoteAircraftFromSimulator);
|
||||
if (m_watcher) { m_watcher->setConnection(m_conn); }
|
||||
m_trafficProxy->removeAllPlanes();
|
||||
this->loadCslPackages();
|
||||
this->emitSimulatorCombinedStatus();
|
||||
return true;
|
||||
@@ -671,6 +687,33 @@ namespace BlackSimPlugin
|
||||
|
||||
// interpolation for all remote aircraft
|
||||
const QList<CXPlaneMPAircraft> xplaneAircraftList(m_xplaneAircraftObjects.values());
|
||||
|
||||
QStringList posCallsigns;
|
||||
QList<double> latitudes;
|
||||
QList<double> longitudes;
|
||||
QList<double> altitudes;
|
||||
QList<double> pitches;
|
||||
QList<double> rolles;
|
||||
QList<double> headings;
|
||||
|
||||
QStringList surfaceCallsign;
|
||||
QList<double> gear;
|
||||
QList<double> flap;
|
||||
QList<double> spoiler;
|
||||
QList<double> speedBrake;
|
||||
QList<double> slat;
|
||||
QList<double> wingSweep;
|
||||
QList<double> thrust;
|
||||
QList<double> elevator;
|
||||
QList<double> rudder;
|
||||
QList<double> aileron;
|
||||
QList<bool> landLight;
|
||||
QList<bool> beaconLight;
|
||||
QList<bool> strobeLight;
|
||||
QList<bool> navLight;
|
||||
QList<int> lightPattern;
|
||||
QList<bool> onGround;
|
||||
|
||||
for (const CXPlaneMPAircraft &xplaneAircraft : xplaneAircraftList)
|
||||
{
|
||||
const CCallsign callsign(xplaneAircraft.getCallsign());
|
||||
@@ -689,13 +732,13 @@ namespace BlackSimPlugin
|
||||
if (!xplaneAircraft.isSameAsSent(interpolatedSituation))
|
||||
{
|
||||
m_xplaneAircraftObjects[xplaneAircraft.getCallsign()].setSituationAsSent(interpolatedSituation);
|
||||
m_trafficProxy->setPlanePosition(interpolatedSituation.getCallsign().asString(),
|
||||
interpolatedSituation.latitude().value(CAngleUnit::deg()),
|
||||
interpolatedSituation.longitude().value(CAngleUnit::deg()),
|
||||
interpolatedSituation.getAltitude().value(CLengthUnit::ft()),
|
||||
interpolatedSituation.getPitch().value(CAngleUnit::deg()),
|
||||
interpolatedSituation.getBank().value(CAngleUnit::deg()),
|
||||
interpolatedSituation.getHeading().value(CAngleUnit::deg()));
|
||||
posCallsigns.push_back(interpolatedSituation.getCallsign().asString());
|
||||
latitudes.push_back(interpolatedSituation.latitude().value(CAngleUnit::deg()));
|
||||
longitudes.push_back(interpolatedSituation.longitude().value(CAngleUnit::deg()));
|
||||
altitudes.push_back(interpolatedSituation.getAltitude().value(CLengthUnit::ft()));
|
||||
pitches.push_back(interpolatedSituation.getPitch().value(CAngleUnit::deg()));
|
||||
rolles.push_back(interpolatedSituation.getBank().value(CAngleUnit::deg()));
|
||||
headings.push_back(interpolatedSituation.getHeading().value(CAngleUnit::deg()));
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -703,40 +746,48 @@ namespace BlackSimPlugin
|
||||
CLogMessage(this).warning(this->getInvalidSituationLogMessage(callsign, result.getInterpolationStatus()));
|
||||
}
|
||||
|
||||
this->updateRemoteAircraftParts(xplaneAircraft, result);
|
||||
const CAircraftParts parts(result);
|
||||
if (result.getPartsStatus().isSupportingParts() || parts.getPartsDetails() == CAircraftParts::GuessedParts)
|
||||
{
|
||||
if(xplaneAircraft.getPartsAsSent() == parts) { continue; }
|
||||
|
||||
surfaceCallsign.push_back(xplaneAircraft.getCallsign().asString());
|
||||
gear.push_back(parts.isGearDown() ? 1 : 0);
|
||||
flap.push_back(parts.getFlapsPercent() / 100.0);
|
||||
spoiler.push_back(parts.isSpoilersOut() ? 1 : 0);
|
||||
speedBrake.push_back(parts.isSpoilersOut() ? 1 : 0);
|
||||
slat.push_back(parts.getFlapsPercent() / 100.0);
|
||||
wingSweep.push_back(0.0);
|
||||
thrust.push_back(parts.isAnyEngineOn() ? 0 : 0.75);
|
||||
elevator.push_back(0.0);
|
||||
rudder.push_back(0.0);
|
||||
aileron.push_back(0.0);
|
||||
landLight.push_back(parts.getLights().isLandingOn());
|
||||
beaconLight.push_back(parts.getLights().isBeaconOn());
|
||||
strobeLight.push_back(parts.getLights().isStrobeOn());
|
||||
navLight.push_back(parts.getLights().isNavOn());
|
||||
lightPattern.push_back(0);
|
||||
onGround.push_back(parts.isOnGround());
|
||||
}
|
||||
|
||||
} // all callsigns
|
||||
|
||||
if (! posCallsigns.isEmpty())
|
||||
{
|
||||
m_trafficProxy->setPlanePositions(posCallsigns, latitudes, longitudes, altitudes, pitches, rolles, headings);
|
||||
}
|
||||
|
||||
if (! surfaceCallsign.isEmpty())
|
||||
{
|
||||
m_trafficProxy->setPlaneSurfaces(surfaceCallsign, gear, flap, spoiler, speedBrake, slat, wingSweep, thrust, elevator, rudder, aileron, landLight, beaconLight, strobeLight, navLight, lightPattern, onGround);
|
||||
}
|
||||
|
||||
const qint64 dt = QDateTime::currentMSecsSinceEpoch() - currentTimestamp;
|
||||
m_statsUpdateAircraftTimeTotalMs += dt;
|
||||
m_statsUpdateAircraftCountMs++;
|
||||
m_statsUpdateAircraftTimeAvgMs = m_statsUpdateAircraftTimeTotalMs / m_statsUpdateAircraftCountMs;
|
||||
}
|
||||
|
||||
bool CSimulatorXPlane::updateRemoteAircraftParts(const CXPlaneMPAircraft &xplaneAircraft, const CInterpolationResult &result)
|
||||
{
|
||||
if (!result.getPartsStatus().isSupportingParts()) { return false; }
|
||||
return this->sendRemoteAircraftPartsToSimulator(xplaneAircraft, result);
|
||||
}
|
||||
|
||||
bool CSimulatorXPlane::sendRemoteAircraftPartsToSimulator(const CXPlaneMPAircraft &xplaneAircraft, const CAircraftParts &parts)
|
||||
{
|
||||
// same as in simulator or same as already send to simulator?
|
||||
if (xplaneAircraft.getPartsAsSent() == parts) { return true; }
|
||||
|
||||
m_trafficProxy->setPlaneSurfaces(xplaneAircraft.getCallsign().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());
|
||||
return true;
|
||||
}
|
||||
|
||||
void CSimulatorXPlane::requestRemoteAircraftDataFromXPlane()
|
||||
{
|
||||
if (!isConnected()) { return; }
|
||||
|
||||
@@ -177,12 +177,6 @@ namespace BlackSimPlugin
|
||||
//! \remark this is where the interpolated data are set
|
||||
void updateRemoteAircraft();
|
||||
|
||||
//! Update remote aircraft parts (send to XSwiftBus)
|
||||
bool updateRemoteAircraftParts(const CXPlaneMPAircraft &xplaneAircraft, const BlackMisc::Simulation::CInterpolationResult &result);
|
||||
|
||||
//! Send parts to simulator
|
||||
bool sendRemoteAircraftPartsToSimulator(const CXPlaneMPAircraft &xplaneAircraft, const BlackMisc::Aviation::CAircraftParts &parts);
|
||||
|
||||
void requestRemoteAircraftDataFromXPlane();
|
||||
void updateRemoteAircraftFromSimulator(const QString &callsign, double latitudeDeg, double longitudeDeg, double elevationMeters, double modelVerticalOffsetMeters);
|
||||
void updateAirportsInRange();
|
||||
|
||||
@@ -13,6 +13,10 @@
|
||||
|
||||
#define XSWIFTBUS_SERVICENAME "org.swift-project.xswiftbus"
|
||||
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackMisc::Geo;
|
||||
using namespace BlackMisc::PhysicalQuantities;
|
||||
|
||||
namespace BlackSimPlugin
|
||||
{
|
||||
namespace XPlane
|
||||
@@ -78,25 +82,16 @@ namespace BlackSimPlugin
|
||||
m_dbusInterface->callDBus(QLatin1String("removeAllPlanes"));
|
||||
}
|
||||
|
||||
void CXSwiftBusTrafficProxy::addPlanePosition(const QString &callsign, double latitude, double longitude, double altitude, double pitch, double roll, double heading, qint64 relativeTime, qint64 timeOffset)
|
||||
void CXSwiftBusTrafficProxy::setPlanePositions(const QStringList &callsigns, const QList<double> &latitudes, const QList<double> &longitudes, const QList<double> &altitudes,
|
||||
const QList<double> &pitches, const QList<double> &rolles, const QList<double> &headings)
|
||||
{
|
||||
m_dbusInterface->callDBus(QLatin1String("addPlanePosition"), callsign, latitude, longitude, altitude, pitch, roll, heading, relativeTime, timeOffset);
|
||||
m_dbusInterface->callDBus(QLatin1String("setPlanePositions"), callsigns, latitudes, longitudes, altitudes, pitches, rolles, headings);
|
||||
}
|
||||
|
||||
void CXSwiftBusTrafficProxy::setPlanePosition(const QString &callsign, double latitude, double longitude, double altitude, double pitch, double roll, double heading)
|
||||
{
|
||||
m_dbusInterface->callDBus(QLatin1String("setPlanePosition"), callsign, latitude, longitude, altitude, pitch, roll, heading);
|
||||
}
|
||||
|
||||
void CXSwiftBusTrafficProxy::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, qint64 timeOffset)
|
||||
{
|
||||
m_dbusInterface->callDBus(QLatin1String("addPlaneSurfaces"), callsign, gear, flap, spoiler, speedBrake, slat, wingSweep, thrust, elevator, rudder, aileron,
|
||||
landLight, beaconLight, strobeLight, navLight, lightPattern, onGround, relativeTime, timeOffset);
|
||||
}
|
||||
|
||||
void CXSwiftBusTrafficProxy::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, bool onGround)
|
||||
void CXSwiftBusTrafficProxy::setPlaneSurfaces(const QStringList &callsign, const QList<double> &gear, const QList<double> &flap, const QList<double> &spoiler,
|
||||
const QList<double> &speedBrake, const QList<double> &slat, const QList<double> &wingSweep, const QList<double> &thrust,
|
||||
const QList<double> &elevator, const QList<double> &rudder, const QList<double> &aileron, const QList<bool> &landLight,
|
||||
const QList<bool> &beaconLight, const QList<bool> &strobeLight, const QList<bool> &navLight, const QList<int> &lightPattern, const QList<bool> &onGround)
|
||||
{
|
||||
m_dbusInterface->callDBus(QLatin1String("setPlaneSurfaces"), callsign, gear, flap, spoiler, speedBrake, slat, wingSweep, thrust, elevator, rudder, aileron,
|
||||
landLight, beaconLight, strobeLight, navLight, lightPattern, onGround);
|
||||
@@ -116,5 +111,28 @@ namespace BlackSimPlugin
|
||||
{
|
||||
m_dbusInterface->callDBus(QLatin1String("requestRemoteAircraftData"));
|
||||
}
|
||||
|
||||
void CXSwiftBusTrafficProxy::getEelevationAtPosition(const CCallsign &callsign, double latitude, double longitude, double altitude,
|
||||
const ElevationCallback &setter)
|
||||
{
|
||||
std::function<void(QDBusPendingCallWatcher *)> callback = [=](QDBusPendingCallWatcher * watcher)
|
||||
{
|
||||
QDBusPendingReply<QString, double> reply = *watcher;
|
||||
if (!reply.isError())
|
||||
{
|
||||
CCallsign cs(reply.argumentAt<0>());
|
||||
double elevationMeters = reply.argumentAt<1>();
|
||||
CAltitude elevationAlt(elevationMeters, CLengthUnit::m());
|
||||
elevationAlt.switchUnit(CLengthUnit::ft());
|
||||
CElevationPlane elevation(CLatitude(latitude, CAngleUnit::deg()),
|
||||
CLongitude(longitude, CAngleUnit::deg()),
|
||||
elevationAlt);
|
||||
elevation.setSinglePointRadius();
|
||||
setter(elevation, cs);
|
||||
}
|
||||
watcher->deleteLater();
|
||||
};
|
||||
m_dbusInterface->callDBusAsync(QLatin1String("getEelevationAtPosition"), callback, callsign.asString(), latitude, longitude, altitude);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#define BLACKSIMPLUGIN_XSWIFTBUS_TRAFFIC_PROXY_H
|
||||
|
||||
#include "blackmisc/genericdbusinterface.h"
|
||||
#include "blackmisc/aviation/callsign.h"
|
||||
#include "blackmisc/geo/elevationplane.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
@@ -37,6 +39,8 @@ namespace BlackSimPlugin
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
using ElevationCallback = std::function<void (const BlackMisc::Geo::CElevationPlane &, const BlackMisc::Aviation::CCallsign &)>;
|
||||
|
||||
//! Service name
|
||||
static const QString &InterfaceName()
|
||||
{
|
||||
@@ -100,19 +104,15 @@ namespace BlackSimPlugin
|
||||
//! \copydoc XSwiftBus::CTraffic::removeAllPlanes
|
||||
void removeAllPlanes();
|
||||
|
||||
//! \deprecated XSwiftBus::CTraffic::addPlanePosition
|
||||
void addPlanePosition(const QString &callsign, double latitude, double longitude, double altitude, double pitch, double roll, double heading, qint64 relativeTime, qint64 timeOffset);
|
||||
|
||||
//! \copydoc XSwiftBus::CTraffic::setPlanePosition
|
||||
void setPlanePosition(const QString &callsign, double latitude, double longitude, double altitude, double pitch, double roll, double heading);
|
||||
|
||||
//! \deprecated XSwiftBus::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, qint64 timeOffset);
|
||||
//! \copydoc XSwiftBus::CTraffic::setPlanePositions
|
||||
void setPlanePositions(const QStringList &callsigns, const QList<double> &latitudes, const QList<double> &longitudes, const QList<double> &altitudes,
|
||||
const QList<double> &pitches, const QList<double> &rolles, const QList<double> &headings);
|
||||
|
||||
//! \copydoc XSwiftBus::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, bool onGround);
|
||||
void setPlaneSurfaces(const QStringList &callsign, const QList<double> &gear, const QList<double> &flap, const QList<double> &spoiler,
|
||||
const QList<double> &speedBrake, const QList<double> &slat, const QList<double> &wingSweep, const QList<double> &thrust,
|
||||
const QList<double> &elevator, const QList<double> &rudder, const QList<double> &aileron, const QList<bool> &landLight,
|
||||
const QList<bool> &beaconLight, const QList<bool> &strobeLight, const QList<bool> &navLight, const QList<int> &lightPattern, const QList<bool> &onGround);
|
||||
|
||||
//! \copydoc XSwiftBus::CTraffic::setPlaneTransponder
|
||||
void setPlaneTransponder(const QString &callsign, int code, bool modeC, bool ident);
|
||||
@@ -123,6 +123,10 @@ namespace BlackSimPlugin
|
||||
//! \copydoc XSwiftBus::CTraffic::requestRemoteAircraftData
|
||||
void requestRemoteAircraftData();
|
||||
|
||||
//! \copydoc XSwiftBus::CTraffic::getEelevationAtPosition
|
||||
void getEelevationAtPosition(const BlackMisc::Aviation::CCallsign &callsign, double latitude, double longitude, double altitude,
|
||||
const ElevationCallback &setter);
|
||||
|
||||
private:
|
||||
BlackMisc::CGenericDBusInterface *m_dbusInterface = nullptr;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user