swift
Loading...
Searching...
No Matches
simulatorxplane.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#ifndef SWIFT_SIMPLUGIN_SIMULATOR_XPLANE_H
7#define SWIFT_SIMPLUGIN_SIMULATOR_XPLANE_H
8
9#include <QDBusConnection>
10#include <QHash>
11#include <QList>
12#include <QObject>
13#include <QPair>
14#include <QString>
15#include <QStringList>
16#include <QTimer>
17
18#include "xplanempaircraft.h"
19
23#include "misc/identifier.h"
24#include "misc/pixmap.h"
25#include "misc/pq/time.h"
26#include "misc/pq/units.h"
27#include "misc/sequence.h"
28#include "misc/settingscache.h"
34#include "misc/statusmessage.h"
37
39
40namespace swift::misc
41{
42 namespace aviation
43 {
44 class CAircraftParts;
46 class CCallsign;
47 } // namespace aviation
48 namespace network
49 {
50 class CTextMessage;
51 }
52 namespace simulation
53 {
58 } // namespace simulation
59} // namespace swift::misc
60
61namespace swift::simplugin::xplane
62{
65
68 {
71 double latitudeDeg = 0;
72 double longitudeDeg = 0;
73 double altitudeM = 0;
74 double pressureAltitudeFt = 0;
75 double heightAglM = 0;
76 double groundspeedMs = 0;
77 double pitchDeg = 0;
78 double rollDeg = 0;
79 double trueHeadingDeg = 0;
80 double localXVelocityMs = 0;
81 double localYVelocityMs = 0;
82 double localZVelocityMs = 0;
83 double pitchRadPerSec = 0;
84 double rollRadPerSec = 0;
85 double headingRadPerSec = 0;
86 bool onGroundAll = false;
87 double groundElevation = 0;
88 int com1ActiveKhz = 122800;
89 int com1StandbyKhz = 122800;
90 bool isCom1Receiving = true;
91 bool isCom1Transmitting = true;
92 double com1Volume = 1;
93 int com2ActiveKhz = 122800;
94 int com2StandbyKhz = 122800;
95 bool isCom2Receiving = true;
96 bool isCom2Transmitting = true;
97 double com2Volume = 1;
98 int xpdrCode = 2000;
99 int xpdrMode = 0;
100 bool xpdrIdent = false;
101 bool beaconLightsOn = false;
102 bool landingLightsOn = false;
103 bool navLightsOn = false;
104 bool strobeLightsOn = false;
105 bool taxiLightsOn = false;
106 double flapsDeployRatio = 0;
107 double gearDeployRatio = 0;
109 double speedBrakeRatio = 0;
111 };
112
115 {
117
118 public:
123 swift::misc::network::IClientProvider *clientProvider, QObject *parent = nullptr);
124
126 ~CSimulatorXPlane() override;
127
130 bool connectTo() override;
131 bool disconnectFrom() override;
133 const swift::misc::CIdentifier &originator) override;
135 const swift::misc::CIdentifier &originator) override;
136 void displayStatusMessage(const swift::misc::CStatusMessage &message) const override;
137 void displayTextMessage(const swift::misc::network::CTextMessage &message) const override;
138 bool isPhysicallyRenderedAircraft(const swift::misc::aviation::CCallsign &callsign) const override;
140 bool followAircraft(const swift::misc::aviation::CCallsign &callsign) override;
141 void unload() override;
143 void resetAircraftStatistics() override;
145 getInterpolationMessages(const swift::misc::aviation::CCallsign &callsign) const override;
148 const swift::misc::aviation::CAircraftParts &parts) override;
150 const swift::misc::aviation::CCallsign &callsign,
151 bool isWater) override;
152 void setFlightNetworkConnected(bool connected) override;
153 void setOwnCallsign(const swift::misc::aviation::CCallsign &callsign) override;
155
158 const swift::misc::aviation::CCallsign &callsign) override;
159
160 protected:
163 bool isConnected() const override;
164 bool physicallyAddRemoteAircraft(const swift::misc::simulation::CSimulatedAircraft &newRemoteAircraft) override;
167 void clearAllRemoteAircraftData() override;
168 bool isPaused() const override
169 {
171 return false;
172 }
173
174
175 private slots:
177 void onDBusServiceUnregistered();
178
179 private:
181 enum DBusMode
182 {
183 Session,
184 P2P
185 };
186
187 using QDoubleList = QList<double>;
188 using QBoolList = QList<bool>;
189
190 void emitOwnAircraftModelChanged(const QString &path, const QString &filename, const QString &livery,
191 const QString &icao, const QString &modelString, const QString &name,
192 const QString &description);
193 void fastTimerTimeout();
194 void slowTimerTimeout();
195
196 void loadCslPackages();
197 QString findCslPackage(const QString &modelFileName);
198
201 void updateRemoteAircraft();
202
205 void requestRemoteAircraftDataFromXPlane();
206 void requestRemoteAircraftDataFromXPlane(const swift::misc::aviation::CCallsignSet &callsigns);
207 void triggerRequestRemoteAircraftDataFromXPlane(const swift::misc::aviation::CCallsignSet &callsigns);
209
212 void addNextPendingAircraft();
213 void triggerAddNextPendingAircraft();
215
217 int detectTimeoutAdding();
218
220 void triggerRemoveAircraft(const swift::misc::aviation::CCallsign &callsign, qint64 deferMs);
221
223 QPair<qint64, qint64> minMaxTimestampsAddInProgress() const;
224
226 bool canAddAircraft() const;
227
230 void onRemoteAircraftAdded(const QString &callsign);
231 void onRemoteAircraftAddingFailed(const QString &callsign);
232 void updateRemoteAircraftFromSimulator(const QStringList &callsigns, const QDoubleList &latitudesDeg,
233 const QDoubleList &longitudesDeg, const QDoubleList &elevationsMeters,
234 const QBoolList &waterFlags, const QDoubleList &verticalOffsetsMeters);
236
238 void disconnectFromDBus();
239
242 bool sendXSwiftBusSettings();
243 swift::misc::simulation::settings::CXSwiftBusSettings receiveXSwiftBusSettings(bool &ok);
245
247 void onXSwiftBusSettingsChanged();
248
250 void setMinTerrainProbeDistance(const swift::misc::physical_quantities::CLength &distance);
251
253 bool handleProbeValue(const swift::misc::geo::CElevationPlane &plane,
254 const swift::misc::aviation::CCallsign &callsign, bool waterFlag, const QString &hint,
255 bool ignoreOutsideRange);
256
257 static bool isSuspiciousTerrainValue(const swift::misc::geo::CElevationPlane &elevation);
258 static const swift::misc::physical_quantities::CLength &maxTerrainRequestDistance();
259
261 fixSimulatorCg(const swift::misc::physical_quantities::CLength &cg,
263
264 DBusMode m_dbusMode;
266 this, &CSimulatorXPlane::onXSwiftBusSettingsChanged
267 };
268 static constexpr qint64 TimeoutAdding = 10000;
269 QDBusConnection m_dBusConnection { "default" };
270 QDBusServiceWatcher *m_watcher { nullptr };
271 CXSwiftBusServiceProxy *m_serviceProxy { nullptr };
272 CXSwiftBusTrafficProxy *m_trafficProxy { nullptr };
273 QTimer m_fastTimer;
274 QTimer m_slowTimer;
275 QTimer m_pendingAddedTimer;
276 unsigned int m_fastTimerCalls = 0;
277 unsigned int m_slowTimerCalls = 0;
278
279 CXPlaneMPAircraftObjects m_xplaneAircraftObjects;
280
281 swift::misc::simulation::CSimulatedAircraftList m_pendingToBeAddedAircraft;
282 QHash<swift::misc::aviation::CCallsign, qint64> m_addingInProgressAircraft;
283 swift::misc::simulation::CSimulatedAircraftList m_aircraftAddedFailed;
284 swift::misc::physical_quantities::CLength m_minSuspicousTerrainProbe {
285 nullptr
286 };
287 XPlaneData m_xplaneData;
288 swift::misc::physical_quantities::CLength
289 m_altitudeDelta;
290
291 // statistics
292 qint64 m_statsAddMaxTimeMs = -1;
293 qint64 m_statsAddCurrentTimeMs = -1;
294
296 void resetXPlaneData() { m_xplaneData = {}; }
297 };
298
301 {
303
304 public:
307
308 protected:
310 void startImpl() override;
311
313 void stopImpl() override;
314
316 void checkImpl() override;
317
318 private:
319 void checkConnection();
320 void checkConnectionViaSessionBus();
321 void checkConnectionViaPeer(const QString &address);
322 void checkConnectionCommon();
323
324 void serviceRegistered(const QString &serviceName);
325 void onXSwiftBusServerSettingChanged();
326
327 QTimer m_timer { this };
328 QDBusConnection m_DBusConnection { "default" };
329 QString m_dBusServerAddress;
331 this, &CSimulatorXPlaneListener::onXSwiftBusServerSettingChanged
332 };
333 };
334
337 {
339 Q_PLUGIN_METADATA(IID "org.swift-project.swift_core.simulatorinterface" FILE "simulatorxplane.json")
341
342 public:
347 swift::misc::network::IClientProvider *clientProvider) override;
348
352 {
353 return new CSimulatorXPlaneListener(info);
354 }
355 };
356} // namespace swift::simplugin::xplane
357
358#endif // SWIFT_SIMPLUGIN_SIMULATOR_XPLANE_H
Factory pattern class to create instances of ISimulator.
Definition simulator.h:694
Interface to a simulator.
Definition simulator.h:59
Interface to a simulator listener.
Definition simulator.h:633
Value object encapsulating information identifying a component of a modular distributed swift process...
Definition identifier.h:29
Class template for accessing a specific value in the CSettingsCache.
Class template for accessing a specific value in the CSettingsCache.
Streamable status message, e.g.
Status messages, e.g. from Core -> GUI.
Value object encapsulating information of aircraft's parts.
Value object encapsulating information of an aircraft's situation.
Value object encapsulating information of a callsign.
Definition callsign.h:30
Value object for a set of callsigns.
Definition callsignset.h:26
Value object for SELCAL.
Definition selcal.h:31
Plane of same elevation, can be a single point or larger area (e.g. airport).
Geodetic coordinate, a position in 3D space relative to the reference geoid.
Value object encapsulating information of a text message.
Definition textmessage.h:31
Direct in memory access to client (network client) data.
Physical unit length (length).
Definition length.h:18
Aircraft model (used by another pilot, my models on disk).
Comprehensive information of an aircraft.
Direct threadsafe in memory access to own aircraft.
Direct thread safe in memory access to remote aircraft.
Common base class for simulator plugins.
Factory for creating CSimulatorXPlane instance.
swift::core::ISimulator * create(const swift::misc::simulation::CSimulatorPluginInfo &info, swift::misc::simulation::IOwnAircraftProvider *ownAircraftProvider, swift::misc::simulation::IRemoteAircraftProvider *remoteAircraftProvider, swift::misc::network::IClientProvider *clientProvider)
Create a new instance of a driver.
swift::core::ISimulatorListener * createListener(const swift::misc::simulation::CSimulatorPluginInfo &info)
Simulator listener instance.
int physicallyRemoveAllRemoteAircraft()
Remove all remote aircraft and their data via ISimulator::clearAllRemoteAircraftData.
bool followAircraft(const swift::misc::aviation::CCallsign &callsign)
Follow aircraft.
bool isConnected() const
Are we connected to the simulator?
bool requestElevation(const swift::misc::geo::ICoordinateGeodetic &reference, const swift::misc::aviation::CCallsign &callsign)
Request elevation, there is no guarantee the requested elevation will be available in the provider.
CSimulatorXPlane(const swift::misc::simulation::CSimulatorPluginInfo &info, swift::misc::simulation::IOwnAircraftProvider *ownAircraftProvider, swift::misc::simulation::IRemoteAircraftProvider *remoteAircraftProvider, swift::misc::network::IClientProvider *clientProvider, QObject *parent=nullptr)
Constructor.
bool testSendSituationAndParts(const swift::misc::aviation::CCallsign &callsign, const swift::misc::aviation::CAircraftSituation &situation, const swift::misc::aviation::CAircraftParts &parts)
Send situation/parts for testing.
void resetAircraftStatistics()
Reset the statistics.
bool updateOwnSimulatorSelcal(const swift::misc::aviation::CSelcal &selcal, const swift::misc::CIdentifier &originator)
Update own aircraft cockpit (usually from context).
void clearAllRemoteAircraftData()
Clear all aircraft related data, but do not physically remove the aircraft.
bool isPhysicallyRenderedAircraft(const swift::misc::aviation::CCallsign &callsign) const
Is the aircraft rendered (displayed in simulator)? This shall only return true if the aircraft is rea...
void setOwnCallsign(const swift::misc::aviation::CCallsign &callsign)
Own callsign has changed.
bool updateOwnSimulatorCockpit(const swift::misc::simulation::CSimulatedAircraft &aircraft, const swift::misc::CIdentifier &originator)
Update own aircraft cockpit (usually from context).
swift::misc::aviation::CCallsignSet physicallyRenderedAircraft() const
Physically rendered (displayed in simulator) This shall only return aircraft handled in the simulator...
swift::misc::CStatusMessageList getInterpolationMessages(const swift::misc::aviation::CCallsign &callsign) const
Interpolation messages for callsign.
void setFlightNetworkConnected(bool connected)
Flight network has been connected.
bool physicallyAddRemoteAircraft(const swift::misc::simulation::CSimulatedAircraft &newRemoteAircraft)
Add new remote aircraft physically to the simulator.
bool physicallyRemoveRemoteAircraft(const swift::misc::aviation::CCallsign &callsign)
Remove remote aircraft from simulator.
QString getStatisticsSimulatorSpecific() const
Allows to print out simulator specific statistics.
void callbackReceivedRequestedElevation(const swift::misc::geo::CElevationPlane &plane, const swift::misc::aviation::CCallsign &callsign, bool isWater)
A requested elevation has been received.
void displayStatusMessage(const swift::misc::CStatusMessage &message) const
Display a status message in the simulator.
bool disconnectFrom()
Disconnect from simulator.
void displayTextMessage(const swift::misc::network::CTextMessage &message) const
Display a text message.
bool isPaused() const
Simulator paused?
Listener waits for xswiftbus service to show up.
CSimulatorXPlaneListener(const swift::misc::simulation::CSimulatorPluginInfo &info)
Constructor.
void checkImpl()
Plugin specific implementation to check.
void startImpl()
Plugin specific implementation to start listener.
void stopImpl()
Plugin specific implementation to stop listener.
Proxy object connected to a real XSwiftBus::CService object via DBus.
Proxy object connected to a real XSwiftBus::CTraffic object via DBus.
Free functions in swift::misc.
QObject(QObject *parent)
Q_INTERFACES(...)
Q_OBJECTQ_OBJECT
QObject * parent() const const
int com2StandbyKhz
COM2 standby [kHz].
double headingRadPerSec
Heading angular velocity [rad/s].
double groundspeedMs
Ground speed [m/s].
double groundElevation
Elevation of ground [m].
double localXVelocityMs
Local x velocity [m/s].
int xpdrMode
Transponder mode (off=0,stdby=1,on=2,test=3).
bool isCom1Transmitting
COM1 transmittings.
QString aircraftModelPath
Aircraft model path.
double flapsDeployRatio
Flaps deployment ratio [%].
double localZVelocityMs
Local z velocity [m/s].
bool isCom2Transmitting
COM2 transmittings.
double rollRadPerSec
Roll angular velocity [rad/s].
double gearDeployRatio
Gear deployment ratio [%].
double trueHeadingDeg
True heading [deg].
bool xpdrIdent
Is transponder in ident?
QString aircraftIcaoCode
Aircraft ICAO code.
bool onGroundAll
All wheels on ground?
double pitchRadPerSec
Pitch angular velocity [rad/s].
QList< double > enginesN1Percentage
N1 per engine [%].
double speedBrakeRatio
Speed break ratio [%].
double seaLevelPressureInHg
Sea level pressure [inhg].
int com1StandbyKhz
COM1 standby [kHz].
double pressureAltitudeFt
Pressure altitude [ft, XP12].
double localYVelocityMs
Local y velocity [m/s].