From 581eef87fc860353a111e6b8b34e9d6269cea8c9 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Fri, 3 Oct 2014 14:05:03 -0500 Subject: [PATCH] auto-sync --- firmware/controllers/core/core.mk | 1 + firmware/controllers/core/fl_stack.h | 14 ++++- .../controllers/core/logic_expression.cpp | 61 +++++++++++++++++++ firmware/controllers/core/logic_expression.h | 53 ++++++++++++++++ firmware/rusefi.cpp | 2 +- unit_tests/main.cpp | 6 +- unit_tests/test_logic_expression.cpp | 20 ++++++ unit_tests/test_util.cpp | 13 ++++ 8 files changed, 166 insertions(+), 4 deletions(-) create mode 100644 firmware/controllers/core/logic_expression.cpp create mode 100644 firmware/controllers/core/logic_expression.h diff --git a/firmware/controllers/core/core.mk b/firmware/controllers/core/core.mk index 52b47c90a5..e220c5e2b8 100644 --- a/firmware/controllers/core/core.mk +++ b/firmware/controllers/core/core.mk @@ -3,5 +3,6 @@ CONTROLLERS_CORE_SRC = $(PROJECT_DIR)/controllers/core/avg_values.c CONTROLLERS_CORE_SRC_CPP = $(PROJECT_DIR)/controllers/core/EfiWave.cpp \ $(PROJECT_DIR)/controllers/core/table_helper.cpp \ + $(PROJECT_DIR)/controllers/core/logic_expression.cpp \ $(PROJECT_DIR)/controllers/core/interpolation.cpp \ diff --git a/firmware/controllers/core/fl_stack.h b/firmware/controllers/core/fl_stack.h index 42edd42915..dd7722f80c 100644 --- a/firmware/controllers/core/fl_stack.h +++ b/firmware/controllers/core/fl_stack.h @@ -14,6 +14,7 @@ class FLStack { public: FLStack(); void push(T value); + void reset(); T pop(); int size(); bool isEmpty(); @@ -24,7 +25,7 @@ private: template FLStack::FLStack() { - index = 0; + reset(); } template @@ -32,11 +33,22 @@ bool FLStack::isEmpty() { return index == 0; } +template +void FLStack::reset() { + index = 0; +} + template void FLStack::push(T value) { values[index++] = value; } +template +T FLStack::pop() { + return values[--index]; +} + + template int FLStack::size() { return index; diff --git a/firmware/controllers/core/logic_expression.cpp b/firmware/controllers/core/logic_expression.cpp new file mode 100644 index 0000000000..fc4a3b47b8 --- /dev/null +++ b/firmware/controllers/core/logic_expression.cpp @@ -0,0 +1,61 @@ +/** + * @file logic_expression.cpp + * + * @date Oct 3, 2014 + * @author Andrey Belomutskiy, (c) 2012-2014 + */ + +#include "main.h" +#include "logic_expression.h" + +LEElement::LEElement() { + action = LE_UNDEFINED; + next = NULL; +} + +//void LEElement::init(le_action_e action, int iValue) { +// this->action = action; +// this->iValue = iValue; +//} + +void LEElement::init(le_action_e action) { + this->action = action; +} + +void LEElement::init(le_action_e action, float fValue) { + this->action = action; + this->fValue = fValue; +} + +LECalculator::LECalculator() { + first = NULL; +} + +float LECalculator::getValue() { + LEElement *element = first; + + stack.reset(); + + while(element != NULL) { + + stack.push(element->fValue); + + + element = element->next; + } + + return stack.pop(); +} + + +void LECalculator::add(LEElement *element) { + if (first == NULL) { + first = element; + } else { + LEElement *last = first; + while (last->next != NULL) { + last = last->next; + } + last->next = element; + } +} diff --git a/firmware/controllers/core/logic_expression.h b/firmware/controllers/core/logic_expression.h new file mode 100644 index 0000000000..226b00afd0 --- /dev/null +++ b/firmware/controllers/core/logic_expression.h @@ -0,0 +1,53 @@ +/** + * @file logic_expression.h + * + * @date Oct 3, 2014 + * @author Andrey Belomutskiy, (c) 2012-2014 + */ + +#ifndef LOGIC_EXPRESSION_H_ +#define LOGIC_EXPRESSION_H_ + +#include "rusefi_enums.h" +#include "fl_stack.h" + +typedef enum { + LE_UNDEFINED, + LE_NUMERIC_VALUE, + LE_OPERATOR_LESS, + LE_OPERATOR_MORE, + LE_OPERATOR_AND, + LE_OPERATOR_OR, + + Force_4b_le_action = ENUM_SIZE_HACK, +} le_action_e; + +class LEElement { +public: + LEElement(); +// void init(le_action_e action, int iValue); + void init(le_action_e action); + void init(le_action_e action, float fValue); + + le_action_e action; + float fValue; + int iValue; + + LEElement *next; +}; + + +#define MAX_STACK_DEPTH 32 + +class LECalculator { +public: + LECalculator(); + float getValue(); + void add(LEElement *element); + LEElement *first; + +private: + FLStack stack; +}; + +#endif /* LOGIC_EXPRESSION_H_ */ diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 5b440578f1..38f9b4ad5a 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -241,5 +241,5 @@ void firmwareError(const char *fmt, ...) { } int getRusEfiVersion(void) { - return 20141002; + return 20141003; } diff --git a/unit_tests/main.cpp b/unit_tests/main.cpp index fbd7405171..a7e5c7f6c6 100644 --- a/unit_tests/main.cpp +++ b/unit_tests/main.cpp @@ -21,6 +21,8 @@ #include "test_fuel_map.h" #include "fuel_math.h" +#include "test_logic_expression.h" +#include "engine_configuration.h" extern "C" { @@ -29,7 +31,6 @@ extern "C" #include "test_event_registry.h" #include "test_signal_executor.h" #include "test_util.h" -#include "engine_configuration.h" } #include "engine_math.h" @@ -95,6 +96,7 @@ static engine_configuration2_s ec2; engine_configuration2_s *engineConfiguration2 = &ec2; int main(void) { + testLogicExpressions(); testOverflow64Counter(); testInterpolate3d(); testFindIndex(); @@ -130,7 +132,7 @@ int main(void) { testFLStack(); // resizeMap(); - printf("Success 20131002\r\n"); + printf("Success 20131003\r\n"); return EXIT_SUCCESS; } diff --git a/unit_tests/test_logic_expression.cpp b/unit_tests/test_logic_expression.cpp index 6a97e002eb..633e64207e 100644 --- a/unit_tests/test_logic_expression.cpp +++ b/unit_tests/test_logic_expression.cpp @@ -9,8 +9,28 @@ #include "main.h" #include "test_logic_expression.h" +#include "logic_expression.h" void testLogicExpressions(void) { + printf("*************************************************** testLogicExpressions\r\n"); + + LECalculator c; + + LEElement value1; + value1.init(LE_NUMERIC_VALUE, 123.0); + c.add(&value1); + + assertEqualsM("123", 123.0, c.getValue()); + + + LEElement value2; + value2.init(LE_NUMERIC_VALUE, 321.0); + c.add(&value2); + + LEElement value3; + value3.init(LE_OPERATOR_AND); + c.add(&value3); + /** * fuel_pump = (time_since_boot < 4 seconds) OR (rpm > 0) * fuel_pump = time_since_boot 4 less rpm 0 more OR diff --git a/unit_tests/test_util.cpp b/unit_tests/test_util.cpp index 902212147a..5ce7c8b4a8 100644 --- a/unit_tests/test_util.cpp +++ b/unit_tests/test_util.cpp @@ -311,6 +311,19 @@ void testFLStack(void) { FLStack stack; assertEquals(0, stack.size()); + + stack.push(123); + stack.push(234); + assertEquals(2, stack.size()); + + int v = stack.pop(); + assertEquals(234, v); + assertEquals(1, stack.size()); + + v = stack.pop(); + assertEquals(123, v); + assertEquals(0, stack.size()); + } void testMisc(void) {