Skip to content

Commit 6014c2f

Browse files
authored
Merge pull request #280 from TwinFan/Next
v4.2.0
2 parents e0c7bc2 + 4b6e02e commit 6014c2f

File tree

15 files changed

+256
-369
lines changed

15 files changed

+256
-369
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
#####################################
1717
# Linux with GCC
1818
build-lin:
19-
runs-on: ubuntu-20.04
19+
runs-on: ubuntu-22.04
2020
env:
2121
platform: lin
2222
steps:

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.1
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/InfoListWnd.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
//
2727
class InfoListWnd : public LTImgWindow
2828
{
29-
protected:
29+
public:
3030
enum ILWTabTy { ILW_TAB_NONE=0, ILW_TAB_AC_LIST, ILW_TAB_MSG, ILW_TAB_STATUS, ILW_TAB_SETTINGS };
31+
protected:
3132
ILWTabTy activeTab = ILW_TAB_NONE;
3233
std::string wndTitle; ///< current window title, contains opened tab
3334

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);

Lib/LTAPI/LTAPI.h

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/// textual info like type, registration, call sign, flight number.
1111
/// @see https://twinfan.github.io/LTAPI/
1212
/// @author Birger Hoppe
13-
/// @copyright (c) 2019-2020 Birger Hoppe
13+
/// @copyright (c) 2019-2025 Birger Hoppe
1414
/// @copyright Permission is hereby granted, free of charge, to any person obtaining a
1515
/// copy of this software and associated documentation files (the "Software"),
1616
/// to deal in the Software without restriction, including without limitation
@@ -41,6 +41,10 @@
4141
#include "XPLMGraphics.h"
4242

4343
class LTDataRef;
44+
class LTAPIAircraft;
45+
46+
/// Smart pointer to an LTAPIAircraft object
47+
typedef std::shared_ptr<LTAPIAircraft> SPtrLTAPIAircraft;
4448

4549
/// @brief Represents one aircraft as controlled by LiveTraffic.
4650
///
@@ -62,6 +66,7 @@ class LTAPIAircraft
6266
/// @brief Flight phase, definition copied from LiveTraffic
6367
enum LTFlightPhase {
6468
FPH_UNKNOWN = 0, ///< used for initializations
69+
FPH_PARKED = 5, ///< Parked at startup position
6570
FPH_TAXI = 10, ///< Taxiing
6671
FPH_TAKE_OFF = 20, ///< Group of status for take-off:
6772
FPH_TO_ROLL, ///< Take-off roll
@@ -117,7 +122,7 @@ class LTAPIAircraft
117122
bool bcn : 1; ///< beacon light
118123
bool strb : 1; ///< strobe light
119124
bool nav : 1; ///< navigaton lights
120-
unsigned filler1 : 1; ///< unused
125+
unsigned hidden : 1; ///< aircraft _not_ visible? (remains an 'unsigned' for backward compatibility)
121126
bool camera : 1; ///< is LiveTraffic's camera on this aircraft?
122127
// Misc
123128
int multiIdx : 8; ///< multiplayer index if plane reported via sim/multiplayer/position dataRefs, 0 if not
@@ -211,6 +216,15 @@ class LTAPIAircraft
211216
/// Helper in update loop, resets `bUpdated` flag
212217
void resetUpdated () { bUpdated = false; }
213218

219+
/// @brief Called when LiveTraffic toggles its aircraft camera, override in your class to handle event
220+
/// @param bCameraActive `True` if camera is on this aircraft now, `false` if camera is switched off
221+
/// @param spPrevAc May point to previous aircraft under camera if switching directly from one to this; can be `null`
222+
virtual void toggleCamera ([[maybe_unused]] bool bCameraActive,
223+
[[maybe_unused]] SPtrLTAPIAircraft spPrevAc) {}
224+
225+
/// @brief Declare the aircraft the one under the camera (e.g. if your plugin is a camera plugin and now views this aircraft)
226+
void setCameraAc ();
227+
214228
// data access
215229
public:
216230
std::string getKey() const { return key; } ///< Unique key for this aircraft, usually ICAO transponder hex code
@@ -250,6 +264,7 @@ class LTAPIAircraft
250264
bool isOnGnd() const { return bulk.bits.onGnd; } ///< Is plane on ground?
251265
LTFlightPhase getPhase() const { return bulk.bits.phase; } ///< flight phase
252266
std::string getPhaseStr() const; ///< flight phase as string
267+
bool isVisible() const { return !bulk.bits.hidden; } ///< aircraft visible?
253268
// configuration
254269
float getFlaps() const { return bulk.flaps; } ///< flap position: 0.0 retracted, 1.0 fully extended
255270
float getGear() const { return bulk.gear; } ///< gear position: 0.0 retracted, 1.0 fully extended
@@ -268,7 +283,7 @@ class LTAPIAircraft
268283
/// @param[out] y Local y coordinate
269284
/// @param[out] z Local z coordinate
270285
void getLocalCoord (double& x, double& y, double& z) const
271-
{ XPLMWorldToLocal(bulk.lat,bulk.lon,bulk.alt_ft, &x,&y,&z); }
286+
{ XPLMWorldToLocal(bulk.lat,bulk.lon,bulk.alt_ft*0.3048, &x,&y,&z); }
272287

273288
public:
274289
/// @brief Standard object creation callback.
@@ -280,9 +295,6 @@ class LTAPIAircraft
280295
// MapLTAPIAircraft
281296
//
282297

283-
/// Smart pointer to an TLAPIAircraft object
284-
typedef std::shared_ptr<LTAPIAircraft> SPtrLTAPIAircraft;
285-
286298
/// @brief Map of all aircrafts stored as smart pointers to LTAPIAircraft objects
287299
///
288300
/// This is what LTAPIConnect::UpdateAcList() returns: a map of all aircrafts.
@@ -363,7 +375,7 @@ class LTAPIConnect
363375
/// Depending on startup order, LiveTraffic might or might not have been started yet.
364376
/// This note is basically true for all requests accessing LiveTraffic data.
365377
/// It is noted here only because it is tempting to fetch the version number once only during startup.
366-
/// @return Version (like 201 for v2.01), or constant 150 if unknown, or 0 if LiveTraffic is unavailable
378+
/// @return Version (like 40101 for v4.1.1), or constant 150 if unknown, or 0 if LiveTraffic is unavailable
367379
static int getLTVerNr();
368380

369381
/// @brief LiveTraffic's version date
@@ -418,6 +430,9 @@ class LTAPIConnect
418430
/// @return Pointer to aircraft in camera view, is empty if none is being viewed
419431
SPtrLTAPIAircraft getAcInCameraView () const;
420432

433+
/// @brief Clear camera information, ie. delcare that no aircraft is currently being viewed
434+
void clearCameraInfo ();
435+
421436
protected:
422437
/// @brief fetch bulk data and create/update aircraft objects
423438
/// @param numAc Total number of aircraft to fetch
@@ -430,6 +445,8 @@ class LTAPIConnect
430445
bool DoBulkFetch (int numAc, LTDataRef& DR, int& outSizeLT,
431446
std::unique_ptr<T[]> &vBulk);
432447

448+
/// @brief shared DataRef event notification
449+
static void CameraSharedDataCB (LTAPIConnect* me);
433450
};
434451

435452

Lib/XPMP2

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/ACTable.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,11 +472,15 @@ bool ACTable::UpdateFDIs (const std::string& _filter)
472472
vecFDI.reserve(mapFd.size());
473473

474474
// First pass: Add all matching and remember those we couldn't get
475+
const bool bHideStatic = dataRefs.GetHideStaticTwr();
475476
std::vector<FDInfo> vecAgain;
476477
for (const mapLTFlightDataTy::value_type& p: mapFd) {
477478
// First filter: Visible a/c only?
478479
if (bFilterAcOnly && (!p.second.hasAc() || !p.second.GetAircraft()->IsVisible()))
479480
continue;
481+
// 2nd filter: Don't show static objects
482+
if (bHideStatic && p.second.GetUnsafeStat().isStaticObject())
483+
continue;
480484
// others: test if filter matches
481485
FDInfo fdi(p.second);
482486
if (fdi.upToDate()) {

0 commit comments

Comments
 (0)