fome-fw/firmware/controllers/core/logic_expression.h

110 lines
2.2 KiB
C
Raw Normal View History

2014-10-03 12:05:03 -07:00
/**
* @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"
2014-10-05 07:03:00 -07:00
#include "engine.h"
2014-10-03 12:05:03 -07:00
typedef enum {
2014-10-03 16:03:06 -07:00
2014-10-05 07:03:00 -07:00
LE_UNDEFINED = 0 ,
LE_NUMERIC_VALUE = 1,
LE_OPERATOR_LESS = 2,
LE_OPERATOR_MORE = 3,
LE_OPERATOR_LESS_OR_EQUAL = 4,
LE_OPERATOR_MORE_OR_EQUAL = 5,
LE_OPERATOR_AND = 6,
LE_OPERATOR_OR = 7,
LE_OPERATOR_NOT = 8,
2014-11-18 18:05:41 -08:00
LE_OPERATOR_ADDITION = 9,
LE_OPERATOR_SUBSTRACTION = 10,
LE_OPERATOR_MULTIPLICATION = 11,
LE_OPERATOR_DIVISION = 12,
2014-10-05 07:03:00 -07:00
LE_METHOD_RPM = 100,
LE_METHOD_COOLANT = 101,
LE_METHOD_FAN = 102,
LE_METHOD_TIME_SINCE_BOOT = 103,
LE_METHOD_FAN_ON_SETTING = 104,
LE_METHOD_FAN_OFF_SETTING = 105,
2014-10-06 00:03:15 -07:00
LE_METHOD_TPS = 106,
LE_METHOD_MAF = 107,
LE_METHOD_INTAKE_AIR = 108,
2014-11-06 10:04:30 -08:00
LE_METHOD_VBATT = 109,
2014-10-03 12:05:03 -07:00
2014-10-05 07:03:00 -07:00
Force_4b_le_action = ENUM_SIZE_HACK,
2014-10-03 15:03:01 -07:00
2014-10-03 12:05:03 -07:00
} 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;
};
2014-10-03 15:03:01 -07:00
class LEElementPool {
public:
2014-11-17 13:03:20 -08:00
LEElementPool(LEElement *pool, int size);
2014-11-17 12:03:37 -08:00
LEElement *pool;
2014-10-03 15:03:01 -07:00
LEElement *next();
void reset();
2014-11-18 13:03:12 -08:00
LEElement * parseExpression(const char * line);
2014-10-03 15:03:01 -07:00
private:
int index;
2014-11-17 12:03:37 -08:00
int size;
2014-10-03 15:03:01 -07:00
};
2014-10-03 12:05:03 -07:00
#define MAX_STACK_DEPTH 32
class LECalculator {
public:
LECalculator();
2014-10-06 05:03:03 -07:00
float getValue(Engine *engine);
2014-10-18 04:03:25 -07:00
float getValue2(LEElement *element, Engine *engine);
2014-10-03 12:05:03 -07:00
void add(LEElement *element);
2014-10-03 15:03:01 -07:00
void reset();
2014-10-06 02:03:01 -07:00
void reset(LEElement *element);
2014-10-03 12:05:03 -07:00
private:
2014-10-06 05:03:03 -07:00
void doJob(Engine *engine, LEElement *element);
2014-10-07 08:04:35 -07:00
float pop(le_action_e action);
2014-10-03 15:03:01 -07:00
LEElement *first;
2014-10-03 12:05:03 -07:00
FLStack<float, MAX_STACK_DEPTH> stack;
};
2014-10-04 15:03:07 -07:00
class LENameOrdinalPair {
public:
LENameOrdinalPair(le_action_e action, const char *name);
LENameOrdinalPair *next;
le_action_e action;
const char *name;
};
2014-11-17 12:03:37 -08:00
/**
* This method extract the first token on the line into the specified buffer
*
* @return pointer after the token
*/
const char *getNextToken(const char *line, char *buffer);
2014-10-04 11:02:53 -07:00
bool isNumeric(const char* line);
le_action_e parseAction(const char * line);
2014-11-18 12:03:13 -08:00
void initEval(Engine *engine);
2014-10-04 08:03:38 -07:00
2014-10-03 12:05:03 -07:00
#endif /* LOGIC_EXPRESSION_H_ */