From 7b36fc951f5bbdbca98a202058a4cb85ba834877 Mon Sep 17 00:00:00 2001 From: rusefi Date: Mon, 27 May 2019 14:21:12 -0400 Subject: [PATCH] messing with TPS mocking --- firmware/controllers/sensors/tps.cpp | 26 ++++++++++++++++------- firmware/controllers/sensors/tps.h | 3 ++- unit_tests/tests/test_fuelCut.cpp | 4 ++-- unit_tests/tests/test_idle_controller.cpp | 6 +++--- unit_tests/tests/test_trigger_decoder.cpp | 10 ++++----- 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/firmware/controllers/sensors/tps.cpp b/firmware/controllers/sensors/tps.cpp index c5656d094a..2017fa6fe3 100644 --- a/firmware/controllers/sensors/tps.cpp +++ b/firmware/controllers/sensors/tps.cpp @@ -12,7 +12,9 @@ EXTERN_ENGINE; #if !EFI_PROD_CODE - static int mockTps; + // for historical reasons we have options to mock TPS on different layers :( + static int mockTpsAdcValue; + static float mockTpsValue = NAN; #endif /* EFI_PROD_CODE */ /** @@ -21,16 +23,19 @@ EXTERN_ENGINE; */ percent_t mockPedalPosition = MOCK_UNDEFINED; +#if !EFI_PROD_CODE /** * this allows unit tests to simulate TPS position */ -void setMockTpsPosition(percent_t tpsPosition) { - UNUSED(tpsPosition); -#if !EFI_PROD_CODE - mockTps = TPS_TS_CONVERSION * tpsPosition; -#endif +void setMockTpsAdc(percent_t tpsPosition) { + mockTpsAdcValue = TPS_TS_CONVERSION * tpsPosition; } +void setMockTpsValue(percent_t tpsPosition) { + mockTpsValue = tpsPosition; +} +#endif /* EFI_PROD_CODE */ + void setMockPedalPosition(percent_t value) { mockPedalPosition = value; } @@ -115,8 +120,8 @@ float getTPSVoltage(DECLARE_ENGINE_PARAMETER_SIGNATURE) { */ int getTPS12bitAdc(DECLARE_ENGINE_PARAMETER_SIGNATURE) { #if !EFI_PROD_CODE - if (mockTps != MOCK_UNDEFINED) { - return mockTps; + if (mockTpsAdcValue != MOCK_UNDEFINED) { + return mockTpsAdcValue; } #endif if (engineConfiguration->tps1_1AdcChannel == EFI_ADC_NONE) @@ -188,6 +193,11 @@ bool hasTpsSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) { } percent_t getTPS(DECLARE_ENGINE_PARAMETER_SIGNATURE) { +#if !EFI_PROD_CODE + if (!cisnan(mockTpsValue)) { + return mockTpsValue; + } +#endif /* EFI_PROD_CODE */ if (!hasTpsSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) return NO_TPS_MAGIC_VALUE; // todo: if (config->isDualTps) diff --git a/firmware/controllers/sensors/tps.h b/firmware/controllers/sensors/tps.h index 4f13849787..ef76dd2c1d 100644 --- a/firmware/controllers/sensors/tps.h +++ b/firmware/controllers/sensors/tps.h @@ -31,7 +31,8 @@ int getTPS12bitAdc(DECLARE_ENGINE_PARAMETER_SIGNATURE); float getTPSVoltage(DECLARE_ENGINE_PARAMETER_SIGNATURE); percent_t getTpsValue(int adc DECLARE_ENGINE_PARAMETER_SUFFIX); void setBosch0280750009(DECLARE_ENGINE_PARAMETER_SIGNATURE); -void setMockTpsPosition(percent_t tpsPosition); +void setMockTpsAdc(percent_t tpsPosition); +void setMockTpsValue(percent_t tpsPosition); void setMockPedalPosition(percent_t value); void grabTPSIsClosed(); void grabTPSIsWideOpen(); diff --git a/unit_tests/tests/test_fuelCut.cpp b/unit_tests/tests/test_fuelCut.cpp index ca5aed654d..798514677a 100644 --- a/unit_tests/tests/test_fuelCut.cpp +++ b/unit_tests/tests/test_fuelCut.cpp @@ -34,7 +34,7 @@ TEST(fuelCut, coasting) { // mock CLT - just above threshold ('hot engine') float hotClt = engine->sensors.clt = engineConfiguration->coastingFuelCutClt + 1; // mock TPS - throttle is opened - setMockTpsPosition(6); + setMockTpsAdc(6); // set 'running' RPM - just above RpmHigh threshold engine->rpmCalculator.mockRpm = engineConfiguration->coastingFuelCutRpmHigh + 1; // 'advance' time (amount doesn't matter) @@ -52,7 +52,7 @@ TEST(fuelCut, coasting) { assertEqualsM("inj dur#1 norm", normalInjDuration, ENGINE(injectionDuration)); // 'releasing' the throttle - setMockTpsPosition(0); + setMockTpsAdc(0); eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE); // Fuel cut-off is enabled now diff --git a/unit_tests/tests/test_idle_controller.cpp b/unit_tests/tests/test_idle_controller.cpp index 5a2838ad8b..5238a2caa1 100644 --- a/unit_tests/tests/test_idle_controller.cpp +++ b/unit_tests/tests/test_idle_controller.cpp @@ -101,7 +101,7 @@ TEST(idle, timingPid) { engineConfiguration->tpsMin = 0; engineConfiguration->tpsMax = 100; engineConfiguration->bc.idlePidDeactivationTpsThreshold = 10; - setMockTpsPosition(0); + setMockTpsAdc(0); // disable temperature sensors eth.engine.sensors.clt = NAN; @@ -135,12 +135,12 @@ TEST(idle, timingPid) { ASSERT_FLOAT_EQ(-5.75f, corr) << "getAdvanceCorrections#5"; // check if PID correction is disabled in running mode (tps > threshold): - setMockTpsPosition(engineConfiguration->bc.idlePidDeactivationTpsThreshold + 1); + setMockTpsAdc(engineConfiguration->bc.idlePidDeactivationTpsThreshold + 1); corr = getAdvanceCorrections(idleRpmTarget PASS_ENGINE_PARAMETER_SUFFIX); ASSERT_EQ(0, corr) << "getAdvanceCorrections#6"; // check if PID correction is interpolated for transient idle-running TPS positions - setMockTpsPosition(engineConfiguration->bc.idlePidDeactivationTpsThreshold / 2); + setMockTpsAdc(engineConfiguration->bc.idlePidDeactivationTpsThreshold / 2); corr = getAdvanceCorrections(baseTestRpm PASS_ENGINE_PARAMETER_SUFFIX); ASSERT_FLOAT_EQ(-5.0f, corr) << "getAdvanceCorrections#7"; diff --git a/unit_tests/tests/test_trigger_decoder.cpp b/unit_tests/tests/test_trigger_decoder.cpp index 516684fe68..eadfa93491 100644 --- a/unit_tests/tests/test_trigger_decoder.cpp +++ b/unit_tests/tests/test_trigger_decoder.cpp @@ -246,11 +246,11 @@ TEST(misc, testStartupFuelPumping) { engineConfiguration->tpsMin = 0; engineConfiguration->tpsMax = 10; - setMockTpsPosition(6); + setMockTpsAdc(6); sf.update(PASS_ENGINE_PARAMETER_SIGNATURE); ASSERT_EQ( 1, sf.pumpsCounter) << "pc#1"; - setMockTpsPosition(3); + setMockTpsAdc(3); sf.update(PASS_ENGINE_PARAMETER_SIGNATURE); ASSERT_EQ( 1, sf.pumpsCounter) << "pumpsCounter#2"; @@ -261,16 +261,16 @@ TEST(misc, testStartupFuelPumping) { sf.update(PASS_ENGINE_PARAMETER_SIGNATURE); ASSERT_EQ( 0, sf.pumpsCounter) << "pc#4"; - setMockTpsPosition(7); + setMockTpsAdc(7); engine->rpmCalculator.mockRpm = 0; sf.update(PASS_ENGINE_PARAMETER_SIGNATURE); ASSERT_EQ( 1, sf.pumpsCounter) << "pc#5"; - setMockTpsPosition(3); + setMockTpsAdc(3); sf.update(PASS_ENGINE_PARAMETER_SIGNATURE); ASSERT_EQ( 1, sf.pumpsCounter) << "pc#6"; - setMockTpsPosition(7); + setMockTpsAdc(7); sf.update(PASS_ENGINE_PARAMETER_SIGNATURE); ASSERT_EQ( 2, sf.pumpsCounter) << "pc#7"; }