rusefi-1/unit_tests/test_trigger_decoder.cpp

1361 lines
53 KiB
C++
Raw Normal View History

2015-07-10 06:01:56 -07:00
/**
* @file test_trigger_decoder.cpp
*
* @date Dec 24, 2013
2018-01-20 17:42:19 -08:00
* @author Andrey Belomutskiy, (c) 2012-2018
2015-07-10 06:01:56 -07:00
*/
#include "main.h"
#include "test_trigger_decoder.h"
#include "trigger_decoder.h"
#include "engine_math.h"
2016-08-26 16:02:56 -07:00
#include "allsensors.h"
2015-07-10 06:01:56 -07:00
#include "ford_aspire.h"
#include "dodge_neon.h"
#include "ford_1995_inline_6.h"
#include "mazda_323.h"
#include "rpm_calculator.h"
#include "event_queue.h"
#include "algo.h"
#include "trigger_mazda.h"
#include "trigger_chrysler.h"
2016-01-31 18:02:03 -08:00
#include "tps.h"
2015-07-10 06:01:56 -07:00
#include "trigger_central.h"
#include "main_trigger_callback.h"
#include "engine.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
2018-03-04 13:30:03 -08:00
extern int timeNowUs;
2016-08-26 16:02:56 -07:00
extern float unitTestValue;
extern float testMafValue;
2017-03-28 15:59:42 -07:00
extern int unitTestWarningCounter;
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) {
2015-07-10 06:01:56 -07:00
EngineTestHelper eth(engineType);
EXPAND_EngineTestHelper;
2017-05-15 20:28:49 -07:00
initDataStructures(PASS_ENGINE_PARAMETER_SIGNATURE);
2015-07-10 06:01:56 -07:00
2017-03-01 19:18:25 -08:00
TriggerShape * shape = &eth.engine.triggerCentral.triggerShape;
2017-05-15 20:28:49 -07:00
return findTriggerZeroEventIndex(&eth.engine.triggerCentral.triggerState, shape, &engineConfiguration->trigger PASS_ENGINE_PARAMETER_SUFFIX);
2015-07-10 06:01:56 -07:00
}
static void testDodgeNeonDecoder(void) {
2017-03-04 17:52:24 -08:00
printf("*************************************************** testDodgeNeonDecoder95\r\n");
2015-07-10 06:01:56 -07:00
initTriggerDecoder();
2017-03-04 17:52:24 -08:00
assertEqualsM("DODGE_NEON_1995: trigger zero index", 8, getTriggerZeroEventIndex(DODGE_NEON_1995));
2015-07-10 06:01:56 -07:00
EngineTestHelper eth(DODGE_NEON_1995);
EXPAND_EngineTestHelper;
2017-03-01 19:18:25 -08:00
TriggerShape * shape = &eth.engine.triggerCentral.triggerShape;
2015-07-10 06:01:56 -07:00
assertEquals(8, shape->getTriggerShapeSynchPointIndex());
TriggerState state;
assertFalseM("1 shaft_is_synchronized", state.shaft_is_synchronized);
// int r = 0;
2016-02-27 20:03:34 -08:00
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_RISING, r + 60);
2015-07-10 06:01:56 -07:00
// assertFalseM("2 shaft_is_synchronized", state.shaft_is_synchronized); // still no synchronization
2016-02-27 20:03:34 -08:00
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_FALLING, r + 210);
2015-07-10 06:01:56 -07:00
// assertFalseM("3 shaft_is_synchronized", state.shaft_is_synchronized); // still no synchronization
//
2016-02-27 20:03:34 -08:00
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_RISING, r + 420);
2015-07-10 06:01:56 -07:00
// assertFalseM("4 shaft_is_synchronized", state.shaft_is_synchronized); // still no synchronization
//
2016-02-27 20:03:34 -08:00
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_FALLING, r + 630);
2015-07-10 06:01:56 -07:00
// assertFalse(state.shaft_is_synchronized); // still no synchronization
//
// 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);
2015-07-10 06:01:56 -07:00
// assertTrue(state.shaft_is_synchronized);
// assertEquals(0, state.current_index);
2016-02-27 20:03:34 -08:00
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_RISING, r + 420);
2015-07-10 06:01:56 -07:00
// assertEquals(1, state.current_index);
2016-02-27 20:03:34 -08:00
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_FALLING, r + 630);
2015-07-10 06:01:56 -07:00
// assertEquals(2, state.current_index);
//
// 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);
2015-07-10 06:01:56 -07:00
// assertEqualsM("current index", 3, state.current_index);
2016-02-27 20:03:34 -08:00
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_FALLING, r + 210);
2015-07-10 06:01:56 -07:00
// assertTrue(state.shaft_is_synchronized);
// assertEqualsM("current index", 0, state.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) {
assertEqualsM("eventIndex", eventIndex, position->eventIndex);
assertEqualsM("angleOffset", angleOffset, position->angleOffset);
}
2016-01-26 19:03:19 -08:00
void test1995FordInline6TriggerDecoder(void) {
2015-07-10 06:01:56 -07:00
printf("*************************************************** test1995FordInline6TriggerDecoder\r\n");
2017-03-01 19:25:00 -08:00
assertEqualsM("triggerIndex ", 0, getTriggerZeroEventIndex(FORD_INLINE_6_1995));
2015-07-10 06:01:56 -07:00
initTriggerDecoder();
EngineTestHelper eth(FORD_INLINE_6_1995);
EXPAND_EngineTestHelper;
2017-03-01 19:18:25 -08:00
TriggerShape * shape = &eth.engine.triggerCentral.triggerShape;
2015-07-10 06:01:56 -07:00
assertEqualsM("triggerShapeSynchPointIndex", 0, shape->getTriggerShapeSynchPointIndex());
2016-01-26 19:03:19 -08:00
// this is needed to have valid CLT and IAT. todo: extract method
2017-05-15 20:28:49 -07:00
engine->updateSlowSensors(PASS_ENGINE_PARAMETER_SIGNATURE);
2016-01-26 19:03:19 -08:00
2015-07-10 06:01:56 -07:00
event_trigger_position_s position;
assertEqualsM("globalTriggerAngleOffset", 0, engineConfiguration->globalTriggerAngleOffset);
2017-05-15 20:28:49 -07:00
TRIGGER_SHAPE(findTriggerPosition(&position, 0 PASS_ENGINE_PARAMETER_SUFFIX));
2015-07-10 06:01:56 -07:00
assertTriggerPosition(&position, 0, 0);
2017-05-15 20:28:49 -07:00
TRIGGER_SHAPE(findTriggerPosition(&position, 200 PASS_ENGINE_PARAMETER_SUFFIX));
2015-07-10 06:01:56 -07:00
assertTriggerPosition(&position, 3, 20);
2017-05-15 20:28:49 -07:00
TRIGGER_SHAPE(findTriggerPosition(&position, 360 PASS_ENGINE_PARAMETER_SUFFIX));
2015-07-10 06:01:56 -07:00
assertTriggerPosition(&position, 6, 0);
2016-08-26 17:03:06 -07:00
eth.applyTriggerShape();
2016-01-26 19:03:19 -08:00
2017-05-15 20:28:49 -07:00
eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
2016-01-26 20:01:44 -08:00
eth.fireTriggerEvents(48);
assertEquals(2000, eth.engine.rpmCalculator.rpmValue);
2017-05-15 20:28:49 -07:00
eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
2016-01-26 20:01:44 -08:00
eth.fireTriggerEvents(48);
2015-07-10 06:01:56 -07:00
2016-12-18 07:02:38 -08:00
IgnitionEventList *ecl = &eth.engine.ignitionEvents;
2016-11-28 09:03:02 -08:00
assertEqualsM("ford inline ignition events size", 1, ecl->isReady);
2015-07-10 06:01:56 -07:00
assertEqualsM("event index", 0, ecl->elements[0].dwellPosition.eventIndex);
2016-01-26 20:01:44 -08:00
assertEqualsM("angle offset#1", 7, ecl->elements[0].dwellPosition.angleOffset);
2015-07-10 06:01:56 -07:00
assertEqualsM("event index", 10, ecl->elements[5].dwellPosition.eventIndex);
2016-01-26 20:01:44 -08:00
assertEqualsM("angle offset#2", 7, ecl->elements[5].dwellPosition.angleOffset);
2015-07-10 06:01:56 -07:00
TriggerState state;
assertFalseM("shaft_is_synchronized", state.shaft_is_synchronized);
int r = 10;
2017-05-15 20:28:49 -07:00
state.decodeTriggerEvent(SHAFT_PRIMARY_FALLING, r PASS_ENGINE_PARAMETER_SUFFIX);
2015-07-10 06:01:56 -07:00
assertFalseM("shaft_is_synchronized", state.shaft_is_synchronized); // still no synchronization
2017-05-15 20:28:49 -07:00
state.decodeTriggerEvent(SHAFT_PRIMARY_RISING, ++r PASS_ENGINE_PARAMETER_SUFFIX);
2015-07-10 06:01:56 -07:00
assertTrue(state.shaft_is_synchronized); // first signal rise synchronize
assertEquals(0, state.getCurrentIndex());
2017-05-15 20:28:49 -07:00
state.decodeTriggerEvent(SHAFT_PRIMARY_FALLING, r++ PASS_ENGINE_PARAMETER_SUFFIX);
2015-07-10 06:01:56 -07:00
assertEquals(1, state.getCurrentIndex());
for (int i = 2; i < 10;) {
2017-05-15 20:28:49 -07:00
state.decodeTriggerEvent(SHAFT_PRIMARY_RISING, r++ PASS_ENGINE_PARAMETER_SUFFIX);
2015-07-10 06:01:56 -07:00
assertEqualsM("even", i++, state.getCurrentIndex());
2017-05-15 20:28:49 -07:00
state.decodeTriggerEvent(SHAFT_PRIMARY_FALLING, r++ PASS_ENGINE_PARAMETER_SUFFIX);
2015-07-10 06:01:56 -07:00
assertEqualsM("odd", i++, state.getCurrentIndex());
}
2017-05-15 20:28:49 -07:00
state.decodeTriggerEvent(SHAFT_PRIMARY_RISING, r++ PASS_ENGINE_PARAMETER_SUFFIX);
2015-07-10 06:01:56 -07:00
assertEquals(10, state.getCurrentIndex());
2017-05-15 20:28:49 -07:00
state.decodeTriggerEvent(SHAFT_PRIMARY_FALLING, r++ PASS_ENGINE_PARAMETER_SUFFIX);
2015-07-10 06:01:56 -07:00
assertEquals(11, state.getCurrentIndex());
2017-05-15 20:28:49 -07:00
state.decodeTriggerEvent(SHAFT_PRIMARY_RISING, r++ PASS_ENGINE_PARAMETER_SUFFIX);
2015-07-10 06:01:56 -07:00
assertEquals(0, state.getCurrentIndex()); // new revolution
2017-05-15 20:28:49 -07:00
assertEqualsM("running dwell", 0.5, getSparkDwell(2000 PASS_ENGINE_PARAMETER_SUFFIX));
2015-07-10 06:01:56 -07:00
}
void testFordAspire(void) {
printf("*************************************************** testFordAspire\r\n");
2017-03-04 06:23:51 -08:00
assertEqualsM("getTriggerZeroEventIndex", 4, getTriggerZeroEventIndex(FORD_ASPIRE_1996));
2015-07-10 06:01:56 -07:00
EngineTestHelper eth(FORD_ASPIRE_1996);
EXPAND_EngineTestHelper;
2017-03-04 06:05:40 -08:00
assertEqualsM("getTriggerShapeSynchPointIndex", 4, TRIGGER_SHAPE(getTriggerShapeSynchPointIndex()));
2015-07-10 06:01:56 -07:00
assertEquals(800, config->fuelRpmBins[0]);
assertEquals(7000, config->fuelRpmBins[15]);
engineConfiguration->crankingChargeAngle = 65;
engineConfiguration->crankingTimingAngle = 31;
2017-07-07 16:37:13 -07:00
engine->rpmCalculator.setRpmValue(200 PASS_ENGINE_PARAMETER_SUFFIX);
2017-05-15 20:28:49 -07:00
assertEqualsM("cranking dwell", 54.166670, getSparkDwell(200 PASS_ENGINE_PARAMETER_SUFFIX));
2017-07-07 16:37:13 -07:00
engine->rpmCalculator.setRpmValue(2000 PASS_ENGINE_PARAMETER_SUFFIX);
2017-05-15 20:28:49 -07:00
assertEqualsM("running dwell", 4, getSparkDwell(2000 PASS_ENGINE_PARAMETER_SUFFIX));
2015-07-10 06:01:56 -07:00
2017-07-07 16:37:13 -07:00
engine->rpmCalculator.setRpmValue(6000 PASS_ENGINE_PARAMETER_SUFFIX);
2017-05-15 20:28:49 -07:00
assertEqualsM("higher rpm dwell", 3.25, getSparkDwell(6000 PASS_ENGINE_PARAMETER_SUFFIX));
2015-07-10 06:01:56 -07:00
}
2017-03-03 21:00:46 -08:00
void testTriggerDecoder2(const char *msg, engine_type_e type, int synchPointIndex, float channel1duty, float channel2duty) {
2015-07-10 06:01:56 -07:00
printf("*************************************************** %s\r\n", msg);
EngineTestHelper eth(type);
EXPAND_EngineTestHelper;
2017-05-15 20:28:49 -07:00
initSpeedDensity(PASS_ENGINE_PARAMETER_SIGNATURE);
2015-07-10 06:01:56 -07:00
2017-03-01 19:18:25 -08:00
TriggerShape *t = &eth.engine.triggerCentral.triggerShape;
2015-07-10 06:01:56 -07:00
2017-03-01 19:37:10 -08:00
assertFalseM("isError", t->shapeDefinitionError);
2015-07-10 06:01:56 -07:00
assertEqualsM("synchPointIndex", synchPointIndex, t->getTriggerShapeSynchPointIndex());
2018-02-05 14:24:45 -08:00
assertEqualsM5(msg, " channel1duty", channel1duty, t->expectedDutyCycle[0], 0.0001);
assertEqualsM5(msg, " channel2duty", channel2duty, t->expectedDutyCycle[1], 0.0001);
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) {
printTriggerDebug = true;
testTriggerDecoder2(msg, type, synchPointIndex, channel1duty, channel2duty);
assertEqualsM2("actual gap ratio", expectedGap, actualSynchGap, 0.001);
printTriggerDebug = false;
}
extern EventQueue schedulingQueue;
2016-08-26 14:02:37 -07:00
void testStartupFuelPumping(void) {
2015-07-10 06:01:56 -07:00
printf("*************************************************** testStartupFuelPumping\r\n");
EngineTestHelper eth(FORD_INLINE_6_1995);
EXPAND_EngineTestHelper;
StartupFuelPumping sf;
engine->rpmCalculator.mockRpm = 0;
2016-06-16 21:01:42 -07:00
engine->engineConfiguration->tpsMin = 0;
engine->engineConfiguration->tpsMax = 10;
2015-07-10 06:01:56 -07:00
2017-11-16 07:29:40 -08:00
setMockTpsPosition(6);
2017-05-15 20:28:49 -07:00
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
2015-07-10 06:01:56 -07:00
assertEqualsM("pc#1", 1, sf.pumpsCounter);
2017-11-16 07:29:40 -08:00
setMockTpsPosition(3);
2017-05-15 20:28:49 -07:00
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
2016-12-26 12:03:03 -08:00
assertEqualsM("pumpsCounter#2", 1, sf.pumpsCounter);
2015-07-10 06:01:56 -07:00
2017-05-15 20:28:49 -07:00
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
2016-12-26 12:03:03 -08:00
assertEqualsM("pc#3", 1, sf.pumpsCounter);
2015-07-10 06:01:56 -07:00
engine->rpmCalculator.mockRpm = 10;
2017-05-15 20:28:49 -07:00
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
2015-07-10 06:01:56 -07:00
assertEqualsM("pc#4", 0, sf.pumpsCounter);
2017-11-16 07:29:40 -08:00
setMockTpsPosition(7);
2015-07-10 06:01:56 -07:00
engine->rpmCalculator.mockRpm = 0;
2017-05-15 20:28:49 -07:00
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
2015-07-10 06:01:56 -07:00
assertEqualsM("pc#5", 1, sf.pumpsCounter);
2017-11-16 07:29:40 -08:00
setMockTpsPosition(3);
2017-05-15 20:28:49 -07:00
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
2016-12-26 12:03:03 -08:00
assertEqualsM("pc#6", 1, sf.pumpsCounter);
2015-07-10 06:01:56 -07:00
2017-11-16 07:29:40 -08:00
setMockTpsPosition(7);
2017-05-15 20:28:49 -07:00
sf.update(PASS_ENGINE_PARAMETER_SIGNATURE);
2016-12-26 12:03:03 -08:00
assertEqualsM("pc#7", 2, sf.pumpsCounter);
2015-07-10 06:01:56 -07:00
}
static void assertREquals(void *expected, void *actual) {
assertEquals((float)(uint64_t)expected, (float)(uint64_t)actual);
}
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;
2016-11-03 20:02:58 -07:00
extern EnginePins enginePins;
2015-07-10 06:01:56 -07:00
2016-01-25 08:02:31 -08:00
void testRpmCalculator(void) {
2015-07-10 06:01:56 -07:00
printf("*************************************************** testRpmCalculator\r\n");
2018-03-04 13:30:03 -08:00
timeNowUs = 0;
2016-08-26 19:03:07 -07:00
schedulingQueue.clear();
2015-07-10 06:01:56 -07:00
EngineTestHelper eth(FORD_INLINE_6_1995);
EXPAND_EngineTestHelper;
2018-07-28 11:33:32 -07:00
IgnitionEventList *ilist = &engine->ignitionEvents;
2016-11-28 09:03:02 -08:00
assertEqualsM("size #1", 0, ilist->isReady);
2015-07-10 06:01:56 -07:00
2018-07-28 11:33:32 -07:00
assertEqualsM("engineCycle", 720, engine->engineCycle);
2015-07-10 06:01:56 -07:00
2018-07-28 11:33:32 -07:00
efiAssertVoid(CUSTOM_ERR_6683, engineConfiguration!=NULL, "null config in engine");
2015-07-10 06:01:56 -07:00
engineConfiguration->trigger.customTotalToothCount = 8;
engineConfiguration->globalFuelCorrection = 3;
2016-08-26 17:03:06 -07:00
eth.applyTriggerShape();
2015-07-10 06:01:56 -07:00
2017-06-11 11:49:23 -07:00
setFlatInjectorLag(0 PASS_ENGINE_PARAMETER_SUFFIX);
2015-07-10 06:01:56 -07:00
2017-05-15 20:28:49 -07:00
engine->updateSlowSensors(PASS_ENGINE_PARAMETER_SIGNATURE);
2018-03-04 13:30:03 -08:00
timeNowUs = 0;
2018-07-28 11:33:32 -07:00
assertEquals(0, engine->rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_SIGNATURE));
2015-07-10 06:01:56 -07:00
// triggerIndexByAngle update is now fixed! prepareOutputSignals() wasn't reliably called
assertEquals(5, TRIGGER_SHAPE(triggerIndexByAngle[240]));
assertEquals(5, TRIGGER_SHAPE(triggerIndexByAngle[241]));
2016-01-30 19:03:36 -08:00
2016-01-24 22:02:55 -08:00
eth.fireTriggerEvents(48);
2018-07-28 11:33:32 -07:00
assertEqualsM("RPM", 1500, engine->rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_SIGNATURE));
assertEqualsM("index #1", 15, engine->triggerCentral.triggerState.getCurrentIndex());
2015-07-10 06:01:56 -07:00
2018-03-04 13:38:01 -08:00
eth.clearQueue();
2015-07-10 06:01:56 -07:00
debugSignalExecutor = true;
2018-07-28 11:33:32 -07:00
assertEquals(engine->triggerCentral.triggerState.shaft_is_synchronized, 1);
2016-01-24 22:02:55 -08:00
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(5); // 5ms
2015-07-10 06:01:56 -07:00
2018-03-04 13:30:03 -08:00
int st = timeNowUs;
2016-01-24 22:02:55 -08:00
assertEqualsM("st value", 485000, st);
2016-01-30 19:03:36 -08:00
// todo: why is this required here? we already have one 'prepareOutputSignals' in constructor, what's wrong with it?
2017-05-15 20:28:49 -07:00
prepareOutputSignals(PASS_ENGINE_PARAMETER_SIGNATURE);
2016-01-30 19:03:36 -08:00
2017-05-15 20:28:49 -07:00
eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
2015-07-10 06:01:56 -07:00
2018-07-28 11:33:32 -07:00
assertEqualsM("fuel #1", 4.5450, engine->injectionDuration);
InjectionEvent *ie0 = &engine->injectionEvents.elements[0];
2016-07-23 19:02:52 -07:00
assertEqualsM("injection angle", 31.365, ie0->injectionStart.angleOffset);
2016-01-26 18:01:37 -08:00
2018-07-28 17:02:01 -07:00
eth.firePrimaryTriggerRise();
2016-01-26 18:01:37 -08:00
assertEquals(1500, eth.engine.rpmCalculator.rpmValue);
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);
2016-11-28 09:03:02 -08:00
assertEqualsM("size #2", 1, ilist->isReady);
2015-07-10 06:01:56 -07:00
assertEqualsM("dwell angle", 0, ilist->elements[0].dwellPosition.eventAngle);
2016-01-26 21:01:34 -08:00
assertEqualsM("dwell offset", 8.5, ilist->elements[0].dwellPosition.angleOffset);
2015-07-10 06:01:56 -07:00
2015-09-13 14:02:44 -07:00
assertEqualsM("index #2", 0, eth.engine.triggerCentral.triggerState.getCurrentIndex());
2016-07-23 19:02:52 -07:00
assertEqualsM("queue size/2", 2, schedulingQueue.size());
2016-01-30 19:03:36 -08:00
{
2016-01-25 20:01:36 -08:00
scheduling_s *ev0 = schedulingQueue.getForUnitText(0);
2015-07-10 06:01:56 -07:00
2016-07-23 19:02:52 -07:00
assertREqualsM("Call@0", (void*)ev0->callback, (void*)turnSparkPinHigh);
assertEqualsM("ev 0", st + 944, ev0->momentX);
2016-11-26 21:01:22 -08:00
assertEqualsLM("coil 0", (long)&enginePins.coils[0], (long)((IgnitionEvent*)ev0->param)->outputs[0]);
2016-01-25 20:01:36 -08:00
scheduling_s *ev1 = schedulingQueue.getForUnitText(1);
2016-07-23 19:02:52 -07:00
assertREqualsM("Call@1", (void*)ev1->callback, (void*)turnSparkPinLow);
assertEqualsM("ev 1", st + 1444, ev1->momentX);
2016-11-26 21:01:22 -08:00
assertEqualsLM("coil 1", (long)&enginePins.coils[0], (long)((IgnitionEvent*)ev1->param)->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
2015-07-10 06:01:56 -07:00
schedulingQueue.clear();
2018-07-28 17:02:01 -07:00
eth.fireFall(5);
eth.fireRise(5);
eth.fireFall(5);
2015-09-13 14:02:44 -07:00
assertEqualsM("index #3", 3, eth.engine.triggerCentral.triggerState.getCurrentIndex());
2016-11-30 17:02:41 -08:00
assertEqualsM("queue size 3", 4, schedulingQueue.size());
2016-07-23 19:02:52 -07:00
assertEqualsM("ev 3", st + 13333 - 1515, schedulingQueue.getForUnitText(0)->momentX);
2016-11-30 17:02:41 -08:00
assertEqualsM2("ev 5", st + 14277, schedulingQueue.getForUnitText(1)->momentX, 2);
assertEqualsM("3/3", st + 14777, schedulingQueue.getForUnitText(2)->momentX);
2015-07-10 06:01:56 -07:00
schedulingQueue.clear();
2017-03-01 19:18:25 -08:00
assertEquals(5, TRIGGER_SHAPE(triggerIndexByAngle[240]));
assertEquals(5, TRIGGER_SHAPE(triggerIndexByAngle[241]));
2016-01-30 19:03:36 -08:00
2018-07-28 17:02:01 -07:00
eth.fireFall(5);
2016-01-30 19:03:36 -08:00
assertEqualsM("queue size 4.1", 0, schedulingQueue.size());
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(5); // 5ms
2018-07-28 17:02:01 -07:00
eth.firePrimaryTriggerRise();
2016-11-30 17:02:41 -08:00
assertEqualsM("queue size 4.2", 4, schedulingQueue.size());
2016-01-30 19:03:36 -08:00
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(5); // 5ms
2018-07-28 17:02:01 -07:00
eth.firePrimaryTriggerRise();
2016-11-30 17:02:41 -08:00
assertEqualsM("queue size 4.3", 4, schedulingQueue.size());
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);
2016-01-30 19:03:36 -08:00
assertEquals(1500, eth.engine.rpmCalculator.rpmValue);
2018-03-04 20:08:32 -08:00
assertInjectorUpEvent("ev 0/2", 0, -4849, 2 PASS_ENGINE_PARAMETER_SUFFIX);
2016-11-30 17:02:41 -08:00
2016-01-30 19:03:36 -08:00
2015-09-13 14:02:44 -07:00
assertEqualsM("index #4", 6, eth.engine.triggerCentral.triggerState.getCurrentIndex());
2016-11-30 17:02:41 -08:00
assertEqualsM("queue size 4", 4, schedulingQueue.size());
2015-07-10 06:01:56 -07:00
schedulingQueue.clear();
2018-07-28 17:02:01 -07:00
eth.fireFall(5);
2016-11-30 17:02:41 -08:00
assertEqualsM("queue size 5", 2, schedulingQueue.size());
2016-07-23 19:02:52 -07:00
// todo: assert queue elements
2015-07-10 06:01:56 -07:00
schedulingQueue.clear();
2018-03-04 13:30:03 -08:00
timeNowUs += 5000; // 5ms
2018-07-28 17:02:01 -07:00
eth.firePrimaryTriggerRise();
2016-07-23 19:02:52 -07:00
assertEqualsM("queue size 6", 2, schedulingQueue.size());
assertEqualsM("6/0", st + 40944, schedulingQueue.getForUnitText(0)->momentX);
assertEqualsM("6/1", st + 41444, schedulingQueue.getForUnitText(1)->momentX);
2015-07-10 06:01:56 -07:00
schedulingQueue.clear();
2018-07-28 17:02:01 -07:00
eth.fireFall(5);
2015-07-10 06:01:56 -07:00
assertEqualsM("queue size 7", 0, schedulingQueue.size());
schedulingQueue.clear();
2018-03-04 13:30:03 -08:00
timeNowUs += 5000; // 5ms
2018-07-28 17:02:01 -07:00
eth.firePrimaryTriggerRise();
2016-11-30 17:02:41 -08:00
assertEqualsM("queue size 8", 4, schedulingQueue.size());
2016-07-23 19:02:52 -07:00
// todo: assert queue elements completely
assertEqualsM("8/0", st + 53333 - 1515, schedulingQueue.getForUnitText(0)->momentX);
2016-11-30 17:02:41 -08:00
assertEqualsM2("8/1", st + 54277, schedulingQueue.getForUnitText(1)->momentX, 0);
assertEqualsM2("8/2", st + 54777, schedulingQueue.getForUnitText(2)->momentX, 0);
2015-07-10 06:01:56 -07:00
schedulingQueue.clear();
2018-03-04 13:30:03 -08:00
timeNowUs += 5000;
2018-07-28 17:02:01 -07:00
eth.firePrimaryTriggerFall();
2015-11-09 16:03:32 -08:00
assertEqualsM("queue size 9", 0, schedulingQueue.size());
2015-07-10 06:01:56 -07:00
schedulingQueue.clear();
2018-03-04 13:30:03 -08:00
timeNowUs += 5000; // 5ms
2018-07-28 17:02:01 -07:00
eth.firePrimaryTriggerRise();
2015-07-10 06:01:56 -07:00
assertEqualsM("queue size 10", 0, schedulingQueue.size());
schedulingQueue.clear();
}
void testTriggerDecoder(void) {
printf("*************************************************** testTriggerDecoder\r\n");
2016-10-31 19:02:12 -07:00
persistent_config_s c;
Engine e(&c);
2017-03-01 19:18:25 -08:00
TriggerShape * s = &e.triggerCentral.triggerShape;
2015-07-10 06:01:56 -07:00
2016-10-31 19:02:12 -07:00
persistent_config_s *config = &c;
Engine *engine = &e;
engine_configuration_s *engineConfiguration = &c.engineConfiguration;
board_configuration_s *boardConfiguration = &c.engineConfiguration.bc;
2017-05-15 20:28:49 -07:00
initializeSkippedToothTriggerShapeExt(s, 2, 0, FOUR_STROKE_CAM_SENSOR PASS_ENGINE_PARAMETER_SUFFIX);
2015-07-10 06:01:56 -07:00
assertEqualsM("shape size", s->getSize(), 4);
assertEquals(s->wave.switchTimes[0], 0.25);
assertEquals(s->wave.switchTimes[1], 0.5);
assertEquals(s->wave.switchTimes[2], 0.75);
assertEquals(s->wave.switchTimes[3], 1);
testNoiselessDecoder();
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
testFordAspire();
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);
//testTriggerDecoder2("bmw", BMW_E34, 0, 0.9750, 0.5167);
2017-03-04 17:52:24 -08:00
testTriggerDecoder2("bmw", BMW_E34, 0, 0.4667, 0.0);
2015-07-10 06:01:56 -07:00
test1995FordInline6TriggerDecoder();
2017-05-12 19:43:49 -07:00
2016-11-03 16:02:46 -07:00
testTriggerDecoder2("Miata NB", MAZDA_MIATA_NB1, 12, 0.0833, 0.0444);
2017-05-12 19:43:49 -07:00
testTriggerDecoder2("Miata 2003", MAZDA_MIATA_2003, 3, 0.0444, 0.0);
2015-07-10 06:01:56 -07:00
2017-03-01 18:38:14 -08:00
testTriggerDecoder2("Civic 4/0 both", TEST_CIVIC_4_0_BOTH, 0, 0.5000, 0.0);
2017-03-04 17:52:24 -08:00
testTriggerDecoder2("Civic 4/0 rise", TEST_CIVIC_4_0_RISE, 0, 0.5000, 0.0);
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);
testTriggerDecoder2("testMiniCooper", MINI_COOPER_R50, 121, 0.5222, 0.4959);
testTriggerDecoder2("testRoverV8", ROVER_V8, 0, 0.4861, 0);
2017-03-12 19:55:41 -07:00
testTriggerDecoder2("SATURN_ION_2004", SATURN_ION_2004, 0, 0.9028, 0.0);
2015-07-10 06:01:56 -07:00
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
2015-07-10 06:01:56 -07:00
testTriggerDecoder2("test1+1", CUSTOM_ENGINE, 0, 0.7500, 0.2500);
testTriggerDecoder2("testCitroen", CITROEN_TU3JP, 0, 0.4833, 0);
testTriggerDecoder2("testAccordCd 3w", HONDA_ACCORD_CD, 12, 0.8146, 0.5000);
testTriggerDecoder2("testAccordCd 2w", HONDA_ACCORD_CD_TWO_WIRES, 2, 0.9167, 0.5);
testTriggerDecoder2("testAccordCdDip", HONDA_ACCORD_CD_DIP, 27, 0.5000, 0.5000);
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);
EXPAND_EngineTestHelper;
2017-05-15 20:28:49 -07:00
initSpeedDensity(PASS_ENGINE_PARAMETER_SIGNATURE);
2015-09-13 10:02:13 -07:00
2017-03-01 19:18:25 -08:00
// TriggerShape *t = &eth.engine.triggerShape;
2017-02-23 19:27:12 -08:00
// assertEquals(1, t->eventAngles[1]);
// assertEqualsM("index at 0", 0, t->triggerIndexByAngle[56]);
// assertEqualsM("index at 1", 1, t->triggerIndexByAngle[57]);
//
// assertEquals(270, t->eventAngles[5]);
// assertEqualsM("index at 269", 4, t->triggerIndexByAngle[269]);
// assertEqualsM("index at 270", 5, t->triggerIndexByAngle[270]);
// assertEqualsM("index at 271", 5, t->triggerIndexByAngle[271]);
//
// assertEquals(306, t->eventAngles[6]);
// assertEquals(5, t->triggerIndexByAngle[305]);
// assertEquals(6, t->triggerIndexByAngle[306]);
// assertEquals(6, t->triggerIndexByAngle[307]);
//
// assertEquals(666, t->eventAngles[11]);
// assertEqualsM("index for 665", 10, t->triggerIndexByAngle[665]);
// assertEqualsM("index for 668", 11, t->triggerIndexByAngle[668]);
2015-09-13 10:02:13 -07:00
2015-09-13 13:01:38 -07:00
2016-02-27 20:03:34 -08:00
eth.persistentConfig.engineConfiguration.useOnlyRisingEdgeForTrigger = false;
2015-09-13 15:01:23 -07:00
eth.persistentConfig.engineConfiguration.bc.sensorChartMode = SC_DETAILED_RPM;
2017-05-15 20:28:49 -07:00
applyNonPersistentConfiguration(NULL PASS_ENGINE_PARAMETER_SUFFIX);
2015-09-13 13:01:38 -07:00
2016-01-24 22:02:55 -08:00
// assertEqualsM2("rpm#1", 16666.9746, eth.engine.triggerCentral.triggerState.instantRpmValue[0], 0.5);
// assertEqualsM2("rpm#2", 16666.3750, eth.engine.triggerCentral.triggerState.instantRpmValue[1], 0.5);
2015-09-13 13:01:38 -07:00
2015-09-13 10:02:13 -07:00
}
2016-08-26 14:02:37 -07:00
testTriggerDecoder2("miata 1990", MIATA_1990, 11, 0.2985, 0.3890);
2015-07-10 06:01:56 -07:00
testTriggerDecoder3("miata 1994", MIATA_1994_DEVIATOR, 11, 0.2985, 0.3890, MIATA_NA_GAP);
testTriggerDecoder3("citroen", CITROEN_TU3JP, 0, 0.4833, 0.0, 2.9994);
2016-08-26 14:02:37 -07:00
testTriggerDecoder2("MAZDA_323", MAZDA_323, 0, 0.4833, 0);
2016-09-21 09:03:07 -07:00
testTriggerDecoder3("neon NGC4", DODGE_NEON_2003_CAM, 6, 0.5000, 0.0, CHRYSLER_NGC4_GAP);
2015-09-24 16:01:36 -07:00
{
printTriggerDebug = true;
2016-09-21 09:03:07 -07:00
EngineTestHelper eth(DODGE_NEON_2003_CAM);
2015-09-24 16:01:36 -07:00
EXPAND_EngineTestHelper;
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
2017-05-15 20:28:49 -07:00
applyNonPersistentConfiguration(NULL PASS_ENGINE_PARAMETER_SUFFIX);
prepareShapes(PASS_ENGINE_PARAMETER_SIGNATURE);
2015-09-24 16:01:36 -07:00
2015-09-24 17:01:25 -07:00
printTriggerDebug = false;
2015-09-24 16:01:36 -07:00
}
2015-07-10 06:01:56 -07:00
testTriggerDecoder2("sachs", SACHS, 0, 0.4800, 0.000);
2015-09-05 20:02:46 -07:00
printTriggerDebug = true;
2015-09-12 12:02:40 -07:00
testTriggerDecoder3("36+2+2+2", DAIHATSU, 28, 0.5000, 0.0, 0.5);
2015-09-06 11:01:29 -07:00
testTriggerDecoder3("stratus NGC6", DODGE_STRATUS, 0, 0.8833, 0.0, CHRYSLER_NGC6_GAP);
2015-09-05 20:02:46 -07:00
2015-07-10 06:01:56 -07:00
testTriggerDecoder2("vw ABA", VW_ABA, 114, 0.5000, 0.0);
testStartupFuelPumping();
testRpmCalculator();
}
2016-08-26 14:02:37 -07:00
2016-08-26 16:02:56 -07:00
extern fuel_Map3D_t fuelMap;
2018-03-04 20:42:30 -08:00
scheduling_s * assertEvent5(const char *msg, int index, void *callback, efitime_t start, efitime_t momentX) {
2016-08-27 17:02:25 -07:00
assertTrueM(msg, schedulingQueue.size() > index);
2018-03-04 20:42:30 -08:00
scheduling_s *event = schedulingQueue.getForUnitText(index);
assertEqualsM4(msg, " up/down", (void*)event->callback == (void*) callback, 1);
assertEqualsM(msg, momentX, event->momentX - start);
return event;
}
void assertEvent(const char *msg, int index, void *callback, efitime_t start, efitime_t momentX, long param) {
scheduling_s *event = assertEvent5(msg, index, callback, start, momentX);
InjectionSignalPair *eventPair = (InjectionSignalPair *)event->param;
2018-03-04 20:36:06 -08:00
InjectionSignalPair *expectedPair = (InjectionSignalPair *)param;
assertEqualsLM(msg, expectedPair->outputs[0], (long)eventPair->outputs[0]);
// but this would not work assertEqualsLM(msg, expectedPair, (long)eventPair);
2016-08-27 10:01:55 -07:00
}
2018-03-04 20:08:32 -08:00
void assertInjectorUpEvent(const char *msg, int eventIndex, efitime_t momentX, long injectorIndex DECLARE_ENGINE_PARAMETER_SUFFIX) {
InjectionSignalPair *pair = &ENGINE(fuelActuators[injectorIndex]);
2018-03-04 20:36:06 -08:00
assertEvent(msg, eventIndex, (void*)seTurnPinHigh, timeNowUs, momentX, (long)pair);
2016-08-27 17:02:25 -07:00
}
2018-03-04 20:08:32 -08:00
void assertInjectorDownEvent(const char *msg, int eventIndex, efitime_t momentX, long injectorIndex DECLARE_ENGINE_PARAMETER_SUFFIX) {
InjectionSignalPair *pair = &ENGINE(fuelActuators[injectorIndex]);
2018-03-04 20:36:06 -08:00
assertEvent(msg, eventIndex, (void*)seTurnPinLow, timeNowUs, momentX, (long)pair);
2016-08-27 17:02:25 -07:00
}
2016-09-03 10:02:55 -07:00
static void assertInjectionEvent(const char *msg, InjectionEvent *ev, int injectorIndex, int eventIndex, angle_t angleOffset, bool isOverlapping) {
2016-11-30 16:01:43 -08:00
assertEqualsM4(msg, "inj index", injectorIndex, ev->outputs[0]->injectorIndex);
2016-11-08 22:02:15 -08:00
assertEqualsM4(msg, " event index", eventIndex, ev->injectionStart.eventIndex);
assertEqualsM4(msg, " event offset", angleOffset, ev->injectionStart.angleOffset);
2016-09-01 20:02:44 -07:00
}
2018-07-28 16:29:13 -07:00
void assertRpm(const char *msg, int expectedRpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
assertEqualsM(msg, expectedRpm, engine->rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_SIGNATURE));
}
void setupSimpleTestEngineWithMafAndTT_ONE_trigger(EngineTestHelper *eth, injection_mode_e injMode) {
2016-09-03 10:02:55 -07:00
Engine *engine = &eth->engine;
EXPAND_Engine
2018-03-04 20:42:30 -08:00
timeNowUs = 0;
2018-03-04 13:38:01 -08:00
eth->clearQueue();
2016-11-07 20:01:47 -08:00
2016-08-28 13:02:34 -07:00
assertEquals(LM_PLAIN_MAF, engineConfiguration->fuelAlgorithm);
2018-03-04 13:30:03 -08:00
engineConfiguration->isIgnitionEnabled = false; // let's focus on injection
2016-08-27 07:03:11 -07:00
engineConfiguration->specs.cylindersCount = 4;
// a bit of flexibility - the mode may be changed by some tests
engineConfiguration->injectionMode = injMode;
// set cranking mode (it's used by getCurrentInjectionMode())
engineConfiguration->crankingInjectionMode = IM_SIMULTANEOUS;
2016-09-03 10:02:55 -07:00
2016-08-26 16:02:56 -07:00
setArrayValues(config->cltFuelCorrBins, CLT_CURVE_SIZE, 1);
setArrayValues(engineConfiguration->injector.battLagCorr, VBAT_INJECTOR_CURVE_SIZE, 0);
// this is needed to update injectorLag
2017-05-15 20:28:49 -07:00
engine->updateSlowSensors(PASS_ENGINE_PARAMETER_SIGNATURE);
2016-08-26 16:02:56 -07:00
assertEqualsM("CLT", 70, engine->sensors.clt);
2018-03-04 18:02:35 -08:00
assertEqualsM("trigger #1", 0, readIfTriggerConfigChangedForUnitTest());
2016-08-26 14:02:37 -07:00
2016-08-26 15:02:39 -07:00
engineConfiguration->trigger.type = TT_ONE;
2017-05-15 20:28:49 -07:00
incrementGlobalConfigurationVersion(PASS_ENGINE_PARAMETER_SIGNATURE);
2018-03-04 18:02:35 -08:00
assertEqualsM("trigger #2", 1, readIfTriggerConfigChangedForUnitTest());
2016-08-26 15:02:39 -07:00
2016-09-03 10:02:55 -07:00
eth->applyTriggerShape();
2016-08-26 15:02:39 -07:00
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);
2016-11-07 20:01:47 -08:00
Engine *engine = &eth->engine;
EXPAND_Engine
2018-07-28 16:29:13 -07:00
assertRpm("RPM=0", 0 PASS_ENGINE_PARAMETER_SUFFIX);
2018-03-04 17:53:19 -08:00
assertEqualsM("setTestBug299 EL", 0, getEngineLoadT(PASS_ENGINE_PARAMETER_SIGNATURE));
assertEqualsM("setTestBug299 IAT", 30, engine->sensors.iat);
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
2018-07-28 16:29:13 -07:00
assertRpm("setTestBug299: RPM#1", 0 PASS_ENGINE_PARAMETER_SUFFIX);
2018-07-28 16:37:10 -07:00
eth->fireTriggerEventsWithDuration(20);
2018-07-28 16:29:13 -07:00
assertRpm("setTestBug299: RPM#2", 3000 PASS_ENGINE_PARAMETER_SUFFIX);
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 |........|.......#|........|.......#|
2016-11-08 22:02:15 -08:00
assertEqualsM("qs#00", 4, schedulingQueue.size());
2016-08-27 17:02:25 -07:00
assertEqualsM("rev cnt#3", 3, engine->rpmCalculator.getRevolutionCounter());
2018-03-04 20:08:32 -08:00
assertInjectorUpEvent("setTestBug299: 1@0", 0, MS2US(8.5), 0 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorDownEvent("@1", 1, MS2US(10), 0 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorUpEvent("1@2", 2, MS2US(18.5), 1 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorDownEvent("1@3", 3, MS2US(20), 1 PASS_ENGINE_PARAMETER_SUFFIX);
2018-03-04 13:30:03 -08:00
assertEqualsM("exec#0", 0, schedulingQueue.executeAll(timeNowUs));
2016-08-26 17:03:06 -07:00
2016-12-18 09:03:48 -08:00
FuelSchedule * t = &ENGINE(injectionEvents);
2016-11-30 18:06:24 -08:00
2016-11-30 19:06:43 -08:00
assertInjectionEvent("#0", &t->elements[0], 0, 1, 153, false);
2016-12-01 17:01:57 -08:00
assertInjectionEvent("#1_i_@", &t->elements[1], 1, 1, 333, false);
2016-11-30 20:02:42 -08:00
assertInjectionEvent("#2@", &t->elements[2], 0, 0, 153, false);
assertInjectionEvent("inj#3@", &t->elements[3], 1, 0, 153 + 180, false);
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 |........|.......#|........|.......#|
2016-08-27 13:02:12 -07:00
assertEqualsM("qs#0", 8, schedulingQueue.size());
2016-08-27 14:01:58 -07:00
assertEqualsM("rev cnt#3", 3, engine->rpmCalculator.getRevolutionCounter());
2018-03-04 20:08:32 -08:00
assertInjectorUpEvent("02@0", 0, MS2US(-11.5), 0 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorDownEvent("@1", 1, MS2US(-10), 0 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorUpEvent("@2", 2, MS2US(-1.5), 1 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorDownEvent("02@3", 3, MS2US(0), 1 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorUpEvent("02@4", 4, MS2US(8.5), 0 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorDownEvent("@5", 5, MS2US(10), 0 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorUpEvent("02@6", 6, MS2US(18.5), 1 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorDownEvent("@7", 7, MS2US(20), 1 PASS_ENGINE_PARAMETER_SUFFIX);
2018-03-04 13:30:03 -08:00
assertEqualsM("exec#1", 4, schedulingQueue.executeAll(timeNowUs));
2016-08-27 14:01:58 -07:00
2016-08-27 17:02:25 -07:00
/**
* Trigger up again
*/
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(20);
2018-03-04 20:08:32 -08:00
assertInjectorUpEvent("22@0", 0, MS2US(-11.5), 0 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorDownEvent("22@1", 1, MS2US(-10), 0 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorUpEvent("22@2", 2, MS2US(-1.5), 1 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorDownEvent("22@3", 3, MS2US(0), 1 PASS_ENGINE_PARAMETER_SUFFIX);
2018-03-04 13:30:03 -08:00
assertEqualsM("exec#20", 4, schedulingQueue.executeAll(timeNowUs));
2016-09-04 21:02:31 -07:00
2016-09-03 10:02:55 -07:00
eth->firePrimaryTriggerRise();
2016-11-08 22:02:15 -08:00
assertEqualsM("qs#0-2", 4, schedulingQueue.size());
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 |........|.......#|........|.......#|
2018-03-04 20:08:32 -08:00
assertInjectorUpEvent("2@0", 0, MS2US(8.5), 0 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorDownEvent("@1", 1, MS2US(10), 0 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorUpEvent("@2", 2, MS2US(18.5), 1 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorDownEvent("2@3", 3, MS2US(20), 1 PASS_ENGINE_PARAMETER_SUFFIX);
2018-03-04 13:30:03 -08:00
assertEqualsM("exec#2", 0, schedulingQueue.executeAll(timeNowUs));
2016-08-27 17:02:25 -07:00
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(20);
schedulingQueue.executeAll(timeNowUs);
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 |........|.......#|........|........|
assertEqualsM("qs#0-2", 4, schedulingQueue.size());
2016-08-27 14:01:58 -07:00
assertEqualsM("rev cnt#4", 4, engine->rpmCalculator.getRevolutionCounter());
2018-03-04 20:08:32 -08:00
assertInjectorUpEvent("0@0", 0, MS2US(8.5), 0 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorDownEvent("0@1", 1, MS2US(10), 0 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorUpEvent("0@2", 2, MS2US(18.5), 1 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorDownEvent("0@3", 3, MS2US(20), 1 PASS_ENGINE_PARAMETER_SUFFIX);
2018-03-04 13:30:03 -08:00
assertEqualsM("exec#3", 0, schedulingQueue.executeAll(timeNowUs));
2016-08-27 14:01:58 -07:00
2016-08-26 16:02:56 -07:00
assertEqualsM("iatC", 1, engine->engineState.iatFuelCorrection);
assertEqualsM("cltC", 1, engine->engineState.cltFuelCorrection);
assertEqualsM("lag", 0, engine->engineState.injectorLag);
2018-07-28 16:29:13 -07:00
testMafValue = 0;
assertEqualsM("maf", 0, getMaf(PASS_ENGINE_PARAMETER_SIGNATURE));
2018-03-04 17:53:19 -08:00
assertEqualsM("setTestBug299: RPM", 3000, engine->rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_SIGNATURE));
2016-08-26 16:02:56 -07:00
2017-11-06 19:29:39 -08:00
assertEqualsM("fuel#1", 1.5, engine->injectionDuration);
2017-05-15 20:28:49 -07:00
assertEqualsM("duty for maf=0", 7.5, getInjectorDutyCycle(engine->rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX));
2016-08-26 16:02:56 -07:00
testMafValue = 3;
2017-05-15 20:28:49 -07:00
assertEqualsM("maf", 3, getMaf(PASS_ENGINE_PARAMETER_SIGNATURE));
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);
}
2016-09-03 10:02:55 -07:00
void testFuelSchedulerBug299smallAndMedium(void) {
printf("*************************************************** testFuelSchedulerBug299 small to medium\r\n");
EngineTestHelper eth(TEST_ENGINE);
EXPAND_EngineTestHelper
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
2016-08-26 16:02:56 -07:00
int engineLoadIndex = findIndex(config->fuelLoadBins, FUEL_LOAD_COUNT, testMafValue);
assertEquals(8, engineLoadIndex);
2016-09-02 23:03:32 -07:00
setArrayValues(fuelMap.pointers[engineLoadIndex], FUEL_RPM_COUNT, 25);
setArrayValues(fuelMap.pointers[engineLoadIndex + 1], FUEL_RPM_COUNT, 25);
2016-08-26 16:02:56 -07:00
2017-05-15 20:28:49 -07:00
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
2017-11-06 19:29:39 -08:00
assertEqualsM("fuel#2", 12.5, engine->injectionDuration);
2017-05-15 20:28:49 -07:00
assertEqualsM("duty for maf=3", 62.5, getInjectorDutyCycle(eth.engine.rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX));
2016-08-26 15:02:39 -07:00
2016-09-04 21:02:31 -07:00
assertEqualsM("qs#1", 4, schedulingQueue.size());
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(20);
assertEqualsM("exec#2#0", 4, schedulingQueue.executeAll(timeNowUs));
2016-09-04 22:03:25 -07:00
assertEqualsM("qs#1#2", 0, schedulingQueue.size());
assertEqualsM("rev cnt#4#0", 4, engine->rpmCalculator.getRevolutionCounter());
2016-08-27 17:02:25 -07:00
eth.firePrimaryTriggerRise();
2016-09-04 22:03:25 -07:00
assertEqualsM("rev cnt#4#1", 5, engine->rpmCalculator.getRevolutionCounter());
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 |.....###|########|....####|########|........|........|........|
2016-11-08 22:02:15 -08:00
assertEqualsM("qs#4", 6, schedulingQueue.size());
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 = schedulingQueue.getForUnitText(9);
// assertEqualsM("rev cnt#4#2", 5, engine->rpmCalculator.getRevolutionCounter());
// assertTrueM("down 50", ev == &engine->engineConfiguration2->fuelActuators[2].signalPair[1].signalTimerDown);
// }
2016-09-04 22:03:25 -07:00
2016-08-27 14:01:58 -07:00
2018-03-04 13:30:03 -08:00
assertEqualsM("exec#4", 0, schedulingQueue.executeAll(timeNowUs));
2016-08-27 14:01:58 -07:00
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(20);
2016-08-27 17:02:25 -07:00
eth.firePrimaryTriggerFall();
2016-11-30 20:02:42 -08:00
assertEqualsM("qs#2#1", 8, schedulingQueue.size());
2016-08-27 17:02:25 -07:00
assertEqualsM("rev cnt#5", 5, engine->rpmCalculator.getRevolutionCounter());
// 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);
2018-03-04 13:30:03 -08:00
assertEqualsM("exec#5", 3, schedulingQueue.executeAll(timeNowUs));
2016-08-27 14:01:58 -07:00
/**
* one more revolution
*/
2017-05-15 20:28:49 -07:00
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
2016-08-27 14:01:58 -07:00
2016-12-18 09:03:48 -08:00
t = &ENGINE(injectionEvents);
2016-11-30 18:06:24 -08:00
2016-11-30 19:06:43 -08:00
assertInjectionEvent("#0", &t->elements[0], 0, 0, 315, false);
2016-12-01 17:01:57 -08:00
assertInjectionEvent("#1__", &t->elements[1], 1, 1, 135, false);
2016-11-30 20:02:42 -08:00
assertInjectionEvent("inj#2", &t->elements[2], 0, 0, 153, false);
assertInjectionEvent("inj#3", &t->elements[3], 1, 0, 333, false);
2016-09-01 20:02:44 -07:00
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(20);
2016-09-04 20:02:10 -07:00
assertEqualsM("qs#02", 5, schedulingQueue.size());
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?
2018-03-04 13:30:03 -08:00
assertEqualsM("exec#07", 5, schedulingQueue.executeAll(timeNowUs));
2016-11-30 20:02:42 -08:00
assertEqualsM("qs#07", 0, schedulingQueue.size());
// 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();
2016-12-01 17:01:57 -08:00
assertEqualsM("qs#2#2", 4, schedulingQueue.size());
2016-08-27 14:01:58 -07:00
assertEqualsM("rev cnt6", 6, engine->rpmCalculator.getRevolutionCounter());
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
2018-03-04 13:30:03 -08:00
assertEqualsM("exec#7", 0, schedulingQueue.executeAll(timeNowUs));
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
2018-03-04 13:30:03 -08:00
timeNowUs += 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 |....####|########|........|........|........|........|........|
2016-12-01 17:01:57 -08:00
assertEqualsM("qs#022", 4, schedulingQueue.size());
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
2018-03-04 13:30:03 -08:00
assertEqualsM("executed #06", 3, schedulingQueue.executeAll(timeNowUs));
2016-09-04 20:02:10 -07:00
assertInjectors("#4", 1, 0);
2016-11-08 22:02:15 -08:00
assertEqualsM("qs#06", 1, schedulingQueue.size());
2018-03-04 20:08:32 -08:00
assertInjectorDownEvent("17@0", 0, MS2US(10), 0 PASS_ENGINE_PARAMETER_SUFFIX);
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();
2016-09-04 22:03:25 -07:00
assertEqualsM("qs#3", 5, schedulingQueue.size());
2016-09-04 20:02:10 -07:00
assertEqualsM("rev cnt6", 6, engine->rpmCalculator.getRevolutionCounter());
2018-03-04 13:30:03 -08:00
assertEqualsM("executed #6", 0, schedulingQueue.executeAll(timeNowUs));
2016-08-29 19:02:57 -07:00
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(20);
assertEqualsM("executed #06", 4, schedulingQueue.executeAll(timeNowUs));
2016-09-04 22:03:25 -07:00
assertEqualsM("qs#06", 1, schedulingQueue.size());
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();
2016-11-08 22:02:15 -08:00
assertEqualsM("Queue.size#03", 5, schedulingQueue.size());
2017-05-15 20:28:49 -07:00
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
2018-03-04 20:08:32 -08:00
assertInjectorUpEvent("07@0", 0, MS2US(7.5), 1 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorDownEvent("07@1", 1, MS2US(10), 0 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorUpEvent("07@2", 2, MS2US(17.5), 0 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorDownEvent("07@3", 3, MS2US(20), 1 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorDownEvent("07@4", 4, MS2US(30), 0 PASS_ENGINE_PARAMETER_SUFFIX);
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
2018-03-04 13:30:03 -08:00
assertEqualsM("executeAll#3", 0, schedulingQueue.executeAll(timeNowUs));
timeNowUs += MS2US(20);
assertEqualsM("executeAll#4", 4, schedulingQueue.executeAll(timeNowUs));
2016-09-04 20:02:10 -07:00
2016-12-18 09:03:48 -08:00
t = &ENGINE(injectionEvents);
2016-11-30 18:06:24 -08:00
2016-11-30 19:06:43 -08:00
assertInjectionEvent("#0#", &t->elements[0], 0, 0, 315, false);
assertInjectionEvent("#1#", &t->elements[1], 1, 1, 135, false);
assertInjectionEvent("#2#", &t->elements[2], 0, 1, 315, true);
assertInjectionEvent("#3#", &t->elements[3], 1, 0, 45 + 90, false);
2016-09-02 23:03:32 -07:00
setArrayValues(fuelMap.pointers[engineLoadIndex], FUEL_RPM_COUNT, 35);
setArrayValues(fuelMap.pointers[engineLoadIndex + 1], FUEL_RPM_COUNT, 35);
2017-05-15 20:28:49 -07:00
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
2017-11-06 19:29:39 -08:00
assertEqualsM("fuel#3", 17.5, engine->injectionDuration);
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
2017-05-15 20:28:49 -07:00
assertEqualsM("duty for maf=3", 87.5, getInjectorDutyCycle(eth.engine.rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX));
2016-09-03 10:02:55 -07:00
2016-08-27 13:02:12 -07:00
2016-11-30 19:06:43 -08:00
assertInjectionEvent("#03", &t->elements[0], 0, 0, 315, false);
2016-09-03 10:02:55 -07:00
2017-05-15 20:28:49 -07:00
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
2016-09-03 10:02:55 -07:00
2016-09-04 20:02:10 -07:00
assertEqualsM("inj#0", 1, enginePins.injectors[0].currentLogicValue);
2016-11-08 22:02:15 -08:00
assertEqualsM("Queue.size#04", 1, schedulingQueue.size());
2018-03-04 20:08:32 -08:00
assertInjectorDownEvent("08@0", 0, MS2US(10), 0 PASS_ENGINE_PARAMETER_SUFFIX);
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
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
2017-05-15 20:28:49 -07:00
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
2016-09-03 10:02:55 -07:00
2018-07-28 16:51:41 -07:00
eth.fireRise(20);
2016-12-01 06:02:30 -08:00
assertEqualsM("Queue.size#05", 7, schedulingQueue.size());
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
2016-09-03 10:02:55 -07:00
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(20);
2016-09-03 10:02:55 -07:00
eth.firePrimaryTriggerFall();
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
2016-09-03 10:02:55 -07:00
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(20);
schedulingQueue.executeAll(timeNowUs);
2016-09-03 10:02:55 -07:00
eth.firePrimaryTriggerRise();
2017-05-15 20:28:49 -07:00
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
2016-09-03 10:02:55 -07:00
2016-12-18 09:03:48 -08:00
t = &ENGINE(injectionEvents);
2016-11-30 18:06:24 -08:00
2016-11-30 19:06:43 -08:00
assertInjectionEvent("#00", &t->elements[0], 0, 0, 225, false); // 87.5 duty cycle
assertInjectionEvent("#10", &t->elements[1], 1, 1, 45, false);
assertInjectionEvent("#20", &t->elements[2], 0, 1, 225, true);
assertInjectionEvent("#30", &t->elements[3], 1, 0, 45, false);
2016-09-03 10:02:55 -07:00
// todo: what's what? a mix of new something and old something?
2016-12-01 06:02:30 -08:00
assertEqualsM("qs#5", 4, schedulingQueue.size());
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
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
2016-08-27 13:02:12 -07:00
2016-08-26 16:02:56 -07:00
unitTestValue = 0;
testMafValue = 0;
2016-08-26 14:02:37 -07:00
}
2016-09-03 10:02:55 -07:00
2017-11-06 19:46:18 -08:00
static void setInjectionMode(int value DECLARE_ENGINE_PARAMETER_SUFFIX) {
engineConfiguration->injectionMode = (injection_mode_e) value;
incrementGlobalConfigurationVersion(PASS_ENGINE_PARAMETER_SIGNATURE);
}
2017-11-06 19:33:06 -08:00
void testDifferentInjectionModes(void) {
printf("*************************************************** testDifferentInjectionModes\r\n");
EngineTestHelper eth(TEST_ENGINE);
EXPAND_EngineTestHelper
setTestBug299(&eth);
2017-11-06 19:37:27 -08:00
assertEqualsM("Lqs#0", 4, schedulingQueue.size());
2017-11-06 19:33:06 -08:00
2017-11-06 19:37:27 -08:00
// set fuel map values - extract method?
int engineLoadIndex = findIndex(config->fuelLoadBins, FUEL_LOAD_COUNT, testMafValue);
assertEquals(8, engineLoadIndex);
setArrayValues(fuelMap.pointers[engineLoadIndex], FUEL_RPM_COUNT, 40);
setArrayValues(fuelMap.pointers[engineLoadIndex + 1], FUEL_RPM_COUNT, 40);
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
assertEqualsM("injectionMode IM_BATCH", (int)IM_BATCH, (int)engineConfiguration->injectionMode);
2017-11-06 19:46:18 -08:00
assertEqualsM("injection while batch", 20, engine->injectionDuration);
setInjectionMode((int)IM_SIMULTANEOUS PASS_ENGINE_PARAMETER_SUFFIX);
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
assertEqualsM("injection while simultaneous", 10, engine->injectionDuration);
setInjectionMode((int)IM_SEQUENTIAL PASS_ENGINE_PARAMETER_SUFFIX);
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
assertEqualsM("injection while IM_SEQUENTIAL", 40, engine->injectionDuration);
setInjectionMode((int)IM_SINGLE_POINT PASS_ENGINE_PARAMETER_SUFFIX);
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
assertEqualsM("injection while IM_SINGLE_POINT", 40, engine->injectionDuration);
2017-11-06 19:33:06 -08:00
}
2016-09-03 10:02:55 -07:00
void testFuelSchedulerBug299smallAndLarge(void) {
printf("*************************************************** testFuelSchedulerBug299 small to large\r\n");
2016-09-03 11:01:47 -07:00
EngineTestHelper eth(TEST_ENGINE);
EXPAND_EngineTestHelper
setTestBug299(&eth);
2016-09-04 21:02:31 -07:00
assertEqualsM("Lqs#0", 4, schedulingQueue.size());
2016-09-03 10:02:55 -07:00
2017-11-06 19:37:27 -08:00
// set fuel map values - extract method?
2016-09-03 11:01:47 -07:00
int engineLoadIndex = findIndex(config->fuelLoadBins, FUEL_LOAD_COUNT, testMafValue);
assertEquals(8, engineLoadIndex);
setArrayValues(fuelMap.pointers[engineLoadIndex], FUEL_RPM_COUNT, 35);
setArrayValues(fuelMap.pointers[engineLoadIndex + 1], FUEL_RPM_COUNT, 35);
2017-05-15 20:28:49 -07:00
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
2017-11-06 19:29:39 -08:00
assertEqualsM("Lfuel#2", 17.5, engine->injectionDuration);
2018-07-28 11:33:32 -07:00
assertEqualsM("Lduty for maf=3", 87.5, getInjectorDutyCycle(engine->rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX));
2016-09-03 11:01:47 -07:00
2016-09-03 22:01:54 -07:00
2016-09-04 21:02:31 -07:00
assertEqualsM("Lqs#1", 4, schedulingQueue.size());
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(20);
schedulingQueue.executeAll(timeNowUs);
2016-09-03 22:01:54 -07:00
// injector #1 is low before the test
assertFalseM("injector@0", enginePins.injectors[0].currentLogicValue);
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 |..######|########|....####|########|........|........|........|
2016-11-30 20:02:42 -08:00
assertEqualsM("Lqs#4", 6, schedulingQueue.size());
2018-03-04 20:08:32 -08:00
assertInjectorUpEvent("L04@0", 0, MS2US(8.5), 0 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorUpEvent("L04@1", 1, MS2US(12.5), 0 PASS_ENGINE_PARAMETER_SUFFIX);
2016-09-03 22:01:54 -07:00
// special overlapping injection is merged with one of the scheduled injections
2018-03-04 20:08:32 -08:00
assertInjectorUpEvent("L04@2", 2, MS2US(18.5), 1 PASS_ENGINE_PARAMETER_SUFFIX);
2016-09-03 22:01:54 -07:00
2018-03-04 20:08:32 -08:00
assertInjectorDownEvent("L04@3", 3, MS2US(26), 0 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorDownEvent("L04@4", 4, MS2US(30), 0 PASS_ENGINE_PARAMETER_SUFFIX);
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
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs + 1);
2016-09-03 22:01:54 -07:00
// injector goes high...
2016-11-30 20:02:42 -08:00
assertFalseM("injector@1", enginePins.injectors[0].currentLogicValue);
2016-09-03 10:02:55 -07:00
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs + MS2US(17.5) + 1);
2016-09-04 23:02:00 -07:00
// injector does not go low too soon, that's a feature :)
2016-09-03 22:01:54 -07:00
assertTrueM("injector@2", enginePins.injectors[0].currentLogicValue);
2016-09-03 10:02:55 -07:00
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(20);
2016-09-04 23:02:00 -07:00
eth.firePrimaryTriggerFall();
assertEqualsM("Lqs#04", 6, schedulingQueue.size());
2018-03-04 20:08:32 -08:00
assertInjectorUpEvent("L015@0", 0, MS2US(-1.5), 1 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorUpEvent("L015@1", 1, MS2US(2.5), 1 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorDownEvent("L015@2", 2, MS2US(6), 0 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorDownEvent("L015@3", 3, MS2US(10), 0 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorDownEvent("L015@4", 4, MS2US(16), 1 PASS_ENGINE_PARAMETER_SUFFIX);
2016-11-30 20:02:42 -08:00
//todo assertInjectorDownEvent("L015@5", 5, MS2US(30), 0);
2016-09-04 23:02:00 -07:00
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs + MS2US(10) + 1);
2016-09-03 22:01:54 -07:00
// end of combined injection
assertFalseM("injector@3", enginePins.injectors[0].currentLogicValue);
2016-09-04 23:02:00 -07:00
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(20);
schedulingQueue.executeAll(timeNowUs);
2016-11-30 20:02:42 -08:00
assertEqualsM("Lqs#04", 0, schedulingQueue.size());
2016-09-04 23:02:00 -07:00
setArrayValues(fuelMap.pointers[engineLoadIndex], FUEL_RPM_COUNT, 4);
setArrayValues(fuelMap.pointers[engineLoadIndex + 1], FUEL_RPM_COUNT, 4);
2017-05-15 20:28:49 -07:00
engine->periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
2017-11-06 19:29:39 -08:00
assertEqualsM("Lfuel#4", 2, engine->injectionDuration);
2017-05-15 20:28:49 -07:00
assertEqualsM("Lduty for maf=3", 10, getInjectorDutyCycle(eth.engine.rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX));
2016-09-04 23:02:00 -07:00
eth.firePrimaryTriggerRise();
2016-11-30 20:02:42 -08:00
//todoassertEqualsM("Lqs#05", 5, schedulingQueue.size());
//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
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(20);
schedulingQueue.executeAll(timeNowUs); // issue here
2016-09-04 23:02:00 -07:00
eth.firePrimaryTriggerFall();
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(20);
schedulingQueue.executeAll(timeNowUs);
2016-09-04 23:02:00 -07:00
eth.firePrimaryTriggerRise();
2016-11-08 22:02:15 -08:00
assertEqualsM("Lqs#5", 4, schedulingQueue.size());
2018-03-04 20:08:32 -08:00
assertInjectorUpEvent("L05@0", 0, MS2US(8), 0 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorDownEvent("L05@1", 1, MS2US(10), 0 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorUpEvent("L05@2", 2, MS2US(18), 1 PASS_ENGINE_PARAMETER_SUFFIX);
assertInjectorDownEvent("L05@3", 3, MS2US(20), 1 PASS_ENGINE_PARAMETER_SUFFIX);
2016-09-04 23:02:00 -07:00
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(20);
schedulingQueue.executeAll(timeNowUs);
2016-09-03 10:02:55 -07:00
}
2016-10-31 17:02:09 -07:00
void testSparkReverseOrderBug319(void) {
printf("*************************************************** testSparkReverseOrderBug319 small to medium\r\n");
EngineTestHelper eth(TEST_ENGINE);
EXPAND_EngineTestHelper
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;
2017-05-15 20:28:49 -07:00
setConstantDwell(45 PASS_ENGINE_PARAMETER_SUFFIX);
2016-10-31 19:02:12 -07:00
// this is needed to update injectorLag
2017-05-15 20:28:49 -07:00
engine->updateSlowSensors(PASS_ENGINE_PARAMETER_SIGNATURE);
2016-10-31 19:02:12 -07:00
assertEqualsM("CLT", 70, engine->sensors.clt);
2016-10-31 19:02:12 -07:00
2016-10-31 17:02:09 -07:00
engineConfiguration->trigger.type = TT_ONE;
2017-05-15 20:28:49 -07:00
incrementGlobalConfigurationVersion(PASS_ENGINE_PARAMETER_SIGNATURE);
2016-10-31 19:02:12 -07:00
eth.applyTriggerShape();
2017-05-15 20:28:49 -07:00
eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
2016-10-31 17:02:09 -07:00
2018-03-04 13:30:03 -08:00
timeNowUs = 0;
2017-05-15 20:28:49 -07:00
setWholeTimingTable(0 PASS_ENGINE_PARAMETER_SUFFIX);
2016-10-31 17:02:09 -07:00
2018-07-28 16:51:41 -07:00
eth.fireRise(20);
2016-10-31 17:02:09 -07:00
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(20);
2016-10-31 17:02:09 -07:00
eth.firePrimaryTriggerFall();
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
2016-10-31 17:02:09 -07:00
2018-07-28 16:51:41 -07:00
eth.fireRise(20);
2016-10-31 17:02:09 -07:00
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(20);
2016-10-31 17:02:09 -07:00
eth.firePrimaryTriggerFall();
2018-03-04 17:53:19 -08:00
assertEqualsM("testSparkReverseOrderBug319: RPM", 3000, eth.engine.rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_SIGNATURE));
2016-10-31 19:02:12 -07:00
2018-03-04 18:23:44 -08:00
assertEqualsM("testSparkReverseOrderBug319: queue size", 7, schedulingQueue.size());
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
2016-10-31 19:02:12 -07:00
printf("***************************************************\r\n");
2018-07-28 16:51:41 -07:00
eth.fireRise(20);
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
2016-10-31 19:02:12 -07:00
2016-10-31 17:02:09 -07:00
2018-03-04 13:30:03 -08:00
timeNowUs += 100; // executing new signal too early
2016-10-31 19:02:12 -07:00
eth.firePrimaryTriggerFall();
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
2016-10-31 17:02:09 -07:00
2016-11-01 20:01:54 -07:00
assertEqualsM("out-of-order #1", 1, enginePins.coils[3].outOfOrder);
2016-10-31 19:02:12 -07:00
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(200); // moving time forward to execute all pending actions
schedulingQueue.executeAll(timeNowUs);
2016-10-31 17:02:09 -07:00
2016-11-01 20:01:54 -07:00
assertEqualsM("out-of-order #2", 0, enginePins.coils[3].outOfOrder);
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);
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
2016-11-01 18:03:07 -07:00
2017-05-15 20:28:49 -07:00
assertEqualsM("RPM#2", 545, eth.engine.rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_SIGNATURE));
2016-11-01 18:03:07 -07:00
2016-11-01 20:01:54 -07:00
assertEqualsM("out-of-order #3", 0, enginePins.coils[3].outOfOrder);
2016-11-01 18:03:07 -07:00
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(20);
2016-11-01 18:03:07 -07:00
eth.firePrimaryTriggerFall();
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
2016-11-01 20:01:54 -07:00
assertEqualsM("out-of-order #4", 1, enginePins.coils[3].outOfOrder);
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);
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
2016-11-01 18:03:07 -07:00
2017-05-15 20:28:49 -07:00
assertEqualsM("RPM#3", 3000, eth.engine.rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_SIGNATURE));
2016-11-01 18:03:07 -07:00
2016-11-28 17:03:43 -08:00
assertEqualsM("out-of-order #5 on c4", 1, enginePins.coils[3].outOfOrder);
2016-11-01 18:03:07 -07:00
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(20);
2016-11-01 18:03:07 -07:00
eth.firePrimaryTriggerFall();
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
2016-11-29 17:02:41 -08:00
assertEqualsM("out-of-order #6 on c4", 1, enginePins.coils[3].outOfOrder);
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);
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
2016-11-01 18:03:07 -07:00
2017-05-15 20:28:49 -07:00
assertEqualsM("RPM#4", 3000, eth.engine.rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_SIGNATURE));
2016-11-01 18:03:07 -07:00
2016-11-29 17:02:41 -08:00
assertEqualsM("out-of-order #7", 1, enginePins.coils[3].outOfOrder);
2016-11-01 18:03:07 -07:00
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(20);
2016-11-01 18:03:07 -07:00
eth.firePrimaryTriggerFall();
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
2016-11-01 20:01:54 -07:00
assertEqualsM("out-of-order #8", 0, enginePins.coils[3].outOfOrder);
2016-10-31 17:02:09 -07:00
}
2016-11-07 19:02:21 -08:00
void testMissedSpark299(void) {
printf("*************************************************** testMissedSpark299\r\n");
EngineTestHelper eth(TEST_ENGINE);
EXPAND_EngineTestHelper
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;
2017-03-28 15:59:42 -07:00
assertEqualsM("warningCounter#0", 4, unitTestWarningCounter);
2016-11-07 19:02:21 -08:00
2018-07-28 17:02:01 -07:00
eth.fireRise(20);
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
2016-11-08 21:02:01 -08:00
assertEqualsM("ci#0", 0, eth.engine.triggerCentral.triggerState.currentCycle.current_index);
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(20);
2016-11-08 21:02:01 -08:00
eth.firePrimaryTriggerFall();
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
2016-11-08 21:02:01 -08:00
assertEqualsM("ci#1", 1, eth.engine.triggerCentral.triggerState.currentCycle.current_index);
2016-11-07 19:02:21 -08:00
2018-07-28 17:02:01 -07:00
eth.fireRise(20);
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
2016-11-08 21:02:01 -08:00
assertEqualsM("ci#2", 0, eth.engine.triggerCentral.triggerState.currentCycle.current_index);
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(20);
2016-11-08 21:02:01 -08:00
eth.firePrimaryTriggerFall();
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
2016-11-08 21:02:01 -08:00
assertEqualsM("ci#3", 1, eth.engine.triggerCentral.triggerState.currentCycle.current_index);
2016-11-07 20:01:47 -08:00
2018-07-28 16:51:41 -07:00
eth.fireRise(20);
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
2016-11-07 19:02:21 -08:00
2018-03-04 13:30:03 -08:00
timeNowUs += MS2US(20);
2016-11-08 21:02:01 -08:00
eth.firePrimaryTriggerFall();
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
2016-11-08 21:02:01 -08:00
assertEqualsM("ci#5", 1, eth.engine.triggerCentral.triggerState.currentCycle.current_index);
2016-11-07 20:01:47 -08:00
printf("*************************************************** testMissedSpark299 start\r\n");
2016-11-08 19:02:47 -08:00
assertEquals(3000, eth.engine.rpmCalculator.rpmValue);
2016-11-07 19:02:21 -08:00
2017-05-15 20:28:49 -07:00
setWholeTimingTable(3 PASS_ENGINE_PARAMETER_SUFFIX);
eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
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);
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
timeNowUs += MS2US(20);
2016-11-08 21:02:01 -08:00
eth.firePrimaryTriggerFall();
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
2016-11-07 20:01:47 -08:00
2018-07-28 17:02:01 -07:00
eth.fireRise(20);
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
timeNowUs += MS2US(20);
2016-11-08 21:02:01 -08:00
eth.firePrimaryTriggerFall();
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
2016-11-07 19:02:21 -08:00
2017-05-15 20:28:49 -07:00
setWholeTimingTable(-5 PASS_ENGINE_PARAMETER_SUFFIX);
eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE);
2016-11-07 20:01:47 -08:00
2018-07-28 16:51:41 -07:00
eth.fireRise(20);
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
timeNowUs += MS2US(20);
2016-11-08 21:02:01 -08:00
eth.firePrimaryTriggerFall();
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
2016-11-07 20:01:47 -08:00
2018-07-28 16:51:41 -07:00
eth.fireRise(20);
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
timeNowUs += MS2US(20);
2016-11-08 21:02:01 -08:00
eth.firePrimaryTriggerFall();
2018-03-04 13:30:03 -08:00
schedulingQueue.executeAll(timeNowUs);
2016-11-07 20:01:47 -08:00
2017-03-28 15:59:42 -07:00
assertEqualsM("warningCounter#1", 5, unitTestWarningCounter);
2016-11-07 19:02:21 -08:00
}