refactoring
This commit is contained in:
parent
82b3cc5eac
commit
d66bd27f96
|
@ -28,6 +28,7 @@ extern fsio8_Map3D_u8t fsioTable4;
|
|||
|
||||
static fsio8_Map3D_u8t * fsio8t_tables[] = {NULL, NULL, &fsioTable2, &fsioTable3, &fsioTable4};
|
||||
|
||||
EXTERN_ENGINE;
|
||||
|
||||
LENameOrdinalPair * LE_FIRST = NULL;
|
||||
|
||||
|
@ -75,12 +76,6 @@ void LEElement::clear() {
|
|||
iValue = 0;
|
||||
}
|
||||
|
||||
|
||||
//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;
|
||||
}
|
||||
|
@ -142,7 +137,7 @@ void LECalculator::push(le_action_e action, float value) {
|
|||
/**
|
||||
* @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__)
|
||||
efiAssert(getRemainingStack(chThdGetSelfX()) > 64, "FSIO logic", false);
|
||||
#endif
|
||||
|
@ -258,7 +253,7 @@ bool LECalculator::processElement(Engine *engine, LEElement *element) {
|
|||
float humanIndex = pop(LE_METHOD_FSIO_SETTING);
|
||||
int index = (int) humanIndex - 1;
|
||||
if (index >= 0 && index < LE_COMMAND_COUNT) {
|
||||
push(element->action, engine->engineConfiguration->bc.fsio_setting[index]);
|
||||
push(element->action, boardConfiguration->fsio_setting[index]);
|
||||
} else {
|
||||
push(element->action, NAN);
|
||||
}
|
||||
|
@ -285,7 +280,7 @@ bool LECalculator::processElement(Engine *engine, LEElement *element) {
|
|||
}
|
||||
break;
|
||||
case LE_METHOD_FSIO_ANALOG_INPUT:
|
||||
push(element->action, getVoltage("fsio", engine->engineConfiguration->fsioAdc[0]));
|
||||
push(element->action, getVoltage("fsio", engineConfiguration->fsioAdc[0]));
|
||||
break;
|
||||
case LE_METHOD_KNOCK:
|
||||
push(element->action, engine->knockCount);
|
||||
|
@ -294,21 +289,21 @@ bool LECalculator::processElement(Engine *engine, LEElement *element) {
|
|||
warning(CUSTOM_UNKNOWN_FSIO, "FSIO undefined action");
|
||||
return true;
|
||||
default:
|
||||
push(element->action, getLEValue(engine, &stack, element->action));
|
||||
push(element->action, getEngineValue(element->action PASS_ENGINE_PARAMETER_SUFFIX));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
float LECalculator::getValue2(float selfValue, LEElement *fistElementInList, Engine *engine) {
|
||||
float LECalculator::getValue2(float selfValue, LEElement *fistElementInList DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
reset(fistElementInList);
|
||||
return getValue(selfValue, engine);
|
||||
return getValue(selfValue PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
}
|
||||
|
||||
bool LECalculator::isEmpty() {
|
||||
return first == NULL;
|
||||
}
|
||||
|
||||
float LECalculator::getValue(float selfValue, Engine *engine) {
|
||||
float LECalculator::getValue(float selfValue DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
if (isEmpty()) {
|
||||
warning(CUSTOM_NO_FSIO, "no FSIO code");
|
||||
return NAN;
|
||||
|
@ -324,7 +319,7 @@ float LECalculator::getValue(float selfValue, Engine *engine) {
|
|||
if (element->action == LE_METHOD_SELF) {
|
||||
push(element->action, selfValue);
|
||||
} else {
|
||||
bool isError = processElement(engine, element);
|
||||
bool isError = processElement(element PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
if (isError) {
|
||||
// error already reported
|
||||
return NAN;
|
||||
|
@ -432,7 +427,7 @@ LEElement *LEElementPool::parseExpression(const char * line) {
|
|||
/**
|
||||
* Cannot recognize token
|
||||
*/
|
||||
warning((obd_code_e) 0, "unrecognized [%s]", parsingBuffer);
|
||||
warning(CUSTOM_ERR_6536, "unrecognized [%s]", parsingBuffer);
|
||||
return NULL;
|
||||
}
|
||||
n->init(action);
|
||||
|
|
|
@ -96,8 +96,8 @@ typedef FLStack<float, MAX_STACK_DEPTH> calc_stack_t;
|
|||
class LECalculator {
|
||||
public:
|
||||
LECalculator();
|
||||
float getValue(float selfValue, Engine *engine);
|
||||
float getValue2(float selfValue, LEElement *fistElementInList, Engine *engine);
|
||||
float getValue(float selfValue DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
float getValue2(float selfValue, LEElement *fistElementInList DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
void add(LEElement *element);
|
||||
bool isEmpty();
|
||||
void reset();
|
||||
|
@ -107,7 +107,7 @@ public:
|
|||
int currentCalculationLogPosition;
|
||||
private:
|
||||
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);
|
||||
LEElement *first;
|
||||
calc_stack_t stack;
|
||||
|
|
|
@ -74,8 +74,7 @@ EXTERN_ENGINE
|
|||
#if EFI_PROD_CODE || EFI_SIMULATOR
|
||||
static Logging *logger;
|
||||
|
||||
float getLEValue(Engine *engine, calc_stack_t *s, le_action_e action) {
|
||||
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
|
||||
float getEngineValue(le_action_e action DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
efiAssert(engine!=NULL, "getLEValue", NAN);
|
||||
switch (action) {
|
||||
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]));
|
||||
fvalue = NAN;
|
||||
} 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;
|
||||
|
||||
|
@ -301,11 +300,11 @@ static const char * action2String(le_action_e action) {
|
|||
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) {
|
||||
warning(CUSTOM_OBD_11, "invalid expression for %s", msg);
|
||||
} 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 (isRunningBenchTest()) {
|
||||
return; // let's not mess with bench testing
|
||||
|
@ -342,7 +341,7 @@ void runFsio(void) {
|
|||
|
||||
#if EFI_FUEL_PUMP || defined(__DOXYGEN__)
|
||||
if (boardConfiguration->fuelPumpPin != GPIO_UNASSIGNED) {
|
||||
setPinState("pump", &enginePins.fuelPumpRelay, fuelPumpLogic, engine);
|
||||
setPinState("pump", &enginePins.fuelPumpRelay, fuelPumpLogic);
|
||||
}
|
||||
#endif /* EFI_FUEL_PUMP */
|
||||
|
||||
|
@ -355,7 +354,7 @@ void runFsio(void) {
|
|||
enginePins.o2heater.setValue(engine->rpmCalculator.isRunning());
|
||||
|
||||
if (boardConfiguration->acRelayPin != GPIO_UNASSIGNED) {
|
||||
setPinState("A/C", &enginePins.acRelay, acRelayLogic, engine);
|
||||
setPinState("A/C", &enginePins.acRelay, acRelayLogic);
|
||||
}
|
||||
|
||||
// if (boardConfiguration->alternatorControlPin != GPIO_UNASSIGNED) {
|
||||
|
@ -363,7 +362,7 @@ void runFsio(void) {
|
|||
// }
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
static void rpnEval(char *line, Engine *engine) {
|
||||
static void rpnEval(char *line) {
|
||||
#if EFI_PROD_CODE || EFI_SIMULATOR
|
||||
line = unquote(line);
|
||||
scheduleMsg(logger, "Parsing [%s]", line);
|
||||
|
@ -477,7 +476,7 @@ static void rpnEval(char *line, Engine *engine) {
|
|||
if (e == NULL) {
|
||||
scheduleMsg(logger, "parsing failed");
|
||||
} else {
|
||||
float result = evalCalc.getValue2(0, e, engine);
|
||||
float result = evalCalc.getValue2(0, e PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
scheduleMsg(logger, "Evaluate result: %f", result);
|
||||
}
|
||||
#endif
|
||||
|
@ -530,11 +529,11 @@ void initFsioImpl(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
#endif /* EFI_PROD_CODE */
|
||||
|
||||
#if EFI_PROD_CODE || EFI_SIMULATOR
|
||||
addConsoleActionSSP("set_rpn_expression", (VoidCharPtrCharPtrVoidPtr) setFsioExpression, engine);
|
||||
addConsoleActionSS("set_rpn_expression", (VoidCharPtrCharPtr) setFsioExpression);
|
||||
addConsoleActionFF("set_fsio_setting", setFsioSetting);
|
||||
addConsoleAction("fsioinfo", showFsioInfo);
|
||||
addConsoleActionSP("rpn_eval", (VoidCharPtrVoidPtr) rpnEval, engine);
|
||||
#endif
|
||||
addConsoleActionS("rpn_eval", (VoidCharPtr) rpnEval);
|
||||
#endif /* EFI_PROD_CODE || EFI_SIMULATOR */
|
||||
|
||||
fsioTable1.init(config->fsioTable1, config->fsioTable1LoadBins,
|
||||
config->fsioTable1RpmBins);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
||||
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 setFsioExt(int index, brain_pin_e pin, const char * exp, int freq DECLARE_ENGINE_PARAMETER_SUFFIX);
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "test_logic_expression.h"
|
||||
#include "fsio_impl.h"
|
||||
#include "cli_registry.h"
|
||||
#include "engine_test_helper.h"
|
||||
|
||||
#define TEST_POOL_SIZE 256
|
||||
|
||||
|
@ -19,7 +20,7 @@ static float mockFan;
|
|||
static float mockRpm;
|
||||
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) {
|
||||
case LE_METHOD_FAN:
|
||||
return mockFan;
|
||||
|
@ -91,7 +92,11 @@ static void testExpression2(float selfValue, const char *line, float expected) {
|
|||
print("Parsing [%s]", line);
|
||||
assertTrueM("Not NULL expected", element != NULL);
|
||||
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) {
|
||||
|
@ -103,13 +108,16 @@ void testLogicExpressions(void) {
|
|||
|
||||
testParsing();
|
||||
|
||||
EngineTestHelper eth(FORD_INLINE_6_1995);
|
||||
EXPAND_EngineTestHelper;
|
||||
|
||||
LECalculator c;
|
||||
|
||||
LEElement value1;
|
||||
value1.init(LE_NUMERIC_VALUE, 123.0);
|
||||
c.add(&value1);
|
||||
|
||||
assertEqualsM("123", 123.0, c.getValue(0, NULL));
|
||||
assertEqualsM("123", 123.0, c.getValue(0 PASS_ENGINE_PARAMETER_SUFFIX));
|
||||
|
||||
LEElement value2;
|
||||
value2.init(LE_NUMERIC_VALUE, 321.0);
|
||||
|
@ -118,7 +126,7 @@ void testLogicExpressions(void) {
|
|||
LEElement value3;
|
||||
value3.init(LE_OPERATOR_AND);
|
||||
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)
|
||||
|
@ -183,7 +191,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(0, element, NULL));
|
||||
assertEqualsM("that expression", 1, c.getValue2(0, element PASS_ENGINE_PARAMETER_SUFFIX));
|
||||
|
||||
assertEquals(12, c.currentCalculationLogPosition);
|
||||
assertEquals(102, c.calcLogAction[0]);
|
||||
|
|
Loading…
Reference in New Issue