diff --git a/input/messaging.cpp b/input/messaging.cpp index 8e4b6829c..89a81faf5 100644 --- a/input/messaging.cpp +++ b/input/messaging.cpp @@ -188,7 +188,7 @@ OnCommandGet(multiplayer::DaneRozkaz const *pRozkaz) d->Damage( pRozkaz->cString[ 0 ] ); d = d->Prev(); // w drugą stronę też } - WyslijUszkodzenia( lookup->asName, static_cast(lookup->physics->EngDmgFlag) ); // zwrot informacji o pojeździe + WyslijUszkodzenia( lookup->asName, static_cast(lookup->physics->equipmentFaults.Bits()) ); // zwrot informacji o pojeździe } break; default: diff --git a/physics/components/airsupply.h b/physics/components/airsupply.h index 6a034f776..b5a04460b 100644 --- a/physics/components/airsupply.h +++ b/physics/components/airsupply.h @@ -33,7 +33,7 @@ class TrainPipe // the pressure in the pipe [bar], as it was last taken from its reservoir double const &Pressure() const { return pressure; } // the pressure taken from the reservoir of the pipe, after the flows of a step - void SetPressure(double const Pressure) { pressure = Pressure; } + void SetPressure(double const Value) { pressure = Value; } // the pipe stepped, its exchange of air through the hoses is yet to come (UpdatePipeCouplers()) bool CouplersPending() const { return couplersPending; } @@ -316,7 +316,7 @@ class AirSupply } // for the tests: the pressure in the reservoir as given, whatever its air - void SetPressureForTest(double const Pressure) { mainReservoirPressure = Pressure; } + void SetPressureForTest(double const Value) { mainReservoirPressure = Value; } private: double mainReservoirPressure{0.0}; diff --git a/physics/components/body.cpp b/physics/components/body.cpp index 084cf703d..dff55b0fe 100644 --- a/physics/components/body.cpp +++ b/physics/components/body.cpp @@ -1300,3 +1300,47 @@ namespace simulation weights_table Weights; } // namespace simulation + +void physics::Vehicle::SetEquipmentFaults(EquipmentFaultSet const Faults) +{ + if (Faults.HasAll(EquipmentFault::differentialRelay)) // różnicówka nie robi nic + { + MainSwitch(false); + FuseOff(); + } + // the faults of the control and of the camshaft hold the start, or the steps of the controller, by delays that never + // pass: the delays of the definition moved out of reach, and back when the fault clears + constexpr double faultoffset{100000001}; + constexpr double faultthreshold{100000000}; + if (Faults.HasAll(EquipmentFault::control)) // usterka sterowania + { + lineContactors.Open(); + if (InitialCtrlDelay < faultthreshold) + InitialCtrlDelay += faultoffset; + } + else if (InitialCtrlDelay > faultthreshold) + { + InitialCtrlDelay -= faultoffset; + } + if (Faults.HasAll(EquipmentFault::converter) && converter.config.start != start_t::disabled) // blokada przetwornicy + { + converter.Overload(); + } + air.compressor.SetFault(Faults.HasAll(EquipmentFault::compressor)); // blokada sprezarki + if (Faults.HasAll(EquipmentFault::camshaft)) // blokada wału + { + if (CtrlDelay < faultthreshold) + CtrlDelay += faultoffset; + if (CtrlDownDelay < faultthreshold) + CtrlDownDelay += faultoffset; + } + else + { + if (CtrlDelay > faultthreshold) + CtrlDelay -= faultoffset; + if (CtrlDownDelay > faultthreshold) + CtrlDownDelay -= faultoffset; + } + // hamowanie nagłe (emergencyBrake): nothing yet + equipmentFaults = Faults; +} diff --git a/physics/components/collisions.cpp b/physics/components/collisions.cpp index 8f985fe39..d8b34be61 100644 --- a/physics/components/collisions.cpp +++ b/physics/components/collisions.cpp @@ -782,7 +782,7 @@ void physics::Vehicle::rerail() void physics::Vehicle::repair_damage() { DamageFlag = {}; - EngDmgFlag = 0; + equipmentFaults = {}; WheelFlat = 0.0; brakes.alarmChain = false; // the crushed ends rebuilt diff --git a/physics/components/electrics.cpp b/physics/components/electrics.cpp index 49c64167a..0e75ef611 100644 --- a/physics/components/electrics.cpp +++ b/physics/components/electrics.cpp @@ -518,7 +518,7 @@ void physics::Vehicle::ConverterCheck(double const Timestep) supply.pantographPressureLock = pantographAir.IsPressureLockActive(); // HACK: allow carriages to operate converter without (missing) fuse prerequisite supply.highVoltage = Power > 1.0 ? MainCircuitPowered() : GetTrainsetHighVoltage() > 0.0; - supply.damaged = TestFlag(EngDmgFlag, 4); + supply.damaged = equipmentFaults.HasAll(EquipmentFault::converter); converter.Update(supply, Timestep); } @@ -869,7 +869,7 @@ bool physics::Vehicle::MainSwitchCheck() const (HasCamshaft ? IsMainCtrlActualNoPowerPos() : lineBreaker.config.closesOnlyAtNoPower ? IsMainCtrlNoPowerPos() : true) && - false == DamageFlag.HasAll(VehicleDamage::derailed) && false == TestFlag(EngDmgFlag, 1) && false == EmergencyBrakeHoldsMainOff(); + false == DamageFlag.HasAll(VehicleDamage::derailed) && false == equipmentFaults.HasAll(EquipmentFault::differentialRelay) && false == EmergencyBrakeHoldsMainOff(); } // ************************************************************************************************* diff --git a/physics/components/lowvoltage.h b/physics/components/lowvoltage.h index 0709d8101..a3c4b1332 100644 --- a/physics/components/lowvoltage.h +++ b/physics/components/lowvoltage.h @@ -33,10 +33,10 @@ class LowVoltageSupply Config config; // the battery of the definition (LMaxVoltage), charged - void SetBattery(double const Voltage) + void SetBattery(double const Value) { - batteryVoltage = Voltage; - config.nominalBatteryVoltage = static_cast(Voltage); + batteryVoltage = Value; + config.nominalBatteryVoltage = static_cast(Value); } bool IsBatteryOn() const { return batteryOn; } @@ -85,9 +85,9 @@ class LowVoltageSupply // the voltage of the battery circuit double Voltage24v() const { return power24vVoltage; } // the circuits in the step: the 24 V one from its voltage, the 110 V one as given - void SetSupply(double const Voltage24v, bool const Available110v) + void SetSupply(double const Volts24, bool const Available110v) { - power24vVoltage = Voltage24v; + power24vVoltage = Volts24; power24vAvailable = power24vVoltage > 0; power110vAvailable = Available110v; } diff --git a/physics/components/pantographs.h b/physics/components/pantographs.h index 4e406593a..be7ab5688 100644 --- a/physics/components/pantographs.h +++ b/physics/components/pantographs.h @@ -36,11 +36,11 @@ class PantographCircuit double Voltage(VehicleEnd const End) const { return End == VehicleEnd::front ? frontVoltage : rearVoltage; } double FrontVoltage() const { return frontVoltage; } double RearVoltage() const { return rearVoltage; } - void SetFrontVoltage(double const Voltage) { frontVoltage = Voltage; } - void SetRearVoltage(double const Voltage) { rearVoltage = Voltage; } + void SetFrontVoltage(double const Value) { frontVoltage = Value; } + void SetRearVoltage(double const Value) { rearVoltage = Value; } // the voltage supplied to the pantographs, from the overhead line the vehicle is under double SupplyVoltage() const { return supplyVoltage; } - void SetSupplyVoltage(double const Voltage) { supplyVoltage = Voltage; } + void SetSupplyVoltage(double const Value) { supplyVoltage = Value; } // the switch that lowers all of them bool AllDown() const { return allDown; } @@ -195,9 +195,9 @@ class PantographAir } // for the tests: the reservoirs at the given pressure, with the pressure switch primed or not - void SetForTest(double const Pressure, bool const PressureSwitchPrimed) + void SetForTest(double const Value, bool const PressureSwitchPrimed) { - pressure = Pressure; + pressure = Value; pressureSwitchActive = PressureSwitchPrimed; } diff --git a/physics/components/traction.cpp b/physics/components/traction.cpp index 3e2e8d468..137dd1446 100644 --- a/physics/components/traction.cpp +++ b/physics/components/traction.cpp @@ -1462,14 +1462,14 @@ bool physics::Vehicle::RelayReset(int const Relays, range_t const Notify) if (TestFlag(Relays, relay_t::maincircuitground) && (EngineType == TEngineType::ElectricSeriesMotor || EngineType == TEngineType::DieselElectric) && (protection.config.groundStart == start_t::manual || protection.config.groundStart == start_t::manualwithautofallback) && IsMainCtrlNoPowerPos() && ScndCtrlPos == 0 && DirActive != 0 && - !TestFlag(EngDmgFlag, 1)) + false == equipmentFaults.HasAll(EquipmentFault::differentialRelay)) { // NOTE: true means the relay is operational reset |= protection.ResetGround(lowvoltagepower); } if (TestFlag(Relays, relay_t::tractionnmotoroverload) && (EngineType == TEngineType::ElectricSeriesMotor || EngineType == TEngineType::DieselElectric) && IsMainCtrlNoPowerPos() && ScndCtrlPos == 0 && DirActive != 0 && - !TestFlag(EngDmgFlag, 1)) + false == equipmentFaults.HasAll(EquipmentFault::differentialRelay)) { // NOTE: false means the relay is operational // TODO: cleanup, flip the FuseFlag code to match other relays diff --git a/physics/vehicle.h b/physics/vehicle.h index 4a1b9effa..5d49ab2a4 100644 --- a/physics/vehicle.h +++ b/physics/vehicle.h @@ -962,7 +962,7 @@ class Vehicle double ActFlowSpeed = 0.0; /*szybkosc stabilizatora*/ DamageSet DamageFlag; // the damage of the vehicle - int EngDmgFlag = 0; // kombinacja bitowa stalych usterek} + EquipmentFaultSet equipmentFaults; // the faults of the equipment set on the vehicle (SetEquipmentFaults()) // EndSignalsFlag: byte; {ABu 060205: zmiany - koncowki: 1/16 - swiatla prz/tyl, 2/31 - blachy prz/tyl} // HeadSignalsFlag: byte; {ABu 060205: zmiany - swiatla: 1/2/4 - przod, 16/32/63 - tyl} @@ -1646,6 +1646,8 @@ class Vehicle bool FuseOn(range_t const Notify = range_t::consist); // bezpiecznik nadamiary bool FuseFlagCheck(void) const; // sprawdzanie flagi nadmiarowego void FuseOff(void); // wylaczenie nadmiarowego + // the faults of the equipment the scenery or the network sets: each sets its fault, or clears it where it was set + void SetEquipmentFaults(EquipmentFaultSet Faults); bool UniversalResetButton(int const Button, range_t const Notify = range_t::consist); bool RelayReset(int const Relays, range_t const Notify = range_t::consist); // resets specified relays // the drive of the kind of engine of the vehicle (physics/components/drive.h) diff --git a/physics/vehicletypes.h b/physics/vehicletypes.h index 79ecd2ea5..dc83b6d88 100644 --- a/physics/vehicletypes.h +++ b/physics/vehicletypes.h @@ -92,6 +92,22 @@ template <> struct IsEnumSetKind : std::true_type }; using DamageSet = EnumSet; +// the faults of the equipment of a vehicle the scenery or the network sets (TDynamicObject::Damage()), in the numbers of +// the messages that carry them +enum class EquipmentFault : unsigned +{ + differentialRelay = 0x1, // the differential relay tripped: the line breaker opens and the fuse with it + control = 0x2, // the control: the line contactors open and the start doesn't go on + converter = 0x4, // the converter locked + compressor = 0x8, // the compressor locked + camshaft = 0x10, // the camshaft locked: the controller doesn't step + emergencyBrake = 0x20, // an emergency brake application, which does nothing more yet +}; +template <> struct IsEnumSetKind : std::true_type +{ +}; +using EquipmentFaultSet = EnumSet; + /// Reason for a derailment event. enum DerailReason { diff --git a/tests/unit/test_equipment_faults.cpp b/tests/unit/test_equipment_faults.cpp new file mode 100644 index 000000000..bd65cacb4 --- /dev/null +++ b/tests/unit/test_equipment_faults.cpp @@ -0,0 +1,56 @@ +#include "stdafx.h" +#include "doctest.h" +#include "vehicle.h" + +// the faults of the equipment the scenery or the network sets on a vehicle (physics::Vehicle::SetEquipmentFaults(), +// TDynamicObject::Damage() with the number of a message) + +TEST_CASE("equipment faults: the number of a message comes back as it went in") { + auto const faults{EquipmentFaultSet::FromBits(0x2A)}; + CHECK(faults.HasAll(EquipmentFault::control)); + CHECK(faults.HasAll(EquipmentFault::compressor)); + CHECK(faults.HasAll(EquipmentFault::emergencyBrake)); + CHECK_FALSE(faults.HasAny(EquipmentFault::differentialRelay | EquipmentFault::converter | EquipmentFault::camshaft)); + CHECK(faults.Bits() == 0x2A); +} + +TEST_CASE("equipment faults: the fault of the control opens the line contactors and holds the start until it clears") { + test::vehicle loco{test::definition::fiz("4e_v1/4e")}; + auto const delay{loco->InitialCtrlDelay}; + loco->lineContactors.Close(); + loco->SetEquipmentFaults(EquipmentFault::control); + CHECK(loco->equipmentFaults.HasAll(EquipmentFault::control)); + CHECK_FALSE(loco->lineContactors.IsClosed()); + CHECK(loco->InitialCtrlDelay > 100000000.0); + // set again, it doesn't move the delay further + loco->SetEquipmentFaults(EquipmentFault::control); + CHECK(loco->InitialCtrlDelay < 200000000.0); + loco->SetEquipmentFaults({}); + CHECK(loco->equipmentFaults.Empty()); + CHECK(loco->InitialCtrlDelay == doctest::Approx(delay)); +} + +TEST_CASE("equipment faults: the fault of the compressor moves its pressures out of reach, and back") { + test::vehicle loco{test::definition::fiz("4e_v1/4e")}; + auto const minpressure{loco->air.compressor.config.minPressure}; + auto const maxpressure{loco->air.compressor.config.maxPressure}; + REQUIRE(minpressure > 0.0); + loco->SetEquipmentFaults(EquipmentFault::compressor); + CHECK(loco->air.compressor.config.minPressure < 0.0); + CHECK(loco->air.compressor.config.maxPressure < 0.0); + loco->SetEquipmentFaults({}); + CHECK(loco->air.compressor.config.minPressure == doctest::Approx(minpressure)); + CHECK(loco->air.compressor.config.maxPressure == doctest::Approx(maxpressure)); +} + +TEST_CASE("equipment faults: the fault of the camshaft holds the steps of the controller until it clears") { + test::vehicle loco{test::definition::fiz("4e_v1/4e")}; + auto const delay{loco->CtrlDelay}; + auto const downdelay{loco->CtrlDownDelay}; + loco->SetEquipmentFaults(EquipmentFault::camshaft); + CHECK(loco->CtrlDelay > 100000000.0); + CHECK(loco->CtrlDownDelay > 100000000.0); + loco->SetEquipmentFaults({}); + CHECK(loco->CtrlDelay == doctest::Approx(delay)); + CHECK(loco->CtrlDownDelay == doctest::Approx(downdelay)); +} diff --git a/vehicle/dynamic/update.cpp b/vehicle/dynamic/update.cpp index cb4d0f1a8..f80d991d6 100644 --- a/vehicle/dynamic/update.cpp +++ b/vehicle/dynamic/update.cpp @@ -1110,63 +1110,9 @@ void TDynamicObject::RadioStop() //--------------------------------------------------------------------------- void TDynamicObject::Damage(char flag) { - if (flag & 1) //różnicówka nie robi nic - { - physics->MainSwitch(false); - physics->FuseOff(); - } - else - { - } - - if (flag & 2) //usterka sterowania - { - physics->lineContactors.Open(); - if (physics->InitialCtrlDelay<100000000) - physics->InitialCtrlDelay += 100000001; - } - else - { - if (physics->InitialCtrlDelay>100000000) - physics->InitialCtrlDelay -= 100000001; - } - - if (flag & 4) //blokada przetwornicy - { - if( physics->converter.config.start != start_t::disabled ) { - physics->converter.Overload(); - } - } - else - { - } - - physics->air.compressor.SetFault((flag & 8) != 0); //blokada sprezarki - - if (flag & 16) //blokada wału - { - if (physics->CtrlDelay<100000000) - physics->CtrlDelay += 100000001; - if (physics->CtrlDownDelay<100000000) - physics->CtrlDownDelay += 100000001; - } - else - { - if (physics->CtrlDelay>100000000) - physics->CtrlDelay -= 100000001; - if (physics->CtrlDownDelay>100000000) - physics->CtrlDownDelay -= 100000001; - } - - if (flag & 32) //hamowanie nagŁe - { - } - else - { - } - - physics->EngDmgFlag = flag; -}; + // the number of the message, as a char (sign extended as the number was) + physics->SetEquipmentFaults(EquipmentFaultSet::FromBits(flag)); +} void TDynamicObject::OverheadTrack(float o) { // ewentualne wymuszanie jazdy