swift
fgswiftbusserviceproxy.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2019 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include <QLatin1String>
7 #include <QPointer>
8 
9 #include "simulatorflightgear.h"
10 
11 class QDBusConnection;
12 
13 #define FGSWIFTBUS_SERVICE_SERVICENAME "org.swift-project.fgswiftbus"
14 
15 namespace swift::simplugin::flightgear
16 {
17  CFGSwiftBusServiceProxy::CFGSwiftBusServiceProxy(QDBusConnection &connection, QObject *parent, bool dummy)
18  : QObject(parent)
19  {
20  m_dbusInterface = new swift::misc::CGenericDBusInterface(FGSWIFTBUS_SERVICE_SERVICENAME, ObjectPath(),
21  InterfaceName(), connection, this);
22  if (!dummy)
23  {
24  bool s;
25  s = connection.connect(
26  QString(), "/fgswiftbus/service", "org.swift_project.fgswiftbus.service", "aircraftModelChanged", this,
27  SIGNAL(aircraftModelChanged(QString, QString, QString, QString, QString, QString, QString)));
28  Q_ASSERT(s);
29 
30  s = connection.connect(
31  QString(), "/fgswiftbus/service", "org.swift_project.fgswiftbus.service", "airportsInRangeUpdated",
32  this,
33  SIGNAL(airportsInRangeUpdated(QStringList, QStringList, QList<double>, QList<double>, QList<double>)));
34  Q_ASSERT(s);
35  }
36  }
37 
39  {
40  return m_dbusInterface->callDBusRet<int>(QLatin1String("getVersionNumber"));
41  }
42 
44  {
45  if (!o_flightgearData) { return; }
46  QPointer<CFGSwiftBusServiceProxy> myself(this);
47  std::function<void(QDBusPendingCallWatcher *)> callback = [=](QDBusPendingCallWatcher *watcher) {
48  if (!myself) { return; }
49  QDBusPendingReply<double, double, double, double, double, double, double, double> reply = *watcher;
50  if (!reply.isError())
51  {
52  o_flightgearData->latitudeDeg = reply.argumentAt<0>();
53  o_flightgearData->longitudeDeg = reply.argumentAt<1>();
54  o_flightgearData->altitudeFt = reply.argumentAt<2>();
55  o_flightgearData->groundspeedKts = reply.argumentAt<3>();
56  o_flightgearData->pitchDeg = reply.argumentAt<4>();
57  o_flightgearData->rollDeg = reply.argumentAt<5>();
58  o_flightgearData->trueHeadingDeg = reply.argumentAt<6>();
59  o_flightgearData->pressureAltitudeFt = reply.argumentAt<7>();
60  }
61  watcher->deleteLater();
62  };
63  m_dbusInterface->callDBusAsync(QLatin1String("getOwnAircraftSituationData"), callback);
64  }
65 
67  {
68  if (!o_flightgearData) { return; }
69  QPointer<CFGSwiftBusServiceProxy> myself(this);
70  std::function<void(QDBusPendingCallWatcher *)> callback = [=](QDBusPendingCallWatcher *watcher) {
71  if (!myself) { return; }
72  QDBusPendingReply<double, double, double, double, double, double> reply = *watcher;
73  if (!reply.isError())
74  {
75  o_flightgearData->velocityXMs = reply.argumentAt<0>();
76  o_flightgearData->velocityYMs = reply.argumentAt<1>();
77  o_flightgearData->velocityZMs = reply.argumentAt<2>();
78  o_flightgearData->pitchRateRadPerSec = reply.argumentAt<3>();
79  o_flightgearData->rollRateRadPerSec = reply.argumentAt<4>();
80  o_flightgearData->yawRateRadPerSec = reply.argumentAt<5>();
81  }
82  watcher->deleteLater();
83  };
84  m_dbusInterface->callDBusAsync(QLatin1String("getOwnAircraftVelocityData"), callback);
85  }
86 
87  void CFGSwiftBusServiceProxy::addTextMessage(const QString &text)
88  {
89  m_dbusInterface->callDBus(QLatin1String("addTextMessage"), text);
90  }
91 
93  {
94  return m_dbusInterface->callDBusRet<QString>(QLatin1String("getAircraftModelPath"));
95  }
97  {
98  m_dbusInterface->callDBusAsync(QLatin1String("getAircraftModelPath"), setterCallback(o_modelPath));
99  }
100 
102  {
103  return m_dbusInterface->callDBusRet<QString>(QLatin1String("getAircraftModelFilename"));
104  }
106  {
107  m_dbusInterface->callDBusAsync(QLatin1String("getAircraftModelFilename"), setterCallback(o_modelFilename));
108  }
109 
111  {
112  return m_dbusInterface->callDBusRet<QString>(QLatin1String("getAircraftLivery"));
113  }
115  {
116  m_dbusInterface->callDBusAsync(QLatin1String("getAircraftLivery"), setterCallback(o_modelLivery));
117  }
118 
120  {
121  return m_dbusInterface->callDBusRet<QString>(QLatin1String("getAircraftIcaoCode"));
122  }
124  {
125  m_dbusInterface->callDBusAsync(QLatin1String("getAircraftIcaoCode"), setterCallback(o_icaoCode));
126  }
127 
129  {
130  return m_dbusInterface->callDBusRet<QString>(QLatin1String("getAircraftDescription"));
131  }
133  {
134  m_dbusInterface->callDBusAsync(QLatin1String("getAircraftDescription"), setterCallback(o_description));
135  }
136 
138  {
139  return m_dbusInterface->callDBusRet<QString>(QLatin1String("getAircraftModelString"));
140  }
142  {
143  m_dbusInterface->callDBusAsync(QLatin1String("getAircraftModelString"), setterCallback(o_modelString));
144  }
145 
147  {
148  return m_dbusInterface->callDBusRet<QString>(QLatin1String("getAircraftName"));
149  }
151  {
152  m_dbusInterface->callDBusAsync(QLatin1String("getAircraftName"), setterCallback(o_name));
153  }
154 
156  {
157  return m_dbusInterface->callDBusRet<bool>(QLatin1String("isPaused"));
158  }
160  {
161  m_dbusInterface->callDBusAsync(QLatin1String("isPaused"), setterCallback(o_paused));
162  }
163 
165  {
166  return m_dbusInterface->callDBusRet<double>(QLatin1String("getLatitudeDeg"));
167  }
169  {
170  m_dbusInterface->callDBusAsync(QLatin1String("getLatitudeDeg"), setterCallback(o_latitude));
171  }
172 
174  {
175  return m_dbusInterface->callDBusRet<double>(QLatin1String("getLongitudeDeg"));
176  }
178  {
179  m_dbusInterface->callDBusAsync(QLatin1String("getLongitudeDeg"), setterCallback(o_longitude));
180  }
181 
183  {
184  return m_dbusInterface->callDBusRet<double>(QLatin1String("getAltitudeMslFt"));
185  }
187  {
188  m_dbusInterface->callDBusAsync(QLatin1String("getAltitudeMslFt"), setterCallback(o_altitude));
189  }
190 
192  {
193  return m_dbusInterface->callDBusRet<double>(QLatin1String("getHeightAglFt"));
194  }
196  {
197  m_dbusInterface->callDBusAsync(QLatin1String("getHeightAglFt"), setterCallback(o_height));
198  }
199 
201  {
202  return m_dbusInterface->callDBusRet<double>(QLatin1String("getGroundSpeedKts"));
203  }
205  {
206  m_dbusInterface->callDBusAsync(QLatin1String("getGroundSpeedKts"), setterCallback(o_groundspeed));
207  }
208 
210  {
211  return m_dbusInterface->callDBusRet<double>(QLatin1String("getPitchDeg"));
212  }
214  {
215  m_dbusInterface->callDBusAsync(QLatin1String("getPitchDeg"), setterCallback(o_pitch));
216  }
217 
219  {
220  return m_dbusInterface->callDBusRet<double>(QLatin1String("getRollDeg"));
221  }
223  {
224  m_dbusInterface->callDBusAsync(QLatin1String("getRollDeg"), setterCallback(o_roll));
225  }
226 
228  {
229  return m_dbusInterface->callDBusRet<bool>(QLatin1String("getAllWheelsOnGround"));
230  }
232  {
233  m_dbusInterface->callDBusAsync(QLatin1String("getAllWheelsOnGround"), setterCallback(o_allWheels));
234  }
235 
237  {
238  return m_dbusInterface->callDBusRet<int>(QLatin1String("getCom1ActiveKhz"));
239  }
241  {
242  m_dbusInterface->callDBusAsync(QLatin1String("getCom1ActiveKhz"), setterCallback(o_com1Active));
243  }
244 
246  {
247  return m_dbusInterface->callDBusRet<int>(QLatin1String("getCom1StandbyKhz"));
248  }
250  {
251  m_dbusInterface->callDBusAsync(QLatin1String("getCom1StandbyKhz"), setterCallback(o_com1Standby));
252  }
253 
255  {
256  return m_dbusInterface->callDBusRet<int>(QLatin1String("getCom2ActiveKhz"));
257  }
259  {
260  m_dbusInterface->callDBusAsync(QLatin1String("getCom2ActiveKhz"), setterCallback(o_com2Active));
261  }
262 
264  {
265  return m_dbusInterface->callDBusRet<double>(QLatin1String("getCom1Volume"));
266  }
268  {
269  m_dbusInterface->callDBusAsync(QLatin1String("getCom1Volume"), setterCallbackWithDefault(o_com1Volume, 0.5));
270  }
271 
273  {
274  return m_dbusInterface->callDBusRet<double>(QLatin1String("getCom2Volume"));
275  }
277  {
278  m_dbusInterface->callDBusAsync(QLatin1String("getCom2Volume"), setterCallbackWithDefault(o_com2Volume, 0.5));
279  }
280 
282  {
283  return m_dbusInterface->callDBusRet<int>(QLatin1String("getCom2StandbyKhz"));
284  }
286  {
287  m_dbusInterface->callDBusAsync(QLatin1String("getCom2StandbyKhz"), setterCallback(o_com2Standby));
288  }
289 
291  {
292  return m_dbusInterface->callDBusRet<int>(QLatin1String("getTransponderCode"));
293  }
295  {
296  m_dbusInterface->callDBusAsync(QLatin1String("getTransponderCode"), setterCallback(o_xpdrCode));
297  }
298 
300  {
301  return m_dbusInterface->callDBusRet<int>(QLatin1String("getTransponderMode"));
302  }
304  {
305  m_dbusInterface->callDBusAsync(QLatin1String("getTransponderMode"), setterCallback(o_xpdrMode));
306  }
307 
309  {
310  return m_dbusInterface->callDBusRet<bool>(QLatin1String("getTransponderIdent"));
311  }
313  {
314  m_dbusInterface->callDBusAsync(QLatin1String("getTransponderIdent"), setterCallback(o_ident));
315  }
316 
318  {
319  return m_dbusInterface->callDBusRet<bool>(QLatin1String("getBeaconLightsOn"));
320  }
321 
323  {
324  m_dbusInterface->callDBusAsync(QLatin1String("getBeaconLightsOn"), setterCallback(o_beaconLightsOn));
325  }
326 
328  {
329  return m_dbusInterface->callDBusRet<bool>(QLatin1String("getLandingLightsOn"));
330  }
331 
333  {
334  m_dbusInterface->callDBusAsync(QLatin1String("getLandingLightsOn"), setterCallback(o_landingLightsOn));
335  }
336 
338  {
339  return m_dbusInterface->callDBusRet<bool>(QLatin1String("getNavLightsOn"));
340  }
341 
343  {
344  m_dbusInterface->callDBusAsync(QLatin1String("getNavLightsOn"), setterCallback(o_navLightsOn));
345  }
346 
348  {
349  return m_dbusInterface->callDBusRet<bool>(QLatin1String("getStrobeLightsOn"));
350  }
351 
353  {
354  m_dbusInterface->callDBusAsync(QLatin1String("getStrobeLightsOn"), setterCallback(o_strobeLightsOn));
355  }
356 
358  {
359  return m_dbusInterface->callDBusRet<bool>(QLatin1String("getTaxiLightsOn"));
360  }
361 
363  {
364  m_dbusInterface->callDBusAsync(QLatin1String("getTaxiLightsOn"), setterCallback(o_taxiLightsOn));
365  }
366 
368  {
369  return m_dbusInterface->callDBusRet<double>(QLatin1String("getPressureAltitudeFt"));
370  }
371 
373  {
374  m_dbusInterface->callDBusAsync(QLatin1String("getPressureAltitudeFt"), setterCallback(o_qnh));
375  }
376 
378  {
379  m_dbusInterface->callDBus(QLatin1String("setCom1ActiveKhz"), freq);
380  }
381 
383  {
384  m_dbusInterface->callDBus(QLatin1String("setCom1StandbyKhz"), freq);
385  }
386 
388  {
389  m_dbusInterface->callDBus(QLatin1String("setCom2ActiveKhz"), freq);
390  }
391 
393  {
394  m_dbusInterface->callDBus(QLatin1String("setCom2StandbyKhz"), freq);
395  }
396 
398  {
399  m_dbusInterface->callDBus(QLatin1String("setTransponderCode"), code);
400  }
401 
403  {
404  m_dbusInterface->callDBus(QLatin1String("setTransponderMode"), mode);
405  }
407  {
408  return m_dbusInterface->callDBusRet<double>(QLatin1String("getFlapsDeployRatio"));
409  }
410 
411  void CFGSwiftBusServiceProxy::getFlapsDeployRatioAsync(double *o_flapsDeployRatio)
412  {
413  m_dbusInterface->callDBusAsync(QLatin1String("getFlapsDeployRatio"), setterCallback(o_flapsDeployRatio));
414  }
415 
417  {
418  return m_dbusInterface->callDBusRet<double>(QLatin1String("getGearDeployRatio"));
419  }
420 
421  void CFGSwiftBusServiceProxy::getGearDeployRatioAsync(double *o_gearDeployRatio)
422  {
423  m_dbusInterface->callDBusAsync(QLatin1String("getGearDeployRatio"), setterCallback(o_gearDeployRatio));
424  }
425 
427  {
428  return m_dbusInterface->callDBusRet<QList<double>>(QLatin1String("getEngineN1Percentage"));
429  }
430 
431  void CFGSwiftBusServiceProxy::getEngineN1PercentageAsync(QList<double> *o_engineN1Percentage)
432  {
433  m_dbusInterface->callDBusAsync(QLatin1String("getEngineN1Percentage"), setterCallback(o_engineN1Percentage));
434  }
435 
437  {
438  return m_dbusInterface->callDBusRet<double>(QLatin1String("getSpeedBrakeRatio"));
439  }
440 
441  void CFGSwiftBusServiceProxy::getSpeedBrakeRatioAsync(double *o_speedBrakeRatio)
442  {
443  m_dbusInterface->callDBusAsync(QLatin1String("getSpeedBrakeRatio"), setterCallback(o_speedBrakeRatio));
444  }
445 
447  {
448  return m_dbusInterface->callDBusRet<double>(QLatin1String("getGroundElevation"));
449  }
450 
451  void CFGSwiftBusServiceProxy::getGroundElevationAsync(double *o_groundElevation)
452  {
453  m_dbusInterface->callDBusAsync(QLatin1String("getGroundElevation"), setterCallback(o_groundElevation));
454  }
455 } // namespace swift::simplugin::flightgear
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...
void getRollDegAsync(double *o_roll)
Get aircraft roll in degrees.
int getTransponderMode() const
Get the current transponder mode (depends on the aircraft, 0 and 1 usually mean standby,...
double getGroundElevation() const
Get ground elevation [m] for current airplane position.
void getOwnAircraftSituationData(FlightgearData *o_flightgearData)
Get own aircraft situation data.
QString getAircraftModelFilename() const
Get base filename of current aircraft model.
void getGroundElevationAsync(double *o_groundElevation)
Get ground elevation [m] for current airplane position.
bool getLandingLightsOn() const
Get whether landing lights are on.
bool getTaxiLightsOn() const
Get whether taxi lights are on.
void getAircraftModelPathAsync(QString *o_modelPath)
Get full path to current aircraft model.
void setCom2StandbyKhz(int freq)
Set the current COM2 standby frequency in kHz.
double getFlapsDeployRatio() const
Get flaps deploy ratio, where 0.0 is flaps fully retracted, and 1.0 is flaps fully extended.
double getGroundSpeedKts() const
Get aircraft groundspeed in knots.
QString getAircraftModelString() const
Get canonical swift model string of current aircraft model.
void getAircraftModelStringAsync(QString *o_modelString)
Get canonical swift model string of current aircraft model.
QString getAircraftName() const
Get name of current aircraft model.
double getHeightAglFt() const
Get aircraft height in feet.
QString getAircraftIcaoCode() const
Get the ICAO code of the current aircraft model.
double getGearDeployRatio() const
Get gear deploy ratio, where 0 is up and 1 is down.
void getGroundSpeedKtsAsync(double *o_groundspeed)
Get aircraft groundspeed in knots.
double getLatitudeDeg() const
Get aircraft latitude in degrees.
void getCom2StandbyKhzAsync(int *o_com2Standby)
Get the current COM2 standby frequency in kHz.
void getCom2VolumeAsync(double *o_com2Volume)
Get Com2 volume [0..1].
bool getAllWheelsOnGround() const
Get whether all wheels are on the ground.
void setCom1StandbyKhz(int freq)
Set the current COM1 standby frequency in kHz.
void getStrobeLightsOnAsync(bool *o_strobeLightsOn)
Get whether strobe lights are on.
void getCom1VolumeAsync(double *o_com1Volume)
Get Com1 volume [0..1].
QString getAircraftLivery() const
Get current aircraft livery.
void getLandingLightsOnAsync(bool *o_landingLightsOn)
Get whether landing lights are on.
bool getNavLightsOn() const
Get whether nav lights are on.
void getLongitudeDegAsync(double *o_longitude)
Get aircraft longitude in degrees.
bool getBeaconLightsOn() const
Get whether beacon lights are on.
int getCom1ActiveKhz() const
Get the current COM1 active frequency in kHz.
void getAircraftDescriptionAsync(QString *o_description)
Get the description of the current aircraft model.
bool getStrobeLightsOn() const
Get whether strobe lights are on.
void getTaxiLightsOnAsync(bool *o_taxiLightsOn)
Get whether taxi lights are on.
void getPitchDegAsync(double *o_pitch)
Get aircraft pitch in degrees above horizon.
void getTransponderModeAsync(int *o_xpdrMode)
Get the current transponder mode (depends on the aircraft, 0 and 1 usually mean standby,...
void getAircraftNameAsync(QString *o_name)
Get name of current aircraft model.
void getNavLightsOnAsync(bool *o_navLightsOn)
Get whether nav lights are on.
void getAllWheelsOnGroundAsync(bool *o_allWheels)
Get whether all wheels are on the ground.
void getLatitudeDegAsync(double *o_latitude)
Get aircraft latitude in degrees.
int getCom2StandbyKhz() const
Get the current COM2 standby frequency in kHz.
QList< double > getEngineN1Percentage() const
Get the N1 speed as percent of max (per engine)
void getCom2ActiveKhzAsync(int *o_com2Active)
Get the current COM2 active frequency in kHz.
void getPressureAltitudeFtAsync(double *o_qnh)
Get pressure altitude in feet.
QString getAircraftDescription() const
Get the description of the current aircraft model.
void getCom1ActiveKhzAsync(int *o_com1Active)
Get the current COM1 active frequency in kHz.
void setCom2ActiveKhz(int freq)
Set the current COM2 active frequency in kHz.
double getSpeedBrakeRatio() const
Get the ratio how much the speedbrakes surfaces are extended (0.0 is fully retracted,...
void isPausedAsync(bool *o_paused)
True if sim is paused.
void getAircraftIcaoCodeAsync(QString *o_icaoCode)
Get the ICAO code of the current aircraft model.
void getTransponderIdentAsync(bool *o_ident)
Get whether we are currently squawking ident.
int getCom2ActiveKhz() const
Get the current COM2 active frequency in kHz.
bool getTransponderIdent() const
Get whether we are currently squawking ident.
void setTransponderCode(int code)
Set the current transponder code in decimal.
void getGearDeployRatioAsync(double *o_gearDeployRatio)
Get gear deploy ratio, where 0 is up and 1 is down.
void getSpeedBrakeRatioAsync(double *o_speedBrakeRatio)
Get the ratio how much the speedbrakes surfaces are extended (0.0 is fully retracted,...
void aircraftModelChanged(const QString &path, const QString &filename, const QString &livery, const QString &icao, const QString &modelString, const QString &name, const QString &description)
Own aircraft model changed.
double getAltitudeMslFt() const
Get aircraft altitude in feet.
void getBeaconLightsOnAsync(bool *o_beaconLightsOn)
Get whether beacon lights are on.
void getAltitudeMslFtAsync(double *o_altitude)
Get aircraft altitude in feet.
void getHeightAglFtAsync(double *o_height)
Get aircraft height in feet.
void getFlapsDeployRatioAsync(double *o_flapsDeployRatio)
Get flaps deploy ratio, where 0.0 is flaps fully retracted, and 1.0 is flaps fully extended.
void getAircraftModelFilenameAsync(QString *o_modelFilename)
Get base filename of current aircraft model.
double getPitchDeg() const
Get aircraft pitch in degrees above horizon.
void getTransponderCodeAsync(int *o_xpdrCode)
Get the current transponder code in decimal.
double getPressureAltitudeFt() const
Get pressure altitude in feet.
void getEngineN1PercentageAsync(QList< double > *o_engineN1Percentage)
Get the N1 speed as percent of max (per engine)
void getCom1StandbyKhzAsync(int *o_com1Standby)
Get the current COM1 standby frequency in kHz.
void setTransponderMode(int mode)
Set the current transponder mode (depends on the aircraft, 0 and 1 usually mean standby,...
void getAircraftLiveryAsync(QString *o_modelLivery)
Get current aircraft livery.
QString getAircraftModelPath() const
Get full path to current aircraft model.
int getCom1StandbyKhz() const
Get the current COM1 standby frequency in kHz.
CFGSwiftBusServiceProxy(QDBusConnection &connection, QObject *parent=nullptr, bool dummy=false)
Constructor.
void setCom1ActiveKhz(int freq)
Set the current COM1 active frequency in kHz.
double getRollDeg() const
Get aircraft roll in degrees.
int getTransponderCode() const
Get the current transponder code in decimal.
void getOwnAircraftVelocityData(FlightgearData *o_flightgearData)
Get own aircraft velocity data.
double getLongitudeDeg() const
Get aircraft longitude in degrees.
void addTextMessage(const QString &text)
Add a text message to the on-screen display.
double pressureAltitudeFt
Pressure altitude [inhg].
double rollRateRadPerSec
Roll angular velocity [rad/s].
double pitchRateRadPerSec
Pitch angular velocity [rad/s].
double yawRateRadPerSec
Yaw angular velocity [rad/s].