6 #include <QDBusConnection>
7 #include <QLatin1String>
9 #define FGSWIFTBUS_SERVICENAME "org.swift-project.fgswiftbus"
11 using namespace swift::misc::aviation;
12 using namespace swift::misc::geo;
13 using namespace swift::misc::physical_quantities;
15 namespace swift::simplugin::flightgear
17 CFGSwiftBusTrafficProxy::CFGSwiftBusTrafficProxy(QDBusConnection &connection, QObject *parent,
bool dummy)
25 s = connection.connect(QString(),
"/fgswiftbus/traffic",
"org.swift_project.fgswiftbus.traffic",
"simFrame",
29 s = connection.connect(QString(),
"/fgswiftbus/traffic",
"org.swift_project.fgswiftbus.traffic",
33 s = connection.connect(QString(),
"/fgswiftbus/traffic",
"org.swift_project.fgswiftbus.traffic",
41 QDBusPendingReply<bool, QString> reply = m_dbusInterface->asyncCall(QLatin1String(
"acquireMultiplayerPlanes"));
42 reply.waitForFinished();
50 info.
owner = reply.argumentAt<1>();
56 return m_dbusInterface->
callDBusRet<
bool>(QLatin1String(
"initialize"));
62 const QString &aircraftIcao,
const QString &airlineIcao,
63 const QString &livery)
65 m_dbusInterface->
callDBus(QLatin1String(
"addPlane"), callsign, modelName, aircraftIcao, airlineIcao, livery);
70 m_dbusInterface->
callDBus(QLatin1String(
"removePlane"), callsign);
77 m_dbusInterface->
callDBus(QLatin1String(
"setPlanesPositions"), planesPositions.
callsigns,
86 m_dbusInterface->
callDBus(QLatin1String(
"setPlanesSurfaces"), planesSurfaces.
callsigns, planesSurfaces.
gears,
96 m_dbusInterface->
callDBus(QLatin1String(
"setPlanesTransponders"), planesTransponders.
callsigns,
103 std::function<void(QDBusPendingCallWatcher *)> callback = [=](QDBusPendingCallWatcher *watcher) {
104 QDBusPendingReply<QStringList, QList<double>, QList<double>, QList<double>, QList<double>> reply = *watcher;
105 if (!reply.isError())
107 const QStringList callsigns = reply.argumentAt<0>();
108 const QList<double> latitudesDeg = reply.argumentAt<1>();
109 const QList<double> longitudesDeg = reply.argumentAt<2>();
110 const QList<double> elevationsM = reply.argumentAt<3>();
111 const QList<double> verticalOffsets = reply.argumentAt<4>();
112 setter(callsigns, latitudesDeg, longitudesDeg, elevationsM, verticalOffsets);
114 watcher->deleteLater();
116 m_dbusInterface->
callDBusAsync(QLatin1String(
"getRemoteAircraftData"), callback, callsigns);
120 double longitudeDeg,
double altitudeMeters,
123 std::function<void(QDBusPendingCallWatcher *)> callback = [=](QDBusPendingCallWatcher *watcher) {
124 QDBusPendingReply<QString, double> reply = *watcher;
125 if (!reply.isError())
127 const CCallsign cs(reply.argumentAt<0>());
128 const double elevationMeters = reply.argumentAt<1>();
129 const CAltitude elevationAlt = std::isnan(elevationMeters) ?
131 CAltitude(elevationMeters, CLengthUnit::m(), CLengthUnit::ft());
133 CLongitude(longitudeDeg, CAngleUnit::deg()), elevationAlt,
134 CElevationPlane::singlePointRadius());
135 setter(elevation, cs);
137 watcher->deleteLater();
139 m_dbusInterface->
callDBusAsync(QLatin1String(
"getElevationAtPosition"), callback, callsign.
asString(),
140 latitudeDeg, longitudeDeg, altitudeMeters);
Used for hand written interface based on virtual methods.
void callDBus(QLatin1String method, Args &&...args)
Call DBus, no return value.
Ret callDBusRet(QLatin1String method, Args &&...args)
Call DBus with synchronous return value.
QDBusPendingCallWatcher * callDBusAsync(QLatin1String method, Func callback, Args &&...args)
Call DBus with asynchronous return value Callback can be any callable object taking a single argument...
Class for emitting a log message.
Derived & error(const char16_t(&format)[N])
Set the severity to error, providing a format string.
Derived & debug()
Set the severity to debug.
QString message() const
Private.
Altitude as used in aviation, can be AGL or MSL altitude.
Value object encapsulating information of a callsign.
const QString & asString() const
Get callsign (normalized)
Plane of same elevation, can be a single point or larger area (e.g. airport)
void remoteAircraftAdded(const QString &callsign)
Remote aircraft successfully added.
void setPlanesTransponders(const swift::simplugin::flightgear::PlanesTransponders &planesTransponders)
Set the transponders of multiple traffic aircrafts.
static const QString & ObjectPath()
Service path.
void setPlanesSurfaces(const swift::simplugin::flightgear::PlanesSurfaces &planesSurfaces)
Set the surfaces of multiple traffic aircrafts.
void cleanup()
Reverse the actions of initialize().
std::function< void(const QStringList &, const QDoubleList &, const QDoubleList &, const QDoubleList &, const QDoubleList &)> RemoteAircraftDataCallback
Remote aircrafts data callback.
void remoteAircraftAddingFailed(const QString &callsign)
Remote aircraft adding failed.
void addPlane(const QString &callsign, const QString &modelName, const QString &aircraftIcao, const QString &airlineIcao, const QString &livery)
Introduce a new traffic aircraft.
bool initialize()
Initialize the multiplayer planes rendering and return true if successful.
void simFrame()
Simulator frame.
MultiplayerAcquireInfo acquireMultiplayerPlanes()
Returns whether multiplayer planes have been acquired. If not, owner will be set to the plugin that a...
void getElevationAtPosition(const swift::misc::aviation::CCallsign &callsign, double latitudeDeg, double longitudeDeg, double altitudeMeters, const ElevationCallback &setter) const
Get the ground elevation at an arbitrary position.
std::function< void(const swift::misc::geo::CElevationPlane &, const swift::misc::aviation::CCallsign &)> ElevationCallback
Elevation callback.
void getRemoteAircraftData(const QStringList &callsigns, const RemoteAircraftDataCallback &setter) const
Get remote aircrafts data (lat, lon, elevation and CG)
void removePlane(const QString &callsign)
Remove a traffic aircraft.
void setPlanesPositions(const swift::simplugin::flightgear::PlanesPositions &planesPositions)
Set the position of multiple traffic aircrafts.
static const QString & InterfaceName()
Service name.
void removeAllPlanes()
Remove all traffic aircraft.
Multiplayer Acquire Info.
QString owner
Name of the plugin having multiplayer planes acquired.
bool hasAcquired
Has FGSwiftBus acquired multiplayer planes?
QList< double > rollsDeg
List of rolls.
QList< bool > onGrounds
List of onGrounds.
QList< double > altitudesFt
List of altitudes.
QList< double > latitudesDeg
List of latitudes.
QList< double > longitudesDeg
List of longitudes.
QList< double > groundSpeedKts
List of groundspeeds.
QList< double > headingsDeg
List of headings.
QStringList callsigns
List of callsigns.
QList< double > pitchesDeg
List of pitches.
QList< bool > strobeLights
List of strobeLights.
QList< double > slats
List of slats.
QList< double > thrusts
List of thrusts.
QList< double > ailerons
List of ailerons.
QList< double > wingSweeps
List of wingSweeps.
QList< double > gears
List of gears.
QList< bool > taxiLights
List of taxi lights.
QList< double > spoilers
List of spoilers.
QList< int > lightPatterns
List of lightPatterns.
QList< double > speedBrakes
List of speedBrakes.
QList< double > rudders
List of rudders.
QList< double > elevators
List of elevators.
QStringList callsigns
List of callsigns.
QList< bool > landLights
List of landLights.
QList< bool > beaconLights
List of beaconLights.
QList< double > flaps
List of flaps.
QList< bool > navLights
List of navLights.
QStringList callsigns
List of callsigns.
QList< int > codes
List of transponder codes.
QList< bool > modeCs
List of active mode C's.
QList< bool > idents
List of active idents.