18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-19 15:45:23 +01:00

fix: Elf emergency brake position vents the pipe only from the driven vehicle, coupled units agree on the controller position

The emergency position of the master controller vented the brake pipe from
every vehicle whose controller stood there, and "MainCtrl" reached the coupled
vehicles raw, so an Elf with EIMCtrlMainEmergency and one without it disagreed
by one notch (the full braking of one was the emergency brake of the other,
neutral of one a power position of the other). The pipe is now vented only
from the vehicle driven from (IsCabMaster()), and the position goes to the
coupled vehicles in the positions without the key (MainCtrlPosForCoupled(),
the emergency one as the full braking), each adding its own shift on receiving
it (MainCtrlPosFromCoupled()).

The loader's fix-up for the old MCPN=4 raises DirChangeMaxPos by the same
shift, so the reverser keeps working at the new neutral.
This commit is contained in:
jerrrrycho
2026-11-08 18:05:00 +01:00
parent 22c8e7322f
commit 97c483e827
3 changed files with 158 additions and 18 deletions

View File

@@ -5,6 +5,9 @@
#include "McZapkie/hamulce.h"
#include <initializer_list>
#include <string>
// the master controller of the Elf (EIMCtrlType 2): its positions, and the emergency brake position below
// them which EIMCtrlMainEmergency adds (eu07/maszyna#413)
@@ -13,16 +16,32 @@ using test::vehicle;
namespace {
// a three-car Elf ready to run, standing with its brakes released and the driver in the front cab of the
// head car, which also drives (the controller's eimic is worked out there)
// the data of an Elf: without the emergency brake position as now, with it in the files updated for it
// (EIMCtrlMainEmergency, MCPN=5, DirChangeMaxPos=4), or with the key alone added to the old files, which the
// loader fixes up
enum class data { plain, emergency, emergency_old_layout };
// three-car Elfs coupled into one train, of the given data each, ready to run, standing with their brakes
// released and the driver in the front cab of the head car of the first one, which also drives (the
// controller's eimic is worked out there)
struct elf {
explicit elf(bool Emergency) {
for (auto const *car : {"elf_v1/21we-a", "elf_v1/21we-b", "elf_v1/21we-c"}) {
auto cardefinition{definition::fiz(car)};
if (Emergency) {
cardefinition.set("Cntrl", "EIMCtrlMainEmergency", "Yes").set("Cntrl", "MCPN", 5);
explicit elf(bool Emergency) : elf({Emergency ? data::emergency : data::plain}) {}
explicit elf(std::initializer_list<data> Units) {
for (auto const units : Units) {
for (auto const *car : {"elf_v1/21we-a", "elf_v1/21we-b", "elf_v1/21we-c"}) {
auto cardefinition{definition::fiz(car)};
if (units != data::plain) {
cardefinition.set("Cntrl", "EIMCtrlMainEmergency", "Yes");
}
if (units == data::emergency) {
cardefinition.set("Cntrl", "MCPN", 5);
if (std::string{car} != "elf_v1/21we-b") {
// the cars with a cab have it, at neutral: 3 before, one up with the key
cardefinition.set("Cntrl", "DirChangeMaxPos", 4);
}
}
unit.add(cardefinition, unit.size() == 0 ? 1 : 0);
}
unit.add(cardefinition, unit.size() == 0 ? 1 : 0);
}
ready = test::start_up(test::driving(unit), line);
// the start-up of the tests leaves the controller at its position 0 (close_line_breaker() in drive.cpp),
@@ -48,6 +67,14 @@ struct elf {
wait(30.0);
}
TMoverParameters &cab() { return unit[0].mover(); }
TMoverParameters &car(std::size_t Index) { return unit[Index].mover(); }
// the driver moves the controller notch by notch, which the cab sends on to the coupled vehicles
void set_controller(int Position) {
while (cab().MainCtrlPos < Position && cab().IncMainCtrl(1)) {
}
while (cab().MainCtrlPos > Position && cab().DecMainCtrl(1)) {
}
}
void wait(double Seconds) { test::drive(test::driving(unit), line, Seconds); }
test::consist unit;
test::track line{0.15, 0.0, test::catenary_3kv};
@@ -124,6 +151,99 @@ TEST_CASE("elf controller: EIMCtrlMainEmergency with the old MCPN gets its posit
vehicle car{definition::fiz("elf_v1/21we-a").set("Cntrl", "EIMCtrlMainEmergency", "Yes")};
CHECK(car->MainCtrlPosNo == 5);
CHECK(car->MainCtrlNoPowerPos() == 4);
// DirChangeMaxPos=3 of the file, the old neutral, moves up with the positions
CHECK(car->MainCtrlMaxDirChangePos == 4);
}
TEST_CASE("elf controller: EIMCtrlMainEmergency leaves DirChangeMaxPos of the files updated for it alone") {
vehicle car{definition::fiz("elf_v1/21we-a").set("Cntrl", "EIMCtrlMainEmergency", "Yes").set("Cntrl", "MCPN", 5).set("Cntrl", "DirChangeMaxPos", 4)};
CHECK(car->MainCtrlPosNo == 5);
CHECK(car->MainCtrlMaxDirChangePos == 4);
}
TEST_CASE("elf controller: the reverser works at the neutral shifted by EIMCtrlMainEmergency") {
// the key added to the old files, DirChangeMaxPos=3 in them
elf unit{{data::emergency_old_layout}};
REQUIRE(unit.ready);
auto &mover{unit.cab()};
REQUIRE(mover.MainCtrlPos == mover.MainCtrlNoPowerPos());
REQUIRE(mover.DirActive == 1);
CHECK(mover.DirectionBackward());
CHECK(mover.DirActive == 0);
CHECK(mover.DirectionForward());
CHECK(mover.DirActive == 1);
// not in the power position
unit.set_controller(mover.MainCtrlNoPowerPos() + 1);
REQUIRE(mover.MainCtrlPos == 5);
CHECK_FALSE(mover.DirectionBackward());
CHECK(mover.DirActive == 1);
}
TEST_CASE("elf controller: the emergency brake position vents the pipe only from the vehicle driven from") {
elf unit{true};
REQUIRE(unit.ready);
REQUIRE(unit.charged);
// the rear car, with its own cab, has its controller in the emergency brake position, the driven one not
auto &rear{unit.car(2)};
rear.MainCtrlPos = 0;
CHECK(rear.IsMainCtrlEmergencyPos());
CHECK_FALSE(rear.IsCabMaster());
unit.wait(10.0);
CHECK(unit.cab().PipePress > 4.5);
CHECK(rear.PipePress > 4.5);
}
TEST_CASE("elf controller: an Elf with the emergency brake position leading one without it") {
elf unit{{data::emergency, data::plain}};
REQUIRE(unit.ready);
REQUIRE(unit.charged);
auto &lead{unit.cab()};
auto &other{unit.car(3)};
REQUIRE_FALSE(other.EIMCtrlMainEmergency);
// neutral of the lead is neutral of the other
CHECK(lead.MainCtrlPos == 4);
CHECK(other.MainCtrlPos == other.MainCtrlNoPowerPos());
SUBCASE("power") {
unit.set_controller(5);
CHECK(other.MainCtrlPos == 4);
}
SUBCASE("full braking") {
unit.set_controller(1);
CHECK(other.MainCtrlPos == 0);
unit.wait(10.0);
CHECK(lead.PipePress > 4.5);
}
SUBCASE("the emergency brake: the other one at its full braking, the pipe vented by the lead") {
unit.set_controller(0);
REQUIRE(lead.IsMainCtrlEmergencyPos());
CHECK(other.MainCtrlPos == 0);
unit.wait(10.0);
CHECK(lead.PipePress < 0.5);
CHECK(other.PipePress < 0.5);
}
}
TEST_CASE("elf controller: an Elf without the emergency brake position leading one with it") {
elf unit{{data::plain, data::emergency}};
REQUIRE(unit.ready);
REQUIRE(unit.charged);
auto &lead{unit.cab()};
auto &other{unit.car(3)};
REQUIRE(other.EIMCtrlMainEmergency);
CHECK(lead.MainCtrlPos == 3);
CHECK(other.MainCtrlPos == other.MainCtrlNoPowerPos());
SUBCASE("power") {
unit.set_controller(4);
CHECK(other.MainCtrlPos == 5);
}
SUBCASE("the full braking of the lead is the full braking of the other, not its emergency brake") {
unit.set_controller(0);
CHECK(other.MainCtrlPos == 1);
CHECK_FALSE(other.IsMainCtrlEmergencyPos());
unit.wait(10.0);
CHECK(lead.PipePress > 4.5);
CHECK(other.PipePress > 4.5);
}
}
TEST_CASE("elf controller: EIMCtrlMainEmergency leaves the other controllers alone") {