rusefi-1/unit_tests/test_trigger_decoder.cpp

543 lines
20 KiB
C++
Raw Normal View History

2014-08-29 07:52:33 -07:00
/**
* @file test_trigger_decoder.cpp
*
* @date Dec 24, 2013
* @author Andrey Belomutskiy, (c) 2012-2013
*/
#include "main.h"
#include "test_trigger_decoder.h"
#include "trigger_decoder.h"
#include "engine_math.h"
#include "thermistors.h"
#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"
2014-12-16 18:05:03 -08:00
#include "trigger_mazda.h"
#include "trigger_chrysler.h"
2014-08-29 07:52:33 -07:00
#include "trigger_central.h"
#include "main_trigger_callback.h"
#include "engine.h"
#include "advance_map.h"
#include "engine_test_helper.h"
#include "speed_density.h"
extern int timeNow;
2014-10-01 18:03:03 -07:00
extern bool printGapRatio;
2014-12-16 17:04:36 -08:00
extern float actualSynchGap;
2014-10-01 18:03:03 -07:00
2014-08-29 07:52:33 -07:00
extern "C" {
void sendOutConfirmation(char *value, int i);
}
void sendOutConfirmation(char *value, int i) {
// test implementation
}
int getTheAngle(engine_type_e engineType) {
2014-10-31 13:03:07 -07:00
EngineTestHelper eth(engineType);
2014-11-25 08:04:15 -08:00
Engine *engine = &eth.engine;
engine_configuration_s *engineConfiguration = eth.ec;
initDataStructures(PASS_ENGINE_PARAMETER_F);
2014-08-29 07:52:33 -07:00
2014-11-24 13:03:32 -08:00
trigger_shape_s * shape = &eth.engine.triggerShape;
2014-11-26 12:04:04 -08:00
return findTriggerZeroEventIndex(shape, &engineConfiguration->triggerConfig PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
}
static void testDodgeNeonDecoder(void) {
printf("*************************************************** testDodgeNeonDecoder\r\n");
initTriggerDecoder();
assertEqualsM("trigger zero index", 8, getTheAngle(DODGE_NEON_1995));
2014-10-31 13:03:07 -07:00
EngineTestHelper eth(DODGE_NEON_1995);
2014-08-29 07:52:33 -07:00
2014-10-31 13:03:07 -07:00
engine_configuration_s *ec = eth.ec;
2014-11-24 13:03:32 -08:00
trigger_shape_s * shape = &eth.engine.triggerShape;
2014-11-24 12:06:11 -08:00
assertEquals(8, shape->getTriggerShapeSynchPointIndex());
2014-08-29 07:52:33 -07:00
TriggerState state;
assertFalseM("1 shaft_is_synchronized", state.shaft_is_synchronized);
int r = 0;
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, r + 60);
// assertFalseM("2 shaft_is_synchronized", state.shaft_is_synchronized); // still no synchronization
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, r + 210);
// assertFalseM("3 shaft_is_synchronized", state.shaft_is_synchronized); // still no synchronization
//
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, r + 420);
// assertFalseM("4 shaft_is_synchronized", state.shaft_is_synchronized); // still no synchronization
//
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, r + 630);
// assertFalse(state.shaft_is_synchronized); // still no synchronization
//
// printf("2nd camshaft revolution\r\n");
// r = 720;
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, r + 60);
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, r + 210);
// assertTrue(state.shaft_is_synchronized);
// assertEquals(0, state.current_index);
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, r + 420);
// assertEquals(1, state.current_index);
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, r + 630);
// assertEquals(2, state.current_index);
//
// printf("3rd camshaft revolution\r\n");
// r = 2 * 720;
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, r + 60);
// assertEqualsM("current index", 3, state.current_index);
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, r + 210);
// assertTrue(state.shaft_is_synchronized);
// assertEqualsM("current index", 0, state.current_index);
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_UP, r + 420);
// processTriggerEvent(&state, shape, &ec->triggerConfig, SHAFT_PRIMARY_DOWN, r + 630);
}
static void assertTriggerPosition(event_trigger_position_s *position, int eventIndex, float angleOffset) {
assertEqualsM("eventIndex", eventIndex, position->eventIndex);
assertEqualsM("angleOffset", angleOffset, position->angleOffset);
}
static void test1995FordInline6TriggerDecoder(void) {
printf("*************************************************** test1995FordInline6TriggerDecoder\r\n");
assertEqualsM("triggerIndex ", 0, getTheAngle(FORD_INLINE_6_1995));
initTriggerDecoder();
2014-10-31 13:03:07 -07:00
EngineTestHelper eth(FORD_INLINE_6_1995);
2014-08-29 07:52:33 -07:00
2014-11-07 21:07:22 -08:00
engine_configuration_s *engineConfiguration = eth.engine.engineConfiguration;
Engine *engine = &eth.engine;
2014-08-29 07:52:33 -07:00
2014-11-24 13:03:32 -08:00
trigger_shape_s * shape = &eth.engine.triggerShape;
2014-11-24 12:06:11 -08:00
assertEqualsM("triggerShapeSynchPointIndex", 0, shape->getTriggerShapeSynchPointIndex());
2014-08-29 07:52:33 -07:00
event_trigger_position_s position;
2014-11-07 21:07:22 -08:00
assertEqualsM("globalTriggerAngleOffset", 0, engineConfiguration->globalTriggerAngleOffset);
2014-11-25 09:05:03 -08:00
findTriggerPosition(&position, 0 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertTriggerPosition(&position, 0, 0);
2014-11-25 09:05:03 -08:00
findTriggerPosition(&position, 200 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertTriggerPosition(&position, 3, 20);
2014-11-25 09:05:03 -08:00
findTriggerPosition(&position, 360 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertTriggerPosition(&position, 6, 0);
2014-11-07 06:03:03 -08:00
IgnitionEventList *ecl = &eth.ec2.ignitionEvents[0];
2014-08-29 07:52:33 -07:00
assertEqualsM("ignition events size", 6, ecl->size);
assertEqualsM("event index", 0, ecl->events[0].dwellPosition.eventIndex);
assertEquals(0, ecl->events[0].dwellPosition.angleOffset);
assertEqualsM("event index", 10, ecl->events[5].dwellPosition.eventIndex);
assertEquals(0, ecl->events[5].dwellPosition.angleOffset);
TriggerState state;
assertFalseM("shaft_is_synchronized", state.shaft_is_synchronized);
int r = 10;
2014-11-26 13:03:29 -08:00
state.decodeTriggerEvent(SHAFT_PRIMARY_DOWN, r PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertFalseM("shaft_is_synchronized", state.shaft_is_synchronized); // still no synchronization
2014-11-26 13:03:29 -08:00
state.decodeTriggerEvent(SHAFT_PRIMARY_UP, ++r PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertTrue(state.shaft_is_synchronized); // first signal rise synchronize
assertEquals(0, state.getCurrentIndex());
2014-11-26 13:03:29 -08:00
state.decodeTriggerEvent(SHAFT_PRIMARY_DOWN, r++ PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertEquals(1, state.getCurrentIndex());
for (int i = 2; i < 10;) {
2014-11-26 13:03:29 -08:00
state.decodeTriggerEvent(SHAFT_PRIMARY_UP, r++ PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertEqualsM("even", i++, state.getCurrentIndex());
2014-11-26 13:03:29 -08:00
state.decodeTriggerEvent(SHAFT_PRIMARY_DOWN, r++ PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertEqualsM("odd", i++, state.getCurrentIndex());
}
2014-11-26 13:03:29 -08:00
state.decodeTriggerEvent(SHAFT_PRIMARY_UP, r++ PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertEquals(10, state.getCurrentIndex());
2014-11-26 13:03:29 -08:00
state.decodeTriggerEvent(SHAFT_PRIMARY_DOWN, r++ PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertEquals(11, state.getCurrentIndex());
2014-11-26 13:03:29 -08:00
state.decodeTriggerEvent(SHAFT_PRIMARY_UP, r++ PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertEquals(0, state.getCurrentIndex()); // new revolution
2014-11-07 21:07:22 -08:00
assertEqualsM("running dwell", 0.5, getSparkDwellMsT(2000 PASS_ENGINE_PARAMETER));
2014-08-29 07:52:33 -07:00
}
void testFordAspire(void) {
printf("*************************************************** testFordAspire\r\n");
assertEquals(4, getTheAngle(FORD_ASPIRE_1996));
2014-10-31 13:03:07 -07:00
EngineTestHelper eth(FORD_ASPIRE_1996);
2014-11-07 21:07:22 -08:00
Engine *engine = &eth.engine;
engine_configuration_s *engineConfiguration = eth.ec;
2014-11-24 13:03:32 -08:00
assertEquals(4, eth.engine.triggerShape.getTriggerShapeSynchPointIndex());
2014-08-29 07:52:33 -07:00
2014-11-07 21:07:22 -08:00
assertEquals(800, engineConfiguration->fuelRpmBins[0]);
assertEquals(7000, engineConfiguration->fuelRpmBins[15]);
2014-08-29 07:52:33 -07:00
2014-11-07 21:07:22 -08:00
engineConfiguration->crankingChargeAngle = 65;
engineConfiguration->crankingTimingAngle = 31;
2014-08-29 07:52:33 -07:00
2014-11-07 21:07:22 -08:00
assertEqualsM("cranking dwell", 54.166670, getSparkDwellMsT(200 PASS_ENGINE_PARAMETER));
assertEqualsM("running dwell", 4, getSparkDwellMsT(2000 PASS_ENGINE_PARAMETER));
2014-08-29 07:52:33 -07:00
2014-11-07 21:07:22 -08:00
assertEqualsM("higher rpm dwell", 3.25, getSparkDwellMsT(6000 PASS_ENGINE_PARAMETER));
2014-08-29 07:52:33 -07:00
}
void testMazda323(void) {
printf("*************************************************** testMazda323\r\n");
2014-10-31 13:03:07 -07:00
EngineTestHelper eth(MAZDA_323);
2014-11-24 13:03:32 -08:00
assertEquals(0, eth.engine.triggerShape.getTriggerShapeSynchPointIndex());
2014-08-29 07:52:33 -07:00
}
void testMazdaMianaNbDecoder(void) {
printf("*************************************************** testMazdaMianaNbDecoder\r\n");
2014-10-31 13:03:07 -07:00
EngineTestHelper eth(MAZDA_MIATA_NB);
engine_configuration_s *ec = eth.ec;
2014-11-07 21:07:22 -08:00
Engine *engine = &eth.engine;
engine_configuration_s *engineConfiguration = ec;
2014-11-24 13:03:32 -08:00
trigger_shape_s * shape = &eth.engine.triggerShape;
2014-11-24 12:06:11 -08:00
assertEquals(11, shape->getTriggerShapeSynchPointIndex());
2014-08-29 07:52:33 -07:00
TriggerState state;
int a = 0;
2014-11-26 13:03:29 -08:00
state.decodeTriggerEvent(SHAFT_PRIMARY_DOWN, a + 20 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertFalseM("0a shaft_is_synchronized", state.shaft_is_synchronized);
2014-11-26 13:03:29 -08:00
state.decodeTriggerEvent(SHAFT_PRIMARY_UP, a + 340 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertFalseM("0b shaft_is_synchronized", state.shaft_is_synchronized);
2014-11-26 13:03:29 -08:00
state.decodeTriggerEvent(SHAFT_PRIMARY_DOWN, a + 360 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertFalseM("0c shaft_is_synchronized", state.shaft_is_synchronized);
2014-11-26 13:03:29 -08:00
state.decodeTriggerEvent(SHAFT_PRIMARY_UP, a + 380 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertFalseM("0d shaft_is_synchronized", state.shaft_is_synchronized);
2014-11-26 13:03:29 -08:00
state.decodeTriggerEvent(SHAFT_PRIMARY_DOWN, a + 400 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertTrueM("0e shaft_is_synchronized", state.shaft_is_synchronized);
2014-11-26 13:03:29 -08:00
state.decodeTriggerEvent(SHAFT_PRIMARY_UP, a + 720 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertTrueM("0f shaft_is_synchronized", state.shaft_is_synchronized);
a = 720;
2014-11-26 13:03:29 -08:00
state.decodeTriggerEvent(SHAFT_PRIMARY_DOWN, a + 20 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertTrueM("1a shaft_is_synchronized", state.shaft_is_synchronized);
2014-11-26 13:03:29 -08:00
state.decodeTriggerEvent(SHAFT_PRIMARY_UP, a + 340 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertTrueM("1b shaft_is_synchronized", state.shaft_is_synchronized);
2014-11-26 13:03:29 -08:00
state.decodeTriggerEvent(SHAFT_PRIMARY_DOWN, a + 360 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertTrueM("1c shaft_is_synchronized", state.shaft_is_synchronized);
2014-11-26 13:03:29 -08:00
state.decodeTriggerEvent(SHAFT_PRIMARY_UP, a + 380 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertTrueM("1d shaft_is_synchronized", state.shaft_is_synchronized);
assertEquals(5, state.getCurrentIndex());
2014-11-26 13:03:29 -08:00
state.decodeTriggerEvent(SHAFT_PRIMARY_DOWN, a + 400 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertTrueM("1e shaft_is_synchronized", state.shaft_is_synchronized);
assertEquals(0, state.getCurrentIndex());
2014-11-26 13:03:29 -08:00
state.decodeTriggerEvent(SHAFT_PRIMARY_UP, a + 720 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertTrueM("1f shaft_is_synchronized", state.shaft_is_synchronized);
event_trigger_position_s position;
assertEqualsM("globalTriggerAngleOffset", 276, ec->globalTriggerAngleOffset);
2014-11-25 09:05:03 -08:00
findTriggerPosition(&position, 0 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertTriggerPosition(&position, 7, 46);
2014-11-25 09:05:03 -08:00
findTriggerPosition(&position, 180 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertTriggerPosition(&position, 13, 46);
2014-11-25 09:05:03 -08:00
findTriggerPosition(&position, 360 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertTriggerPosition(&position, 17, 46);
2014-11-25 09:05:03 -08:00
findTriggerPosition(&position, 444 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertTriggerPosition(&position, 0, 0);
2014-11-25 09:05:03 -08:00
findTriggerPosition(&position, 444.1 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertTriggerPosition(&position, 0, 0.1);
2014-11-25 09:05:03 -08:00
findTriggerPosition(&position, 445 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertTriggerPosition(&position, 0, 1);
2014-11-25 09:05:03 -08:00
findTriggerPosition(&position, 494 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertTriggerPosition(&position, 3, 0);
2014-11-25 09:05:03 -08:00
findTriggerPosition(&position, 719 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertTriggerPosition(&position, 7, 45);
ec->globalTriggerAngleOffset = 0;
2014-11-25 09:05:03 -08:00
findTriggerPosition(&position, 0 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertTriggerPosition(&position, 0, 0);
ec->globalTriggerAngleOffset = 10;
2014-11-25 09:05:03 -08:00
findTriggerPosition(&position, 0 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertTriggerPosition(&position, 0, 10);
2014-11-25 09:05:03 -08:00
findTriggerPosition(&position, -10 PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertTriggerPosition(&position, 0, 0);
}
static void testTriggerDecoder2(const char *msg, engine_type_e type, int synchPointIndex, float channel1duty, float channel2duty) {
printf("*************************************************** %s\r\n", msg);
2014-10-31 13:03:07 -07:00
EngineTestHelper eth(type);
engine_configuration_s *ec = eth.ec;
2014-08-29 07:52:33 -07:00
initSpeedDensity(ec);
2014-11-24 13:03:32 -08:00
trigger_shape_s *t = &eth.engine.triggerShape;
2014-08-29 07:52:33 -07:00
2014-11-24 12:06:11 -08:00
assertEqualsM("synchPointIndex", synchPointIndex, t->getTriggerShapeSynchPointIndex());
assertEqualsM("channel1duty", channel1duty, t->dutyCycle[0]);
assertEqualsM("channel2duty", channel2duty, t->dutyCycle[1]);
2014-08-29 07:52:33 -07:00
}
2014-12-16 17:04:36 -08:00
static void testTriggerDecoder3(const char *msg, engine_type_e type, int synchPointIndex, float channel1duty, float channel2duty, float expectedGap) {
printGapRatio = true;
testTriggerDecoder2(msg, type, synchPointIndex, channel1duty, channel2duty);
assertEqualsM("actual gap ratio", expectedGap, actualSynchGap);
printGapRatio = false;
}
2014-08-29 07:52:33 -07:00
void testGY6_139QMB(void) {
printf("*************************************************** testGY6_139QMB\r\n");
2014-10-31 13:03:07 -07:00
EngineTestHelper eth(GY6_139QMB);
engine_configuration_s *ec = eth.ec;
2014-11-26 12:04:04 -08:00
Engine *engine = &eth.engine;
engine_configuration_s *engineConfiguration = ec;
2014-08-29 07:52:33 -07:00
TriggerState state;
assertFalseM("shaft_is_synchronized", state.shaft_is_synchronized);
2014-11-24 13:03:32 -08:00
trigger_shape_s * shape = &eth.engine.triggerShape;
2014-08-29 07:52:33 -07:00
assertFalseM("shaft_is_synchronized", state.shaft_is_synchronized);
assertEquals(0, state.getCurrentIndex());
int now = 0;
2014-11-26 13:03:29 -08:00
state.decodeTriggerEvent(SHAFT_PRIMARY_UP, now++ PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertTrueM("shaft_is_synchronized", state.shaft_is_synchronized);
assertEquals(0, state.getCurrentIndex());
2014-11-26 13:03:29 -08:00
state.decodeTriggerEvent(SHAFT_PRIMARY_DOWN, now++ PASS_ENGINE_PARAMETER);
2014-08-29 07:52:33 -07:00
assertTrueM("shaft_is_synchronized", state.shaft_is_synchronized);
assertEquals(1, state.getCurrentIndex());
}
extern EventQueue schedulingQueue;
2014-10-17 13:05:16 -07:00
extern int mockTps;
2014-10-17 12:02:59 -07:00
static void testStartupFuelPumping(void) {
EngineTestHelper eth(FORD_INLINE_6_1995);
StartupFuelPumping sf;
Engine * engine = &eth.engine;
2014-11-24 19:03:19 -08:00
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
2014-10-17 12:02:59 -07:00
2014-11-11 13:05:09 -08:00
engine->rpmCalculator.mockRpm = 0;
2014-10-17 12:02:59 -07:00
engine->engineConfiguration->tpsMin = 0;
2014-10-17 13:05:16 -07:00
engine->engineConfiguration->tpsMax = 10;
mockTps = 6;
2014-11-24 19:03:19 -08:00
sf.update(PASS_ENGINE_PARAMETER_F);
2014-10-17 13:05:16 -07:00
assertEqualsM("pc#1", 1, sf.pumpsCounter);
mockTps = 3;
2014-11-24 19:03:19 -08:00
sf.update(PASS_ENGINE_PARAMETER_F);
2014-10-17 13:05:16 -07:00
assertEqualsM("pc#2", 1, sf.pumpsCounter);
2014-11-24 19:03:19 -08:00
sf.update(PASS_ENGINE_PARAMETER_F);
2014-10-17 13:05:16 -07:00
assertEqualsM("pc#3", 1, sf.pumpsCounter);
2014-10-17 12:02:59 -07:00
2014-11-11 13:05:09 -08:00
engine->rpmCalculator.mockRpm = 10;
2014-11-24 19:03:19 -08:00
sf.update(PASS_ENGINE_PARAMETER_F);
2014-10-17 13:05:16 -07:00
assertEqualsM("pc#4", 0, sf.pumpsCounter);
2014-10-17 12:02:59 -07:00
2014-10-17 13:05:16 -07:00
mockTps = 7;
2014-11-11 13:05:09 -08:00
engine->rpmCalculator.mockRpm = 0;
2014-11-24 19:03:19 -08:00
sf.update(PASS_ENGINE_PARAMETER_F);
2014-10-17 13:05:16 -07:00
assertEqualsM("pc#5", 1, sf.pumpsCounter);
mockTps = 3;
2014-11-24 19:03:19 -08:00
sf.update(PASS_ENGINE_PARAMETER_F);
2014-10-17 13:05:16 -07:00
assertEqualsM("pc#6", 1, sf.pumpsCounter);
mockTps = 7;
2014-11-24 19:03:19 -08:00
sf.update(PASS_ENGINE_PARAMETER_F);
2014-10-17 13:05:16 -07:00
assertEqualsM("pc#7", 2, sf.pumpsCounter);
2014-10-17 12:02:59 -07:00
}
2014-08-29 07:52:33 -07:00
static void testRpmCalculator(void) {
printf("*************************************************** testRpmCalculator\r\n");
EngineTestHelper eth(FORD_INLINE_6_1995);
2014-11-07 08:08:15 -08:00
assertEquals(720, eth.engine.engineConfiguration->engineCycle);
assertEquals(720, eth.ec->engineCycle);
2014-10-02 21:02:57 -07:00
efiAssertVoid(eth.engine.engineConfiguration!=NULL, "null config in engine");
2014-10-02 11:03:28 -07:00
initThermistors(&eth.engine);
2014-11-25 08:04:15 -08:00
Engine *engine = &eth.engine;
engine_configuration_s *engineConfiguration = &eth.persistentConfig.engineConfiguration;
2014-08-29 07:52:33 -07:00
engine_configuration2_s *ec2 = &eth.ec2;
2014-11-25 08:04:15 -08:00
engineConfiguration->triggerConfig.customTotalToothCount = 8;
engineConfiguration->globalFuelCorrection = 3;
2014-08-29 07:52:33 -07:00
eth.initTriggerShapeAndRpmCalculator();
2014-10-02 21:02:57 -07:00
// this is a very dirty and sad hack. todo: eliminate
2014-11-07 18:03:15 -08:00
// engine.engineConfiguration = eth.engine.engineConfiguration;
eth.engine.engineConfiguration->injectorLag = 0.0;
2014-11-03 18:03:13 -08:00
2014-08-29 07:52:33 -07:00
timeNow = 0;
2014-12-03 14:03:09 -08:00
assertEquals(0, eth.engine.rpmCalculator.rpm(PASS_ENGINE_PARAMETER_F));
2014-08-29 07:52:33 -07:00
eth.fireTriggerEvents();
2014-12-03 14:03:09 -08:00
assertEqualsM("RPM", 1500, eth.engine.rpmCalculator.rpm(PASS_ENGINE_PARAMETER_F));
2014-08-29 07:52:33 -07:00
assertEqualsM("index #1", 15, eth.triggerCentral.triggerState.getCurrentIndex());
static MainTriggerCallback triggerCallbackInstance;
triggerCallbackInstance.init(&eth.engine, ec2);
2014-11-24 18:03:34 -08:00
eth.triggerCentral.addEventListener(mainTriggerCallback, "main loop", &eth.engine);
2014-11-07 18:03:15 -08:00
// engine.rpmCalculator = &eth.rpmState;
2014-11-25 08:04:15 -08:00
prepareTimingMap(PASS_ENGINE_PARAMETER_F);
2014-08-29 07:52:33 -07:00
timeNow += 5000; // 5ms
2014-11-24 18:03:34 -08:00
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP, &eth.engine, eth.ec);
2014-08-29 07:52:33 -07:00
assertEqualsM("index #2", 0, eth.triggerCentral.triggerState.getCurrentIndex());
2014-11-07 18:03:15 -08:00
assertEqualsM("queue size", 6, schedulingQueue.size());
2014-11-07 22:05:46 -08:00
assertEqualsM("ev 1", 246444, schedulingQueue.getForUnitText(0)->momentX);
assertEqualsM("ev 2", 245944, schedulingQueue.getForUnitText(1)->momentX);
2014-08-29 07:52:33 -07:00
schedulingQueue.clear();
timeNow += 5000;
2014-11-24 18:03:34 -08:00
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN, &eth.engine, eth.ec);
2014-08-29 07:52:33 -07:00
timeNow += 5000; // 5ms
2014-11-24 18:03:34 -08:00
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP, &eth.engine, eth.ec);
2014-08-29 07:52:33 -07:00
timeNow += 5000;
2014-11-24 18:03:34 -08:00
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN, &eth.engine, eth.ec);
2014-08-29 07:52:33 -07:00
assertEqualsM("index #3", 3, eth.triggerCentral.triggerState.getCurrentIndex());
assertEqualsM("queue size 3", 6, schedulingQueue.size());
2014-11-07 22:05:46 -08:00
assertEqualsM("ev 3", 259777, schedulingQueue.getForUnitText(0)->momentX);
assertEquals(259277, schedulingQueue.getForUnitText(1)->momentX);
2014-11-29 21:03:06 -08:00
assertEqualsM2("ev 5", 261362, schedulingQueue.getForUnitText(2)->momentX, 2);
2014-11-07 22:05:46 -08:00
assertEqualsM("3/3", 258333, schedulingQueue.getForUnitText(3)->momentX);
2014-08-29 07:52:33 -07:00
schedulingQueue.clear();
timeNow += 5000;
2014-11-24 18:03:34 -08:00
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN, &eth.engine, eth.ec);
2014-08-29 07:52:33 -07:00
timeNow += 5000; // 5ms
2014-11-24 18:03:34 -08:00
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP, &eth.engine, eth.ec);
2014-08-29 07:52:33 -07:00
timeNow += 5000; // 5ms
2014-11-24 18:03:34 -08:00
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP, &eth.engine, eth.ec);
2014-08-29 07:52:33 -07:00
assertEqualsM("index #4", 6, eth.triggerCentral.triggerState.getCurrentIndex());
assertEqualsM("queue size 4", 6, schedulingQueue.size());
2014-11-07 22:05:46 -08:00
assertEqualsM("4/0", 273111, schedulingQueue.getForUnitText(0)->momentX);
2014-08-29 07:52:33 -07:00
schedulingQueue.clear();
timeNow += 5000;
2014-11-24 18:03:34 -08:00
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN, &eth.engine, eth.ec);
2014-11-07 18:03:15 -08:00
assertEqualsM("queue size 5", 0, schedulingQueue.size());
// assertEqualsM("5/1", 284500, schedulingQueue.getForUnitText(0)->momentUs);
2014-08-29 07:52:33 -07:00
schedulingQueue.clear();
timeNow += 5000; // 5ms
2014-11-24 18:03:34 -08:00
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP, &eth.engine, eth.ec);
2014-11-07 18:03:15 -08:00
assertEqualsM("queue size 6", 6, schedulingQueue.size());
2014-11-07 22:05:46 -08:00
assertEqualsM("6/0", 286444, schedulingQueue.getForUnitText(0)->momentX);
assertEqualsM("6/1", 285944, schedulingQueue.getForUnitText(1)->momentX);
2014-11-29 21:03:06 -08:00
assertEqualsM2("6/2", 288029, schedulingQueue.getForUnitText(2)->momentX, 1);
2014-08-29 07:52:33 -07:00
schedulingQueue.clear();
timeNow += 5000;
2014-11-24 18:03:34 -08:00
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN, &eth.engine, eth.ec);
2014-08-29 07:52:33 -07:00
assertEqualsM("queue size 7", 0, schedulingQueue.size());
schedulingQueue.clear();
timeNow += 5000; // 5ms
2014-11-24 18:03:34 -08:00
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP, &eth.engine, eth.ec);
2014-08-29 07:52:33 -07:00
assertEqualsM("queue size 8", 6, schedulingQueue.size());
2014-11-07 22:05:46 -08:00
assertEqualsM("8/0", 299777, schedulingQueue.getForUnitText(0)->momentX);
assertEqualsM("8/1", 299277, schedulingQueue.getForUnitText(1)->momentX);
2014-11-29 21:03:06 -08:00
assertEqualsM2("8/2", 301362, schedulingQueue.getForUnitText(2)->momentX, 1);
2014-11-07 22:05:46 -08:00
assertEqualsM("8/3", 298333, schedulingQueue.getForUnitText(3)->momentX);
2014-08-29 07:52:33 -07:00
schedulingQueue.clear();
timeNow += 5000;
2014-11-24 18:03:34 -08:00
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_DOWN, &eth.engine, eth.ec);
2014-08-29 07:52:33 -07:00
assertEqualsM("queue size 9", 0, schedulingQueue.size());
schedulingQueue.clear();
timeNow += 5000; // 5ms
2014-11-24 18:03:34 -08:00
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP, &eth.engine, eth.ec);
2014-08-29 07:52:33 -07:00
assertEqualsM("queue size 10", 0, schedulingQueue.size());
schedulingQueue.clear();
}
void testTriggerDecoder(void) {
printf("*************************************************** testTriggerDecoder\r\n");
2014-11-24 13:03:32 -08:00
Engine engine;
trigger_shape_s * s = &engine.triggerShape;
2014-11-24 12:06:11 -08:00
2014-08-29 07:52:33 -07:00
2014-11-24 12:06:11 -08:00
initializeSkippedToothTriggerShapeExt(s, 2, 0, FOUR_STROKE_CAM_SENSOR);
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);
2014-08-29 07:52:33 -07:00
testDodgeNeonDecoder();
testTriggerDecoder2("dodge neon", DODGE_NEON_1995, 8, 0.4931, 0.2070);
testFordAspire();
// lame duty cycle implementation!
2014-09-11 18:02:50 -07:00
testTriggerDecoder2("ford aspire", FORD_ASPIRE_1996, 4, 0.5, 0.3841);
2014-08-29 07:52:33 -07:00
test1995FordInline6TriggerDecoder();
testMazdaMianaNbDecoder();
testGY6_139QMB();
testTriggerDecoder2("testFordEscortGt", FORD_ESCORT_GT, 0, 0.6280, 0);
testTriggerDecoder2("testMiniCooper", MINI_COOPER_R50, 121, 0.5222, 0.4959);
testTriggerDecoder2("testRoverV8", ROVER_V8, 0, 0.4861, 0);
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, 10, 0.8146, 0.5);
testTriggerDecoder2("testAccordCdDip", HONDA_ACCORD_CD_DIP, 27, 0.5000, 0.5000);
testTriggerDecoder2("testMitsu", MITSU_4G93, 3, 0.3750, 0.3889);
// testTriggerDecoder2("miata 1990", MIATA_1990, 0, 0.6280, 0.0);
2014-12-16 18:05:03 -08: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);
2014-08-29 07:52:33 -07:00
2014-12-16 18:05:03 -08:00
testTriggerDecoder3("neon NGC", DODGE_NEON_2003, 5, 0.4861, 0.0, CHRYSLER_NGC_GAP);
2014-10-01 18:03:03 -07:00
2014-08-29 07:52:33 -07:00
testMazda323();
testRpmCalculator();
2014-10-17 12:02:59 -07:00
testStartupFuelPumping();
2014-08-29 07:52:33 -07:00
}