Skip to content

Commit 0ca72a1

Browse files
committed
Merge branch 'Next'
2 parents aa39f41 + ddd03d8 commit 0ca72a1

37 files changed

+1611
-201
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33

44
cmake_minimum_required(VERSION 3.9)
5-
project(LiveTraffic VERSION 1.15 DESCRIPTION "LiveTraffic X-Plane plugin")
5+
project(LiveTraffic VERSION 1.20 DESCRIPTION "LiveTraffic X-Plane plugin")
66

77
# By default, use optimized release configuration.
88
if (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
@@ -15,6 +15,7 @@ set(CMAKE_CXX_STANDARD 17)
1515
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/Src")
1616
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/Include")
1717
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/Lib/xplanemp")
18+
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/Lib/LTAPI")
1819
include_directories("${CMAKE_SOURCE_DIR}/Lib/XPSDK301/CHeaders/Widgets")
1920
include_directories("${CMAKE_SOURCE_DIR}/Lib/XPSDK301/CHeaders/Wrappers")
2021
include_directories("${CMAKE_SOURCE_DIR}/Lib/XPSDK301/CHeaders/XPLM")

Include/Constants.h

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
//
3131
// MARK: Version Information (CHANGE VERSION HERE)
3232
//
33-
constexpr float VERSION_NR = 1.15f;
33+
constexpr float VERSION_NR = 1.20f;
3434
constexpr bool VERSION_BETA = false;
3535
extern float verXPlaneOrg; // version on X-Plane.org
3636
extern int verDateXPlaneOrg; // and its date
@@ -97,6 +97,12 @@ constexpr float MDL_EXT_FAST_DEG = 5.0f;
9797
constexpr float MDL_EXT_STEP_FACTOR = 1.025f; // step factor with one zoom command
9898
constexpr float MDL_EXT_FAST_FACTOR = 1.1f;
9999
#define MDL_LABEL_COLOR "LABEL_COLOR"
100+
constexpr double MDL_REVERSERS_TIME = 2.0; ///< [s] to open/close reversers
101+
constexpr double MDL_SPOILERS_TIME = 0.5; ///< [s] to extend/retract spoilers
102+
constexpr double MDL_TIRE_SLOW_TIME = 5.0; ///< [s] time till tires stop rotating after take-off
103+
constexpr double MDL_TIRE_MAX_RPM = 2000; ///< [rpm] max tire rotation speed
104+
constexpr double MDL_TIRE_CF_M = 3.2; ///< [m] tire circumfence (3.2m for a 40-inch tire)
105+
constexpr double MDL_GEAR_DEFL_TIME = 0.5; ///< [s] time for gear deflection (one direction...up down is twice this value)
100106

101107
constexpr int COLOR_YELLOW = 0xFFFF00;
102108
constexpr int COLOR_RED = 0xFF0000;
@@ -110,7 +116,7 @@ extern char HTTP_USER_AGENT[]; // like "LiveTraffic/1.0"
110116
extern time_t LT_BETA_VER_LIMIT; // BETA versions are limited
111117
extern char LT_BETA_VER_LIMIT_TXT[];
112118
#define BETA_LIMITED_VERSION "BETA limited to %s"
113-
#define BETA_LIMITED_EXPIRED "BETA-Version limited to %s has EXPIRED -> SHUTTING DOWN!"
119+
#define BETA_LIMITED_EXPIRED "BETA-Version limited to %s has EXPIRED -> SHUTTING DOWN! Get an up-to-date version from X-Plane.org."
114120
constexpr int LT_NEW_VER_CHECK_TIME = 48; // [h] between two checks of a new
115121

116122
//MARK: Text Constants
@@ -119,7 +125,7 @@ constexpr int LT_NEW_VER_CHECK_TIME = 48; // [h] between two checks of a new
119125
#define LT_CFG_VERSION "1.1" // current version of config file format
120126
#define LT_FM_VERSION "1.1" // version of flight model file format
121127
#define PLUGIN_SIGNATURE "TwinFan.plugin.LiveTraffic"
122-
#define PLUGIN_DESCRIPTION "Create Multiplayer Aircrafts based on live traffic."
128+
#define PLUGIN_DESCRIPTION "Create Multiplayer Aircraft based on live traffic."
123129
#define LT_DOWNLOAD_URL "https://forums.x-plane.org/index.php?/files/file/49749-livetraffic/"
124130
#define LT_DOWNLOAD_CH "X-Plane.org"
125131
#define MSG_DISABLED "Disabled"
@@ -130,20 +136,21 @@ constexpr int LT_NEW_VER_CHECK_TIME = 48; // [h] between two checks of a new
130136
#define MSG_LT_NEW_VER_AVAIL "The new version %01.2f of LiveTraffic is available at X-Plane.com!"
131137
#define MSG_REQUESTING_LIVE_FD "Requesting live flight data online..."
132138
#define MSG_READING_HIST_FD "Reading historic flight data..."
133-
#define MSG_NUM_AC_INIT "Initially created %d aircrafts"
134-
#define MSG_NUM_AC_ZERO "No more aircrafts displayed"
135-
#define MSG_BUF_FILL_COUNTDOWN "Filling buffer: seeing %d aircrafts, displaying %d, still %d seconds to buffer"
139+
#define MSG_NUM_AC_INIT "Initially created %d aircraft"
140+
#define MSG_NUM_AC_ZERO "No more aircraft displayed"
141+
#define MSG_BUF_FILL_COUNTDOWN "Filling buffer: seeing %d aircraft, displaying %d, still %d seconds to buffer"
136142
#define MSG_HIST_WITH_SYS_TIME "When using historic data you cannot run X-Plane with 'always track system time',\ninstead, choose the historic date in X-Plane's date/time settings."
143+
#define MSG_ADSBEX_LIMITE "%ld / %ld requests left"
137144
#define INFO_AC_ADDED "Added aircraft %s, operator '%s', a/c model '%s', flight model [%s], bearing %.0f, distance %.1fkm"
138145
#define INFO_AC_MDL_CHANGED "Changed CSL model for aircraft %s, operator '%s': a/c model now '%s'"
139146
#define INFO_AC_REMOVED "Removed aircraft %s"
140-
#define INFO_AC_ALL_REMOVED "Removed all aircrafts"
147+
#define INFO_AC_ALL_REMOVED "Removed all aircraft"
141148
#define INFO_WND_AUTO_AC "AUTO"
142149
#define INFO_AC_HIDDEN "A/c %s hidden"
143150
#define INFO_AC_HIDDEN_AUTO "A/c %s automatically hidden"
144151
#define INFO_AC_SHOWN "A/c %s visible"
145152
#define INFO_AC_SHOWN_AUTO "A/c %s automatically visible"
146-
#define MSG_TOO_MANY_AC "Reached limit of %d aircrafts, will create new ones only after removing outdated ones."
153+
#define MSG_TOO_MANY_AC "Reached limit of %d aircraft, will create new ones only after removing outdated ones."
147154
#define MSG_CSL_PACKAGE_LOADED "Successfully loaded CSL package %s"
148155
#define MSG_MDL_FORCED "Settings > Debug: Model matching forced to '%s'/'%s'/'%s'"
149156
#define MSG_MDL_NOT_FORCED "Settings > Debug: Model matching no longer forced"
@@ -167,8 +174,8 @@ constexpr int LT_NEW_VER_CHECK_TIME = 48; // [h] between two checks of a new
167174
#define MENU_AC_INFO_WND_POPOUT "Aircraft Info... (Popped out)"
168175
#define MENU_AC_INFO_WND_SHOWN "Aircraft Info shown"
169176
#define MENU_AC_INFO_WND_CLOSEALL "Close All Windows"
170-
#define MENU_TOGGLE_AIRCRAFTS "Aircrafts displayed"
171-
#define MENU_TOGGLE_AC_NUM "Aircrafts displayed (%d shown)"
177+
#define MENU_TOGGLE_AIRCRAFTS "Aircraft displayed"
178+
#define MENU_TOGGLE_AC_NUM "Aircraft displayed (%d shown)"
172179
#define MENU_HAVE_TCAS "TCAS controlled"
173180
#define MENU_TOGGLE_LABELS "Labels shown"
174181
#define MENU_SETTINGS_UI "Settings..."
@@ -214,8 +221,11 @@ constexpr int LT_NEW_VER_CHECK_TIME = 48; // [h] between two checks of a new
214221
//MARK: Error Texsts
215222
constexpr long HTTP_OK = 200;
216223
constexpr long HTTP_BAD_REQUEST = 400;
224+
constexpr long HTTP_UNAUTHORIZED = 401;
225+
constexpr long HTTP_FORBIDDEN = 403;
217226
constexpr long HTTP_NOT_FOUND = 404;
218227
constexpr long HTTP_NOT_AVAIL = 503; // "Service not available"
228+
constexpr long CURL_TIMEOUT = 30; ///< [s] network timeout, see CURLOPT_TIMEOUT
219229
constexpr int CH_MAC_ERR_CNT = 5; // max number of tolerated errors, afterwards invalid channel
220230
constexpr int SERR_LEN = 100; // size of buffer for IO error texts (strerror_s)
221231
#define ERR_XPLANE_ONLY "LiveTraffic works in X-Plane only, version 10 or higher"
@@ -231,8 +241,10 @@ constexpr int SERR_LEN = 100; // size of buffer for IO error t
231241
#define ERR_CURL_PERFORM "%s: Could not get network data: %d - %s"
232242
#define ERR_CURL_NOVERCHECK "Could not browse X-Plane.org for version info: %d - %s"
233243
#define ERR_CURL_HTTP_RESP "%s: HTTP response is not OK but %ld"
234-
#define ERR_CURL_REVOKE_MSG "revocation" // appears in error text if querying revocation list fails
244+
#define ERR_CURL_REVOKE_MSG {"revocation","80092012","80092013"} // appear in error text if querying revocation list fails
235245
#define ERR_CURL_DISABLE_REV_QU "%s: Querying revocation list failed - have set CURLSSLOPT_NO_REVOKE and am trying again"
246+
#define ERR_HTTP_NOT_OK "HTTP response was not HTTP_OK"
247+
#define ERR_FOUND_NO_VER_INFO "Found no version info in response"
236248
#define ERR_CH_NONE_ACTIVE "No enabled active channel for tracking data! Check Basic Settings and enable channels."
237249
#define ERR_CH_UNKNOWN_NAME "(unknown channel)"
238250
#define ERR_CH_INVALID "%s: Channel invalid and disabled"
@@ -244,7 +256,7 @@ constexpr int SERR_LEN = 100; // size of buffer for IO error t
244256
#define ERR_DIR_CONTENT "Could not retrieve directory content for %s"
245257
#define ERR_JSON_PARSE "Parsing flight data as JSON failed"
246258
#define ERR_JSON_MAIN_OBJECT "JSON: Getting main object failed"
247-
#define ERR_JSON_ACLIST "JSON: List of aircrafts (%s) not found"
259+
#define ERR_JSON_ACLIST "JSON: List of aircraft (%s) not found"
248260
#define ERR_JSON_AC "JSON: Could not get %d. aircraft in '%s'"
249261
#define ERR_NEW_OBJECT "Could not create new object (memory?): %s"
250262
#define ERR_LOCK_ERROR "Could not acquire lock for '%s': %s"
@@ -256,7 +268,7 @@ constexpr int SERR_LEN = 100; // size of buffer for IO error t
256268
#define ERR_POS_UNNORMAL "A/c %s reached invalid pos: %s"
257269
#define ERR_IGNORE_POS "A/c %s: Ignoring data leading to sharp turn or invalid speed: %s"
258270
#define ERR_INV_TRANP_ICAO "Ignoring data for invalid transponder code '%s'"
259-
#define ERR_TIME_NONLINEAR "Time moved non-linear/jumped by %.1f seconds, will re-init aircrafts."
271+
#define ERR_TIME_NONLINEAR "Time moved non-linear/jumped by %.1f seconds, will re-init aircraft."
260272
#define ERR_TOP_LEVEL_EXCEPTION "Caught top-level exception! %s"
261273
#define ERR_WIDGET_CREATE "Could not create widget required for settings UI"
262274
#define ERR_CFG_FILE_OPEN_OUT "Could not create config file '%s': %s"

Include/DataRefs.h

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ class Doc8643 {
6868
// return the string for FlightModel matching
6969
operator std::string() const;
7070

71+
// Helicopter or Gyrocopter with big rotor?
72+
inline bool hasRotor () const
73+
{ return classification.size() >= 1 ?
74+
(classification[0] == 'H' || classification[0] == 'G') : false;
75+
}
76+
7177
// static functions for reading the doc8643.txt file
7278
// and returning information from it
7379
public:
@@ -199,6 +205,9 @@ enum dataRefsLT {
199205
DR_AC_BEARING,
200206
DR_AC_DIST, // last of a/c info
201207

208+
DR_AC_BULK_QUICK, // bulk a/c primarily for communication with LTAPI
209+
DR_AC_BULK_EXPENSIVE, // similar, but for expensive data, should be called less often
210+
202211
DR_SIM_DATE,
203212
DR_SIM_TIME,
204213

@@ -224,6 +233,7 @@ enum dataRefsLT {
224233
DR_CFG_LND_LIGHTS_TAXI,
225234
DR_CFG_HIDE_BELOW_AGL,
226235
DR_CFG_HIDE_TAXIING,
236+
DR_CFG_DR_LIBXPLANEMP,
227237
DR_CFG_LAST_CHECK_NEW_VER,
228238

229239
// debug options
@@ -282,6 +292,7 @@ class DataRefs
282292
XPLMSetDatai_f ifWrite = NULL;
283293
XPLMGetDataf_f ffRead = NULL;
284294
XPLMSetDataf_f ffWrite = NULL;
295+
XPLMGetDatab_f bfRead = NULL;
285296
void* refCon = NULL;
286297
bool bCfgFile = false;
287298

@@ -304,6 +315,15 @@ class DataRefs
304315
ffRead(_ffRead), ffWrite(_ffWrite),
305316
refCon(_refCon), bCfgFile(_bCfg) {}
306317

318+
// constructor for xplmType_Data
319+
dataRefDefinitionT (const char* name,
320+
XPLMGetDatab_f _bfRead, XPLMSetDataf_f /*_bfWrite*/ = NULL,
321+
void* _refCon = NULL,
322+
bool _bCfg = false) :
323+
dataName(name), dataType(xplmType_Data),
324+
bfRead(_bfRead),
325+
refCon(_refCon), bCfgFile(_bCfg) {}
326+
307327
// allows using the object in string context -> dataName
308328
inline const std::string getDataNameStr() const { return dataName; }
309329
inline const char* getDataName() const { return dataName.c_str(); }
@@ -317,7 +337,8 @@ class DataRefs
317337
inline XPLMSetDatai_f setDatai_f () const { return ifWrite; }
318338
inline XPLMGetDataf_f getDataf_f () const { return ffRead; }
319339
inline XPLMSetDataf_f setDataf_f () const { return ffWrite; }
320-
340+
inline XPLMGetDatab_f getDatab_f () const { return bfRead; }
341+
321342
inline XPLMDataTypeID getDataType() const { return dataType; }
322343
inline void* getRefCon() const { return refCon; }
323344
inline void setRefCon (void* _refCon) { refCon = _refCon; }
@@ -386,6 +407,7 @@ class DataRefs
386407
inline bool empty() const { return path.empty(); }
387408
inline bool enabled() const { return bEnabled && !empty(); }
388409
inline bool operator== (const CSLPathCfgTy& o) const { return path == o.path; }
410+
inline bool operator== (const std::string& s) const { return path == s; }
389411
};
390412
typedef std::vector<CSLPathCfgTy> vecCSLPaths;
391413

@@ -442,6 +464,7 @@ class DataRefs
442464
int bLndLightsTaxi = false; // keep landing lights on while taxiing? (to be able to see the a/c as there is no taxi light functionality)
443465
int hideBelowAGL = 0; // if positive: a/c visible only above this height AGL
444466
int hideTaxiing = 0; // hide a/c while taxiing?
467+
int drLibXplaneMP = 1; // CSL models: register original 'libxplanemp' dataRefs?
445468

446469
// channel config options
447470
int rtListenPort = 10747; // port opened for RT to connect
@@ -471,6 +494,8 @@ class DataRefs
471494
std::string cslFixOpIcao; // ...newly created aircrafts for...
472495
std::string cslFixLivery; // ...CSL model package testing
473496
RealTrafficConnection *pRTConn = nullptr; // ptr to RealTraffic connection object
497+
long ADSBExRLimit = 0; // ADSBEx: Limit on RapidAPI
498+
long ADSBExRRemain = 0; // ADSBEx: Remaining Requests on RapidAPI
474499

475500
//MARK: Constructor
476501
public:
@@ -517,6 +542,10 @@ class DataRefs
517542
static int LTGetInt(void* p);
518543
static float LTGetFloat(void* p);
519544
static void LTSetBool(void* p, int i);
545+
546+
// Bulk data access to transfer a lot of a/c info to LTAPI
547+
static int LTGetBulkAc (void* inRefcon, void * outValue,
548+
int inStartIdx, int inNumAc);
520549

521550
protected:
522551
// a/c info
@@ -586,7 +615,10 @@ class DataRefs
586615
inline int GetHideBelowAGL() const { return hideBelowAGL; }
587616
inline bool GetHideTaxiing() const { return hideTaxiing != 0; }
588617
inline bool IsAutoHidingActive() const { return hideBelowAGL > 0 || hideTaxiing != 0; }
589-
618+
619+
inline bool GetDrLibXplaneMP() const { return drLibXplaneMP != 0; }
620+
inline void SetDrLibXplaneMP(int i) { drLibXplaneMP = i; }
621+
590622
bool NeedNewVerCheck () const;
591623
void SetLastCheckedNewVerNow ();
592624

Include/LTADSBEx.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,14 @@
3434
#define ADSBEX_NAME "ADS-B Exchange Online"
3535
#define ADSBEX_URL "https://adsbexchange.com/api/aircraft/json/lat/%f/lon/%f/dist/%d/"
3636
#define ADSBEX_API_AUTH "api-auth:" // additional HTTP header
37+
38+
#define ADSBEX_RAPIDAPI_25_URL "https://adsbx-flight-sim-traffic.p.rapidapi.com/api/aircraft/json/lat/%f/lon/%f/dist/25/"
39+
#define ADSBEX_RAPIDAPI_HOST "X-RapidAPI-Host:adsbx-flight-sim-traffic.p.rapidapi.com"
40+
#define ADSBEX_RAPIDAPI_KEY "X-RapidAPI-Key:"
41+
#define ADSBEX_RAPIDAPI_RLIMIT "X-RateLimit-Requests-Limit:"
42+
#define ADSBEX_RAPIDAPI_RREMAIN "X-RateLimit-Requests-Remaining:"
43+
44+
#define ADSBEX_TOTAL "total"
3745
#define ADSBEX_TIME "ctime"
3846
#define ADSBEX_AIRCRAFT_ARR "ac"
3947
#define ADSBEX_TRANSP_ICAO "icao" // Key data
@@ -77,6 +85,11 @@
7785
#define ADSBEX_VERIFY_KEY_URL "https://adsbexchange.com/api/aircraft/icao/000000"
7886
#define ADSBEX_ERR "ERR"
7987
#define ADSBEX_NO_API_KEY "NO API KEY"
88+
89+
#define ADSBEX_VERIFY_RAPIDAPI "https://adsbx-flight-sim-traffic.p.rapidapi.com/api/aircraft/json/lat/0.0/lon/0.0/dist/25/"
90+
#define ADSBEX_RAPID_ERR "message"
91+
#define ADSBEX_NO_RAPIDAPI_KEY "Key doesn't exists"
92+
8093
#define ERR_ADSBEX_KEY_TECH "ADSBEx: Technical problem while testing key: %d - %s"
8194
#define MSG_ADSBEX_KEY_SUCCESS "ADS-B Exchange: API Key tested SUCCESSFULLY"
8295
#define ERR_ADSBEX_KEY_FAILED "ADS-B Exchange: API Key INVALID"
@@ -92,8 +105,12 @@ constexpr double ADSBEX_SMOOTH_GROUND = 35.0; // smooth 35s of ground data
92105
//
93106
class ADSBExchangeConnection : public LTOnlineChannel, LTFlightDataChannel
94107
{
108+
public:
109+
enum keyTypeE { ADSBEX_KEY_NONE=0, ADSBEX_KEY_EXCHANGE, ADSBEX_KEY_RAPIDAPI };
110+
95111
protected:
96112
std::string apiKey;
113+
keyTypeE keyTy = ADSBEX_KEY_NONE;
97114
struct curl_slist* slistKey = NULL;
98115
public:
99116
ADSBExchangeConnection () :
@@ -114,8 +131,13 @@ class ADSBExchangeConnection : public LTOnlineChannel, LTFlightDataChannel
114131
// need to add/cleanup API key
115132
virtual bool InitCurl ();
116133
virtual void CleanupCurl ();
134+
// make list of HTTP header fields
135+
static struct curl_slist* MakeCurlSList (keyTypeE keyTy, const std::string theKey);
136+
// read header and parse for request limit/remaining
137+
static size_t ReceiveHeader(char *buffer, size_t size, size_t nitems, void *userdata);
117138

118139
public:
140+
static keyTypeE GetKeyType (const std::string theKey);
119141
// Just quickly sends one simple request to ADSBEx and checks if the response is not "NO KEY"
120142
// Does a SHOW_MSG about the result and saves the key to dataRefs on success.
121143
static void TestADSBExAPIKey (const std::string newKey);

0 commit comments

Comments
 (0)