From a86bcb1ef51b9ddd4c6ae030d15c7895185b2361 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sat, 7 Nov 2026 20:08:59 +0100 Subject: [PATCH 1/3] fix: SM42 shunt mode switched on at the first move of the switch (eu07/maszyna#497) CurrentSwitch() asked MaxCurrentSwitch() first. Since 2e86b3a5 (2021) that one takes any change of the motor overload relay threshold, on every engine type, and reports it, so the first move of the switch only flipped the threshold (meaningless on a diesel) and the shunt mode of the SM42/SP42 (and the 2Ls150 gear of the SM03) took a second one, both on and off; the cab switch, which shows the shunt mode, didn't move at the first click. The diesels with a shunt mode now set it alone. --- McZapkie/Mover.cpp | 27 +++++++++++++-------------- tests/unit/test_diesel.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index 330e8eb8f..34caced15 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -809,6 +809,19 @@ bool TMoverParameters::ChangeCab(int direction) // rozruch wysoki (true) albo niski (false) bool TMoverParameters::CurrentSwitch(bool const State) { + // TBD, TODO: split off shunt mode toggle into a separate command? It doesn't make much sense to have these two together like that + // the diesels with a shunt mode have no motor overload relay threshold to switch, the switch sets their shunt mode alone. + // MaxCurrentSwitch() takes any change of the setting, so asked first it took the first move of the switch (eu07/maszyna#497) + if (true == ShuntModeAllow && (EngineType == TEngineType::DieselEngine || EngineType == TEngineType::DieselElectric)) + { + // dla 2Ls150 przed ustawieniem kierunku, for SM42/SP42 at the controller's zero position + if (EngineType == TEngineType::DieselEngine ? DirActive != 0 : false == IsMainCtrlNoPowerPos()) + { + return false; + } + ShuntMode = State; + return true; + } if (MaxCurrentSwitch(State)) { @@ -818,20 +831,6 @@ bool TMoverParameters::CurrentSwitch(bool const State) } return true; } - // TBD, TODO: split off shunt mode toggle into a separate command? It doesn't make much sense to have these two together like that - // dla 2Ls150 - if (EngineType == TEngineType::DieselEngine && true == ShuntModeAllow && DirActive == 0) - { - // przed ustawieniem kierunku - ShuntMode = State; - return true; - } - // for SM42/SP42 - if (EngineType == TEngineType::DieselElectric && true == ShuntModeAllow && IsMainCtrlNoPowerPos()) - { - ShuntMode = State; - return true; - } return false; }; diff --git a/tests/unit/test_diesel.cpp b/tests/unit/test_diesel.cpp index 07686dc10..c4ea147d3 100644 --- a/tests/unit/test_diesel.cpp +++ b/tests/unit/test_diesel.cpp @@ -177,3 +177,32 @@ TEST_CASE("diesel: the 214M railbus's speed control, up to the speed of a button CHECK_FALSE(railbus.SpeedCtrlUnit.IsActive); scenario.check(); } + +TEST_CASE("diesel: the SM42's shunt mode, switched on and off with one move of the switch") { + // eu07/maszyna#497: the shunt mode of the diesel-electrics (ShuntMode=1) shares its switch with the motor + // overload relay threshold of the electric locomotives (CurrentSwitch()). the SM42 has no such relay, so + // the switch sets the shunt mode at the first move, at the controller's zero position only + scenario scenario{"diesel/sm42 shunt mode", motion() + traction(), test::track{}}; + scenario.add("sm42_v1/6d1", 1); + REQUIRE(scenario.start_up()); + auto &sm42{scenario.cab()}; + REQUIRE(sm42.ShuntModeAllow); + CHECK_FALSE(sm42.ShuntMode); + scenario.act("shunt mode on"); + CHECK(sm42.CurrentSwitch(true)); + CHECK(sm42.ShuntMode); + scenario.get_going(); + scenario.act("shunting power"); + sm42.AnPos = 0.5; + CHECK(sm42.IncMainCtrl(1)); + scenario.wait(60.0); + CHECK(sm42.Vel > 1.0); + // not with the controller out of its zero position + CHECK_FALSE(sm42.CurrentSwitch(false)); + CHECK(sm42.ShuntMode); + scenario.notch_back(0); + scenario.act("shunt mode off"); + CHECK(sm42.CurrentSwitch(false)); + CHECK_FALSE(sm42.ShuntMode); + scenario.check(); +} From 329dc4e42efda784739d82386737398189267f36 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sat, 7 Nov 2026 20:13:46 +0100 Subject: [PATCH 2/3] feat: SM42 vigilance device switched off in the shunt mode (eu07/maszyna#457) The shunt mode of the diesel-electrics (ShuntMode=1: SM42, SP42, SU42) now suspends their vigilance device (CA): no alerter while running, no alarm for the button held too long, and an alarm already on goes out. The cab signalling (SHP) stays as it was. Back in the line mode the CA works as before. --- McZapkie/MOVER.h | 2 ++ McZapkie/Mover.cpp | 26 ++++++++++++++++++++++---- tests/unit/test_cab.cpp | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 4 deletions(-) diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h index 199c65a0c..0149bfb7d 100644 --- a/McZapkie/MOVER.h +++ b/McZapkie/MOVER.h @@ -1131,6 +1131,7 @@ class TSecuritySystem bool is_sifa = false; // Sifa-like pedal device, with inverted input for convenient keyboard usage bool separate_acknowledge = false; // cabsignal reset button is separate from vigilance bool cabsignal_lock = false; + bool vigilance_suspended = false; // the vigilance device switched off by the vehicle, as by the SM42's shunt mode double vigilance_timer = 0.0; double alert_timer = 0.0; @@ -1155,6 +1156,7 @@ class TSecuritySystem void update(double dt, double Vel, bool pwr, int cab); void set_cabsignal(); void set_cabsignal_lock(bool); + void set_vigilance_suspended(bool Suspended); bool is_blinking() const; bool is_vigilance_blinking() const; bool is_cabsignal_blinking() const; diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index 34caced15..eaed979f0 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -152,11 +152,22 @@ void TSecuritySystem::update(double dt, double vel, bool pwr, int cab) velocity = vel; cabactive = cab; - if (vigilance_enabled && velocity > AwareMinSpeed) - vigilance_timer += dt; + if (vigilance_suspended) + { + // the vigilance device is switched off: neither the alerter nor the button held too long, its alarm gone with it + vigilance_timer = 0.0; + press_timer = 0.0; + if (!cabsignal_active) + alert_timer = 0.0; + } + else + { + if (vigilance_enabled && velocity > AwareMinSpeed) + vigilance_timer += dt; - if (pressed && (!is_sifa || velocity > AwareMinSpeed)) - press_timer += dt; + if (pressed && (!is_sifa || velocity > AwareMinSpeed)) + press_timer += dt; + } if (vigilance_timer > AwareDelay || press_timer > MaxHoldTime || cabsignal_active) alert_timer += dt; @@ -231,6 +242,11 @@ void TSecuritySystem::set_cabsignal_lock(bool v) cabsignal_lock = v; } +void TSecuritySystem::set_vigilance_suspended(bool const Suspended) +{ + vigilance_suspended = Suspended; +} + bool TSecuritySystem::is_engine_blocked() const { if (!is_sifa) @@ -3142,6 +3158,8 @@ void TMoverParameters::SecuritySystemReset(void) // zbijanie czuwaka/SHP void TMoverParameters::SecuritySystemCheck(double dt) { bool isPower = Power24vIsAvailable || Power110vIsAvailable; + // the shunt mode of the SM42/SP42 switches their vigilance device (CA) off (eu07/maszyna#457) + SecuritySystem.set_vigilance_suspended(EngineType == TEngineType::DieselElectric && ShuntMode); SecuritySystem.update(dt, Vel, isPower, CabActive); if (!Battery || !Radio) diff --git a/tests/unit/test_cab.cpp b/tests/unit/test_cab.cpp index 4c5ba9f53..69f6278e9 100644 --- a/tests/unit/test_cab.cpp +++ b/tests/unit/test_cab.cpp @@ -227,3 +227,38 @@ TEST_CASE("cab: the lamps and the buzzer of the security system left unattended" CHECK(security.radiostop_available()); scenario.check(); } + +TEST_CASE("cab: the SM42's vigilance device switched off in the shunt mode") { + // eu07/maszyna#457: the shunt mode of the SM42 switches its vigilance device (CA) off, it alerts again + // once the shunt mode is off + scenario scenario{"cab/sm42 vigilance in shunt mode", motion() + brakes(), test::track{}}; + scenario.add("sm42_v1/6d1", 1); + REQUIRE(scenario.start_up()); + auto &sm42{scenario.cab()}; + auto const &security{sm42.SecuritySystem}; + REQUIRE(sm42.CurrentSwitch(true)); + REQUIRE(sm42.ShuntMode); + scenario.get_going(); + sm42.AnPos = 0.3; + sm42.IncMainCtrl(1); + scenario.act("unattended in shunt mode"); + bool blinked{false}; + for (int i = 0; i < 120; ++i) { + scenario.train().run(1.0, scenario.line()); + blinked |= security.is_blinking(); + } + CHECK(sm42.Vel > 1.0); + CHECK_FALSE(blinked); + CHECK(sm42.PipePress > 3.5); + scenario.act("shunt mode off"); + scenario.notch_back(0); + REQUIRE(sm42.CurrentSwitch(false)); + sm42.IncMainCtrl(1); + scenario.act("unattended"); + for (int i = 0; i < 120; ++i) { + scenario.train().run(1.0, scenario.line()); + blinked |= security.is_vigilance_blinking(); + } + CHECK(blinked); + scenario.check(); +} From d755c7708f752684231e8f7792582993133b56bf Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sun, 8 Nov 2026 18:19:59 +0100 Subject: [PATCH 3/3] fix: the SM42's CA off in the shunt mode only with AwareOffInShuntMode, an alarm on kept Review of #275. The shunt mode suspends the vigilance device (CA) only on the vehicles whose .fiz sets the new Security key AwareOffInShuntMode=Yes (default No), instead of on every diesel-electric with ShuntMode=1 (SP42, SU42 and the 401Z generator car had it too). Suspended, the CA counts no time towards a new alarm, but an alarm already on stays, goes on to the emergency braking and needs the usual acknowledgement, instead of going out with the shunt mode. --- McZapkie/MOVER.h | 5 +- McZapkie/Mover.cpp | 20 +++-- tests/unit/test_cab.cpp | 184 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 189 insertions(+), 20 deletions(-) diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h index 0149bfb7d..e67da9b54 100644 --- a/McZapkie/MOVER.h +++ b/McZapkie/MOVER.h @@ -1131,7 +1131,7 @@ class TSecuritySystem bool is_sifa = false; // Sifa-like pedal device, with inverted input for convenient keyboard usage bool separate_acknowledge = false; // cabsignal reset button is separate from vigilance bool cabsignal_lock = false; - bool vigilance_suspended = false; // the vigilance device switched off by the vehicle, as by the SM42's shunt mode + bool vigilance_suspended = false; // the vigilance device switched off by the shunt mode of the vehicle, see AwareOffInShuntMode double vigilance_timer = 0.0; double alert_timer = 0.0; @@ -1147,6 +1147,7 @@ class TSecuritySystem double EmergencyBrakeDelay = 5.0; double MaxHoldTime = 1.5; bool CabDependent = false; + bool AwareOffInShuntMode = false; // the shunt mode of the vehicle switches the vigilance device off, as on the SM42 public: void set_enabled(bool e); @@ -1156,7 +1157,7 @@ class TSecuritySystem void update(double dt, double Vel, bool pwr, int cab); void set_cabsignal(); void set_cabsignal_lock(bool); - void set_vigilance_suspended(bool Suspended); + void set_shunt_mode(bool State); bool is_blinking() const; bool is_vigilance_blinking() const; bool is_cabsignal_blinking() const; diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index eaed979f0..af3591c24 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -154,11 +154,12 @@ void TSecuritySystem::update(double dt, double vel, bool pwr, int cab) if (vigilance_suspended) { - // the vigilance device is switched off: neither the alerter nor the button held too long, its alarm gone with it - vigilance_timer = 0.0; - press_timer = 0.0; - if (!cabsignal_active) - alert_timer = 0.0; + // the vigilance device is switched off: no time counts towards a new alarm, of the alerter or of the button held + // too long. an alarm already on, with the emergency braking it leads to, stays until it's acknowledged as usual + if (vigilance_timer <= AwareDelay) + vigilance_timer = 0.0; + if (press_timer <= MaxHoldTime) + press_timer = 0.0; } else { @@ -242,9 +243,9 @@ void TSecuritySystem::set_cabsignal_lock(bool v) cabsignal_lock = v; } -void TSecuritySystem::set_vigilance_suspended(bool const Suspended) +void TSecuritySystem::set_shunt_mode(bool const State) { - vigilance_suspended = Suspended; + vigilance_suspended = State && AwareOffInShuntMode; } bool TSecuritySystem::is_engine_blocked() const @@ -276,6 +277,7 @@ void TSecuritySystem::load(std::string const &line, double Vmax) extract_value(radiostop_enabled, "RadioStop", line, ""); extract_value(MagnetLocation, "MagnetLocation", line, ""); extract_value(CabDependent, "CabDependent", line, ""); + extract_value(AwareOffInShuntMode, "AwareOffInShuntMode", line, ""); } double TableInterpolation(std::map &Map, double Parameter) @@ -3158,8 +3160,8 @@ void TMoverParameters::SecuritySystemReset(void) // zbijanie czuwaka/SHP void TMoverParameters::SecuritySystemCheck(double dt) { bool isPower = Power24vIsAvailable || Power110vIsAvailable; - // the shunt mode of the SM42/SP42 switches their vigilance device (CA) off (eu07/maszyna#457) - SecuritySystem.set_vigilance_suspended(EngineType == TEngineType::DieselElectric && ShuntMode); + // the shunt mode of the SM42 switches its vigilance device (CA) off, on the vehicles with AwareOffInShuntMode=Yes (eu07/maszyna#457) + SecuritySystem.set_shunt_mode(ShuntMode); SecuritySystem.update(dt, Vel, isPower, CabActive); if (!Battery || !Radio) diff --git a/tests/unit/test_cab.cpp b/tests/unit/test_cab.cpp index 69f6278e9..063e70911 100644 --- a/tests/unit/test_cab.cpp +++ b/tests/unit/test_cab.cpp @@ -228,11 +228,31 @@ TEST_CASE("cab: the lamps and the buzzer of the security system left unattended" scenario.check(); } -TEST_CASE("cab: the SM42's vigilance device switched off in the shunt mode") { - // eu07/maszyna#457: the shunt mode of the SM42 switches its vigilance device (CA) off, it alerts again - // once the shunt mode is off +namespace { + +// the SM42, its shunt mode switching its vigilance device (CA) off or not (AwareOffInShuntMode), set in the +// test whatever the converted definition says +definition sm42_vigilance(bool const Off) { + return definition::fiz("sm42_v1/6d1").set("Security", "AwareOffInShuntMode", Off ? "Yes" : "No"); +} + +// runs the train for Seconds with nobody acknowledging the vigilance; returns whether the vigilance alarm came +bool unattended(scenario &Scenario, int const Seconds) { + bool blinked{false}; + for (int i = 0; i < Seconds; ++i) { + Scenario.train().run(1.0, Scenario.line()); + blinked |= Scenario.cab().SecuritySystem.is_vigilance_blinking(); + } + return blinked; +} + +} // namespace + +TEST_CASE("cab: the SM42's vigilance device switched off in the shunt mode, where its definition says so") { + // eu07/maszyna#457: with AwareOffInShuntMode=Yes the shunt mode of the SM42 switches its vigilance device (CA) + // off, it alerts again once the shunt mode is off scenario scenario{"cab/sm42 vigilance in shunt mode", motion() + brakes(), test::track{}}; - scenario.add("sm42_v1/6d1", 1); + scenario.train().add(sm42_vigilance(true), 1); REQUIRE(scenario.start_up()); auto &sm42{scenario.cab()}; auto const &security{sm42.SecuritySystem}; @@ -255,10 +275,156 @@ TEST_CASE("cab: the SM42's vigilance device switched off in the shunt mode") { REQUIRE(sm42.CurrentSwitch(false)); sm42.IncMainCtrl(1); scenario.act("unattended"); - for (int i = 0; i < 120; ++i) { - scenario.train().run(1.0, scenario.line()); - blinked |= security.is_vigilance_blinking(); - } - CHECK(blinked); + CHECK(unattended(scenario, 120)); scenario.check(); } + +TEST_CASE("cab: the vigilance device of the SM42 kept in the shunt mode, by default") { + // without AwareOffInShuntMode the shunt mode leaves the vigilance device alone: unattended, it alerts and brakes + scenario scenario{"cab/sm42 vigilance kept in shunt mode", motion() + brakes(), test::track{}}; + scenario.train().add(sm42_vigilance(false), 1); + REQUIRE(scenario.start_up()); + auto &sm42{scenario.cab()}; + REQUIRE(sm42.CurrentSwitch(true)); + REQUIRE(sm42.ShuntMode); + scenario.get_going(); + sm42.AnPos = 0.3; + sm42.IncMainCtrl(1); + scenario.act("unattended in shunt mode"); + CHECK(unattended(scenario, 120)); + CHECK(sm42.ShuntMode); + CHECK(sm42.PipePress < 1.0); + scenario.check(); +} + +TEST_CASE("cab: the SM42's vigilance alarm on, not cleared by switching into the shunt mode") { + // the shunt mode switches the vigilance device off for the time to come: an alarm already on goes on to the + // emergency braking, until the driver acknowledges it (#275 review) + scenario scenario{"cab/sm42 vigilance alarm into shunt mode", motion() + brakes(), test::track{}}; + scenario.train().add(sm42_vigilance(true), 1); + REQUIRE(scenario.start_up()); + auto &sm42{scenario.cab()}; + auto const &security{sm42.SecuritySystem}; + scenario.get_going(); + sm42.IncMainCtrl(1); + scenario.act("unattended"); + // the alerter counts only on the move, which takes a while on the first notch + for (int i = 0; i < 300 && false == security.is_vigilance_blinking(); ++i) { + scenario.train().run(1.0, scenario.line()); + } + REQUIRE(security.is_vigilance_blinking()); + REQUIRE_FALSE(security.is_braking()); + scenario.act("shunt mode on"); + for (int i = 0; i < 20 && false == sm42.IsMainCtrlNoPowerPos(); ++i) { + sm42.DecMainCtrl(1); + } + REQUIRE(sm42.CurrentSwitch(true)); + REQUIRE(sm42.ShuntMode); + scenario.train().run(15.0, scenario.line()); + CHECK(security.is_vigilance_blinking()); + CHECK(security.is_beeping()); + CHECK(security.is_braking()); + CHECK(sm42.PipePress < 1.0); + scenario.act("acknowledged"); + sm42.SecuritySystemReset(); + scenario.train().run(1.0, scenario.line()); + CHECK_FALSE(security.is_blinking()); + CHECK_FALSE(security.is_braking()); + scenario.check(); +} + +namespace { + +TSecuritySystem sm42_security(bool const OffInShuntMode) { + TSecuritySystem security; + security.load(std::string{"Security: AwareSystem=Active AwareMinSpeed=0.0 AwareDelay=60 SoundSignalDelay=2.5 MaxHoldTime=1.0 " + "EmergencyBrakeDelay=2.5 AwareOffInShuntMode="} + + (OffInShuntMode ? "Yes" : "No"), + 90.0); + security.set_enabled(true); + security.update(0.1, 20.0, true, 1); + return security; +} + +void run(TSecuritySystem &Security, double const Seconds) { + for (int i = 0; i < std::lround(Seconds / 0.1); ++i) { + Security.update(0.1, 20.0, true, 1); + } +} + +} // namespace + +TEST_CASE("cab: the alerter in the shunt mode, with and without AwareOffInShuntMode") { + for (auto const off : {false, true}) { + CAPTURE(off); + auto security{sm42_security(off)}; + security.set_shunt_mode(true); + run(security, 120.0); + // without the key the shunt mode changes nothing: the alerter alerts and brakes + CHECK(security.is_vigilance_blinking() != off); + CHECK(security.is_braking() != off); + } +} + +TEST_CASE("cab: the alerter's alarm on, not cleared by the shunt mode") { + auto security{sm42_security(true)}; + run(security, 61.0); + REQUIRE(security.is_vigilance_blinking()); + REQUIRE_FALSE(security.is_braking()); + security.set_shunt_mode(true); + run(security, 10.0); + CHECK(security.is_vigilance_blinking()); + CHECK(security.is_beeping()); + CHECK(security.is_braking()); + security.acknowledge_press(); + security.acknowledge_release(); + run(security, 0.1); + CHECK_FALSE(security.is_blinking()); + CHECK_FALSE(security.is_braking()); + // then nothing more on the move in the shunt mode + run(security, 300.0); + CHECK_FALSE(security.is_blinking()); + // and back in the line mode the alerter counts again + security.set_shunt_mode(false); + run(security, 61.0); + CHECK(security.is_vigilance_blinking()); +} + +TEST_CASE("cab: the vigilance button held too long, its alarm not cleared by the shunt mode") { + // the alarm of the button held too long stays on in the shunt mode too, until the button is let go + TSecuritySystem security; + security.load("Security: AwareSystem=Active AwareMinSpeed=0.0 AwareDelay=60 SoundSignalDelay=2.5 MaxHoldTime=1.0 " + "EmergencyBrakeDelay=2.5 AwareOffInShuntMode=Yes", + 90.0); + security.set_enabled(true); + security.update(0.1, 20.0, true, 1); + security.acknowledge_press(); + for (int i = 0; i < 20; ++i) { + security.update(0.1, 20.0, true, 1); + } + REQUIRE(security.is_vigilance_blinking()); + security.set_shunt_mode(true); + for (int i = 0; i < 60; ++i) { + security.update(0.1, 20.0, true, 1); + } + CHECK(security.is_vigilance_blinking()); + CHECK(security.is_braking()); + security.acknowledge_release(); + security.update(0.1, 20.0, true, 1); + CHECK_FALSE(security.is_blinking()); + CHECK_FALSE(security.is_braking()); + // held again in the shunt mode, no new alarm + security.acknowledge_press(); + for (int i = 0; i < 100; ++i) { + security.update(0.1, 20.0, true, 1); + } + CHECK_FALSE(security.is_blinking()); + security.acknowledge_release(); + // out of the shunt mode, held too long again + security.set_shunt_mode(false); + security.acknowledge_press(); + for (int i = 0; i < 20; ++i) { + security.update(0.1, 20.0, true, 1); + } + CHECK(security.is_vigilance_blinking()); +}