Skip to content

Commit

Permalink
Merge pull request #251 from TwinFan/Next
Browse files Browse the repository at this point in the history
v3.3.1
  • Loading branch information
TwinFan authored Feb 5, 2023
2 parents 19c688a + 9918b69 commit 90490a8
Show file tree
Hide file tree
Showing 11 changed files with 1,488 additions and 946 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
#####################################
# Linux with GCC
build-lin:
runs-on: ubuntu-latest
runs-on: ubuntu-20.04
env:
platform: lin
steps:
Expand All @@ -37,7 +37,7 @@ jobs:
#####################################
# MacOS with CMake/clang and sign/notarize in self-written script
build-mac:
runs-on: macos-latest
runs-on: macos-11
steps:
- name: Checkout Code
uses: actions/checkout@v3 # must checkout before we can use our own actions
Expand Down
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.3.0
VERSION 3.3.1
DESCRIPTION "LiveTraffic X-Plane plugin")

# Provide compile macros from the above project version definition
Expand Down
30 changes: 26 additions & 4 deletions Include/DataRefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ enum dataRefsLT {
DR_CFG_RT_LISTEN_PORT,
DR_CFG_RT_TRAFFIC_PORT,
DR_CFG_RT_WEATHER_PORT,
DR_CFG_RT_SIM_TIME_CTRL,
DR_CFG_FF_SEND_PORT,
DR_CFG_FF_SEND_USER_PLANE,
DR_CFG_FF_SEND_TRAFFIC,
Expand Down Expand Up @@ -443,6 +444,14 @@ enum exportFDFormat {
EXP_FD_RTTFC, ///< user RTTFC format, introduced with RealTraffic v9
};

/// Which simulator time to send to RealTraffic?
enum SimTimeCtrlTy : int {
STC_NO_CTRL = 0, ///< Don't send any sim time
STC_SIM_TIME, ///< Send current sim time unchanged
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
};


// 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 @@ -685,8 +694,9 @@ class DataRefs
int fscEnv = 0; ///< FSCharter: Which environment to connect to?
int ognUseRequRepl = 0; ///< OGN: Use Request/Reply instead of TCP receiver
int rtListenPort = 10747; // port opened for RT to connect
int rtTrafficPort = 49003; // UDP Port receiving traffic
int rtTrafficPort = 49005; // UDP Port receiving traffic
int rtWeatherPort = 49004; // UDP Port receiving weather info
SimTimeCtrlTy rtSTC = STC_SIM_TIME_PLUS_BUFFER; ///< Which sim time to send to RealTraffic?
int ffSendPort = 49002; // UDP Port to send ForeFlight feeding data
int bffUserPlane = 1; // bool Send User plane data?
int bffTraffic = 1; // bool Send traffic data?
Expand Down Expand Up @@ -726,6 +736,11 @@ class DataRefs

// MARK: Public members
public:
/// X-Plane version information
int xpVer = 0;
int xplmVer = 0;
std::string sXpVer;

/// once per Flarm a/c type: matching it to one or more ICAO types
std::array<std::vector<std::string>, 14> aFlarmToIcaoAcTy;

Expand Down Expand Up @@ -770,6 +785,7 @@ class DataRefs
static positionTy lastCamPos; ///< cached read camera position
float lastNetwTime = 0.0f; ///< cached network time
double lastSimTime = NAN; ///< cached simulated time
long long lastXPSimTime_ms = 0; ///< X-Plane's simulated time in milliseconds since the Unix epoch
bool lastReplay = true; ///< cached: is replay mode?
bool lastVREnabled = false; ///< cached info: VR enabled?
bool bUsingModernDriver = false; ///< modern driver in use?
Expand All @@ -796,9 +812,14 @@ class DataRefs
inline bool UsingModernDriver () const { return bUsingModernDriver; }
inline bool IsVREnabled() const { return lastVREnabled; }

inline void SetLocalDateDays(int days) { XPLMSetDatai(adrXP[DR_LOCAL_DATE_DAYS], days); }
inline void SetUseSystemTime(bool bSys) { XPLMSetDatai(adrXP[DR_USE_SYSTEM_TIME], (int)bSys); }
inline void SetZuluTimeSec(float sec) { XPLMSetDataf(adrXP[DR_ZULU_TIME_SEC], sec); }
bool IsUsingSystemTime() const { return XPLMGetDatai(adrXP[DR_USE_SYSTEM_TIME]); }
int GetLocalDateDays() const { return XPLMGetDatai(adrXP[DR_LOCAL_DATE_DAYS]); }
float GetLocalTimeSec() const { return XPLMGetDataf(adrXP[DR_LOCAL_TIME_SEC]); }
float GetZuluTimeSec() const { return XPLMGetDataf(adrXP[DR_ZULU_TIME_SEC]); }
long long GetXPSimTime_ms() const { return lastXPSimTime_ms; }
void UpdateXPSimTime(); ///< Calculate X-Plane's current simulation time as Unix epoch time in milliseconds (Java timestamp)
std::string GetXPSimTimeStr() const; ///< Return a nicely formated time string with XP's simulated time in UTC

void SetViewType(XPViewTypes vt);
positionTy GetUsersPlanePos(double& trueAirspeed_m, double& track) const;

Expand Down Expand Up @@ -934,6 +955,7 @@ class DataRefs
void SetADSBExAPIKey (std::string apiKey) { sADSBExAPIKey = apiKey; }

bool SetRTTrafficPort (int port) { return SetCfgValue(&rtTrafficPort, port); }
SimTimeCtrlTy GetRTSTC () const { return rtSTC; } ///< RealTraffic simulator time control setting

size_t GetFSCEnv() const { return (size_t)fscEnv; }
void GetFSCharterCredentials (std::string& user, std::string& pwd)
Expand Down
11 changes: 7 additions & 4 deletions Include/LTRealTraffic.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ 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 MSG_RT_ADJUST " | historic traffic from %s"

#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 INFO_RT_ADJUST_TS "RealTraffic: Receive and display past tracking data from %s"
#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"
Expand Down Expand Up @@ -247,8 +247,11 @@ class RealTrafficConnection : public LTOnlineChannel, LTFlightDataChannel
static void tcpConnectionS (RealTrafficConnection* me) { me->tcpConnection();}
bool StopTcpConnection ();

void SendPos (const positionTy& pos, double speed_m);
void SendUsersPlanePos();
void SendMsg (const char* msg); ///< Send and log a message to RealTraffic
void SendTime (long long ts); ///< Send a timestamp to RealTraffic
void SendXPSimTime(); ///< Send XP's current simulated time to RealTraffic, adapted to "today or earlier"
void SendPos (const positionTy& pos, double speed_m); ///< Send position/speed info for own ship to RealTraffic
void SendUsersPlanePos(); ///< Send user's plane's position/speed to RealTraffic

// MARK: UDP
// UDP Listen: the main function for receiving UDP broadcasts
Expand Down
2 changes: 1 addition & 1 deletion Lib/XPMP2
Submodule XPMP2 updated 68 files
+2 −2 .github/workflows/build.yml
+1 −1 CMakeLists.txt
+61 −0 docs/Contrails.md
+4 −0 docs/Deploying.md
+0 −721 docs/html/Client_8cpp.html
+0 −300 docs/html/Client_8h.html
+0 −196 docs/html/Client_8h_source.html
+2 −2 docs/html/Contrails_8md.html
+0 −112 docs/html/FMOD__Logo_8cpp.html
+0 −113 docs/html/FMOD__Logo_8h.html
+0 −79 docs/html/FMOD__Logo_8h_source.html
+0 −381 docs/html/XPMP2-Remote_2Utilities_8cpp.html
+0 −611 docs/html/XPMP2-Remote_2Utilities_8h.html
+0 −158 docs/html/XPMP2-Remote_2Utilities_8h_source.html
+0 −692 docs/html/XPMP2-Remote_8cpp.html
+0 −263 docs/html/XPMP2-Remote_8h.html
+0 −154 docs/html/XPMP2-Remote_8h_source.html
+0 −52 docs/html/XPMP2-Sample_2README_8md.html
+0 −1,435 docs/html/XPMP2-Sample_8cpp.html
+0 −265 docs/html/classLegacySampleAircraft-members.html
+0 −881 docs/html/classLegacySampleAircraft.html
+ docs/html/classLegacySampleAircraft.png
+0 −278 docs/html/classRemoteAC-members.html
+0 −1,284 docs/html/classRemoteAC.html
+ docs/html/classRemoteAC.png
+0 −258 docs/html/classSampleAircraft-members.html
+0 −775 docs/html/classSampleAircraft.html
+ docs/html/classSampleAircraft.png
+0 −68 docs/html/dir_05cb372b8b5d29a91f8ab8956535a165.html
+0 −62 docs/html/dir_51881af2d47c8c327d633c4b13cbc753.html
+0 −62 docs/html/dir_697d5b740a2e246e51f61ae622e5094c.html
+0 −66 docs/html/dir_7370f38adb3ae597f7d725dcce8bc0c8.html
+0 −78 docs/html/dir_ee4fc00837492ac40974302c5064a581.html
+0 −55 docs/html/globals_b.html
+0 −90 docs/html/globals_g.html
+0 −65 docs/html/globals_h.html
+0 −58 docs/html/globals_n.html
+0 −68 docs/html/globals_r.html
+2 −2 docs/html/index.html
+0 −63 docs/html/md_XPMP2_Remote_README.html
+0 −76 docs/html/md_XPMP2_Sample_README.html
+4 −4 docs/html/md_docs_CSLdataRefs.html
+82 −0 docs/html/md_docs_Contrails.html
+3 −3 docs/html/md_docs_CopyingObjFiles.html
+4 −3 docs/html/md_docs_Deploying.html
+4 −4 docs/html/md_docs_HowTo.html
+3 −3 docs/html/md_docs_Matching.html
+4 −4 docs/html/md_docs_Remote.html
+3 −3 docs/html/md_docs_SharedDataRefs.html
+3 −3 docs/html/md_docs_TCAS.html
+2 −2 docs/html/md_docs_Wake.html
+3 −3 docs/html/md_docs_XSBAircraftFormat.html
+5 −4 docs/html/md_docs_index.html
+0 −256 docs/html/namespaceFMODLogo.html
+14 −13 docs/html/pages.html
+0 −181 docs/html/src_2Utilities_8cpp.html
+0 −565 docs/html/src_2Utilities_8h.html
+0 −369 docs/html/src_2Utilities_8h_source.html
+0 −59 docs/html/structSenderAddrTy-members.html
+0 −177 docs/html/structSenderAddrTy.html
+0 −62 docs/html/structSenderTy-members.html
+0 −242 docs/html/structSenderTy.html
+0 −65 docs/html/structXPMP2RCGlobals-members.html
+0 −233 docs/html/structXPMP2RCGlobals.html
+1 −0 docs/index.md
+43 −8 src/Sound.cpp
+30 −1 src/Utilities.cpp
+2 −0 src/Utilities.h
4 changes: 2 additions & 2 deletions LiveTraffic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@
LIVETRAFFIC_VERSION_BETA = 0;
LIVETRAFFIC_VER_MAJOR = 3;
LIVETRAFFIC_VER_MINOR = 3;
LIVETRAFFIC_VER_PATCH = 0;
LIVETRAFFIC_VER_PATCH = 1;
LLVM_LTO = NO;
MACH_O_TYPE = mh_dylib;
MACOSX_DEPLOYMENT_TARGET = 11.0;
Expand Down Expand Up @@ -894,7 +894,7 @@
LIVETRAFFIC_VERSION_BETA = 0;
LIVETRAFFIC_VER_MAJOR = 3;
LIVETRAFFIC_VER_MINOR = 3;
LIVETRAFFIC_VER_PATCH = 0;
LIVETRAFFIC_VER_PATCH = 1;
LLVM_LTO = YES;
MACH_O_TYPE = mh_dylib;
MACOSX_DEPLOYMENT_TARGET = 11.0;
Expand Down
132 changes: 128 additions & 4 deletions Src/DataRefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ DataRefs::dataRefDefinitionT DATA_REFS_LT[CNT_DATAREFS_LT] = {
{"livetraffic/channel/real_traffic/listen_port",DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/channel/real_traffic/traffic_port",DataRefs::LTGetInt,DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/channel/real_traffic/weather_port",DataRefs::LTGetInt,DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/channel/real_traffic/sim_time_ctrl",DataRefs::LTGetInt,DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/channel/fore_flight/send_port", DataRefs::LTGetInt, DataRefs::LTSetCfgValue, GET_VAR, true },
{"livetraffic/channel/fore_flight/user_plane", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true },
{"livetraffic/channel/fore_flight/traffic", DataRefs::LTGetInt, DataRefs::LTSetBool, GET_VAR, true },
Expand Down Expand Up @@ -643,6 +644,7 @@ void* DataRefs::getVarAddr (dataRefsLT dr)
case DR_CFG_RT_LISTEN_PORT: return &rtListenPort;
case DR_CFG_RT_TRAFFIC_PORT: return &rtTrafficPort;
case DR_CFG_RT_WEATHER_PORT: return &rtWeatherPort;
case DR_CFG_RT_SIM_TIME_CTRL: return &rtSTC;
case DR_CFG_FF_SEND_PORT: return &ffSendPort;
case DR_CFG_FF_SEND_USER_PLANE: return &bffUserPlane;
case DR_CFG_FF_SEND_TRAFFIC: return &bffTraffic;
Expand Down Expand Up @@ -779,6 +781,13 @@ bool DataRefs::Init ()
XPLMGetSystemPath ( aszPath );
XPSystemPath = aszPath;

// XP Version
XPLMGetVersions(&xpVer, &xplmVer, nullptr);
snprintf(aszPath, sizeof(aszPath), "X-Plane %d.%02d",
xpVer / 1000,
((xpVer) / 10) % 100);
sXpVer = aszPath;

// Directory Separator provided by XP
DirSeparator = XPLMGetDirectorySeparator();

Expand Down Expand Up @@ -999,6 +1008,98 @@ float DataRefs::GetMiscNetwTime() const
return lastNetwTime;
}


// Calculates X-Plane's current simulation time as Unix epoch time in milliseconds (Java timestamp)
/// @details Complication:
/// X-Plane provides _local_ data and time,
/// but only zulu time, no date, but zulu date can easily differ
/// from local date. So from user position's longitude we need to guess
/// if zulu data is before, on, or after local date.
void DataRefs::UpdateXPSimTime()
{
// convert all numbers right away to milliseconds as we need that in the end anyway
// and that way we preserve the meaning of the fractional seconds coming from X-Plane
constexpr long long DAY_MS = 24LL * 60LL * 60LL * 1000LL;
long long t = (long long)(GetLocalDateDays()) * DAY_MS;
const long long localTime = (long long)(GetLocalTimeSec() * 1000.0f);
const long long zuluTime = (long long)(GetZuluTimeSec() * 1000.0f);
// if local and zulu time are different at all (testing for more than one minute difference)
if (std::llabs(localTime - zuluTime) > 60000LL) {
// Eastern hemisphere? -> Zulu is _behind_ local time
if (lastUsersPlanePos.lon() > 0.0) {
// but if the local Zulu time component is actually _ahead of_ local time, then need to decrement zulu date
if (zuluTime > localTime)
t -= DAY_MS;
} else {
// Western hemisphere -> Zulu is _ahead of_ local time
// but if the zulu time component is actually _behind_ local time, then need to increment zulu date
if (zuluTime < localTime)
t += DAY_MS;
}
}
// Now t is date in zulu days, just add time component
t += zuluTime;

// Last thing to do: Add the beginning of the right year to it
// Complications: X-Plane has no notion of a "year", it just returns days since start of the year
// X-Plane offers only 28 days for February, so it runs on a 365d year
// If the day of the year is past current real life day of year, then assume "last year"
// But: What do we do with leap years in reality???

// Find this year's beginning
time_t now;
std::tm tm;
time(&now); // today, actually 'now'
gmtime_s(&tm, &now);
tm.tm_yday = 0; // set to 01-JAN of 'this year'
tm.tm_mday = 1;
tm.tm_mon = 0;
tm.tm_hour = 0;
tm.tm_min = 0;
tm.tm_sec = 0;
tm.tm_isdst = 0;
time_t jan01 = mktime_utc(tm); // convert 01-JAN back to Unix epoch

// Convert to milliseconds, then add to our result
t += (long long)(jan01) * 1000LL;

// if t is now (more than 1s) in the future, then we reduce t by an entire year,
// supposingly pointing to the same day last year
if (t > (long long)(now+1) * 1000LL) {
// Save a date representation of what we computed so far in the future
time_t unix_t = time_t(t / 1000LL);
std::tm tm_future;
gmtime_s(&tm_future, &unix_t);

// reduce by 365 days
t -= 365LL * DAY_MS;

// Would we need to skip over a leap year's 29th Feb?
// Goal is: We need to end up on the same day of the month,
// so convert back to calendar days and let's check
unix_t = time_t(t / 1000LL);
gmtime_s(&tm, &unix_t);
// If day of month don't agree then reduce by another day to cover leap day
if (tm.tm_mday != tm_future.tm_mday)
t -= DAY_MS;
}

// Done: store as our last calculate value
lastXPSimTime_ms = (long long)t;
}


// Return a nicely formated time string with XP's simulated time in UTC
std::string DataRefs::GetXPSimTimeStr() const
{
char s[100];
time_t xp_t = time_t(lastXPSimTime_ms / 1000L);
struct tm xp_tm;
gmtime_s(&xp_tm, &xp_t);
std::strftime(s, sizeof(s), "%Y-%m-%d %H:%M:%S UTC", &xp_tm);
return s;
}

/// Set the view type, translating from XPViewTypes to command ref needed
void DataRefs::SetViewType(XPViewTypes vt)
{
Expand Down Expand Up @@ -1613,6 +1714,7 @@ bool DataRefs::SetCfgValue (void* p, int val)
rtListenPort < 1024 || rtListenPort > 65535 ||
rtTrafficPort < 1024 || rtTrafficPort > 65535 ||
rtWeatherPort < 1024 || rtWeatherPort > 65535 ||
rtSTC < STC_NO_CTRL || rtSTC > STC_SIM_TIME_PLUS_BUFFER ||
contrailAltMin_ft < 0 || contrailAltMin_ft> 90000 ||
contrailAltMax_ft < 0 || contrailAltMax_ft> 90000 ||
contrailLifeTime < 5 || contrailLifeTime > 300 ||
Expand Down Expand Up @@ -1898,7 +2000,8 @@ bool DataRefs::LoadConfigFile()
assert (aFlarmToIcaoAcTy.size() == size_t(FAT_UAV)+1);

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

// open a config file
std::string sFileName (LTCalcFullPath(PATH_CONFIG_FILE));
Expand Down Expand Up @@ -1945,8 +2048,24 @@ bool DataRefs::LoadConfigFile()
// Any pre-v3 version?
if (ln[1][0] < '3')
conv = CFG_V3;
else if (ln[1] < "3.1")
conv = CFG_V31;
else {
// we expect a version number with 3 parts...but we'll be careful
std::regex reVerNum ("(\\d+)\\.(\\d+)\\.(\\d+)");
std::smatch m;
std::regex_search(ln[1], m, reVerNum);
if (m.size() >= 2)
cfgFileVer = std::stoul(m[1]) * 10000;
if (m.size() >= 3)
cfgFileVer += std::stoul(m[2]) * 100;
if (m.size() >= 4)
cfgFileVer += std::stoul(m[3]);

// any conversions required?
if (cfgFileVer < 30100) // < 3.1.0
conv = CFG_V31;
else if (cfgFileVer < 30301) // < 3.3.1
conv = CFG_V331;
}
}

// *** Delete LiveTraffic_imgui.prf? ***
Expand Down Expand Up @@ -1993,8 +2112,12 @@ bool DataRefs::LoadConfigFile()
// conversion of older config file formats
switch (conv) {
case CFG_NO_CONV:
case CFG_V31: break;
break;
case CFG_V331:
case CFG_V31:
case CFG_V3:
// 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")
Expand Down Expand Up @@ -2354,6 +2477,7 @@ void DataRefs::UpdateCachedValues ()
UpdateViewPos();
UpdateUsersPlanePos();
UpdateSimWind();
UpdateXPSimTime();
ExportUserAcData();
}

Expand Down
20 changes: 20 additions & 0 deletions Src/InfoListWnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,26 @@ void InfoListWnd::buildInterface()

ImGui::TreePop();
}

// X-Plane Version info
if (ImGui::TreeNode(dataRefs.sXpVer.c_str())) {
if (ImGui::BeginTable("X-Plane Version Info", 2, ImGuiTableFlags_SizingPolicyFixedX)) {
ImGui::TableNextRow();
if (ImGui::TableSetColumnIndex(0)) ImGui::TextUnformatted("X-Plane Version");
if (ImGui::TableSetColumnIndex(1)) ImGui::Text("%d", dataRefs.xpVer);
ImGui::TableNextRow();
if (ImGui::TableSetColumnIndex(0)) ImGui::TextUnformatted("XPLM Version");
if (ImGui::TableSetColumnIndex(1)) ImGui::Text("%d", dataRefs.xplmVer);
ImGui::TableNextRow();
if (ImGui::TableSetColumnIndex(0)) ImGui::TextUnformatted("Sim Time");
if (ImGui::TableSetColumnIndex(1))
ImGui::Text("%s (%s)",
dataRefs.GetXPSimTimeStr().c_str(),
dataRefs.IsUsingSystemTime() ? "live" : "user setting");
ImGui::EndTable();
}
ImGui::TreePop();
}

// Credits
if (ImGui::TreeNode("Credits")) {
Expand Down
Loading

0 comments on commit 90490a8

Please sign in to comment.