Skip to content

Commit

Permalink
Merge pull request #51 from opensky-to/agent-xp11-experiment
Browse files Browse the repository at this point in the history
Agent xp11 experiment
  • Loading branch information
sushiat authored Feb 11, 2022
2 parents ca66332 + 388aea2 commit 39ad6d9
Show file tree
Hide file tree
Showing 36 changed files with 2,686 additions and 168 deletions.
32 changes: 16 additions & 16 deletions OpenSky.Agent.SimConnectMSFS/SimConnect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ namespace OpenSky.Agent.SimConnectMSFS

using OpenSkyApi;

using AircraftIdentity = OpenSky.Agent.SimConnectMSFS.Structs.AircraftIdentity;
using FuelTanks = OpenSky.Agent.SimConnectMSFS.Structs.FuelTanks;
using LandingAnalysis = OpenSky.Agent.SimConnectMSFS.Structs.LandingAnalysis;
using PayloadStations = OpenSky.Agent.SimConnectMSFS.Structs.PayloadStations;
using PrimaryTracking = OpenSky.Agent.SimConnectMSFS.Structs.PrimaryTracking;
using SecondaryTracking = OpenSky.Agent.SimConnectMSFS.Structs.SecondaryTracking;
using Simulator = OpenSky.Agent.Simulator.Simulator;
using SlewAircraftIntoPosition = OpenSky.Agent.SimConnectMSFS.Structs.SlewAircraftIntoPosition;
using WeightAndBalance = OpenSky.Agent.SimConnectMSFS.Structs.WeightAndBalance;
using AircraftIdentity = Structs.AircraftIdentity;
using FuelTanks = Structs.FuelTanks;
using LandingAnalysis = Structs.LandingAnalysis;
using PayloadStations = Structs.PayloadStations;
using PrimaryTracking = Structs.PrimaryTracking;
using SecondaryTracking = Structs.SecondaryTracking;
using Simulator = Simulator.Simulator;
using SlewAircraftIntoPosition = Structs.SlewAircraftIntoPosition;
using WeightAndBalance = Structs.WeightAndBalance;

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Simconnect client.
/// Simconnect client for Microsoft Flight Simulator 2020.
/// </summary>
/// <remarks>
/// sushi.at, 13/03/2021.
Expand Down Expand Up @@ -174,7 +174,7 @@ public override void SetAircraftRegistry(string registry)
if (this.fsConnect.Connected)
{
var planeRegistry = new PlaneRegistry { AtcID = registry };
this.fsConnect.UpdateData(Requests.PlaneRegistry, planeRegistry);
this.fsConnect.UpdateData(Requests.AircraftRegistry, planeRegistry);
}
else
{
Expand Down Expand Up @@ -527,10 +527,10 @@ private void FsDataReceived(object sender, FsDataReceivedEventArgs e)
this.LastReceivedTimes[Requests.PayloadStations] = DateTime.UtcNow;
}

if (simConnectObject is AircraftIdentity isPlaneIdentity)
if (simConnectObject is AircraftIdentity isAircraftIdentity)
{
this.AircraftIdentity = isPlaneIdentity.Convert();
this.LastReceivedTimes[Requests.PlaneIdentity] = DateTime.UtcNow;
this.AircraftIdentity = isAircraftIdentity.Convert();
this.LastReceivedTimes[Requests.AircraftIdentity] = DateTime.UtcNow;
new Thread(this.ProcessAircraftIdentity) { Name = "OpenSky.ProcessAircraftIdentity" }.Start();
}

Expand Down Expand Up @@ -591,11 +591,11 @@ private void ReadFromSimconnect()
this.fsConnect.RegisterDataDefinition<SecondaryTracking>(Requests.Secondary, SecondaryTrackingDefinition.Definition);
this.fsConnect.RegisterDataDefinition<FuelTanks>(Requests.FuelTanks, FuelTanksDefinition.Definition);
this.fsConnect.RegisterDataDefinition<PayloadStations>(Requests.PayloadStations, PayloadStationsDefinition.Definition);
this.fsConnect.RegisterDataDefinition<AircraftIdentity>(Requests.PlaneIdentity, AircraftIdentityDefinition.Definition);
this.fsConnect.RegisterDataDefinition<AircraftIdentity>(Requests.AircraftIdentity, AircraftIdentityDefinition.Definition);
this.fsConnect.RegisterDataDefinition<WeightAndBalance>(Requests.WeightAndBalance, WeightAndBalanceDefinition.Definition);
this.fsConnect.RegisterDataDefinition<LandingAnalysis>(Requests.LandingAnalysis, LandingAnalysisDefinition.Definition);
this.fsConnect.RegisterDataDefinition<SlewAircraftIntoPosition>(Requests.SlewPlaneIntoPosition, SlewAircraftIntoPositionDefinition.Definition);
this.fsConnect.RegisterDataDefinition<PlaneRegistry>(Requests.PlaneRegistry, PlaneRegistryDefinition.Definition);
this.fsConnect.RegisterDataDefinition<PlaneRegistry>(Requests.AircraftRegistry, PlaneRegistryDefinition.Definition);

// Register client events
this.fsConnect.MapClientEventToSimEvent(ClientEvents.SetTime, ClientEvents.SetZuluYears, "ZULU_YEAR_SET");
Expand Down
4 changes: 2 additions & 2 deletions OpenSky.Agent.SimConnectMSFS/Structs/PayloadStations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public static Simulator.Models.PayloadStations Convert(this PayloadStations stat
Weight17 = stations.Weight17,
Weight18 = stations.Weight18,
Weight19 = stations.Weight19,
Weight20 = stations.Weight20,
Weight20 = stations.Weight20
};
}

Expand Down Expand Up @@ -464,7 +464,7 @@ public static PayloadStations ConvertBack(this Simulator.Models.PayloadStations
Weight17 = stations.Weight17,
Weight18 = stations.Weight18,
Weight19 = stations.Weight19,
Weight20 = stations.Weight20,
Weight20 = stations.Weight20
};
}
}
Expand Down
10 changes: 10 additions & 0 deletions OpenSky.Agent.SimConnectMSFS/Structs/SlewAircraftIntoPosition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ public struct SlewAircraftIntoPosition
/// -------------------------------------------------------------------------------------------------
public double Longitude { get; set; }

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// The altitude in feet.
/// </summary>
/// -------------------------------------------------------------------------------------------------
public double Altitude { get; set; }

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// The radio height in feet.
Expand Down Expand Up @@ -118,6 +125,7 @@ public static Agent.Simulator.Models.SlewAircraftIntoPosition Convert(this SlewA
{
Latitude = position.Latitude,
Longitude = position.Longitude,
Altitude = position.Altitude,
RadioHeight = position.RadioHeight,
Heading = position.Heading,
AirspeedTrue = position.AirspeedTrue,
Expand Down Expand Up @@ -148,6 +156,7 @@ public static SlewAircraftIntoPosition ConvertBack(this Agent.Simulator.Models.S
{
Latitude = position.Latitude,
Longitude = position.Longitude,
Altitude = position.Altitude,
RadioHeight = position.RadioHeight,
Heading = position.Heading,
AirspeedTrue = position.AirspeedTrue,
Expand Down Expand Up @@ -179,6 +188,7 @@ public static class SlewAircraftIntoPositionDefinition
{
new SimVar("PLANE LATITUDE", "Degrees", SIMCONNECT_DATATYPE.FLOAT64),
new SimVar("PLANE LONGITUDE", "Degrees", SIMCONNECT_DATATYPE.FLOAT64),
new SimVar("PLANE ALTITUDE", "Feet", SIMCONNECT_DATATYPE.FLOAT64),
new SimVar("PLANE ALT ABOVE GROUND", "Feet", SIMCONNECT_DATATYPE.FLOAT64),
new SimVar("PLANE HEADING DEGREES MAGNETIC", "Degrees", SIMCONNECT_DATATYPE.FLOAT64),
new SimVar("AIRSPEED TRUE", "Knots", SIMCONNECT_DATATYPE.FLOAT64),
Expand Down
8 changes: 4 additions & 4 deletions OpenSky.Agent.Simulator/Enums/Requests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public enum Requests : uint
PayloadStations = 3,

/// <summary>
/// Plane identity request
/// Aircraft identity request
/// </summary>
PlaneIdentity = 4,
AircraftIdentity = 4,

/// <summary>
/// Weight and balance request
Expand All @@ -60,8 +60,8 @@ public enum Requests : uint
SlewPlaneIntoPosition = 7,

/// <summary>
/// Plane registry request
/// Aircraft registry request
/// </summary>
PlaneRegistry = 8
AircraftRegistry = 8
}
}
26 changes: 26 additions & 0 deletions OpenSky.Agent.Simulator/Models/FuelTanks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,32 @@ public double TotalQuantity
}
}

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Updates the capacities from a modified dictionary.
/// </summary>
/// <remarks>
/// sushi.at, 10/02/2022.
/// </remarks>
/// <param name="modifiedDictionary">
/// The modified dictionary containing the new capacity values.
/// </param>
/// -------------------------------------------------------------------------------------------------
public void UpdateCapactiesFromDictionary(Dictionary<FuelTank, double> modifiedDictionary)
{
this.FuelTankCenterCapacity = modifiedDictionary[FuelTank.Center];
this.FuelTankCenter2Capacity = modifiedDictionary[FuelTank.Center2];
this.FuelTankCenter3Capacity = modifiedDictionary[FuelTank.Center3];
this.FuelTankLeftMainCapacity = modifiedDictionary[FuelTank.LeftMain];
this.FuelTankLeftAuxCapacity = modifiedDictionary[FuelTank.LeftAux];
this.FuelTankLeftTipCapacity = modifiedDictionary[FuelTank.LeftTip];
this.FuelTankRightMainCapacity = modifiedDictionary[FuelTank.RightMain];
this.FuelTankRightAuxCapacity = modifiedDictionary[FuelTank.RightAux];
this.FuelTankRightTipCapacity = modifiedDictionary[FuelTank.RightTip];
this.FuelTankExternal1Capacity = modifiedDictionary[FuelTank.External1];
this.FuelTankExternal2Capacity = modifiedDictionary[FuelTank.External2];
}

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Updates the quantities from a modified dictionary.
Expand Down
8 changes: 8 additions & 0 deletions OpenSky.Agent.Simulator/Models/SlewAircraftIntoPosition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ public class SlewAircraftIntoPosition
/// -------------------------------------------------------------------------------------------------
public double AirspeedTrue { get; set; }

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// Gets or sets the altitude.
/// </summary>
/// -------------------------------------------------------------------------------------------------
public double Altitude { get; set; }

/// -------------------------------------------------------------------------------------------------
/// <summary>
/// The bank angle in degrees.
Expand Down Expand Up @@ -109,6 +116,7 @@ public static SlewAircraftIntoPosition FromPrimaryTracking(PrimaryTracking prima
Latitude = primary.Latitude,
Longitude = primary.Longitude,
RadioHeight = primary.RadioHeight,
Altitude = primary.Altitude,
Heading = primary.Heading,
AirspeedTrue = primary.AirspeedTrue,
PitchAngle = primary.PitchAngle,
Expand Down
1 change: 1 addition & 0 deletions OpenSky.Agent.Simulator/OpenSky.Agent.Simulator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
<Compile Include="Simulator.SaveLoadXML.cs" />
<Compile Include="Simulator.simBrief.cs" />
<Compile Include="SpeechSoundPacks.cs" />
<Compile Include="Tools\AircraftRegistryExtensions.cs" />
<Compile Include="Tools\ColorExtensions.cs" />
<Compile Include="Tools\SleepScheduler.cs" />
<Compile Include="Tools\StringEnumExtension.cs" />
Expand Down
17 changes: 9 additions & 8 deletions OpenSky.Agent.Simulator/Simulator.Flight.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace OpenSky.Agent.Simulator
using OpenSkyApi;

using PositionReport = OpenSkyApi.PositionReport;
using TrackingEventMarker = OpenSky.Agent.Simulator.Models.TrackingEventMarker;
using TrackingEventMarker = Models.TrackingEventMarker;

/// -------------------------------------------------------------------------------------------------
/// <content>
Expand Down Expand Up @@ -261,13 +261,13 @@ public Flight Flight
}
};

this.TrackingConditions[(int)Agent.Simulator.Models.TrackingConditions.Fuel].Expected =
this.TrackingConditions[(int)Models.TrackingConditions.Fuel].Expected =
$"{value.FuelGallons:F1} gal, {value.FuelGallons * 3.78541:F1} liters ▶ {value.FuelGallons * value.Aircraft.Type.FuelWeightPerGallon:F1} lbs, {value.FuelGallons * value.Aircraft.Type.FuelWeightPerGallon * 0.453592:F1} kg";
this.TrackingConditions[(int)Agent.Simulator.Models.TrackingConditions.Payload].Expected = $"{value.PayloadPounds:F1} lbs, {value.PayloadPounds * 0.453592:F1} kg";
this.TrackingConditions[(int)Agent.Simulator.Models.TrackingConditions.PlaneModel].Expected = $"{value.Aircraft.Type.Name} (v{value.Aircraft.Type.VersionNumber})";
this.TrackingConditions[(int)Models.TrackingConditions.Payload].Expected = $"{value.PayloadPounds:F1} lbs, {value.PayloadPounds * 0.453592:F1} kg";
this.TrackingConditions[(int)Models.TrackingConditions.PlaneModel].Expected = $"{value.Aircraft.Type.Name} (v{value.Aircraft.Type.VersionNumber})";

this.TrackingConditions[(int)Agent.Simulator.Models.TrackingConditions.Fuel].AutoSet = !value.Aircraft.Type.RequiresManualFuelling;
this.TrackingConditions[(int)Agent.Simulator.Models.TrackingConditions.Payload].AutoSet = !value.Aircraft.Type.RequiresManualLoading;
this.TrackingConditions[(int)Models.TrackingConditions.Fuel].AutoSet = !value.Aircraft.Type.RequiresManualFuelling;
this.TrackingConditions[(int)Models.TrackingConditions.Payload].AutoSet = !value.Aircraft.Type.RequiresManualLoading;

if (!value.Resume)
{
Expand Down Expand Up @@ -332,12 +332,13 @@ public Flight Flight
PitchAngle = value.PitchAngle,
OnGround = value.OnGround,
AirspeedTrue = value.AirspeedTrue ?? 0,
Altitude = value.Altitude ?? 0,
RadioHeight = value.RadioHeight ?? 0,
VerticalSpeedSeconds = value.VerticalSpeedSeconds
}
};

this.TrackingConditions[(int)Agent.Simulator.Models.TrackingConditions.Fuel].Expected =
this.TrackingConditions[(int)Models.TrackingConditions.Fuel].Expected =
$"{this.flightLoadingTempModels.FuelTanks.TotalQuantity:F1} gal, {this.flightLoadingTempModels.FuelTanks.TotalQuantity * 3.78541:F1} liters ▶ {this.flightLoadingTempModels.FuelTanks.TotalQuantity * value.Aircraft.Type.FuelWeightPerGallon:F1} lbs, {this.flightLoadingTempModels.FuelTanks.TotalQuantity * value.Aircraft.Type.FuelWeightPerGallon * 0.453592:F1} kg";
}
}
Expand Down Expand Up @@ -531,7 +532,7 @@ public void StopTracking(bool resumeLater)
this.TrackingConditions[(int)condition].Reset();
}

this.TrackingConditions[(int)Agent.Simulator.Models.TrackingConditions.RealismSettings].Expected = "No slew, No unlimited fuel,\r\nCrash detection, SimRate=1";
this.TrackingConditions[(int)Models.TrackingConditions.RealismSettings].Expected = "No slew, No unlimited fuel,\r\nCrash detection, SimRate=0 or 1";
}

if (!resumeLater)
Expand Down
2 changes: 1 addition & 1 deletion OpenSky.Agent.Simulator/Simulator.Process.FlightPhases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private void TransitionFlightPhase()
var player = new SoundPlayer(assembly.GetManifestResourceStream("OpenSky.Agent.Resources.OSnegative.wav"));
player.Play();
SpeechSoundPacks.Instance.PlaySpeechEvent(SpeechEvent.AbortedSimMainMenu);
this.StopTracking(false);
this.StopTracking(true);
}
}

Expand Down
12 changes: 6 additions & 6 deletions OpenSky.Agent.Simulator/Simulator.Process.Systems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private void MonitorPrimarySystems(ProcessPrimaryTracking ppt)
var player = new SoundPlayer(assembly.GetManifestResourceStream("OpenSky.Agent.Resources.OSnegative.wav"));
player.Play();
SpeechSoundPacks.Instance.PlaySpeechEvent(SpeechEvent.AbortedSlew);
this.StopTracking(false);
this.StopTracking(true);
}

// Teleport to another position?
Expand All @@ -119,7 +119,7 @@ private void MonitorPrimarySystems(ProcessPrimaryTracking ppt)
var player = new SoundPlayer(assembly.GetManifestResourceStream("OpenSky.Agent.Resources.OSnegative.wav"));
player.Play();
SpeechSoundPacks.Instance.PlaySpeechEvent(SpeechEvent.AbortedTeleport);
this.StopTracking(false);
this.StopTracking(true);
}
}
}
Expand Down Expand Up @@ -154,7 +154,7 @@ private void MonitorSecondarySystems(ProcessSecondaryTracking pst)
var player = new SoundPlayer(assembly.GetManifestResourceStream("OpenSky.Agent.Resources.OSnegative.wav"));
player.PlaySync();
SpeechSoundPacks.Instance.PlaySpeechEvent(SpeechEvent.AbortedEnginesGroundHandling);
this.StopTracking(false);
this.StopTracking(true);
}

// Was the beacon light off when the engine was started?
Expand Down Expand Up @@ -231,7 +231,7 @@ private void MonitorSecondarySystems(ProcessSecondaryTracking pst)
var player = new SoundPlayer(assembly.GetManifestResourceStream("OpenSky.Agent.Resources.OSnegative.wav"));
player.PlaySync();
SpeechSoundPacks.Instance.PlaySpeechEvent(SpeechEvent.AbortedPushbackGroundHandling);
this.StopTracking(false);
this.StopTracking(true);
}

// Pushback start?
Expand Down Expand Up @@ -345,7 +345,7 @@ private void MonitorSecondarySystems(ProcessSecondaryTracking pst)
var player = new SoundPlayer(assembly.GetManifestResourceStream("OpenSky.Agent.Resources.OSnegative.wav"));
player.PlaySync();
SpeechSoundPacks.Instance.PlaySpeechEvent(SpeechEvent.AbortedTimeBackwards);
this.StopTracking(false);
this.StopTracking(true);
}

if (timeDelta.TotalSeconds > 30)
Expand All @@ -355,7 +355,7 @@ private void MonitorSecondarySystems(ProcessSecondaryTracking pst)
var player = new SoundPlayer(assembly.GetManifestResourceStream("OpenSky.Agent.Resources.OSnegative.wav"));
player.PlaySync();
SpeechSoundPacks.Instance.PlaySpeechEvent(SpeechEvent.AbortedTimeChanged);
this.StopTracking(false);
this.StopTracking(true);
}
}
}
Expand Down
Loading

0 comments on commit 39ad6d9

Please sign in to comment.