From 87f1d960a094f5f2f17eb69170df5f9d806a6ba9 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sun, 8 Nov 2026 04:25:34 +0100 Subject: [PATCH 1/4] fix: EN57 brakes hauled with the brake hose alone, Knorr EP brake without control power eu07/maszyna#87: the EP2 (and EP1) valve charged its auxiliary reservoir only from the main reservoir pipe. A dead EN57 hauled by a locomotive coupled with the hook and the brake hose alone ("3") never charged it, its control reservoir stopped at about 2.5 bar and the unit didn't brake. The valve now refills the auxiliary reservoir from the brake pipe through the slide valve's check valve, as every ESt does (TESt::FillBrakeRes, shared with TESt::GetPF, which stays bit for bit the same). With the main reservoir pipe charged the auxiliary reservoir stays above the brake pipe and nothing changes; the reservoir now also takes air from the brake pipe while it is below it, e.g. at start-up before the compressor has charged the main reservoir pipe. eu07/maszyna#134: the EP brake of the Knorr St113 handle (EN57-001) worked with the reverser in neutral, the battery off or the EP fuse switched off (Ctrl+Z). It now needs the control powered, as the Oerlikon handle's does (EPBrakeControlPowered: battery, reverser out of neutral, EP fuse), and an EP brake switched on drops out (holding the cylinder pressure) when the control loses power. The positions of the EP release and brake were already moved by 810b7ad07; a test pins them. No change to game data needed. --- McZapkie/MOVER.h | 2 + McZapkie/Mover.cpp | 15 ++++- McZapkie/hamulce.cpp | 36 ++++++++--- McZapkie/hamulce.h | 9 +++ tests/unit/test_brake_handles.cpp | 103 ++++++++++++++++++++++++++++++ tests/unit/test_brakes.cpp | 46 +++++++++++++ 6 files changed, 200 insertions(+), 11 deletions(-) diff --git a/McZapkie/MOVER.h b/McZapkie/MOVER.h index 16bb207f..e6d6296a 100644 --- a/McZapkie/MOVER.h +++ b/McZapkie/MOVER.h @@ -2413,6 +2413,8 @@ class TMoverParameters bool BrakeReleaser(int state); bool UniversalBrakeButton(int button, int state); /*uniwersalny przycisk hamulca*/ bool SwitchEPBrake(int state); + // whether the EP brake control of the cab has power: battery, the reverser out of neutral and the EP fuse on + bool EPBrakeControlPowered() const; bool AntiSlippingButton(void); /*! reczny wlacznik urzadzen antyposlizgowych*/ /*funkcje dla ukladow pneumatycznych*/ diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index 20761bac..6e38ad14 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -4161,7 +4161,8 @@ bool TMoverParameters::SwitchEPBrake(int state) OK = false; if (BrakeHandle == TBrakeHandle::St113 && CabOccupied != 0) { - if (state > 0) + // the handle works the EP contactors pneumatically, their supply is cut as the Oerlikon handle's is + if (state > 0 && EPBrakeControlPowered()) EpForce = Handle->GetEP(); // TODO: przetlumaczyc else EpForce = 0; @@ -4173,6 +4174,11 @@ bool TMoverParameters::SwitchEPBrake(int state) return OK; } +bool TMoverParameters::EPBrakeControlPowered() const +{ + return Power24vIsAvailable && DirActive != 0 && EpFuse; +} + // ************************************************************************************************* // Q: 20160711 // zwiększenie ciśnienia hamowania @@ -4706,7 +4712,7 @@ void TMoverParameters::UpdatePipePressure(double dt) if ((BrakeHandle == TBrakeHandle::FVel6 || BrakeHandle == TBrakeHandle::FVE408) && CabOccupied != 0) { - if (Power24vIsAvailable && DirActive != 0 && EpFuse) // tu powinien byc jeszcze bezpiecznik EP i baterie - + if (EPBrakeControlPowered()) // tu powinien byc jeszcze bezpiecznik EP i baterie - // temp = (Handle as TFVel6).GetCP EpForce = Handle->GetEP(); else @@ -4725,6 +4731,11 @@ void TMoverParameters::UpdatePipePressure(double dt) // Ra 2014-11: na tym się wysypuje, ale nie wiem, w jakich warunkach SendCtrlToNext("Brake", EpForce, CabActive); } + else if (BrakeHandle == TBrakeHandle::St113 && CabOccupied != 0 && std::abs(EpForce) > 0.001 && !EPBrakeControlPowered()) + { + // the EP brake switched on with the button drops out with the control's supply + SwitchEPBrake(0); + } Pipe->Act(); PipePress = Pipe->P(); diff --git a/McZapkie/hamulce.cpp b/McZapkie/hamulce.cpp index c0a7d2a0..da0a9811 100644 --- a/McZapkie/hamulce.cpp +++ b/McZapkie/hamulce.cpp @@ -968,6 +968,28 @@ double TESt::BVs(double const BCP) const return 0; } +/// +/// Refills the auxiliary reservoir (ZP) from the valve pre-chamber through the +/// check valve of the slide valve, opened as far as says for the +/// given cylinder (or impulse-chamber) pressure, while the pre-chamber is more +/// than 0.05 bar above the reservoir. The flows wait for the caller's Act(). +/// +/// Brake cylinder (or impulse-chamber) pressure. +/// Time step [s]. +/// Volume taken into the auxiliary reservoir, 0.96 of it drawn from the brake pipe. +double TESt::FillBrakeRes(double const BCP, double const dt) +{ + double const BVP{BrakeRes->P()}; + double const VVP{ValveRes->P()}; + double const temp{BVs(BCP)}; + double dv{0.0}; + if (VVP - 0.05 > BVP) + dv = PF(BVP, VVP, 0.02 * SizeBR * temp / 1.87) * dt; + BrakeRes->Flow(dv); + ValveRes->Flow(-0.04 * dv); + return dv; +} + /// /// One-step Oerlikon ESt distributor advance: runs CheckState/CheckReleaser, /// integrates the ZS <-> PG, ZP <-> cylinder, ZP <-> pre-chamber and @@ -1021,15 +1043,7 @@ double TESt::GetPF(double const PP, double const dt, double const Vel) BrakeCyl->Flow(-dv); // przeplyw ZP <-> rozdzielacz - temp = BVs(BCP); - // if(BrakeStatus and b_hld)=b_off then - if (VVP - 0.05 > BVP) - dv = PF(BVP, VVP, 0.02 * SizeBR * temp / 1.87) * dt; - else - dv = 0; - BrakeRes->Flow(dv); - dV1 = dV1 + dv * 0.96; - ValveRes->Flow(-0.04 * dv); + dV1 = dV1 + FillBrakeRes(BCP, dt) * 0.96; // przeplyw PG <-> rozdzielacz dv = PF(PP, VVP, 0.01) * dt; ValveRes->Flow(-dv); @@ -1191,6 +1205,10 @@ double TEStEP2::GetPF(double const PP, double const dt, double const Vel) ValveRes->Flow(-0.04 * dv); dV1 = dV1 - 0.96 * dv; + // przeplyw ZP <-> rozdzielacz: as in every ESt, the auxiliary reservoir also charges from the brake pipe, + // not from the main reservoir pipe alone, so a unit hauled with the brake hose alone charges and brakes + dV1 = dV1 + FillBrakeRes(BCP, dt) * 0.96; + // hamulec EP EPCalc(dt); diff --git a/McZapkie/hamulce.h b/McZapkie/hamulce.h index 37b9b6a4..b9a5ffd1 100644 --- a/McZapkie/hamulce.h +++ b/McZapkie/hamulce.h @@ -620,6 +620,15 @@ class TESt : public TBrake /// Brake cylinder pressure. /// Dimensionless opening coefficient. double BVs(double BCP) const; // napelniacz pomocniczego + /// + /// Refills the auxiliary reservoir (ZP) from the valve pre-chamber through the + /// check valve of the slide valve, opened as far as says, while + /// the pre-chamber is above the reservoir. The flows wait for the caller's Act(). + /// + /// Brake cylinder (or impulse-chamber) pressure for . + /// Time step [s]. + /// Volume taken into the auxiliary reservoir, 0.96 of it drawn from the brake pipe. + double FillBrakeRes(double BCP, double dt); // napelnianie pomocniczego z rozdzielacza /// Vents the valve, brake and control reservoirs to zero. void ForceEmptiness() override; // wymuszenie bycia pustym diff --git a/tests/unit/test_brake_handles.cpp b/tests/unit/test_brake_handles.cpp index 51c25243..e6b43547 100644 --- a/tests/unit/test_brake_handles.cpp +++ b/tests/unit/test_brake_handles.cpp @@ -4,6 +4,7 @@ #include "golden.h" #include "real_vehicles.h" #include "drive.h" +#include "consist.h" #include "McZapkie/hamulce.h" @@ -152,3 +153,105 @@ TEST_CASE("brake handles: the overload and the high pressure buttons of the MHZ trace.check(); } } + +// eu07/maszyna#134: the Knorr St113 of the EN57-001 releases the EP brake in the running position (bh_RP, Num 6) +// and applies it one position on (Num 8), short of the lap position (Num 5); the positions are those the keys +// select, and the EP brake works only with the control of the cab powered: the battery, the reverser out of +// neutral and the EP fuse on (Ctrl+Z), as the Oerlikon handle's +namespace { + +// the front car of the EN57-001 driven from its cab, with the motor car behind it, which has the battery of the two; +// air in the reservoirs, the battery on +void ready_knorr_ep(test::consist &Unit) { + Unit.add(definition::fiz("en57_v1/6bai"), 1); + Unit.add(definition::fiz("en57_v1/5bgb")); + auto &cab{Unit[0]}; + REQUIRE(cab->BrakeHandle == TBrakeHandle::St113); + cab->BatterySwitch(true); + cab->CabActivisation(); + cab.hold_brake_pipe(5.0); + cab->BrakeLevelSet(cab->Handle->GetPos(bh_RP)); + Unit.run(60.0); +} + +// the EP brake button pressed in the given handle position, held for Seconds; the cylinder pressure of the cab car +double ep_brake(test::consist &Unit, double Position, double Seconds) { + auto &cab{Unit[0]}; + cab->BrakeLevelSet(Position); + Unit.run(0.1); + cab->SwitchEPBrake(1); + Unit.run(Seconds); + return cab->BrakePress; +} + +} // namespace + +TEST_CASE("brake handles: the positions of the Knorr St113 EP brake") { + test::consist unit; + ready_knorr_ep(unit); + auto &cab{unit[0]}; + auto &handle{*cab->Handle}; + auto const ep_at{[&unit, &cab, &handle](double Position) { + cab->BrakeLevelSet(Position); + unit.run(0.1); + return handle.GetEP(); + }}; + // the keys: Num 6 running, Num 8 the first position on, Num 5 the middle of the handle + CHECK(handle.GetPos(bh_RP) == doctest::Approx(0.0)); + CHECK(ep_at(0.0) == doctest::Approx(-1.0)); // EP release + CHECK(ep_at(1.0) == doctest::Approx(1.0)); // EP brake + CHECK(ep_at(cab->BrakeCtrlPosNo / 2) == doctest::Approx(0.0)); // lap, Num 5 + CHECK(ep_at(handle.GetPos(bh_FB)) == doctest::Approx(0.0)); + CHECK(ep_at(handle.GetPos(bh_EPR)) == doctest::Approx(-1.0)); + CHECK(ep_at(handle.GetPos(bh_EPB)) == doctest::Approx(1.0)); +} + +TEST_CASE("brake handles: the Knorr St113 EP brake needs the control of the cab powered") { + for (std::string const cut : {"reverser in neutral", "EP fuse off", "battery off"}) { + CAPTURE(cut); + test::consist unit; + ready_knorr_ep(unit); + auto &cab{unit[0]}; + cab->DirectionForward(); + unit.run(1.0); + REQUIRE(cab->EPBrakeControlPowered()); + if (cut == "reverser in neutral") { + cab->DirectionBackward(); + } + else if (cut == "EP fuse off") { + cab->EpFuseSwitch(false); + } + else { + cab->BatterySwitch(false); + } + unit.run(1.0); + REQUIRE_FALSE(cab->EPBrakeControlPowered()); + // the button in the EP brake position does nothing + CHECK(ep_brake(unit, 1.0, 5.0) < 0.1); + CHECK(cab->EpForce == doctest::Approx(0.0)); + cab->SwitchEPBrake(0); + } + + test::consist unit; + ready_knorr_ep(unit); + auto &cab{unit[0]}; + cab->DirectionForward(); + unit.run(1.0); + // powered, the EP brake applies + auto const applied{ep_brake(unit, 1.0, 2.0)}; + CHECK(applied > 0.5); + // the reverser put to neutral with the button still held: the EP brake drops out and holds what it applied + cab->DirectionBackward(); + unit.run(0.1); + CHECK(cab->EpForce == doctest::Approx(0.0)); + auto const held{cab->BrakePress}; + unit.run(5.0); + CHECK(cab->BrakePress < held + 0.05); + CHECK(cab->BrakePress > 0.2); + // and doesn't release either, until the control is powered again + CHECK(ep_brake(unit, 0.0, 5.0) > 0.2); + cab->SwitchEPBrake(0); + cab->DirectionForward(); + unit.run(0.1); + CHECK(ep_brake(unit, 0.0, 10.0) < 0.1); +} diff --git a/tests/unit/test_brakes.cpp b/tests/unit/test_brakes.cpp index 83416807..e12694f3 100644 --- a/tests/unit/test_brakes.cpp +++ b/tests/unit/test_brakes.cpp @@ -1,6 +1,7 @@ #include "stdafx.h" #include "doctest.h" #include "vehicle.h" +#include "consist.h" using test::definition; using test::vehicle; @@ -91,3 +92,48 @@ TEST_CASE("brakes: service braking stops a heavier wagon too") { wagon.run(40.0 /* s */, test::track{0.15 /* friction */, 0.0 /* gradient */}); CHECK(std::abs(wagon.speed()) < 0.1); } + +// eu07/maszyna#87: the ESt4d of the EN57's EP2 valve charged its auxiliary reservoir from the main reservoir pipe +// alone, so a dead unit hauled by a locomotive coupled with the hook and the brake hose ("3") never charged it, +// its control reservoir stopped half way, and it didn't brake. Like every ESt, it charges from the brake pipe too +TEST_CASE("brakes: a dead EN57 hauled with the brake hose alone charges from the brake pipe and brakes") { + test::consist train; + auto &locomotive{train.add(definition::fiz("sm42_v1/6d1"))}; + train.add(definition::fiz("en57_v1/5bgb"), 0, coupling::coupler | coupling::brakehose); + train.add(definition::fiz("en57_v1/6ba_840")); + train.add(definition::fiz("en57_v1/5bgaiii_led_spot")); + // a unit standing dead: no air anywhere, nothing in its main reservoir pipe + for (std::size_t i = 1; i < train.size(); ++i) { + auto &car{train[i].mover()}; + REQUIRE(car.BrakeValve == TBrakeValve::EP2); + car.Hamulec->ForceEmptiness(); + car.Pipe->CreatePress(0.0); + car.Pipe->Act(); + car.Pipe2->CreatePress(0.0); + car.Pipe2->Act(); + car.CompressedVolume = 0.0; + } + locomotive.hold_brake_pipe(5.0); + train.run(900.0); + for (std::size_t i = 1; i < train.size(); ++i) { + CAPTURE(i); + auto &car{train[i].mover()}; + REQUIRE(car.ScndPipePress < 0.1); // no main reservoir pipe + CHECK(car.Hamulec->GetBRP() > 4.8); + CHECK(car.Hamulec->GetCRP() > 4.8); + CHECK(car.BrakePress < 0.1); + } + // a full service application brakes the unit, and it releases again + locomotive.hold_brake_pipe(3.5); + train.run(20.0); + for (std::size_t i = 1; i < train.size(); ++i) { + CAPTURE(i); + CHECK(train[i]->BrakePress > 2.0); + } + locomotive.hold_brake_pipe(5.0); + train.run(60.0); + for (std::size_t i = 1; i < train.size(); ++i) { + CAPTURE(i); + CHECK(train[i]->BrakePress < 0.1); + } +} From 200d3ae73b25ffa355bb4e40ebc220d5015397e0 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sun, 8 Nov 2026 17:37:56 +0100 Subject: [PATCH 2/4] fix: review of the EN57 EP brake (Sonar null check, EP fuse of the cab car, AI re-asserts the EP brake) - tests: REQUIRE the brake handle before dereferencing it (Sonar cpp:S2259) - TESt::FillBrakeRes is const (S5817) - cab EP brake command: drop the mvControlled->EpFuse check, SwitchEPBrake already checks the cab car's (mvOccupied) EP fuse with the control supply - AI: with the handle already at the EP brake position, switch the EP brake on again once the control supply is back --- McZapkie/hamulce.cpp | 2 +- McZapkie/hamulce.h | 2 +- tests/unit/test_brake_handles.cpp | 5 +++++ vehicle/Driver.cpp | 8 ++++++++ vehicle/Train.cpp | 4 +++- 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/McZapkie/hamulce.cpp b/McZapkie/hamulce.cpp index da0a9811..9411dc42 100644 --- a/McZapkie/hamulce.cpp +++ b/McZapkie/hamulce.cpp @@ -977,7 +977,7 @@ double TESt::BVs(double const BCP) const /// Brake cylinder (or impulse-chamber) pressure. /// Time step [s]. /// Volume taken into the auxiliary reservoir, 0.96 of it drawn from the brake pipe. -double TESt::FillBrakeRes(double const BCP, double const dt) +double TESt::FillBrakeRes(double const BCP, double const dt) const { double const BVP{BrakeRes->P()}; double const VVP{ValveRes->P()}; diff --git a/McZapkie/hamulce.h b/McZapkie/hamulce.h index b9a5ffd1..2fb433a8 100644 --- a/McZapkie/hamulce.h +++ b/McZapkie/hamulce.h @@ -628,7 +628,7 @@ class TESt : public TBrake /// Brake cylinder (or impulse-chamber) pressure for . /// Time step [s]. /// Volume taken into the auxiliary reservoir, 0.96 of it drawn from the brake pipe. - double FillBrakeRes(double BCP, double dt); // napelnianie pomocniczego z rozdzielacza + double FillBrakeRes(double BCP, double dt) const; // napelnianie pomocniczego z rozdzielacza /// Vents the valve, brake and control reservoirs to zero. void ForceEmptiness() override; // wymuszenie bycia pustym diff --git a/tests/unit/test_brake_handles.cpp b/tests/unit/test_brake_handles.cpp index e6b43547..1490e43d 100644 --- a/tests/unit/test_brake_handles.cpp +++ b/tests/unit/test_brake_handles.cpp @@ -36,6 +36,7 @@ void hold(vehicle &Vehicle, test::trace &Trace, std::string const &Event, double // every position of the driver's handle, recorded in the trace void every_position(vehicle &Vehicle, test::trace &Trace) { Vehicle.hold_main_reservoir(std::max(Vehicle->MaxCompressor, 8.0)); + REQUIRE(Vehicle->Handle != nullptr); auto &handle{*Vehicle->Handle}; Vehicle.record(Trace); @@ -97,6 +98,7 @@ TEST_CASE("brake handles: the local brake handle of every real vehicle") { real.hold_main_reservoir(std::max(real->MaxCompressor, 8.0)); test::trace trace{"local brake/" + path, handle_channels(), 100}; real.record(trace); + REQUIRE(real->Handle != nullptr); real->BrakeLevelSet(real->Handle->GetPos(bh_RP)); trace.mark("charge"); real.run(60.0); @@ -127,6 +129,7 @@ TEST_CASE("brake handles: the overload and the high pressure buttons of the MHZ real.hold_main_reservoir(std::max(real->MaxCompressor, 8.0)); test::trace trace{"brake handles/buttons/" + name, handle_channels(), 100}; real.record(trace); + REQUIRE(real->Handle != nullptr); auto &handle{*real->Handle}; auto const at{[&trace, &real](std::string const &Event, double Position, double Seconds) { trace.mark(Event); @@ -167,6 +170,7 @@ void ready_knorr_ep(test::consist &Unit) { Unit.add(definition::fiz("en57_v1/5bgb")); auto &cab{Unit[0]}; REQUIRE(cab->BrakeHandle == TBrakeHandle::St113); + REQUIRE(cab->Handle != nullptr); cab->BatterySwitch(true); cab->CabActivisation(); cab.hold_brake_pipe(5.0); @@ -190,6 +194,7 @@ TEST_CASE("brake handles: the positions of the Knorr St113 EP brake") { test::consist unit; ready_knorr_ep(unit); auto &cab{unit[0]}; + REQUIRE(cab->Handle != nullptr); auto &handle{*cab->Handle}; auto const ep_at{[&unit, &cab, &handle](double Position) { cab->BrakeLevelSet(Position); diff --git a/vehicle/Driver.cpp b/vehicle/Driver.cpp index 9f83b6d5..d174a377 100644 --- a/vehicle/Driver.cpp +++ b/vehicle/Driver.cpp @@ -3126,6 +3126,14 @@ bool TController::IncBrake() mvOccupied->SwitchEPBrake( 1 ); // to nie chce działać OK = true; } + else if( ( mvOccupied->Handle->GetPos( bh_EPR ) - mvOccupied->Handle->GetPos( bh_EPN ) < 0.1 ) + && ( mvOccupied->EpForce <= 0.0 ) + && ( mvOccupied->EPBrakeControlPowered() ) ) { + // the handle already in the EP brake position, but the EP brake dropped out with the control's + // supply (e.g. the EP fuse off in the running brake test): switch it on again + mvOccupied->SwitchEPBrake( 1 ); + OK = ( mvOccupied->EpForce > 0.0 ); + } else OK = false; break; diff --git a/vehicle/Train.cpp b/vehicle/Train.cpp index e30635f4..333d99a6 100644 --- a/vehicle/Train.cpp +++ b/vehicle/Train.cpp @@ -2235,7 +2235,9 @@ void TTrain::OnCommand_wheelspinbrakeactivate(TTrain *Train, command_data const // visual feedback Train->ggAntiSlipButton.UpdateValue(1.0, Train->dsbPneumaticSwitch); - if (Train->mvOccupied->BrakeHandle == TBrakeHandle::St113 && Train->mvControlled->EpFuse == true) + // the EP fuse is the cab car's (Ctrl+Z switches mvOccupied's), checked by SwitchEPBrake with the rest of + // the control's supply + if (Train->mvOccupied->BrakeHandle == TBrakeHandle::St113) { Train->mvOccupied->SwitchEPBrake(1); } From 7ba478aea96bc52d59e3610fa077115b329966ec Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sun, 8 Nov 2026 19:30:46 +0100 Subject: [PATCH 3/4] test: reach the mover by reference in the brake handle lambdas (Sonar S2259) The lambdas of the St113 EP brake and the MHZ buttons tests called the mover through test::vehicle::operator->(), which the analyser takes as possibly null; they capture a reference from mover() instead. --- tests/unit/test_brake_handles.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/unit/test_brake_handles.cpp b/tests/unit/test_brake_handles.cpp index 1490e43d..eeecac75 100644 --- a/tests/unit/test_brake_handles.cpp +++ b/tests/unit/test_brake_handles.cpp @@ -131,9 +131,10 @@ TEST_CASE("brake handles: the overload and the high pressure buttons of the MHZ real.record(trace); REQUIRE(real->Handle != nullptr); auto &handle{*real->Handle}; - auto const at{[&trace, &real](std::string const &Event, double Position, double Seconds) { + auto &mover{real.mover()}; + auto const at{[&trace, &real, &mover](std::string const &Event, double Position, double Seconds) { trace.mark(Event); - real->BrakeLevelSet(Position); + mover.BrakeLevelSet(Position); test::drive(test::driving(real), {}, Seconds); }}; at("running", handle.GetPos(bh_RP), 60.0); @@ -196,8 +197,9 @@ TEST_CASE("brake handles: the positions of the Knorr St113 EP brake") { auto &cab{unit[0]}; REQUIRE(cab->Handle != nullptr); auto &handle{*cab->Handle}; - auto const ep_at{[&unit, &cab, &handle](double Position) { - cab->BrakeLevelSet(Position); + auto &mover{cab.mover()}; + auto const ep_at{[&unit, &mover, &handle](double Position) { + mover.BrakeLevelSet(Position); unit.run(0.1); return handle.GetEP(); }}; From db65dfa5f0ef58370dad7802fc0d44d83d628984 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sun, 8 Nov 2026 21:15:12 +0100 Subject: [PATCH 4/4] test: file-local helpers instead of lambdas in the brake handle tests (Sonar S2259) The analyser loses track of references captured by lambdas; the St113 EP and MHZ buttons tests call plain helpers, as ep_brake() and ready_knorr_ep() do, which it doesn't report. --- tests/unit/test_brake_handles.cpp | 49 ++++++++++++++++--------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/tests/unit/test_brake_handles.cpp b/tests/unit/test_brake_handles.cpp index eeecac75..889beb33 100644 --- a/tests/unit/test_brake_handles.cpp +++ b/tests/unit/test_brake_handles.cpp @@ -59,6 +59,13 @@ void every_position(vehicle &Vehicle, test::trace &Trace) { hold(Vehicle, Trace, "running", handle.GetPos(bh_RP), 60.0); } +// the handle put to the given position and the vehicle driven from its cab for Seconds, marked in the trace +void driven_at(vehicle &Vehicle, test::trace &Trace, std::string const &Event, double Position, double Seconds) { + Trace.mark(Event); + Vehicle->BrakeLevelSet(Position); + test::drive(test::driving(Vehicle), {}, Seconds); +} + } // namespace TEST_CASE("brake handles: every position of the driver's handle of every real vehicle") { @@ -131,25 +138,19 @@ TEST_CASE("brake handles: the overload and the high pressure buttons of the MHZ real.record(trace); REQUIRE(real->Handle != nullptr); auto &handle{*real->Handle}; - auto &mover{real.mover()}; - auto const at{[&trace, &real, &mover](std::string const &Event, double Position, double Seconds) { - trace.mark(Event); - mover.BrakeLevelSet(Position); - test::drive(test::driving(real), {}, Seconds); - }}; - at("running", handle.GetPos(bh_RP), 60.0); + driven_at(real, trace, "running", handle.GetPos(bh_RP), 60.0); auto const running{real->PipePress}; handle.SetUniversalFlag(TUniversalBrake::ub_Overload); - at("overload button", handle.GetPos(bh_RP), 30.0); + driven_at(real, trace, "overload button", handle.GetPos(bh_RP), 30.0); handle.SetUniversalFlag(0); auto const overloaded{real->PipePress}; - at("overload decaying", handle.GetPos(bh_RP), 240.0); + driven_at(real, trace, "overload decaying", handle.GetPos(bh_RP), 240.0); auto const decayed{real->PipePress}; handle.SetUniversalFlag(TUniversalBrake::ub_HighPressure); - at("high pressure button, filling stroke", handle.GetPos(bh_FS), 10.0); + driven_at(real, trace, "high pressure button, filling stroke", handle.GetPos(bh_FS), 10.0); auto const filled{real->PipePress}; handle.SetUniversalFlag(0); - at("running", handle.GetPos(bh_RP), 120.0); + driven_at(real, trace, "running", handle.GetPos(bh_RP), 120.0); CHECK(running == doctest::Approx(5.0).epsilon(0.01)); CHECK(overloaded > running + 0.3); CHECK(decayed < overloaded); @@ -189,6 +190,14 @@ double ep_brake(test::consist &Unit, double Position, double Seconds) { return cab->BrakePress; } +// the EP force the St113 handle of the cab car gives in the given position +double ep_at(test::consist &Unit, double Position) { + auto &cab{Unit[0]}; + cab->BrakeLevelSet(Position); + Unit.run(0.1); + return cab->Handle->GetEP(); +} + } // namespace TEST_CASE("brake handles: the positions of the Knorr St113 EP brake") { @@ -197,20 +206,14 @@ TEST_CASE("brake handles: the positions of the Knorr St113 EP brake") { auto &cab{unit[0]}; REQUIRE(cab->Handle != nullptr); auto &handle{*cab->Handle}; - auto &mover{cab.mover()}; - auto const ep_at{[&unit, &mover, &handle](double Position) { - mover.BrakeLevelSet(Position); - unit.run(0.1); - return handle.GetEP(); - }}; // the keys: Num 6 running, Num 8 the first position on, Num 5 the middle of the handle CHECK(handle.GetPos(bh_RP) == doctest::Approx(0.0)); - CHECK(ep_at(0.0) == doctest::Approx(-1.0)); // EP release - CHECK(ep_at(1.0) == doctest::Approx(1.0)); // EP brake - CHECK(ep_at(cab->BrakeCtrlPosNo / 2) == doctest::Approx(0.0)); // lap, Num 5 - CHECK(ep_at(handle.GetPos(bh_FB)) == doctest::Approx(0.0)); - CHECK(ep_at(handle.GetPos(bh_EPR)) == doctest::Approx(-1.0)); - CHECK(ep_at(handle.GetPos(bh_EPB)) == doctest::Approx(1.0)); + CHECK(ep_at(unit, 0.0) == doctest::Approx(-1.0)); // EP release + CHECK(ep_at(unit, 1.0) == doctest::Approx(1.0)); // EP brake + CHECK(ep_at(unit, cab->BrakeCtrlPosNo / 2) == doctest::Approx(0.0)); // lap, Num 5 + CHECK(ep_at(unit, handle.GetPos(bh_FB)) == doctest::Approx(0.0)); + CHECK(ep_at(unit, handle.GetPos(bh_EPR)) == doctest::Approx(-1.0)); + CHECK(ep_at(unit, handle.GetPos(bh_EPB)) == doctest::Approx(1.0)); } TEST_CASE("brake handles: the Knorr St113 EP brake needs the control of the cab powered") {