mirror of https://github.com/rusefi/rusefi-1.git
Fix pre sync timestamp copy (#2892)
* fix tests * fix pre sync copy * this fixes the issue
This commit is contained in:
parent
95d14ca2d8
commit
8569f028d6
|
@ -203,11 +203,24 @@ int TriggerState::getTotalRevolutionCounter() const {
|
||||||
void TriggerStateWithRunningStatistics::movePreSynchTimestamps(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
void TriggerStateWithRunningStatistics::movePreSynchTimestamps(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||||
// here we take timestamps of events which happened prior to synchronization and place them
|
// here we take timestamps of events which happened prior to synchronization and place them
|
||||||
// at appropriate locations
|
// at appropriate locations
|
||||||
for (int i = 0; i < spinningEventIndex;i++) {
|
auto triggerSize = getTriggerSize();
|
||||||
int newIndex = getTriggerSize() - i;
|
|
||||||
assertIsInBounds(newIndex, timeOfLastEvent, "move timeOfLastEvent");
|
int eventsToCopy = minI(spinningEventIndex, triggerSize);
|
||||||
timeOfLastEvent[newIndex] = spinningEvents[i];
|
|
||||||
|
size_t firstSrc;
|
||||||
|
size_t firstDst;
|
||||||
|
|
||||||
|
if (eventsToCopy >= triggerSize) {
|
||||||
|
// Only copy one trigger length worth of events, filling the whole buffer
|
||||||
|
firstSrc = spinningEventIndex - triggerSize;
|
||||||
|
firstDst = 0;
|
||||||
|
} else {
|
||||||
|
// There is less than one full cycle, copy to the end of the buffer
|
||||||
|
firstSrc = 0;
|
||||||
|
firstDst = triggerSize - spinningEventIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
memcpy(timeOfLastEvent + firstDst, spinningEvents + firstSrc, eventsToCopy * sizeof(timeOfLastEvent[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
float TriggerStateWithRunningStatistics::calculateInstantRpm(TriggerFormDetails *triggerFormDetails, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
float TriggerStateWithRunningStatistics::calculateInstantRpm(TriggerFormDetails *triggerFormDetails, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||||
|
@ -650,7 +663,7 @@ void TriggerState::decodeTriggerEvent(
|
||||||
|
|
||||||
toothed_previous_time = nowNt;
|
toothed_previous_time = nowNt;
|
||||||
}
|
}
|
||||||
if (!isValidIndex(triggerShape) && triggerStateListener) {
|
if (shaft_is_synchronized && !isValidIndex(triggerShape) && triggerStateListener) {
|
||||||
triggerStateListener->OnTriggerInvalidIndex(currentCycle.current_index);
|
triggerStateListener->OnTriggerInvalidIndex(currentCycle.current_index);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ TEST(fuelControl, transitionIssue1592) {
|
||||||
ENGINE(tdcMarkEnabled) = false;
|
ENGINE(tdcMarkEnabled) = false;
|
||||||
setupSimpleTestEngineWithMafAndTT_ONE_trigger(ð, IM_SEQUENTIAL);
|
setupSimpleTestEngineWithMafAndTT_ONE_trigger(ð, IM_SEQUENTIAL);
|
||||||
|
|
||||||
EXPECT_CALL(eth.mockAirmass, getAirmass(400))
|
EXPECT_CALL(eth.mockAirmass, getAirmass(499))
|
||||||
.WillRepeatedly(Return(AirmassResult{0.1008f, 50.0f}));
|
.WillRepeatedly(Return(AirmassResult{0.1008f, 50.0f}));
|
||||||
|
|
||||||
// This is easiest to trip on a wheel that requires sync
|
// This is easiest to trip on a wheel that requires sync
|
||||||
|
|
|
@ -115,7 +115,7 @@ static void doTestFasterEngineSpinningUp60_2(int startUpDelayMs, int rpm1, int e
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(cranking, testFasterEngineSpinningUp60_2) {
|
TEST(cranking, testFasterEngineSpinningUp60_2) {
|
||||||
doTestFasterEngineSpinningUp60_2(0, 288, 263);
|
doTestFasterEngineSpinningUp60_2(0, 549, 549);
|
||||||
doTestFasterEngineSpinningUp60_2(100, 288, 263);
|
doTestFasterEngineSpinningUp60_2(100, 549, 549);
|
||||||
doTestFasterEngineSpinningUp60_2(1000, 288, 263);
|
doTestFasterEngineSpinningUp60_2(1000, 549, 549);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,10 +22,9 @@ TEST(cranking, realCrankingFromFile) {
|
||||||
reader.readLine(ð);
|
reader.readLine(ð);
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT_EQ( 42, GET_RPM())<< reader.lineIndex() << " @ 0";
|
ASSERT_EQ( 229, GET_RPM())<< reader.lineIndex() << " @ 0";
|
||||||
ASSERT_EQ( 0, eth.recentWarnings()->getCount())<< "warningCounter#got synch";
|
ASSERT_EQ( 0, eth.recentWarnings()->getCount())<< "warningCounter#got synch";
|
||||||
|
|
||||||
ASSERT_EQ(0, engine->tdcScheduler[1].momentX);
|
|
||||||
reader.readLine(ð);
|
reader.readLine(ð);
|
||||||
|
|
||||||
ASSERT_EQ( 213, GET_RPM())<< reader.lineIndex() << " @ 1";
|
ASSERT_EQ( 213, GET_RPM())<< reader.lineIndex() << " @ 1";
|
||||||
|
@ -45,8 +44,6 @@ TEST(cranking, realCrankingFromFile) {
|
||||||
reader.processLine(ð);
|
reader.processLine(ð);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: we should avoid this warning
|
ASSERT_EQ(0, eth.recentWarnings()->getCount())<< "warningCounter#realCranking";
|
||||||
// See https://github.com/rusefi/rusefi/issues/2889
|
ASSERT_EQ(560, GET_RPM())<< reader.lineIndex();
|
||||||
ASSERT_EQ(1, eth.recentWarnings()->getCount())<< "warningCounter#realCranking";
|
|
||||||
ASSERT_EQ(560, GET_RPM()) << reader.lineIndex();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,11 +56,11 @@ TEST(cranking, hardcodedRealCranking) {
|
||||||
EXPECT_EQ(0, GET_RPM());
|
EXPECT_EQ(0, GET_RPM());
|
||||||
/* 14 */ EVENT(/* timestamp*/1.194742, T_PRIMARY, /*value*/true);
|
/* 14 */ EVENT(/* timestamp*/1.194742, T_PRIMARY, /*value*/true);
|
||||||
// first synch & fast spinning RPM
|
// first synch & fast spinning RPM
|
||||||
EXPECT_EQ( 31, GET_RPM());
|
EXPECT_EQ(227, GET_RPM());
|
||||||
/* 15 */ EVENT(/* timestamp*/1.20417975, T_SECONDARY, /*value*/false);
|
/* 15 */ EVENT(/* timestamp*/1.20417975, T_SECONDARY, /*value*/false);
|
||||||
EXPECT_EQ(36, GET_RPM());
|
EXPECT_EQ(233, GET_RPM());
|
||||||
/* 16 */ EVENT(/* timestamp*/1.25380075, T_SECONDARY, /*value*/true);
|
/* 16 */ EVENT(/* timestamp*/1.25380075, T_SECONDARY, /*value*/true);
|
||||||
EXPECT_EQ(53, GET_RPM());
|
EXPECT_EQ(234, GET_RPM());
|
||||||
/* 17 */ EVENT(/* timestamp*/1.30114225, T_PRIMARY, /*value*/true);
|
/* 17 */ EVENT(/* timestamp*/1.30114225, T_PRIMARY, /*value*/true);
|
||||||
EXPECT_EQ(219, GET_RPM());
|
EXPECT_EQ(219, GET_RPM());
|
||||||
/* 18 */ EVENT(/* timestamp*/1.3341915, T_SECONDARY, /*value*/false);
|
/* 18 */ EVENT(/* timestamp*/1.3341915, T_SECONDARY, /*value*/false);
|
||||||
|
|
Loading…
Reference in New Issue