feat(blackbox): the speed of the wheels read from the cab record, shown when they slip or skid

The simulator adds the speed of the wheels at the end of the cab record. It is read when there, and the cab
panel shows it next to the vehicle's speed when the two are a km/h apart or more: the wheels slipping, or
locked in a skid.
This commit is contained in:
maj00r
2026-11-14 00:50:03 +01:00
parent 1398545ff2
commit 7823bb8d09
6 changed files with 35 additions and 3 deletions

View File

@@ -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);
}
}
}

View File

@@ -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()
{