diff --git a/firmware/controllers/core/fsio_core.cpp b/firmware/controllers/core/fsio_core.cpp index e605145fa3..4c0ee93fed 100644 --- a/firmware/controllers/core/fsio_core.cpp +++ b/firmware/controllers/core/fsio_core.cpp @@ -259,7 +259,7 @@ FsioResult LECalculator::processElement(const LEElement *element DECLARE_ENGINE_ } } -float LECalculator::evaluate(float selfValue, const LEElement* element DECLARE_ENGINE_PARAMETER_SUFFIX) { +float LECalculator::evaluate(const char * msg, float selfValue, const LEElement* element DECLARE_ENGINE_PARAMETER_SUFFIX) { if (!element) { warning(CUSTOM_NO_FSIO, "no FSIO code"); return NAN; diff --git a/firmware/controllers/core/fsio_core.h b/firmware/controllers/core/fsio_core.h index 03f1d6ac90..b18a2f4276 100644 --- a/firmware/controllers/core/fsio_core.h +++ b/firmware/controllers/core/fsio_core.h @@ -132,7 +132,7 @@ typedef FLStack calc_stack_t; class LECalculator { public: LECalculator(); - float evaluate(float selfValue, const LEElement* element DECLARE_ENGINE_PARAMETER_SUFFIX); + float evaluate(const char * msg, float selfValue, const LEElement* element DECLARE_ENGINE_PARAMETER_SUFFIX); void reset(); // Log history of calculation actions for debugging diff --git a/firmware/controllers/core/fsio_impl.cpp b/firmware/controllers/core/fsio_impl.cpp index a9c2b15a94..1712d8c2df 100644 --- a/firmware/controllers/core/fsio_impl.cpp +++ b/firmware/controllers/core/fsio_impl.cpp @@ -345,7 +345,7 @@ float getFsioOutputValue(int index DECLARE_ENGINE_PARAMETER_SUFFIX) { warning(CUSTOM_NO_FSIO, "no FSIO for #%d %s", index + 1, hwPortname(CONFIG(fsioOutputPins)[index])); return NAN; } else { - return calc.evaluate(engine->fsioState.fsioLastValue[index], state.fsioLogics[index] PASS_ENGINE_PARAMETER_SUFFIX); + return calc.evaluate("FSIO", engine->fsioState.fsioLastValue[index], state.fsioLogics[index] PASS_ENGINE_PARAMETER_SUFFIX); } } @@ -412,7 +412,7 @@ static void setPinState(const char * msg, OutputPin *pin, LEElement *element DEC if (!element) { warning(CUSTOM_FSIO_INVALID_EXPRESSION, "invalid expression for %s", msg); } else { - int value = (int)calc.evaluate(pin->getLogicValue(), element PASS_ENGINE_PARAMETER_SUFFIX); + int value = (int)calc.evaluate(msg, pin->getLogicValue(), element PASS_ENGINE_PARAMETER_SUFFIX); if (pin->isInitialized() && value != pin->getLogicValue()) { for (int i = 0;i < calc.currentCalculationLogPosition;i++) { @@ -454,7 +454,7 @@ static bool updateValueOrWarning(int humanIndex, const char *msg, float *value D return false; } else { float beforeValue = *value; - *value = calc.evaluate(beforeValue, element PASS_ENGINE_PARAMETER_SUFFIX); + *value = calc.evaluate(msg, beforeValue, element PASS_ENGINE_PARAMETER_SUFFIX); // floating '==' comparison without EPS seems fine here return (beforeValue != *value); } @@ -674,7 +674,7 @@ static void rpnEval(char *line) { if (e == NULL) { scheduleMsg(logger, "parsing failed"); } else { - float result = evalCalc.evaluate(0, e PASS_ENGINE_PARAMETER_SUFFIX); + float result = evalCalc.evaluate("eval", 0, e PASS_ENGINE_PARAMETER_SUFFIX); scheduleMsg(logger, "Evaluate result: %.2f", result); } #endif diff --git a/unit_tests/tests/test_logic_expression.cpp b/unit_tests/tests/test_logic_expression.cpp index 695033ecaa..6039f04269 100644 --- a/unit_tests/tests/test_logic_expression.cpp +++ b/unit_tests/tests/test_logic_expression.cpp @@ -117,7 +117,7 @@ static void testExpression2(float selfValue, const char *line, float expected, E EXPAND_Engine; - ASSERT_NEAR(expected, c.evaluate(selfValue, element PASS_ENGINE_PARAMETER_SUFFIX), EPS4D) << line; + ASSERT_NEAR(expected, c.evaluate("test", selfValue, element PASS_ENGINE_PARAMETER_SUFFIX), EPS4D) << line; } static void testExpression2(float selfValue, const char *line, float expected, const std::unordered_map& sensorVals = {}) { @@ -144,20 +144,20 @@ TEST(fsio, testHysteresisSelf) { double selfValue = 0; engine->fsioState.mockRpm = 0; - selfValue = c.evaluate(selfValue, element PASS_ENGINE_PARAMETER_SUFFIX); + selfValue = c.evaluate("test", selfValue, element PASS_ENGINE_PARAMETER_SUFFIX); ASSERT_EQ(0, selfValue); engine->fsioState.mockRpm = 430; - selfValue = c.evaluate(selfValue, element PASS_ENGINE_PARAMETER_SUFFIX); + selfValue = c.evaluate("test", selfValue, element PASS_ENGINE_PARAMETER_SUFFIX); // OFF since not ON yet ASSERT_EQ(0, selfValue); engine->fsioState.mockRpm = 460; - selfValue = c.evaluate(selfValue, element PASS_ENGINE_PARAMETER_SUFFIX); + selfValue = c.evaluate("test", selfValue, element PASS_ENGINE_PARAMETER_SUFFIX); ASSERT_EQ(1, selfValue); engine->fsioState.mockRpm = 430; - selfValue = c.evaluate(selfValue, element PASS_ENGINE_PARAMETER_SUFFIX); + selfValue = c.evaluate("test", selfValue, element PASS_ENGINE_PARAMETER_SUFFIX); // OFF since was ON yet ASSERT_EQ(1, selfValue); } @@ -241,7 +241,7 @@ TEST(fsio, testLogicExpressions) { LEElement * element = pool.parseExpression("fan NOT coolant 90 > AND fan coolant 85 > AND OR"); ASSERT_TRUE(element != NULL) << "Not NULL expected"; LECalculator c; - ASSERT_EQ( 1, c.evaluate(0, element PASS_ENGINE_PARAMETER_SUFFIX)) << "that expression"; + ASSERT_EQ( 1, c.evaluate("test", 0, element PASS_ENGINE_PARAMETER_SUFFIX)) << "that expression"; ASSERT_EQ(12, c.currentCalculationLogPosition); ASSERT_EQ(102, c.calcLogAction[0]);