Skip to content

Commit

Permalink
Merge pull request #202 from TwinFan/Next
Browse files Browse the repository at this point in the history
v2.30
  • Loading branch information
TwinFan authored Nov 29, 2020
2 parents 584a916 + 33963f7 commit bba4912
Show file tree
Hide file tree
Showing 39 changed files with 950 additions and 322 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ endif ()

if (WIN32)
# Link platform-specific libraries especially for networking
target_link_libraries(LiveTraffic ws2_32.lib wldap32.lib advapi32.lib crypt32.lib)
target_link_libraries(LiveTraffic ws2_32.lib iphlpapi wldap32.lib advapi32.lib crypt32.lib)
elseif (APPLE)
# X-Plane supports OS X 10.10+, so this should ensure FlyWithLua can run on
# all supported versions.
Expand Down
6 changes: 5 additions & 1 deletion Data/RealTraffic/SendTraffic.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def compWaitTS(ts_s: str) -> str:
print (f"Waiting for {ts-now} seconds...", end='\r')
time.sleep (ts-now)

# Adjust returned timestamp value for historic timestamp
ts -= args.historic

return str(ts)

""" === Handle traffic data ==="""
Expand Down Expand Up @@ -97,11 +100,12 @@ def sendWeatherData(ln: str) -> int:
""" === MAIN === """

# --- Handling command line argumens ---
parser = argparse.ArgumentParser(description='SendTraffic 0.1.0: Sends air traffic tracking data from a file out on a UDP port for LiveTraffic to receive it on the RealTraffic channel',fromfile_prefix_chars='@')
parser = argparse.ArgumentParser(description='SendTraffic 0.2.0: Sends air traffic tracking data from a file out on a UDP port for LiveTraffic to receive it on the RealTraffic channel',fromfile_prefix_chars='@')
parser.add_argument('inFile', help='Tracking data file: records in CSV format holding air traffic data in RealTraffic\'s AITraffic format and weather data.\n<stdin> by default', nargs='?', type=argparse.FileType('r'), default=sys.stdin)
parser.add_argument('-a', '--aircraft', metavar='HEX_LIST', help='List of aircraft to read, others skipped. Add one or several transponder hex id codes, separate by comma.')
parser.add_argument('-d', '--aircraftDecimal', metavar='NUM_LIST', help='Same as -a, but specify decimal values (as used in the CSV file).')
parser.add_argument('-b', '--bufPeriod', metavar='NUM', help='Buffering period: Number of seconds the first record is pushed into the past so that LiveTraffic\'s buffer fills more quickly. Recommended to be slightly less than LiveTraffic\'s buffering period.', type=int, default=0)
parser.add_argument('--historic', metavar='NUM', help='Send historic data, ie. reduce included timestamp by this many seconds', type=int, default=0)
parser.add_argument('-l', '--loop', help='Endless loop: restart from the beginning when reaching end of file. Will only work if data contains loop with last position(s) being roughly equal to first position(s).', action='store_true')
parser.add_argument('--host', metavar='NAME_OR_IP', help='UDP target host or ip to send the data to, defaults to \'localhost\'', default='localhost')
parser.add_argument('--port', metavar='NUM', help='UDP port to send traffic data to, defaults to 49003', type=int, default=49003)
Expand Down
8 changes: 7 additions & 1 deletion Include/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
//
// MARK: Version Information (CHANGE VERSION HERE)
//
constexpr float VERSION_NR = 2.20f;
constexpr float VERSION_NR = 2.30f;
constexpr bool VERSION_BETA = false;
extern float verXPlaneOrg; // version on X-Plane.org
extern int verDateXPlaneOrg; // and its date
Expand Down Expand Up @@ -151,6 +151,7 @@ constexpr int LT_NEW_VER_CHECK_TIME = 48; // [h] between two checks of a new
#define LT_FM_VERSION "2.2" // expected version of flight model file format
#define PLUGIN_SIGNATURE "TwinFan.plugin.LiveTraffic"
#define PLUGIN_DESCRIPTION "Create Multiplayer Aircraft based on live traffic."
constexpr const char* REMOTE_SIGNATURE = "TwinFan.plugin.XPMP2.Remote";
#define LT_DOWNLOAD_URL "https://forums.x-plane.org/index.php?/files/file/49749-livetraffic/"
#define LT_DOWNLOAD_CH "X-Plane.org"
#define MSG_DISABLED "Disabled"
Expand All @@ -175,6 +176,7 @@ constexpr int LT_NEW_VER_CHECK_TIME = 48; // [h] between two checks of a new
#define INFO_AC_REMOVED "Removed aircraft %s"
#define INFO_AC_ALL_REMOVED "Removed all aircraft"
#define INFO_REQU_AI_RELEASE "%s requested us to release TCAS / AI control. Switch off '" MENU_HAVE_TCAS "' if you want so."
#define INFO_REQU_AI_REMOTE "XPMP2 Remote Client requested us to release TCAS / AI control, so we do."
#define INFO_GOT_AI_CONTROL LIVE_TRAFFIC " has TCAS / AI control now"
#define INFO_RETRY_GET_AI "Another plugin released AI control, will try again to get control..."
#define INFO_AC_HIDDEN "A/c %s hidden"
Expand Down Expand Up @@ -354,6 +356,10 @@ constexpr int SERR_LEN = 100; // size of buffer for IO error t
#define ERR_FM_UNKNOWN_PARENT "Parent section missing in '%s', line %d: %s"
#define ERR_FM_REGEX "%s in '%s', line %d: %s"
#define ERR_FM_NOT_FOUND "Found no flight model for ICAO %s/match-string %s: will use default"
#define ERR_TCP_LISTENACCEPT "%s: Error opening the TCP port on %s:%s: %s"
#define ERR_SOCK_SEND_FAILED "%s: Could not send position: send operation failed"
#define ERR_UDP_SOCKET_CREAT "%s: Error creating UDP socket for %s:%d: %s"
#define ERR_UDP_RCVR_RCVR "%s: Error receiving UDP: %s"
constexpr int ERR_CFG_FILE_MAXWARN = 10; // maximum number of warnings while reading config file, then: dead

//MARK: Debug Texts
Expand Down
7 changes: 5 additions & 2 deletions Include/DataRefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ enum dataRefsLT {
DR_CFG_HIDE_NEARBY_GND,
DR_CFG_HIDE_NEARBY_AIR,
DR_CFG_COPY_OBJ_FILES,
DR_CFG_REMOTE_SUPPORT,
DR_CFG_LAST_CHECK_NEW_VER,

// debug options
Expand Down Expand Up @@ -507,7 +508,7 @@ class DataRefs

// this is a bit ugly but avoids a wrapper union with an int
inline unsigned GetUInt() const { return *reinterpret_cast<const unsigned*>(this); }
inline void SetUInt(int i) { *reinterpret_cast<unsigned*>(this) = i; }
inline void SetUInt(unsigned i) { *reinterpret_cast<unsigned*>(this) = i; }
inline bool operator != (const LabelCfgTy& o) const
{ return GetUInt() != o.GetUInt(); }
};
Expand Down Expand Up @@ -612,13 +613,14 @@ class DataRefs
int fdRefreshIntvl = DEF_FD_REFRESH_INTVL; ///< how often to fetch new flight data
int fdBufPeriod = DEF_FD_BUF_PERIOD; ///< seconds to buffer before simulating aircraft
int acOutdatedIntvl = DEF_AC_OUTDATED_INTVL; ///< a/c considered outdated if latest flight data more older than this compare to 'now'
int netwTimeout = 90; // [s] of network request timeout
int netwTimeout = DEF_NETW_TIMEOUT; ///< [s] of network request timeout
int bLndLightsTaxi = false; // keep landing lights on while taxiing? (to be able to see the a/c as there is no taxi light functionality)
int hideBelowAGL = 0; // if positive: a/c visible only above this height AGL
int hideTaxiing = 0; // hide a/c while taxiing?
int hideNearbyGnd = 0; // [m] hide a/c if closer than this to user's aircraft on the ground
int hideNearbyAir = 0; // [m] hide a/c if closer than this to user's aircraft in the air
int cpyObjFiles = 1; ///< copy `.obj` files for replacing dataRefs and textures
int remoteSupport = 0; ///< support XPMP2 Remote Client? (3-way: -1 off, 0 auto, 1 on)

// channel config options
int ognUseRequRepl = 0; ///< OGN: Use Request/Reply instead of TCP receiver
Expand Down Expand Up @@ -807,6 +809,7 @@ class DataRefs
{ return hideBelowAGL > 0 || hideTaxiing != 0 ||
hideNearbyGnd > 0 || hideNearbyAir > 0; }
bool ShallCpyObjFiles () const { return cpyObjFiles != 0; }
int GetRemoteSupport () const { return remoteSupport; }

bool NeedNewVerCheck () const;
void SetLastCheckedNewVerNow ();
Expand Down
4 changes: 2 additions & 2 deletions Include/LTADSBEx.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ class ADSBExchangeConnection : public LTOnlineChannel, LTFlightDataChannel
#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_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"
Expand Down
4 changes: 1 addition & 3 deletions Include/LTFlightData.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,6 @@ class LTFlightData
bool validForAcCreate( double simTime = NAN ) const;
// a/c available for this FD?
inline bool hasAc() const { return pAc != nullptr; }
// is the data outdated (considered too old to be useful)?
bool outdated ( double simTime = NAN ) const;

// produce a/c label
void UpdateStaticLabel();
Expand Down Expand Up @@ -370,7 +368,7 @@ class LTFlightData
// access/create/destroy aircraft
bool AircraftMaintenance ( double simTime ); // returns: delete me?
bool DetermineAcModel (); ///< try interpreting model text or check for ground vehicle, last resort: default a/c type
bool AcSlotAvailable (double simTime); ///< checks if there is a slot available to create this a/c, tries to remove the farest a/c if too many a/c rendered
bool AcSlotAvailable (); ///< checks if there is a slot available to create this a/c, tries to remove the farest a/c if too many a/c rendered
bool CreateAircraft ( double simTime );
void DestroyAircraft ();
LTAircraft* GetAircraft () const { return pAc; }
Expand Down
15 changes: 14 additions & 1 deletion Include/LTRealTraffic.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ constexpr double RT_VSI_AIRBORNE = 80.0; ///< if VSI is more than this then w

#define MSG_RT_STATUS "RealTraffic network status changed to: %s"
#define MSG_RT_LAST_RCVD " | last: %lds ago"
#define MSG_RT_ADJUST " | historic traffic from %s ago"

#define INFO_RT_REAL_TIME "RealTraffic: Tracking data is real-time again."
#define INFO_RT_ADJUST_TS "RealTraffic: Detected tracking data from %s in the past, will adjust them to display now."
#define ERR_RT_CANTLISTEN "RealTraffic: Cannot listen to network, can't tell RealTraffic our position"
#define ERR_RT_WEATHER_QNH "RealTraffic reports unreasonable QNH %ld - ignored"
#define ERR_RT_DISCARDED_MSG "RealTraffic: Discarded invalid message: %s"
#define ERR_SOCK_NOTCONNECTED "%s: Cannot send position: not connected"
#define ERR_SOCK_INV_POS "%s: Cannot send position: position not fully valid"

// Traffic data format and fields
#define RT_TRAFFIC_AITFC "AITFC"
Expand Down Expand Up @@ -142,6 +147,10 @@ class RealTrafficConnection : public LTOnlineChannel, LTFlightDataChannel
std::map<unsigned long,RTUDPDatagramTy> mapDatagrams;
// weather, esp. current barometric pressure to correct altitude values
std::string lastWeather; // for duplicate detection
/// rolling list of timestamp (diff to now) for detecting historic sending
std::deque<double> dequeTS;
/// current timestamp adjustment
double tsAdjust = 0.0;

public:
RealTrafficConnection (mapLTFlightDataTy& _fdMap);
Expand Down Expand Up @@ -200,10 +209,14 @@ class RealTrafficConnection : public LTOnlineChannel, LTFlightDataChannel
bool ProcessRecvedTrafficData (const char* traffic);
bool ProcessRecvedWeatherData (const char* weather);

/// Determine timestamp adjustment necessairy in case of historic data
void AdjustTimestamp (double& ts);
/// Return a string describing the current timestamp adjustment
std::string GetAdjustTSText () const;

// UDP datagram duplicate check
// Is it a duplicate? (if not datagram is copied into a map)
bool IsDatagramDuplicate (unsigned long numId,
double posTime,
const char* datagram);
// remove outdated entries from mapDatagrams
void CleanupMapDatagrams();
Expand Down
16 changes: 2 additions & 14 deletions Include/LiveTraffic.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,7 @@ bool begins_with(const TContainer& input, const TContainer& match)
&& std::equal(match.cbegin(), match.cend(), input.cbegin());
}

/// Clamps `v` between `lo` and `hi`: `lo` if `v` < `lo`, `hi` if `hi` < `v`, otherwise `v`
/// @see C++17, https://en.cppreference.com/w/cpp/algorithm/clamp
template<class T>
constexpr const T& clamp( const T& v, const T& lo, const T& hi )
{
assert( !(hi < lo) );
return (v < lo) ? lo : (hi < v) ? hi : v;
}

/// Is value `lo <= v <= hi`?
template<class T>
constexpr bool between( const T& v, const T& lo, const T& hi )
{
Expand Down Expand Up @@ -372,15 +364,11 @@ inline struct tm *localtime_s(struct tm * result, const time_t * time)
#define STRCPY_S(dest,src) strncpy_s(dest,sizeof(dest),src,sizeof(dest)-1)
#define STRCPY_ATMOST(dest,src) strncpy_s(dest,sizeof(dest),strAtMost(src,sizeof(dest)-1).c_str(),sizeof(dest)-1)

#if APL == 1
#if APL == 1 || LIN == 1
// XCode/Linux don't provide the _s functions, not even with __STDC_WANT_LIB_EXT1__ 1
inline int strerror_s( char *buf, size_t bufsz, int errnum )
{ return strerror_r(errnum, buf, bufsz); }
#endif
#if LIN == 1
inline int strerror_s( char *buf, size_t bufsz, int errnum )
{ strncpy_s(buf,bufsz,strerror(errnum),bufsz-1); return 0; }
#endif

// MARK: Thread names
#ifdef DEBUG
Expand Down
Loading

0 comments on commit bba4912

Please sign in to comment.