Skip to content

Commit

Permalink
Finished CG slider and alpha5 revive
Browse files Browse the repository at this point in the history
- Updated libraries to fix security issues and bugs
- Added CG slider to advanced weight and balance section
- Fixed w&b section still using simconnect instead of unified sim interface
- New design for aircraft position arrow
- Added update aircraft type, both for adding new updated type and added db upgrade
  panel from client as well
- Fixed departure range bug in flight state code
- Added support for newly cleaned up payload station names
- Support for actualy missing manufacturer instead of dummy one
  • Loading branch information
sushiat committed Nov 21, 2023
1 parent adcdf4b commit 4788925
Show file tree
Hide file tree
Showing 22 changed files with 534 additions and 161 deletions.
4 changes: 2 additions & 2 deletions OpenSky.Agent.SimConnectMSFS/SimConnect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -633,10 +633,10 @@ private void ReadFromSimconnect()

foreach (Requests request in Enum.GetValues(typeof(Requests)))
{
if (this.SampleRates.ContainsKey(request))
if (this.SampleRates.TryGetValue(request, out var rate))
{
var lastTime = this.LastReceivedTimes[request];
if (request != Requests.Primary && (!lastTime.HasValue || (DateTime.UtcNow - lastTime.Value).TotalMilliseconds > this.SampleRates[request]))
if (request != Requests.Primary && (!lastTime.HasValue || (DateTime.UtcNow - lastTime.Value).TotalMilliseconds > rate))
{
this.fsConnect.RequestData(request, request);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,17 +217,17 @@ public bool MatchesAircraftInSimulator()
// Skip these checks if detailed checks are TEMPORARILY disabled
if (!this.DetailedChecksDisabled)
{
if (Math.Abs(OpenSky.Agent.Simulator.Simulator.Instance.WeightAndBalance.EmptyWeight - this.EmptyWeight) > 0.5)
if (Math.Abs(OpenSky.Agent.Simulator.Simulator.Instance.WeightAndBalance.EmptyWeight - this.EmptyWeight) > 0.05 * this.EmptyWeight)
{
return false;
}

if (Math.Abs(OpenSky.Agent.Simulator.Simulator.Instance.WeightAndBalance.FuelTotalCapacity - this.FuelTotalCapacity) > 0.5)
if (Math.Abs(OpenSky.Agent.Simulator.Simulator.Instance.WeightAndBalance.FuelTotalCapacity - this.FuelTotalCapacity) > 0.05 * this.FuelTotalCapacity)
{
return false;
}

if (Math.Abs(OpenSky.Agent.Simulator.Simulator.Instance.WeightAndBalance.MaxGrossWeight - this.MaxGrossWeight) > 0.5)
if (Math.Abs(OpenSky.Agent.Simulator.Simulator.Instance.WeightAndBalance.MaxGrossWeight - this.MaxGrossWeight) > 0.05 * this.MaxGrossWeight)
{
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions OpenSky.Agent.Simulator/Simulator.Flight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public Flight Flight
return;
}

Debug.WriteLine("SimConnect flight changing...");
Debug.WriteLine("Simulator flight changing...");
if (value != null && this.TrackingStatus != TrackingStatus.NotTracking)
{
Debug.WriteLine("Throwing error: You need to abort the current flight before changing to a new one!");
Expand All @@ -211,7 +211,7 @@ public Flight Flight
if (value != null)
{
// Start the ground handling thread for this flight
new Thread(this.DoGroundHandling) { Name = "OpenSky.SimConnect.GroundHandling" }.Start();
new Thread(this.DoGroundHandling) { Name = "OpenSky.Simulator.GroundHandling" }.Start();

// Add airport markers to map (do this in both new and restore, save file doesn't contain these cause the data would just be redundant)
UpdateGUIDelegate addAirports = () =>
Expand Down
12 changes: 6 additions & 6 deletions OpenSky.Agent.Simulator/Simulator.Process.FlightPhases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ private void TransitionFlightPhase()
}

// Departure
if (distanceToDepartureAirport < 10 && this.VerticalProfile == VerticalProfile.Climbing && !this.PrimaryTracking.OnGround)
var approachDepartureDistance = this.AircraftIdentity.EngineType is EngineType.Jet or EngineType.Turboprop ? 40 : 10;
if (distanceToDepartureAirport < approachDepartureDistance && this.VerticalProfile == VerticalProfile.Climbing && !this.PrimaryTracking.OnGround)
{
if (unknownFlightPhase)
{
Expand All @@ -286,8 +287,7 @@ private void TransitionFlightPhase()
}

// Climb
var approachDistance = this.AircraftIdentity.EngineType is EngineType.Jet or EngineType.Turboprop ? 40 : 10;
if (distanceToDepartureAirport >= approachDistance && this.VerticalProfile == VerticalProfile.Climbing && !this.PrimaryTracking.OnGround)
if (distanceToDepartureAirport >= approachDepartureDistance && this.VerticalProfile == VerticalProfile.Climbing && !this.PrimaryTracking.OnGround)
{
if (unknownFlightPhase)
{
Expand All @@ -302,7 +302,7 @@ private void TransitionFlightPhase()
}

// Cruise
if (distanceToDestinationAirport >= approachDistance && distanceToAlternateAirport >= approachDistance && this.VerticalProfile == VerticalProfile.Level && !this.PrimaryTracking.OnGround)
if (distanceToDestinationAirport >= approachDepartureDistance && distanceToAlternateAirport >= approachDepartureDistance && this.VerticalProfile == VerticalProfile.Level && !this.PrimaryTracking.OnGround)
{
if (unknownFlightPhase)
{
Expand All @@ -317,7 +317,7 @@ private void TransitionFlightPhase()
}

// Descent
if (distanceToDestinationAirport >= approachDistance && distanceToAlternateAirport >= approachDistance && this.VerticalProfile == VerticalProfile.Descending && !this.PrimaryTracking.OnGround)
if (distanceToDestinationAirport >= approachDepartureDistance && distanceToAlternateAirport >= approachDepartureDistance && this.VerticalProfile == VerticalProfile.Descending && !this.PrimaryTracking.OnGround)
{
if (unknownFlightPhase)
{
Expand All @@ -332,7 +332,7 @@ private void TransitionFlightPhase()
}

// Approach
if ((distanceToDestinationAirport < approachDistance || distanceToAlternateAirport < approachDistance) && !this.PrimaryTracking.OnGround && this.PrimaryTracking.RadioHeight > 500)
if ((distanceToDestinationAirport < approachDepartureDistance || distanceToAlternateAirport < approachDepartureDistance) && !this.PrimaryTracking.OnGround && this.PrimaryTracking.RadioHeight > 500)
{
if (unknownFlightPhase)
{
Expand Down
5 changes: 4 additions & 1 deletion OpenSky.Agent.Simulator/Simulator.Process.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ private void ProcessLandingAnalysis()
}
}

private DateTime lastLocationUpdate=DateTime.MinValue;

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Process the primary tracking data (old vs new).
Expand All @@ -362,8 +364,9 @@ private void ProcessPrimaryTracking()
this.TrackFlight(ppt);

// Fire the location changed event?
if (!ppt.Old.MapLocation.Equals(ppt.New.MapLocation))
if (!ppt.Old.MapLocation.Equals(ppt.New.MapLocation) || (DateTime.Now-this.lastLocationUpdate).TotalSeconds>5)
{
this.lastLocationUpdate = DateTime.Now;
newLocation = ppt.New.MapLocation;
}

Expand Down
8 changes: 8 additions & 0 deletions OpenSky.Agent.Simulator/Simulator.simBrief.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ public partial class Simulator
/// -------------------------------------------------------------------------------------------------
private bool simbriefOfpLoaded;

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Occurs when simbrief ofp loaded property changed.
/// </summary>
/// -------------------------------------------------------------------------------------------------
public event EventHandler<bool> SimbriefOfpLoadedChanged;

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Occurs when SimConnect adds a new simbrief waypoint marker.
Expand All @@ -64,6 +71,7 @@ private set

this.simbriefOfpLoaded = value;
this.OnPropertyChanged();
this.SimbriefOfpLoadedChanged?.Invoke(this, value);
}
}

Expand Down
4 changes: 2 additions & 2 deletions OpenSky.Agent.UdpXPlane11/UdpXPlane11.cs
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,10 @@ private void ReadFromXPlane()
}
foreach (Requests request in Enum.GetValues(typeof(Requests)))
{
if (this.SampleRates.ContainsKey(request))
if (this.SampleRates.TryGetValue(request, out var rate))
{
var lastTime = this.LastReceivedTimes[request];
if (request != Requests.Primary && (!lastTime.HasValue || (DateTime.UtcNow - lastTime.Value).TotalMilliseconds > this.SampleRates[request]))
if (request != Requests.Primary && (!lastTime.HasValue || (DateTime.UtcNow - lastTime.Value).TotalMilliseconds > rate))
{
if (request == Requests.Secondary)
{
Expand Down
4 changes: 2 additions & 2 deletions OpenSky.Agent/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,13 @@ private static void AppDispatcherUnhandledException(
crashReport += "\r\n\r\n";

Debug.WriteLine(crashReport);
var filePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\OpenSky.Agent.Crash.txt";
var filePath = Environment.ExpandEnvironmentVariables("%localappdata%\\OpenSky\\agent_crash.log");

try
{
File.AppendAllText(filePath, crashReport);
ModernWpf.MessageBox.Show(
e.Exception.Message + "\r\n\r\nPlease check OpenSky.Agent.Crash.txt for details!",
e.Exception.Message + "\r\n\r\nPlease check agent_crash.log for details!",
"Unexpected error!",
MessageBoxButton.OK,
MessageBoxImage.Error);
Expand Down
2 changes: 1 addition & 1 deletion OpenSky.Agent/Controls/FuelTankControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<Rectangle Grid.Row="0" Grid.RowSpan="2" Grid.Column="0" Grid.ColumnSpan="3" Fill="#404040" Stroke="Gray" RadiusX="1.5" RadiusY="1.5" />
<TextBlock Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" VerticalAlignment="Center" Margin="5,0" Text="{Binding ElementName=FuelTank, Path=FuelTankName, Mode=OneWay}" />
<Slider Grid.Row="0" Grid.Column="1" MinWidth="100" Margin="10,5,10,0" TickFrequency="0.5" IsSnapToTickEnabled="True" Value="{Binding ElementName=FuelTank, Path=FuelTankQuantity, Mode=TwoWay}" Maximum="{Binding ElementName=FuelTank, Path=FuelTankCapacity, Mode=OneWay}" />
<TextBox Grid.Row="0" Grid.Column="2" Margin="0,5,5,0" Text="{Binding ElementName=FuelTank, Path=FuelTankQuantity, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Grid.Row="0" Grid.Column="2" Margin="0,5,5,0" Text="{Binding ElementName=FuelTank, Path=FuelTankQuantity, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, StringFormat=N1}" />
<TextBlock Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Margin="0,2,5,5" FontSize="10" HorizontalAlignment="Right" Text="{Binding ElementName=FuelTank, Path=FuelTankInfo, Mode=OneWay}" />
</Grid>
</UserControl>
8 changes: 4 additions & 4 deletions OpenSky.Agent/Controls/FuelTankControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,28 @@ public partial class FuelTankControl
/// The fuel tangent capacity property.
/// </summary>
/// -------------------------------------------------------------------------------------------------
public static readonly DependencyProperty FuelTankCapacityProperty = DependencyProperty.Register("FuelTankCapacity", typeof(double), typeof(FuelTankControl), new UIPropertyMetadata(0.0));
public static readonly DependencyProperty FuelTankCapacityProperty = DependencyProperty.Register(nameof(FuelTankCapacity), typeof(double), typeof(FuelTankControl), new UIPropertyMetadata(0.0));

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// The fuel tank name property.
/// </summary>
/// -------------------------------------------------------------------------------------------------
public static readonly DependencyProperty FuelTankNameProperty = DependencyProperty.Register("FuelTankName", typeof(string), typeof(FuelTankControl), new UIPropertyMetadata("Unknown tank"));
public static readonly DependencyProperty FuelTankNameProperty = DependencyProperty.Register(nameof(FuelTankName), typeof(string), typeof(FuelTankControl), new UIPropertyMetadata("Unknown tank"));

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// The fuel tank info property.
/// </summary>
/// -------------------------------------------------------------------------------------------------
public static readonly DependencyProperty FuelTankInfoProperty = DependencyProperty.Register("FuelTankInfo", typeof(string), typeof(FuelTankControl), new UIPropertyMetadata("??"));
public static readonly DependencyProperty FuelTankInfoProperty = DependencyProperty.Register(nameof(FuelTankInfo), typeof(string), typeof(FuelTankControl), new UIPropertyMetadata("??"));

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// The fuel tank quantity property.
/// </summary>
/// -------------------------------------------------------------------------------------------------
public static readonly DependencyProperty FuelTankQuantityProperty = DependencyProperty.Register("FuelTankQuantity", typeof(double), typeof(FuelTankControl), new UIPropertyMetadata(0.0));
public static readonly DependencyProperty FuelTankQuantityProperty = DependencyProperty.Register(nameof(FuelTankQuantity), typeof(double), typeof(FuelTankControl), new UIPropertyMetadata(0.0));

/// -------------------------------------------------------------------------------------------------
/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion OpenSky.Agent/Controls/PayloadStationControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
</Grid.ColumnDefinitions>
<Rectangle Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Fill="#404040" Stroke="Gray" RadiusX="1.5" RadiusY="1.5" />
<TextBlock Grid.Row="0" Grid.Column="0" VerticalAlignment="Center" TextWrapping="Wrap" Margin="5,0" Text="{Binding ElementName=PayloadStation, Path=PayloadStationName, Mode=OneWay}" />
<TextBox Grid.Row="0" Grid.Column="1" Margin="5" Text="{Binding ElementName=PayloadStation, Path=PayloadStationWeight, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Grid.Row="0" Grid.Column="1" Margin="5" Text="{Binding ElementName=PayloadStation, Path=PayloadStationWeight, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, StringFormat=N0}" />
</Grid>
</UserControl>
8 changes: 4 additions & 4 deletions OpenSky.Agent/Controls/PayloadStationControl.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ public partial class PayloadStationControl
/// The payload station name property.
/// </summary>
/// -------------------------------------------------------------------------------------------------
public static readonly DependencyProperty PayloadStationNameProperty = DependencyProperty.Register("PayloadStationName", typeof(string), typeof(PayloadStationControl), new UIPropertyMetadata("Unknown"));
public static readonly DependencyProperty PayloadStationNameProperty = DependencyProperty.Register(nameof(PayloadStationName), typeof(string), typeof(PayloadStationControl), new UIPropertyMetadata("Unknown"));

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// The payload station weight property.
/// </summary>
/// -------------------------------------------------------------------------------------------------
public static readonly DependencyProperty PayloadStationWeightProperty = DependencyProperty.Register("PayloadStationWeight", typeof(double), typeof(PayloadStationControl), new UIPropertyMetadata(0.0));
public static readonly DependencyProperty PayloadStationWeightProperty = DependencyProperty.Register(nameof(PayloadStationWeight), typeof(double), typeof(PayloadStationControl), new UIPropertyMetadata(0.0));

/// -------------------------------------------------------------------------------------------------
/// <summary>
Expand Down Expand Up @@ -61,9 +61,9 @@ public string PayloadStationName
/// </summary>
/// -------------------------------------------------------------------------------------------------
[Bindable(true)]
public string PayloadStationWeight
public double PayloadStationWeight
{
get => (string)this.GetValue(PayloadStationWeightProperty);
get => (double)this.GetValue(PayloadStationWeightProperty);
set => this.SetValue(PayloadStationWeightProperty, value);
}
}
Expand Down
1 change: 1 addition & 0 deletions OpenSky.Agent/Native/PInvoke/Structs/Rect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public struct Rect : IEquatable<Rect>
/// Empty Rect structure.
/// </summary>
/// -------------------------------------------------------------------------------------------------
// ReSharper disable once UnassignedReadonlyField
public static readonly Rect Empty;

/// -------------------------------------------------------------------------------------------------
Expand Down
20 changes: 10 additions & 10 deletions OpenSky.Agent/OpenSky.Agent.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -365,19 +365,19 @@
<Version>2.5.13</Version>
</PackageReference>
<PackageReference Include="DiscordRichPresence">
<Version>1.0.175</Version>
<Version>1.2.1.24</Version>
</PackageReference>
<PackageReference Include="Hardcodet.NotifyIcon.Wpf">
<Version>1.1.0</Version>
</PackageReference>
<PackageReference Include="JetBrains.Annotations">
<Version>2022.1.0</Version>
<Version>2023.3.0</Version>
</PackageReference>
<PackageReference Include="MdXaml">
<Version>1.13.0</Version>
<Version>1.21.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers">
<Version>6.0.0</Version>
<Version>8.0.0</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand All @@ -388,28 +388,28 @@
<Version>0.5.2</Version>
</PackageReference>
<PackageReference Include="ModernWpfUI">
<Version>0.9.4</Version>
<Version>0.9.6</Version>
</PackageReference>
<PackageReference Include="MSFT.ParallelExtensionsExtras">
<Version>1.2.0</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>13.0.1</Version>
<Version>13.0.3</Version>
</PackageReference>
<PackageReference Include="OpenSky.FlightLogXML">
<Version>0.1.6</Version>
</PackageReference>
<PackageReference Include="Syncfusion.SfChart.WPF">
<Version>20.1.0.52</Version>
<Version>23.1.44</Version>
</PackageReference>
<PackageReference Include="Syncfusion.SfProgressBar.WPF">
<Version>20.1.0.52</Version>
<Version>23.1.44</Version>
</PackageReference>
<PackageReference Include="Syncfusion.Themes.MaterialDark.WPF">
<Version>20.1.0.52</Version>
<Version>23.1.44</Version>
</PackageReference>
<PackageReference Include="TomsToolbox.Wpf">
<Version>2.7.6</Version>
<Version>2.10.0</Version>
</PackageReference>
<PackageReference Include="XDMessaging.Lite">
<Version>5.0.6</Version>
Expand Down
Loading

0 comments on commit 4788925

Please sign in to comment.