Skip to content

Commit

Permalink
Merge pull request #238 from TwinFan/Next
Browse files Browse the repository at this point in the history
v3.0.0
  • Loading branch information
TwinFan authored Jul 8, 2022
2 parents 1cd3a2d + 68366fb commit feaa050
Show file tree
Hide file tree
Showing 20 changed files with 1,342 additions and 1,849 deletions.
817 changes: 0 additions & 817 deletions Data/ADSB/REST/ADSBExchange_20180402_1955_UTC.json

This file was deleted.

470 changes: 470 additions & 0 deletions Data/ADSB/REST/ADSBExchange_v2.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions Include/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,9 @@ constexpr const char* REMOTE_SIGNATURE = "TwinFan.plugin.XPMP2.Remote";
#define MSG_TIMESTAMPS "Current System time is %sZ, current simulated time is %s"
#define MSG_AI_LOAD_ACF "Changing AI control: X-Plane is now loading AI Aircraft models..."
#define MSG_REQUESTING_LIVE_FD "Requesting live flight data online..."
#define MSG_READING_HIST_FD "Reading historic flight data..."
#define MSG_NUM_AC_INIT "Initially created %d aircraft"
#define MSG_NUM_AC_ZERO "No more aircraft displayed"
#define MSG_BUF_FILL_COUNTDOWN "Filling buffer: seeing %d aircraft, displaying %d, still %ds to buffer"
#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."
#define INFO_WEATHER_UPDATED "Weather updated: QNH %.f hPa at %s (%.2f / %.2f)"
#define INFO_AC_ADDED "Added aircraft %s, operator '%s', a/c model '%s', flight model [%s], bearing %.0f, distance %.1fnm, from channel %s"
#define INFO_AC_MDL_CHANGED "Changed CSL model for aircraft %s, operator '%s': a/c model now '%s' (Flight model '%s')"
Expand Down Expand Up @@ -205,6 +203,8 @@ constexpr const char* REMOTE_SIGNATURE = "TwinFan.plugin.XPMP2.Remote";
#define CFG_DEFAULT_CAR_TYPE "DEFAULT_CAR_TYPE"
#define CFG_DEFAULT_AC_TYP_INFO "Default a/c type is '%s'"
#define CFG_DEFAULT_CAR_TYP_INFO "Default car type is '%s'"
#define CFG_OPENSKY_USER "OpenSky_User"
#define CFG_OPENSKY_PWD "OpenSky_Pwd"
#define CFG_ADSBEX_API_KEY "ADSBEX_API_KEY"
#define CFG_FSC_USER "FSC_User"
#define CFG_FSC_PWD "FSC_Pwd"
Expand Down Expand Up @@ -291,6 +291,7 @@ constexpr long HTTP_BAD_REQUEST = 400;
constexpr long HTTP_UNAUTHORIZED = 401;
constexpr long HTTP_FORBIDDEN = 403;
constexpr long HTTP_NOT_FOUND = 404;
constexpr long HTTP_TOO_MANY_REQU = 429; ///< too many requests, e.g. OpenSky after request limit ran out
constexpr long HTTP_BAD_GATEWAY = 502; // typical cloudflare responses: Bad Gateway
constexpr long HTTP_NOT_AVAIL = 503; // Service not available
constexpr long HTTP_GATEWAY_TIMEOUT=504; // Gateway Timeout
Expand Down
40 changes: 30 additions & 10 deletions Include/DataRefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,11 @@ enum dataRefsXP {
DR_PLANE_PITCH,
DR_PLANE_ROLL,
DR_PLANE_HEADING,
DR_PLANE_MAG_HEADING, ///< sim/flightmodel/position/mag_psi float n degrees The real magnetic heading of the aircraft
DR_PLANE_TRACK,
DR_PLANE_TRUE_AIRSPEED,
DR_PLANE_KIAS, ///< sim/flightmodel/position/indicated_airspeed float y kias Air speed indicated - this takes into account air density and wind direction
DR_PLANE_TAS, ///< sim/flightmodel/position/true_airspeed float n meters/sec Air speed true - this does not take into account air density at altitude!
DR_PLANE_GS, ///< sim/flightmodel/position/groundspeed float n meters/sec The ground speed of the aircraft
DR_PLANE_VVI, ///< sim/flightmodel/position/vh_ind float n meters/second VVI (vertical velocity in meters per second)
DR_PLANE_ONGRND,
DR_PLANE_REG, ///< sim/aircraft/view/acf_tailnum byte[40] y string Tail number
Expand Down Expand Up @@ -357,7 +360,6 @@ enum dataRefsLT {
DR_CFG_LOG_LEVEL,
DR_CFG_MSG_AREA_LEVEL,
DR_CFG_LOG_LIST_LEN,
DR_CFG_USE_HISTORIC_DATA,
DR_CFG_MAX_NUM_AC,
DR_CFG_FD_STD_DISTANCE,
DR_CFG_FD_SNAP_TAXI_DIST,
Expand Down Expand Up @@ -386,6 +388,7 @@ enum dataRefsLT {
DR_DBG_EXPORT_FD,
DR_DBG_EXPORT_USER_AC,
DR_DBG_EXPORT_NORMALIZE_TS,
DR_DBG_EXPORT_FORMAT,

// channel configuration options
DR_CFG_FSC_ENV,
Expand Down Expand Up @@ -425,6 +428,12 @@ enum cmdRefsLT {
CNT_CMDREFS_LT // always last, number of elements
};

/// Which format to use for exporting flight tracking data
enum exportFDFormat {
EXP_FD_AITFC = 1, ///< use AITFC format, the older shorter format
EXP_FD_RTTFC, ///< user RTTFC format, introduced with RealTraffic v9
};

// first/last channel; number of channels:
constexpr int DR_CHANNEL_FIRST = DR_CHANNEL_FUTUREDATACHN_ONLINE;
constexpr int DR_CHANNEL_LAST = CNT_DATAREFS_LT-1;
Expand Down Expand Up @@ -606,6 +615,7 @@ class DataRefs
unsigned uDebugAcFilter = 0; // icao24 for a/c filter
int bDebugAcPos = false;// output debug info on position calc into log file?
int bDebugLogRawFd = false;// log raw flight data to LTRawFD.log
exportFDFormat eDebugExportFdFormat = EXP_FD_AITFC; ///< Which format to use when exporting flight data?
int bDebugExportFd = false;// export flight data to LTExportFD.csv
int bDebugExportUserAc = false;///< export user's aircraft data to LTExportFD.csv
float lastExportUserAc = 0.0f; ///< last time user's aircraft data has been written to export file
Expand All @@ -614,7 +624,6 @@ class DataRefs
std::string XPSystemPath;
std::string LTPluginPath; // path to plugin directory
std::string DirSeparator;
int bUseHistoricData = false;
int bChannel[CNT_DR_CHANNELS]; // is channel enabled?
double chTsOffset = 0.0f; // offset of network time compared to system clock
int chTsOffsetCnt = 0; // how many offset reports contributed to the calculated average offset?
Expand Down Expand Up @@ -671,9 +680,11 @@ class DataRefs

std::string sDefaultAcIcaoType = CSL_DEFAULT_ICAO_TYPE;
std::string sDefaultCarIcaoType = CSL_CAR_ICAO_TYPE;
std::string sOpenSkyUser; ///< OpenSky Network user
std::string sOpenSkyPwd; ///< OpenSky Network password
std::string sADSBExAPIKey; ///< ADS-B Exchange API key
std::string sFSCUser; ///< FSCharter login user
std::string sFSCPwd; ///< FSCharter login password, base64-encoded
std::string sFSCPwd; ///< FSCharter login password

// live values
bool bReInitAll = false; // shall all a/c be re-initiaized (e.g. time jumped)?
Expand Down Expand Up @@ -701,7 +712,9 @@ class DataRefs
public:
/// once per Flarm a/c type: matching it to one or more ICAO types
std::array<std::vector<std::string>, 14> aFlarmToIcaoAcTy;


long OpenSkyRRemain = LONG_MAX; ///< OpenSky: Remaining number of requests per day
std::string OpenSkyRetryAt; ///< OpenSky: If limit is reached, when to retry? (local time as string)
long ADSBExRLimit = 0; // ADSBEx: Limit on RapidAPI
long ADSBExRRemain = 0; // ADSBEx: Remaining Requests on RapidAPI

Expand Down Expand Up @@ -792,7 +805,6 @@ class DataRefs
std::string GetSimTimeString() const;

// livetraffic/sim/date and .../time
static void LTSetSimDateTime(void* p, int i);
static int LTGetSimDateTime(void* p);

/// Are we in replay mode?
Expand All @@ -813,10 +825,8 @@ class DataRefs
inline logLevelTy GetLogLevel() { return iLogLevel; }
inline logLevelTy GetMsgAreaLevel() { return iMsgAreaLevel; }

// livetraffic/cfg/use_historic_data: Simulate history
static void LTSetUseHistData(void*, int i);
bool SetUseHistData (bool bUseHistData, bool bForceReload);
inline bool GetUseHistData() const { return bUseHistoricData; }
/// Reinit data usage
void ForceDataReload ();

// general config values
static void LTSetCfgValue(void* p, int val);
Expand Down Expand Up @@ -880,6 +890,11 @@ class DataRefs
inline bool IsChannelEnabled (dataRefsLT ch) const { return bChannel[ch - DR_CHANNEL_FIRST]; }
int CntChannelEnabled () const;

void GetOpenSkyCredentials (std::string& user, std::string& pwd)
{ user = sOpenSkyUser; pwd = sOpenSkyPwd; }
void SetOpenSkyUser (const std::string& user) { sOpenSkyUser = user; OpenSkyRRemain = LONG_MAX; }
void SetOpenSkyPwd (const std::string& pwd) { sOpenSkyPwd = pwd; OpenSkyRRemain = LONG_MAX; }

std::string GetADSBExAPIKey () const { return sADSBExAPIKey; }
void SetADSBExAPIKey (std::string apiKey) { sADSBExAPIKey = apiKey; }

Expand Down Expand Up @@ -912,6 +927,8 @@ class DataRefs
inline bool GetDebugLogRawFD() const { return bDebugLogRawFd; }
void SetDebugLogRawFD (bool bLog) { bDebugLogRawFd = bLog; }

exportFDFormat GetDebugExportFormat() const { return eDebugExportFdFormat; }
void SetDebugExportFormat (exportFDFormat e) { eDebugExportFdFormat = e; }
bool GetDebugExportFD() const { return bDebugExportFd; }
void SetDebugExportFD (bool bExport) { bDebugExportFd = bExport; }
bool GetDebugExportUserAc() const { return bDebugExportUserAc; }
Expand Down Expand Up @@ -969,6 +986,9 @@ class DataRefs
void SetWeather (float hPa, float lat, float lon, const std::string& stationId,
const std::string& METAR);
/// Compute geometric altitude [ft] from pressure altitude and current weather in a very simplistic manner good enough for the first 3,000ft
static double WeatherAltCorr_ft (double pressureAlt_ft, double hPa)
{ return pressureAlt_ft + ((hPa - HPA_STANDARD) * FT_per_HPA); }
/// Compute geometric altitude [ft] from pressure altitude and current weather in a very simplistic manner good enough for the first 3,000ft
double WeatherAltCorr_ft (double pressureAlt_ft) { return pressureAlt_ft + altPressCorr_ft; }
/// Compute geometric altitude [m] from pressure altitude and current weather in a very simplistic manner good enough for the first 3,000ft
double WeatherAltCorr_m (double pressureAlt_m) { return pressureAlt_m + altPressCorr_ft * M_per_FT; }
Expand Down
140 changes: 62 additions & 78 deletions Include/LTADSBEx.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#define ADSBEX_CHECK_POPUP "Check ADS-B Exchange's coverage"

#define ADSBEX_NAME "ADS-B Exchange Online"
#define ADSBEX_URL "https://adsbexchange.com/api/aircraft/json/lat/%f/lon/%f/dist/%d/"
#define ADSBEX_URL "https://adsbexchange.com/api/aircraft/v2/lat/%f/lon/%f/dist/%d/"
#define ADSBEX_API_AUTH "api-auth:" // additional HTTP header

#define ADSBEX_RAPIDAPI_25_URL "https://adsbx-flight-sim-traffic.p.rapidapi.com/api/aircraft/json/lat/%f/lon/%f/dist/25/"
Expand All @@ -50,40 +50,59 @@
#define ADSBEX_RAPIDAPI_RREMAIN "X-RateLimit-Requests-Remaining:"

#define ADSBEX_TOTAL "total"
#define ADSBEX_TIME "ctime"
#define ADSBEX_NOW "now"
#define ADSBEX_AIRCRAFT_ARR "ac"
#define ADSBEX_TRANSP_ICAO "icao" // Key data
#define ADSBEX_TRT "trt"
#define ADSBEX_RADAR_CODE "sqk" // Dynamic data
#define ADSBEX_CALL "call"
#define ADSBEX_LAT "lat"
#define ADSBEX_LON "lon"
#define ADSBEX_ELEVATION "galt" // geometric altitude
#define ADSBEX_ALT "alt" // barometric altitude
#define ADSBEX_HEADING "trak"
#define ADSBEX_GND "gnd"
#define ADSBEX_POS_TIME "postime"
#define ADSBEX_SPD "spd"
#define ADSBEX_VSI "vsi"
#define ADSBEX_REG "reg"
#define ADSBEX_COUNTRY "cou"
#define ADSBEX_AC_TYPE_ICAO "type"
#define ADSBEX_MIL "mil"
#define ADSBEX_OP_ICAO "opicao"
#define ADSBEX_ORIGIN "from"
#define ADSBEX_DESTINATION "to"

#define ADSBEX_TYPE_GND "-GND"

// still used in historic data code, unsure if supported:
#define ADSBEX_RCVR "Rcvr"
#define ADSBEX_SIG "Sig"
#define ADSBEX_COS "Cos" // array of short trails

// Version 2 keys
#define ADSBEX_V2_TRANSP_ICAO "hex" // Key data
#define ADSBEX_V2_RADAR_CODE "squawk" // Dynamic data
#define ADSBEX_V2_FLIGHT "flight"
#define ADSBEX_V2_LAT "lat"
#define ADSBEX_V2_LON "lon"
#define ADSBEX_V2_ALT_GEOM "alt_geom" // geometric altitude
#define ADSBEX_V2_ALT_BARO "alt_baro" // barometric altitude
#define ADSBEX_V2_NAV_QNH "nav_qnh" // QNH of barometric altitude
#define ADSBEX_V2_HEADING "true_heading"
#define ADSBEX_V2_TRACK "track"
#define ADSBEX_V2_SEE_POS "seen_pos"
#define ADSBEX_V2_SPD "gs"
#define ADSBEX_V2_VSI_GEOM "geom_rate"
#define ADSBEX_V2_VSI_BARO "baro_rate"
#define ADSBEX_V2_REG "r"
#define ADSBEX_V2_AC_TYPE_ICAO "t"
#define ADSBEX_V2_AC_CATEGORY "category"
#define ADSBEX_V2_FLAGS "dbFlags"

// Version 1 keys
#define ADSBEX_TIME "ctime"
#define ADSBEX_V1_TRANSP_ICAO "icao" // Key data
#define ADSBEX_V1_RADAR_CODE "sqk" // Dynamic data
#define ADSBEX_V1_CALL "call"
#define ADSBEX_V1_LAT "lat"
#define ADSBEX_V1_LON "lon"
#define ADSBEX_V1_ELEVATION "galt" // geometric altitude
#define ADSBEX_V1_ALT "alt" // barometric altitude
#define ADSBEX_V1_HEADING "trak"
#define ADSBEX_V1_GND "gnd"
#define ADSBEX_V1_POS_TIME "postime"
#define ADSBEX_V1_SPD "spd"
#define ADSBEX_V1_VSI "vsi"
#define ADSBEX_V1_REG "reg"
#define ADSBEX_V1_COUNTRY "cou"
#define ADSBEX_V1_AC_TYPE_ICAO "type"
#define ADSBEX_V1_MIL "mil"
#define ADSBEX_V1_OP_ICAO "opicao"
#define ADSBEX_V1_ORIGIN "from"
#define ADSBEX_V1_DESTINATION "to"

#define ADSBEX_V1_TYPE_GND "-GND"


// Testing an API key
#define ADSBEX_VERIFY_KEY_URL "https://adsbexchange.com/api/aircraft/icao/000000"
#define ADSBEX_ERR "msg"
#define ADSBEX_NO_API_KEY "You need a key."
#define ADSBEX_SUCCESS "No error"
#define ADSBEX_NO_API_KEY "You need an authorized API key."

#define ADSBEX_VERIFY_RAPIDAPI "https://adsbx-flight-sim-traffic.p.rapidapi.com/api/aircraft/json/lat/0.0/lon/0.0/dist/25/"
#define ADSBEX_RAPID_ERR "message"
Expand Down Expand Up @@ -118,6 +137,7 @@ class ADSBExchangeConnection : public LTOnlineChannel, LTFlightDataChannel
virtual bool IsLiveFeed() const { return true; }
virtual LTChannelType GetChType() const { return CHT_TRACKING_DATA; }
virtual bool FetchAllData(const positionTy& pos) { return LTOnlineChannel::FetchAllData(pos); }
virtual std::string GetStatusText () const; ///< return a human-readable staus
// // shall data of this channel be subject to LTFlightData::DataSmoothing?
// virtual bool DoDataSmoothing (double& gndRange, double& airbRange) const
// { gndRange = ADSBEX_SMOOTH_GROUND; airbRange = ADSBEX_SMOOTH_AIRBORNE; return true; }
Expand All @@ -126,6 +146,18 @@ class ADSBExchangeConnection : public LTOnlineChannel, LTFlightDataChannel
// need to add/cleanup API key
virtual bool InitCurl ();
virtual void CleanupCurl ();

/// Process v2 data
void ProcessV2 (JSON_Object* pJAc, LTFlightData::FDKeyTy& fdKey,
mapLTFlightDataTy& fdMap,
const double tsCutOff, const double adsbxTime,
const positionTy& viewPos);
/// Process v1 data
void ProcessV1 (JSON_Object* pJAc, LTFlightData::FDKeyTy& fdKey,
mapLTFlightDataTy& fdMap,
const double tsCutOff, const double adsbxTime,
const positionTy& viewPos);

// make list of HTTP header fields
static struct curl_slist* MakeCurlSList (keyTypeE keyTy, const std::string theKey);
// read header and parse for request limit/remaining
Expand All @@ -146,52 +178,4 @@ class ADSBExchangeConnection : public LTOnlineChannel, LTFlightDataChannel
};


//MARK: ADS-B Exchange (Historic) Constants
#define ADSBEX_HIST_NAME "ADS-B Exchange Historic"
constexpr int ADSBEX_HIST_MIN_CHARS = 20; // minimum nr chars per line to be a 'reasonable' line
constexpr int ADSBEX_HIST_MAX_ERR_CNT = 5; // after that many errorneous line we stop reading
#define ADSBEX_HIST_PATH "Custom Data/ADSB" // TODO : Move to options: relative to XP main
#define ADSBEX_HIST_PATH_2 "Custom Data/ADSB2" // TODO : Move to options: fallback, if first one doesn't work
#define ADSBEX_HIST_DATE_PATH "%c%04d-%02d-%02d"
#define ADSBEX_HIST_FILE_NAME "%c%04d-%02d-%02d-%02d%02dZ.json"
#define ADSBEX_HIST_PATH_EMPTY "Historic Data Path doesn't exist or folder empty at %s"
#define ADSBEX_HIST_TRY_FALLBACK "Trying fallback as primary Historic Data Path doesn't exist or folder empty at %s"
#define ADSBEX_HIST_FALLBACK_EMPTY "Also fallback Historic Data Path doesn't exist or folder empty at %s"
#define ADSBEX_HIST_FILE_ERR "Could not open historic file '%s': %s"
#define ADSBEX_HIST_READ_FILE "Reading from historic file %s"
#define ADSBEX_HIST_LN1_END "\"acList\":[" // end of first line
#define ADSBEX_HIST_LAT "\"Lat\":" // latitude tag
#define ADSBEX_HIST_LONG "\"Long\":" // longitude tag
#define ADSBEX_HIST_COS "\"Cos\":[" // start of short trails
#define ADSBEX_HIST_LAST_LN "]" // begin of last line
#define ADSBEX_HIST_LN1_UNEXPECT "First line doesn't look like hist file: %s"
#define ADSBEX_HIST_LN_ERROR "Error reading line %d of hist file %s"
#define ADSBEX_HIST_TRAIL_ERR "Trail data not quadrupels (%s @ %f)"
#define ADSBEX_HIST_START_FILE "START OF FILE "
#define ADSBEX_HIST_END_FILE "END OF FILE "

//
//MARK: ADS-B Exchange Historical Data
//
class ADSBExchangeHistorical : public LTFileChannel, LTFlightDataChannel
{
// helper type to select best receiver per a/c from multiple in one file
struct FDSelection
{
int quality; // quality value
std::string ln; // line of flight data from file
};

typedef std::map<std::string, FDSelection> mapFDSelectionTy;

public:
ADSBExchangeHistorical (std::string base = ADSBEX_HIST_PATH,
std::string fallback = ADSBEX_HIST_PATH_2);
virtual bool FetchAllData (const positionTy& pos);
virtual bool IsLiveFeed() const { return false; }
virtual LTChannelType GetChType() const { return CHT_TRACKING_DATA; }
virtual bool ProcessFetchedData (mapLTFlightDataTy& fdMap);
};


#endif /* LTADSBEx_h */
13 changes: 1 addition & 12 deletions Include/LTFlightData.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,6 @@
// from LTChannel.h
class LTChannel;

// transponder types (as defined by ADSB exchange)
enum transpTy {
trt_Unknown=0,
trt_Mode_S=1,
trt_ADS_B_unknown=2,
trt_ADS_B_0=3,
trt_ADS_B_1=4,
trt_ADS_B_2=5
};

//
//MARK: Flight Data
// Represents an Aircraft's flight data, as read from the source(s)
Expand Down Expand Up @@ -105,7 +95,6 @@ class LTFlightData
int engMount = -1; // type of engine mount
int year = 0; // year built 2008
bool mil = false; // military? false
transpTy trt = trt_Unknown; // transponder type ADS_B_unknown=2

// more aircraft info
const Doc8643* pDoc8643 = NULL;
Expand Down Expand Up @@ -153,7 +142,7 @@ class LTFlightData
// KEY (protected, can be set only once, no mutex-control)
public:
// in ascending order of priority
enum FDKeyType { KEY_UNKNOWN=0, KEY_OGN, KEY_RT, KEY_FLARM, KEY_ICAO, KEY_FSC };
enum FDKeyType { KEY_UNKNOWN=0, KEY_OGN, KEY_RT, KEY_FLARM, KEY_ICAO, KEY_FSC, KEY_ADSBEX };
struct FDKeyTy {
FDKeyType eKeyType = KEY_UNKNOWN;
std::string key; // the primary key in use
Expand Down
Loading

0 comments on commit feaa050

Please sign in to comment.