auto-sync

This commit is contained in:
rusEfi 2016-03-02 22:02:37 -05:00
parent 87111dc687
commit 9b56badbfd
5 changed files with 33 additions and 21 deletions

View File

@ -46,6 +46,7 @@ static LENameOrdinalPair leLessOrEquals(LE_OPERATOR_LESS_OR_EQUAL, "<=");
static LENameOrdinalPair leMax(LE_METHOD_MAX, "max"); static LENameOrdinalPair leMax(LE_METHOD_MAX, "max");
static LENameOrdinalPair leMin(LE_METHOD_MIN, "min"); static LENameOrdinalPair leMin(LE_METHOD_MIN, "min");
static LENameOrdinalPair leIf(LE_METHOD_IF, "if"); static LENameOrdinalPair leIf(LE_METHOD_IF, "if");
static LENameOrdinalPair leSelf(LE_METHOD_SELF, "self");
LENameOrdinalPair::LENameOrdinalPair(le_action_e action, const char *name) { LENameOrdinalPair::LENameOrdinalPair(le_action_e action, const char *name) {
this->action = action; this->action = action;
@ -126,7 +127,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::doJob(Engine *engine, LEElement *element) { bool LECalculator::processElement(Engine *engine, LEElement *element) {
#if EFI_PROD_CODE || defined(__DOXYGEN__) #if EFI_PROD_CODE || defined(__DOXYGEN__)
efiAssert(getRemainingStack(chThdSelf()) > 64, "FSIO logic", false); efiAssert(getRemainingStack(chThdSelf()) > 64, "FSIO logic", false);
#endif #endif
@ -260,12 +261,12 @@ bool LECalculator::doJob(Engine *engine, LEElement *element) {
return false; return false;
} }
float LECalculator::getValue2(LEElement *element, Engine *engine) { float LECalculator::getValue2(float selfValue, LEElement *fistElementInList, Engine *engine) {
reset(element); reset(fistElementInList);
return getValue(engine); return getValue(selfValue, engine);
} }
float LECalculator::getValue(Engine *engine) { float LECalculator::getValue(float selfValue, Engine *engine) {
if (first == NULL) { if (first == NULL) {
warning(OBD_PCM_Processor_Fault, "no FSIO code"); warning(OBD_PCM_Processor_Fault, "no FSIO code");
return NAN; return NAN;
@ -278,10 +279,14 @@ float LECalculator::getValue(Engine *engine) {
while (element != NULL) { while (element != NULL) {
efiAssert(counter < 200, "FSIOcount", NAN); // just in case efiAssert(counter < 200, "FSIOcount", NAN); // just in case
bool isError = doJob(engine, element); if (element->action == LE_METHOD_SELF) {
if (isError) { push(element->action, selfValue);
// error already reported } else {
return NAN; bool isError = processElement(engine, element);
if (isError) {
// error already reported
return NAN;
}
} }
element = element->next; element = element->next;
counter++; counter++;

View File

@ -30,6 +30,7 @@ typedef enum {
LE_METHOD_MAX = 13, LE_METHOD_MAX = 13,
LE_METHOD_MIN = 14, LE_METHOD_MIN = 14,
LE_METHOD_IF = 15, LE_METHOD_IF = 15,
LE_METHOD_SELF = 16,
LE_METHOD_RPM = 100, LE_METHOD_RPM = 100,
LE_METHOD_COOLANT = 101, LE_METHOD_COOLANT = 101,
@ -86,8 +87,8 @@ typedef FLStack<float, MAX_STACK_DEPTH> calc_stack_t;
class LECalculator { class LECalculator {
public: public:
LECalculator(); LECalculator();
float getValue(Engine *engine); float getValue(float selfValue, Engine *engine);
float getValue2(LEElement *element, Engine *engine); float getValue2(float selfValue, LEElement *fistElementInList, Engine *engine);
void add(LEElement *element); void add(LEElement *element);
void reset(); void reset();
void reset(LEElement *element); void reset(LEElement *element);
@ -96,7 +97,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 doJob(Engine *engine, LEElement *element); bool processElement(Engine *engine, LEElement *element);
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

@ -220,7 +220,7 @@ static void handleFsio(Engine *engine, int index) {
bool isPwmMode = boardConfiguration->fsioFrequency[index] != NO_PWM; bool isPwmMode = boardConfiguration->fsioFrequency[index] != NO_PWM;
float fvalue = calc.getValue2(fsioLogics[index], engine); float fvalue = calc.getValue2(engine->engineConfiguration2->fsioLastValue[index], fsioLogics[index], engine);
engine->engineConfiguration2->fsioLastValue[index] = fvalue; engine->engineConfiguration2->fsioLastValue[index] = fvalue;
if (isPwmMode) { if (isPwmMode) {
@ -260,7 +260,7 @@ static void setPinState(const char * msg, OutputPin *pin, LEElement *element, En
if (element == NULL) { if (element == NULL) {
warning(OBD_PCM_Processor_Fault, "invalid expression for %s", msg); warning(OBD_PCM_Processor_Fault, "invalid expression for %s", msg);
} else { } else {
int value = calc.getValue2(element, engine); int value = calc.getValue2(pin->getLogicValue(), element, engine);
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
@ -417,7 +417,7 @@ static void eval(char *line, Engine *engine) {
if (e == NULL) { if (e == NULL) {
scheduleMsg(logger, "parsing failed"); scheduleMsg(logger, "parsing failed");
} else { } else {
float result = evalCalc.getValue2(e, engine); float result = evalCalc.getValue2(0, e, engine);
scheduleMsg(logger, "Eval result: %f", result); scheduleMsg(logger, "Eval result: %f", result);
} }
#endif #endif

View File

@ -275,5 +275,5 @@ int getRusEfiVersion(void) {
return 123; // this is here to make the compiler happy about the unused array return 123; // this is here to make the compiler happy about the unused array
if (UNUSED_CCM_SIZE[0] * 0 != 0) if (UNUSED_CCM_SIZE[0] * 0 != 0)
return 3211; // this is here to make the compiler happy about the unused array return 3211; // this is here to make the compiler happy about the unused array
return 20160227; return 20160302;
} }

View File

@ -84,14 +84,18 @@ static void testParsing(void) {
assertTrue(element == NULL); assertTrue(element == NULL);
} }
static void testExpression(const char *line, float expected) { static void testExpression2(float selfValue, const char *line, float expected) {
LEElement thepool[TEST_POOL_SIZE]; LEElement thepool[TEST_POOL_SIZE];
LEElementPool pool(thepool, TEST_POOL_SIZE); LEElementPool pool(thepool, TEST_POOL_SIZE);
LEElement * element = pool.parseExpression(line); LEElement * element = pool.parseExpression(line);
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(element, NULL)); assertEqualsM(line, expected, c.getValue2(selfValue, element, NULL));
}
static void testExpression(const char *line, float expected) {
testExpression2(0, line, expected);
} }
void testLogicExpressions(void) { void testLogicExpressions(void) {
@ -105,7 +109,7 @@ void testLogicExpressions(void) {
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(NULL)); assertEqualsM("123", 123.0, c.getValue(0, NULL));
LEElement value2; LEElement value2;
value2.init(LE_NUMERIC_VALUE, 321.0); value2.init(LE_NUMERIC_VALUE, 321.0);
@ -114,7 +118,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(NULL)); assertEqualsM("123 and 321", 1.0, c.getValue(0, NULL));
/** /**
* fuel_pump = (time_since_boot < 4 seconds) OR (rpm > 0) * fuel_pump = (time_since_boot < 4 seconds) OR (rpm > 0)
@ -170,6 +174,8 @@ void testLogicExpressions(void) {
testExpression("100 200 1 if", 200); testExpression("100 200 1 if", 200);
testExpression("10 99 max", 99); testExpression("10 99 max", 99);
testExpression2(123, "10 self max", 123);
testExpression("fan NOT coolant 90 > AND fan coolant 85 > AND OR", 1); testExpression("fan NOT coolant 90 > AND fan coolant 85 > AND OR", 1);
{ {
LEElement thepool[TEST_POOL_SIZE]; LEElement thepool[TEST_POOL_SIZE];
@ -177,7 +183,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(element, NULL)); assertEqualsM("that expression", 1, c.getValue2(0, element, NULL));
assertEquals(12, c.currentCalculationLogPosition); assertEquals(12, c.currentCalculationLogPosition);
assertEquals(102, c.calcLogAction[0]); assertEquals(102, c.calcLogAction[0]);