Skip to content

Commit b0498e4

Browse files
authored
Merge pull request #292 from TwinFan/Next
v4.3.0
2 parents d408a38 + 54a1b0d commit b0498e4

32 files changed

+862
-199
lines changed

CMakeLists.txt

Lines changed: 3 additions & 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.2.1
26+
VERSION 4.3.0
2727
DESCRIPTION "LiveTraffic X-Plane plugin")
2828
set(VERSION_BETA 0)
2929

@@ -167,6 +167,7 @@ set(Header_Files
167167
Include/LTADSBHub.h
168168
Include/LTAircraft.h
169169
Include/LTApt.h
170+
Include/LTAutoATC.h
170171
Include/LTChannel.h
171172
Include/LTFlightData.h
172173
Include/LTForeFlight.h
@@ -214,6 +215,7 @@ set(Source_Files
214215
Src/LTADSBHub.cpp
215216
Src/LTAircraft.cpp
216217
Src/LTApt.cpp
218+
Src/LTAutoATC.cpp
217219
Src/LTChannel.cpp
218220
Src/LTFlightData.cpp
219221
Src/LTForeFlight.cpp
477 Bytes
Binary file not shown.

Data/AutoATC/AutoATC.sjson/data

171 Bytes
Binary file not shown.
214 Bytes
Binary file not shown.
Binary file not shown.

Include/Constants.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ constexpr const char* REMOTE_SIGNATURE = "TwinFan.plugin.XPMP2.Remote";
270270
#define HELP_SET_CH_REALTRAFFIC "setup/installation/realtraffic-connectivity"
271271
#define HELP_SET_CH_FSCHARTER "setup/installation/fscharter"
272272
#define HELP_SET_CH_SI "setup/installation/sayintentions"
273+
#define HELP_SET_CH_AUTOATC "setup/installation/autoatc"
273274
#define HELP_SET_OUTPUT_CH "setup/installation/foreflight" // currently the same as ForeFlight, which is the only output channel
274275
#define HELP_SET_CH_FOREFLIGHT "setup/installation/foreflight"
275276
#define HELP_SET_ACLABELS "setup/configuration/settings-a-c-labels"

Include/DataRefs.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ enum dataRefsLT {
434434
DR_CHANNEL_FUTUREDATACHN_ONLINE, // placeholder, first channel
435435
DR_CHANNEL_FORE_FLIGHT_SENDER,
436436
DR_CHANNEL_SYNTHETIC,
437+
DR_CHANNEL_AUTOATC,
437438
DR_CHANNEL_SAYINTENTIONS,
438439
DR_CHANNEL_FSCHARTER,
439440
DR_CHANNEL_OPEN_GLIDER_NET,
@@ -475,6 +476,13 @@ enum SimTimeCtrlTy : int {
475476
STC_SIM_TIME_PLUS_BUFFER, ///< Send current sim time plus buffering period, so that the traffic, when it appears, matches up with current sim time
476477
};
477478

479+
/// Which amount of planes to send to ForeFlight?
480+
enum TrafficToSendTy : int {
481+
TTS_NONE = 0, ///< Don't send any traffic
482+
TTS_ALL, ///< Send all known planes
483+
TTS_NONTCAS_ONLY, ///< Send only planes that don't have a TCAS slot in X-Plane
484+
};
485+
478486
/// How to control weather?
479487
enum WeatherCtrlTy : int {
480488
WC_INIT = -1, ///< Initial value when not available in config file, then a default is determined in first flight loop depending if XP is using real weather
@@ -682,8 +690,7 @@ class DataRefs
682690
std::string LTPluginPath; // path to plugin directory
683691
std::string DirSeparator;
684692
int bChannel[CNT_DR_CHANNELS]; // is channel enabled?
685-
double chTsOffset = 0.0f; // offset of network time compared to system clock
686-
int chTsOffsetCnt = 0; // how many offset reports contributed to the calculated average offset?
693+
double chTsOffset = NAN; ///< offset of network time compared to system clock
687694
int iTodaysDayOfYear = 0;
688695
time_t tStartThisYear = 0, tStartPrevYear = 0;
689696
int lastCheckNewVer = 0; // when did we last check for updates? (hours since the epoch)
@@ -746,7 +753,7 @@ class DataRefs
746753
int ffListenPort = 63093; ///< UDP Port to listen to ForeFlight announcing itself, https://www.foreflight.com/connect/spec/
747754
int ffSendPort = 49002; ///< UDP Port to send simulator data to ForeFlight, https://www.foreflight.com/support/network-gps/
748755
int bffUserPlane = 1; // bool Send User plane data?
749-
int bffTraffic = 1; // bool Send traffic data?
756+
TrafficToSendTy ffTraffic=TTS_ALL; ///< Send traffic data? And which amount of traffic?
750757
int ffSendTrfcIntvl = 3; // [s] interval to broadcast traffic info
751758

752759
vecCSLPaths vCSLPaths; // list of paths to search for CSL packages
@@ -1033,11 +1040,9 @@ class DataRefs
10331040
const std::string& GetSIDisplayName () const { return sSIDisplayName; }
10341041
void SetSIDisplayName (const std::string& dn) { sSIDisplayName = dn; }
10351042

1036-
// timestamp offset network vs. system clock
1037-
inline void ChTsOffsetReset() { chTsOffset = 0.0f; chTsOffsetCnt = 0; }
1038-
inline double GetChTsOffset () const { return chTsOffset; }
1039-
bool ChTsAcceptMore () const { return cntAc == 0 && chTsOffsetCnt < CntChannelEnabled() * 2; }
1040-
void ChTsOffsetAdd (double aNetTS);
1043+
/// Get current time from a network resource to determine the offset of this computer to real time
1044+
void GetNetwTsOffset ();
1045+
inline double GetChTsOffset () const { return std::isnan(chTsOffset) ? 0.0 : chTsOffset; }
10411046

10421047
// livetraffic/dbg/ac_filter: Debug a/c filter (the integer is converted to hex as an transpIcao key)
10431048
std::string GetDebugAcFilter() const;

Include/LTAutoATC.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/// @file LTAutoATC.h
2+
/// @brief Channel to AutoATC traffic
3+
/// @see https://autoatc.zem-solutions.com/
4+
/// @details Defines AutoATCConnection:\n
5+
/// Takes AI traffic generated by AutoATC
6+
/// @author Birger Hoppe
7+
/// @copyright (c) 2025 Birger Hoppe
8+
/// @copyright Permission is hereby granted, free of charge, to any person obtaining a
9+
/// copy of this software and associated documentation files (the "Software"),
10+
/// to deal in the Software without restriction, including without limitation
11+
/// the rights to use, copy, modify, merge, publish, distribute, sublicense,
12+
/// and/or sell copies of the Software, and to permit persons to whom the
13+
/// Software is furnished to do so, subject to the following conditions:\n
14+
/// The above copyright notice and this permission notice shall be included in
15+
/// all copies or substantial portions of the Software.\n
16+
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
/// THE SOFTWARE.
23+
24+
#ifndef LTAutoATC_h
25+
#define LTAutoATC_h
26+
27+
#include "LTChannel.h"
28+
29+
//
30+
//MARK: AutoATC Constants
31+
//
32+
#define AATC_CHECK_NAME "AutoATC Generated Traffic"
33+
#define AATC_CHECK_URL "https://autoatc.zem-solutions.com/Status.html"
34+
#define AATC_CHECK_POPUP "See AutoATC's status, but there is no list or map of flights"
35+
36+
#define AATC_NAME "AutoATC"
37+
#define AATC_URL "https://load1.zem-solutions.com/AutoATCPeek?lat=%.4f&lon=%.4f"
38+
39+
#define AATC_RESULT "result" ///< expected to be "success", all else treated as failure
40+
#define AATC_RESULT_SUCCESS "success"
41+
#define AATC_DATA "data" ///< array of aircraft
42+
#define AATC_TIMESTAMP "timestamp" ///< when was the response compiled, used as timestamp for all positions
43+
44+
#define AATC_KEY "ADS-B"
45+
#define AATC_LAT "lat"
46+
#define AATC_LON "lon"
47+
#define AATC_ALT "alt"
48+
#define AATC_HEADING "h"
49+
#define AATC_GND "ground"
50+
#define AATC_CALL_SPOKEN "cs" ///< callsign as spoken, e.g. "air serbia 4139"
51+
#define AATC_AC_TYPE "af"
52+
#define AATC_OP_ICAO "icao" ///< ICAO operator code
53+
54+
//
55+
// MARK: SayIntentions connection class
56+
//
57+
58+
/// Connection to AutoATC
59+
class AutoATCConnection : public LTFlightDataChannel
60+
{
61+
public:
62+
AutoATCConnection (); ///< Constructor
63+
std::string GetURL (const positionTy& pos) override; ///< returns the URL to AutoATC traffic by position
64+
bool ProcessFetchedData () override; ///< Process response, forwarding to the processing queues
65+
protected:
66+
void Main () override; ///< virtual thread main function
67+
};
68+
69+
#endif /* LTAutoATC_h */

Include/LTFlightData.h

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,22 @@ class LTFlightData
161161

162162
// KEY (protected, can be set only once, no mutex-control)
163163
public:
164-
// in ascending order of priority
165-
enum FDKeyType { KEY_UNKNOWN=0, KEY_OGN, KEY_RT, KEY_FLARM, KEY_ICAO, KEY_FSC, KEY_ADSBEX, KEY_SAYINTENTIONS };
164+
/// Types/origin of an aircraft's id, though some types are interchangeable
165+
enum FDKeyType : unsigned {
166+
KEY_UNKNOWN=0,
167+
// the "interchangeable" key types, which essentially signify the same number range, they "compare equal" for the purpose of operator==()
168+
KEY_ICAO,
169+
KEY_FLARM,
170+
KEY_ADSBEX,
171+
KEY_RT,
172+
KEY_OGN,
173+
// here starts the range of non-interchangeable, truly organisation-specific keys
174+
KEY_ORG_SPECIFIC = 0x0010,
175+
KEY_FSC,
176+
KEY_SAYINTENTIONS,
177+
KEY_AUTOATC,
178+
KEY_PRIVATE, // plane doesn't want to be identified, so we generate a private internally key ourselves
179+
};
166180
struct FDKeyTy {
167181
FDKeyType eKeyType = KEY_UNKNOWN;
168182
std::string key; // the primary key in use
@@ -183,10 +197,10 @@ class LTFlightData
183197
FDKeyTy& operator=(const FDKeyTy& o) = default;
184198
FDKeyTy& operator=(FDKeyTy&& o) = default;
185199

186-
// strict order based on numeric value
187-
inline bool operator==(const FDKeyTy& o) const { return eKeyType == o.eKeyType && num == o.num; }
188-
inline bool operator!=(const FDKeyTy& o) const { return eKeyType != o.eKeyType || num != o.num; }
189-
inline bool operator<(const FDKeyTy& o) const { return eKeyType == o.eKeyType ? num < o.num : eKeyType < o.eKeyType; }
200+
// strict order based on key type and numeric value
201+
bool operator==(const FDKeyTy& o) const;
202+
bool operator!=(const FDKeyTy& o) const { return !operator==(o); }
203+
bool operator<(const FDKeyTy& o) const;
190204

191205
// imitate some (std::)string functionality
192206
inline bool operator==(const std::string o) const { return key == o; }
@@ -195,16 +209,15 @@ class LTFlightData
195209

196210
inline const char* c_str() const { return key.c_str(); }
197211
inline bool empty() const { return key.empty(); }
212+
inline operator bool() const { return !num && !key.empty(); }
198213
void clear() { *this = FDKeyTy(); }
199214

200-
// matches any string?
201-
bool isMatch (const std::string t) const;
202-
203215
/// return the type of key (as string)
204216
const char* GetKeyTypeText () const;
205217
};
206218
protected:
207-
FDKeyTy acKey;
219+
FDKeyTy acKey; ///< the planes unique identifier, publicly visible
220+
FDKeyTy acPrivateKey; ///< (optional) the true but private, ie. non-public identifier of the plane, for purposes of matching against public planes
208221

209222
// last used Receiver ID, identifies the receiver of the signal of this flight data
210223
int rcvr;
@@ -286,8 +299,9 @@ class LTFlightData
286299
void SetKey (FDKeyType eType, const std::string _key, int base=16) { acKey.SetKey(eType, _key, base); }
287300
const FDKeyTy& key() const { return acKey; }
288301
std::string keyDbg() const { return key().key + ' ' + statData.acId("-"); }
289-
/// Checks for a duplicate key on another key type and updates _key if so
290-
static bool CheckDupKey(FDKeyTy& _key, FDKeyType _ty);
302+
/// Set a private hidden key
303+
void SetPrivateKey (const FDKeyTy& _privKey) { acPrivateKey = _privKey; }
304+
const FDKeyTy& keyPrivate() const { return acPrivateKey; }
291305

292306
// Search support: icao, registration, call sign, flight number matches?
293307
bool IsMatch (const std::string t) const;
@@ -451,4 +465,13 @@ mapLTFlightDataTy::iterator mapFdAcByIdx (int idx);
451465
/// Find a/c by text, compares with key, call sigh, registration etc., passes pure numbers to mapFdAcByIdx()
452466
mapLTFlightDataTy::iterator mapFdSearchAc (const std::string& _s);
453467

468+
/// Return aircraft with given key (optionally: if it has an active aircraft)
469+
LTFlightData* mapFdAc (const LTFlightData::FDKeyTy& key,
470+
bool bMustHaveAc = false);
471+
472+
/// Do we know an aircraft with the given key (no matter if currently displayed or not)
473+
inline bool mapFdHasAc (const LTFlightData::FDKeyTy& key,
474+
bool bMustHaveAc = false)
475+
{ return mapFdAc(key,bMustHaveAc) != nullptr; }
476+
454477
#endif /* LTFlightData_h */

Include/LTOpenGlider.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ class OpenGliderConnection : public LTFlightDataChannel
230230
/// @return Shall the aircraft be displayed at all? (Otherwise it is marked non-trackable and we shall not show it.)
231231
bool AcListLookup (const std::string& sDevId,
232232
LTFlightData::FDKeyTy& key,
233+
LTFlightData::FDKeyTy& privateKey,
233234
LTFlightData::FDStaticData& stat);
234235
};
235236

0 commit comments

Comments
 (0)