diff --git a/firmware/controllers/core/fsio_core.cpp b/firmware/controllers/core/fsio_core.cpp index 638cfbe130..7dec1e3b9d 100644 --- a/firmware/controllers/core/fsio_core.cpp +++ b/firmware/controllers/core/fsio_core.cpp @@ -46,6 +46,7 @@ static LENameOrdinalPair leLessOrEquals(LE_OPERATOR_LESS_OR_EQUAL, "<="); static LENameOrdinalPair leMax(LE_METHOD_MAX, "max"); static LENameOrdinalPair leMin(LE_METHOD_MIN, "min"); static LENameOrdinalPair leIf(LE_METHOD_IF, "if"); +static LENameOrdinalPair leSelf(LE_METHOD_SELF, "self"); LENameOrdinalPair::LENameOrdinalPair(le_action_e action, const char *name) { this->action = action; @@ -126,7 +127,7 @@ void LECalculator::push(le_action_e action, float value) { /** * @return true in case of error, false otherwise */ -bool LECalculator::doJob(Engine *engine, LEElement *element) { +bool LECalculator::processElement(Engine *engine, LEElement *element) { #if EFI_PROD_CODE || defined(__DOXYGEN__) efiAssert(getRemainingStack(chThdSelf()) > 64, "FSIO logic", false); #endif @@ -260,12 +261,12 @@ bool LECalculator::doJob(Engine *engine, LEElement *element) { return false; } -float LECalculator::getValue2(LEElement *element, Engine *engine) { - reset(element); - return getValue(engine); +float LECalculator::getValue2(float selfValue, LEElement *fistElementInList, Engine *engine) { + reset(fistElementInList); + return getValue(selfValue, engine); } -float LECalculator::getValue(Engine *engine) { +float LECalculator::getValue(float selfValue, Engine *engine) { if (first == NULL) { warning(OBD_PCM_Processor_Fault, "no FSIO code"); return NAN; @@ -278,10 +279,14 @@ float LECalculator::getValue(Engine *engine) { while (element != NULL) { efiAssert(counter < 200, "FSIOcount", NAN); // just in case - bool isError = doJob(engine, element); - if (isError) { - // error already reported - return NAN; + if (element->action == LE_METHOD_SELF) { + push(element->action, selfValue); + } else { + bool isError = processElement(engine, element); + if (isError) { + // error already reported + return NAN; + } } element = element->next; counter++; diff --git a/firmware/controllers/core/fsio_core.h b/firmware/controllers/core/fsio_core.h index 7674d7b062..0c1e9a858d 100644 --- a/firmware/controllers/core/fsio_core.h +++ b/firmware/controllers/core/fsio_core.h @@ -30,6 +30,7 @@ typedef enum { LE_METHOD_MAX = 13, LE_METHOD_MIN = 14, LE_METHOD_IF = 15, + LE_METHOD_SELF = 16, LE_METHOD_RPM = 100, LE_METHOD_COOLANT = 101, @@ -86,8 +87,8 @@ typedef FLStack calc_stack_t; class LECalculator { public: LECalculator(); - float getValue(Engine *engine); - float getValue2(LEElement *element, Engine *engine); + float getValue(float selfValue, Engine *engine); + float getValue2(float selfValue, LEElement *fistElementInList, Engine *engine); void add(LEElement *element); void reset(); void reset(LEElement *element); @@ -96,7 +97,7 @@ public: int currentCalculationLogPosition; private: void push(le_action_e action, float value); - bool doJob(Engine *engine, LEElement *element); + bool processElement(Engine *engine, LEElement *element); float pop(le_action_e action); LEElement *first; calc_stack_t stack; diff --git a/firmware/controllers/core/fsio_impl.cpp b/firmware/controllers/core/fsio_impl.cpp index 2f49f7ffe0..4022e06bef 100644 --- a/firmware/controllers/core/fsio_impl.cpp +++ b/firmware/controllers/core/fsio_impl.cpp @@ -220,7 +220,7 @@ static void handleFsio(Engine *engine, int index) { bool isPwmMode = boardConfiguration->fsioFrequency[index] != NO_PWM; - float fvalue = calc.getValue2(fsioLogics[index], engine); + float fvalue = calc.getValue2(engine->engineConfiguration2->fsioLastValue[index], fsioLogics[index], engine); engine->engineConfiguration2->fsioLastValue[index] = fvalue; if (isPwmMode) { @@ -260,7 +260,7 @@ static void setPinState(const char * msg, OutputPin *pin, LEElement *element, En if (element == NULL) { warning(OBD_PCM_Processor_Fault, "invalid expression for %s", msg); } else { - int value = calc.getValue2(element, engine); + int value = calc.getValue2(pin->getLogicValue(), element, engine); if (pin->isInitialized() && value != pin->getLogicValue()) { if (isRunningBenchTest()) { return; // let's not mess with bench testing @@ -417,7 +417,7 @@ static void eval(char *line, Engine *engine) { if (e == NULL) { scheduleMsg(logger, "parsing failed"); } else { - float result = evalCalc.getValue2(e, engine); + float result = evalCalc.getValue2(0, e, engine); scheduleMsg(logger, "Eval result: %f", result); } #endif diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 1d3b2096ba..c358648a51 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -275,5 +275,5 @@ int getRusEfiVersion(void) { return 123; // this is here to make the compiler happy about the unused array if (UNUSED_CCM_SIZE[0] * 0 != 0) return 3211; // this is here to make the compiler happy about the unused array - return 20160227; + return 20160302; } diff --git a/unit_tests/test_logic_expression.cpp b/unit_tests/test_logic_expression.cpp index 92458260b2..cb623f5c76 100644 --- a/unit_tests/test_logic_expression.cpp +++ b/unit_tests/test_logic_expression.cpp @@ -84,14 +84,18 @@ static void testParsing(void) { assertTrue(element == NULL); } -static void testExpression(const char *line, float expected) { +static void testExpression2(float selfValue, const char *line, float expected) { LEElement thepool[TEST_POOL_SIZE]; LEElementPool pool(thepool, TEST_POOL_SIZE); LEElement * element = pool.parseExpression(line); print("Parsing [%s]", line); assertTrueM("Not NULL expected", element != NULL); LECalculator c; - assertEqualsM(line, expected, c.getValue2(element, NULL)); + assertEqualsM(line, expected, c.getValue2(selfValue, element, NULL)); +} + +static void testExpression(const char *line, float expected) { + testExpression2(0, line, expected); } void testLogicExpressions(void) { @@ -105,7 +109,7 @@ void testLogicExpressions(void) { value1.init(LE_NUMERIC_VALUE, 123.0); c.add(&value1); - assertEqualsM("123", 123.0, c.getValue(NULL)); + assertEqualsM("123", 123.0, c.getValue(0, NULL)); LEElement value2; value2.init(LE_NUMERIC_VALUE, 321.0); @@ -114,7 +118,7 @@ void testLogicExpressions(void) { LEElement value3; value3.init(LE_OPERATOR_AND); c.add(&value3); - assertEqualsM("123 and 321", 1.0, c.getValue(NULL)); + assertEqualsM("123 and 321", 1.0, c.getValue(0, NULL)); /** * fuel_pump = (time_since_boot < 4 seconds) OR (rpm > 0) @@ -170,6 +174,8 @@ void testLogicExpressions(void) { testExpression("100 200 1 if", 200); testExpression("10 99 max", 99); + testExpression2(123, "10 self max", 123); + testExpression("fan NOT coolant 90 > AND fan coolant 85 > AND OR", 1); { LEElement thepool[TEST_POOL_SIZE]; @@ -177,7 +183,7 @@ void testLogicExpressions(void) { LEElement * element = pool.parseExpression("fan NOT coolant 90 > AND fan coolant 85 > AND OR"); assertTrueM("Not NULL expected", element != NULL); LECalculator c; - assertEqualsM("that expression", 1, c.getValue2(element, NULL)); + assertEqualsM("that expression", 1, c.getValue2(0, element, NULL)); assertEquals(12, c.currentCalculationLogPosition); assertEquals(102, c.calcLogAction[0]);