diff --git a/Eu07.BlackBox.Views/BlackBoxStrings.cs b/Eu07.BlackBox.Views/BlackBoxStrings.cs index dd94933..c31ad20 100644 --- a/Eu07.BlackBox.Views/BlackBoxStrings.cs +++ b/Eu07.BlackBox.Views/BlackBoxStrings.cs @@ -183,6 +183,7 @@ public sealed class DefaultBlackBoxStrings : IBlackBoxStrings ["EventSecurityBraking"] = "BRAKING BY {0}", ["EventTimetable"] = "Timetable {0}, {1}", ["CabSpeed"] = "Speed", + ["CabWheels"] = "wheels {0:0}", ["CabAiTarget"] = "AI {0:0} km/h", ["CabAcceleration"] = "Along", ["CabLateral"] = "Lateral", @@ -454,6 +455,7 @@ public sealed class DefaultBlackBoxStrings : IBlackBoxStrings ["EventSecurityBraking"] = "HAMOWANIE PRZEZ {0}", ["EventTimetable"] = "Rozkład {0}, {1}", ["CabSpeed"] = "Prędkość", + ["CabWheels"] = "koła {0:0}", ["CabAiTarget"] = "AI {0:0} km/h", ["CabAcceleration"] = "Wzdłużne", ["CabLateral"] = "Boczne", diff --git a/Eu07.BlackBox.Views/CabPanel.cs b/Eu07.BlackBox.Views/CabPanel.cs index f896579..b5f9c50 100644 --- a/Eu07.BlackBox.Views/CabPanel.cs +++ b/Eu07.BlackBox.Views/CabPanel.cs @@ -22,6 +22,7 @@ public sealed class CabPanel : Control private const double LampRow = 14; private const int DoorColumns = 2; private const double DriveRow = 34; + private const double WheelsApartKmh = 1.0; // the wheels shown when they turn this much faster or slower private Recording? _recording; private double _time; @@ -92,7 +93,12 @@ public sealed class CabPanel : Control var speed = MapView.Text(s.AbsSpeedKmh.ToString("0", culture), judgement is SpeedJudgement.Over ? Palette.Bad : judgement is SpeedJudgement.Slightly ? Palette.Warn : Palette.Text, 36, FontWeight.SemiBold); context.DrawText(speed, new Point(Pad, 24)); - context.DrawText(MapView.Text("km/h", Palette.DimText, 12), new Point(Pad + speed.Width + 4, 24 + speed.Height - 21)); + var unit = MapView.Text("km/h", Palette.DimText, 12); + context.DrawText(unit, new Point(Pad + speed.Width + 4, 24 + speed.Height - 21)); + // the wheels, when they turn otherwise: slipping, or locked in a skid + if (s.WheelSpeedKmh is { } wheels && Math.Abs(Math.Abs(wheels) - s.AbsSpeedKmh) >= WheelsApartKmh) + context.DrawText(MapView.Text(string.Format(culture, Strings["CabWheels"], Math.Abs(wheels)), Palette.Warn, 12), + new Point(Pad + speed.Width + 4 + unit.Width + 8, 24 + speed.Height - 21)); double gaugeX = Pad + Math.Max(150, width * 0.42); if (s.AiValid) { diff --git a/Eu07.BlackBox/BlackBoxReader.cs b/Eu07.BlackBox/BlackBoxReader.cs index 55b4da9..97a0e48 100644 --- a/Eu07.BlackBox/BlackBoxReader.cs +++ b/Eu07.BlackBox/BlackBoxReader.cs @@ -172,6 +172,9 @@ public sealed class BlackBoxReader Extra = new CabExtra((EngineKind)r.U8(), r.U8(), r.U8(), r.F32(), r.F32(), r.F32(), r.F32(), r.F32(), r.F32(), r.F32(), r.F32(), r.I8(), r.U8(), r.U8(), r.F32(), r.F32(), r.F32(), r.F32()) }; + // The speed of the wheels, later again. + if (sample.Extra is not null && r.Remaining >= 4) + sample = sample with { WheelSpeedKmh = r.F32() }; rec.AddCab(sample); break; } diff --git a/Eu07.BlackBox/Records.cs b/Eu07.BlackBox/Records.cs index a5046af..91df8d0 100644 --- a/Eu07.BlackBox/Records.cs +++ b/Eu07.BlackBox/Records.cs @@ -366,8 +366,12 @@ public readonly record struct CabSample(double Time, int Vehicle, Position Posit Lights LightsHead, Lights LightsTail, sbyte CabEnd = 0, SecurityFlags Security = SecurityFlags.None, float LateralAcceleration = 0, Movement Movement = Movement.Unknown, short LightHintHead = -1, short LightHintTail = -1, - Lights? EquippedHead = null, Lights? EquippedTail = null, CabExtra? Extra = null) + Lights? EquippedHead = null, Lights? EquippedTail = null, CabExtra? Extra = null, + float? WheelSpeedKmh = null) { + // WheelSpeedKmh: the speed of the wheels as they turn, which the speedometer shows, signed as SpeedKmh; apart + // from it while they slip, 0 while they are locked in a skid. None in a recording made before it. + public bool Has(CabDevices device) => (Devices & device) == device; public bool Has(SecurityFlags flag) => (Security & flag) == flag; diff --git a/StarterNG.Tests/BlackBox/BlackBoxFile.cs b/StarterNG.Tests/BlackBox/BlackBoxFile.cs index b0a49e7..ac39b62 100644 --- a/StarterNG.Tests/BlackBox/BlackBoxFile.cs +++ b/StarterNG.Tests/BlackBox/BlackBoxFile.cs @@ -109,7 +109,7 @@ internal sealed class BlackBoxFile uint devices = 0x0007, bool extended = true, sbyte cabEnd = 1, byte security = 0, float lateral = 0.2f, ushort lightsHead = 0x15, ushort lightsTail = 0x22, byte? movement = null, short hintHead = -1, short hintTail = -1, ushort? equippedHead = null, ushort? equippedTail = null, - byte? engine = null, float oilTemperature = 70) => + byte? engine = null, float oilTemperature = 70, float? wheelSpeed = null) => Record(0x20, w => { w.Write(time); @@ -181,6 +181,9 @@ internal sealed class BlackBoxFile w.Write(1.0f); // clutch w.Write(0.0f); // torque converter w.Write(2.5f); // the highest brake cylinder of the train + // the speed of the wheels: a recording made before it ends above + if (wheelSpeed is { } wheels) + w.Write(wheels); } } } diff --git a/StarterNG.Tests/BlackBox/BlackBoxSignalsTests.cs b/StarterNG.Tests/BlackBox/BlackBoxSignalsTests.cs index be035bc..9991b6f 100644 --- a/StarterNG.Tests/BlackBox/BlackBoxSignalsTests.cs +++ b/StarterNG.Tests/BlackBox/BlackBoxSignalsTests.cs @@ -125,6 +125,20 @@ public class HeadCodeTests Assert.Null(cab[1].Extra); } + [Fact] + public void The_speed_of_the_wheels_is_read_when_written() + { + var f = new BlackBoxFile().Info(); + // the wheels slipping at 40 km/h + f.Cab(0, 1, 1000, 40, movement: 1, equippedHead: 0x15, equippedTail: 0x22, engine: 1, wheelSpeed: 55.5f); + f.Cab(0.5, 1, 1000, 40, movement: 1, equippedHead: 0x15, equippedTail: 0x22, engine: 1); + var cab = BlackBoxReader.Read(f.End(1).Stream()).Cab; + Assert.Equal(55.5f, cab[0].WheelSpeedKmh); + Assert.Equal(40f, cab[0].SpeedKmh); + // an older sample has none + Assert.Null(cab[1].WheelSpeedKmh); + } + [Fact] public void A_vehicle_with_no_lamps_is_not_judged() {