auto-sync

This commit is contained in:
rusEfi 2014-10-03 17:03:01 -05:00
parent f7c3f9da20
commit d6f74ca7b4
5 changed files with 67 additions and 1 deletions

View File

@ -16,6 +16,7 @@ public:
void push(T value);
void reset();
T pop();
T get(int index);
int size();
bool isEmpty();
private:
@ -48,6 +49,10 @@ T FLStack<T, MAXSIZE>::pop() {
return values[--index];
}
template<typename T, int MAXSIZE>
T FLStack<T, MAXSIZE>::get(int index) {
return values[index];
}
template<typename T, int MAXSIZE>
int FLStack<T, MAXSIZE>::size() {

View File

@ -28,7 +28,12 @@ void LEElement::init(le_action_e action, float fValue) {
}
LECalculator::LECalculator() {
reset();
}
void LECalculator::reset() {
first = NULL;
stack.reset();
}
static bool float2bool(float v) {
@ -114,3 +119,15 @@ void LECalculator::add(LEElement *element) {
last->next = element;
}
}
LEElementPool::LEElementPool() {
reset();
}
void LEElementPool::reset() {
index = 0;
}
LEElement *LEElementPool::next() {
return &pool[index++];
}

View File

@ -21,6 +21,11 @@ typedef enum {
LE_OPERATOR_AND,
LE_OPERATOR_OR,
LE_METHOD_RPM,
LE_METHOD_COOLANT,
LE_METHOD_FAN,
LE_METHOD_TIME_SINCE_BOOT,
Force_4b_le_action = ENUM_SIZE_HACK,
} le_action_e;
@ -38,6 +43,18 @@ public:
LEElement *next;
};
#define LE_ELEMENT_POOL_SIZE 64
class LEElementPool {
public:
LEElementPool();
LEElement pool[LE_ELEMENT_POOL_SIZE];
LEElement *next();
void reset();
private:
int index;
};
#define MAX_STACK_DEPTH 32
@ -46,10 +63,11 @@ public:
LECalculator();
float getValue();
void add(LEElement *element);
LEElement *first;
void reset();
private:
void doJob(LEElement *element);
LEElement *first;
FLStack<float, MAX_STACK_DEPTH> stack;
};

View File

@ -37,6 +37,31 @@ void testLogicExpressions(void) {
* fuel_pump = time_since_boot 4 less rpm 0 more OR
*/
c.reset();
LEElementPool pool;
LEElement *e = pool.next();
e->init(LE_METHOD_TIME_SINCE_BOOT);
e = pool.next();
e->init(LE_NUMERIC_VALUE, 4);
e = pool.next();
e->init(LE_OPERATOR_LESS);
e = pool.next();
e->init(LE_METHOD_RPM);
e = pool.next();
e->init(LE_NUMERIC_VALUE, 0);
e = pool.next();
e->init(LE_OPERATOR_MORE);
e = pool.next();
e->init(LE_OPERATOR_OR);
/**
* fan = (not fan && coolant > 90) OR (fan && coolant > 85)
* fan = fan NOT coolant 90 AND more fan coolant 85 more AND OR

View File

@ -319,6 +319,7 @@ void testFLStack(void) {
int v = stack.pop();
assertEquals(234, v);
assertEquals(1, stack.size());
assertEquals(123, stack.get(0));
v = stack.pop();
assertEquals(123, v);