Skip to content

Commit

Permalink
Updated beacon and gear change logic one more
Browse files Browse the repository at this point in the history
  • Loading branch information
sushiat committed Dec 3, 2023
1 parent 92f6d4d commit 4a63fde
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/discord-release-msg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
color: "1711650"
username: "Agent Release Changelog"
avatar_url: "https://cdn.discordapp.com/icons/837475420923756544/941238cca4a5e355f16a9d710b423c0e.webp?size=96"
content: "||@progress ping||"
content: "||@progress_ping||"
footer_title: "Changelog"
footer_icon_url: "https://cdn.discordapp.com/icons/837475420923756544/941238cca4a5e355f16a9d710b423c0e.webp?size=96"
footer_timestamp: true
25 changes: 17 additions & 8 deletions OpenSky.Agent.Simulator/Simulator.Process.Lights.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,29 @@ public partial class Simulator
/// -------------------------------------------------------------------------------------------------
private void MonitorLights(ProcessSecondaryTracking pst)
{
// Beacon
var wasBeaconChange = false;
if (pst.Old.LightBeacon != pst.New.LightBeacon)
{
if ((DateTime.UtcNow - this.lastBeaconChange).TotalSeconds > 5)
{
this.AddTrackingEvent(this.PrimaryTracking, pst.New, FlightTrackingEventType.Beacon, OpenSkyColors.OpenSkyLightYellow, pst.New.LightBeacon ? "Beacon on" : "Beacon off");
this.lastBeaconChange = DateTime.UtcNow;
this.lastBeaconStatus = pst.New.LightBeacon;
wasBeaconChange = true;
}

if (this.lastBeaconStatus.HasValue && this.lastBeaconStatus.Value != pst.New.LightBeacon && (DateTime.UtcNow - this.lastBeaconChange).TotalSeconds > 5)
{
this.AddTrackingEvent(this.PrimaryTracking, pst.New, FlightTrackingEventType.Beacon, OpenSkyColors.OpenSkyLightYellow, pst.New.LightBeacon ? "Beacon on" : "Beacon off");
this.lastBeaconChange = DateTime.UtcNow;
this.lastBeaconStatus = null;
}
this.lastBeaconChange = DateTime.UtcNow;
}

if (this.lastBeaconStatus.HasValue && this.lastBeaconStatus.Value != pst.New.LightBeacon && (DateTime.UtcNow - this.lastBeaconChange).TotalSeconds > 5)
{
this.lastBeaconChange = DateTime.UtcNow;
this.lastBeaconStatus = null;
wasBeaconChange = true;
}

if (wasBeaconChange)
{
this.AddTrackingEvent(this.PrimaryTracking, pst.New, FlightTrackingEventType.Beacon, OpenSkyColors.OpenSkyLightYellow, pst.New.LightBeacon ? "Beacon on" : "Beacon off");

// Engine running?
if (!pst.New.LightBeacon && pst.New.EngineRunning && (this.TrackingStatus is TrackingStatus.GroundOperations or TrackingStatus.Tracking) && this.Flight?.Aircraft.Type.UsesStrobeForBeacon != true)
Expand All @@ -81,6 +89,7 @@ private void MonitorLights(ProcessSecondaryTracking pst)
}
}

// Nav lights
if (pst.Old.LightNav != pst.New.LightNav)
{
this.AddTrackingEvent(this.PrimaryTracking, pst.New, FlightTrackingEventType.NavLights, OpenSkyColors.OpenSkyLightYellow, pst.New.LightNav ? "Nav lights on" : "Nav lights off");
Expand Down
20 changes: 18 additions & 2 deletions OpenSky.Agent.Simulator/Simulator.Process.Systems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,27 @@ private void MonitorSecondarySystems(ProcessSecondaryTracking pst)
}

// Was the landing gear lowered/raised?
if (((pst.Old.GearHandle != pst.New.GearHandle) || (this.lastGearStatus.HasValue && this.lastGearStatus.Value != pst.New.GearHandle)) && (DateTime.UtcNow - this.lastGearChange).TotalSeconds > 10)
var wasGearChange = false;
if (pst.Old.GearHandle != pst.New.GearHandle)
{
if ((DateTime.UtcNow - this.lastGearChange).TotalSeconds > 10)
{
this.lastGearStatus = pst.New.GearHandle;
wasGearChange = true;
}

this.lastGearChange = DateTime.UtcNow;
this.lastGearStatus = this.lastGearStatus.HasValue ? null : pst.New.GearHandle;
}

if (this.lastGearStatus.HasValue && this.lastGearStatus.Value != pst.New.GearHandle && (DateTime.UtcNow - this.lastGearChange).TotalSeconds > 10)
{
this.lastGearChange = DateTime.UtcNow;
this.lastGearStatus = null;
wasGearChange = true;
}

if (wasGearChange)
{
if (!this.PrimaryTracking.OnGround)
{
this.AddTrackingEvent(this.PrimaryTracking, pst.New, FlightTrackingEventType.LandingGear, OpenSkyColors.OpenSkyTealLight, pst.New.GearHandle ? "Landing gear lowered" : "Landing gear raised");
Expand Down
3 changes: 1 addition & 2 deletions OpenSky.Agent.UdpXPlane11/Models/SecondaryTrackingDataRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ private void DataRefUpdated(DataRefElement element, float value)
if (int.TryParse(indexString, out var index) && index is >= 0 and < 40)
{
this.tailNumber[index] = (char)value;
var tailString = new string(this.tailNumber).Replace("\0", string.Empty);
Debug.WriteLine($"Registry: {tailString}");
Debug.WriteLine($"Registry: {new string(this.tailNumber).Replace("\0", string.Empty)}");
}
}
}
Expand Down

0 comments on commit 4a63fde

Please sign in to comment.