Skip to content

Commit 87c8340

Browse files
committed
Merge branch 'adsbex-v2' into Next
2 parents f298745 + 4f1db5e commit 87c8340

File tree

8 files changed

+162
-354
lines changed

8 files changed

+162
-354
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ endif()
2323
set(CMAKE_BUILD_TYPE RelWithDebInfo)
2424

2525
project(LiveTraffic
26-
VERSION 4.1.2
26+
VERSION 4.2.0
2727
DESCRIPTION "LiveTraffic X-Plane plugin")
2828
set(VERSION_BETA 0)
2929

Include/DataRefs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,7 @@ class DataRefs
796796
std::string OpenSkyRetryAt; ///< OpenSky: If limit is reached, when to retry? (local time as string)
797797
long ADSBExRLimit = 0; // ADSBEx: Limit on RapidAPI
798798
long ADSBExRRemain = 0; // ADSBEx: Remaining Requests on RapidAPI
799+
long ADSBExRReset = 0; ///< [s] ADSBEx: When will the quota reset?
799800

800801
// UI information
801802
int UIopacity = DEF_UI_OPACITY; ///< [%] UI opacity

Include/LTADSBEx.h

Lines changed: 32 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
/// @file LTADSBEx.h
22
/// @brief ADS-B Exchange and adsb.fi: Requests and processes live tracking data
3-
/// @see https://www.adsbexchange.com/
4-
/// @see https://github.com/adsbfi/opendata
3+
/// @see ADSBEx: https://www.adsbexchange.com/
4+
/// RAPID API: https://rapidapi.com/adsbx/api/adsbexchange-com1
5+
/// RAPID API Endpoint: https://rapidapi.com/adsbx/api/adsbexchange-com1/playground/endpoint_7dee5835-86b3-40ce-a402-f1ab43240884
6+
/// ADSBEx v2 API documentation:
7+
/// ...on Swagger: https://adsbexchange.com/api/aircraft/v2/docs
8+
/// ...fields: https://www.adsbexchange.com/version-2-api-wip/
9+
/// @see adsb.fi: https://github.com/adsbfi/opendata
510
/// @details Defines a base class handling the ADSBEx data format,
611
/// which is shared by both ADS-B Exchange and adsb.fi.
712
/// @details Defines ADSBExchangeConnection:\n
@@ -39,21 +44,25 @@
3944
#define ADSBEX_CHECK_POPUP "Check ADS-B Exchange's coverage"
4045

4146
#define ADSBEX_NAME "ADS-B Exchange"
42-
#define ADSBEX_URL "https://adsbexchange.com/api/aircraft/v2/lat/%f/lon/%f/dist/%d/"
43-
#define ADSBEX_API_AUTH "api-auth:" // additional HTTP header
44-
45-
#define ADSBEX_RAPIDAPI_25_URL "https://adsbx-flight-sim-traffic.p.rapidapi.com/api/aircraft/json/lat/%f/lon/%f/dist/25/"
46-
#define ADSBEX_RAPIDAPI_HOST "X-RapidAPI-Host:adsbx-flight-sim-traffic.p.rapidapi.com"
47-
#define ADSBEX_RAPIDAPI_KEY "X-RapidAPI-Key:"
48-
#define ADSBEX_RAPIDAPI_RLIMIT "x-ratelimit-requests-limit:"
49-
#define ADSBEX_RAPIDAPI_RREMAIN "x-ratelimit-requests-remaining:"
47+
#define ADSBEX_RAPIDAPI_URL "https://adsbexchange-com1.p.rapidapi.com/v2/lat/%f/lon/%f/dist/%d/"
48+
#define ADSBEX_RAPIDAPI_HOST "x-rapidapi-host: adsbexchange-com1.p.rapidapi.com"
49+
#define ADSBEX_RAPIDAPI_KEY "x-rapidapi-key: "
50+
#define ADSBEX_RAPIDAPI_RLIMIT "x-ratelimit-api-requests-limit: "
51+
#define ADSBEX_RAPIDAPI_RREMAIN "x-ratelimit-api-requests-remaining: "
52+
#define ADSBEX_RAPIDAPI_RESET "x-ratelimit-api-requests-reset: "
5053

5154
#define ADSBEX_TOTAL "total"
5255
#define ADSBEX_NOW "now"
56+
#define ADSBEX_TIME "ctime"
5357
#define ADSBEX_AIRCRAFT_ARR "ac"
58+
#define ADSBEX_MSG "msg" ///< Error message text field according to documentation
59+
#define ADSBEX_MESSAGE "message" ///< Error message text field we actually see in the responses
60+
61+
#define ADSBEX_SUCCESS "No error" ///< Content of 'msg' in case of success
5462

5563
// Version 2 keys
5664
#define ADSBEX_V2_TRANSP_ICAO "hex" // Key data
65+
#define ADSBEX_V2_TRANSP_TYPE "type" ///< type of transponder, or source of data, like "adsb_icao", "adsr_icao", or "tisb_other"
5766
#define ADSBEX_V2_RADAR_CODE "squawk" // Dynamic data
5867
#define ADSBEX_V2_FLIGHT "flight"
5968
#define ADSBEX_V2_LAT "lat"
@@ -72,47 +81,19 @@
7281
#define ADSBEX_V2_AC_CATEGORY "category"
7382
#define ADSBEX_V2_FLAGS "dbFlags"
7483

75-
// Version 1 keys
76-
#define ADSBEX_TIME "ctime"
77-
#define ADSBEX_V1_TRANSP_ICAO "icao" // Key data
78-
#define ADSBEX_V1_RADAR_CODE "sqk" // Dynamic data
79-
#define ADSBEX_V1_CALL "call"
80-
#define ADSBEX_V1_LAT "lat"
81-
#define ADSBEX_V1_LON "lon"
82-
#define ADSBEX_V1_ELEVATION "galt" // geometric altitude
83-
#define ADSBEX_V1_ALT "alt" // barometric altitude
84-
#define ADSBEX_V1_TTRK "ttrk"
85-
#define ADSBEX_V1_HEADING "trak"
86-
#define ADSBEX_V1_GND "gnd"
87-
#define ADSBEX_V1_POS_TIME "postime"
88-
#define ADSBEX_V1_SPD "spd"
89-
#define ADSBEX_V1_VSI "vsi"
90-
#define ADSBEX_V1_REG "reg"
91-
#define ADSBEX_V1_COUNTRY "cou"
92-
#define ADSBEX_V1_AC_TYPE_ICAO "type"
93-
#define ADSBEX_V1_MIL "mil"
94-
#define ADSBEX_V1_OP_ICAO "opicao"
95-
#define ADSBEX_V1_ORIGIN "from"
96-
#define ADSBEX_V1_DESTINATION "to"
97-
98-
#define ADSBEX_V1_TYPE_GND "-GND"
84+
#define ADSBEX_V2_TYPE_TISB "tisb_other" ///< type value for TIS-B data
9985

86+
// Version 1 keys (only for enabling meaningful error message)
87+
#define ADSBEX_V1_TRANSP_ICAO "icao" // Key data
10088

10189
// Testing an API key
102-
#define ADSBEX_VERIFY_KEY_URL "https://adsbexchange.com/api/aircraft/icao/000000"
103-
#define ADSBEX_ERR "msg"
104-
#define ADSBEX_SUCCESS "No error"
105-
#define ADSBEX_NO_API_KEY "You need an authorized API key."
106-
107-
#define ADSBEX_VERIFY_RAPIDAPI "https://adsbx-flight-sim-traffic.p.rapidapi.com/api/aircraft/json/lat/0.0/lon/0.0/dist/25/"
108-
#define ADSBEX_RAPID_ERR "message"
109-
#define ADSBEX_NO_RAPIDAPI_KEY "Key doesn't exists"
90+
#define ADSBEX_VERIFY_RAPIDAPI "https://adsbexchange-com1.p.rapidapi.com/v2/lat/0.0/lon/0.0/dist/1/"
11091

11192
#define ERR_ADSBEX_KEY_TECH "ADSBEx: Technical problem while testing key: %d - %s"
11293
#define MSG_ADSBEX_KEY_SUCCESS "ADS-B Exchange: API Key tested SUCCESSFULLY"
113-
#define ERR_ADSBEX_KEY_FAILED "ADS-B Exchange: API Key INVALID"
114-
#define ERR_ADSBEX_KEY_UNKNOWN "ADS-B Exchange: API Key test responded with unknown answer"
115-
#define ERR_ADSBEX_NO_KEY_DEF "ADS-B Exchange: API Key missing. Get one at adsbexchange.com and enter it in Basic Settings."
94+
#define ERR_ADSBEX_KEY_FAILED "ADS-B Exchange: API Key test FAILED: %s"
95+
#define ERR_ADSBEX_KEY_UNKNOWN "ADS-B Exchange: API Key test responded with unknown answer: %s"
96+
#define ERR_ADSBEX_NO_KEY_DEF "ADS-B Exchange: API Key missing. Get one at rapidapi.com/adsbx/api/adsbexchange-com1 and enter it in Basic Settings."
11697
#define ERR_ADSBEX_OTHER "ADS-B Exchange: Received an ERRor response: %s"
11798

11899
constexpr double ADSBEX_SMOOTH_AIRBORNE = 65.0; // smooth 65s of airborne data
@@ -131,29 +112,23 @@ class ADSBBase : public LTFlightDataChannel
131112
LTFlightDataChannel(ch, chName), sSlugBase(slugBase) {}
132113
/// Process ADSBEx foramtted data
133114
bool ProcessFetchedData () override;
134-
/// Give derived class chance for channel-specific error-checking
135-
virtual bool ProcessErrors (const JSON_Object* pObj) = 0;
136115
/// Process v2 data
137-
void ProcessV2 (JSON_Object* pJAc, LTFlightData::FDKeyTy& fdKey,
116+
void ProcessV2 (const JSON_Object* pJAc, LTFlightData::FDKeyTy& fdKey,
138117
const double tBufPeriod, const double adsbxTime,
139118
const positionTy& viewPos);
140-
/// Process v1 data
141-
void ProcessV1 (JSON_Object* pJAc, LTFlightData::FDKeyTy& fdKey,
142-
const double tsSimTime,
143-
const positionTy& viewPos);
119+
/// Give derived class chance for channel-specific error-checking
120+
virtual bool ProcessErrors (const JSON_Object* pObj) = 0;
121+
/// Return the 'msg' content, if any
122+
static std::string FetchMsg (const char* buf);
144123
};
145124

146125
//
147126
// MARK: ADS-B Exchange
148127
//
149128
class ADSBExchangeConnection : public ADSBBase
150129
{
151-
public:
152-
enum keyTypeE { ADSBEX_KEY_NONE=0, ADSBEX_KEY_EXCHANGE, ADSBEX_KEY_RAPIDAPI };
153-
154130
protected:
155131
std::string apiKey;
156-
keyTypeE keyTy = ADSBEX_KEY_NONE;
157132
struct curl_slist* slistKey = NULL;
158133
public:
159134
ADSBExchangeConnection ();
@@ -174,12 +149,11 @@ class ADSBExchangeConnection : public ADSBBase
174149
bool ProcessErrors (const JSON_Object* pObj) override;
175150

176151
// make list of HTTP header fields
177-
static struct curl_slist* MakeCurlSList (keyTypeE keyTy, const std::string theKey);
152+
static struct curl_slist* MakeCurlSList (const std::string theKey);
178153
// read header and parse for request limit/remaining
179154
static size_t ReceiveHeader(char *buffer, size_t size, size_t nitems, void *userdata);
180155

181156
public:
182-
static keyTypeE GetKeyType (const std::string theKey);
183157
// Just quickly sends one simple request to ADSBEx and checks if the response is not "NO KEY"
184158
// Does a SHOW_MSG about the result and saves the key to dataRefs on success.
185159
static void TestADSBExAPIKey (const std::string newKey);

LiveTraffic.xcodeproj/project.pbxproj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@
598598
KnownAssetTags = (
599599
New,
600600
);
601-
LastUpgradeCheck = 1610;
601+
LastUpgradeCheck = 1620;
602602
};
603603
buildConfigurationList = D607B16209A5563100699BC3 /* Build configuration list for PBXProject "LiveTraffic" */;
604604
compatibilityVersion = "Xcode 12.0";
@@ -807,8 +807,8 @@
807807
LIBRARY_SEARCH_PATHS = Lib/fmod;
808808
LIVETRAFFIC_VERSION_BETA = 0;
809809
LIVETRAFFIC_VER_MAJOR = 4;
810-
LIVETRAFFIC_VER_MINOR = 1;
811-
LIVETRAFFIC_VER_PATCH = 1;
810+
LIVETRAFFIC_VER_MINOR = 2;
811+
LIVETRAFFIC_VER_PATCH = 0;
812812
LLVM_LTO = NO;
813813
MACH_O_TYPE = mh_dylib;
814814
MACOSX_DEPLOYMENT_TARGET = 10.15;
@@ -916,8 +916,8 @@
916916
LIBRARY_SEARCH_PATHS = Lib/fmod;
917917
LIVETRAFFIC_VERSION_BETA = 0;
918918
LIVETRAFFIC_VER_MAJOR = 4;
919-
LIVETRAFFIC_VER_MINOR = 1;
920-
LIVETRAFFIC_VER_PATCH = 1;
919+
LIVETRAFFIC_VER_MINOR = 2;
920+
LIVETRAFFIC_VER_PATCH = 0;
921921
LLVM_LTO = YES;
922922
MACH_O_TYPE = mh_dylib;
923923
MACOSX_DEPLOYMENT_TARGET = 10.15;

LiveTraffic.xcodeproj/xcuserdata/birger.xcuserdatad/xcschemes/LiveTraffic.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1610"
3+
LastUpgradeVersion = "1620"
44
version = "1.8">
55
<BuildAction
66
parallelizeBuildables = "YES"

Src/DataRefs.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2033,7 +2033,7 @@ bool DataRefs::LoadConfigFile()
20332033

20342034
// which conversion to do with the (older) version of the config file?
20352035
unsigned long cfgFileVer = 0;
2036-
enum cfgFileConvE { CFG_NO_CONV=0, CFG_V3, CFG_V31, CFG_V331, CFG_V342, CFG_V350 } conv = CFG_NO_CONV;
2036+
enum cfgFileConvE { CFG_NO_CONV=0, CFG_V3, CFG_V31, CFG_V331, CFG_V342, CFG_V350, CFG_V420 } conv = CFG_NO_CONV;
20372037

20382038
// open a config file
20392039
std::string sFileName (LTCalcFullPath(PATH_CONFIG_FILE));
@@ -2103,6 +2103,8 @@ bool DataRefs::LoadConfigFile()
21032103
rtConnType = RT_CONN_APP; // Switch RealTraffic default to App as it was before
21042104
conv = CFG_V350;
21052105
}
2106+
if (cfgFileVer < 40200) // < 4.2.0: Clear ADSBEx API key (switch to other service)
2107+
conv = CFG_V420;
21062108
}
21072109
}
21082110

@@ -2174,6 +2176,11 @@ bool DataRefs::LoadConfigFile()
21742176
// RealTraffic Sim Time Control: previous value 1 is re-purposed, switch instead to 2
21752177
if (*i == DATA_REFS_LT[DR_CFG_RT_SIM_TIME_CTRL] && sVal == "1")
21762178
sVal = "2";
2179+
[[fallthrough]];
2180+
case CFG_V420:
2181+
// Switching to v4.2 we need to disable ADSBEx until a new API key is configured
2182+
if (*i == DATA_REFS_LT[DR_CHANNEL_ADSB_EXCHANGE_ONLINE])
2183+
sVal = "0";
21772184
break;
21782185
}
21792186

@@ -2200,9 +2207,11 @@ bool DataRefs::LoadConfigFile()
22002207
SetOpenSkyUser(sVal);
22012208
else if (sDataRef == CFG_OPENSKY_PWD)
22022209
SetOpenSkyPwd(Cleartext(sVal));
2203-
else if (sDataRef == CFG_ADSBEX_API_KEY)
2204-
// With v3 we start obfuscating the API key
2205-
SetADSBExAPIKey(conv == CFG_V3 ? sVal : Cleartext(sVal));
2210+
else if (sDataRef == CFG_ADSBEX_API_KEY) {
2211+
// With v4.2 ADSBEx switches to a new service, so we need a new API key
2212+
if (conv != CFG_V420)
2213+
SetADSBExAPIKey(Cleartext(sVal));
2214+
}
22062215
else if (sDataRef == CFG_RT_LICENSE)
22072216
SetRTLicense(Cleartext(sVal));
22082217
else if (sDataRef == CFG_FSC_USER)

0 commit comments

Comments
 (0)