diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 6031bdfd62..6db732a83a 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -210,7 +210,7 @@ static void printSensors(Logging *log, bool fileFormat) { } #if EFI_ANALOG_SENSORS if (hasMapSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) { - reportSensorF(log, fileFormat, "MAP", "kPa", getMap(), 2); + reportSensorF(log, fileFormat, "MAP", "kPa", getMap(PASS_ENGINE_PARAMETER_SIGNATURE), 2); // reportSensorF(log, fileFormat, "map_r", "V", getRawMap(), 2); } #endif /* EFI_ANALOG_SENSORS */ @@ -318,7 +318,7 @@ static void printSensors(Logging *log, bool fileFormat) { reportSensorF(log, fileFormat, "f: el delta", "v", engine->engineLoadAccelEnrichment.getMaxDelta(), 2); if (hasMapSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) { - reportSensorF(log, fileFormat, "f: el fuel", "v", engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_SIGNATURE) * 100 / getMap(), 2); + reportSensorF(log, fileFormat, "f: el fuel", "v", engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_SIGNATURE) * 100 / getMap(PASS_ENGINE_PARAMETER_SIGNATURE), 2); } reportSensorF(log, fileFormat, GAUGE_NAME_FUEL_INJ_DUTY, "%", getInjectorDutyCycle(rpm PASS_ENGINE_PARAMETER_SUFFIX), 2); @@ -704,7 +704,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ tsOutputChannels->accelerationY = engine->sensors.accelerometer.y; if (hasMapSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) { - float mapValue = getMap(); + float mapValue = getMap(PASS_ENGINE_PARAMETER_SIGNATURE); tsOutputChannels->veValue = engine->engineState.currentBaroCorrectedVE * PERCENT_MULT; // todo: bug here? target afr could work based on real MAF? tsOutputChannels->currentTargetAfr = afrMap.getValue(rpm, mapValue); @@ -874,7 +874,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ tsOutputChannels->tpsAccelFuel = engine->engineState.tpsAccelEnrich; // engine load acceleration if (hasMapSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) { - tsOutputChannels->engineLoadAccelExtra = engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_SIGNATURE) * 100 / getMap(); + tsOutputChannels->engineLoadAccelExtra = engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_SIGNATURE) * 100 / getMap(PASS_ENGINE_PARAMETER_SIGNATURE); } tsOutputChannels->engineLoadDelta = engine->engineLoadAccelEnrichment.getMaxDelta(); diff --git a/firmware/controllers/actuators/lcd_controller.cpp b/firmware/controllers/actuators/lcd_controller.cpp index 8dfb86b010..06373e3b88 100644 --- a/firmware/controllers/actuators/lcd_controller.cpp +++ b/firmware/controllers/actuators/lcd_controller.cpp @@ -285,7 +285,7 @@ static void showLine(lcd_line_e line, int screenY) { return; case LL_MAP: if (hasMapSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) { - lcdPrintf("MAP %.2f", getMap()); + lcdPrintf("MAP %.2f", getMap(PASS_ENGINE_PARAMETER_SIGNATURE)); } else { lcdPrintf("MAP: none"); } diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 15b8f0690b..88ade9af23 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -358,6 +358,12 @@ public: int globalSparkIdCoutner = 0; +#if !EFI_PROD_CODE + float mockMapValue = 0; + // for historical reasons we have options to mock TPS on different layers :( + int mockTpsAdcValue = 0; + float mockTpsValue = NAN; +#endif int getGlobalConfigurationVersion(void) const; /** diff --git a/firmware/controllers/algo/engine2.cpp b/firmware/controllers/algo/engine2.cpp index 1ff7bb8d58..5c29fe843a 100644 --- a/firmware/controllers/algo/engine2.cpp +++ b/firmware/controllers/algo/engine2.cpp @@ -210,7 +210,7 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) { if (engineConfiguration->fuelAlgorithm == LM_SPEED_DENSITY) { float tps = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE); updateTChargeK(rpm, tps PASS_ENGINE_PARAMETER_SUFFIX); - float map = getMap(); + float map = getMap(PASS_ENGINE_PARAMETER_SIGNATURE); /** * *0.01 because of https://sourceforge.net/p/rusefi/tickets/153/ diff --git a/firmware/controllers/algo/fuel_math.cpp b/firmware/controllers/algo/fuel_math.cpp index 5e645489ea..1c3779fbeb 100644 --- a/firmware/controllers/algo/fuel_math.cpp +++ b/firmware/controllers/algo/fuel_math.cpp @@ -83,7 +83,7 @@ floatms_t getBaseFuel(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) { floatms_t baseFuel; if (CONFIG(fuelAlgorithm) == LM_SPEED_DENSITY) { - baseFuel = getSpeedDensityFuel(getMap() PASS_ENGINE_PARAMETER_SUFFIX); + baseFuel = getSpeedDensityFuel(getMap(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX); efiAssert(CUSTOM_ERR_ASSERT, !cisnan(baseFuel), "NaN sd baseFuel", 0); } else if (engineConfiguration->fuelAlgorithm == LM_REAL_MAF) { float maf = getRealMaf(PASS_ENGINE_PARAMETER_SIGNATURE) + engine->engineLoadAccelEnrichment.getEngineLoadEnrichment(PASS_ENGINE_PARAMETER_SIGNATURE); @@ -268,7 +268,7 @@ float getFuelCutOffCorrection(efitick_t nowNt, int rpm DECLARE_ENGINE_PARAMETER_ // coasting fuel cut-off correction if (CONFIGB(coastingFuelCutEnabled)) { percent_t tpsPos = getTPS(PASS_ENGINE_PARAMETER_SIGNATURE); - float map = getMap(); + float map = getMap(PASS_ENGINE_PARAMETER_SIGNATURE); // gather events bool mapDeactivate = (map >= CONFIG(coastingFuelCutMap)); diff --git a/firmware/controllers/core/fsio_impl.cpp b/firmware/controllers/core/fsio_impl.cpp index 973ba174b2..46781713e8 100644 --- a/firmware/controllers/core/fsio_impl.cpp +++ b/firmware/controllers/core/fsio_impl.cpp @@ -125,7 +125,7 @@ float getEngineValue(le_action_e action DECLARE_ENGINE_PARAMETER_SUFFIX) { case LE_METHOD_MAF: return getMaf(PASS_ENGINE_PARAMETER_SIGNATURE); case LE_METHOD_MAP: - return getMap(); + return getMap(PASS_ENGINE_PARAMETER_SIGNATURE); case LE_METHOD_INTAKE_VVT: case LE_METHOD_EXHAUST_VVT: return engine->triggerCentral.vvtPosition; diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index cde515e4b4..0808313779 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -64,7 +64,7 @@ float getEngineLoadT(DECLARE_ENGINE_PARAMETER_SIGNATURE) { case LM_SPEED_DENSITY: // SD engine load is used for timing lookup but not for fuel calculation case LM_MAP: - return getMap(); + return getMap(PASS_ENGINE_PARAMETER_SIGNATURE); case LM_ALPHA_N: return getTPS(PASS_ENGINE_PARAMETER_SIGNATURE); case LM_REAL_MAF: { diff --git a/firmware/controllers/obd2.cpp b/firmware/controllers/obd2.cpp index b3eb3b1daa..50a18ceadb 100644 --- a/firmware/controllers/obd2.cpp +++ b/firmware/controllers/obd2.cpp @@ -146,7 +146,7 @@ static void handleGetDataRequest(CANRxFrame *rx) { break; case PID_INTAKE_MAP: scheduleMsg(&logger, "Got MAP request"); - obdSendValue(1, pid, 1, getMap()); + obdSendValue(1, pid, 1, getMap(PASS_ENGINE_PARAMETER_SIGNATURE)); break; case PID_RPM: scheduleMsg(&logger, "Got RPM request"); diff --git a/firmware/controllers/sensors/map.h b/firmware/controllers/sensors/map.h index f3987e6fdb..1ce72b20c8 100644 --- a/firmware/controllers/sensors/map.h +++ b/firmware/controllers/sensors/map.h @@ -22,7 +22,7 @@ bool hasMapSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE); /** * @return MAP value averaged within a window of measurement */ -float getMap(void); +float getMap(DECLARE_ENGINE_PARAMETER_SIGNATURE); float getMapByVoltage(float voltage DECLARE_ENGINE_PARAMETER_SUFFIX); float decodePressure(float voltage, air_pressure_sensor_config_s * mapConfig DECLARE_ENGINE_PARAMETER_SUFFIX); float validateMap(float mapKPa DECLARE_ENGINE_PARAMETER_SUFFIX); diff --git a/firmware/controllers/sensors/tps.cpp b/firmware/controllers/sensors/tps.cpp index 2017fa6fe3..9ed925733c 100644 --- a/firmware/controllers/sensors/tps.cpp +++ b/firmware/controllers/sensors/tps.cpp @@ -11,12 +11,6 @@ EXTERN_ENGINE; -#if !EFI_PROD_CODE - // for historical reasons we have options to mock TPS on different layers :( - static int mockTpsAdcValue; - static float mockTpsValue = NAN; -#endif /* EFI_PROD_CODE */ - /** * set mock_pedal_position X * See also directPwmValue @@ -27,16 +21,16 @@ percent_t mockPedalPosition = MOCK_UNDEFINED; /** * this allows unit tests to simulate TPS position */ -void setMockTpsAdc(percent_t tpsPosition) { - mockTpsAdcValue = TPS_TS_CONVERSION * tpsPosition; +void setMockTpsAdc(percent_t tpsPosition DECLARE_ENGINE_PARAMETER_SUFFIX) { + engine->mockTpsAdcValue = TPS_TS_CONVERSION * tpsPosition; } -void setMockTpsValue(percent_t tpsPosition) { - mockTpsValue = tpsPosition; +void setMockTpsValue(percent_t tpsPosition DECLARE_ENGINE_PARAMETER_SUFFIX) { + engine->mockTpsValue = tpsPosition; } #endif /* EFI_PROD_CODE */ -void setMockPedalPosition(percent_t value) { +void setMockPedalPosition(percent_t value DECLARE_ENGINE_PARAMETER_SUFFIX) { mockPedalPosition = value; } @@ -120,8 +114,8 @@ float getTPSVoltage(DECLARE_ENGINE_PARAMETER_SIGNATURE) { */ int getTPS12bitAdc(DECLARE_ENGINE_PARAMETER_SIGNATURE) { #if !EFI_PROD_CODE - if (mockTpsAdcValue != MOCK_UNDEFINED) { - return mockTpsAdcValue; + if (engine->mockTpsAdcValue != MOCK_UNDEFINED) { + return engine->mockTpsAdcValue; } #endif if (engineConfiguration->tps1_1AdcChannel == EFI_ADC_NONE) @@ -194,8 +188,8 @@ bool hasTpsSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) { percent_t getTPS(DECLARE_ENGINE_PARAMETER_SIGNATURE) { #if !EFI_PROD_CODE - if (!cisnan(mockTpsValue)) { - return mockTpsValue; + if (!cisnan(engine->mockTpsValue)) { + return engine->mockTpsValue; } #endif /* EFI_PROD_CODE */ if (!hasTpsSensor(PASS_ENGINE_PARAMETER_SIGNATURE)) diff --git a/firmware/controllers/sensors/tps.h b/firmware/controllers/sensors/tps.h index ef76dd2c1d..18ea24042c 100644 --- a/firmware/controllers/sensors/tps.h +++ b/firmware/controllers/sensors/tps.h @@ -31,9 +31,9 @@ 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 setMockTpsAdc(percent_t tpsPosition); -void setMockTpsValue(percent_t tpsPosition); -void setMockPedalPosition(percent_t value); +void setMockTpsAdc(percent_t tpsPosition DECLARE_ENGINE_PARAMETER_SUFFIX); +void setMockTpsValue(percent_t tpsPosition DECLARE_ENGINE_PARAMETER_SUFFIX); +void setMockPedalPosition(percent_t value DECLARE_ENGINE_PARAMETER_SUFFIX); void grabTPSIsClosed(); void grabTPSIsWideOpen(); void grabPedalIsUp(); diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index 6c676fedc3..2480a49bb6 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -480,7 +480,7 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t trgEventIndex D bool limitedFuel = rpm > CONFIG(rpmHardLimit); if (CONFIG(boostCutPressure) !=0) { - if (getMap() > CONFIG(boostCutPressure)) { + if (getMap(PASS_ENGINE_PARAMETER_SIGNATURE) > CONFIG(boostCutPressure)) { limitedSpark = true; limitedFuel = true; } diff --git a/unit_tests/tests/test_engine_math.cpp b/unit_tests/tests/test_engine_math.cpp index 0864e84884..32a5575dfb 100644 --- a/unit_tests/tests/test_engine_math.cpp +++ b/unit_tests/tests/test_engine_math.cpp @@ -7,7 +7,7 @@ #include "global.h" #include "engine_math.h" -#include "engine_configuration.h" +#include "engine.h" #include "map.h" #include "speed_density.h" #include "engine_test_helper.h" @@ -107,8 +107,6 @@ TEST(misc, testMafLookup) { ASSERT_EQ( 738, engine->mafDecodingLookup[255]) << "@255"; } -float mockMapValue = 0; - -float getMap(void) { - return mockMapValue; +float getMap(DECLARE_ENGINE_PARAMETER_SIGNATURE) { + return engine->mockMapValue; } diff --git a/unit_tests/tests/test_fuelCut.cpp b/unit_tests/tests/test_fuelCut.cpp index 798514677a..128fa005bf 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 - setMockTpsAdc(6); + setMockTpsAdc(6 PASS_ENGINE_PARAMETER_SUFFIX); // 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 - setMockTpsAdc(0); + setMockTpsAdc(0 PASS_ENGINE_PARAMETER_SUFFIX); eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE); // Fuel cut-off is enabled now diff --git a/unit_tests/tests/test_fuel_map.cpp b/unit_tests/tests/test_fuel_map.cpp index d2e9ea34e8..07ebd8c91f 100644 --- a/unit_tests/tests/test_fuel_map.cpp +++ b/unit_tests/tests/test_fuel_map.cpp @@ -224,7 +224,6 @@ TEST(misc, testPinHelper) { } extern fuel_Map3D_t veMap; -extern float mockMapValue; TEST(fuel, testTpsBasedVeDefect799) { @@ -251,8 +250,8 @@ TEST(fuel, testTpsBasedVeDefect799) { setLinearCurve(CONFIG(ignitionTpsBins), IGN_TPS_COUNT, 0, 15, 1); - mockMapValue = 107; - setMockTpsValue(7); + engine->mockMapValue = 107; + setMockTpsValue(7 PASS_ENGINE_PARAMETER_SUFFIX); engine->engineState.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE); // we have a problem - we get value on the edge of the MAP axis, not middle of TPS axis diff --git a/unit_tests/tests/test_idle_controller.cpp b/unit_tests/tests/test_idle_controller.cpp index 5238a2caa1..2f6b8e02d0 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; - setMockTpsAdc(0); + setMockTpsAdc(0 PASS_ENGINE_PARAMETER_SUFFIX); // 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): - setMockTpsAdc(engineConfiguration->bc.idlePidDeactivationTpsThreshold + 1); + setMockTpsAdc(engineConfiguration->bc.idlePidDeactivationTpsThreshold + 1 PASS_ENGINE_PARAMETER_SUFFIX); 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 - setMockTpsAdc(engineConfiguration->bc.idlePidDeactivationTpsThreshold / 2); + setMockTpsAdc(engineConfiguration->bc.idlePidDeactivationTpsThreshold / 2 PASS_ENGINE_PARAMETER_SUFFIX); 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 eadfa93491..4e3a8cfa7e 100644 --- a/unit_tests/tests/test_trigger_decoder.cpp +++ b/unit_tests/tests/test_trigger_decoder.cpp @@ -31,7 +31,6 @@ #include "spark_logic.h" #include "trigger_universal.h" -extern float mockMapValue; extern float testMafValue; extern WarningCodeState unitTestWarningCodeState; extern bool printTriggerDebug; @@ -246,11 +245,11 @@ TEST(misc, testStartupFuelPumping) { engineConfiguration->tpsMin = 0; engineConfiguration->tpsMax = 10; - setMockTpsAdc(6); + setMockTpsAdc(6 PASS_ENGINE_PARAMETER_SUFFIX); sf.update(PASS_ENGINE_PARAMETER_SIGNATURE); ASSERT_EQ( 1, sf.pumpsCounter) << "pc#1"; - setMockTpsAdc(3); + setMockTpsAdc(3 PASS_ENGINE_PARAMETER_SUFFIX); sf.update(PASS_ENGINE_PARAMETER_SIGNATURE); ASSERT_EQ( 1, sf.pumpsCounter) << "pumpsCounter#2"; @@ -261,16 +260,16 @@ TEST(misc, testStartupFuelPumping) { sf.update(PASS_ENGINE_PARAMETER_SIGNATURE); ASSERT_EQ( 0, sf.pumpsCounter) << "pc#4"; - setMockTpsAdc(7); + setMockTpsAdc(7 PASS_ENGINE_PARAMETER_SUFFIX); engine->rpmCalculator.mockRpm = 0; sf.update(PASS_ENGINE_PARAMETER_SIGNATURE); ASSERT_EQ( 1, sf.pumpsCounter) << "pc#5"; - setMockTpsAdc(3); + setMockTpsAdc(3 PASS_ENGINE_PARAMETER_SUFFIX); sf.update(PASS_ENGINE_PARAMETER_SIGNATURE); ASSERT_EQ( 1, sf.pumpsCounter) << "pc#6"; - setMockTpsAdc(7); + setMockTpsAdc(7 PASS_ENGINE_PARAMETER_SUFFIX); sf.update(PASS_ENGINE_PARAMETER_SIGNATURE); ASSERT_EQ( 2, sf.pumpsCounter) << "pc#7"; } @@ -931,7 +930,7 @@ void doTestFuelSchedulerBug299smallAndMedium(int startUpDelayMs) { eth.executeActions(); - mockMapValue = 0; + engine->mockMapValue = 0; testMafValue = 0; ASSERT_EQ( 1, unitTestWarningCodeState.recentWarnings.getCount()) << "warningCounter#testFuelSchedulerBug299smallAndMedium"; ASSERT_EQ(CUSTOM_OBD_SKIPPED_FUEL, unitTestWarningCodeState.recentWarnings.get(0));