rusefi-1/unit_tests/tests/trigger/test_trigger_decoder.cpp

1283 lines
46 KiB
C++
Raw Normal View History

2015-07-10 06:01:56 -07:00
/**
* @file test_trigger_decoder.cpp
*
* @date Dec 24, 2013
2020-01-13 18:57:43 -08:00
* @author Andrey Belomutskiy, (c) 2012-2020
2015-07-10 06:01:56 -07:00
*/
#include "pch.h"
2015-07-10 06:01:56 -07:00
#include "trigger_decoder.h"
#include "ford_aspire.h"
#include "dodge_neon.h"
#include "ford_1995_inline_6.h"
#include "event_queue.h"
#include "trigger_mazda.h"
#include "trigger_chrysler.h"
#include "advance_map.h"
#include "speed_density.h"
2016-08-26 16:02:56 -07:00
#include "fuel_math.h"
2016-09-21 20:03:22 -07:00
#include "spark_logic.h"
2017-01-03 14:01:42 -08:00
#include "trigger_universal.h"
2015-07-10 06:01:56 -07:00
2020-07-28 14:27:34 -07:00
using ::testing::_;
extern WarningCodeState unitTestWarningCodeState;
2015-07-10 06:01:56 -07:00
extern bool printTriggerDebug;
extern float actualSynchGap;
extern "C" {
void sendOutConfirmation(char *value, int i);
}
void sendOutConfirmation(char *value, int i) {
// test implementation
}
2017-03-01 19:25:00 -08:00
static int getTriggerZeroEventIndex(engine_type_e engineType) {
EngineTestHelper eth(engineType);
2015-07-10 06:01:56 -07:00
initDataStructures();
2015-07-10 06:01:56 -07:00
const auto& triggerConfiguration = engine->primaryTriggerConfiguration;
2020-08-23 22:21:42 -07:00
TriggerWaveform& shape = eth.engine.triggerCentral.triggerShape;
2020-08-23 22:21:42 -07:00
return eth.engine.triggerCentral.triggerState.findTriggerZeroEventIndex(shape, triggerConfiguration,
engineConfiguration->trigger);
2015-07-10 06:01:56 -07:00
}
TEST(misc, testSkipped2_0) {
EngineTestHelper eth(TEST_ENGINE);
// for this test we need a trigger with isSynchronizationNeeded=true
engineConfiguration->trigger.customTotalToothCount = 2;
engineConfiguration->trigger.customSkippedToothCount = 0;
eth.setTriggerType(TT_TOOTHED_WHEEL);
ASSERT_EQ( 0, GET_RPM()) << "testNoStartUpWarnings RPM";
}
static void testDodgeNeonDecoder() {
2017-03-04 17:52:24 -08:00
printf("*************************************************** testDodgeNeonDecoder95\r\n");
2015-07-10 06:01:56 -07:00
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 8, getTriggerZeroEventIndex(DODGE_NEON_1995)) << "DODGE_NEON_1995: trigger zero index";
2015-07-10 06:01:56 -07:00
EngineTestHelper eth(DODGE_NEON_1995);
2015-07-10 06:01:56 -07:00
TriggerWaveform * shape = &eth.engine.triggerCentral.triggerShape;
ASSERT_EQ(8, shape->getTriggerWaveformSynchPointIndex());
2015-07-10 06:01:56 -07:00
TriggerState state;
2021-07-03 07:37:03 -07:00
ASSERT_FALSE(state.getShaftSynchronized()) << "1 shaft_is_synchronized";
2015-07-10 06:01:56 -07:00
// int r = 0;
2016-02-27 20:03:34 -08:00
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_RISING, r + 60);
2019-01-14 16:02:36 -08:00
// ASSERT_FALSE(state.shaft_is_synchronized) << "2 shaft_is_synchronized"; // still no synchronization
2015-07-10 06:01:56 -07:00
2016-02-27 20:03:34 -08:00
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_FALLING, r + 210);
2019-01-14 16:02:36 -08:00
// ASSERT_FALSE(state.shaft_is_synchronized) << "3 shaft_is_synchronized"; // still no synchronization
2015-07-10 06:01:56 -07:00
//
2016-02-27 20:03:34 -08:00
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_RISING, r + 420);
2019-01-14 16:02:36 -08:00
// ASSERT_FALSE(state.shaft_is_synchronized) << "4 shaft_is_synchronized"; // still no synchronization
2015-07-10 06:01:56 -07:00
//
2016-02-27 20:03:34 -08:00
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_FALLING, r + 630);
2019-01-14 12:37:05 -08:00
// ASSERT_FALSE(state.shaft_is_synchronized); // still no synchronization
2015-07-10 06:01:56 -07:00
//
// printf("2nd camshaft revolution\r\n");
// r = 720;
2016-02-27 20:03:34 -08:00
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_RISING, r + 60);
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_FALLING, r + 210);
2019-01-14 12:37:05 -08:00
// ASSERT_TRUE(state.shaft_is_synchronized);
2019-01-14 12:45:35 -08:00
// ASSERT_EQ(0, state.current_index);
2016-02-27 20:03:34 -08:00
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_RISING, r + 420);
2019-01-14 12:45:35 -08:00
// ASSERT_EQ(1, state.current_index);
2016-02-27 20:03:34 -08:00
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_FALLING, r + 630);
2019-01-14 12:45:35 -08:00
// ASSERT_EQ(2, state.current_index);
2015-07-10 06:01:56 -07:00
//
// printf("3rd camshaft revolution\r\n");
// r = 2 * 720;
2016-02-27 20:03:34 -08:00
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_RISING, r + 60);
2019-01-14 15:38:20 -08:00
// ASSERT_EQ( 3, state.current_index) << "current index";
2016-02-27 20:03:34 -08:00
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_FALLING, r + 210);
2019-01-14 12:37:05 -08:00
// ASSERT_TRUE(state.shaft_is_synchronized);
2019-01-14 15:38:20 -08:00
// ASSERT_EQ( 0, state.current_index) << "current index";
2016-02-27 20:03:34 -08:00
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_RISING, r + 420);
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_FALLING, r + 630);
2015-07-10 06:01:56 -07:00
}
static void assertTriggerPosition(event_trigger_position_s *position, int eventIndex, float angleOffset) {
2019-10-07 21:54:19 -07:00
assertEqualsM("eventIndex", eventIndex, position->triggerEventIndex);
2019-10-07 22:03:57 -07:00
assertEqualsM("angleOffset", angleOffset, position->angleOffsetFromTriggerEvent);
2015-07-10 06:01:56 -07:00
}
2019-01-14 12:31:56 -08:00
TEST(misc, testSomethingWeird) {
EngineTestHelper eth(FORD_INLINE_6_1995);
2018-07-29 07:27:23 -07:00
TriggerState state_;
TriggerState *sta = &state_;
const auto& triggerConfiguration = engine->primaryTriggerConfiguration;
2020-08-23 22:21:42 -07:00
2018-07-29 07:27:23 -07:00
2019-01-14 16:02:36 -08:00
ASSERT_FALSE(sta->shaft_is_synchronized) << "shaft_is_synchronized";
2018-07-29 07:27:23 -07:00
int r = 10;
sta->decodeTriggerEvent(engine->triggerCentral.triggerShape, nullptr, /* override */ nullptr, triggerConfiguration, SHAFT_PRIMARY_FALLING, r);
2019-01-14 16:02:36 -08:00
ASSERT_FALSE(sta->shaft_is_synchronized) << "shaft_is_synchronized"; // still no synchronization
sta->decodeTriggerEvent(engine->triggerCentral.triggerShape, nullptr, /* override */ nullptr, triggerConfiguration, SHAFT_PRIMARY_RISING, ++r);
2019-01-14 12:37:05 -08:00
ASSERT_TRUE(sta->shaft_is_synchronized); // first signal rise synchronize
2019-01-14 12:45:35 -08:00
ASSERT_EQ(0, sta->getCurrentIndex());
sta->decodeTriggerEvent(engine->triggerCentral.triggerShape, nullptr, /* override */ nullptr, triggerConfiguration, SHAFT_PRIMARY_FALLING, r++);
2019-01-14 12:45:35 -08:00
ASSERT_EQ(1, sta->getCurrentIndex());
2018-07-29 07:27:23 -07:00
for (int i = 2; i < 10;) {
sta->decodeTriggerEvent(engine->triggerCentral.triggerShape, nullptr, /* override */ nullptr, triggerConfiguration, SHAFT_PRIMARY_RISING, r++);
2018-07-29 07:27:23 -07:00
assertEqualsM("even", i++, sta->getCurrentIndex());
sta->decodeTriggerEvent(engine->triggerCentral.triggerShape, nullptr, /* override */ nullptr, triggerConfiguration, SHAFT_PRIMARY_FALLING, r++);
2018-07-29 07:27:23 -07:00
assertEqualsM("odd", i++, sta->getCurrentIndex());
}
sta->decodeTriggerEvent(engine->triggerCentral.triggerShape, nullptr, /* override */ nullptr, triggerConfiguration, SHAFT_PRIMARY_RISING, r++);
2019-01-14 12:45:35 -08:00
ASSERT_EQ(10, sta->getCurrentIndex());
2018-07-29 07:27:23 -07:00
sta->decodeTriggerEvent(engine->triggerCentral.triggerShape, nullptr, /* override */ nullptr, triggerConfiguration, SHAFT_PRIMARY_FALLING, r++);
2019-01-14 12:45:35 -08:00
ASSERT_EQ(11, sta->getCurrentIndex());
2018-07-29 07:27:23 -07:00
sta->decodeTriggerEvent(engine->triggerCentral.triggerShape, nullptr, /* override */ nullptr, triggerConfiguration, SHAFT_PRIMARY_RISING, r++);
2019-01-14 12:45:35 -08:00
ASSERT_EQ(0, sta->getCurrentIndex()); // new revolution
2018-07-29 07:27:23 -07:00
}
2019-01-14 12:31:56 -08:00
TEST(misc, test1995FordInline6TriggerDecoder) {
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, getTriggerZeroEventIndex(FORD_INLINE_6_1995)) << "triggerIndex ";
2015-07-10 06:01:56 -07:00
EngineTestHelper eth(FORD_INLINE_6_1995);
setWholeTimingTable(-13);
2015-07-10 06:01:56 -07:00
Sensor::setMockValue(SensorType::Iat, 49.579071f);
TriggerWaveform * shape = &engine->triggerCentral.triggerShape;
2015-07-10 06:01:56 -07:00
ASSERT_EQ( 0, shape->getTriggerWaveformSynchPointIndex()) << "triggerShapeSynchPointIndex";
2015-07-10 06:01:56 -07:00
event_trigger_position_s position;
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, engineConfiguration->globalTriggerAngleOffset) << "globalTriggerAngleOffset";
findTriggerPosition(&engine->triggerCentral.triggerShape,
&engine->triggerCentral.triggerFormDetails,
&position, 0);
2015-07-10 06:01:56 -07:00
assertTriggerPosition(&position, 0, 0);
findTriggerPosition(&engine->triggerCentral.triggerShape,
&engine->triggerCentral.triggerFormDetails,
&position, 200);
2015-07-10 06:01:56 -07:00
assertTriggerPosition(&position, 3, 20);
findTriggerPosition(&engine->triggerCentral.triggerShape,
&engine->triggerCentral.triggerFormDetails,
&position, 360);
2015-07-10 06:01:56 -07:00
assertTriggerPosition(&position, 6, 0);
eth.applyTriggerWaveform();
2016-01-26 19:03:19 -08:00
engine->periodicFastCallback();
2016-01-26 20:01:44 -08:00
eth.fireTriggerEvents(48);
2019-01-21 19:32:30 -08:00
eth.assertRpm(2000, "rpm");
engine->periodicFastCallback();
2016-01-26 20:01:44 -08:00
eth.fireTriggerEvents(48);
2015-07-10 06:01:56 -07:00
2018-07-29 07:27:23 -07:00
IgnitionEventList *ecl = &engine->ignitionEvents;
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 1, ecl->isReady) << "ford inline ignition events size";
2019-10-07 21:54:19 -07:00
ASSERT_EQ( 0, ecl->elements[0].dwellPosition.triggerEventIndex) << "event index";
ASSERT_NEAR(7.9579, ecl->elements[0].dwellPosition.angleOffsetFromTriggerEvent, EPS4D) << "angle offset#1";
2015-07-10 06:01:56 -07:00
2019-10-07 21:54:19 -07:00
ASSERT_EQ( 10, ecl->elements[5].dwellPosition.triggerEventIndex) << "event index";
ASSERT_NEAR(7.9579, ecl->elements[5].dwellPosition.angleOffsetFromTriggerEvent, EPS4D) << "angle offset#2";
2015-07-10 06:01:56 -07:00
ASSERT_FLOAT_EQ(0.5, getSparkDwell(2000)) << "running dwell";
2015-07-10 06:01:56 -07:00
}
2019-10-15 02:30:38 -07:00
TEST(misc, testGetCoilDutyCycleIssue977) {
EngineTestHelper eth(FORD_ASPIRE_1996);
2019-10-15 02:30:38 -07:00
int rpm = 2000;
engine->rpmCalculator.setRpmValue(rpm);
ASSERT_EQ( 4, getSparkDwell(rpm)) << "running dwell";
2019-10-15 02:30:38 -07:00
ASSERT_NEAR( 26.66666, getCoilDutyCycle(rpm), 0.0001);
2019-10-15 02:30:38 -07:00
}
2019-01-14 12:31:56 -08:00
TEST(misc, testFordAspire) {
2015-07-10 06:01:56 -07:00
printf("*************************************************** testFordAspire\r\n");
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 4, getTriggerZeroEventIndex(FORD_ASPIRE_1996)) << "getTriggerZeroEventIndex";
2015-07-10 06:01:56 -07:00
EngineTestHelper eth(FORD_ASPIRE_1996);
2015-07-10 06:01:56 -07:00
ASSERT_EQ( 4, TRIGGER_WAVEFORM(getTriggerWaveformSynchPointIndex())) << "getTriggerWaveformSynchPointIndex";
2015-07-10 06:01:56 -07:00
engineConfiguration->crankingTimingAngle = 31;
int rpm = 2000;
engine->rpmCalculator.setRpmValue(rpm);
ASSERT_EQ( 4, getSparkDwell(rpm)) << "running dwell";
engine->rpmCalculator.setRpmValue(6000);
assertEqualsM("higher rpm dwell", 3.25, getSparkDwell(6000));
2015-07-10 06:01:56 -07:00
}
static void testTriggerDecoder2(const char *msg, engine_type_e type, int synchPointIndex, float channel1duty, float channel2duty) {
2018-12-25 16:13:28 -08:00
printf("====================================================================================== testTriggerDecoder2 msg=%s\r\n", msg);
2015-07-10 06:01:56 -07:00
// Some configs use aux valves, which requires this sensor
std::unordered_map<SensorType, float> sensorVals = {{SensorType::DriverThrottleIntent, 0}};
EngineTestHelper eth(type, sensorVals);
2015-07-10 06:01:56 -07:00
TriggerWaveform *t = &engine->triggerCentral.triggerShape;
2015-07-10 06:01:56 -07:00
2019-01-14 16:02:36 -08:00
ASSERT_FALSE(t->shapeDefinitionError) << "isError";
2017-03-01 19:37:10 -08:00
assertEqualsM("synchPointIndex", synchPointIndex, t->getTriggerWaveformSynchPointIndex());
2015-07-10 06:01:56 -07:00
2019-07-24 21:28:04 -07:00
ASSERT_NEAR(channel1duty, t->expectedDutyCycle[0], 0.0001) << msg << " channel1duty";
ASSERT_NEAR(channel2duty, t->expectedDutyCycle[1], 0.0001) << msg << " channel2duty";
2015-07-10 06:01:56 -07:00
}
static void testTriggerDecoder3(const char *msg, engine_type_e type, int synchPointIndex, float channel1duty, float channel2duty, float expectedGap) {
testTriggerDecoder2(msg, type, synchPointIndex, channel1duty, channel2duty);
assertEqualsM2("actual gap ratio", expectedGap, actualSynchGap, 0.001);
}
2019-01-14 12:31:56 -08:00
TEST(misc, testStartupFuelPumping) {
EngineTestHelper eth(FORD_INLINE_6_1995);
2015-07-10 06:01:56 -07:00
StartupFuelPumping sf;
engine->rpmCalculator.mockRpm = 0;
Sensor::setMockValue(SensorType::DriverThrottleIntent, 60);
sf.update();
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 1, sf.pumpsCounter) << "pc#1";
2015-07-10 06:01:56 -07:00
Sensor::setMockValue(SensorType::DriverThrottleIntent, 30);
sf.update();
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 1, sf.pumpsCounter) << "pumpsCounter#2";
2015-07-10 06:01:56 -07:00
sf.update();
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 1, sf.pumpsCounter) << "pc#3";
2015-07-10 06:01:56 -07:00
engine->rpmCalculator.mockRpm = 10;
sf.update();
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, sf.pumpsCounter) << "pc#4";
2015-07-10 06:01:56 -07:00
Sensor::setMockValue(SensorType::DriverThrottleIntent, 70);
2015-07-10 06:01:56 -07:00
engine->rpmCalculator.mockRpm = 0;
sf.update();
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 1, sf.pumpsCounter) << "pc#5";
2015-07-10 06:01:56 -07:00
Sensor::setMockValue(SensorType::DriverThrottleIntent, 30);
sf.update();
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 1, sf.pumpsCounter) << "pc#6";
2015-07-10 06:01:56 -07:00
Sensor::setMockValue(SensorType::DriverThrottleIntent, 70);
sf.update();
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 2, sf.pumpsCounter) << "pc#7";
2015-07-10 06:01:56 -07:00
}
static void assertREquals(void *expected, void *actual) {
2019-01-14 12:45:35 -08:00
ASSERT_EQ((float)(uint64_t)expected, (float)(uint64_t)actual);
2015-07-10 06:01:56 -07:00
}
2016-07-23 19:02:52 -07:00
static void assertREqualsM(const char *msg, void *expected, void *actual) {
assertEqualsM(msg, (float)(uint64_t)expected, (float)(uint64_t)actual);
}
2015-07-10 06:01:56 -07:00
extern bool_t debugSignalExecutor;
2019-01-14 12:31:56 -08:00
TEST(misc, testRpmCalculator) {
EngineTestHelper eth(FORD_INLINE_6_1995);
engine->tdcMarkEnabled = false;
// These tests were written when the default target AFR was 14.0, so replicate that
engineConfiguration->stoichRatioPrimary = 14;
2020-07-28 14:27:34 -07:00
EXPECT_CALL(eth.mockAirmass, getAirmass(_))
.WillRepeatedly(Return(AirmassResult{0.1008f, 50.0f}));
2018-07-28 11:33:32 -07:00
IgnitionEventList *ilist = &engine->ignitionEvents;
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, ilist->isReady) << "size #1";
2015-07-10 06:01:56 -07:00
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 720, engine->engineCycle) << "engineCycle";
2015-07-10 06:01:56 -07:00
2018-09-10 19:23:16 -07:00
efiAssertVoid(CUSTOM_ERR_6670, engineConfiguration!=NULL, "null config in engine");
2015-07-10 06:01:56 -07:00
setWholeTimingTable(-13);
2015-07-10 06:01:56 -07:00
engineConfiguration->trigger.customTotalToothCount = 8;
engineConfiguration->globalFuelCorrection = 3;
eth.applyTriggerWaveform();
2015-07-10 06:01:56 -07:00
setFlatInjectorLag(0);
2015-07-10 06:01:56 -07:00
engine->updateSlowSensors();
2019-01-10 20:24:36 -08:00
2019-01-21 18:48:58 -08:00
ASSERT_EQ(0, GET_RPM());
2015-07-10 06:01:56 -07:00
// triggerIndexByAngle update is now fixed! prepareOutputSignals() wasn't reliably called
ASSERT_EQ(5, engine->triggerCentral.triggerShape.findAngleIndex(&engine->triggerCentral.triggerFormDetails, 240));
ASSERT_EQ(5, engine->triggerCentral.triggerShape.findAngleIndex(&engine->triggerCentral.triggerFormDetails, 241));
2016-01-30 19:03:36 -08:00
2019-01-10 20:33:50 -08:00
eth.fireTriggerEvents(/* count */ 48);
2016-01-24 22:02:55 -08:00
2019-01-21 18:48:58 -08:00
ASSERT_EQ( 1500, GET_RPM()) << "RPM";
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 15, engine->triggerCentral.triggerState.getCurrentIndex()) << "index #1";
2015-07-10 06:01:56 -07:00
2021-10-01 19:29:44 -07:00
eth.executeActions();
2015-07-10 06:01:56 -07:00
2019-08-24 23:01:09 -07:00
// debugSignalExecutor = true;
2015-07-10 06:01:56 -07:00
2021-07-03 07:37:03 -07:00
ASSERT_EQ(engine->triggerCentral.triggerState.getShaftSynchronized(), 1);
2016-01-24 22:02:55 -08:00
2019-01-21 19:34:17 -08:00
eth.moveTimeForwardMs(5 /*ms*/);
2015-07-10 06:01:56 -07:00
2019-01-10 18:50:13 -08:00
int start = eth.getTimeNowUs();
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 485000, start) << "start value";
2016-01-24 22:02:55 -08:00
eth.engine.periodicFastCallback();
2015-07-10 06:01:56 -07:00
ASSERT_NEAR(engine->engineState.timingAdvance, 707, 0.1f);
2018-07-28 11:33:32 -07:00
assertEqualsM("fuel #1", 4.5450, engine->injectionDuration);
InjectionEvent *ie0 = &engine->injectionEvents.elements[0];
2019-10-07 22:03:57 -07:00
assertEqualsM("injection angle", 31.365, ie0->injectionStart.angleOffsetFromTriggerEvent);
2016-01-26 18:01:37 -08:00
2018-07-28 17:02:01 -07:00
eth.firePrimaryTriggerRise();
ASSERT_EQ(1500, eth.engine.rpmCalculator.getRpm());
2015-07-10 06:01:56 -07:00
2018-07-28 11:33:32 -07:00
assertEqualsM("dwell", 4.5, engine->engineState.dwellAngle);
assertEqualsM("fuel #2", 4.5450, engine->injectionDuration);
assertEqualsM("one degree", 111.1111, engine->rpmCalculator.oneDegreeUs);
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 1, ilist->isReady) << "size #2";
2019-11-23 14:44:44 -08:00
ASSERT_EQ( 0, ilist->elements[0].dwellPosition.triggerEventIndex) << "dwell @ index";
2019-10-07 22:03:57 -07:00
assertEqualsM("dwell offset", 8.5, ilist->elements[0].dwellPosition.angleOffsetFromTriggerEvent);
2015-07-10 06:01:56 -07:00
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, eth.engine.triggerCentral.triggerState.getCurrentIndex()) << "index #2";
ASSERT_EQ( 2, engine->executor.size()) << "queue size/2";
2016-01-30 19:03:36 -08:00
{
scheduling_s *ev0 = engine->executor.getForUnitTest(0);
2015-07-10 06:01:56 -07:00
assertREqualsM("Call@0", (void*)ev0->action.getCallback(), (void*)turnSparkPinHigh);
2018-12-08 15:35:05 -08:00
assertEqualsM("ev 0", start + 944, ev0->momentX);
assertEqualsLM("coil 0", (uintptr_t)&enginePins.coils[0], (uintptr_t)((IgnitionEvent*)ev0->action.getArgument())->outputs[0]);
2016-01-25 20:01:36 -08:00
scheduling_s *ev1 = engine->executor.getForUnitTest(1);
assertREqualsM("Call@1", (void*)ev1->action.getCallback(), (void*)fireSparkAndPrepareNextSchedule);
2018-12-08 15:35:05 -08:00
assertEqualsM("ev 1", start + 1444, ev1->momentX);
assertEqualsLM("coil 1", (uintptr_t)&enginePins.coils[0], (uintptr_t)((IgnitionEvent*)ev1->action.getArgument())->outputs[0]);
2016-01-25 20:01:36 -08:00
2016-01-30 19:03:36 -08:00
}
2016-01-25 20:01:36 -08:00
engine->executor.clear();
2015-07-10 06:01:56 -07:00
2018-07-28 17:02:01 -07:00
eth.fireFall(5);
eth.fireRise(5);
eth.fireFall(5);
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 3, eth.engine.triggerCentral.triggerState.getCurrentIndex()) << "index #3";
ASSERT_EQ( 4, engine->executor.size()) << "queue size 3";
assertEqualsM("ev 3", start + 13333 - 1515, engine->executor.getForUnitTest(0)->momentX);
assertEqualsM2("ev 5", start + 14277, engine->executor.getForUnitTest(1)->momentX, 2);
assertEqualsM("3/3", start + 14777, engine->executor.getForUnitTest(2)->momentX);
engine->executor.clear();
2015-07-10 06:01:56 -07:00
ASSERT_EQ(5, engine->triggerCentral.triggerShape.findAngleIndex(&engine->triggerCentral.triggerFormDetails, 240));
ASSERT_EQ(5, engine->triggerCentral.triggerShape.findAngleIndex(&engine->triggerCentral.triggerFormDetails, 241));
2016-01-30 19:03:36 -08:00
2018-07-28 17:02:01 -07:00
eth.fireFall(5);
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, engine->executor.size()) << "queue size 4.1";
2016-01-30 19:03:36 -08:00
2018-07-28 17:06:55 -07:00
eth.fireRise(5);
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 4, engine->executor.size()) << "queue size 4.2";
2016-01-30 19:03:36 -08:00
2018-07-28 17:06:55 -07:00
eth.fireRise(5);
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 4, engine->executor.size()) << "queue size 4.3";
2016-01-30 19:03:36 -08:00
assertEqualsM("dwell", 4.5, eth.engine.engineState.dwellAngle);
2017-11-06 19:29:39 -08:00
assertEqualsM("fuel #3", 4.5450, eth.engine.injectionDuration);
ASSERT_EQ(1500, eth.engine.rpmCalculator.getRpm());
2016-01-30 19:03:36 -08:00
2019-01-10 18:50:13 -08:00
eth.assertInjectorUpEvent("ev 0/2", 0, -4849, 2);
2016-11-30 17:02:41 -08:00
2016-01-30 19:03:36 -08:00
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 6, eth.engine.triggerCentral.triggerState.getCurrentIndex()) << "index #4";
ASSERT_EQ( 4, engine->executor.size()) << "queue size 4";
engine->executor.clear();
2015-07-10 06:01:56 -07:00
2018-07-28 17:02:01 -07:00
eth.fireFall(5);
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 2, engine->executor.size()) << "queue size 5";
2016-07-23 19:02:52 -07:00
// todo: assert queue elements
engine->executor.clear();
2015-07-10 06:01:56 -07:00
2018-07-28 17:06:55 -07:00
eth.fireRise(5);
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 2, engine->executor.size()) << "queue size 6";
assertEqualsM("6/0", start + 40944, engine->executor.getForUnitTest(0)->momentX);
assertEqualsM("6/1", start + 41444, engine->executor.getForUnitTest(1)->momentX);
engine->executor.clear();
2015-07-10 06:01:56 -07:00
2018-07-28 17:02:01 -07:00
eth.fireFall(5);
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, engine->executor.size()) << "queue size 7";
engine->executor.clear();
2015-07-10 06:01:56 -07:00
2019-01-21 16:15:17 -08:00
eth.fireRise(5 /*ms*/);
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 4, engine->executor.size()) << "queue size 8";
2016-07-23 19:02:52 -07:00
// todo: assert queue elements completely
assertEqualsM("8/0", start + 53333 - 1515, engine->executor.getForUnitTest(0)->momentX);
assertEqualsM2("8/1", start + 54277, engine->executor.getForUnitTest(1)->momentX, 0);
assertEqualsM2("8/2", start + 54777, engine->executor.getForUnitTest(2)->momentX, 0);
engine->executor.clear();
2015-07-10 06:01:56 -07:00
2018-07-28 17:06:55 -07:00
eth.fireFall(5);
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, engine->executor.size()) << "queue size 9";
engine->executor.clear();
2015-07-10 06:01:56 -07:00
2018-07-28 17:06:55 -07:00
eth.fireRise(5);
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, engine->executor.size()) << "queue size 10";
engine->executor.clear();
2015-07-10 06:01:56 -07:00
}
2020-04-26 17:40:06 -07:00
TEST(misc, testAnotherTriggerDecoder) {
testTriggerDecoder2("Miata 2003", FRANKENSO_MAZDA_MIATA_2003, 3, 0.38888889, 0.0);
2020-04-26 17:40:06 -07:00
}
2019-01-14 12:31:56 -08:00
TEST(misc, testTriggerDecoder) {
2018-12-25 14:26:36 -08:00
printf("====================================================================================== testTriggerDecoder\r\n");
2015-07-10 06:01:56 -07:00
2020-04-26 17:40:06 -07:00
{
2016-10-31 19:02:12 -07:00
persistent_config_s c;
Engine e;
EngineTestHelperBase base(&e, &c.engineConfiguration, &c);
TriggerWaveform * s = &e.triggerCentral.triggerShape;
2015-07-10 06:01:56 -07:00
s->useOnlyRisingEdgeForTriggerTemp = false;
initializeSkippedToothTriggerWaveformExt(s, 2, 0, FOUR_STROKE_CAM_SENSOR);
2015-07-10 06:01:56 -07:00
assertEqualsM("shape size", s->getSize(), 4);
ASSERT_EQ(s->wave->getSwitchTime(0), 0.25);
ASSERT_EQ(s->wave->getSwitchTime(1), 0.5);
ASSERT_EQ(s->wave->getSwitchTime(2), 0.75);
ASSERT_EQ(s->wave->getSwitchTime(3), 1);
2015-07-10 06:01:56 -07:00
2020-04-26 17:40:06 -07:00
}
2018-12-25 14:26:36 -08:00
printf("====================================================================================== testTriggerDecoder part 2\r\n");
2015-07-10 06:01:56 -07:00
testDodgeNeonDecoder();
2017-03-04 17:52:24 -08:00
testTriggerDecoder2("Dodge Neon 1995", DODGE_NEON_1995, 8, 0.4931, 0.2070);
2015-07-10 06:01:56 -07:00
2017-03-04 17:52:24 -08:00
testTriggerDecoder2("ford aspire", FORD_ASPIRE_1996, 4, 0.0000, 0.5);
2015-07-10 06:01:56 -07:00
testTriggerDecoder2("dodge ram", DODGE_RAM, 16, 0.5000, 0.06);
2021-11-06 17:24:41 -07:00
testTriggerDecoder2("Miata NB2", HELLEN_NB2, 3, 0.3888888955, 0);
2015-07-10 06:01:56 -07:00
2018-12-25 14:26:36 -08:00
printf("====================================================================================== testTriggerDecoder part 3\r\n");
2017-03-01 18:38:14 -08:00
2017-03-06 14:42:16 -08:00
testTriggerDecoder2("test 2/1 both", TEST_ISSUE_366_BOTH, 0, 0.2500, 0.0);
testTriggerDecoder2("test 2/1 rise", TEST_ISSUE_366_RISE, 0, 0.0000, 0.0);
2015-09-24 16:01:36 -07:00
testTriggerDecoder2("test engine", TEST_ENGINE, 0, 0.7500, 0.2500);
2015-07-10 06:01:56 -07:00
testTriggerDecoder2("testGY6_139QMB", GY6_139QMB, 0, 0.4375, 0.0);
testTriggerDecoder2("testSubary", SUBARU_2003_WRX, 0, 0.4000, 0.0);
testTriggerDecoder2("testFordEscortGt", FORD_ESCORT_GT, 0, 0.8096, 0.3844);
2018-01-01 20:04:31 -08:00
testTriggerDecoder2("NISSAN_PRIMERA", NISSAN_PRIMERA, 2, 0.9611, 0.0);
2017-03-18 17:59:52 -07:00
testTriggerDecoder2("test1+1", DEFAULT_FRANKENSO, 0, 0.7500, 0.2500);
2015-07-10 06:01:56 -07:00
testTriggerDecoder2("testCitroen", CITROEN_TU3JP, 0, 0.4833, 0);
testTriggerDecoder2("testAccordCd 2w", HONDA_ACCORD_CD_TWO_WIRES, 2, 0.9167, 0.5);
2017-02-23 19:27:12 -08:00
testTriggerDecoder2("testMitsu", MITSU_4G93, 0, 0.3553, 0.3752);
2015-09-13 10:02:13 -07:00
{
EngineTestHelper eth(MITSU_4G93);
2015-09-13 10:02:13 -07:00
2016-02-27 20:03:34 -08:00
eth.persistentConfig.engineConfiguration.useOnlyRisingEdgeForTrigger = false;
eth.persistentConfig.engineConfiguration.sensorChartMode = SC_DETAILED_RPM;
applyNonPersistentConfiguration();
2015-09-13 13:01:38 -07:00
2015-09-13 10:02:13 -07:00
}
2021-11-06 17:24:41 -07:00
testTriggerDecoder2("miata 1990", MRE_MIATA_NA6_VAF, 4, 1 - 0.7015, 1 - 0.3890);
2015-07-10 06:01:56 -07:00
testTriggerDecoder3("citroen", CITROEN_TU3JP, 0, 0.4833, 0.0, 2.9994);
testTriggerDecoder2("CAMARO_4", CAMARO_4, 40, 0.5, 0);
2016-08-26 14:02:37 -07:00
2020-08-29 06:39:52 -07:00
testTriggerDecoder3("neon NGC4", DODGE_NEON_2003_CRANK, 6, 0.5000, 0.0, CHRYSLER_NGC4_GAP);
2015-09-24 16:01:36 -07:00
{
EngineTestHelper eth(DODGE_NEON_2003_CRANK);
2015-09-24 16:01:36 -07:00
2016-02-27 20:03:34 -08:00
printf("!!!!!!!!!!!!!!!!!! Now trying with only rising edges !!!!!!!!!!!!!!!!!\r\n");
engineConfiguration->useOnlyRisingEdgeForTrigger = true;
2015-09-24 16:01:36 -07:00
applyNonPersistentConfiguration();
prepareShapes();
2015-09-24 16:01:36 -07:00
}
2015-07-10 06:01:56 -07:00
testTriggerDecoder2("sachs", SACHS, 0, 0.4800, 0.000);
testTriggerDecoder2("vw ABA", VW_ABA, 0, 0.51666, 0.0);
2015-07-10 06:01:56 -07:00
}
2016-08-26 14:02:37 -07:00
2016-08-26 16:02:56 -07:00
extern fuel_Map3D_t fuelMap;
static void assertInjectionEventBase(const char *msg, InjectionEvent *ev, int injectorIndex, int eventIndex, angle_t angleOffset) {
ASSERT_EQ(injectorIndex, ev->outputs[0]->injectorIndex) << msg << "inj index";
2019-10-07 21:54:19 -07:00
assertEqualsM4(msg, " event index", eventIndex, ev->injectionStart.triggerEventIndex);
2019-10-07 22:03:57 -07:00
assertEqualsM4(msg, " event offset", angleOffset, ev->injectionStart.angleOffsetFromTriggerEvent);
2016-09-01 20:02:44 -07:00
}
static void assertInjectionEvent(const char *msg, InjectionEvent *ev, int injectorIndex, int eventIndex, angle_t angleOffset) {
assertInjectionEventBase(msg, ev, injectorIndex, eventIndex, angleOffset);
// There should NOT be a second injector configured
EXPECT_EQ(nullptr, ev->outputs[1]);
}
static void assertInjectionEventBatch(const char *msg, InjectionEvent *ev, int injectorIndex, int secondInjectorIndex, int eventIndex, angle_t angleOffset) {
assertInjectionEventBase(msg, ev, injectorIndex, eventIndex, angleOffset);
// There should be a second injector - confirm it's the correct one
ASSERT_NE(nullptr, ev->outputs[1]);
EXPECT_EQ(secondInjectorIndex, ev->outputs[1]->injectorIndex);
}
2016-11-07 20:01:47 -08:00
static void setTestBug299(EngineTestHelper *eth) {
2018-03-04 13:13:23 -08:00
setupSimpleTestEngineWithMafAndTT_ONE_trigger(eth);
2020-07-31 12:44:22 -07:00
EXPECT_CALL(eth->mockAirmass, getAirmass(_))
.WillRepeatedly(Return(AirmassResult{0.1008001f, 50.0f}));
2020-07-31 12:44:22 -07:00
2016-11-07 20:01:47 -08:00
Engine *engine = &eth->engine;
2016-11-07 20:01:47 -08:00
2019-01-21 19:32:30 -08:00
eth->assertRpm(0, "RPM=0");
2020-07-31 12:44:22 -07:00
2018-07-28 16:37:10 -07:00
eth->fireTriggerEventsWithDuration(20);
2016-08-27 10:01:55 -07:00
// still no RPM since need to cycles measure cycle duration
2019-01-21 19:32:30 -08:00
eth->assertRpm(0, "setTestBug299: RPM#1");
2018-07-28 16:37:10 -07:00
eth->fireTriggerEventsWithDuration(20);
2019-01-21 19:32:30 -08:00
eth->assertRpm(3000, "setTestBug299: RPM#2");
2016-08-27 10:01:55 -07:00
2018-03-04 13:38:01 -08:00
eth->clearQueue();
2016-08-26 20:02:24 -07:00
2016-08-27 17:02:25 -07:00
/**
* Trigger up - scheduling fuel for full engine cycle
*/
2018-07-28 16:51:41 -07:00
eth->fireRise(20);
2016-08-27 17:02:25 -07:00
// fuel schedule - short pulses.
// time...|0.......|10......|20......|30......|40
// inj #0 |.......#|........|.......#|........|
// inj #1 |........|.......#|........|.......#|
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 4, engine->executor.size()) << "qs#00";
ASSERT_EQ( 3, getRevolutionCounter()) << "rev cnt#3";
2019-01-10 19:43:31 -08:00
eth->assertInjectorUpEvent("setTestBug299: 1@0", 0, MS2US(8.5), 0);
eth->assertInjectorDownEvent("@1", 1, MS2US(10), 0);
2019-01-10 18:50:13 -08:00
eth->assertInjectorUpEvent("1@2", 2, MS2US(18.5), 1);
2019-01-10 19:43:31 -08:00
eth->assertInjectorDownEvent("1@3", 3, MS2US(20), 1);
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, eth->executeActions()) << "exec#0";
2016-08-26 17:03:06 -07:00
FuelSchedule * t = &engine->injectionEvents;
2016-11-30 18:06:24 -08:00
2019-10-07 23:17:32 -07:00
assertInjectionEvent("#0", &t->elements[0], 0, 1, 153);
assertInjectionEvent("#1_i_@", &t->elements[1], 1, 1, 333);
assertInjectionEvent("#2@", &t->elements[2], 0, 0, 153);
assertInjectionEvent("inj#3@", &t->elements[3], 1, 0, 153 + 180);
2016-09-02 22:02:32 -07:00
2016-08-27 17:02:25 -07:00
/**
* Trigger down - no new events, executing some
*/
2018-07-28 17:02:01 -07:00
eth->fireFall(20);
2016-08-27 17:02:25 -07:00
// same exact picture
// time...|-20.....|-10.....|0.......|10......|20
2016-08-27 14:01:58 -07:00
// inj #0 |.......#|........|.......#|........|
// inj #1 |........|.......#|........|.......#|
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 8, engine->executor.size()) << "qs#0";
ASSERT_EQ( 3, getRevolutionCounter()) << "rev cnt#3";
2019-01-10 19:43:31 -08:00
eth->assertInjectorUpEvent("02@0", 0, MS2US(-11.5), 0);
eth->assertInjectorDownEvent("@1", 1, MS2US(-10), 0);
eth->assertInjectorUpEvent("@2", 2, MS2US(-1.5), 1);
eth->assertInjectorDownEvent("02@3", 3, MS2US(0), 1);
eth->assertInjectorUpEvent("02@4", 4, MS2US(8.5), 0);
eth->assertInjectorDownEvent("@5", 5, MS2US(10), 0);
eth->assertInjectorUpEvent("02@6", 6, MS2US(18.5), 1);
eth->assertInjectorDownEvent("@7", 7, MS2US(20), 1);
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 4, eth->executeActions()) << "exec#1";
2016-08-27 14:01:58 -07:00
2016-08-27 17:02:25 -07:00
/**
* Trigger up again
*/
2019-01-21 19:34:17 -08:00
eth->moveTimeForwardMs(20 /*ms*/);
2019-01-10 19:43:31 -08:00
eth->assertInjectorUpEvent("22@0", 0, MS2US(-11.5), 0);
eth->assertInjectorDownEvent("22@1", 1, MS2US(-10), 0);
eth->assertInjectorUpEvent("22@2", 2, MS2US(-1.5), 1);
eth->assertInjectorDownEvent("22@3", 3, MS2US(0), 1);
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 4, eth->executeActions()) << "exec#20";
2016-09-04 21:02:31 -07:00
2016-09-03 10:02:55 -07:00
eth->firePrimaryTriggerRise();
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 4, engine->executor.size()) << "qs#0-2";
2016-08-27 14:01:58 -07:00
// fuel schedule - short pulses. and more realistic schedule this time
2016-08-27 17:02:25 -07:00
// time...|-20.....|-10.....|0.......|10......|20
2016-08-27 14:01:58 -07:00
// inj #0 |.......#|........|.......#|........|
// inj #1 |........|.......#|........|.......#|
2019-01-10 19:43:31 -08:00
eth->assertInjectorUpEvent("2@0", 0, MS2US(8.5), 0);
eth->assertInjectorDownEvent("@1", 1, MS2US(10), 0);
eth->assertInjectorUpEvent("@2", 2, MS2US(18.5), 1);
eth->assertInjectorDownEvent("2@3", 3, MS2US(20), 1);
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, eth->executeActions()) << "exec#2";
2016-08-27 17:02:25 -07:00
2019-01-10 20:15:24 -08:00
eth->moveTimeForwardUs(MS2US(20));
2019-01-10 18:26:02 -08:00
eth->executeActions();
2016-09-03 10:02:55 -07:00
eth->firePrimaryTriggerFall();
2016-08-27 17:02:25 -07:00
// fuel schedule - short pulses. and more realistic schedule this time
// time...|-20.....|-10.....|0.......|10......|20
// inj #0 |.......#|........|........|........|
// inj #1 |........|.......#|........|........|
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 4, engine->executor.size()) << "qs#0-2";
ASSERT_EQ( 4, getRevolutionCounter()) << "rev cnt#4";
2019-01-10 19:43:31 -08:00
eth->assertInjectorUpEvent("0@0", 0, MS2US(8.5), 0);
eth->assertInjectorDownEvent("0@1", 1, MS2US(10), 0);
eth->assertInjectorUpEvent("0@2", 2, MS2US(18.5), 1);
eth->assertInjectorDownEvent("0@3", 3, MS2US(20), 1);
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, eth->executeActions()) << "exec#3";
2016-08-27 14:01:58 -07:00
2016-08-26 16:02:56 -07:00
2019-08-26 20:41:04 -07:00
ASSERT_EQ( 1, engine->engineState.running.intakeTemperatureCoefficient) << "iatC";
ASSERT_EQ( 1, engine->engineState.running.coolantTemperatureCoefficient) << "cltC";
ASSERT_EQ( 0, engine->engineState.running.injectorLag) << "lag";
2016-08-26 16:02:56 -07:00
2019-01-21 18:48:58 -08:00
ASSERT_EQ( 3000, GET_RPM()) << "setTestBug299: RPM";
2016-08-26 16:02:56 -07:00
2017-11-06 19:29:39 -08:00
assertEqualsM("fuel#1", 1.5, engine->injectionDuration);
assertEqualsM("duty for maf=0", 7.5, getInjectorDutyCycle(GET_RPM()));
2016-09-03 10:02:55 -07:00
}
2016-09-04 20:02:10 -07:00
static void assertInjectors(const char *msg, int value0, int value1) {
assertEqualsM4(msg, "inj#0", value0, enginePins.injectors[0].currentLogicValue);
assertEqualsM4(msg, "inj#1", value1, enginePins.injectors[1].currentLogicValue);
}
static void setArray(float* p, size_t count, float value) {
while (count--) {
*p++ = value;
}
}
2019-01-21 19:45:37 -08:00
void doTestFuelSchedulerBug299smallAndMedium(int startUpDelayMs) {
2016-09-03 10:02:55 -07:00
printf("*************************************************** testFuelSchedulerBug299 small to medium\r\n");
EngineTestHelper eth(TEST_ENGINE);
engine->tdcMarkEnabled = false;
2019-01-21 19:45:37 -08:00
eth.moveTimeForwardMs(startUpDelayMs); // nice to know that same test works the same with different anount of idle time on start
2016-09-03 10:02:55 -07:00
setTestBug299(&eth);
FuelSchedule * t;
2016-08-26 16:02:56 -07:00
2016-12-01 17:01:57 -08:00
assertInjectors("#0_inj", 0, 0);
2016-09-04 20:02:10 -07:00
engine->periodicFastCallback();
2020-07-31 22:09:23 -07:00
engine->injectionDuration = 12.5f;
// Injection duration of 12.5ms
MockInjectorModel2 im;
EXPECT_CALL(im, getInjectionDuration(_)).WillRepeatedly(Return(12.5f));
engine->module<InjectorModel>().set(&im);
assertEqualsM("duty for maf=3", 62.5, getInjectorDutyCycle(GET_RPM()));
2016-08-26 15:02:39 -07:00
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 4, engine->executor.size()) << "qs#1";
2019-01-10 20:15:24 -08:00
eth.moveTimeForwardUs(MS2US(20));
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 4, eth.executeActions()) << "exec#2#0";
ASSERT_EQ( 0, engine->executor.size()) << "qs#1#2";
2016-09-04 22:03:25 -07:00
ASSERT_EQ( 4, getRevolutionCounter()) << "rev cnt#4#0";
2016-08-27 17:02:25 -07:00
eth.firePrimaryTriggerRise();
ASSERT_EQ( 5, getRevolutionCounter()) << "rev cnt#4#1";
2016-08-27 17:02:25 -07:00
// time...|0.......|10......|20......|30......|40......|50......|60......|
2016-09-02 23:03:32 -07:00
// inj #0 |########|##...###|########|.....###|########|........|........|
// inj #1 |.....###|########|....####|########|........|........|........|
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 6, engine->executor.size()) << "qs#4";
2016-11-30 20:02:42 -08:00
//todo assertInjectorUpEvent("04@0", 0, MS2US(0), 0);
// assertInjectorUpEvent("04@1", 1, MS2US(7.5), 1);
// assertInjectorDownEvent("04@2", 2, MS2US(12.5), 0);
// assertInjectorUpEvent("04@3", 3, MS2US(17.5), 0);
// assertInjectorDownEvent("04@4", 4, MS2US(20), 1);
// assertInjectorDownEvent("04@5", 5, MS2US(30), 0);
2016-11-08 22:02:15 -08:00
// assertInjectorDownEvent("04@6", 6, MS2US(30), 0);
// assertInjectorUpEvent("04@7", 7, MS2US(37.5), 0);
// assertInjectorDownEvent("04@8", 8, MS2US(40.0), 1);
// assertInjectorDownEvent("04@9", 9, MS2US(50.0), 0);
2016-08-27 13:02:12 -07:00
2016-11-08 22:02:15 -08:00
// {
// scheduling_s *ev = engine->executor.getForUnitTest(9);
// ASSERT_EQ( 5, getRevolutionCounter()) << "rev cnt#4#2";
2019-01-14 15:56:32 -08:00
// ASSERT_TRUE(ev == &engineConfiguration->fuelActuators[2].signalPair[1].signalTimerDown) << "down 50";
2016-11-08 22:02:15 -08:00
// }
2016-09-04 22:03:25 -07:00
2016-08-27 14:01:58 -07:00
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, eth.executeActions()) << "exec#4";
2016-08-27 14:01:58 -07:00
2018-07-28 17:06:55 -07:00
eth.fireFall(20);
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 8, engine->executor.size()) << "qs#2#1";
ASSERT_EQ( 5, getRevolutionCounter()) << "rev cnt#5";
2016-08-27 17:02:25 -07:00
// using old fuel schedule - but already wider pulses
// time...|-20.....|-10.....|0.......|10......|20......|30......|40......|
2016-09-02 23:03:32 -07:00
// inj #0 |........|.....###|########|.....###|########|........|........|
// inj #1 |.....###|########|.....###|########|........|........|........|
2016-11-30 20:02:42 -08:00
// assertInjectorUpEvent("5@0", 0, MS2US(-12.5), 1);
// assertInjectorDownEvent("5@1", 1, MS2US(-7.5), 0);
// assertInjectorUpEvent("5@2", 2, MS2US(-2.5), 0);
// assertInjectorDownEvent("5@3", 3, MS2US(0), 1);
// assertInjectorUpEvent("5@4", 4, MS2US(7.5), 1);
//
// assertInjectorDownEvent("5@4", 5, MS2US(10), 0);
// assertInjectorUpEvent("5@6", 6, MS2US(17.5), 0);
// assertInjectorDownEvent("5@7", 7, MS2US(20.0), 1);
// assertInjectorDownEvent("5@8", 8, MS2US(30.0), 0);
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 3, eth.executeActions()) << "exec#5";
2016-08-27 14:01:58 -07:00
/**
* one more revolution
*/
t = &engine->injectionEvents;
2016-11-30 18:06:24 -08:00
2019-10-07 23:17:32 -07:00
assertInjectionEvent("#0", &t->elements[0], 0, 0, 315);
assertInjectionEvent("#1__", &t->elements[1], 1, 1, 135);
assertInjectionEvent("inj#2", &t->elements[2], 0, 0, 153);
assertInjectionEvent("inj#3", &t->elements[3], 1, 0, 333);
2016-09-01 20:02:44 -07:00
2019-01-10 20:15:24 -08:00
eth.moveTimeForwardUs(MS2US(20));
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 5, engine->executor.size()) << "qs#02";
2016-11-30 20:02:42 -08:00
// assertInjectorUpEvent("6@0", 0, MS2US(-12.5), 1);
// assertInjectorDownEvent("6@1", 1, MS2US(-10.0), 0);
// assertInjectorUpEvent("6@2", 2, MS2US(-2.5), 0);
// assertInjectorDownEvent("6@3", 3, MS2US(0), 1);
// assertInjectorDownEvent("6@4", 4, MS2US(10.0), 0);
2016-09-04 20:02:10 -07:00
// so placing this 'executeAll' changes much?
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 5, eth.executeActions()) << "exec#07";
ASSERT_EQ( 0, engine->executor.size()) << "qs#07";
2016-11-30 20:02:42 -08:00
// assertInjectorDownEvent("26@0", 0, MS2US(10.0), 0);
2016-09-04 20:02:10 -07:00
2016-08-27 17:02:25 -07:00
eth.firePrimaryTriggerRise();
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 4, engine->executor.size()) << "qs#2#2";
ASSERT_EQ( 6, getRevolutionCounter()) << "rev cnt6";
2016-08-29 19:02:57 -07:00
// time...|-20.....|-10.....|0.......|10......|20......|30......|40......|
2016-09-02 23:03:32 -07:00
// inj #0 |########|.....###|########|....####|........|........|........|
// inj #1 |.....###|########|.....###|########|........|........|........|
2016-11-08 22:02:15 -08:00
// assertInjectorDownEvent("06@5", 5, MS2US(30.0), 0);
// assertInjectorUpEvent("06@6", 6, MS2US(37.5), 0);
// assertInjectorDownEvent("06@7", 7, MS2US(40.0), 1);
2016-08-27 14:01:58 -07:00
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, eth.executeActions()) << "exec#7";
2016-08-27 20:02:39 -07:00
2016-12-01 17:01:57 -08:00
assertInjectors("#1_ij_", 0, 0);
2016-08-27 20:02:39 -07:00
2019-01-10 20:15:24 -08:00
eth.moveTimeForwardUs(MS2US(20));
2016-08-27 13:02:12 -07:00
2016-08-29 19:02:57 -07:00
// time...|-20.....|-10.....|0.......|10......|20......|30......|40......|
2016-09-04 20:02:10 -07:00
// inj #0 |########|.......#|........|........|........|........|........|
2016-09-02 23:03:32 -07:00
// inj #1 |....####|########|........|........|........|........|........|
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 4, engine->executor.size()) << "qs#022";
2016-11-30 20:02:42 -08:00
// assertInjectorUpEvent("7@0", 0, MS2US(-12.5), 1);
// assertInjectorDownEvent("7@1", 1, MS2US(-10.0), 0);
// assertInjectorUpEvent("7@2", 2, MS2US(-2.5), 0);
// assertInjectorDownEvent("7@3", 3, MS2US(0), 1);
// assertInjectorDownEvent("7@4", 4, MS2US(10), 0);
//// assertInjectorDownEvent("i7@5", 5, MS2US(20.0), 0);
//// assertInjectorUpEvent("7@6", 6, MS2US(17.5), 0);
//// assertInjectorDownEvent("7@7", 7, MS2US(20), 1);
// // todo index 8
2016-09-04 20:02:10 -07:00
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 3, eth.executeActions()) << "executed #06";
2016-09-04 20:02:10 -07:00
assertInjectors("#4", 1, 0);
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 1, engine->executor.size()) << "qs#06";
2019-01-10 19:43:31 -08:00
eth.assertInjectorDownEvent("17@0", 0, MS2US(10), 0);
2016-11-08 22:02:15 -08:00
// assertInjectorDownEvent("17@1", 1, MS2US(10.0), 0);
// assertInjectorUpEvent("17@2", 2, MS2US(17.5), 0);
// assertInjectorDownEvent("17@3", 3, MS2US(20), 1);
2016-09-04 22:03:25 -07:00
// todo index 4
2016-09-04 20:02:10 -07:00
eth.firePrimaryTriggerFall();
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 5, engine->executor.size()) << "qs#3";
ASSERT_EQ( 6, getRevolutionCounter()) << "rev cnt6";
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, eth.executeActions()) << "executed #6";
2016-08-29 19:02:57 -07:00
2019-01-10 20:15:24 -08:00
eth.moveTimeForwardUs(MS2US(20));
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 4, eth.executeActions()) << "executed #06";
ASSERT_EQ( 1, engine->executor.size()) << "qs#06";
2016-12-17 08:01:40 -08:00
assertInjectors("inj#2", 1, 0);
2016-09-04 20:02:10 -07:00
2016-08-29 19:02:57 -07:00
eth.firePrimaryTriggerRise();
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 5, engine->executor.size()) << "Queue.size#03";
2020-07-31 22:09:23 -07:00
2019-01-10 19:43:31 -08:00
eth.assertInjectorUpEvent("07@0", 0, MS2US(7.5), 1);
eth.assertInjectorDownEvent("07@1", 1, MS2US(10), 0);
eth.assertInjectorUpEvent("07@2", 2, MS2US(17.5), 0);
eth.assertInjectorDownEvent("07@3", 3, MS2US(20), 1);
eth.assertInjectorDownEvent("07@4", 4, MS2US(30), 0);
2016-11-08 22:02:15 -08:00
// assertInjectorDownEvent("07@5", 5, MS2US(30), 0);
// assertInjectorUpEvent("07@6", 6, MS2US(37.5), 0);
// assertInjectorDownEvent("07@7", 7, MS2US(40), 1);
// assertInjectorDownEvent("07@8", 8, MS2US(50), 0);
2016-08-29 19:02:57 -07:00
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, eth.executeActions()) << "executeAll#3";
2019-01-10 20:15:24 -08:00
eth.moveTimeForwardUs(MS2US(20));
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 4, eth.executeActions()) << "executeAll#4";
2016-09-04 20:02:10 -07:00
t = &engine->injectionEvents;
2016-11-30 18:06:24 -08:00
2019-10-07 23:17:32 -07:00
assertInjectionEvent("#0#", &t->elements[0], 0, 0, 315);
assertInjectionEvent("#1#", &t->elements[1], 1, 1, 135);
assertInjectionEvent("#2#", &t->elements[2], 0, 1, 315);
assertInjectionEvent("#3#", &t->elements[3], 1, 0, 45 + 90);
2016-09-02 23:03:32 -07:00
2020-07-31 22:09:23 -07:00
engine->injectionDuration = 17.5;
// Injection duration of 17.5ms
MockInjectorModel2 im2;
EXPECT_CALL(im2, getInjectionDuration(_)).WillRepeatedly(Return(17.5f));
engine->module<InjectorModel>().set(&im2);
2016-09-03 10:02:55 -07:00
// duty cycle above 75% is a special use-case because 'special' fuel event overlappes the next normal event in batch mode
assertEqualsM("duty for maf=3", 87.5, getInjectorDutyCycle(GET_RPM()));
2016-09-03 10:02:55 -07:00
2016-08-27 13:02:12 -07:00
2019-10-07 23:17:32 -07:00
assertInjectionEvent("#03", &t->elements[0], 0, 0, 315);
2016-09-03 10:02:55 -07:00
2016-09-04 20:02:10 -07:00
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 1, enginePins.injectors[0].currentLogicValue) << "inj#0";
2016-09-04 20:02:10 -07:00
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 1, engine->executor.size()) << "Queue.size#04";
2019-01-10 19:43:31 -08:00
eth.assertInjectorDownEvent("08@0", 0, MS2US(10), 0);
2016-11-08 22:02:15 -08:00
// assertInjectorDownEvent("08@1", 1, MS2US(10), 0);
// assertInjectorUpEvent("08@2", 2, MS2US(17.5), 0);
// assertInjectorDownEvent("08@3", 3, MS2US(20), 1);
// assertInjectorDownEvent("08@4", 4, MS2US(30), 0);
2016-09-04 20:02:10 -07:00
2016-09-03 10:02:55 -07:00
eth.firePrimaryTriggerFall();
2016-09-04 20:02:10 -07:00
2019-01-10 18:26:02 -08:00
eth.executeActions();
2018-07-28 16:51:41 -07:00
eth.fireRise(20);
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 7, engine->executor.size()) << "Queue.size#05";
2019-01-10 18:26:02 -08:00
eth.executeActions();
2016-09-03 10:02:55 -07:00
2018-07-28 17:06:55 -07:00
eth.fireFall(20);
2019-01-10 18:26:02 -08:00
eth.executeActions();
2016-09-03 10:02:55 -07:00
2019-01-10 20:15:24 -08:00
eth.moveTimeForwardUs(MS2US(20));
2019-01-10 18:26:02 -08:00
eth.executeActions();
2016-09-03 10:02:55 -07:00
eth.firePrimaryTriggerRise();
t = &engine->injectionEvents;
2016-11-30 18:06:24 -08:00
2019-10-07 23:17:32 -07:00
assertInjectionEvent("#00", &t->elements[0], 0, 0, 225); // 87.5 duty cycle
assertInjectionEvent("#10", &t->elements[1], 1, 1, 45);
assertInjectionEvent("#20", &t->elements[2], 0, 1, 225);
assertInjectionEvent("#30", &t->elements[3], 1, 0, 45);
2016-09-03 10:02:55 -07:00
// todo: what's what? a mix of new something and old something?
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 4, engine->executor.size()) << "qs#5";
2016-11-30 20:02:42 -08:00
// assertInjectorDownEvent("8@0", 0, MS2US(5.0), 1);
// assertInjectorUpEvent("8@1", 1, MS2US(7.5), 1);
// assertInjectorDownEvent("8@2", 2, MS2US(15.0), 0);
// assertInjectorUpEvent("8@3", 3, MS2US(17.5), 0);
// assertInjectorDownEvent("8@4", 4, MS2US(25), 1);
// assertInjectorDownEvent("8@5", 5, MS2US(35), 0);
//// assertInjectorDownEvent("8@6", 6, MS2US(35), 0);
//// assertInjectorUpEvent("8@7", 7, MS2US(37.5), 0);
//// assertInjectorDownEvent("8@8", 8, MS2US(45), 1);
//// assertInjectorDownEvent("8@9", 9, MS2US(55), 0);
2016-09-03 10:02:55 -07:00
ASSERT_EQ( 0, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testFuelSchedulerBug299smallAndMedium";
/*
ASSERT_EQ(CUSTOM_OBD_SKIPPED_FUEL, unitTestWarningCodeState.recentWarnings.get(0));
*/
2016-08-26 14:02:37 -07:00
}
2016-09-03 10:02:55 -07:00
void setInjectionMode(int value) {
2017-11-06 19:46:18 -08:00
engineConfiguration->injectionMode = (injection_mode_e) value;
incrementGlobalConfigurationVersion();
2017-11-06 19:46:18 -08:00
}
2019-01-21 19:45:37 -08:00
TEST(big, testFuelSchedulerBug299smallAndMedium) {
doTestFuelSchedulerBug299smallAndMedium(0);
doTestFuelSchedulerBug299smallAndMedium(1000);
}
TEST(big, testTwoWireBatch) {
EngineTestHelper eth(TEST_ENGINE);
setupSimpleTestEngineWithMafAndTT_ONE_trigger(&eth);
2020-07-28 14:27:34 -07:00
EXPECT_CALL(eth.mockAirmass, getAirmass(_))
.WillRepeatedly(Return(AirmassResult{0.1008f, 50.0f}));
engineConfiguration->injectionMode = IM_BATCH;
engineConfiguration->twoWireBatchInjection = true;
eth.fireTriggerEventsWithDuration(20);
// still no RPM since need to cycles measure cycle duration
eth.fireTriggerEventsWithDuration(20);
2021-10-01 19:29:44 -07:00
eth.executeActions();
/**
* Trigger up - scheduling fuel for full engine cycle
*/
eth.fireRise(20);
FuelSchedule * t = &engine->injectionEvents;
assertInjectionEventBatch("#0", &t->elements[0], 0, 3, 1, 153); // Cyl 1 and 4
assertInjectionEventBatch("#1_i_@", &t->elements[1], 2, 1, 1, 153 + 180); // Cyl 3 and 2
assertInjectionEventBatch("#2@", &t->elements[2], 3, 0, 0, 153); // Cyl 4 and 1
assertInjectionEventBatch("inj#3@", &t->elements[3], 1, 2, 0, 153 + 180); // Cyl 2 and 3
}
TEST(big, testSequential) {
EngineTestHelper eth(TEST_ENGINE);
2020-07-28 14:27:34 -07:00
EXPECT_CALL(eth.mockAirmass, getAirmass(_))
.WillRepeatedly(Return(AirmassResult{0.1008f, 50.0f}));
setupSimpleTestEngineWithMafAndTT_ONE_trigger(&eth);
engineConfiguration->injectionMode = IM_SEQUENTIAL;
eth.fireTriggerEventsWithDuration(20);
// still no RPM since need to cycles measure cycle duration
eth.fireTriggerEventsWithDuration(20);
2021-10-01 19:29:44 -07:00
eth.executeActions();
2017-11-06 19:33:06 -08:00
/**
* Trigger up - scheduling fuel for full engine cycle
*/
eth.fireRise(20);
FuelSchedule * t = &engine->injectionEvents;
assertInjectionEvent("#0", &t->elements[0], 0, 1, 126); // Cyl 1
assertInjectionEvent("#1_i_@", &t->elements[1], 2, 1, 126 + 180); // Cyl 3
assertInjectionEvent("#2@", &t->elements[2], 3, 0, 126); // Cyl 4
assertInjectionEvent("inj#3@", &t->elements[3], 1, 0, 126 + 180); // Cyl 2
}
TEST(big, testFuelSchedulerBug299smallAndLarge) {
EngineTestHelper eth(TEST_ENGINE);
engine->tdcMarkEnabled = false;
2016-09-03 11:01:47 -07:00
setTestBug299(&eth);
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 4, engine->executor.size()) << "Lqs#0";
2016-09-03 10:02:55 -07:00
engine->periodicFastCallback();
2020-07-31 22:09:23 -07:00
engine->injectionDuration = 17.5f;
// Injection duration of 17.5ms
MockInjectorModel2 im;
EXPECT_CALL(im, getInjectionDuration(_)).WillRepeatedly(Return(17.5f));
engine->module<InjectorModel>().set(&im);
assertEqualsM("Lduty for maf=3", 87.5, getInjectorDutyCycle(GET_RPM()));
2016-09-03 11:01:47 -07:00
2016-09-03 22:01:54 -07:00
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 4, engine->executor.size()) << "Lqs#1";
2019-01-10 20:15:24 -08:00
eth.moveTimeForwardUs(MS2US(20));
2019-01-10 18:26:02 -08:00
eth.executeActions();
2016-09-03 22:01:54 -07:00
// injector #1 is low before the test
2019-01-14 16:02:36 -08:00
ASSERT_FALSE(enginePins.injectors[0].currentLogicValue) << "injector@0";
2016-09-03 22:01:54 -07:00
2016-09-03 11:01:47 -07:00
eth.firePrimaryTriggerRise();
2016-09-03 22:01:54 -07:00
2016-09-03 11:01:47 -07:00
// time...|0.......|10......|20......|30......|40......|50......|60......|
2016-09-03 22:01:54 -07:00
// inj #0 |########|########|########|.....###|########|........|........|
// inj #1 |..######|########|....####|########|........|........|........|
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 6, engine->executor.size()) << "Lqs#4";
2019-01-10 19:43:31 -08:00
eth.assertInjectorUpEvent("L04@0", 0, MS2US(8.5), 0);
eth.assertInjectorUpEvent("L04@1", 1, MS2US(12.5), 0);
2016-09-03 22:01:54 -07:00
// special overlapping injection is merged with one of the scheduled injections
2019-01-10 19:43:31 -08:00
eth.assertInjectorUpEvent("L04@2", 2, MS2US(18.5), 1);
2016-09-03 22:01:54 -07:00
2019-01-10 19:43:31 -08:00
eth.assertInjectorDownEvent("L04@3", 3, MS2US(26), 0);
eth.assertInjectorDownEvent("L04@4", 4, MS2US(30), 0);
2016-09-03 22:01:54 -07:00
2016-11-08 22:02:15 -08:00
// assertInjectorDownEvent("L04@5", 5, MS2US(30), 0);
// assertInjectorUpEvent("L04@6", 6, MS2US(32.5), 0);
// assertInjectorDownEvent("L04@7", 7, MS2US(40.0), 1);
// assertInjectorDownEvent("L04@8", 8, MS2US(50.0), 0);
2016-09-03 22:01:54 -07:00
2016-09-03 10:02:55 -07:00
engine->executor.executeAll(eth.getTimeNowUs() + 1);
2016-09-03 22:01:54 -07:00
// injector goes high...
2019-01-14 16:02:36 -08:00
ASSERT_FALSE(enginePins.injectors[0].currentLogicValue) << "injector@1";
2016-09-03 10:02:55 -07:00
engine->executor.executeAll(eth.getTimeNowUs() + MS2US(17.5) + 1);
2016-09-04 23:02:00 -07:00
// injector does not go low too soon, that's a feature :)
2019-01-14 15:56:32 -08:00
ASSERT_TRUE(enginePins.injectors[0].currentLogicValue) << "injector@2";
2016-09-03 10:02:55 -07:00
2018-07-28 17:08:48 -07:00
eth.fireFall(20);
2016-09-04 23:02:00 -07:00
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 6, engine->executor.size()) << "Lqs#04";
2019-01-10 19:43:31 -08:00
eth.assertInjectorUpEvent("L015@0", 0, MS2US(-1.5), 1);
eth.assertInjectorUpEvent("L015@1", 1, MS2US(2.5), 1);
eth.assertInjectorDownEvent("L015@2", 2, MS2US(6), 0);
eth.assertInjectorDownEvent("L015@3", 3, MS2US(10), 0);
eth.assertInjectorDownEvent("L015@4", 4, MS2US(16), 1);
2016-11-30 20:02:42 -08:00
//todo assertInjectorDownEvent("L015@5", 5, MS2US(30), 0);
2016-09-04 23:02:00 -07:00
engine->executor.executeAll(eth.getTimeNowUs() + MS2US(10) + 1);
2016-09-03 22:01:54 -07:00
// end of combined injection
2019-01-14 16:02:36 -08:00
ASSERT_FALSE(enginePins.injectors[0].currentLogicValue) << "injector@3";
2016-09-04 23:02:00 -07:00
2019-01-10 20:15:24 -08:00
eth.moveTimeForwardUs(MS2US(20));
2019-01-10 18:26:02 -08:00
eth.executeActions();
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, engine->executor.size()) << "Lqs#04";
2016-09-04 23:02:00 -07:00
engine->periodicFastCallback();
// Injection duration of 2ms
2020-07-31 22:09:23 -07:00
engine->injectionDuration = 2.0f;
MockInjectorModel2 im2;
EXPECT_CALL(im2, getInjectionDuration(_)).WillRepeatedly(Return(2.0f));
engine->module<InjectorModel>().set(&im2);
ASSERT_EQ( 10, getInjectorDutyCycle(GET_RPM())) << "Lduty for maf=3";
2016-09-04 23:02:00 -07:00
eth.firePrimaryTriggerRise();
2019-01-14 15:38:20 -08:00
//todoASSERT_EQ( 5, engine->executor.size()) << "Lqs#05";
2016-11-30 20:02:42 -08:00
//todo assertInjectorUpEvent("L016@0", 0, MS2US(8), 0);
//todo assertInjectorDownEvent("L016@1", 1, MS2US(10), 0);
//todo assertInjectorDownEvent("L016@2", 2, MS2US(10), 0);
2016-09-04 23:02:00 -07:00
2019-01-10 20:15:24 -08:00
eth.moveTimeForwardUs(MS2US(20));
2019-01-10 18:26:02 -08:00
eth.executeActions(); // issue here
2016-09-04 23:02:00 -07:00
eth.firePrimaryTriggerFall();
2019-01-10 20:15:24 -08:00
eth.moveTimeForwardUs(MS2US(20));
2019-01-10 18:26:02 -08:00
eth.executeActions();
2016-09-04 23:02:00 -07:00
eth.firePrimaryTriggerRise();
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 4, engine->executor.size()) << "Lqs#5";
2019-01-10 19:43:31 -08:00
eth.assertInjectorUpEvent("L05@0", 0, MS2US(8), 0);
eth.assertInjectorDownEvent("L05@1", 1, MS2US(10), 0);
eth.assertInjectorUpEvent("L05@2", 2, MS2US(18), 1);
eth.assertInjectorDownEvent("L05@3", 3, MS2US(20), 1);
2016-09-04 23:02:00 -07:00
2019-01-10 18:19:46 -08:00
eth.moveTimeForwardUs(MS2US(20));
eth.executeActions();
ASSERT_EQ( 0, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testFuelSchedulerBug299smallAndLarge";
/*
ASSERT_EQ(CUSTOM_OBD_SKIPPED_FUEL, unitTestWarningCodeState.recentWarnings.get(0));
*/
2016-09-03 10:02:55 -07:00
}
2016-10-31 17:02:09 -07:00
TEST(big, testSparkReverseOrderBug319) {
2016-10-31 17:02:09 -07:00
printf("*************************************************** testSparkReverseOrderBug319 small to medium\r\n");
EngineTestHelper eth(TEST_ENGINE);
engine->tdcMarkEnabled = false;
2016-10-31 17:02:09 -07:00
2016-10-31 19:02:12 -07:00
engineConfiguration->useOnlyRisingEdgeForTrigger = false;
2016-10-31 17:02:09 -07:00
engineConfiguration->isInjectionEnabled = false;
engineConfiguration->specs.cylindersCount = 4;
engineConfiguration->ignitionMode = IM_INDIVIDUAL_COILS;
setConstantDwell(45);
2016-10-31 19:02:12 -07:00
// this is needed to update injectorLag
engine->updateSlowSensors();
2016-10-31 19:02:12 -07:00
eth.setTriggerType(TT_ONE);
eth.engine.periodicFastCallback();
2016-10-31 17:02:09 -07:00
setWholeTimingTable(0);
2016-10-31 17:02:09 -07:00
2018-07-28 16:51:41 -07:00
eth.fireRise(20);
2018-07-28 17:06:55 -07:00
eth.fireFall(20);
2016-10-31 17:02:09 -07:00
2019-01-10 18:26:02 -08:00
eth.executeActions();
2016-10-31 17:02:09 -07:00
2018-07-28 16:51:41 -07:00
eth.fireRise(20);
2018-07-28 17:06:55 -07:00
eth.fireFall(20);
2016-10-31 17:02:09 -07:00
2019-01-21 18:48:58 -08:00
ASSERT_EQ( 3000, GET_RPM()) << "testSparkReverseOrderBug319: RPM";
2016-10-31 19:02:12 -07:00
ASSERT_EQ( 8, engine->executor.size()) << "testSparkReverseOrderBug319: queue size";
2019-01-10 18:26:02 -08:00
eth.executeActions();
2016-10-31 19:02:12 -07:00
printf("***************************************************\r\n");
2018-07-28 16:51:41 -07:00
eth.fireRise(20);
2019-01-10 18:26:02 -08:00
eth.executeActions();
2016-10-31 19:02:12 -07:00
2019-01-12 19:24:29 -08:00
/**
* here we throw scheduling logic off
*/
eth.fireFall(0.1); // executing new signal too early
2019-01-10 18:26:02 -08:00
eth.executeActions();
2016-10-31 17:02:09 -07:00
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 1, enginePins.coils[3].outOfOrder) << "out-of-order #1";
2016-10-31 19:02:12 -07:00
2019-01-10 20:15:24 -08:00
eth.moveTimeForwardUs(MS2US(200)); // moving time forward to execute all pending actions
2019-01-10 18:26:02 -08:00
eth.executeActions();
2016-10-31 17:02:09 -07:00
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, enginePins.coils[3].outOfOrder) << "out-of-order #2";
2016-11-01 18:03:07 -07:00
printf("*************************************************** now let's have a good engine cycle and confirm things work\r\n");
2018-07-28 16:51:41 -07:00
eth.fireRise(20);
2019-01-10 18:26:02 -08:00
eth.executeActions();
2016-11-01 18:03:07 -07:00
2019-01-21 18:48:58 -08:00
ASSERT_EQ( 545, GET_RPM()) << "RPM#2";
2016-11-01 18:03:07 -07:00
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, enginePins.coils[3].outOfOrder) << "out-of-order #3";
2016-11-01 18:03:07 -07:00
2018-07-28 17:06:55 -07:00
eth.fireFall(20);
2019-01-10 18:26:02 -08:00
eth.executeActions();
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 1, enginePins.coils[3].outOfOrder) << "out-of-order #4";
2016-11-01 18:03:07 -07:00
printf("*************************************************** (rpm is back) now let's have a good engine cycle and confirm things work\r\n");
2018-07-28 16:51:41 -07:00
eth.fireRise(20);
2019-01-10 18:26:02 -08:00
eth.executeActions();
2016-11-01 18:03:07 -07:00
2019-01-21 18:48:58 -08:00
ASSERT_EQ( 3000, GET_RPM()) << "RPM#3";
2016-11-01 18:03:07 -07:00
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 1, enginePins.coils[3].outOfOrder) << "out-of-order #5 on c4";
2016-11-01 18:03:07 -07:00
2018-07-28 17:06:55 -07:00
eth.fireFall(20);
2019-01-10 18:26:02 -08:00
eth.executeActions();
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 1, enginePins.coils[3].outOfOrder) << "out-of-order #6 on c4";
2016-11-01 18:03:07 -07:00
printf("*************************************************** (rpm is back 2) now let's have a good engine cycle and confirm things work\r\n");
2018-07-28 16:51:41 -07:00
eth.fireRise(20);
2019-01-10 18:26:02 -08:00
eth.executeActions();
2016-11-01 18:03:07 -07:00
2019-01-21 18:48:58 -08:00
ASSERT_EQ( 3000, GET_RPM()) << "RPM#4";
2016-11-01 18:03:07 -07:00
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 1, enginePins.coils[3].outOfOrder) << "out-of-order #7";
2016-11-01 18:03:07 -07:00
2018-07-28 17:06:55 -07:00
eth.fireFall(20);
2019-01-10 18:26:02 -08:00
eth.executeActions();
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, enginePins.coils[3].outOfOrder) << "out-of-order #8";
ASSERT_EQ( 2, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#SparkReverseOrderBug319";
ASSERT_EQ(CUSTOM_DWELL_TOO_LONG, unitTestWarningCodeState.recentWarnings.get(0)) << "warning @0";
ASSERT_EQ(CUSTOM_OUT_OF_ORDER_COIL, unitTestWarningCodeState.recentWarnings.get(1));
2016-10-31 17:02:09 -07:00
}
2016-11-07 19:02:21 -08:00
2019-01-10 20:24:36 -08:00
TEST(big, testMissedSpark299) {
2016-11-07 19:02:21 -08:00
printf("*************************************************** testMissedSpark299\r\n");
EngineTestHelper eth(TEST_ENGINE);
2016-11-07 20:01:47 -08:00
engineConfiguration->ignitionMode = IM_WASTED_SPARK;
2016-11-08 19:02:47 -08:00
engineConfiguration->useOnlyRisingEdgeForTrigger = false;
2018-03-04 13:13:23 -08:00
setupSimpleTestEngineWithMafAndTT_ONE_trigger(&eth);
2016-11-07 19:02:21 -08:00
engineConfiguration->isIgnitionEnabled = true;
engineConfiguration->isInjectionEnabled = false;
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#0";
2016-11-07 19:02:21 -08:00
2018-07-28 17:02:01 -07:00
eth.fireRise(20);
2019-01-10 18:26:02 -08:00
eth.executeActions();
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, eth.engine.triggerCentral.triggerState.currentCycle.current_index) << "ci#0";
2016-11-08 21:02:01 -08:00
2018-07-28 17:06:55 -07:00
eth.fireFall(20);
2019-01-10 18:26:02 -08:00
eth.executeActions();
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 1, eth.engine.triggerCentral.triggerState.currentCycle.current_index) << "ci#1";
2016-11-07 19:02:21 -08:00
2018-07-28 17:02:01 -07:00
eth.fireRise(20);
2019-01-10 18:26:02 -08:00
eth.executeActions();
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 0, eth.engine.triggerCentral.triggerState.currentCycle.current_index) << "ci#2";
2016-11-08 21:02:01 -08:00
2018-07-28 17:06:55 -07:00
eth.fireFall(20);
2019-01-10 18:26:02 -08:00
eth.executeActions();
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 1, eth.engine.triggerCentral.triggerState.currentCycle.current_index) << "ci#3";
2016-11-07 20:01:47 -08:00
2018-07-28 16:51:41 -07:00
eth.fireRise(20);
2019-01-10 18:26:02 -08:00
eth.executeActions();
2016-11-07 19:02:21 -08:00
2018-07-28 17:06:55 -07:00
eth.fireFall(20);
2019-01-10 18:26:02 -08:00
eth.executeActions();
2019-01-14 15:38:20 -08:00
ASSERT_EQ( 1, eth.engine.triggerCentral.triggerState.currentCycle.current_index) << "ci#5";
2016-11-08 21:02:01 -08:00
2016-11-07 20:01:47 -08:00
printf("*************************************************** testMissedSpark299 start\r\n");
ASSERT_EQ(3000, eth.engine.rpmCalculator.getRpm());
2016-11-07 19:02:21 -08:00
setWholeTimingTable(3);
eth.engine.periodicFastCallback();
2016-11-07 19:02:21 -08:00
2016-11-07 20:01:47 -08:00
2018-07-28 17:02:01 -07:00
eth.fireRise(20);
2019-01-10 18:26:02 -08:00
eth.executeActions();
2018-07-28 17:06:55 -07:00
eth.fireFall(20);
2019-01-10 18:26:02 -08:00
eth.executeActions();
2016-11-07 20:01:47 -08:00
2018-07-28 17:02:01 -07:00
eth.fireRise(20);
2019-01-10 18:26:02 -08:00
eth.executeActions();
2018-07-28 17:06:55 -07:00
eth.fireFall(20);
2019-01-10 18:26:02 -08:00
eth.executeActions();
2016-11-07 19:02:21 -08:00
setWholeTimingTable(-5);
eth.engine.periodicFastCallback();
2016-11-07 20:01:47 -08:00
2018-07-28 16:51:41 -07:00
eth.fireRise(20);
2019-01-10 18:26:02 -08:00
eth.executeActions();
2018-07-28 17:06:55 -07:00
eth.fireFall(20);
2019-01-10 18:26:02 -08:00
eth.executeActions();
2016-11-07 20:01:47 -08:00
2018-07-28 16:51:41 -07:00
eth.fireRise(20);
2019-01-10 18:26:02 -08:00
eth.executeActions();
2018-07-28 17:06:55 -07:00
eth.fireFall(20);
2019-01-10 18:26:02 -08:00
eth.executeActions();
2016-11-07 20:01:47 -08:00
ASSERT_EQ( 0, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#1";
2016-11-07 19:02:21 -08:00
}