From 74bd1d7e10017830b23e677529cc1cacb4cda925 Mon Sep 17 00:00:00 2001 From: rusefi Date: Mon, 23 Jul 2018 21:03:20 -0400 Subject: [PATCH] error code into angle validation --- firmware/controllers/algo/advance_map.cpp | 2 +- firmware/controllers/algo/obd_error_codes.h | 12 ++++++++++++ firmware/controllers/engine_controller.cpp | 2 +- firmware/controllers/math/engine_math.cpp | 14 +++++++------- firmware/controllers/math/engine_math.h | 6 +++--- firmware/controllers/trigger/spark_logic.cpp | 4 ++-- firmware/controllers/trigger/trigger_structure.cpp | 4 ++-- 7 files changed, 28 insertions(+), 16 deletions(-) diff --git a/firmware/controllers/algo/advance_map.cpp b/firmware/controllers/algo/advance_map.cpp index 7ba7f73f2d..aff54ade50 100644 --- a/firmware/controllers/algo/advance_map.cpp +++ b/firmware/controllers/algo/advance_map.cpp @@ -143,7 +143,7 @@ angle_t getAdvance(int rpm, float engineLoad DECLARE_ENGINE_PARAMETER_SUFFIX) { angle_t angle; if (ENGINE(rpmCalculator).isCranking(PASS_ENGINE_PARAMETER_SIGNATURE)) { angle = getCrankingAdvance(rpm, engineLoad PASS_ENGINE_PARAMETER_SUFFIX); - assertAngleRange(angle, "crAngle"); + assertAngleRange(angle, "crAngle", CUSTOM_ERR_6541); efiAssert(!cisnan(angle), "crAngleN", 0); if (CONFIG(useAdvanceCorrectionsForCranking)) angle += getAdvanceCorrections(rpm PASS_ENGINE_PARAMETER_SUFFIX); diff --git a/firmware/controllers/algo/obd_error_codes.h b/firmware/controllers/algo/obd_error_codes.h index 6a9ee6db14..01fcad66ee 100644 --- a/firmware/controllers/algo/obd_error_codes.h +++ b/firmware/controllers/algo/obd_error_codes.h @@ -1908,6 +1908,18 @@ typedef enum { CUSTOM_ERR_6548 = 6548, CUSTOM_ERR_6549 = 6549, + CUSTOM_ERR_6550 = 6550, + CUSTOM_ERR_6551 = 6551, + CUSTOM_ERR_6552 = 6552, + CUSTOM_ERR_6553 = 6553, + CUSTOM_ERR_6554 = 6554, + CUSTOM_ERR_6555 = 6555, + CUSTOM_ERR_6556 = 6556, + CUSTOM_ERR_6557 = 6557, + CUSTOM_ERR_6558 = 6557, + CUSTOM_ERR_6559 = 6559, + + // this is needed for proper enum size, this matters for malfunction_central Internal_ForceMyEnumIntSize_cranking_obd_code = ENUM_32_BITS, } obd_code_e; diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index bb9a5dcfe4..05143f5333 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -733,5 +733,5 @@ int getRusEfiVersion(void) { if (initBootloader() != 0) return 123; #endif /* EFI_BOOTLOADER_INCLUDE_CODE */ - return 20180617; + return 20180721; } diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index 1367b6e12e..a43e45433e 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -131,7 +131,7 @@ bool FuelSchedule::addFuelEventsForCylinder(int i DECLARE_ENGINE_PARAMETER_SUFF efiAssert(!cisnan(fuelMs), "NaN fuelMs", false); angle_t injectionDuration = MS2US(fuelMs) / oneDegreeUs; efiAssert(!cisnan(injectionDuration), "NaN injectionDuration", false); - assertAngleRange(injectionDuration, "injectionDuration_r"); + assertAngleRange(injectionDuration, "injectionDuration_r", CUSTOM_ERR_6542); floatus_t injectionOffset = ENGINE(engineState.injectionOffset); if (cisnan(injectionOffset)) { // injection offset map not ready - we are not ready to schedule fuel events @@ -139,7 +139,7 @@ bool FuelSchedule::addFuelEventsForCylinder(int i DECLARE_ENGINE_PARAMETER_SUFF } angle_t baseAngle = injectionOffset - injectionDuration; efiAssert(!cisnan(baseAngle), "NaN baseAngle", false); - assertAngleRange(baseAngle, "baseAngle_r"); + assertAngleRange(baseAngle, "baseAngle_r", CUSTOM_ERR_6554); int injectorIndex; @@ -159,7 +159,7 @@ bool FuelSchedule::addFuelEventsForCylinder(int i DECLARE_ENGINE_PARAMETER_SUFF bool isSimultanious = mode == IM_SIMULTANEOUS; - assertAngleRange(baseAngle, "addFbaseAngle"); + assertAngleRange(baseAngle, "addFbaseAngle", CUSTOM_ERR_6543); int cylindersCount = CONFIG(specs.cylindersCount); if (cylindersCount < 1) { @@ -206,7 +206,7 @@ bool FuelSchedule::addFuelEventsForCylinder(int i DECLARE_ENGINE_PARAMETER_SUFF } efiAssert(!cisnan(angle), "findAngle#3", false); - assertAngleRange(angle, "findAngle#a33"); + assertAngleRange(angle, "findAngle#a33", CUSTOM_ERR_6544); TRIGGER_SHAPE(findTriggerPosition(&ev->injectionStart, angle PASS_ENGINE_PARAMETER_SUFFIX)); #if EFI_UNIT_TEST || defined(__DOXYGEN__) printf("registerInjectionEvent angle=%.2f trgIndex=%d inj %d\r\n", angle, ev->injectionStart.eventIndex, injectorIndex); @@ -293,13 +293,13 @@ int TriggerShape::findAngleIndex(float target DECLARE_ENGINE_PARAMETER_SUFFIX) { void TriggerShape::findTriggerPosition(event_trigger_position_s *position, angle_t angleOffset DECLARE_ENGINE_PARAMETER_SUFFIX) { efiAssertVoid(!cisnan(angleOffset), "findAngle#1"); - assertAngleRange(angleOffset, "findAngle#a1"); + assertAngleRange(angleOffset, "findAngle#a1", CUSTOM_ERR_6545); efiAssertVoid(!cisnan(ENGINE(triggerCentral.triggerShape.tdcPosition)), "tdcPos#1") - assertAngleRange(ENGINE(triggerCentral.triggerShape.tdcPosition), "tdcPos#a1"); + assertAngleRange(ENGINE(triggerCentral.triggerShape.tdcPosition), "tdcPos#a1", CUSTOM_ERR_6546); efiAssertVoid(!cisnan(CONFIG(globalTriggerAngleOffset)), "tdcPos#2") - assertAngleRange(CONFIG(globalTriggerAngleOffset), "tdcPos#a2"); + assertAngleRange(CONFIG(globalTriggerAngleOffset), "tdcPos#a2", CUSTOM_ERR_6547); // convert engine cycle angle into trigger cycle angle angleOffset += tdcPosition(); diff --git a/firmware/controllers/math/engine_math.h b/firmware/controllers/math/engine_math.h index f1914dbcd6..fe00f63861 100644 --- a/firmware/controllers/math/engine_math.h +++ b/firmware/controllers/math/engine_math.h @@ -20,9 +20,9 @@ void setAlgorithm(engine_load_mode_e algo DECLARE_ENGINE_PARAMETER_SUFFIX); #if EFI_ENABLE_ASSERTS -#define assertAngleRange(angle, msg) if(angle > 10000000 || angle < -10000000) { firmwareError(ERROR_ANGLE_RANGE, "angle range %s %.2f", msg, angle);angle = 0;} +#define assertAngleRange(angle, msg, code) if(angle > 10000000 || angle < -10000000) { firmwareError(code, "angle range %s %.2f", msg, angle);angle = 0;} #else -#define assertAngleRange(angle, msg) {} +#define assertAngleRange(angle, msg, code) {} #endif void setFlatInjectorLag(float value DECLARE_ENGINE_PARAMETER_SUFFIX); @@ -38,7 +38,7 @@ void setFlatInjectorLag(float value DECLARE_ENGINE_PARAMETER_SUFFIX); firmwareError(CUSTOM_ERR_ANGLE, "angle NaN %s", msg); \ angle = 0; \ } \ - assertAngleRange(angle, msg); \ + assertAngleRange(angle, msg, CUSTOM_ERR_6548); \ float engineCycleDurationLocalCopy = ENGINE(engineCycle); \ /* todo: split this method into 'fixAngleUp' and 'fixAngleDown'*/ \ /* as a performance optimization?*/ \ diff --git a/firmware/controllers/trigger/spark_logic.cpp b/firmware/controllers/trigger/spark_logic.cpp index 2d8f301063..ed6ba93555 100644 --- a/firmware/controllers/trigger/spark_logic.cpp +++ b/firmware/controllers/trigger/spark_logic.cpp @@ -174,7 +174,7 @@ static ALWAYS_INLINE void handleSparkEvent(bool limitedSpark, uint32_t trgEventI */ float advance = iEvent->advance; efiAssertVoid(!cisnan(advance), "findAngle#4"); - assertAngleRange(advance, "findAngle#a5"); + assertAngleRange(advance, "findAngle#a5", CUSTOM_ERR_6549); TRIGGER_SHAPE(findTriggerPosition(&iEvent->sparkPosition, advance PASS_ENGINE_PARAMETER_SUFFIX)); #if EFI_UNIT_TEST || defined(__DOXYGEN__) @@ -249,7 +249,7 @@ void prepareIgnitionSchedule(IgnitionEvent *event DECLARE_ENGINE_PARAMETER_SUFFI angle_t a = localAdvance - dwellAngle; efiAssertVoid(!cisnan(a), "findAngle#5"); - assertAngleRange(a, "findAngle#a6"); + assertAngleRange(a, "findAngle#a6", CUSTOM_ERR_6550); TRIGGER_SHAPE(findTriggerPosition(&event->dwellPosition, a PASS_ENGINE_PARAMETER_SUFFIX)); #if FUEL_MATH_EXTREME_LOGGING || defined(__DOXYGEN__) diff --git a/firmware/controllers/trigger/trigger_structure.cpp b/firmware/controllers/trigger/trigger_structure.cpp index b036b1f0f1..f5851cc040 100644 --- a/firmware/controllers/trigger/trigger_structure.cpp +++ b/firmware/controllers/trigger/trigger_structure.cpp @@ -64,7 +64,7 @@ void TriggerShape::calculateTriggerSynchPoint(TriggerState *state DECLARE_ENGINE } float firstAngle = getAngle(triggerShapeSynchPointIndex); - assertAngleRange(triggerShapeSynchPointIndex, "firstAngle"); + assertAngleRange(triggerShapeSynchPointIndex, "firstAngle", CUSTOM_ERR_6551); int frontOnlyIndex = 0; @@ -76,7 +76,7 @@ void TriggerShape::calculateTriggerSynchPoint(TriggerState *state DECLARE_ENGINE eventAngles[1] = 0; frontOnlyIndexes[0] = 0; } else { - assertAngleRange(triggerShapeSynchPointIndex, "triggerShapeSynchPointIndex"); + assertAngleRange(triggerShapeSynchPointIndex, "triggerShapeSynchPointIndex", CUSTOM_ERR_6552); int triggerDefinitionCoordinate = (triggerShapeSynchPointIndex + eventIndex) % engine->engineCycleEventCount; efiAssertVoid(engine->engineCycleEventCount != 0, "zero engineCycleEventCount"); int triggerDefinitionIndex = triggerDefinitionCoordinate >= size ? triggerDefinitionCoordinate - size : triggerDefinitionCoordinate;