Custom Trigger Tooth with 1+0 causes endless loop #5471

only:test
This commit is contained in:
Andrey 2023-08-05 12:44:16 -04:00
parent 9bea3a0ca6
commit 0787b4f4a0
3 changed files with 30 additions and 1 deletions

View File

@ -816,12 +816,16 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta
auto nextToothIndex = triggerIndexForListeners;
angle_t nextPhase = 0;
int loopAllowance = 1000000;
do {
// I don't love this.
nextToothIndex = (nextToothIndex + 1) % engineCycleEventCount;
nextPhase = getTriggerCentral()->triggerFormDetails.eventAngles[nextToothIndex] - tdcPosition();
wrapAngle(nextPhase, "nextEnginePhase", ObdCode::CUSTOM_ERR_6555);
} while (nextPhase == currentEngineDecodedPhase);
} while (nextPhase == currentEngineDecodedPhase && --loopAllowance > 0);
if (loopAllowance == 0) {
firmwareError(ObdCode::CUSTOM_ERR_TRIGGER_ZERO, "handleShaftSignal endless loop");
}
float expectNextPhase = nextPhase + tdcPosition();
wrapAngle(expectNextPhase, "nextEnginePhase", ObdCode::CUSTOM_ERR_6555);

View File

@ -1,5 +1,6 @@
TESTS_SRC_CPP = \
tests/trigger/test_all_triggers.cpp \
tests/trigger/test_2_stroke.cpp \
tests/trigger/test_symmetrical_crank.cpp \
tests/trigger/test_trigger_decoder.cpp \
tests/trigger/test_trigger_decoder_2.cpp \

View File

@ -0,0 +1,24 @@
#include "pch.h"
TEST(trigger, twoStrokeSingleToothAsSkippedWheel) {
EngineTestHelper eth(engine_type_e::TEST_CRANK_ENGINE);
setTwoStrokeOperationMode();
engineConfiguration->trigger.customTotalToothCount = 1;
engineConfiguration->trigger.customSkippedToothCount = 0;
eth.setTriggerType(trigger_type_e::TT_TOOTHED_WHEEL);
EXPECT_FATAL_ERROR(eth.smartFireTriggerEvents2(/*count*/20, /*delay*/ 40));
// todo ASSERT_EQ(750, Sensor::getOrZero(SensorType::Rpm));
}
TEST(trigger, twoStrokeSingleToothTrigger) {
EngineTestHelper eth(engine_type_e::TEST_CRANK_ENGINE);
setTwoStrokeOperationMode();
eth.setTriggerType(trigger_type_e::TT_ONE);
eth.smartFireTriggerEvents2(/*count*/20, /*delay*/ 40);
ASSERT_EQ(750, Sensor::getOrZero(SensorType::Rpm));
}