diff --git a/firmware/controllers/core/le_functions.cpp b/firmware/controllers/core/le_functions.cpp index 585c713bd9..c80d5bdcd4 100644 --- a/firmware/controllers/core/le_functions.cpp +++ b/firmware/controllers/core/le_functions.cpp @@ -12,6 +12,10 @@ extern LENameOrdinalPair * LE_FIRST; +static LENameOrdinalPair leLess(LE_OPERATOR_LESS, "<"); +static LENameOrdinalPair leLessEquals(LE_OPERATOR_LESS_OR_EQUAL, "<="); +static LENameOrdinalPair leMore(LE_OPERATOR_MORE, ">"); +static LENameOrdinalPair leMoreEquals(LE_OPERATOR_MORE_OR_EQUAL, ">="); static LENameOrdinalPair leRpm(LE_METHOD_RPM, "rpm"); static LENameOrdinalPair leTps(LE_METHOD_TPS, "tps"); static LENameOrdinalPair leMaf(LE_METHOD_MAF, "maf"); @@ -21,10 +25,10 @@ static LENameOrdinalPair leFanOnSetting(LE_METHOD_FAN_ON_SETTING, "fan_on_settin static LENameOrdinalPair leFanOffSetting(LE_METHOD_FAN_OFF_SETTING, "fan_off_setting"); static LENameOrdinalPair leTimeSinceBoot(LE_METHOD_TIME_SINCE_BOOT, "time_since_boot"); - #if EFI_PROD_CODE || EFI_SIMULATOR float getLEValue(Engine *engine, le_action_e action) { - switch(action) { + efiAssert(engine!=NULL, "getLEValue", NAN); + switch (action) { // case LE_METHOD_FAN: // return ; case LE_METHOD_COOLANT: diff --git a/firmware/controllers/core/le_functions.h b/firmware/controllers/core/le_functions.h index cc383cdbc7..da72f31329 100644 --- a/firmware/controllers/core/le_functions.h +++ b/firmware/controllers/core/le_functions.h @@ -11,6 +11,8 @@ #include "engine.h" #include "logic_expression.h" +#define FUEL_PUMP_LOGIC "time_since_boot 4 < rpm 0 > OR" + float getLEValue(Engine *engine, le_action_e action); #endif /* LE_FUNCTIONS_H_ */ diff --git a/firmware/controllers/core/logic_expression.cpp b/firmware/controllers/core/logic_expression.cpp index cc1d1ebfff..59fc6f6f4b 100644 --- a/firmware/controllers/core/logic_expression.cpp +++ b/firmware/controllers/core/logic_expression.cpp @@ -1,5 +1,13 @@ /** * @file logic_expression.cpp + * @brief Logical expressions handling logic + * + * Here we parse and evaluate logical expressions in + * http://en.wikipedia.org/wiki/Reverse_Polish_notation + * + * Once the expressions are parsed on startup (that's a heavy operation), + * evaluating those is relatively efficient. + * * * @date Oct 3, 2014 * @author Andrey Belomutskiy, (c) 2012-2014 @@ -147,7 +155,7 @@ void LECalculator::doJob(Engine *engine, LEElement *element) { firmwareError("Undefined not expected here"); break; default: - stack.push(getLEValue(NULL, element->action)); + stack.push(getLEValue(engine, element->action)); } } diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 32f8484435..a8f23b14cf 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -53,8 +53,7 @@ #include "PwmTester.h" #include "engine.h" #include "logic_expression.h" - -#define FUEL_PUMP_LOGIC "time_since_boot 4 < rpm 0 > OR" +#include "le_functions.h" LECalculator calc; diff --git a/unit_tests/main.cpp b/unit_tests/main.cpp index 6eba285de4..e4d125cc57 100644 --- a/unit_tests/main.cpp +++ b/unit_tests/main.cpp @@ -132,7 +132,7 @@ int main(void) { testFLStack(); // resizeMap(); - printf("Success 20131004\r\n"); + printf("Success 20131009\r\n"); return EXIT_SUCCESS; } diff --git a/unit_tests/test_logic_expression.cpp b/unit_tests/test_logic_expression.cpp index cc579492c0..808631caf9 100644 --- a/unit_tests/test_logic_expression.cpp +++ b/unit_tests/test_logic_expression.cpp @@ -10,11 +10,14 @@ #include "main.h" #include "test_logic_expression.h" #include "logic_expression.h" +#include "le_functions.h" #include "cli_registry.h" #include "engine.h" static float mockCoolant; static float mockFan; +static float mockRpm; +static float mockTimeSinceBoot; float getLEValue(Engine *engine, le_action_e action) { switch(action) { @@ -22,13 +25,16 @@ float getLEValue(Engine *engine, le_action_e action) { return mockFan; case LE_METHOD_COOLANT: return mockCoolant; + case LE_METHOD_RPM: + return mockRpm; + case LE_METHOD_TIME_SINCE_BOOT: + return mockTimeSinceBoot; default: - firmwareError("No value for %d", action); + firmwareError("No mock value for %d", action); return NAN; } } - static void testParsing(void) { char buffer[64]; @@ -77,6 +83,7 @@ static void testExpression(const char *line, float expected) { LEElementPool pool; pool.reset(); LEElement * element = parseExpression(&pool, line); + print("Parsing [%s]", line); assertTrueM("Not NULL expected", element != NULL); LECalculator c; c.add(element); @@ -158,4 +165,7 @@ void testLogicExpressions(void) { testExpression("fan NOT coolant 90 > AND fan coolant 85 > AND OR", 1); + mockRpm = 900; + testExpression(FUEL_PUMP_LOGIC, 1); + }