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
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"
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
11899constexpr 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//
149128class ADSBExchangeConnection : public ADSBBase
150129{
151- public:
152- enum keyTypeE { ADSBEX_KEY_NONE=0 , ADSBEX_KEY_EXCHANGE, ADSBEX_KEY_RAPIDAPI };
153-
154130protected:
155131 std::string apiKey;
156- keyTypeE keyTy = ADSBEX_KEY_NONE;
157132 struct curl_slist * slistKey = NULL ;
158133public:
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
181156public:
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);
0 commit comments