Skip to content

Commit

Permalink
Refactor: ForeFlight working; standardised status texts
Browse files Browse the repository at this point in the history
  • Loading branch information
TwinFan committed Dec 14, 2023
1 parent df54010 commit 2a512f0
Show file tree
Hide file tree
Showing 14 changed files with 192 additions and 282 deletions.
1 change: 1 addition & 0 deletions Include/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ constexpr const char* REMOTE_SIGNATURE = "TwinFan.plugin.XPMP2.Remote";
#define HELP_SET_BASICS "setup/configuration/settings-basics"
#define HELP_SET_INPUT_CH "introduction/features/channels"
#define HELP_SET_CH_OPENSKY "setup/installation/opensky"
#define HELP_SET_CH_ADSBHUB "setup/installation/adsbhub"
#define HELP_SET_CH_ADSBEX "setup/installation/ads-b-exchange"
#define HELP_SET_CH_OPENGLIDER "setup/installation/ogn"
#define HELP_SET_CH_REALTRAFFIC "setup/installation/realtraffic-connectivity"
Expand Down
4 changes: 2 additions & 2 deletions Include/LTADSBEx.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
#define ADSBEX_RAPIDAPI_25_URL "https://adsbx-flight-sim-traffic.p.rapidapi.com/api/aircraft/json/lat/%f/lon/%f/dist/25/"
#define ADSBEX_RAPIDAPI_HOST "X-RapidAPI-Host:adsbx-flight-sim-traffic.p.rapidapi.com"
#define ADSBEX_RAPIDAPI_KEY "X-RapidAPI-Key:"
#define ADSBEX_RAPIDAPI_RLIMIT "X-RateLimit-Requests-Limit:"
#define ADSBEX_RAPIDAPI_RREMAIN "X-RateLimit-Requests-Remaining:"
#define ADSBEX_RAPIDAPI_RLIMIT "x-ratelimit-requests-limit:"
#define ADSBEX_RAPIDAPI_RREMAIN "x-ratelimit-requests-remaining:"

#define ADSBEX_TOTAL "total"
#define ADSBEX_NOW "now"
Expand Down
2 changes: 0 additions & 2 deletions Include/LTChannel.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ class LTChannel
virtual bool IsEnabled () const;
virtual void SetEnable (bool bEnable);
virtual std::string GetStatusText () const; ///< return a human-readable staus
virtual std::string GetStatusTextExt () const///< optionally return an extended status
{ return std::string(); }
virtual int GetNumAcServed () const = 0; ///< how many a/c do we feed?

// shall data of this channel be subject to LTFlightData::DataSmoothing?
Expand Down
21 changes: 2 additions & 19 deletions Include/LTForeFlight.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,8 @@ constexpr std::chrono::milliseconds FF_INTVL = std::chrono::milliseconds(
class ForeFlightSender : public LTOutputChannel
{
protected:
// thread
std::thread thrUdpSender;
volatile bool bStopUdpSender = true; // tells thread to stop
std::mutex ffStopMutex; // supports wake-up and stop synchronization
std::condition_variable ffStopCV;
// UDP sender
UDPReceiver udpSender;
bool bSendUsersPlane = true;
bool bSendAITraffic = true;
// time points last sent something
std::chrono::steady_clock::time_point nextGPS;
std::chrono::steady_clock::time_point nextAtt;
Expand All @@ -70,26 +63,16 @@ class ForeFlightSender : public LTOutputChannel

public:
ForeFlightSender ();
~ForeFlightSender () override;

std::string GetURL (const positionTy&) override { return ""; } // don't need URL, no request/reply

// interface called from LTChannel
bool FetchAllData(const positionTy& pos) override;
bool FetchAllData(const positionTy&) override { return false; }
bool ProcessFetchedData () override { return true; }
void DoDisabledProcessing() override;
void Close () override;

protected:
void Main () override; ///< virtual thread main function

// Start/Stop
bool StartConnection ();
bool StopConnection ();

// send positions
void udpSend(); // thread's main function
static void udpSendS (ForeFlightSender* me) { me->udpSend(); }
void Main () override; ///< virtual thread main function
void SendGPS (const positionTy& pos, double speed_m, double track); // position of user's aircraft
void SendAtt (const positionTy& pos, double speed_m, double track); // attitude of user's aircraft
void SendAllTraffic (); // other traffic
Expand Down
5 changes: 2 additions & 3 deletions Include/LTRealTraffic.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ constexpr size_t RT_NET_BUF_SIZE = 8192;
constexpr double RT_VSI_AIRBORNE = 80.0; ///< if VSI is more than this then we assume "airborne"

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

#define INFO_RT_REAL_TIME "RealTraffic: Tracking data is real-time again."
Expand Down Expand Up @@ -211,8 +211,7 @@ class RealTrafficConnection : public LTFlightDataChannel
inline rtStatusTy GetStatus () const { return status; }
double GetLastRcvdTime () const { return lastReceivedTime; }
std::string GetStatusStr () const;
std::string GetStatusText () const override; ///< return a human-readable staus
std::string GetStatusTextExt () const override;
std::string GetStatusText () const override; ///< return a human-readable status

inline bool IsConnected () const { return RT_STATUS_CONNECTED_PASSIVELY <= status && status <= RT_STATUS_CONNECTED_FULL; }
inline bool IsConnecting () const { return RT_STATUS_STARTING <= status && status <= RT_STATUS_CONNECTED_FULL; }
Expand Down
2 changes: 1 addition & 1 deletion Lib/XPMP2
Submodule XPMP2 updated 1 files
+1 −1 Resources/Doc8643.txt
6 changes: 1 addition & 5 deletions Src/InfoListWnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,12 +423,8 @@ void InfoListWnd::buildInterface()
ImGui::TextUnformatted(pCh->ChName());
}
// Channel's status
if (ImGui::TableSetColumnIndex(1)) {
if (ImGui::TableSetColumnIndex(1))
ImGui::TextUnformatted(pCh->GetStatusText().c_str());
const std::string extStatus = pCh->GetStatusTextExt();
if (!extStatus.empty())
ImGui::TextUnformatted(extStatus.c_str());
}
ImGui::PopID();
}
}
Expand Down
12 changes: 9 additions & 3 deletions Src/LTADSBEx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,9 @@ std::string ADSBExchangeConnection::GetStatusText () const
std::string s = LTChannel::GetStatusText();
if (IsValid() && IsEnabled() && dataRefs.ADSBExRLimit > 0)
{
s += ", ";
s += " | ";
s += std::to_string(dataRefs.ADSBExRRemain);
s += " / ";
s += " of ";
s += std::to_string(dataRefs.ADSBExRLimit);
s += " RAPID API requests left";
}
Expand Down Expand Up @@ -596,6 +596,12 @@ size_t ADSBExchangeConnection::ReceiveHeader(char *buffer, size_t size, size_t n
static size_t lenRLimit = strlen(ADSBEX_RAPIDAPI_RLIMIT);
static size_t lenRRemain = strlen(ADSBEX_RAPIDAPI_RREMAIN);
char num[50];

// Turn buffer content lower case for the first few chars we are to compare
const size_t lenMax = std::min(std::max(lenRLimit,lenRRemain),len);
size_t i = 0;
for (char* p = buffer; i < lenMax; ++i, ++p)
*p = char(std::tolower(*p));

// Limit?
if (len > lenRLimit &&
Expand All @@ -606,7 +612,7 @@ size_t ADSBExchangeConnection::ReceiveHeader(char *buffer, size_t size, size_t n
num[copyCnt]=0; // zero termination
dataRefs.ADSBExRLimit = std::atol(num);
}
// Remining?
// Remaining?
else if (len > lenRRemain &&
memcmp(buffer, ADSBEX_RAPIDAPI_RREMAIN, lenRRemain) == 0)
{
Expand Down
8 changes: 4 additions & 4 deletions Src/LTADSBHub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ std::string ADSBHubConnection::GetStatusText () const
}
else if (isRunning()) {
switch (eFormat) {
case FMT_SBS: s += ", receiving SBS format"; break;
case FMT_ComprVRS: s += ", receiving Compressed VRS format"; break;
default: s += ", connecting...";
case FMT_SBS: s += " | SBS format"; break;
case FMT_ComprVRS: s += " | Compressed VRS format"; break;
default: s += " | connecting...";
}
// add time since last data
if (lastData != std::chrono::time_point<std::chrono::steady_clock>()) {
char t[100];
std::chrono::duration<double> diff = std::chrono::steady_clock::now() - lastData;
snprintf(t, sizeof(t), ", last data %.1fs ago", diff.count());
snprintf(t, sizeof(t), " | last msg %.0fs ago", diff.count());
s += t;
}
}
Expand Down
Loading

0 comments on commit 2a512f0

Please sign in to comment.