Skip to content

Commit

Permalink
Added support for unavailable metar
Browse files Browse the repository at this point in the history
Fixed landing report 0 index
  • Loading branch information
sushiat committed Dec 13, 2023
1 parent 62f5379 commit 361a8c2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
24 changes: 18 additions & 6 deletions OpenSky.Agent.Simulator/Simulator.Metar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ public partial class Simulator
/// The alternate metar.
/// </summary>
/// -------------------------------------------------------------------------------------------------
private string alternateMetar = "???";
private string alternateMetar = "???\n";

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Destination metar.
/// </summary>
/// -------------------------------------------------------------------------------------------------
private string destinationMetar = "???";
private string destinationMetar = "???\n";

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// The origin metar.
/// </summary>
/// -------------------------------------------------------------------------------------------------
private string originMetar = "???";
private string originMetar = "???\n";

/// -------------------------------------------------------------------------------------------------
/// <summary>
Expand Down Expand Up @@ -122,10 +122,14 @@ public void RefreshMetar()
{
var url = $"https://aviationweather.gov/api/data/metar?ids={this.Flight.Origin.Icao}";
this.OriginMetar = client.DownloadString(url);
if (string.IsNullOrEmpty(this.OriginMetar))
{
this.OriginMetar = "Unavailable\n";
}
}
else
{
this.OriginMetar = "???";
this.OriginMetar = "???\n";
}
}
catch (Exception ex)
Expand All @@ -140,10 +144,14 @@ public void RefreshMetar()
{
var url = $"https://aviationweather.gov/api/data/metar?ids={this.Flight.Destination.Icao}";
this.DestinationMetar = client.DownloadString(url);
if (string.IsNullOrEmpty(this.DestinationMetar))
{
this.DestinationMetar = "Unavailable\n";
}
}
else
{
this.DestinationMetar = "???";
this.DestinationMetar = "???\n";
}
}
catch (Exception ex)
Expand All @@ -158,10 +166,14 @@ public void RefreshMetar()
{
var url = $"https://aviationweather.gov/api/data/metar?ids={this.Flight.Alternate.Icao}";
this.AlternateMetar = client.DownloadString(url);
if (string.IsNullOrEmpty(this.AlternateMetar))
{
this.AlternateMetar = "Unavailable\n";
}
}
else
{
this.AlternateMetar = "???";
this.AlternateMetar = "???\n";
}
}
catch (Exception ex)
Expand Down
2 changes: 1 addition & 1 deletion OpenSky.Agent.Simulator/Simulator.Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ private void ProcessPrimaryTracking()
}

// Are we close to landing?
this.SampleRates[Requests.LandingAnalysis] = this.WasAirborne && ppt.New.RadioHeight < 500 ? 25 : 500;
this.SampleRates[Requests.LandingAnalysis] = this.WasAirborne && ppt.New.RadioHeight < 200 ? 25 : 500;
this.OnPropertyChanged(nameof(this.SampleRates));

// Was the sim paused/un-paused?
Expand Down
2 changes: 1 addition & 1 deletion OpenSky.Agent/Views/Models/LandingReportViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public LandingReportViewModel()
this.FlightNumberHeader = $"Flight #{this.Simulator.Flight?.FullFlightNumber}\r\nLanding Report";

// Fetch the initial already existing landing report(s)
if (this.Simulator.FinalTouchDownIndex > 0)
if (this.Simulator.FinalTouchDownIndex >= 0)
{
for (var i = this.Simulator.FinalTouchDownIndex; i < this.Simulator.LandingReports.Count; i++)
{
Expand Down

0 comments on commit 361a8c2

Please sign in to comment.