2021-07-21 20:08:56 -07:00
|
|
|
/*
|
|
|
|
* @file test_real_cranking_nissan_vq40.cpp
|
|
|
|
*
|
|
|
|
* @date Jul 21, 2021
|
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2021
|
|
|
|
*/
|
|
|
|
|
2021-08-03 19:05:01 -07:00
|
|
|
#include "pch.h"
|
2021-07-21 20:08:56 -07:00
|
|
|
#include "logicdata_csv_reader.h"
|
|
|
|
|
2022-09-08 13:15:36 -07:00
|
|
|
static void test(int engineSyncCam, float camOffsetAdd) {
|
2021-07-21 20:08:56 -07:00
|
|
|
CsvReader reader(1, /* vvtCount */ 2);
|
|
|
|
|
2022-09-24 20:01:42 -07:00
|
|
|
reader.open("tests/trigger/resources/nissan_vq40_cranking-1.csv");
|
2021-11-16 13:52:11 -08:00
|
|
|
EngineTestHelper eth (HELLEN_121_NISSAN_6_CYL);
|
2022-04-23 06:51:47 -07:00
|
|
|
engineConfiguration->isFasterEngineSpinUpEnabled = false;
|
2022-08-19 12:03:20 -07:00
|
|
|
engineConfiguration->alwaysInstantRpm = true;
|
2021-07-21 20:08:56 -07:00
|
|
|
|
2022-09-08 13:15:36 -07:00
|
|
|
// Different sync cam may result in different TDC point, so we might need different cam offsets.
|
|
|
|
engineConfiguration->vvtOffsets[0] += camOffsetAdd;
|
|
|
|
engineConfiguration->vvtOffsets[2] += camOffsetAdd;
|
|
|
|
engineConfiguration->engineSyncCam = engineSyncCam;
|
|
|
|
|
2021-07-21 22:02:37 -07:00
|
|
|
bool hasSeenFirstVvt = false;
|
|
|
|
|
2021-07-21 20:08:56 -07:00
|
|
|
while (reader.haveMore()) {
|
|
|
|
reader.processLine(ð);
|
2021-07-21 22:02:37 -07:00
|
|
|
float vvt1 = engine->triggerCentral.getVVTPosition(/*bankIndex*/0, /*camIndex*/0);
|
2022-09-08 13:15:36 -07:00
|
|
|
float vvt2 = engine->triggerCentral.getVVTPosition(/*bankIndex*/1, /*camIndex*/0);
|
|
|
|
|
|
|
|
if (vvt1 != 0) {
|
|
|
|
if (!hasSeenFirstVvt) {
|
|
|
|
EXPECT_NEAR(vvt1, -45.56, 1);
|
|
|
|
hasSeenFirstVvt = true;
|
|
|
|
}
|
2021-07-21 22:02:37 -07:00
|
|
|
|
2022-09-08 13:15:36 -07:00
|
|
|
// cam position should never be reported outside of correct range
|
|
|
|
EXPECT_TRUE(vvt1 > -48 && vvt1 < -43);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vvt2 != 0) {
|
|
|
|
// cam position should never be reported outside of correct range
|
|
|
|
EXPECT_TRUE(vvt2 > -48 && vvt2 < -43);
|
2021-07-21 22:02:37 -07:00
|
|
|
}
|
2021-07-21 20:08:56 -07:00
|
|
|
}
|
|
|
|
|
2022-08-19 12:03:20 -07:00
|
|
|
EXPECT_NEAR(engine->triggerCentral.getVVTPosition(/*bankIndex*/0, /*camIndex*/0), -45.64, 1e-2);
|
|
|
|
EXPECT_NEAR(engine->triggerCentral.getVVTPosition(/*bankIndex*/1, /*camIndex*/0), -45.45, 1e-2);
|
|
|
|
ASSERT_EQ(101, round(Sensor::getOrZero(SensorType::Rpm)))<< reader.lineIndex();
|
2021-07-21 20:08:56 -07:00
|
|
|
|
2021-07-21 20:24:23 -07:00
|
|
|
// TODO: why warnings?
|
2022-08-23 20:32:14 -07:00
|
|
|
ASSERT_EQ(2, eth.recentWarnings()->getCount());
|
|
|
|
ASSERT_EQ(CUSTOM_OUT_OF_ORDER_COIL, eth.recentWarnings()->get(0).Code); // this is from a coil being protected by overdwell protection
|
2022-09-04 06:15:24 -07:00
|
|
|
ASSERT_EQ(CUSTOM_PRIMARY_TOO_MANY_TEETH, eth.recentWarnings()->get(1).Code);
|
2021-07-21 20:08:56 -07:00
|
|
|
}
|
2022-09-08 13:15:36 -07:00
|
|
|
|
|
|
|
// On Nissan VQ, all cams have the same pattern, so all should be equally good for engine sync. Check them all!
|
|
|
|
|
|
|
|
TEST(realCrankingVQ40, normalCrankingSyncCam1) {
|
|
|
|
test(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(realCrankingVQ40, normalCrankingSyncCam2) {
|
|
|
|
test(2, -360);
|
|
|
|
}
|