Skip to content

Commit

Permalink
Merge pull request #259 from TwinFan/Next
Browse files Browse the repository at this point in the history
v3.4.2
  • Loading branch information
TwinFan committed Nov 4, 2023
2 parents 835f688 + 9f08466 commit 032a4f8
Show file tree
Hide file tree
Showing 16 changed files with 122 additions and 45 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ else()
endif()

project(LiveTraffic
VERSION 3.4.1
VERSION 3.4.2
DESCRIPTION "LiveTraffic X-Plane plugin")

# Provide compile macros from the above project version definition
Expand Down
13 changes: 8 additions & 5 deletions Include/DataRefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ const bool DEF_SND_FMOD_INST = false; ///< Enforce using our own FMOD
const bool DEF_SND_FMOD_INST = true; ///< Enforce using our own FMOD instance instead of X-Plane's?
#endif
const int DEF_SUI_TRANSP = 0; ///< Settings UI: transaprent background?
const int MIN_NETW_TIMEOUT = 5; ///< [s] minimum network request timeout
const int DEF_NETW_TIMEOUT = 90; ///< [s] of network request timeout
const int DEF_MIN_NETW_TIMEOUT = 5; ///< [s] default minimum network request timeout
const int DEF_MAX_NETW_TIMEOUT = 5; ///< [s] default maximum network request timeout


constexpr int DEF_UI_FONT_SCALE = 100; ///< [%] Default font scaling
Expand Down Expand Up @@ -382,7 +382,8 @@ enum dataRefsLT {
DR_CFG_FD_LONG_REFRESH_INTVL,
DR_CFG_FD_BUF_PERIOD,
DR_CFG_FD_REDUCE_HEIGHT,
DR_CFG_NETW_TIMEOUT,
DR_CFG_MIN_NETW_TIMEOUT,
DR_CFG_MAX_NETW_TIMEOUT,
DR_CFG_LND_LIGHTS_TAXI,
DR_CFG_HIDE_BELOW_AGL,
DR_CFG_HIDE_TAXIING,
Expand Down Expand Up @@ -685,7 +686,8 @@ class DataRefs
int fdCurrRefrIntvl = DEF_FD_REFRESH_INTVL; ///< current value of how often to fetch new flight data
int fdBufPeriod = DEF_FD_BUF_PERIOD; ///< seconds to buffer before simulating aircraft
int fdReduceHeight = DEF_FD_REDUCE_HEIGHT; ///< [ft] reduce flight data usage when user aircraft is flying above this altitude
int netwTimeout = DEF_NETW_TIMEOUT; ///< [s] of network request timeout
int netwTimeoutMin = DEF_MIN_NETW_TIMEOUT; ///< [s] of min network request timeout
int netwTimeoutMax = DEF_MAX_NETW_TIMEOUT; ///< [s] of max 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?
Expand Down Expand Up @@ -922,7 +924,8 @@ class DataRefs
inline int GetFdRefreshIntvl() const { return fdCurrRefrIntvl; }
inline int GetFdBufPeriod() const { return fdBufPeriod; }
inline int GetAcOutdatedIntvl() const { return 2 * GetFdBufPeriod(); }
inline int GetNetwTimeout() const { return netwTimeout; }
inline int GetNetwTimeoutMin() const { return netwTimeoutMin; }
inline int GetNetwTimeoutMax() const { return netwTimeoutMax; }
inline bool GetLndLightsTaxi() const { return bLndLightsTaxi != 0; }
inline int GetHideBelowAGL() const { return hideBelowAGL; }
inline bool GetHideTaxiing() const { return hideTaxiing != 0; }
Expand Down
4 changes: 2 additions & 2 deletions Include/LTWeather.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/// @file LTWeather.h
/// @brief Fetch real weather information from AWC
/// @see https://www.aviationweather.gov/dataserver/example?datatype=metar
/// @see https://aviationweather.gov/data/api/#/Dataserver/dataserverMetars
/// @author Birger Hoppe
/// @copyright (c) 2018-2020 Birger Hoppe
/// @copyright (c) 2018-2023 Birger Hoppe
/// @copyright Permission is hereby granted, free of charge, to any person obtaining a
/// copy of this software and associated documentation files (the "Software"),
/// to deal in the Software without restriction, including without limitation
Expand Down
2 changes: 1 addition & 1 deletion Lib/XPMP2
Submodule XPMP2 updated 207 files
6 changes: 3 additions & 3 deletions LiveTraffic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@
KnownAssetTags = (
New,
);
LastUpgradeCheck = 1410;
LastUpgradeCheck = 1420;
};
buildConfigurationList = D607B16209A5563100699BC3 /* Build configuration list for PBXProject "LiveTraffic" */;
compatibilityVersion = "Xcode 12.0";
Expand Down Expand Up @@ -790,7 +790,7 @@
LIVETRAFFIC_VERSION_BETA = 0;
LIVETRAFFIC_VER_MAJOR = 3;
LIVETRAFFIC_VER_MINOR = 4;
LIVETRAFFIC_VER_PATCH = 1;
LIVETRAFFIC_VER_PATCH = 2;
LLVM_LTO = NO;
MACH_O_TYPE = mh_dylib;
MACOSX_DEPLOYMENT_TARGET = 10.15;
Expand Down Expand Up @@ -896,7 +896,7 @@
LIVETRAFFIC_VERSION_BETA = 0;
LIVETRAFFIC_VER_MAJOR = 3;
LIVETRAFFIC_VER_MINOR = 4;
LIVETRAFFIC_VER_PATCH = 1;
LIVETRAFFIC_VER_PATCH = 2;
LLVM_LTO = YES;
MACH_O_TYPE = mh_dylib;
MACOSX_DEPLOYMENT_TARGET = 10.15;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1410"
LastUpgradeVersion = "1420"
version = "1.8">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
27 changes: 20 additions & 7 deletions Src/DataRefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ DataRefs::dataRefDefinitionT DATA_REFS_LT[CNT_DATAREFS_LT] = {
{"livetraffic/cfg/fd_long_refresh_intvl", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true, true },
{"livetraffic/cfg/fd_buf_period", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true, true },
{"livetraffic/cfg/fd_reduce_height", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true, true },
{"livetraffic/cfg/network_timeout_min", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/network_timeout", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/lnd_lights_taxi", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/cfg/hide_below_agl", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true, true },
Expand Down Expand Up @@ -612,7 +613,8 @@ void* DataRefs::getVarAddr (dataRefsLT dr)
case DR_CFG_FD_LONG_REFRESH_INTVL: return &fdLongRefrIntvl;
case DR_CFG_FD_BUF_PERIOD: return &fdBufPeriod;
case DR_CFG_FD_REDUCE_HEIGHT: return &fdReduceHeight;
case DR_CFG_NETW_TIMEOUT: return &netwTimeout;
case DR_CFG_MIN_NETW_TIMEOUT: return &netwTimeoutMin;
case DR_CFG_MAX_NETW_TIMEOUT: return &netwTimeoutMax;
case DR_CFG_LND_LIGHTS_TAXI: return &bLndLightsTaxi;
case DR_CFG_HIDE_BELOW_AGL: return &hideBelowAGL;
case DR_CFG_HIDE_TAXIING: return &hideTaxiing;
Expand Down Expand Up @@ -1709,7 +1711,7 @@ bool DataRefs::SetCfgValue (void* p, int val)
fdBufPeriod < fdLongRefrIntvl || fdBufPeriod > 180 ||
fdReduceHeight < 1000 || fdReduceHeight > 100000||
fdSnapTaxiDist < 0 || fdSnapTaxiDist > 50 ||
netwTimeout < 10 ||
netwTimeoutMax < 5 || netwTimeoutMin > netwTimeoutMax ||
hideBelowAGL < 0 || hideBelowAGL > MDL_ALT_MAX ||
hideNearbyGnd < 0 || hideNearbyGnd > 500 ||
hideNearbyAir < 0 || hideNearbyAir > 5000 ||
Expand Down Expand Up @@ -1776,7 +1778,8 @@ void DataRefs::ResetAdvCfgToDefaults ()
fdLongRefrIntvl = DEF_FD_LONG_REFR_INTVL;
fdBufPeriod = DEF_FD_BUF_PERIOD;
fdReduceHeight = DEF_FD_REDUCE_HEIGHT;
netwTimeout = DEF_NETW_TIMEOUT;
netwTimeoutMin = DEF_MIN_NETW_TIMEOUT;
netwTimeoutMax = DEF_MAX_NETW_TIMEOUT;
contrailAltMin_ft = DEF_CONTR_ALT_MIN;
contrailAltMax_ft = DEF_CONTR_ALT_MAX;
contrailLifeTime = DEF_CONTR_LIFETIME;
Expand Down Expand Up @@ -2010,7 +2013,7 @@ bool DataRefs::LoadConfigFile()

// which conversion to do with the (older) version of the config file?
unsigned long cfgFileVer = 0;
enum cfgFileConvE { CFG_NO_CONV=0, CFG_V3, CFG_V31, CFG_V331 } conv = CFG_NO_CONV;
enum cfgFileConvE { CFG_NO_CONV=0, CFG_V3, CFG_V31, CFG_V331, CFG_V342 } conv = CFG_NO_CONV;

// open a config file
std::string sFileName (LTCalcFullPath(PATH_CONFIG_FILE));
Expand Down Expand Up @@ -2072,8 +2075,10 @@ bool DataRefs::LoadConfigFile()
// any conversions required?
if (cfgFileVer < 30100) // < 3.1.0
conv = CFG_V31;
else if (cfgFileVer < 30301) // < 3.3.1
if (cfgFileVer < 30301) // < 3.3.1
conv = CFG_V331;
if (cfgFileVer < 30402) // < 3.4.2: Reset Force FMOD instance = 0, set network timeout to 5s
conv = CFG_V342;
}
}

Expand Down Expand Up @@ -2122,16 +2127,24 @@ bool DataRefs::LoadConfigFile()
switch (conv) {
case CFG_NO_CONV:
break;
case CFG_V331:
case CFG_V31:
case CFG_V3:
case CFG_V31:
case CFG_V331:
// We "forgot" to change the default to 49005 for fresh installations,
// so we need to convert the port all the way up to v3.3.1:
if (*i == DATA_REFS_LT[DR_CFG_RT_TRAFFIC_PORT]) {
// With v3 preferred port changes from 49003 to 49005
if (sVal == "49003")
sVal = "49005";
}
[[fallthrough]];
case CFG_V342:
// Re-implemented XP Sound, so we reset the "Force own FMOD Instance flag" because we believe in the XP implementation now ;-)
if (*i == DATA_REFS_LT[DR_CFG_SND_FORCE_FMOD_INSTANCE])
sVal = "0";
// With OpenSky API timeouts we set the max timeout to just 5s so we try more often
if (*i == DATA_REFS_LT[DR_CFG_MAX_NETW_TIMEOUT])
sVal = "5";
break;
}

Expand Down
2 changes: 1 addition & 1 deletion Src/LTADSBEx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ bool ADSBExchangeConnection::DoTestADSBExAPIKey (const std::string newKey)
// prepare the handle with the right options
readBuf.reserve(CURL_MAX_WRITE_SIZE);
curl_easy_setopt(pCurl, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt(pCurl, CURLOPT_TIMEOUT, dataRefs.GetNetwTimeout());
curl_easy_setopt(pCurl, CURLOPT_TIMEOUT, dataRefs.GetNetwTimeoutMax());
curl_easy_setopt(pCurl, CURLOPT_ERRORBUFFER, curl_errtxt);
curl_easy_setopt(pCurl, CURLOPT_HEADERFUNCTION, testKeyTy == ADSBEX_KEY_RAPIDAPI ? ReceiveHeader : NULL);
curl_easy_setopt(pCurl, CURLOPT_WRITEFUNCTION, DoTestADSBExAPIKeyCB);
Expand Down
2 changes: 1 addition & 1 deletion Src/LTADSBHub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ void ADSBHubConnection::StreamMain ()
#endif

// *** Main Loop ***
struct timeval timeout = { ADSBHUB_TIMEOUT_S, 0 };
while (!bStopThr && tcpStream.isOpen())
{
// wait for some signal on either socket (Stream or self-pipe)
Expand All @@ -132,6 +131,7 @@ void ADSBHubConnection::StreamMain ()
#if APL == 1 || LIN == 1
FD_SET(streamPipe[0], &sRead); // check the self-pipe
#endif
struct timeval timeout = { ADSBHUB_TIMEOUT_S, 0 };
int retval = select(maxSock, &sRead, NULL, NULL, &timeout);

// short-cut if we are to shut down (return from 'select' due to closed socket)
Expand Down
26 changes: 19 additions & 7 deletions Src/LTChannel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ std::ofstream LTOnlineChannel::outRaw;

LTOnlineChannel::LTOnlineChannel () :
pCurl(NULL),
nTimeout(dataRefs.GetNetwTimeout()),
nTimeout(dataRefs.GetNetwTimeoutMax()),
netData((char*)malloc(CURL_MAX_WRITE_SIZE)), // initial buffer allocation
netDataPos(0), netDataSize(CURL_MAX_WRITE_SIZE),
curl_errtxt{0}, httpResponse(HTTP_OK)
Expand Down Expand Up @@ -575,10 +575,20 @@ bool LTOnlineChannel::FetchAllData (const positionTy& pos)

// In case of timeout increase the channel's timeout and don't count it as an error
if (cc == CURLE_OPERATION_TIMEDOUT) {
LOG_MSG(logWARN, ERR_CURL_PERFORM, ChName(), cc, curl_errtxt);
nTimeout = std::min (nTimeout * 2,
dataRefs.GetNetwTimeout());
LOG_MSG(logWARN, "%s: Timeout increased to %ds", ChName(), nTimeout);
// But bother the user only with messages once every 3 minutes (this is due to OpenSky having been plagued with slow API responses running into timeouts)
static float tLastMsg = 0.0f; // time last message was logged
const float now = dataRefs.GetMiscNetwTime();
if (tLastMsg + 180.0f < now) {
LOG_MSG(logWARN, ERR_CURL_PERFORM, ChName(), cc, curl_errtxt);
tLastMsg = now;
}
// Increase the timeout
const int prevTimeout = nTimeout;
nTimeout = std::min (nTimeout * 2, // double the timeout
dataRefs.GetNetwTimeoutMax());
if (nTimeout > prevTimeout) {
LOG_MSG(logWARN, "%s: Timeout increased to %ds", ChName(), nTimeout);
}
} else {
SHOW_MSG(logERR, ERR_CURL_PERFORM, ChName(), cc, curl_errtxt);
IncErrCnt();
Expand All @@ -594,9 +604,11 @@ bool LTOnlineChannel::FetchAllData (const positionTy& pos)
// Based on actual time take set a new network timeout as twice the response time
{
const std::chrono::seconds d = std::chrono::duration_cast<std::chrono::seconds>(tEnd - tStart);
// In case of a reduction we reduce to no less than half the previous value,
// keep value between min/max network timeout
nTimeout = std::clamp<int> ((int)d.count() * 2,
std::max(MIN_NETW_TIMEOUT,nTimeout/2), // this means the in case of a reduction we reduce to now less than half the previous value
dataRefs.GetNetwTimeout());
std::max(dataRefs.GetNetwTimeoutMin(),nTimeout/2),
dataRefs.GetNetwTimeoutMax());
// LOG_MSG(logWARN, "%s: Timeout set to %ds", ChName(), nTimeout);
break;
}
Expand Down
17 changes: 12 additions & 5 deletions Src/LTOpenGlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
/// @details Also downloads and performs searches in the aircraft list
/// @see http://ddb.glidernet.org/download/
/// @author Birger Hoppe
/// @copyright (c) 2018-2020 Birger Hoppe
/// @copyright (c) 2018-2023 Birger Hoppe
/// @copyright Permission is hereby granted, free of charge, to any person obtaining a
/// copy of this software and associated documentation files (the "Software"),
/// to deal in the Software without restriction, including without limitation
Expand Down Expand Up @@ -355,7 +355,6 @@ void OpenGliderConnection::APRSMain (const positionTy& pos, unsigned dist_km)
}

// *** Main Loop ***
struct timeval timeout = { OGN_APRS_TIMEOUT_S, 0 };
while (!bStopAprs && tcpAprs.isOpen())
{
// wait for some signal on either socket (APRS or self-pipe)
Expand All @@ -365,6 +364,7 @@ void OpenGliderConnection::APRSMain (const positionTy& pos, unsigned dist_km)
#if APL == 1 || LIN == 1
FD_SET(aprsPipe[0], &sRead); // check the self-pipe
#endif
struct timeval timeout = { OGN_APRS_TIMEOUT_S, 0 };
int retval = select(maxSock, &sRead, NULL, NULL, &timeout);

// short-cut if we are to shut down (return from 'select' due to closed socket)
Expand Down Expand Up @@ -546,8 +546,15 @@ bool OpenGliderConnection::APRSProcessLine (const std::string& ln)
// We expect 16 matches, 17 if fpm is given. Size is one more because element 0 is the complete matched string:
if (m.size() < 17) {
// didn't match. But if we think this _could_ be a valid message then we should warn, maybe there's still a flaw in the regex above
if (ln.find("! id") != std::string::npos) {
LOG_MSG(logWARN, WARN_OGN_APRS_NOT_MATCHED, ln.c_str());
if (ln.find("! id") != std::string::npos && // seems to include an id
ln.find("/A=") != std::string::npos) // as well as an altitude (there are messages out there without altitude, which we rightfully and silently discard this way)
{
static float lastWarn = -300.0f;
const float now = dataRefs.GetMiscNetwTime();
if (lastWarn < now - 300.0f) { // only issue warning if last such warning is more than 5 minutes ago
lastWarn = now;
LOG_MSG(logWARN, WARN_OGN_APRS_NOT_MATCHED, ln.c_str());
}
}
// but otherwise no issue...there are some message in the stream that we just don't need
return true;
Expand Down Expand Up @@ -919,7 +926,7 @@ static bool OGNAcListDoDownload ()
// prepare the handle with the right options
ho.readBuf.reserve(CURL_MAX_WRITE_SIZE);
curl_easy_setopt(pCurl, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt(pCurl, CURLOPT_TIMEOUT, dataRefs.GetNetwTimeout());
curl_easy_setopt(pCurl, CURLOPT_TIMEOUT, dataRefs.GetNetwTimeoutMax());
curl_easy_setopt(pCurl, CURLOPT_ERRORBUFFER, curl_errtxt);
curl_easy_setopt(pCurl, CURLOPT_WRITEFUNCTION, OGNAcListNetwCB);
curl_easy_setopt(pCurl, CURLOPT_WRITEDATA, &ho);
Expand Down
1 change: 0 additions & 1 deletion Src/LTOpenSky.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,6 @@ bool OpenSkyAcMasterdata::FetchAllData (const positionTy& /*pos*/)
if (!info.empty())
vecAc.push_back(std::move(info));

IncErrCnt();
return !listMd.empty(); // return `true` if there is data to process, otherwise we wouldn't process what had been received before the error
}

Expand Down
2 changes: 1 addition & 1 deletion Src/LTVersion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ bool FetchXPlaneOrgVersion ()
verXPlaneOrg = 0;
readBuf.reserve(CURL_MAX_WRITE_SIZE);
curl_easy_setopt(pCurl, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt(pCurl, CURLOPT_TIMEOUT, dataRefs.GetNetwTimeout());
curl_easy_setopt(pCurl, CURLOPT_TIMEOUT, dataRefs.GetNetwTimeoutMax());
curl_easy_setopt(pCurl, CURLOPT_ERRORBUFFER, curl_errtxt);
curl_easy_setopt(pCurl, CURLOPT_WRITEFUNCTION, FetchVersionCB);
curl_easy_setopt(pCurl, CURLOPT_WRITEDATA, &readBuf);
Expand Down
Loading

0 comments on commit 032a4f8

Please sign in to comment.