XPPlanes
X-Plane plugin to display additional planes based on network data
FlightData.h
Go to the documentation of this file.
1 
22 #pragma once
23 
24 //
25 // MARK: Flight Data
26 //
27 
29 typedef std::chrono::time_point<std::chrono::system_clock> tsTy;
30 
33 {
34 public:
35  // Key and identification
36  XPMPPlaneID _modeS_id = 0;
37  std::string icaoType;
38  std::string icaoAirline;
39  std::string tailNum;
40  std::string callSign;
41  std::string label;
42 
43  // Validity
44  tsTy ts;
45 
46  // Location
47  double lat = NAN;
48  double lon = NAN;
49  double alt_m = NAN;
50  bool bGnd = false;
51 
52  // Attitude
53  float pitch = NAN;
54  float heading = NAN;
55  float roll = NAN;
56 
58  struct wakeTy : public XPMP2::Aircraft::wakeTy {
59  float lift = NAN;
60  } wake;
61 
62  // Configuration
63  float gear = NAN;
64  float nws = NAN;
65  float flaps = NAN;
66  float spoilers = NAN;
67  float reversers = NAN;
68 
69  float thrust = NAN;
70  float engineRpm = NAN;
71 
72  // Visibility
73  bool bVisDefined = false;
74  bool bVisible = true;
75 
77  struct lightsTy {
78  bool defined : 1;
79  bool taxi : 1;
80  bool landing : 1;
81  bool beacon : 1;
82  bool strobe : 1;
83  bool nav : 1;
84  } lights = { false, false, false, false, false, false };
85 
86 public:
93  static bool ProcessNetworkData (const std::string& s);
94 
95 protected:
100  static bool AddNew (std::shared_ptr<FlightData>&& pFD);
101 
102 public:
104  FlightData (const std::string& csv);
105 
107  FlightData (const JSON_Object* obj);
108 
115  void SetTimestamp (double tsIn);
116 
118  bool operator< (const FlightData& o) const { return ts < o.ts; }
119 
121  bool IsUsable () const;
122 
124  operator XPLMDrawInfo_t () const;
125 
127  void NANtoZero ();
129  void NANtoCopy (const FlightData& o);
130 
131 protected:
132 
135  bool FillFromRTTFC (const std::string& csv);
136 
138  bool FillFromXPPTraffic (const JSON_Object* obj);
140 };
141 
143 typedef std::shared_ptr<FlightData> ptrFlightDataTy;
144 
146 typedef std::list<ptrFlightDataTy> listFlightDataTy;
147 
149 typedef std::map<XPMPPlaneID,listFlightDataTy> mapListFlightDataTy;
150 
151 //
152 // MARK: Exception class
153 //
154 
156 class FlightData_error : public std::runtime_error {
157 public:
159  FlightData_error (const std::string& what_arg) :
160  std::runtime_error(what_arg) {}
161 };
162 
163 //
164 // MARK: Global Functions
165 //
166 
168 bool FlightDataStartup ();
169 
171 void FlightDataShutdown ();
void FlightDataShutdown()
Shutdown the FlightData module.
Definition: FlightData.cpp:271
std::list< ptrFlightDataTy > listFlightDataTy
List of flight data elements.
Definition: FlightData.h:146
bool FlightDataStartup()
Initialize the FlightData module.
Definition: FlightData.cpp:264
std::map< XPMPPlaneID, listFlightDataTy > mapListFlightDataTy
Map indexed by plane id holding lists of flight data elements.
Definition: FlightData.h:149
std::shared_ptr< FlightData > ptrFlightDataTy
Smart pointer to flight data objects.
Definition: FlightData.h:143
std::chrono::time_point< std::chrono::system_clock > tsTy
Timestamp format is a system clock's timepoint.
Definition: FlightData.h:29
Exception thrown by FlightData, e.g. when object creation impossible.
Definition: FlightData.h:156
FlightData_error(const std::string &what_arg)
Constructor takes some error message.
Definition: FlightData.h:159
Transports flight data for location, attitude, configuration between the network and the main thread.
Definition: FlightData.h:33
std::string icaoAirline
ICAO airline code (for model matching)
Definition: FlightData.h:38
XPMPPlaneID _modeS_id
key
Definition: FlightData.h:36
bool FillFromRTTFC(const std::string &csv)
RTTFC: Interprets the data as an RTTFC line.
Definition: FD_RTTFC.cpp:80
bool beacon
beacon lights
Definition: FlightData.h:81
double alt_m
altitude in meter above ground
Definition: FlightData.h:49
bool bGnd
on the ground?
Definition: FlightData.h:50
double lat
latitude
Definition: FlightData.h:47
std::string callSign
call sign
Definition: FlightData.h:40
std::string tailNum
tail number / registration, also used as special livery code (optional, for model matching)
Definition: FlightData.h:39
bool FillFromXPPTraffic(const JSON_Object *obj)
Converts the purpose-desgined XPPTraffic JSON format.
Definition: FD_XPPTraffic.cpp:81
float nws
nose wheel steering degree, 0.0 = straight ahead, negative = left
Definition: FlightData.h:64
bool bVisible
Shall plane be drawn?
Definition: FlightData.h:74
float reversers
deployment of reversers, 1.0 = fully open
Definition: FlightData.h:67
float flaps
flaps deployed = 1.0, flaps up = 0.0
Definition: FlightData.h:65
float heading
Heading in local coordinates to rotate the object, clockwise.
Definition: FlightData.h:54
bool IsUsable() const
Has usable data? (Has at least position information)
Definition: FlightData.cpp:197
float thrust
thrust ratio, -1.0 .. 0.0 .. 1.0
Definition: FlightData.h:69
void NANtoCopy(const FlightData &o)
Replace any remaining NANs with values from the other object.
Definition: FlightData.cpp:235
float pitch
Pitch in degres to rotate the object, positive is up.
Definition: FlightData.h:53
bool taxi
taxi lights
Definition: FlightData.h:79
float roll
Roll to rotate the object.
Definition: FlightData.h:55
void SetTimestamp(double tsIn)
Set timestamp from input value.
Definition: FlightData.cpp:168
bool bVisDefined
Has visibility been set in the data?
Definition: FlightData.h:73
std::string label
label text
Definition: FlightData.h:41
static bool ProcessNetworkData(const std::string &s)
Main function to interpret network data.
Definition: FlightData.cpp:29
bool nav
navigation lights
Definition: FlightData.h:83
bool defined
are lights values valid, ie. defined?
Definition: FlightData.h:78
FlightData(const std::string &csv)
Constructor: Creates a FlightData object from single record CSV-style data.
Definition: FlightData.cpp:152
bool landing
landing lights
Definition: FlightData.h:80
static bool AddNew(std::shared_ptr< FlightData > &&pFD)
Add a just created object to the internal list.
Definition: FlightData.cpp:104
float spoilers
spoilers (speedbrakes) up = 1.0, down = 0.0
Definition: FlightData.h:66
tsTy ts
timestamp
Definition: FlightData.h:44
FlightData::wakeTy wake
struct FlightData::lightsTy lights
std::string icaoType
ICAO aircraft type according to doc8643.
Definition: FlightData.h:37
double lon
longitude
Definition: FlightData.h:48
float engineRpm
revolutions per minute of engine/rotor/prop
Definition: FlightData.h:70
void NANtoZero()
Replace any remaining NANs with 0.0
Definition: FlightData.cpp:218
bool operator<(const FlightData &o) const
Order is solely by timestamp.
Definition: FlightData.h:118
bool strobe
strobe lights
Definition: FlightData.h:82
float gear
gear down = 1.0, gear up = 0.0
Definition: FlightData.h:63
Aircraft lights.
Definition: FlightData.h:77
Wake turbulence calculation data: wing span, wing area, aircraft mass.
Definition: FlightData.h:58
float lift
current lift produced
Definition: FlightData.h:59