18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-02 21:15:20 +01:00

refactor(physics): the parts of the main circuit keep their state to themselves

The line breaker, the line contactors, the protective relays and the converter
(physics/components/maincircuit.h) become classes: what the .fiz defines is in
their public `config`, their state is private, read through queries
(IsClosed(), UndervoltageHolds(), IsRunning()) and changed through operations
(Close(), ResetGround(), Switch()). The logic that concerns only them moves in:
the initialisation of the main circuit, the ground relay, the pressure switch,
the resets of the relays, and the whole step of the converter, which gets what
it needs from the vehicle as plain values (ConverterSupply).

The vehicle still decides when they act (the interlocks, the controller
positions, the voltages); the parts don't take a physics::Vehicle.

No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
This commit is contained in:
2026-11-29 09:37:01 +01:00
parent dfb43c4f05
commit 22ebc41d70
53 changed files with 789 additions and 654 deletions
+17 -17
View File
@@ -39,7 +39,7 @@ void prepare(consist &Train) {
}
bool running(physics::Vehicle const &Vehicle) {
return Vehicle.lineBreaker.closed && Vehicle.enrot > 0.5 * Vehicle.diesel.minRevolutions;
return Vehicle.lineBreaker.IsClosed() && Vehicle.enrot > 0.5 * Vehicle.diesel.minRevolutions;
}
// the time step of the train in the loops below
@@ -65,8 +65,8 @@ TEST_CASE("engine start: the joint start is the default, and JointEngineStart=No
consist train;
auto const &joint{train.add(sn61(), 1).physics()};
auto const &separate{train.add(sn61(false)).physics()};
CHECK(joint.lineBreaker.jointStart);
CHECK_FALSE(separate.lineBreaker.jointStart);
CHECK(joint.lineBreaker.config.jointStart);
CHECK_FALSE(separate.lineBreaker.config.jointStart);
CHECK(joint.MainSwitchRange() == range_t::consist);
CHECK(separate.MainSwitchRange() == range_t::local);
}
@@ -120,16 +120,16 @@ TEST_CASE("engine start: by default the cab's switch starts and stops the engine
auto &first{train.add(sn61(), 1).physics()};
auto const &second{train.add(sn61()).physics()};
prepare(train);
REQUIRE_FALSE(first.lineBreaker.closed);
REQUIRE_FALSE(second.lineBreaker.closed);
REQUIRE_FALSE(first.lineBreaker.IsClosed());
REQUIRE_FALSE(second.lineBreaker.IsClosed());
first.MainSwitch(true, first.MainSwitchRange());
train.run(15.0);
CHECK(running(first));
CHECK(running(second));
first.MainSwitch(false, first.MainSwitchRange());
train.run(5.0);
CHECK_FALSE(first.lineBreaker.closed);
CHECK_FALSE(second.lineBreaker.closed);
CHECK_FALSE(first.lineBreaker.IsClosed());
CHECK_FALSE(second.lineBreaker.IsClosed());
}
TEST_CASE("engine start: with JointEngineStart=No each engine has its own switch") {
@@ -142,8 +142,8 @@ TEST_CASE("engine start: with JointEngineStart=No each engine has its own switch
first.MainSwitch(true, first.MainSwitchRange());
train.run(15.0);
REQUIRE(running(first));
CHECK_FALSE(second.lineBreaker.closed);
CHECK_FALSE(third.lineBreaker.closed);
CHECK_FALSE(second.lineBreaker.IsClosed());
CHECK_FALSE(third.lineBreaker.IsClosed());
// the second one's switch, mainb_*, starts the second engine
engine_start::remote_switch switchb;
@@ -155,7 +155,7 @@ TEST_CASE("engine start: with JointEngineStart=No each engine has its own switch
hold(train, switchb, engineb, 2.0); // past the SN61's delay of 1.5 s
train.run(15.0);
CHECK(running(second));
CHECK_FALSE(third.lineBreaker.closed);
CHECK_FALSE(third.lineBreaker.IsClosed());
// and the third one's, mainc_*, the third
hold(train, switchc, enginec, 2.0);
train.run(15.0);
@@ -164,12 +164,12 @@ TEST_CASE("engine start: with JointEngineStart=No each engine has its own switch
// the switches open their own vehicles' circuits only
CHECK(engine_start::remote_switch::open(second));
train.run(5.0);
CHECK_FALSE(second.lineBreaker.closed);
CHECK_FALSE(second.lineBreaker.IsClosed());
CHECK(running(first));
CHECK(running(third));
first.MainSwitch(false, first.MainSwitchRange());
train.run(5.0);
CHECK_FALSE(first.lineBreaker.closed);
CHECK_FALSE(first.lineBreaker.IsClosed());
CHECK(running(third));
CHECK_FALSE(engine_start::remote_switch::open(second)); // already stopped
}
@@ -184,7 +184,7 @@ TEST_CASE("engine start: the switch of another vehicle is held for the vehicle's
// without the battery the switch does nothing, however long it's held
hold(train, switchb, &second, 5.0);
train.run(5.0);
CHECK_FALSE(second.lineBreaker.closed);
CHECK_FALSE(second.lineBreaker.IsClosed());
CHECK_FALSE(second.diesel.startupRequested);
prepare(train);
@@ -245,7 +245,7 @@ TEST_CASE("engine start: an engine stopping on its own stops the others only whe
// the first one's fuel cut off, its engine stops
first.FuelPump.is_disabled = true;
train.run(15.0);
CHECK_FALSE(first.lineBreaker.closed);
CHECK_FALSE(first.lineBreaker.IsClosed());
CHECK(first.enrot == 0.0);
// started on their own, the others keep running
CHECK(running(second) == (false == joint));
@@ -275,7 +275,7 @@ TEST_CASE("engine start: an engine stopped from its own switch doesn't stop the
// mainb_off
CHECK(engine_start::remote_switch::open(second));
train.run(30.0);
CHECK_FALSE(second.lineBreaker.closed);
CHECK_FALSE(second.lineBreaker.IsClosed());
CHECK(second.enrot == 0.0);
CHECK(running(first));
CHECK(running(third));
@@ -287,12 +287,12 @@ TEST_CASE("engine start: the stopped engine of the cab's vehicle doesn't stop th
auto &first{train.add(sn61(), 1).physics()};
auto &second{train.add(sn61(false)).physics()};
prepare(train);
REQUIRE_FALSE(first.lineBreaker.closed);
REQUIRE_FALSE(first.lineBreaker.IsClosed());
// mainb_on
engine_start::remote_switch switchb;
hold(train, switchb, engine_start::engine(first, first, 2), 2.0);
train.run(15.0);
CHECK(running(second));
CHECK_FALSE(first.lineBreaker.closed);
CHECK_FALSE(first.lineBreaker.IsClosed());
CHECK(first.enrot == 0.0);
}