Fix pre sync timestamp copy (#2892)

* fix tests

* fix pre sync copy

* this fixes the issue
This commit is contained in:
Matthew Kennedy 2021-07-01 15:58:28 -07:00 committed by GitHub
parent 95d14ca2d8
commit 8569f028d6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 18 deletions

View File

@ -203,11 +203,24 @@ int TriggerState::getTotalRevolutionCounter() const {
void TriggerStateWithRunningStatistics::movePreSynchTimestamps(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
// here we take timestamps of events which happened prior to synchronization and place them
// at appropriate locations
for (int i = 0; i < spinningEventIndex;i++) {
int newIndex = getTriggerSize() - i;
assertIsInBounds(newIndex, timeOfLastEvent, "move timeOfLastEvent");
timeOfLastEvent[newIndex] = spinningEvents[i];
auto triggerSize = getTriggerSize();
int eventsToCopy = minI(spinningEventIndex, triggerSize);
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) {
@ -650,7 +663,7 @@ void TriggerState::decodeTriggerEvent(
toothed_previous_time = nowNt;
}
if (!isValidIndex(triggerShape) && triggerStateListener) {
if (shaft_is_synchronized && !isValidIndex(triggerShape) && triggerStateListener) {
triggerStateListener->OnTriggerInvalidIndex(currentCycle.current_index);
return;
}

View File

@ -32,7 +32,7 @@ TEST(fuelControl, transitionIssue1592) {
ENGINE(tdcMarkEnabled) = false;
setupSimpleTestEngineWithMafAndTT_ONE_trigger(&eth, IM_SEQUENTIAL);
EXPECT_CALL(eth.mockAirmass, getAirmass(400))
EXPECT_CALL(eth.mockAirmass, getAirmass(499))
.WillRepeatedly(Return(AirmassResult{0.1008f, 50.0f}));
// This is easiest to trip on a wheel that requires sync

View File

@ -115,7 +115,7 @@ static void doTestFasterEngineSpinningUp60_2(int startUpDelayMs, int rpm1, int e
}
TEST(cranking, testFasterEngineSpinningUp60_2) {
doTestFasterEngineSpinningUp60_2(0, 288, 263);
doTestFasterEngineSpinningUp60_2(100, 288, 263);
doTestFasterEngineSpinningUp60_2(1000, 288, 263);
doTestFasterEngineSpinningUp60_2(0, 549, 549);
doTestFasterEngineSpinningUp60_2(100, 549, 549);
doTestFasterEngineSpinningUp60_2(1000, 549, 549);
}

View File

@ -22,10 +22,9 @@ TEST(cranking, realCrankingFromFile) {
reader.readLine(&eth);
}
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, engine->tdcScheduler[1].momentX);
reader.readLine(&eth);
ASSERT_EQ( 213, GET_RPM())<< reader.lineIndex() << " @ 1";
@ -45,8 +44,6 @@ TEST(cranking, realCrankingFromFile) {
reader.processLine(&eth);
}
// TODO: we should avoid this warning
// See https://github.com/rusefi/rusefi/issues/2889
ASSERT_EQ(1, eth.recentWarnings()->getCount())<< "warningCounter#realCranking";
ASSERT_EQ(560, GET_RPM()) << reader.lineIndex();
ASSERT_EQ(0, eth.recentWarnings()->getCount())<< "warningCounter#realCranking";
ASSERT_EQ(560, GET_RPM())<< reader.lineIndex();
}

View File

@ -56,11 +56,11 @@ TEST(cranking, hardcodedRealCranking) {
EXPECT_EQ(0, GET_RPM());
/* 14 */ EVENT(/* timestamp*/1.194742, T_PRIMARY, /*value*/true);
// first synch & fast spinning RPM
EXPECT_EQ( 31, GET_RPM());
EXPECT_EQ(227, GET_RPM());
/* 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);
EXPECT_EQ(53, GET_RPM());
EXPECT_EQ(234, GET_RPM());
/* 17 */ EVENT(/* timestamp*/1.30114225, T_PRIMARY, /*value*/true);
EXPECT_EQ(219, GET_RPM());
/* 18 */ EVENT(/* timestamp*/1.3341915, T_SECONDARY, /*value*/false);