diff --git a/firmware/controllers/core/logic_expression.cpp b/firmware/controllers/core/logic_expression.cpp index 409da04f2f..fabfc6beb0 100644 --- a/firmware/controllers/core/logic_expression.cpp +++ b/firmware/controllers/core/logic_expression.cpp @@ -182,8 +182,8 @@ float LECalculator::getValue(Engine *engine) { return stack.pop(); } -LEElementPool::LEElementPool(int size) { - pool = thepool; +LEElementPool::LEElementPool(LEElement *pool, int size) { + this->pool = pool; this->size = size; reset(); } @@ -193,7 +193,7 @@ void LEElementPool::reset() { } LEElement *LEElementPool::next() { - if (index == LE_ELEMENT_POOL_SIZE - 1) { + if (index == size - 1) { firmwareError("LE_ELEMENT_POOL_SIZE overflow"); return NULL; } diff --git a/firmware/controllers/core/logic_expression.h b/firmware/controllers/core/logic_expression.h index 6dba118130..d5fd287b38 100644 --- a/firmware/controllers/core/logic_expression.h +++ b/firmware/controllers/core/logic_expression.h @@ -53,12 +53,9 @@ public: LEElement *next; }; -#define LE_ELEMENT_POOL_SIZE 256 - class LEElementPool { public: - LEElementPool(int size); - LEElement thepool[LE_ELEMENT_POOL_SIZE]; + LEElementPool(LEElement *pool, int size); LEElement *pool; LEElement *next(); void reset(); diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 7ed73e34fd..c180dfb199 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -57,7 +57,11 @@ LECalculator calc; -LEElementPool lePool(LE_ELEMENT_POOL_SIZE); +#define LE_ELEMENT_POOL_SIZE 256 + +static LEElement mainPool[LE_ELEMENT_POOL_SIZE]; +LEElementPool lePool(mainPool, LE_ELEMENT_POOL_SIZE); + LEElement * fuelPumpLogic; LEElement * radiatorFanLogic; diff --git a/unit_tests/test_logic_expression.cpp b/unit_tests/test_logic_expression.cpp index 94272be227..ea74a483e9 100644 --- a/unit_tests/test_logic_expression.cpp +++ b/unit_tests/test_logic_expression.cpp @@ -14,6 +14,8 @@ #include "cli_registry.h" #include "engine.h" +#define TEST_POOL_SIZE 256 + static float mockCoolant; static float mockFan; static float mockRpm; @@ -56,7 +58,8 @@ static void testParsing(void) { assertTrue(isNumeric("123")); assertFalse(isNumeric("a123")); - LEElementPool pool(LE_ELEMENT_POOL_SIZE); + LEElement thepool[TEST_POOL_SIZE]; + LEElementPool pool(thepool, TEST_POOL_SIZE); LEElement *element; element = parseExpression(&pool, "1 3 AND not"); @@ -80,7 +83,8 @@ static void testParsing(void) { } static void testExpression(const char *line, float expected) { - LEElementPool pool(LE_ELEMENT_POOL_SIZE); + LEElement thepool[TEST_POOL_SIZE]; + LEElementPool pool(thepool, TEST_POOL_SIZE); pool.reset(); LEElement * element = parseExpression(&pool, line); print("Parsing [%s]", line); @@ -119,7 +123,8 @@ void testLogicExpressions(void) { c.reset(); - LEElementPool pool(LE_ELEMENT_POOL_SIZE); + LEElement thepool[TEST_POOL_SIZE]; + LEElementPool pool(thepool, TEST_POOL_SIZE); LEElement *e = pool.next(); e->init(LE_METHOD_TIME_SINCE_BOOT);