4#ifndef SWIFT_SIM_XSWIFTBUS_SERVICE_H
5#define SWIFT_SIM_XSWIFTBUS_SERVICE_H
14#include "dbusobject.h"
17#include "terrainprobe.h"
18#include "custom_datarefs.h"
19#include <XPLM/XPLMNavigation.h>
26#define XSWIFTBUS_SERVICE_INTERFACENAME "org.swift_project.xswiftbus.service"
27#define XSWIFTBUS_SERVICE_OBJECTPATH "/xswiftbus/service"
47 static const std::string s(XSWIFTBUS_SERVICE_INTERFACENAME);
54 static const std::string s(XSWIFTBUS_SERVICE_OBJECTPATH);
71 void addTextMessage(
const std::string &text,
double red,
double green,
double blue);
142 return m_pressureAlt.isValid() ? m_pressureAlt.get() : std::numeric_limits<double>::quiet_NaN();
189 return m_terrainProbe.getElevation(m_latitude.get(), m_longitude.get(), m_elevation.get())[0];
298 std::vector<double> list;
300 list.reserve(
static_cast<std::vector<double>::size_type
>(number));
301 for (
int engineNumber = 0; engineNumber < number; ++engineNumber)
303 list.push_back(m_enginesN1Percentage.getAt(engineNumber));
337 void emitAircraftModelChanged(
const std::string &path,
const std::string &filename,
const std::string &livery,
338 const std::string &icao,
const std::string &modelString,
const std::string &name,
339 const std::string &description);
341 void emitSceneryLoaded();
344 bool m_popupMessageWindow =
true;
345 bool m_disappearMessageWindow =
true;
346 int m_disapperMessageWindowTimeMs = 5000;
347 std::chrono::system_clock::time_point m_disappearMessageWindowTime;
348 CTerrainProbe m_terrainProbe;
351 void updateMessageBoxFromSettings();
353 struct FramePeriodSampler;
354 std::unique_ptr<FramePeriodSampler> m_framePeriodSampler;
356 DataRef<xplane::data::sim::graphics::scenery::async_scenery_load_in_progress> m_sceneryIsLoading;
357 int m_sceneryWasLoading = 0;
359 CustomDataRef<TSwiftNetworkConnected> m_swiftNetworkConnected;
360 CustomDataRef<TSwiftCallsign> m_swiftCallsign;
361 StringDataRef<xplane::data::sim::aircraft::view::acf_livery_path> m_liveryPath;
362 StringDataRef<xplane::data::sim::aircraft::view::acf_ICAO> m_icao;
363 StringDataRef<xplane::data::sim::aircraft::view::acf_descrip> m_descrip;
364 DataRef<xplane::data::sim::time::paused> m_paused;
365 DataRef<xplane::data::sim::time::use_system_time> m_useSystemTime;
366 DataRef<xplane::data::sim::flightmodel::position::latitude> m_latitude;
367 DataRef<xplane::data::sim::flightmodel::position::longitude> m_longitude;
368 DataRef<xplane::data::sim::flightmodel::position::elevation> m_elevation;
369 DataRef<xplane::data::sim::flightmodel2::position::pressure_altitude> m_pressureAlt;
370 DataRef<xplane::data::sim::flightmodel::position::y_agl> m_agl;
371 DataRef<xplane::data::sim::flightmodel::position::groundspeed> m_groundSpeed;
372 DataRef<xplane::data::sim::flightmodel::position::indicated_airspeed2> m_indicatedAirspeed;
373 DataRef<xplane::data::sim::flightmodel::position::true_airspeed> m_trueAirspeed;
374 DataRef<xplane::data::sim::flightmodel::position::theta> m_pitch;
375 DataRef<xplane::data::sim::flightmodel::position::phi> m_roll;
376 DataRef<xplane::data::sim::flightmodel::position::psi> m_heading;
377 DataRef<xplane::data::sim::flightmodel::position::local_vx> m_velocityX;
378 DataRef<xplane::data::sim::flightmodel::position::local_vy> m_velocityY;
379 DataRef<xplane::data::sim::flightmodel::position::local_vz> m_velocityZ;
380 DataRef<xplane::data::sim::flightmodel::position::Prad> m_rollVelocity;
381 DataRef<xplane::data::sim::flightmodel::position::Qrad> m_pitchVelocity;
382 DataRef<xplane::data::sim::flightmodel::position::Rrad> m_headingVelocity;
383 DataRef<xplane::data::sim::flightmodel::failures::onground_any> m_onGroundAny;
384 DataRef<xplane::data::sim::flightmodel::failures::onground_all> m_onGroundAll;
385 DataRef<xplane::data::sim::cockpit2::radios::actuators::com1_frequency_hz_833> m_com1Active;
386 DataRef<xplane::data::sim::cockpit2::radios::actuators::com1_standby_frequency_hz_833> m_com1Standby;
387 DataRef<xplane::data::sim::cockpit2::radios::actuators::audio_com_selection>
389 DataRef<xplane::data::sim::cockpit2::radios::actuators::com1_power> m_com1Power;
390 DataRef<xplane::data::sim::cockpit2::radios::actuators::audio_volume_com1> m_com1Volume;
391 DataRef<xplane::data::sim::cockpit2::radios::actuators::audio_selection_com1> m_com1Listening;
392 DataRef<xplane::data::sim::cockpit2::radios::actuators::com2_frequency_hz_833> m_com2Active;
393 DataRef<xplane::data::sim::cockpit2::radios::actuators::com2_standby_frequency_hz_833> m_com2Standby;
394 DataRef<xplane::data::sim::cockpit2::radios::actuators::com2_power> m_com2Power;
395 DataRef<xplane::data::sim::cockpit2::radios::actuators::audio_volume_com2> m_com2Volume;
396 DataRef<xplane::data::sim::cockpit2::radios::actuators::audio_selection_com2> m_com2Listening;
397 DataRef<xplane::data::sim::cockpit::radios::transponder_code> m_xpdrCode;
398 DataRef<xplane::data::sim::cockpit::radios::transponder_mode> m_xpdrMode;
399 DataRef<xplane::data::sim::cockpit::radios::transponder_id> m_xpdrIdent;
400 DataRef<xplane::data::sim::cockpit::electrical::beacon_lights_on> m_beaconLightsOn;
401 DataRef<xplane::data::sim::cockpit::electrical::landing_lights_on> m_landingLightsOn;
402 DataRef<xplane::data::sim::cockpit::electrical::nav_lights_on> m_navLightsOn;
403 DataRef<xplane::data::sim::cockpit::electrical::strobe_lights_on> m_strobeLightsOn;
404 DataRef<xplane::data::sim::cockpit::electrical::taxi_light_on> m_taxiLightsOn;
405 DataRef<xplane::data::sim::flightmodel2::controls::flap_handle_deploy_ratio> m_flapsReployRatio;
406 ArrayDataRef<xplane::data::sim::flightmodel2::gear::deploy_ratio> m_gearReployRatio;
407 DataRef<xplane::data::sim::aircraft::engine::acf_num_engines> m_numberOfEngines;
408 ArrayDataRef<xplane::data::sim::flightmodel::engine::ENGN_N1_> m_enginesN1Percentage;
409 DataRef<xplane::data::sim::flightmodel2::controls::speedbrake_ratio> m_speedBrakeRatio;
410 DataRef<xplane::data::sim::weather::barometer_sealevel_inhg> m_qnhInhg;
CDBusObject(CSettingsProvider *settingsProvider)
Constructor.
Class which builds upon CMessageBox with a scrollback buffer and commands for user control.
static const std::string & InterfaceName()
DBus interface name.
bool isCom1Transmitting() const
Is COM1 transmitting?
double getRollDeg() const
Get aircraft roll in degrees.
bool getCom2Power() const
Get the COM2 power on/off.
float getCom1Volume() const
Get the COM1 volume 0..1.
double getFlapsDeployRatio() const
Get flaps deploy ratio, where 0.0 is flaps fully retracted, and 1.0 is flaps fully extended.
static std::string getCommitHash()
Returns the SHA1 of the last commit that could influence xswiftbus.
float getCom2Volume() const
Get the COM2 volume 0..1.
int getCom1ActiveKhz() const
Get the current COM1 active frequency in kHz.
void toggleMessageBoxVisibility()
Toggles the visibility of the message box.
static const std::string & ObjectPath()
DBus object path.
void setDisappearMessageWindow(bool enabled)
Enable/disable message window disappearing again after x ms.
virtual ~CService()
Destructor.
double getLongitudeDeg() const
Get aircraft longitude in degrees.
double getAltitudeMslM() const
Get aircraft altitude in meters.
double getGroundSpeedMps() const
Get aircraft groundspeed in meters per second.
std::string getAircraftIcaoCode() const
Get the ICAO code of the current aircraft model.
static std::string getAircraftModelPath()
Get full path to current aircraft model.
static int getXPlaneVersionMinor()
Get minor version number.
int getComSelection() const
COM Selection 6/7.
bool isPaused() const
True if sim is paused.
int getCom2StandbyKhz() const
Get the current COM2 standby frequency in kHz.
void setFlightNetworkConnected(bool connected)
Set the current connection state.
double getTrueAirspeedKias() const
Get aircraft TAS in meters per second.
double getRollRadPerSec() const
Get aircraft angular velocity in radians per second.
bool isCom2Receiving() const
Is COM2 receiving?
std::tuple< double, double, double, double > getFrameStats()
Frames-per-second, averaged over the last 500 frames, or since this function was last called,...
void resetFrameTotals()
Reset the monitoring of total miles and minutes lost due to low frame rate.
double getLocalZVelocityMps() const
Get aircraft local velocity in world coordinates meters per second.
CService(CSettingsProvider *settingsProvider)
Constructor.
DBusHandlerResult dbusMessageHandler(const CDBusMessage &message)
DBus message handler.
bool getTaxiLightsOn() const
Get whether taxi lights are on.
double getPitchRadPerSec() const
Get aircraft angular velocity in radians per second.
double getSpeedBrakeRatio() const
Get the ratio how much the speedbrakes surfaces are extended (0.0 is fully retracted,...
double getHeadingRadPerSec() const
Get aircraft angular velocity in radians per second.
double getPitchDeg() const
Get aircraft pitch in degrees above horizon.
void onAircraftModelChanged()
Called by XPluginReceiveMessage when the model changes.
int getTransponderCode() const
Get the current transponder code in decimal.
double getGearDeployRatio() const
Get gear deploy ratio, where 0 is up and 1 is down.
double getLocalYVelocityMps() const
Get aircraft local velocity in world coordinates meters per second.
bool getTransponderIdent() const
Get whether we are currently squawking ident.
bool isCom2Selected() const
COM Selection 6/7.
bool getCom2Listening() const
Get the COM2 listening yes/no.
int getCom1StandbyKhz() const
Get the current COM1 standby frequency in kHz.
static std::string getVersionNumber()
Returns the xswiftbus version number.
static int getXPlaneVersionMajor()
Get major version number.
static std::string getXPlaneInstallationPath()
Get root of X-Plane install path.
void setOwnCallsign(const std::string &callsign)
Set the current own callsign.
bool getCom1Listening() const
Get the COM1 listening yes/no.
bool getAnyWheelOnGround() const
Get whether any wheel is on the ground.
void setTransponderMode(int mode)
Set the current transponder mode (depends on the aircraft, 0 and 1 usually mean standby,...
void setCom1StandbyKhz(int freq)
Set the current COM1 standby frequency in kHz.
bool getCom1Power() const
Get the COM1 power on/off.
bool getLandingLightsOn() const
Get whether landing lights are on.
std::vector< double > getEngineN1Percentage() const
Get the N1 speed as percent of max (per engine).
bool isCom1Receiving() const
Is COM1 receiving?
void onSceneryLoaded()
Called by XPluginReceiveMessage when some scenery is loaded.
double getHeightAglM() const
Get aircraft height in meters.
std::string getAircraftDescription() const
Get the description of the current aircraft model.
void setTransponderCode(int code)
Set the current transponder code in decimal.
void setDisappearMessageWindowTimeMs(int durationMs)
Enable/disable message window disappearing after x ms.
void setPopupMessageWindow(bool enabled)
Enable/disable message window popping up for new messages.
double getIndicatedAirspeedKias() const
Get aircraft IAS in knots.
void setCom2ActiveKhz(int freq)
Set the current COM2 active frequency in kHz.
double getLocalXVelocityMps() const
Get aircraft local velocity in world coordinates meters per second.
bool getBeaconLightsOn() const
Get whether beacon lights are on.
int process()
Perform generic processing.
double getPressureAltitudeFt() const
Get aircraft pressure altitude in feet in standard atmosphere in X-Plane 12. NaN in earlier versions ...
bool getStrobeLightsOn() const
Get whether strobe lights are on.
bool isCom1Selected() const
COM Selection 6/7.
void addTextMessage(const std::string &text, double red, double green, double blue)
Add a text message to the on-screen display, with RGB components in the range [0,1].
double getLatitudeDeg() const
Get aircraft latitude in degrees.
int getCom2ActiveKhz() const
Get the current COM2 active frequency in kHz.
bool isCom2Transmitting() const
Is COM2 transmitting?
static std::string getAircraftModelFilename()
Get base filename of current aircraft model.
double getTrueHeadingDeg() const
Get aircraft true heading in degrees.
static std::string getXPlanePreferencesPath()
Get full path to X-Plane preferences file.
std::string getAircraftLivery() const
Get current aircraft livery.
double getQNHInHg() const
Get barometric pressure at sea level in inches of mercury.
static std::string getAircraftModelString()
Get canonical swift model string of current aircraft model.
void setCom1ActiveKhz(int freq)
Set the current COM1 active frequency in kHz.
void setCom2StandbyKhz(int freq)
Set the current COM2 standby frequency in kHz.
int getTransponderMode() const
Get the current transponder mode (depends on the aircraft, 0 and 1 usually mean standby,...
int getNumberOfEngines() const
Get the number of engines of current aircraft.
std::string getSettingsJson() const
Get settings in JSON format.
bool isUsingRealTime() const
True if sim time is tracking operating system time.
double getGroundElevation() const
Get elevation of ground under the plane in meters.
static std::string getAircraftName()
Get name of current aircraft model.
void setSettingsJson(const std::string &jsonString)
Set settings.
bool getAllWheelsOnGround() const
Get whether all wheels are on the ground.
bool getNavLightsOn() const
Get whether nav lights are on.
Something owning the settings.
Plugin loaded by X-Plane which publishes a DBus service.