11#include <simgear/constants.h>
12#include <simgear/debug/logstream.hxx>
13#include <simgear/structure/commands.hxx>
15#define FGSWIFTBUS_API_VERSION 3;
25 m_textMessageNode =
fgGetNode(
"/sim/messages/copilot",
true);
26 m_aircraftModelPathNode =
fgGetNode(
"/sim/aircraft-dir",
true);
27 m_aircraftDescriptionNode =
fgGetNode(
"/sim/description",
true);
28 m_isPausedNode =
fgGetNode(
"/sim/freeze/master",
true);
29 m_latitudeNode =
fgGetNode(
"/position/latitude-deg",
true);
30 m_longitudeNode =
fgGetNode(
"/position/longitude-deg",
true);
31 m_altitudeMSLNode =
fgGetNode(
"/position/altitude-ft",
true);
32 m_heightAGLNode =
fgGetNode(
"/position/altitude-agl-ft",
true);
33 m_groundSpeedNode =
fgGetNode(
"/velocities/groundspeed-kt",
true);
34 m_pitchNode =
fgGetNode(
"/orientation/pitch-deg",
true);
35 m_rollNode =
fgGetNode(
"/orientation/roll-deg",
true);
36 m_trueHeadingNode =
fgGetNode(
"/orientation/heading-deg",
true);
37 m_wheelsOnGroundNode =
fgGetNode(
"/gear/gear/wow",
true);
38 m_com1ActiveNode =
fgGetNode(
"/instrumentation/comm/frequencies/selected-mhz",
true);
39 m_com1StandbyNode =
fgGetNode(
"/instrumentation/comm/frequencies/standby-mhz",
true);
40 m_com2ActiveNode =
fgGetNode(
"/instrumentation/comm[1]/frequencies/selected-mhz",
true);
41 m_com2StandbyNode =
fgGetNode(
"/instrumentation/comm[1]/frequencies/standby-mhz",
true);
42 m_transponderCodeNode =
fgGetNode(
"/instrumentation/transponder/id-code",
true);
43 m_transponderModeNode =
fgGetNode(
"/instrumentation/transponder/inputs/knob-mode",
true);
44 m_transponderIdentNode =
fgGetNode(
"/instrumentation/transponder/ident",
true);
45 m_beaconLightsNode =
fgGetNode(
"/controls/lighting/beacon",
true);
46 m_landingLightsNode =
fgGetNode(
"/controls/lighting/landing-lights",
true);
47 m_navLightsNode =
fgGetNode(
"/controls/lighting/nav-lights",
true);
48 m_strobeLightsNode =
fgGetNode(
"/controls/lighting/strobe",
true);
49 m_taxiLightsNode =
fgGetNode(
"/controls/lighting/taxi-light",
true);
50 m_altimeterServiceableNode =
fgGetNode(
"/instrumentation/altimeter/serviceable",
true);
51 m_pressAltitudeFtNode =
fgGetNode(
"/instrumentation/altimeter/pressure-alt-ft",
true);
52 m_flapsDeployRatioNode =
fgGetNode(
"/surface-positions/flap-pos-norm",
true);
53 m_gearDeployRatioNode =
fgGetNode(
"/gear/gear/position-norm",
true);
54 m_speedBrakeDeployRatioNode =
fgGetNode(
"/surface-positions/speedbrake-pos-norm",
true);
55 m_aircraftNameNode =
fgGetNode(
"/sim/aircraft",
true);
56 m_groundElevationNode =
fgGetNode(
"/position/ground-elev-m",
true);
57 m_velocityXNode =
fgGetNode(
"/velocities/speed-east-fps",
true);
58 m_velocityYNode =
fgGetNode(
"/velocities/speed-down-fps",
true);
59 m_velocityZNode =
fgGetNode(
"/velocities/speed-north-fps",
true);
60 m_rollRateNode =
fgGetNode(
"/orientation/roll-rate-degps",
true);
61 m_pichRateNode =
fgGetNode(
"/orientation/pitch-rate-degps",
true);
62 m_yawRateNode =
fgGetNode(
"/orientation/yaw-rate-degps",
true);
63 m_com1VolumeNode =
fgGetNode(
"/instrumentation/comm/volume",
true);
64 m_com2VolumeNode =
fgGetNode(
"/instrumentation/comm[1]/volume",
true);
66 SG_LOG(SG_NETWORK, SG_INFO,
"FGSwiftBus Service initialized");
87 if (text.empty()) {
return; }
88 m_textMessageNode->setStringValue(text);
93 return m_aircraftModelPathNode->getStringValue();
108 return m_aircraftDescriptionNode->getStringValue();
113 return m_isPausedNode->getBoolValue();
118 return m_latitudeNode->getDoubleValue();
123 return m_longitudeNode->getDoubleValue();
128 return m_altitudeMSLNode->getDoubleValue();
133 return m_heightAGLNode->getDoubleValue();
138 return m_groundSpeedNode->getDoubleValue();
143 return m_pitchNode->getDoubleValue();
148 return m_rollNode->getDoubleValue();
153 return m_trueHeadingNode->getDoubleValue();
158 return m_wheelsOnGroundNode->getBoolValue();
163 return (
int)(m_com1ActiveNode->getDoubleValue() * 1000);
168 return (
int)(m_com1StandbyNode->getDoubleValue() * 1000);
173 return (
int)(m_com2ActiveNode->getDoubleValue() * 1000);
178 return (
int)(m_com2StandbyNode->getDoubleValue() * 1000);
183 return m_transponderCodeNode->getIntValue();
188 return m_transponderModeNode->getIntValue();
193 return m_transponderIdentNode->getBoolValue();
198 return m_beaconLightsNode->getBoolValue();
203 return m_landingLightsNode->getBoolValue();
208 return m_navLightsNode->getBoolValue();
214 return m_strobeLightsNode->getBoolValue();
219 return m_taxiLightsNode->getBoolValue();
224 if (m_altimeterServiceableNode->getBoolValue()) {
225 return m_pressAltitudeFtNode->getDoubleValue();
227 return m_altitudeMSLNode->getDoubleValue();
233 m_com1ActiveNode->setDoubleValue(freq / (
double)1000);
238 m_com1StandbyNode->setDoubleValue(freq / (
double)1000);
243 m_com2ActiveNode->setDoubleValue(freq / (
double)1000);
248 m_com2StandbyNode->setDoubleValue(freq / (
double)1000);
253 m_transponderCodeNode->setIntValue(code);
258 m_transponderModeNode->setIntValue(mode);
263 return m_flapsDeployRatioNode->getFloatValue();
268 return m_gearDeployRatioNode->getFloatValue();
280 std::vector<double> list;
282 list.reserve(number);
283 for (
unsigned int engineNumber = 0; engineNumber < number; ++engineNumber) {
291 return m_speedBrakeDeployRatioNode->getFloatValue();
296 return m_groundElevationNode->getDoubleValue();
302 modelFileName.append(
"-set.xml");
303 return modelFileName;
309 std::string modelString =
"FG " + modelName;
315 return m_aircraftNameNode->getStringValue();
320 return m_velocityXNode->getDoubleValue() * SG_FEET_TO_METER;
325 return m_velocityYNode->getDoubleValue() * SG_FEET_TO_METER * -1;
330 return m_velocityZNode->getDoubleValue() * SG_FEET_TO_METER;
335 return m_rollRateNode->getDoubleValue() * SG_DEGREES_TO_RADIANS;
339 return m_pichRateNode->getDoubleValue() * SG_DEGREES_TO_RADIANS;
344 return m_yawRateNode->getDoubleValue() * SG_DEGREES_TO_RADIANS;
349 return m_com1VolumeNode->getDoubleValue();
354 return m_com2VolumeNode->getDoubleValue();
363 const std::string sender = message.
getSender();
364 const dbus_uint32_t serial = message.
getSerial();
381 }
else if (message.
getMethodName() ==
"getOwnAircraftSituationData") {
403 }
else if (message.
getMethodName() ==
"getOwnAircraftVelocityData") {
425 }
else if (message.
getMethodName() ==
"getAircraftModelPath") {
429 }
else if (message.
getMethodName() ==
"getAircraftModelFilename") {
433 }
else if (message.
getMethodName() ==
"getAircraftModelString") {
445 }
else if (message.
getMethodName() ==
"getAircraftIcaoCode") {
449 }
else if (message.
getMethodName() ==
"getAircraftDescription") {
485 }
else if (message.
getMethodName() ==
"getAllWheelsOnGround") {
505 }
else if (message.
getMethodName() ==
"getTransponderCode") {
509 }
else if (message.
getMethodName() ==
"getTransponderMode") {
513 }
else if (message.
getMethodName() ==
"getTransponderIdent") {
521 }
else if (message.
getMethodName() ==
"getLandingLightsOn") {
541 }
else if (message.
getMethodName() ==
"getGroundElevation") {
577 }
else if (message.
getMethodName() ==
"setTransponderCode") {
585 }
else if (message.
getMethodName() ==
"setTransponderMode") {
593 }
else if (message.
getMethodName() ==
"getFlapsDeployRatio") {
597 }
else if (message.
getMethodName() ==
"getGearDeployRatio") {
601 }
else if (message.
getMethodName() ==
"getEngineN1Percentage") {
606 }
else if (message.
getMethodName() ==
"getSpeedBrakeRatio") {
620 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
623 return DBUS_HANDLER_RESULT_HANDLED;
void appendArgument(bool value)
Append argument.
static CDBusMessage createReply(const std::string &destination, dbus_uint32_t serial)
Creates a DBus message containing a DBus reply.
std::string getSender() const
Get the message sender.
dbus_uint32_t getSerial() const
Get the message serial. This is usally required for reply message.
std::string getMethodName() const
Get the called method name.
std::string getInterfaceName() const
Get the called interface name.
bool wantsReply() const
Does this message want a reply?
void getArgument(int &value)
Read single argument.
void beginArgumentRead()
Begin reading arguments.
void beginArgumentWrite()
Begin writing argument.
void sendDBusMessage(const CDBusMessage &message)
Send DBus message.
void invokeQueuedDBusCalls()
Invoke all pending DBus calls. They will be executed in the calling thread.
void sendDBusReply(const std::string &destination, dbus_uint32_t serial, const T &argument)
Send DBus reply.
void maybeSendEmptyDBusReply(bool wantsReply, const std::string &destination, dbus_uint32_t serial)
Maybe sends an empty DBus reply (acknowledgement)
void queueDBusCall(const std::function< void()> &func)
Queue a DBus call to be executed in a different thread.
std::string getAircraftIcaoCode() const
Get the ICAO code of the current aircraft model.
std::string getAircraftLivery() const
void setCom1Standby(int freq)
Set the current COM1 standby frequency in kHz.
double getHeightAGL() const
Get aircraft height in feet.
double getFlapsDeployRatio() const
Get flaps deploy ratio, where 0.0 is flaps fully retracted, and 1.0 is flaps fully extended.
void setCom2Active(int freq)
Set the current COM2 active frequency in kHz.
void setCom2Standby(int freq)
Set the current COM2 standby frequency in kHz.
double getPressAlt() const
Get pressure altitude in ft.
double getVelocityX() const
Get x velocity in m/s.
double getAltitudeMSL() const
Get aircraft altitude in feet.
void setTransponderCode(int code)
bool getBeaconLightsOn() const
Get whether beacon lights are on.
double getGroundSpeed() const
Get aircraft groundspeed in knots.
void setTransponderMode(int mode)
double getGroundElevation() const
Get ground elevation at aircraft current position.
bool getStrobeLightsOn() const
Get whether strobe lights are on.
double getPitch() const
Get aircraft pitch in degrees above horizon.
bool getLandingLightsOn() const
Get whether landing lights are on.
static const std::string & ObjectPath()
DBus object path.
double getVelocityY() const
Get y velocity in m/s.
DBusHandlerResult dbusMessageHandler(const CDBusMessage &message) override
DBus message handler.
bool getTaxiLightsOn() const
Get whether taxi lights are on.
std::string getAircraftModelFilename() const
std::string getAircraftDescription() const
std::string getAircraftModelPath() const
void setCom1Active(int freq)
Set the current COM1 active frequency in kHz.
int process()
Perform generic processing.
int getTransponderMode() const
Get the current transponder mode (depends on the aircraft, 0-2 usually mean standby,...
double getSpeedBrakeRatio() const
Get the ratio how much the speedbrakes surfaces are extended (0.0 is fully retracted,...
int getCom2Active() const
Get the current COM2 active frequency in kHz.
double getRollRate() const
Get roll rate in rad/sec.
double getPitchRate() const
Get pitch rate in rad/sec.
int getCom2Standby() const
Get the current COM2 standby frequency in kHz.
int getTransponderCode() const
Get the current transponder code in decimal.
static int getVersionNumber()
Getting flightgear version.
std::vector< double > getEngineN1Percentage() const
Get the N1 speed as percent of max (per engine)
double getTrueHeading() const
Get aircraft true heading in degrees.
double getLatitude() const
Get aircraft latitude in degrees.
double getVelocityZ() const
Get z velocity in m/s.
std::string getAircraftModelString() const
bool getAllWheelsOnGround() const
Get whether all wheels are on the ground.
double getGearDeployRatio() const
Get gear deploy ratio, where 0 is up and 1 is down.
bool isPaused() const
True if sim is paused.
double getLongitude() const
Get aircraft longitude in degrees.
double getYawRate() const
Get yaw rate in rad/sec.
int getNumberOfEngines() const
Get the number of engines of current aircraft.
int getCom1Active() const
Get the current COM1 active frequency in kHz.
bool getNavLightsOn() const
Get whether nav lights are on.
bool getTransponderIdent() const
Get whether we are currently squawking ident.
double getCom2Volume() const
double getRoll() const
Get aircraft roll in degrees.
void addTextMessage(const std::string &text)
int getCom1Standby() const
Get the current COM1 standby frequency in kHz.
std::string getAircraftName() const
static const std::string & InterfaceName()
DBus interface name.
double getCom1Volume() const
static const char * introspection_service
static const std::string k_fgswiftbus_service_interfacename
static const std::string k_fgswiftbus_service_objectpath
double fgGetDouble(const char *name, double defaultValue)
Get a double value for a property.
SGPropertyNode * fgGetNode(const char *path, bool create)
Get a property node.
#define FGSWIFTBUS_API_VERSION