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 {
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,
28  Q_ASSERT(s);
29  }
30  }
31 
33  {
34  return m_dbusInterface->callDBusRet<int>(QLatin1String("getVersionNumber"));
35  }
36 
38  {
39  if (!o_flightgearData) { return; }
41  std::function<void(QDBusPendingCallWatcher *)> callback = [=](QDBusPendingCallWatcher *watcher) {
42  if (!myself) { return; }
44  if (!reply.isError())
45  {
46  o_flightgearData->latitudeDeg = reply.argumentAt<0>();
47  o_flightgearData->longitudeDeg = reply.argumentAt<1>();
48  o_flightgearData->altitudeFt = reply.argumentAt<2>();
49  o_flightgearData->groundspeedKts = reply.argumentAt<3>();
50  o_flightgearData->pitchDeg = reply.argumentAt<4>();
51  o_flightgearData->rollDeg = reply.argumentAt<5>();
52  o_flightgearData->trueHeadingDeg = reply.argumentAt<6>();
53  o_flightgearData->pressureAltitudeFt = reply.argumentAt<7>();
54  }
55  watcher->deleteLater();
56  };
57  m_dbusInterface->callDBusAsync(QLatin1String("getOwnAircraftSituationData"), callback);
58  }
59 
61  {
62  if (!o_flightgearData) { return; }
64  std::function<void(QDBusPendingCallWatcher *)> callback = [=](QDBusPendingCallWatcher *watcher) {
65  if (!myself) { return; }
67  if (!reply.isError())
68  {
69  o_flightgearData->velocityXMs = reply.argumentAt<0>();
70  o_flightgearData->velocityYMs = reply.argumentAt<1>();
71  o_flightgearData->velocityZMs = reply.argumentAt<2>();
72  o_flightgearData->pitchRateRadPerSec = reply.argumentAt<3>();
73  o_flightgearData->rollRateRadPerSec = reply.argumentAt<4>();
74  o_flightgearData->yawRateRadPerSec = reply.argumentAt<5>();
75  }
76  watcher->deleteLater();
77  };
78  m_dbusInterface->callDBusAsync(QLatin1String("getOwnAircraftVelocityData"), callback);
79  }
80 
82  {
83  m_dbusInterface->callDBus(QLatin1String("addTextMessage"), text);
84  }
85 
87  {
88  return m_dbusInterface->callDBusRet<QString>(QLatin1String("getAircraftModelPath"));
89  }
91  {
92  m_dbusInterface->callDBusAsync(QLatin1String("getAircraftModelPath"), setterCallback(o_modelPath));
93  }
94 
96  {
97  return m_dbusInterface->callDBusRet<QString>(QLatin1String("getAircraftModelFilename"));
98  }
100  {
101  m_dbusInterface->callDBusAsync(QLatin1String("getAircraftModelFilename"), setterCallback(o_modelFilename));
102  }
103 
105  {
106  return m_dbusInterface->callDBusRet<QString>(QLatin1String("getAircraftLivery"));
107  }
109  {
110  m_dbusInterface->callDBusAsync(QLatin1String("getAircraftLivery"), setterCallback(o_modelLivery));
111  }
112 
114  {
115  return m_dbusInterface->callDBusRet<QString>(QLatin1String("getAircraftIcaoCode"));
116  }
118  {
119  m_dbusInterface->callDBusAsync(QLatin1String("getAircraftIcaoCode"), setterCallback(o_icaoCode));
120  }
121 
123  {
124  return m_dbusInterface->callDBusRet<QString>(QLatin1String("getAircraftDescription"));
125  }
127  {
128  m_dbusInterface->callDBusAsync(QLatin1String("getAircraftDescription"), setterCallback(o_description));
129  }
130 
132  {
133  return m_dbusInterface->callDBusRet<QString>(QLatin1String("getAircraftModelString"));
134  }
136  {
137  m_dbusInterface->callDBusAsync(QLatin1String("getAircraftModelString"), setterCallback(o_modelString));
138  }
139 
141  {
142  return m_dbusInterface->callDBusRet<QString>(QLatin1String("getAircraftName"));
143  }
145  {
146  m_dbusInterface->callDBusAsync(QLatin1String("getAircraftName"), setterCallback(o_name));
147  }
148 
150  {
151  return m_dbusInterface->callDBusRet<bool>(QLatin1String("isPaused"));
152  }
154  {
155  m_dbusInterface->callDBusAsync(QLatin1String("isPaused"), setterCallback(o_paused));
156  }
157 
159  {
160  return m_dbusInterface->callDBusRet<double>(QLatin1String("getLatitudeDeg"));
161  }
163  {
164  m_dbusInterface->callDBusAsync(QLatin1String("getLatitudeDeg"), setterCallback(o_latitude));
165  }
166 
168  {
169  return m_dbusInterface->callDBusRet<double>(QLatin1String("getLongitudeDeg"));
170  }
172  {
173  m_dbusInterface->callDBusAsync(QLatin1String("getLongitudeDeg"), setterCallback(o_longitude));
174  }
175 
177  {
178  return m_dbusInterface->callDBusRet<double>(QLatin1String("getAltitudeMslFt"));
179  }
181  {
182  m_dbusInterface->callDBusAsync(QLatin1String("getAltitudeMslFt"), setterCallback(o_altitude));
183  }
184 
186  {
187  return m_dbusInterface->callDBusRet<double>(QLatin1String("getHeightAglFt"));
188  }
190  {
191  m_dbusInterface->callDBusAsync(QLatin1String("getHeightAglFt"), setterCallback(o_height));
192  }
193 
195  {
196  return m_dbusInterface->callDBusRet<double>(QLatin1String("getGroundSpeedKts"));
197  }
199  {
200  m_dbusInterface->callDBusAsync(QLatin1String("getGroundSpeedKts"), setterCallback(o_groundspeed));
201  }
202 
204  {
205  return m_dbusInterface->callDBusRet<double>(QLatin1String("getPitchDeg"));
206  }
208  {
209  m_dbusInterface->callDBusAsync(QLatin1String("getPitchDeg"), setterCallback(o_pitch));
210  }
211 
213  {
214  return m_dbusInterface->callDBusRet<double>(QLatin1String("getRollDeg"));
215  }
217  {
218  m_dbusInterface->callDBusAsync(QLatin1String("getRollDeg"), setterCallback(o_roll));
219  }
220 
222  {
223  return m_dbusInterface->callDBusRet<bool>(QLatin1String("getAllWheelsOnGround"));
224  }
226  {
227  m_dbusInterface->callDBusAsync(QLatin1String("getAllWheelsOnGround"), setterCallback(o_allWheels));
228  }
229 
231  {
232  return m_dbusInterface->callDBusRet<int>(QLatin1String("getCom1ActiveKhz"));
233  }
235  {
236  m_dbusInterface->callDBusAsync(QLatin1String("getCom1ActiveKhz"), setterCallback(o_com1Active));
237  }
238 
240  {
241  return m_dbusInterface->callDBusRet<int>(QLatin1String("getCom1StandbyKhz"));
242  }
244  {
245  m_dbusInterface->callDBusAsync(QLatin1String("getCom1StandbyKhz"), setterCallback(o_com1Standby));
246  }
247 
249  {
250  return m_dbusInterface->callDBusRet<int>(QLatin1String("getCom2ActiveKhz"));
251  }
253  {
254  m_dbusInterface->callDBusAsync(QLatin1String("getCom2ActiveKhz"), setterCallback(o_com2Active));
255  }
256 
258  {
259  return m_dbusInterface->callDBusRet<double>(QLatin1String("getCom1Volume"));
260  }
262  {
263  m_dbusInterface->callDBusAsync(QLatin1String("getCom1Volume"), setterCallbackWithDefault(o_com1Volume, 0.5));
264  }
265 
267  {
268  return m_dbusInterface->callDBusRet<double>(QLatin1String("getCom2Volume"));
269  }
271  {
272  m_dbusInterface->callDBusAsync(QLatin1String("getCom2Volume"), setterCallbackWithDefault(o_com2Volume, 0.5));
273  }
274 
276  {
277  return m_dbusInterface->callDBusRet<int>(QLatin1String("getCom2StandbyKhz"));
278  }
280  {
281  m_dbusInterface->callDBusAsync(QLatin1String("getCom2StandbyKhz"), setterCallback(o_com2Standby));
282  }
283 
285  {
286  return m_dbusInterface->callDBusRet<int>(QLatin1String("getTransponderCode"));
287  }
289  {
290  m_dbusInterface->callDBusAsync(QLatin1String("getTransponderCode"), setterCallback(o_xpdrCode));
291  }
292 
294  {
295  return m_dbusInterface->callDBusRet<int>(QLatin1String("getTransponderMode"));
296  }
298  {
299  m_dbusInterface->callDBusAsync(QLatin1String("getTransponderMode"), setterCallback(o_xpdrMode));
300  }
301 
303  {
304  return m_dbusInterface->callDBusRet<bool>(QLatin1String("getTransponderIdent"));
305  }
307  {
308  m_dbusInterface->callDBusAsync(QLatin1String("getTransponderIdent"), setterCallback(o_ident));
309  }
310 
312  {
313  return m_dbusInterface->callDBusRet<bool>(QLatin1String("getBeaconLightsOn"));
314  }
315 
317  {
318  m_dbusInterface->callDBusAsync(QLatin1String("getBeaconLightsOn"), setterCallback(o_beaconLightsOn));
319  }
320 
322  {
323  return m_dbusInterface->callDBusRet<bool>(QLatin1String("getLandingLightsOn"));
324  }
325 
327  {
328  m_dbusInterface->callDBusAsync(QLatin1String("getLandingLightsOn"), setterCallback(o_landingLightsOn));
329  }
330 
332  {
333  return m_dbusInterface->callDBusRet<bool>(QLatin1String("getNavLightsOn"));
334  }
335 
337  {
338  m_dbusInterface->callDBusAsync(QLatin1String("getNavLightsOn"), setterCallback(o_navLightsOn));
339  }
340 
342  {
343  return m_dbusInterface->callDBusRet<bool>(QLatin1String("getStrobeLightsOn"));
344  }
345 
347  {
348  m_dbusInterface->callDBusAsync(QLatin1String("getStrobeLightsOn"), setterCallback(o_strobeLightsOn));
349  }
350 
352  {
353  return m_dbusInterface->callDBusRet<bool>(QLatin1String("getTaxiLightsOn"));
354  }
355 
357  {
358  m_dbusInterface->callDBusAsync(QLatin1String("getTaxiLightsOn"), setterCallback(o_taxiLightsOn));
359  }
360 
362  {
363  return m_dbusInterface->callDBusRet<double>(QLatin1String("getPressureAltitudeFt"));
364  }
365 
367  {
368  m_dbusInterface->callDBusAsync(QLatin1String("getPressureAltitudeFt"), setterCallback(o_qnh));
369  }
370 
372  {
373  m_dbusInterface->callDBus(QLatin1String("setCom1ActiveKhz"), freq);
374  }
375 
377  {
378  m_dbusInterface->callDBus(QLatin1String("setCom1StandbyKhz"), freq);
379  }
380 
382  {
383  m_dbusInterface->callDBus(QLatin1String("setCom2ActiveKhz"), freq);
384  }
385 
387  {
388  m_dbusInterface->callDBus(QLatin1String("setCom2StandbyKhz"), freq);
389  }
390 
392  {
393  m_dbusInterface->callDBus(QLatin1String("setTransponderCode"), code);
394  }
395 
397  {
398  m_dbusInterface->callDBus(QLatin1String("setTransponderMode"), mode);
399  }
401  {
402  return m_dbusInterface->callDBusRet<double>(QLatin1String("getFlapsDeployRatio"));
403  }
404 
405  void CFGSwiftBusServiceProxy::getFlapsDeployRatioAsync(double *o_flapsDeployRatio)
406  {
407  m_dbusInterface->callDBusAsync(QLatin1String("getFlapsDeployRatio"), setterCallback(o_flapsDeployRatio));
408  }
409 
411  {
412  return m_dbusInterface->callDBusRet<double>(QLatin1String("getGearDeployRatio"));
413  }
414 
415  void CFGSwiftBusServiceProxy::getGearDeployRatioAsync(double *o_gearDeployRatio)
416  {
417  m_dbusInterface->callDBusAsync(QLatin1String("getGearDeployRatio"), setterCallback(o_gearDeployRatio));
418  }
419 
421  {
422  return m_dbusInterface->callDBusRet<QList<double>>(QLatin1String("getEngineN1Percentage"));
423  }
424 
426  {
427  m_dbusInterface->callDBusAsync(QLatin1String("getEngineN1Percentage"), setterCallback(o_engineN1Percentage));
428  }
429 
431  {
432  return m_dbusInterface->callDBusRet<double>(QLatin1String("getSpeedBrakeRatio"));
433  }
434 
435  void CFGSwiftBusServiceProxy::getSpeedBrakeRatioAsync(double *o_speedBrakeRatio)
436  {
437  m_dbusInterface->callDBusAsync(QLatin1String("getSpeedBrakeRatio"), setterCallback(o_speedBrakeRatio));
438  }
439 
441  {
442  return m_dbusInterface->callDBusRet<double>(QLatin1String("getGroundElevation"));
443  }
444 
445  void CFGSwiftBusServiceProxy::getGroundElevationAsync(double *o_groundElevation)
446  {
447  m_dbusInterface->callDBusAsync(QLatin1String("getGroundElevation"), setterCallback(o_groundElevation));
448  }
449 } // 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.
bool connect(const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
QVariant argumentAt(int index) const const
bool isError() const const
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].