17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-09 18:22:15 +01:00
Files
maszyna/tests/unit/test_engine_shutdown.cpp
jerrrrycho 7e426192b7 fix(cab): a diesel with only the starter button stops its engine with the main switch off command (eu07/maszyna#427)
The SM03 had no way to stop its engine. Its fuel pump starts on its own, so the fuel pump switch is ignored; the
engine runs the converter feeding the low voltage circuit, so the battery switch doesn't starve the fuel pump either;
and its cab has only the starter button, for which TTrain::OnCommand_linebreakeropen() kept a legacy branch which
animated the button and returned without opening the circuit. MainSwitch(false) itself stops the engine fine.

The command now opens the circuit on diesels whose cab has only the starter button
(TMoverParameters::MainCircuitOpensWithStarterOnly()), without animating the button, which held down would start
the engine again. Other vehicles with only the button closing the circuit keep ignoring the command.

Tests: tests/unit/test_engine_shutdown.cpp, on a shunter made after the SM03.
2026-11-07 14:06:38 +01:00

75 lines
2.9 KiB
C++

#include "stdafx.h"
#include "doctest.h"
#include "vehicle.h"
// stopping the engine of a diesel shunter like the SM03 (eu07/maszyna#427): its fuel pump starts on its own with the
// engine and the engine runs the converter which feeds the low voltage circuit, so neither the fuel pump switch nor the
// battery switch stop it. the cab has only the starter button, and the command opening the main circuit has to stop it
namespace {
// the shunter with its engine started from the cab and idling
test::vehicle running_shunter() {
test::vehicle shunter{test::definition::load("diesel_shunter")};
shunter->CabOccupied = 1;
shunter->CabActivisation();
shunter->BatterySwitch(true);
shunter->OilPumpSwitch(true);
shunter.run(20.0); // the oil pressure builds up
shunter->MainSwitch(true);
shunter.run(15.0);
return shunter;
}
} // namespace
TEST_CASE("engine shutdown: the shunter starts with the starter button") {
auto shunter{running_shunter()};
REQUIRE(shunter->EngineType == TEngineType::DieselEngine);
REQUIRE(shunter->FuelPump.start_type == start_t::automatic);
CHECK(shunter->Mains);
CHECK(shunter->FuelPump.is_active);
CHECK(shunter->enrot > 0.9 * shunter->dizel_nmin);
}
TEST_CASE("engine shutdown: neither the fuel pump switch nor the battery switch stop the engine") {
auto shunter{running_shunter()};
shunter->FuelPumpSwitchOff(true, range_t::local); // the pump started automatically ignores its switch
shunter.run(10.0);
CHECK(shunter->Mains);
shunter->BatterySwitch(false);
shunter.run(10.0);
CHECK(shunter->Power110vIsAvailable); // the converter run by the engine keeps feeding the fuel pump
CHECK(shunter->Mains);
CHECK(shunter->enrot > 0.9 * shunter->dizel_nmin);
}
TEST_CASE("engine shutdown: the command opening the main circuit stops the engine and it stays stopped") {
auto shunter{running_shunter()};
REQUIRE(shunter->MainCircuitOpensWithStarterOnly()); // the cab passes the command on with only the starter button
CHECK(shunter->MainSwitch(false));
shunter.run(20.0);
CHECK_FALSE(shunter->Mains);
CHECK_FALSE(shunter->FuelPump.is_active);
CHECK(shunter->enrot == 0.0);
}
TEST_CASE("engine shutdown: the engine starts again after it was stopped") {
auto shunter{running_shunter()};
shunter->MainSwitch(false);
shunter.run(20.0);
REQUIRE(shunter->enrot == 0.0);
shunter->MainSwitch(true);
shunter.run(15.0);
CHECK(shunter->Mains);
CHECK(shunter->enrot > 0.9 * shunter->dizel_nmin);
}
TEST_CASE("engine shutdown: vehicles without a diesel keep ignoring the command with only the button closing the circuit") {
test::vehicle wagon{test::definition::load("wagon")};
CHECK_FALSE(wagon->MainCircuitOpensWithStarterOnly());
test::vehicle electric{test::definition::load("wagon").set("Engine", "EngineType", "ElectricSeriesMotor")};
REQUIRE(electric->EngineType == TEngineType::ElectricSeriesMotor);
CHECK_FALSE(electric->MainCircuitOpensWithStarterOnly());
}