Skip to content

Commit

Permalink
Merge pull request #77 from #76-xplane-engine-type
Browse files Browse the repository at this point in the history
Agent#76 xplane engine type
  • Loading branch information
sushiat authored Nov 24, 2023
2 parents 558ebf1 + 5cb9d8f commit ba907a0
Show file tree
Hide file tree
Showing 15 changed files with 208 additions and 86 deletions.
6 changes: 3 additions & 3 deletions OpenSky.Agent.SimConnectMSFS/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("OpenSky")]
[assembly: AssemblyProduct("OpenSky")]
[assembly: AssemblyCopyright("OpenSky project 2021-2022")]
[assembly: AssemblyCopyright("OpenSky project 2021-2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("1f9cbede-669d-4510-bca2-e6ad29d6a498")]
[assembly: AssemblyVersion("0.5.0")]
[assembly: AssemblyFileVersion("0.5.0")]
[assembly: AssemblyVersion("0.5.4")]
[assembly: AssemblyFileVersion("0.5.4")]
6 changes: 3 additions & 3 deletions OpenSky.Agent.Simulator/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("OpenSky")]
[assembly: AssemblyProduct("OpenSky")]
[assembly: AssemblyCopyright("OpenSky project 2021-2022")]
[assembly: AssemblyCopyright("OpenSky project 2021-2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("30c467e8-2eee-41e5-be01-0142a61ba171")]
[assembly: AssemblyVersion("0.5.0")]
[assembly: AssemblyFileVersion("0.5.0")]
[assembly: AssemblyVersion("0.5.4")]
[assembly: AssemblyFileVersion("0.5.4")]
2 changes: 1 addition & 1 deletion OpenSky.Agent.Simulator/Simulator.SaveLoadXML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private XElement GenerateSaveFile()
{
Agent = AgentIdentifier,
AgentVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(),
OpenSkyUser = "TODO", //UserSessionService.Instance.Username, TODO restore/workaround
OpenSkyUser = this.OpenSkyUserName ?? "Unknown",
LocalTimeZone = TimeZoneInfo.Local.BaseUtcOffset.TotalHours,
TrackingStarted = this.trackingStarted ?? DateTime.MinValue,
TrackingStopped = DateTime.UtcNow,
Expand Down
7 changes: 7 additions & 0 deletions OpenSky.Agent.Simulator/Simulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ protected set
}
}

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Gets or sets the OpenSky user name - let's the simulator interface know which user is logged in.
/// </summary>
/// -------------------------------------------------------------------------------------------------
public string OpenSkyUserName { get; set; }

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Gets the type of the simulator.
Expand Down
131 changes: 131 additions & 0 deletions OpenSky.Agent.UdpXPlane11/EngineType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="FuelWeightHelper.cs" company="OpenSky">
// OpenSky project 2021-2023
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace OpenSky.Agent.UdpXPlane11
{
/// -------------------------------------------------------------------------------------------------
/// <summary>
/// XPlane engine type.
/// </summary>
/// <remarks>
/// sushi.at, 24/11/2023.
/// </remarks>
/// -------------------------------------------------------------------------------------------------
public static class EngineType
{
/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Gets fuel weight for engine type.
/// </summary>
/// <remarks>
/// sushi.at, 24/11/2023.
/// </remarks>
/// <param name="engineType">
/// Type of the engine.
/// </param>
/// <returns>
/// The fuel weight in lbs per gallon.
/// </returns>
/// -------------------------------------------------------------------------------------------------
public static double GetFuelWeightForEngineType(int engineType)
{
return engineType switch
{
// Reciprocating carburetor
0 => 6,

// Reciprocating injected
1 => 6,

// Free turbo deprecated
2 => 6.7,

// Electric engine
3 => 0,

// Lo Bypass Jet deprecated
4 => 6.7,

// Single spool jet
5 => 6.7,

// Rocket
6 => 0,

// Multi spool jet
7 => 6.7,

// Turbo Prop Fixed deprecated
8 => 6.7,

// Free turbo prop
9 => 6.7,

// Fixed turbo prop
10 => 6.7,

// Unknown engine type
_ => 0
};
}

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Convert engine type to OpenSky enum.
/// </summary>
/// <remarks>
/// sushi.at, 24/11/2023.
/// </remarks>
/// <param name="engineType">
/// Type of the engine from xplane.
/// </param>
/// <returns>
/// The engine type converted to OpenSky.
/// </returns>
/// -------------------------------------------------------------------------------------------------
public static OpenSkyApi.EngineType ConvertEngineType(int engineType)
{
return engineType switch
{
// Reciprocating carburetor
0 => OpenSkyApi.EngineType.Piston,

// Reciprocating injected
1 => OpenSkyApi.EngineType.Piston,

// Free turbo deprecated
2 => OpenSkyApi.EngineType.Turboprop,

// Electric engine
3 => OpenSkyApi.EngineType.Unsupported,

// Lo Bypass Jet deprecated
4 => OpenSkyApi.EngineType.Jet,

// Single spool jet
5 => OpenSkyApi.EngineType.Jet,

// Rocket
6 => OpenSkyApi.EngineType.Unsupported,

// Multi spool jet
7 => OpenSkyApi.EngineType.Jet,

// Turbo Prop Fixed deprecated
8 => OpenSkyApi.EngineType.Turboprop,

// Free turbo prop
9 => OpenSkyApi.EngineType.Turboprop,

// Fixed turbo prop
10 => OpenSkyApi.EngineType.Turboprop,

// Unknown engine type
_ => OpenSkyApi.EngineType.None
};
}
}
}
16 changes: 1 addition & 15 deletions OpenSky.Agent.UdpXPlane11/Models/AircraftIdentityDataRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

namespace OpenSky.Agent.UdpXPlane11.Models
{
using OpenSkyApi;

using XPlaneConnector;
using XPlaneConnector.DataRefs;

Expand Down Expand Up @@ -162,19 +160,7 @@ private void DataRefUpdated(DataRefElement element, float value)

if (element.DataRef.StartsWith(DataRefs.AircraftPropAcfEnType.DataRef))
{
this.EngineType = (int)value switch
{
0 => EngineType.Piston,
1 => EngineType.Piston,
2 => EngineType.Turboprop,
3 => EngineType.Unsupported, // Electric engine
4 => EngineType.Jet,
5 => EngineType.Jet,
6 => EngineType.Unsupported, // Rocket
7 => EngineType.Unsupported, // Tip rockets
8 => EngineType.Turboprop,
_ => EngineType.None
};
this.EngineType = Agent.UdpXPlane11.EngineType.ConvertEngineType((int)value);
}

if (element.DataRef == DataRefs.AircraftGearAcfGearRetract.DataRef)
Expand Down
14 changes: 1 addition & 13 deletions OpenSky.Agent.UdpXPlane11/Models/FuelTanksDataRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,7 @@ private void DataRefUpdated(DataRefElement element, float value)

if (element.DataRef.StartsWith(DataRefs.AircraftPropAcfEnType.DataRef))
{
this.fuelWeight = (int)value switch
{
0 => 6,
1 => 6,
2 => 6.7,
3 => 0, // Electric engine
4 => 6.7,
5 => 6.7,
6 => 0, // Rocket
7 => 0, // Tip rockets
8 => 6.7,
_ => 0
};
this.fuelWeight = EngineType.GetFuelWeightForEngineType((int)value);
updateCapacities = true;
updateQuantities = true;
}
Expand Down
16 changes: 1 addition & 15 deletions OpenSky.Agent.UdpXPlane11/Models/WeightAndBalanceDataRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,7 @@ private void DataRefUpdated(DataRefElement element, float value)

if (element.DataRef.StartsWith(DataRefs.AircraftPropAcfEnType.DataRef))
{
this.FuelWeightPerGallon = (int)value switch
{
0 => 6, // Recip carb
1 => 6, // Recip injected
2 => 6.7, // Free turbo deprecated
3 => 0, // Electric engine
4 => 6.7, // Lo Bypass Jet deprecated
5 => 6.7, // Single spool jet
6 => 0, // Rocket
7 => 6.7, // Multi spool jet
8 => 6.7, // Turbo Prop Fixed deprecated
9 => 6.7, // Free turbo prop
10 => 6.7, // Fixed turbo prop
_ => 0
};
this.FuelWeightPerGallon = EngineType.GetFuelWeightForEngineType((int)value);
updateFuelValues = true;
}

Expand Down
1 change: 1 addition & 0 deletions OpenSky.Agent.UdpXPlane11/OpenSky.Agent.UdpXPlane11.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="EngineType.cs" />
<Compile Include="Models\AircraftIdentityDataRef.cs" />
<Compile Include="Models\FuelTanksDataRef.cs" />
<Compile Include="Models\LandingAnalysisDataRef.cs" />
Expand Down
6 changes: 3 additions & 3 deletions OpenSky.Agent.UdpXPlane11/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("OpenSky")]
[assembly: AssemblyProduct("OpenSky")]
[assembly: AssemblyCopyright("OpenSky project 2021-2022")]
[assembly: AssemblyCopyright("OpenSky project 2021-2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("dfbda2b8-5775-4766-be86-d729fcf20de1")]
[assembly: AssemblyVersion("0.5.0")]
[assembly: AssemblyFileVersion("0.5.0")]
[assembly: AssemblyVersion("0.5.4")]
[assembly: AssemblyFileVersion("0.5.4")]
4 changes: 2 additions & 2 deletions OpenSky.Agent/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: ThemeInfo(ResourceDictionaryLocation.None, ResourceDictionaryLocation.SourceAssembly)]
[assembly: AssemblyVersion("0.5.3")]
[assembly: AssemblyFileVersion("0.5.3")]
[assembly: AssemblyVersion("0.5.4")]
[assembly: AssemblyFileVersion("0.5.4")]

// This allows us to detect debug mode in XAML
#if DEBUG
Expand Down
8 changes: 4 additions & 4 deletions OpenSky.Agent/Views/AircraftTypes.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -423,8 +423,8 @@
<TextBlock Grid.Column="0" Grid.Row="24" VerticalAlignment="Center" Margin="0,0,5,0">Minimum runway<LineBreak/>length in feet</TextBlock>
<TextBlock Grid.Column="0" Grid.Row="25" VerticalAlignment="Center" Margin="0,0,5,0">Is variant of</TextBlock>
<TextBlock Grid.Column="0" Grid.Row="26" VerticalAlignment="Center" Margin="0,0,5,0">Next version</TextBlock>
<TextBlock Grid.Column="0" Grid.Row="27" VerticalAlignment="Center" Margin="0,0,5,0">Minimum price</TextBlock>
<TextBlock Grid.Column="0" Grid.Row="28" VerticalAlignment="Center" Margin="0,0,5,0">Maximum price</TextBlock>
<TextBlock Grid.Column="0" Grid.Row="27" VerticalAlignment="Center" Margin="0,0,5,0">Minimum price<LineBreak/>~50% of list</TextBlock>
<TextBlock Grid.Column="0" Grid.Row="28" VerticalAlignment="Center" Margin="0,0,5,0">Maximum price<LineBreak/>~110% of list</TextBlock>
<TextBlock Grid.Column="0" Grid.Row="29" VerticalAlignment="Center" Margin="0,0,5,0">Max payload Δ lbs</TextBlock>
<TextBlock Grid.Column="0" Grid.Row="30" VerticalAlignment="Center" Margin="0,0,5,0">Comments</TextBlock>

Expand Down Expand Up @@ -561,8 +561,8 @@
<TextBlock Grid.Column="0" Grid.Row="24" VerticalAlignment="Center" Margin="0,0,5,0">Manual loading?</TextBlock>
<TextBlock Grid.Column="0" Grid.Row="25" VerticalAlignment="Center" Margin="0,0,5,0">Minimum runway<LineBreak />length in feet</TextBlock>
<TextBlock Grid.Column="0" Grid.Row="26" VerticalAlignment="Center" Margin="0,0,5,0">Is variant of</TextBlock>
<TextBlock Grid.Column="0" Grid.Row="27" VerticalAlignment="Center" Margin="0,0,5,0">Minimum price</TextBlock>
<TextBlock Grid.Column="0" Grid.Row="28" VerticalAlignment="Center" Margin="0,0,5,0">Maximum price</TextBlock>
<TextBlock Grid.Column="0" Grid.Row="27" VerticalAlignment="Center" Margin="0,0,5,0">Minimum price<LineBreak/>~50% of list</TextBlock>
<TextBlock Grid.Column="0" Grid.Row="28" VerticalAlignment="Center" Margin="0,0,5,0">Maximum price<LineBreak/>~110% of list</TextBlock>
<TextBlock Grid.Column="0" Grid.Row="29" VerticalAlignment="Center" Margin="0,0,5,0">Max payload Δ lbs</TextBlock>
<TextBlock Grid.Column="0" Grid.Row="30" VerticalAlignment="Center" Margin="0,0,5,0">Comments</TextBlock>

Expand Down
1 change: 1 addition & 0 deletions OpenSky.Agent/Views/Models/AircraftTypesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,7 @@ private void CancelAddAircraft()
this.MinimumRunwayLength = 0;
this.Comments = null;
this.OverrideFuelType = FuelType.NotUsed;
this.EngineModel = null;

this.aircraftTypeBeingUpdated = null;
}
Expand Down
Loading

0 comments on commit ba907a0

Please sign in to comment.