refactoring

This commit is contained in:
rusefi 2017-06-04 15:25:37 -04:00
parent 82b3cc5eac
commit d66bd27f96
5 changed files with 39 additions and 37 deletions

View File

@ -28,6 +28,7 @@ extern fsio8_Map3D_u8t fsioTable4;
static fsio8_Map3D_u8t * fsio8t_tables[] = {NULL, NULL, &fsioTable2, &fsioTable3, &fsioTable4}; static fsio8_Map3D_u8t * fsio8t_tables[] = {NULL, NULL, &fsioTable2, &fsioTable3, &fsioTable4};
EXTERN_ENGINE;
LENameOrdinalPair * LE_FIRST = NULL; LENameOrdinalPair * LE_FIRST = NULL;
@ -75,12 +76,6 @@ void LEElement::clear() {
iValue = 0; iValue = 0;
} }
//void LEElement::init(le_action_e action, int iValue) {
// this->action = action;
// this->iValue = iValue;
//}
void LEElement::init(le_action_e action) { void LEElement::init(le_action_e action) {
this->action = action; this->action = action;
} }
@ -142,7 +137,7 @@ void LECalculator::push(le_action_e action, float value) {
/** /**
* @return true in case of error, false otherwise * @return true in case of error, false otherwise
*/ */
bool LECalculator::processElement(Engine *engine, LEElement *element) { bool LECalculator::processElement(LEElement *element DECLARE_ENGINE_PARAMETER_SUFFIX) {
#if EFI_PROD_CODE || defined(__DOXYGEN__) #if EFI_PROD_CODE || defined(__DOXYGEN__)
efiAssert(getRemainingStack(chThdGetSelfX()) > 64, "FSIO logic", false); efiAssert(getRemainingStack(chThdGetSelfX()) > 64, "FSIO logic", false);
#endif #endif
@ -258,7 +253,7 @@ bool LECalculator::processElement(Engine *engine, LEElement *element) {
float humanIndex = pop(LE_METHOD_FSIO_SETTING); float humanIndex = pop(LE_METHOD_FSIO_SETTING);
int index = (int) humanIndex - 1; int index = (int) humanIndex - 1;
if (index >= 0 && index < LE_COMMAND_COUNT) { if (index >= 0 && index < LE_COMMAND_COUNT) {
push(element->action, engine->engineConfiguration->bc.fsio_setting[index]); push(element->action, boardConfiguration->fsio_setting[index]);
} else { } else {
push(element->action, NAN); push(element->action, NAN);
} }
@ -285,7 +280,7 @@ bool LECalculator::processElement(Engine *engine, LEElement *element) {
} }
break; break;
case LE_METHOD_FSIO_ANALOG_INPUT: case LE_METHOD_FSIO_ANALOG_INPUT:
push(element->action, getVoltage("fsio", engine->engineConfiguration->fsioAdc[0])); push(element->action, getVoltage("fsio", engineConfiguration->fsioAdc[0]));
break; break;
case LE_METHOD_KNOCK: case LE_METHOD_KNOCK:
push(element->action, engine->knockCount); push(element->action, engine->knockCount);
@ -294,21 +289,21 @@ bool LECalculator::processElement(Engine *engine, LEElement *element) {
warning(CUSTOM_UNKNOWN_FSIO, "FSIO undefined action"); warning(CUSTOM_UNKNOWN_FSIO, "FSIO undefined action");
return true; return true;
default: default:
push(element->action, getLEValue(engine, &stack, element->action)); push(element->action, getEngineValue(element->action PASS_ENGINE_PARAMETER_SUFFIX));
} }
return false; return false;
} }
float LECalculator::getValue2(float selfValue, LEElement *fistElementInList, Engine *engine) { float LECalculator::getValue2(float selfValue, LEElement *fistElementInList DECLARE_ENGINE_PARAMETER_SUFFIX) {
reset(fistElementInList); reset(fistElementInList);
return getValue(selfValue, engine); return getValue(selfValue PASS_ENGINE_PARAMETER_SUFFIX);
} }
bool LECalculator::isEmpty() { bool LECalculator::isEmpty() {
return first == NULL; return first == NULL;
} }
float LECalculator::getValue(float selfValue, Engine *engine) { float LECalculator::getValue(float selfValue DECLARE_ENGINE_PARAMETER_SUFFIX) {
if (isEmpty()) { if (isEmpty()) {
warning(CUSTOM_NO_FSIO, "no FSIO code"); warning(CUSTOM_NO_FSIO, "no FSIO code");
return NAN; return NAN;
@ -324,7 +319,7 @@ float LECalculator::getValue(float selfValue, Engine *engine) {
if (element->action == LE_METHOD_SELF) { if (element->action == LE_METHOD_SELF) {
push(element->action, selfValue); push(element->action, selfValue);
} else { } else {
bool isError = processElement(engine, element); bool isError = processElement(element PASS_ENGINE_PARAMETER_SUFFIX);
if (isError) { if (isError) {
// error already reported // error already reported
return NAN; return NAN;
@ -432,7 +427,7 @@ LEElement *LEElementPool::parseExpression(const char * line) {
/** /**
* Cannot recognize token * Cannot recognize token
*/ */
warning((obd_code_e) 0, "unrecognized [%s]", parsingBuffer); warning(CUSTOM_ERR_6536, "unrecognized [%s]", parsingBuffer);
return NULL; return NULL;
} }
n->init(action); n->init(action);

View File

@ -96,8 +96,8 @@ typedef FLStack<float, MAX_STACK_DEPTH> calc_stack_t;
class LECalculator { class LECalculator {
public: public:
LECalculator(); LECalculator();
float getValue(float selfValue, Engine *engine); float getValue(float selfValue DECLARE_ENGINE_PARAMETER_SUFFIX);
float getValue2(float selfValue, LEElement *fistElementInList, Engine *engine); float getValue2(float selfValue, LEElement *fistElementInList DECLARE_ENGINE_PARAMETER_SUFFIX);
void add(LEElement *element); void add(LEElement *element);
bool isEmpty(); bool isEmpty();
void reset(); void reset();
@ -107,7 +107,7 @@ public:
int currentCalculationLogPosition; int currentCalculationLogPosition;
private: private:
void push(le_action_e action, float value); void push(le_action_e action, float value);
bool processElement(Engine *engine, LEElement *element); bool processElement(LEElement *element DECLARE_ENGINE_PARAMETER_SUFFIX);
float pop(le_action_e action); float pop(le_action_e action);
LEElement *first; LEElement *first;
calc_stack_t stack; calc_stack_t stack;

View File

@ -74,8 +74,7 @@ EXTERN_ENGINE
#if EFI_PROD_CODE || EFI_SIMULATOR #if EFI_PROD_CODE || EFI_SIMULATOR
static Logging *logger; static Logging *logger;
float getLEValue(Engine *engine, calc_stack_t *s, le_action_e action) { float getEngineValue(le_action_e action DECLARE_ENGINE_PARAMETER_SUFFIX) {
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
efiAssert(engine!=NULL, "getLEValue", NAN); efiAssert(engine!=NULL, "getLEValue", NAN);
switch (action) { switch (action) {
case LE_METHOD_FAN: case LE_METHOD_FAN:
@ -264,7 +263,7 @@ static void handleFsio(Engine *engine, int index) {
warning(CUSTOM_NO_FSIO, "no FSIO for #%d %s", index + 1, hwPortname(boardConfiguration->fsioPins[index])); warning(CUSTOM_NO_FSIO, "no FSIO for #%d %s", index + 1, hwPortname(boardConfiguration->fsioPins[index]));
fvalue = NAN; fvalue = NAN;
} else { } else {
fvalue = calc.getValue2(engine->fsioLastValue[index], fsioLogics[index], engine); fvalue = calc.getValue2(engine->fsioLastValue[index], fsioLogics[index] PASS_ENGINE_PARAMETER_SUFFIX);
} }
engine->fsioLastValue[index] = fvalue; engine->fsioLastValue[index] = fvalue;
@ -301,11 +300,11 @@ static const char * action2String(le_action_e action) {
return buffer; return buffer;
} }
static void setPinState(const char * msg, OutputPin *pin, LEElement *element, Engine *engine) { static void setPinState(const char * msg, OutputPin *pin, LEElement *element) {
if (element == NULL) { if (element == NULL) {
warning(CUSTOM_OBD_11, "invalid expression for %s", msg); warning(CUSTOM_OBD_11, "invalid expression for %s", msg);
} else { } else {
int value = (int)calc.getValue2(pin->getLogicValue(), element, engine); int value = (int)calc.getValue2(pin->getLogicValue(), element PASS_ENGINE_PARAMETER_SUFFIX);
if (pin->isInitialized() && value != pin->getLogicValue()) { if (pin->isInitialized() && value != pin->getLogicValue()) {
if (isRunningBenchTest()) { if (isRunningBenchTest()) {
return; // let's not mess with bench testing return; // let's not mess with bench testing
@ -342,7 +341,7 @@ void runFsio(void) {
#if EFI_FUEL_PUMP || defined(__DOXYGEN__) #if EFI_FUEL_PUMP || defined(__DOXYGEN__)
if (boardConfiguration->fuelPumpPin != GPIO_UNASSIGNED) { if (boardConfiguration->fuelPumpPin != GPIO_UNASSIGNED) {
setPinState("pump", &enginePins.fuelPumpRelay, fuelPumpLogic, engine); setPinState("pump", &enginePins.fuelPumpRelay, fuelPumpLogic);
} }
#endif /* EFI_FUEL_PUMP */ #endif /* EFI_FUEL_PUMP */
@ -355,7 +354,7 @@ void runFsio(void) {
enginePins.o2heater.setValue(engine->rpmCalculator.isRunning()); enginePins.o2heater.setValue(engine->rpmCalculator.isRunning());
if (boardConfiguration->acRelayPin != GPIO_UNASSIGNED) { if (boardConfiguration->acRelayPin != GPIO_UNASSIGNED) {
setPinState("A/C", &enginePins.acRelay, acRelayLogic, engine); setPinState("A/C", &enginePins.acRelay, acRelayLogic);
} }
// if (boardConfiguration->alternatorControlPin != GPIO_UNASSIGNED) { // if (boardConfiguration->alternatorControlPin != GPIO_UNASSIGNED) {
@ -363,7 +362,7 @@ void runFsio(void) {
// } // }
if (boardConfiguration->fanPin != GPIO_UNASSIGNED) { if (boardConfiguration->fanPin != GPIO_UNASSIGNED) {
setPinState("fan", &enginePins.fanRelay, radiatorFanLogic, engine); setPinState("fan", &enginePins.fanRelay, radiatorFanLogic);
} }
} }
@ -468,7 +467,7 @@ static void setFsioExpression(const char *indexStr, const char *quotedLine, Engi
#endif #endif
} }
static void rpnEval(char *line, Engine *engine) { static void rpnEval(char *line) {
#if EFI_PROD_CODE || EFI_SIMULATOR #if EFI_PROD_CODE || EFI_SIMULATOR
line = unquote(line); line = unquote(line);
scheduleMsg(logger, "Parsing [%s]", line); scheduleMsg(logger, "Parsing [%s]", line);
@ -477,7 +476,7 @@ static void rpnEval(char *line, Engine *engine) {
if (e == NULL) { if (e == NULL) {
scheduleMsg(logger, "parsing failed"); scheduleMsg(logger, "parsing failed");
} else { } else {
float result = evalCalc.getValue2(0, e, engine); float result = evalCalc.getValue2(0, e PASS_ENGINE_PARAMETER_SUFFIX);
scheduleMsg(logger, "Evaluate result: %f", result); scheduleMsg(logger, "Evaluate result: %f", result);
} }
#endif #endif
@ -530,11 +529,11 @@ void initFsioImpl(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */
#if EFI_PROD_CODE || EFI_SIMULATOR #if EFI_PROD_CODE || EFI_SIMULATOR
addConsoleActionSSP("set_rpn_expression", (VoidCharPtrCharPtrVoidPtr) setFsioExpression, engine); addConsoleActionSS("set_rpn_expression", (VoidCharPtrCharPtr) setFsioExpression);
addConsoleActionFF("set_fsio_setting", setFsioSetting); addConsoleActionFF("set_fsio_setting", setFsioSetting);
addConsoleAction("fsioinfo", showFsioInfo); addConsoleAction("fsioinfo", showFsioInfo);
addConsoleActionSP("rpn_eval", (VoidCharPtrVoidPtr) rpnEval, engine); addConsoleActionS("rpn_eval", (VoidCharPtr) rpnEval);
#endif #endif /* EFI_PROD_CODE || EFI_SIMULATOR */
fsioTable1.init(config->fsioTable1, config->fsioTable1LoadBins, fsioTable1.init(config->fsioTable1, config->fsioTable1LoadBins,
config->fsioTable1RpmBins); config->fsioTable1RpmBins);

View File

@ -18,7 +18,7 @@ typedef Map3D<FSIO_TABLE_8, FSIO_TABLE_8, float> fsio8_Map3D_f32t;
typedef Map3D<FSIO_TABLE_8, FSIO_TABLE_8, uint8_t> fsio8_Map3D_u8t; typedef Map3D<FSIO_TABLE_8, FSIO_TABLE_8, uint8_t> fsio8_Map3D_u8t;
float getLEValue(Engine *engine, calc_stack_t *s, le_action_e action); float getEngineValue(le_action_e action DECLARE_ENGINE_PARAMETER_SUFFIX);
void setFsio(int index, brain_pin_e pin, const char * exp DECLARE_ENGINE_PARAMETER_SUFFIX); void setFsio(int index, brain_pin_e pin, const char * exp DECLARE_ENGINE_PARAMETER_SUFFIX);
void setFsioExt(int index, brain_pin_e pin, const char * exp, int freq DECLARE_ENGINE_PARAMETER_SUFFIX); void setFsioExt(int index, brain_pin_e pin, const char * exp, int freq DECLARE_ENGINE_PARAMETER_SUFFIX);

View File

@ -11,6 +11,7 @@
#include "test_logic_expression.h" #include "test_logic_expression.h"
#include "fsio_impl.h" #include "fsio_impl.h"
#include "cli_registry.h" #include "cli_registry.h"
#include "engine_test_helper.h"
#define TEST_POOL_SIZE 256 #define TEST_POOL_SIZE 256
@ -19,7 +20,7 @@ static float mockFan;
static float mockRpm; static float mockRpm;
static float mockTimeSinceBoot; static float mockTimeSinceBoot;
float getLEValue(Engine *engine, calc_stack_t *s, le_action_e action) { float getEngineValue(le_action_e action DECLARE_ENGINE_PARAMETER_SUFFIX) {
switch(action) { switch(action) {
case LE_METHOD_FAN: case LE_METHOD_FAN:
return mockFan; return mockFan;
@ -91,7 +92,11 @@ static void testExpression2(float selfValue, const char *line, float expected) {
print("Parsing [%s]", line); print("Parsing [%s]", line);
assertTrueM("Not NULL expected", element != NULL); assertTrueM("Not NULL expected", element != NULL);
LECalculator c; LECalculator c;
assertEqualsM(line, expected, c.getValue2(selfValue, element, NULL));
EngineTestHelper eth(FORD_INLINE_6_1995);
EXPAND_EngineTestHelper;
assertEqualsM(line, expected, c.getValue2(selfValue, element PASS_ENGINE_PARAMETER_SUFFIX));
} }
static void testExpression(const char *line, float expected) { static void testExpression(const char *line, float expected) {
@ -103,13 +108,16 @@ void testLogicExpressions(void) {
testParsing(); testParsing();
EngineTestHelper eth(FORD_INLINE_6_1995);
EXPAND_EngineTestHelper;
LECalculator c; LECalculator c;
LEElement value1; LEElement value1;
value1.init(LE_NUMERIC_VALUE, 123.0); value1.init(LE_NUMERIC_VALUE, 123.0);
c.add(&value1); c.add(&value1);
assertEqualsM("123", 123.0, c.getValue(0, NULL)); assertEqualsM("123", 123.0, c.getValue(0 PASS_ENGINE_PARAMETER_SUFFIX));
LEElement value2; LEElement value2;
value2.init(LE_NUMERIC_VALUE, 321.0); value2.init(LE_NUMERIC_VALUE, 321.0);
@ -118,7 +126,7 @@ void testLogicExpressions(void) {
LEElement value3; LEElement value3;
value3.init(LE_OPERATOR_AND); value3.init(LE_OPERATOR_AND);
c.add(&value3); c.add(&value3);
assertEqualsM("123 and 321", 1.0, c.getValue(0, NULL)); assertEqualsM("123 and 321", 1.0, c.getValue(0 PASS_ENGINE_PARAMETER_SUFFIX));
/** /**
* fuel_pump = (time_since_boot < 4 seconds) OR (rpm > 0) * fuel_pump = (time_since_boot < 4 seconds) OR (rpm > 0)
@ -183,7 +191,7 @@ void testLogicExpressions(void) {
LEElement * element = pool.parseExpression("fan NOT coolant 90 > AND fan coolant 85 > AND OR"); LEElement * element = pool.parseExpression("fan NOT coolant 90 > AND fan coolant 85 > AND OR");
assertTrueM("Not NULL expected", element != NULL); assertTrueM("Not NULL expected", element != NULL);
LECalculator c; LECalculator c;
assertEqualsM("that expression", 1, c.getValue2(0, element, NULL)); assertEqualsM("that expression", 1, c.getValue2(0, element PASS_ENGINE_PARAMETER_SUFFIX));
assertEquals(12, c.currentCalculationLogPosition); assertEquals(12, c.currentCalculationLogPosition);
assertEquals(102, c.calcLogAction[0]); assertEquals(102, c.calcLogAction[0]);