Skip to content

Commit

Permalink
Feat/Weather: Prepare for more generic weather, METAR-based
Browse files Browse the repository at this point in the history
  • Loading branch information
TwinFan committed Aug 24, 2024
1 parent 43cd78c commit 2626f06
Show file tree
Hide file tree
Showing 22 changed files with 241 additions and 276 deletions.
Binary file not shown.
Binary file not shown.
169 changes: 0 additions & 169 deletions Data/RealTraffic/RTAPI_example.py

This file was deleted.

Binary file removed Data/RealTraffic/RTTFC_Template.xlsx
Binary file not shown.
Binary file removed Data/RealTraffic/RT_API.sjson/725578599.580375
Binary file not shown.
Binary file removed Data/RealTraffic/RT_API.sjson/742555946.884103
Binary file not shown.
Binary file added Data/RealTraffic/RT_API.sjson/744147965.110025
Binary file not shown.
Binary file added Data/RealTraffic/RT_API.sjson/744148065.431184
Binary file not shown.
Binary file not shown.
Binary file modified Data/RealTraffic/RT_API.sjson/data
Binary file not shown.
Binary file modified Data/RealTraffic/RT_API.sjson/metaData
Binary file not shown.
Binary file modified Data/RealTraffic/RealTraffic API.pdf
Binary file not shown.
1 change: 1 addition & 0 deletions Include/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ constexpr const char* REMOTE_SIGNATURE = "TwinFan.plugin.XPMP2.Remote";
#define HELP_SET_OUTPUT_CH "setup/installation/foreflight" // currently the same as ForeFlight, which is the only output channel
#define HELP_SET_CH_FOREFLIGHT "setup/installation/foreflight"
#define HELP_SET_ACLABELS "setup/configuration/settings-a-c-labels"
#define HELP_SET_WEATHER "setup/configuration/settings-weather"
#define HELP_SET_ADVANCED "setup/configuration/settings-advanced"
#define HELP_SET_CSL "setup/configuration/settings-csl"
#define HELP_SET_DEBUG "setup/configuration/settings-debug"
Expand Down
33 changes: 26 additions & 7 deletions Include/DataRefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ const bool DEF_SND_FMOD_INST = true; ///< Enforce using our own FMOD
#endif
const int DEF_SUI_TRANSP = 0; ///< Settings UI: transaprent background?
const int DEF_MAX_NETW_TIMEOUT = 5; ///< [s] default maximum network request timeout

const int DEF_WEATHER_MAX_METAR_AGL_FT = 5000; ///< Max height AGL up to which we weigh METAR higher than other weather data
const int DEF_WEATHER_MAX_METAR_DIST_NM = 25; ///< Max distance up to which to use a METAR for weather

constexpr int DEF_UI_FONT_SCALE = 100; ///< [%] Default font scaling
constexpr int DEF_UI_OPACITY = 25; ///< [%] Default background opacity
Expand Down Expand Up @@ -395,6 +396,9 @@ enum dataRefsLT {
DR_CFG_CONTRAIL_MAX_ALT,
DR_CFG_CONTRAIL_LIFE_TIME,
DR_CFG_CONTRAIL_MULTIPLE,
DR_CFG_WEATHER_CONTROL,
DR_CFG_WEATHER_MAX_METAR_AGL,
DR_CFG_WEATHER_MAX_METAR_DIST,
DR_CFG_REMOTE_SUPPORT,
DR_CFG_EXTERNAL_CAMERA,
DR_CFG_LAST_CHECK_NEW_VER,
Expand All @@ -419,7 +423,6 @@ enum dataRefsLT {
DR_CFG_RT_SIM_TIME_CTRL,
DR_CFG_RT_MAN_TOFFSET,
DR_CFG_RT_CONNECT_TYPE,
DR_CFG_RT_SET_WEATHER,
DR_CFG_FF_LISTEN_PORT,
DR_CFG_FF_SEND_PORT,
DR_CFG_FF_SEND_USER_PLANE,
Expand Down Expand Up @@ -470,6 +473,14 @@ enum SimTimeCtrlTy : int {
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
};

/// How to control weather?
enum WeatherCtrlTy : int {
WC_INIT = -1, ///< Initial value when not available in config file, then a default is determined in first flight loop depending if XP is using real weather
WC_NONE = 0, ///< No weather control, X-Plane is in control
WC_METAR_XP, ///< Use METAR to control weather in lower altitudes, X-Plane Live Weather in higher altitudes
WC_REAL_TRAFFIC, ///< Use RealTraffic's weather data to control all weather
};

/// Which RealTraffic connection type to use?
enum RTConnTypeTy : int {
RT_CONN_REQU_REPL = 0, ///< Expect a license and use request/reply
Expand Down Expand Up @@ -725,7 +736,9 @@ class DataRefs
SimTimeCtrlTy rtSTC = STC_SIM_TIME_PLUS_BUFFER; ///< Which sim time to send to RealTraffic?
int rtManTOfs = 0; ///< manually configure time offset for requesting historic data
RTConnTypeTy rtConnType = RT_CONN_REQU_REPL; ///< Which type of connection to use for RealTraffic data
int rtSetWeather = 1; ///< Set X-Plane's weather based on RealTraffic weather data? (0-Off, 1-Auto, 2-On)
WeatherCtrlTy weatherCtl = WC_INIT; ///< How to control weather?
int weatherMaxMETARheight_ft = DEF_WEATHER_MAX_METAR_AGL_FT; ///< height AGL up to which we use/prefer METAR data
int weatherMaxMETARdist_nm = DEF_WEATHER_MAX_METAR_DIST_NM; ///< distance [nm] up to which to use METAR for weather
int ffListenPort = 63093; ///< UDP Port to listen to ForeFlight announcing itself, https://www.foreflight.com/connect/spec/
int ffSendPort = 49002; ///< UDP Port to send simulator data to ForeFlight, https://www.foreflight.com/support/network-gps/
int bffUserPlane = 1; // bool Send User plane data?
Expand Down Expand Up @@ -974,6 +987,12 @@ class DataRefs
bool SetDefaultAcIcaoType(const std::string type);
bool SetDefaultCarIcaoType(const std::string type);

WeatherCtrlTy GetWeatherControl() const { return weatherCtl; }
int GetWeatherMaxMetarHeight_ft() const { return weatherMaxMETARheight_ft; }
float GetWeatherMaxMetarHeight_m() const { return float(weatherMaxMETARheight_ft * M_per_FT); }
int GetWeatherMaxMetarDist_nm() const { return weatherMaxMETARdist_nm; }
float GetWeatherMaxMetarDist_m() const { return weatherMaxMETARdist_nm * M_per_NM; }

// livetraffic/channel/...
void SetChannelEnabled (dataRefsLT ch, bool bEnable);
inline bool IsChannelEnabled (dataRefsLT ch) const { return bChannel[ch - DR_CHANNEL_FIRST]; }
Expand All @@ -993,7 +1012,6 @@ class DataRefs
RTConnTypeTy GetRTConnType () const { return rtConnType; }
const std::string& GetRTLicense () const { return sRTLicense; }
void SetRTLicense (const std::string& license) { sRTLicense = license; }
int GetRTSetWeather() const { return rtSetWeather; }

size_t GetFSCEnv() const { return (size_t)fscEnv; }
void GetFSCharterCredentials (std::string& user, std::string& pwd)
Expand Down Expand Up @@ -1079,10 +1097,11 @@ class DataRefs

// Weather
bool WeatherFetchMETAR (); ///< check if weather updated needed, then do
/// @brief set/update current weather
/// @brief set/update current weather, tries reading QNH from METAR
/// @details if lat/lon ar NAN, then location of provided station is taken if found, else current camera pos
void SetWeather (float hPa, float lat, float lon, const std::string& stationId,
const std::string& METAR);
/// @returns QNH (`hPa` if not read from `METAR`)
float SetWeather (float hPa, float lat, float lon, const std::string& stationId,
const std::string& METAR);
/// Get current sea level air pressure
double GetPressureHPA() const { return lastWeatherHPA; }
/// Thread-safely gets current weather info
Expand Down
2 changes: 0 additions & 2 deletions Include/LTRealTraffic.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ constexpr double RT_VSI_AIRBORNE = 80.0; ///< if VSI is more than this then w
constexpr long RT_DRCT_DEFAULT_WAIT = 8000L; ///< [ms] Default wait time between traffic requests
constexpr std::chrono::seconds RT_DRCT_ERR_WAIT = std::chrono::seconds(5); ///< standard wait between errors
constexpr std::chrono::minutes RT_DRCT_WX_WAIT = std::chrono::minutes(1); ///< How often to update weather?
constexpr long RT_DRCT_WX_DIST = 10L * M_per_NM; ///< Distance for which weather is considered valid, greater than that and we re-request
constexpr int RT_DRCT_MAX_WX_ERR = 5; ///< Max number of consecutive errors during initial weather requests we wait for...before not asking for weather any longer
constexpr double RT_DRCT_MAX_METAR_DIST_NM = 10.0; ///< Max distance a METAR station is considered valid...otherwise we rather use no METAR (for clouds, for example)

/// Fields in a response of a direct connection's request
enum RT_DIRECT_FIELDS_TY {
Expand Down
8 changes: 4 additions & 4 deletions Include/LTWeather.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ void WeatherStop ();

/// Can we, technically, set weather? (X-Plane 12 forward only)
bool WeatherCanSet ();
/// Shall we actuall set the weather as per ability and user's configuration?
bool WeatherShallSet ();
/// Are we controlling weather?
bool WeatherInControl ();
/// Is X-Plane set to use real weather?
bool WeatherIsXPRealWeather ();

/// Thread-safely store weather information to be set in X-Plane in the main thread later
void WeatherSet (const LTWeather& w);
/// Thread-safely store weather information to be set in X-Plane in the main thread later
void WeatherSet (const std::string& metar);
/// Actually update X-Plane's weather if there is anything to do (called from main thread)
void WeatherUpdate ();
/// Reset weather settings to what they were before X-Plane took over
Expand All @@ -61,8 +63,6 @@ constexpr double WEATHER_MAX_DIST_M = 50 * M_per_NM;
constexpr float WEATHER_METAR_CLOUD_HEIGHT_M = 500;
/// Thickness of a METAR Cumulo-nimbus cloud layer [m]
constexpr float WEATHER_METAR_CB_CLOUD_HEIGHT_M = 5000;
/// May height AGL up to which we weigh METAR higher than other weather data
constexpr double PREFER_METAR_MAX_AGL_M = 5000.0 * M_per_FT;

/// @brief Weather data to be set in X-Plane
/// @details A value of `NAN` means: don't set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,54 @@
uuid = "C8095CDD-1C39-4D01-99B0-6AD4723390BD"
type = "1"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "E55D723C-8070-4161-9583-3E9CDC9CE64F"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Src/LTWeather.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "1417"
endingLineNumber = "1417"
landmarkName = "WeatherSet(metar)"
landmarkType = "9">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "98DFB638-5AC7-4BC1-8615-61BD3D72712F"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Src/DataRefs.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "2768"
endingLineNumber = "2768"
landmarkName = "DataRefs::SetWeather(hPa, lat, lon, stationId, METAR)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "35908039-6A9A-4468-98DE-266A5395A2AF"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "Src/LTRealTraffic.cpp"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "579"
endingLineNumber = "579"
landmarkName = "RealTrafficConnection::ProcessFetchedData()"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
Loading

0 comments on commit 2626f06

Please sign in to comment.