feat(blackbox): the train protection's buzzer told apart from its braking

The buzzer has a colour of its own on the timeline and in the cab, no longer the braking's red, and an event of its
own: acknowledged after how long, or not acknowledged when the braking follows. The alerter's buzzer needs its lamp,
since a protection with one acknowledgement tells the cab signalling's buzzer as the alerter's too. Braking with no
lamp, the protection with no power, is not shown as the driver's on the timeline and in the cab either.
This commit is contained in:
maj00r
2026-11-16 02:17:57 +01:00
parent e4d092ab3e
commit 5bc5da3fbf
8 changed files with 121 additions and 26 deletions

View File

@@ -181,6 +181,9 @@ public sealed class DefaultBlackBoxStrings : IBlackBoxStrings
["EventHornMissed"] = "W6: NO HORN", ["EventHornMissed"] = "W6: NO HORN",
["EventCab"] = "Cab {0} of {1}", ["EventCab"] = "Cab {0} of {1}",
["EventSecurityBraking"] = "BRAKING BY {0}", ["EventSecurityBraking"] = "BRAKING BY {0}",
["EventSecurityAlarm"] = "{0} buzzer",
["EventSecurityAlarmAcknowledged"] = "{0} buzzer, acknowledged after {1:0.0} s",
["EventSecurityAlarmMissed"] = "{0} buzzer, not acknowledged",
["EventTimetable"] = "Timetable {0}, {1}", ["EventTimetable"] = "Timetable {0}, {1}",
["CabSpeed"] = "Speed", ["CabSpeed"] = "Speed",
["CabAiTarget"] = "AI {0:0} km/h", ["CabAiTarget"] = "AI {0:0} km/h",
@@ -452,6 +455,9 @@ public sealed class DefaultBlackBoxStrings : IBlackBoxStrings
["EventHornMissed"] = "W6: BEZ TRĄBIENIA", ["EventHornMissed"] = "W6: BEZ TRĄBIENIA",
["EventCab"] = "Kabina {0} w {1}", ["EventCab"] = "Kabina {0} w {1}",
["EventSecurityBraking"] = "HAMOWANIE PRZEZ {0}", ["EventSecurityBraking"] = "HAMOWANIE PRZEZ {0}",
["EventSecurityAlarm"] = "Brzęczyk {0}",
["EventSecurityAlarmAcknowledged"] = "Brzęczyk {0}, potwierdzony po {1:0.0} s",
["EventSecurityAlarmMissed"] = "Brzęczyk {0}, bez potwierdzenia",
["EventTimetable"] = "Rozkład {0}, {1}", ["EventTimetable"] = "Rozkład {0}, {1}",
["CabSpeed"] = "Prędkość", ["CabSpeed"] = "Prędkość",
["CabAiTarget"] = "AI {0:0} km/h", ["CabAiTarget"] = "AI {0:0} km/h",

View File

@@ -530,12 +530,12 @@ public sealed class CabPanel : Control
if (s.Security != SecurityFlags.None || s.CabEnd != 0) if (s.Security != SecurityFlags.None || s.CabEnd != 0)
{ {
// A recording which tells them apart. // A recording which tells them apart.
safety.Add((Strings["DevVigilance"], Security(SecurityFlags.VigilanceBeeping, Palette.LampAlarm) ?? Security(SecurityFlags.Vigilance, Palette.Vigilance))); safety.Add((Strings["DevVigilance"], s.VigilanceBuzzer ? Palette.Buzzer : Security(SecurityFlags.Vigilance, Palette.Vigilance)));
safety.Add((Strings["DevCabSignal"], Security(SecurityFlags.CabSignalBeeping, Palette.LampAlarm) ?? Security(SecurityFlags.CabSignal, Palette.CabSignal))); safety.Add((Strings["DevCabSignal"], s.CabSignalBuzzer ? Palette.Buzzer : Security(SecurityFlags.CabSignal, Palette.CabSignal)));
safety.Add((Strings["DevSecurityBraking"], Security(SecurityFlags.Braking, Palette.LampAlarm))); safety.Add((Strings["DevSecurityBraking"], s.ProtectionBraking ? Palette.LampAlarm : null));
} }
else else
safety.Add((Strings["DevAlerter"], (s.Flags & CabFlags.AlerterBeeping) != 0 ? Palette.LampAlarm safety.Add((Strings["DevAlerter"], (s.Flags & CabFlags.AlerterBeeping) != 0 ? Palette.Buzzer
: (s.Flags & CabFlags.AlerterBlinking) != 0 ? Palette.LampWarning : null)); : (s.Flags & CabFlags.AlerterBlinking) != 0 ? Palette.LampWarning : null));
safety.Add(Flag("DevWheelSlip", CabFlags.WheelSlip, Palette.LampAlarm)); safety.Add(Flag("DevWheelSlip", CabFlags.WheelSlip, Palette.LampAlarm));
safety.Add(On("DevOverloadRelay", CabDevices.OverloadRelay, Palette.LampAlarm)); safety.Add(On("DevOverloadRelay", CabDevices.OverloadRelay, Palette.LampAlarm));

View File

@@ -178,14 +178,7 @@ public sealed class EventList : ListBox
foreach (var horn in recording.UserHornChecks()) foreach (var horn in recording.UserHornChecks())
events.Add(new BlackBoxEvent(horn.Request.Time, strings[horn.Sounded ? "EventHornSounded" : "EventHornMissed"], events.Add(new BlackBoxEvent(horn.Request.Time, strings[horn.Sounded ? "EventHornSounded" : "EventHornMissed"],
horn.Sounded ? Palette.HornPoint : Palette.Bad, !horn.Sounded)); horn.Sounded ? Palette.HornPoint : Palette.Bad, !horn.Sounded));
foreach (var span in recording.SecurityBrakings()) AddSecurity(recording, strings, events, culture);
{
// Which of them was not acknowledged: the lamps blinking when it braked.
string who = recording.CabAt(span.Start) is { } s
? s.Has(SecurityFlags.CabSignal) && s.Has(SecurityFlags.Vigilance) ? "CA/SHP" : s.Has(SecurityFlags.CabSignal) ? "SHP" : "CA"
: "CA";
events.Add(new BlackBoxEvent(span.Start, string.Format(culture, strings["EventSecurityBraking"], who), Palette.Bad, true));
}
AddCameras(recording, strings, events, culture); AddCameras(recording, strings, events, culture);
AddCouplings(recording, strings, events, culture); AddCouplings(recording, strings, events, culture);
AddCabChanges(recording, strings, events, culture); AddCabChanges(recording, strings, events, culture);
@@ -198,6 +191,35 @@ public sealed class EventList : ListBox
return events.OrderBy(e => e.Time).ToList(); return events.OrderBy(e => e.Time).ToList();
} }
/// <summary>
/// The train protection: its buzzer, acknowledged or not, and the braking apart. A lamp acknowledged before the
/// buzzer is the driving as usual, not told.
/// </summary>
private static void AddSecurity(Recording recording, IBlackBoxStrings strings, List<BlackBoxEvent> events, CultureInfo culture)
{
var brakings = recording.SecurityBrakings();
foreach (var span in recording.SecurityAlarms())
{
string who = ProtectionName(recording.CabAt(span.Start));
string text = brakings.Any(b => b.Start >= span.Start && b.Start <= span.End)
? string.Format(culture, strings["EventSecurityAlarmMissed"], who)
// Acknowledged when the sample it ended at buzzes no more: not the end of the recording or a gap in it.
: recording.CabAt(span.End) is { } after && !after.VigilanceBuzzer && !after.CabSignalBuzzer
? string.Format(culture, strings["EventSecurityAlarmAcknowledged"], who, span.End - span.Start)
: string.Format(culture, strings["EventSecurityAlarm"], who);
events.Add(new BlackBoxEvent(span.Start, text, Palette.Buzzer, false));
}
foreach (var span in brakings)
events.Add(new BlackBoxEvent(span.Start, string.Format(culture, strings["EventSecurityBraking"],
ProtectionName(recording.CabAt(span.Start))), Palette.Bad, true));
}
/// <summary>Which of them it was: the lamps blinking.</summary>
private static string ProtectionName(CabSample? sample) =>
sample is not { } s ? "CA"
: s.Has(SecurityFlags.CabSignal) && s.Has(SecurityFlags.Vigilance) ? "CA/SHP"
: s.Has(SecurityFlags.CabSignal) ? "SHP" : "CA";
private static void AddUserVehicles(Recording recording, IBlackBoxStrings strings, List<BlackBoxEvent> events, CultureInfo culture) private static void AddUserVehicles(Recording recording, IBlackBoxStrings strings, List<BlackBoxEvent> events, CultureInfo culture)
{ {
UserVehicleChange? before = null; UserVehicleChange? before = null;

View File

@@ -79,6 +79,8 @@ public static class Palette
public static readonly IBrush LampOn = Brush("#4cc46e"); public static readonly IBrush LampOn = Brush("#4cc46e");
public static readonly IBrush LampWarning = Brush("#e8c547"); public static readonly IBrush LampWarning = Brush("#e8c547");
public static readonly IBrush LampAlarm = Brush("#f0584a"); public static readonly IBrush LampAlarm = Brush("#f0584a");
/// <summary>The train protection's buzzer: still to be acknowledged, not braking yet.</summary>
public static readonly IBrush Buzzer = Brush("#c77dff");
public static readonly IBrush LightWhite = Brush("#fff6d8"); public static readonly IBrush LightWhite = Brush("#fff6d8");
public static readonly IBrush LightRed = Brush("#ff3b30"); public static readonly IBrush LightRed = Brush("#ff3b30");
public static readonly IBrush Command = Brush("#8b96a3"); public static readonly IBrush Command = Brush("#8b96a3");

View File

@@ -245,16 +245,16 @@ public sealed class TimelineView : Control
rows[2].Add(x0, x1, s.BrakeCylinder > 0.2f ? BrakeShade(s.BrakeCylinder) : null, BandHeight); rows[2].Add(x0, x1, s.BrakeCylinder > 0.2f ? BrakeShade(s.BrakeCylinder) : null, BandHeight);
if (s.Security != SecurityFlags.None || s.CabEnd != 0) if (s.Security != SecurityFlags.None || s.CabEnd != 0)
{ {
// The alerter and the cab signalling apart, red when not acknowledged in time. // The alerter and the cab signalling apart: the lamp, then its buzzer, red when it braked.
rows[3].Add(x0, x1, s.Has(SecurityFlags.VigilanceBeeping) ? Palette.LampAlarm rows[3].Add(x0, x1, s.VigilanceBuzzer ? Palette.Buzzer
: s.Has(SecurityFlags.Vigilance) ? Palette.Vigilance : null, BandHeight); : s.Has(SecurityFlags.Vigilance) ? Palette.Vigilance : null, BandHeight);
rows[4].Add(x0, x1, s.Has(SecurityFlags.CabSignalBeeping) ? Palette.LampAlarm rows[4].Add(x0, x1, s.CabSignalBuzzer ? Palette.Buzzer
: s.Has(SecurityFlags.CabSignal) ? Palette.CabSignal : null, BandHeight); : s.Has(SecurityFlags.CabSignal) ? Palette.CabSignal : null, BandHeight);
if (s.Has(SecurityFlags.Braking)) if (s.ProtectionBraking)
rows[s.Has(SecurityFlags.CabSignal) && !s.Has(SecurityFlags.Vigilance) ? 4 : 3].Add(x0, x1, Palette.Bad, BandHeight); rows[s.Has(SecurityFlags.CabSignal) && !s.Has(SecurityFlags.Vigilance) ? 4 : 3].Add(x0, x1, Palette.Bad, BandHeight);
} }
else else
rows[3].Add(x0, x1, (s.Flags & CabFlags.AlerterBeeping) != 0 ? Palette.LampAlarm rows[3].Add(x0, x1, (s.Flags & CabFlags.AlerterBeeping) != 0 ? Palette.Buzzer
: (s.Flags & CabFlags.AlerterBlinking) != 0 ? Palette.Vigilance : null, BandHeight); : (s.Flags & CabFlags.AlerterBlinking) != 0 ? Palette.Vigilance : null, BandHeight);
// Where the user looked from: the samples go on in time, and so does the camera. // Where the user looked from: the samples go on in time, and so does the camera.
while (camera + 1 < cameras.Count && cameras[camera + 1].Time <= s.Time) while (camera + 1 < cameras.Count && cameras[camera + 1].Time <= s.Time)

View File

@@ -519,13 +519,14 @@ public sealed class Recording
return false; return false;
} }
/// <summary>When the train protection braked the user's train: the alerter or the cab signalling not acknowledged.</summary>
public IReadOnlyList<TimeSpanRange> SecurityBrakings() => CabSpans(s => s.ProtectionBraking);
/// <summary> /// <summary>
/// When the train protection braked the user's train: the alerter or the cab signalling not acknowledged, its lamp /// When the train protection's buzzer sounded in the user's cab: a lamp not acknowledged in time, the braking to
/// blinking. Braking with neither is the protection with no power (TSecuritySystem::is_braking), a cab not yet /// follow unless acknowledged on. Until it ends, braking included.
/// started or a power cut: no driver's fault, not counted.
/// </summary> /// </summary>
public IReadOnlyList<TimeSpanRange> SecurityBrakings() => public IReadOnlyList<TimeSpanRange> SecurityAlarms() => CabSpans(s => s.VigilanceBuzzer || s.CabSignalBuzzer);
CabSpans(s => s.Has(SecurityFlags.Braking) && (s.Has(SecurityFlags.Vigilance) || s.Has(SecurityFlags.CabSignal)));
/// <summary>The commands the user gave in a vehicle, presses only.</summary> /// <summary>The commands the user gave in a vehicle, presses only.</summary>
public IEnumerable<CommandEntry> UserCommands() => _commands.Where(c => c.Pressed && c.Vehicle != 0); public IEnumerable<CommandEntry> UserCommands() => _commands.Where(c => c.Pressed && c.Vehicle != 0);

View File

@@ -371,6 +371,21 @@ public readonly record struct CabSample(double Time, int Vehicle, Position Posit
public bool Has(CabDevices device) => (Devices & device) == device; public bool Has(CabDevices device) => (Devices & device) == device;
public bool Has(SecurityFlags flag) => (Security & flag) == flag; public bool Has(SecurityFlags flag) => (Security & flag) == flag;
/// <summary>
/// The alerter's buzzer: its lamp not acknowledged in time. A protection with one acknowledgement for both tells
/// the cab signalling's buzzer as the alerter's too, so the alerter's lamp has to blink with it.
/// </summary>
public bool VigilanceBuzzer => Has(SecurityFlags.VigilanceBeeping) && Has(SecurityFlags.Vigilance);
/// <summary>The cab signalling's buzzer: its lamp not acknowledged in time.</summary>
public bool CabSignalBuzzer => Has(SecurityFlags.CabSignalBeeping);
/// <summary>
/// The train protection braking for an alarm not acknowledged, its lamp blinking. Braking with no lamp is the
/// protection with no power (TSecuritySystem::is_braking), a cab not started or a power cut: no driver's fault.
/// </summary>
public bool ProtectionBraking => Has(SecurityFlags.Braking) && (Has(SecurityFlags.Vigilance) || Has(SecurityFlags.CabSignal));
public bool AiValid => (Flags & CabFlags.AiValid) != 0; public bool AiValid => (Flags & CabFlags.AiValid) != 0;
public bool InCab => (Flags & CabFlags.InCab) != 0; public bool InCab => (Flags & CabFlags.InCab) != 0;
public float AbsSpeedKmh => Math.Abs(SpeedKmh); public float AbsSpeedKmh => Math.Abs(SpeedKmh);

View File

@@ -1,19 +1,68 @@
using System.Globalization;
using Eu07.BlackBox; using Eu07.BlackBox;
using Eu07.BlackBox.Views;
namespace StarterNG.Tests.BlackBox; namespace StarterNG.Tests.BlackBox;
public class SecurityBrakingTests public class SecurityBrakingTests
{ {
// as the simulator writes them: one acknowledgement for both, so the cab signalling's buzzer is the alerter's too
private const byte CabSignal = 0x02, CabSignalBuzzing = 0x0e, CabSignalBraking = 0x1e, NoPower = 0x10;
private static Recording Drive(System.Func<double, byte> security)
{
var file = new BlackBoxFile().Info().Vehicle(1, "EP07-424").User(0, 1, true);
for (double t = 0; t <= 20; t += 0.5)
file.Cab(t, 1, 100, 0, security: security(t));
return BlackBoxReader.Read(file.Stream());
}
private static List<string> Events(Recording recording)
{
var culture = CultureInfo.CurrentCulture;
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
try
{
return EventList.Collect(recording, new DefaultBlackBoxStrings("pl")).Select(e => e.Text).ToList();
}
finally
{
CultureInfo.CurrentCulture = culture;
}
}
[Fact] [Fact]
public void The_protection_braking_with_no_power_is_not_the_drivers_fault() public void The_protection_braking_with_no_power_is_not_the_drivers_fault()
{ {
var file = new BlackBoxFile().Info().Vehicle(1, "EP07-424").User(0, 1, true);
// no power for the first seconds, then the cab signalling not acknowledged // no power for the first seconds, then the cab signalling not acknowledged
for (double t = 0; t <= 20; t += 0.5) var recording = Drive(t => t < 5 ? NoPower : t is >= 10 and < 12 ? (byte)0x1a : (byte)0);
file.Cab(t, 1, 100, 0, security: (byte)(t < 5 ? 0x10 : t is >= 10 and < 12 ? 0x1a : 0));
var recording = BlackBoxReader.Read(file.Stream());
var braking = Assert.Single(recording.SecurityBrakings()); var braking = Assert.Single(recording.SecurityBrakings());
Assert.Equal(10, braking.Start, 6); Assert.Equal(10, braking.Start, 6);
} }
[Fact]
public void A_buzzer_acknowledged_in_time_is_told_apart_from_braking()
{
var recording = Drive(t => t is >= 2 and < 4 ? CabSignal : t is >= 4 and < 5.5 ? CabSignalBuzzing : (byte)0);
var events = Events(recording);
Assert.Contains("Brzęczyk SHP, potwierdzony po 1.5 s", events);
Assert.DoesNotContain(events, e => e.StartsWith("HAMOWANIE", System.StringComparison.Ordinal));
Assert.Empty(recording.SecurityBrakings());
}
[Fact]
public void A_buzzer_not_acknowledged_is_followed_by_the_braking()
{
// the cab signalling at the start: the buzzer at once, braking when not acknowledged
var recording = Drive(t => t < 3 ? CabSignalBuzzing : t < 6 ? CabSignalBraking : (byte)0);
var events = Events(recording);
Assert.Equal(["Brzęczyk SHP, bez potwierdzenia", "HAMOWANIE PRZEZ SHP"],
events.Where(e => e.Contains("SHP", System.StringComparison.Ordinal)));
Assert.DoesNotContain(events, e => e.Contains("CA", System.StringComparison.Ordinal));
}
} }