refactoring: getShaftSynchronized

This commit is contained in:
Andrey 2021-07-03 10:37:03 -04:00
parent 152eea43b1
commit f5e937fe2b
9 changed files with 21 additions and 16 deletions

View File

@ -86,7 +86,7 @@ static void SetNextCompositeEntry(efitick_t timestamp DECLARE_ENGINE_PARAMETER_S
buffer[NextIdx].priLevel = currentTrigger1; buffer[NextIdx].priLevel = currentTrigger1;
buffer[NextIdx].secLevel = currentTrigger2; buffer[NextIdx].secLevel = currentTrigger2;
buffer[NextIdx].trigger = currentTdc; buffer[NextIdx].trigger = currentTdc;
buffer[NextIdx].sync = engine->triggerCentral.triggerState.shaft_is_synchronized; buffer[NextIdx].sync = engine->triggerCentral.triggerState.getShaftSynchronized();
buffer[NextIdx].coil = currentCoilState; buffer[NextIdx].coil = currentCoilState;
buffer[NextIdx].injector = currentInjectorState; buffer[NextIdx].injector = currentInjectorState;

View File

@ -459,7 +459,7 @@ bool TriggerNoiseFilter::noiseFilter(efitick_t nowNt,
efitick_t allowedPeriod = accumSignalPrevPeriods[os]; efitick_t allowedPeriod = accumSignalPrevPeriods[os];
// but first check if we're expecting a gap // but first check if we're expecting a gap
bool isGapExpected = TRIGGER_WAVEFORM(isSynchronizationNeeded) && triggerState->shaft_is_synchronized && bool isGapExpected = TRIGGER_WAVEFORM(isSynchronizationNeeded) && triggerState->getShaftSynchronized() &&
(triggerState->currentCycle.eventCount[ti] + 1) == TRIGGER_WAVEFORM(getExpectedEventCount(ti)); (triggerState->currentCycle.eventCount[ti] + 1) == TRIGGER_WAVEFORM(getExpectedEventCount(ti));
if (isGapExpected) { if (isGapExpected) {
@ -553,7 +553,7 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta
} }
reportEventToWaveChart(signal, triggerIndexForListeners PASS_ENGINE_PARAMETER_SUFFIX); reportEventToWaveChart(signal, triggerIndexForListeners PASS_ENGINE_PARAMETER_SUFFIX);
if (!triggerState.shaft_is_synchronized) { if (!triggerState.getShaftSynchronized()) {
// we should not propagate event if we do not know where we are // we should not propagate event if we do not know where we are
return; return;
} }

View File

@ -45,6 +45,10 @@ TriggerState::TriggerState() {
resetTriggerState(); resetTriggerState();
} }
bool TriggerState::getShaftSynchronized() {
return shaft_is_synchronized;
}
void TriggerState::setShaftSynchronized(bool value) { void TriggerState::setShaftSynchronized(bool value) {
if (value) { if (value) {
if (!shaft_is_synchronized) { if (!shaft_is_synchronized) {
@ -278,7 +282,7 @@ float TriggerStateWithRunningStatistics::calculateInstantRpm(TriggerFormDetails
} }
void TriggerStateWithRunningStatistics::setLastEventTimeForInstantRpm(efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) { void TriggerStateWithRunningStatistics::setLastEventTimeForInstantRpm(efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
if (shaft_is_synchronized) { if (getShaftSynchronized()) {
return; return;
} }
// here we remember tooth timestamps which happen prior to synchronization // here we remember tooth timestamps which happen prior to synchronization
@ -498,7 +502,7 @@ void TriggerState::decodeTriggerEvent(
isFirstEvent = false; isFirstEvent = false;
bool isSynchronizationPoint; bool isSynchronizationPoint;
bool wasSynchronized = shaft_is_synchronized; bool wasSynchronized = getShaftSynchronized();
DISPLAY_STATE(Trigger_State) DISPLAY_STATE(Trigger_State)
DISPLAY_TEXT(Current_Gap); DISPLAY_TEXT(Current_Gap);
@ -623,12 +627,12 @@ void TriggerState::decodeTriggerEvent(
unsigned int endOfCycleIndex = triggerShape.getSize() - (triggerConfiguration.UseOnlyRisingEdgeForTrigger ? 2 : 1); unsigned int endOfCycleIndex = triggerShape.getSize() - (triggerConfiguration.UseOnlyRisingEdgeForTrigger ? 2 : 1);
isSynchronizationPoint = !shaft_is_synchronized || (currentCycle.current_index >= endOfCycleIndex); isSynchronizationPoint = !getShaftSynchronized() || (currentCycle.current_index >= endOfCycleIndex);
#if EFI_UNIT_TEST #if EFI_UNIT_TEST
if (printTriggerTrace) { if (printTriggerTrace) {
printf("decodeTriggerEvent sync=%d isSynchronizationPoint=%d index=%d size=%d\r\n", printf("decodeTriggerEvent sync=%d isSynchronizationPoint=%d index=%d size=%d\r\n",
shaft_is_synchronized, getShaftSynchronized(),
isSynchronizationPoint, isSynchronizationPoint,
currentCycle.current_index, currentCycle.current_index,
triggerShape.getSize()); triggerShape.getSize());
@ -667,7 +671,7 @@ void TriggerState::decodeTriggerEvent(
toothed_previous_time = nowNt; toothed_previous_time = nowNt;
} }
if (shaft_is_synchronized && !isValidIndex(triggerShape) && triggerStateListener) { if (getShaftSynchronized() && !isValidIndex(triggerShape) && triggerStateListener) {
triggerStateListener->OnTriggerInvalidIndex(currentCycle.current_index); triggerStateListener->OnTriggerInvalidIndex(currentCycle.current_index);
return; return;
} }

View File

@ -143,6 +143,7 @@ public:
void resetTriggerState(); void resetTriggerState();
void setShaftSynchronized(bool value); void setShaftSynchronized(bool value);
bool getShaftSynchronized();
/** /**
* this is start of real trigger cycle * this is start of real trigger cycle

View File

@ -148,7 +148,7 @@ uint32_t TriggerStimulatorHelper::findTriggerSyncPoint(
triggerConfiguration, triggerConfiguration,
state, shape, i); state, shape, i);
if (state.shaft_is_synchronized) { if (state.getShaftSynchronized()) {
return i; return i;
} }
} }

View File

@ -30,7 +30,7 @@ TEST(tachometer, testPulsePerRev) {
// ensure engine speed // ensure engine speed
ASSERT_EQ(1500, GET_RPM()) << "RPM"; ASSERT_EQ(1500, GET_RPM()) << "RPM";
ASSERT_EQ(engine->triggerCentral.triggerState.shaft_is_synchronized, true); ASSERT_EQ(engine->triggerCentral.triggerState.getShaftSynchronized(), true);
// Poke the fast callback to update the tach // Poke the fast callback to update the tach
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE); engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);

View File

@ -118,8 +118,8 @@ TEST(nissan, vq_vvt) {
TriggerCentral *tc = &engine->triggerCentral; TriggerCentral *tc = &engine->triggerCentral;
ASSERT_TRUE(tc->vvtState[0][0].shaft_is_synchronized); ASSERT_TRUE(tc->vvtState[0][0].getShaftSynchronized());
//huh? ASSERT_TRUE(tc->vvtState[0][1].shaft_is_synchronized); //huh? ASSERT_TRUE(tc->vvtState[0][1].getShaftSynchronized());
angle_t firstVVTangle = 27.5; angle_t firstVVTangle = 27.5;
ASSERT_NEAR(firstVVTangle, tc->vvtPosition[0][0], EPS2D); ASSERT_NEAR(firstVVTangle, tc->vvtPosition[0][0], EPS2D);

View File

@ -34,9 +34,9 @@ TEST(engine, testSymmetricalCrank) {
eth.fireFall(mult * 384); eth.fireFall(mult * 384);
eth.fireRise(mult * 16); eth.fireRise(mult * 16);
eth.fireFall(mult * 304); eth.fireFall(mult * 304);
ASSERT_FALSE(engine->triggerCentral.triggerState.shaft_is_synchronized); ASSERT_FALSE(engine->triggerCentral.triggerState.getShaftSynchronized());
eth.fireRise(mult * 16); eth.fireRise(mult * 16);
ASSERT_TRUE(engine->triggerCentral.triggerState.shaft_is_synchronized); ASSERT_TRUE(engine->triggerCentral.triggerState.getShaftSynchronized());
ASSERT_EQ( 0, GET_RPM()) << "RPM#0"; ASSERT_EQ( 0, GET_RPM()) << "RPM#0";

View File

@ -70,7 +70,7 @@ static void testDodgeNeonDecoder(void) {
TriggerState state; TriggerState state;
ASSERT_FALSE(state.shaft_is_synchronized) << "1 shaft_is_synchronized"; ASSERT_FALSE(state.getShaftSynchronized()) << "1 shaft_is_synchronized";
// int r = 0; // int r = 0;
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_RISING, r + 60); // processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_RISING, r + 60);
@ -339,7 +339,7 @@ TEST(misc, testRpmCalculator) {
// debugSignalExecutor = true; // debugSignalExecutor = true;
ASSERT_EQ(engine->triggerCentral.triggerState.shaft_is_synchronized, 1); ASSERT_EQ(engine->triggerCentral.triggerState.getShaftSynchronized(), 1);
eth.moveTimeForwardMs(5 /*ms*/); eth.moveTimeForwardMs(5 /*ms*/);