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

168 lines
3.5 KiB
C
Raw Normal View History

2015-07-10 06:01:56 -07:00
/**
* @file fsio_core.h
*
* @date Oct 3, 2014
2020-01-13 18:57:43 -08:00
* @author Andrey Belomutskiy, (c) 2012-2020
2015-07-10 06:01:56 -07:00
*/
2020-03-28 16:49:36 -07:00
#pragma once
2015-07-10 06:01:56 -07:00
#include "engine.h"
2020-05-21 22:03:27 -07:00
#include "fl_stack.h"
2015-07-10 06:01:56 -07:00
2016-07-05 11:02:26 -07:00
#define MAX_TABLE_INDEX 4
2015-07-10 06:01:56 -07:00
typedef enum {
LE_UNDEFINED = 0,
LE_METHOD_RETURN = 130,
2015-07-10 06:01:56 -07:00
LE_NUMERIC_VALUE = 1,
LE_BOOLEAN_VALUE = 126,
2015-07-10 06:01:56 -07:00
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,
LE_OPERATOR_ADDITION = 9,
LE_OPERATOR_SUBTRACTION = 10,
LE_OPERATOR_MULTIPLICATION = 11,
LE_OPERATOR_DIVISION = 12,
LE_METHOD_MAX = 13,
LE_METHOD_MIN = 14,
LE_METHOD_IF = 15,
LE_METHOD_RPM = 100,
LE_METHOD_COOLANT = 101,
LE_METHOD_FAN = 102,
LE_METHOD_TIME_SINCE_BOOT = 103,
LE_METHOD_TPS = 106,
LE_METHOD_MAF = 107,
LE_METHOD_INTAKE_AIR = 108,
LE_METHOD_VBATT = 109,
LE_METHOD_AC_TOGGLE = 110,
2019-09-08 18:05:03 -07:00
LE_METHOD_TIME_SINCE_AC_TOGGLE = 111,
2015-07-10 06:01:56 -07:00
LE_METHOD_KNOCK = 112,
2016-03-22 00:03:22 -07:00
LE_METHOD_FSIO_TABLE = 113,
LE_METHOD_SELF = 114,
2016-07-07 20:01:43 -07:00
LE_METHOD_MAP = 115,
2016-10-22 21:03:08 -07:00
LE_METHOD_FSIO_ANALOG_INPUT = 116,
2016-12-17 09:03:02 -08:00
LE_METHOD_INTAKE_VVT = 117,
LE_METHOD_EXHAUST_VVT = 118,
2017-06-04 12:00:19 -07:00
LE_METHOD_IS_COOLANT_BROKEN = 119,
2017-06-14 02:39:00 -07:00
LE_METHOD_CRANKING_RPM = 120,
LE_METHOD_STARTUP_FUEL_PUMP_DURATION = 121,
LE_METHOD_IN_SHUTDOWN = 122,
LE_METHOD_FSIO_DIGITAL_INPUT = 123,
2019-09-08 18:05:03 -07:00
LE_METHOD_FSIO_SETTING = 124,
2020-04-10 14:46:56 -07:00
LE_METHOD_PPS = 125,
LE_METHOD_TIME_SINCE_TRIGGER_EVENT = 127,
2021-01-10 17:30:08 -08:00
LE_METHOD_IN_MR_BENCH = 128,
LE_METHOD_FUEL_FLOW_RATE = 131,
LE_METHOD_OIL_PRESSURE = 132,
2015-07-10 06:01:56 -07:00
2019-09-10 19:55:58 -07:00
#include "fsio_enums_generated.def"
2015-07-10 06:01:56 -07:00
Force_4b_le_action = ENUM_32_BITS,
} le_action_e;
// This type borrows the least significant bit of a float and uses it to indicate
// whether it's actually a boolean hiding inside that float
class FsioValue
{
public:
/*implicit*/ FsioValue(float f);
/*implicit*/ FsioValue(bool b);
bool isFloat() const;
float asFloat() const;
bool isBool() const;
bool asBool() const;
private:
// These must match for this trick to work!
static_assert(sizeof(float) == sizeof(uint32_t));
union
{
uint32_t u32;
float f32;
} u;
};
using FsioResult = expected<float>;
2015-07-10 06:01:56 -07:00
class LEElement {
public:
LEElement();
2016-04-19 17:03:53 -07:00
void clear();
2015-07-10 06:01:56 -07:00
void init(le_action_e action);
void init(le_action_e action, float value);
void init(le_action_e action, bool value);
2015-07-10 06:01:56 -07:00
le_action_e action;
float fValue;
};
class LEElementPool {
public:
LEElementPool(LEElement *pool, int size);
2015-07-10 06:01:56 -07:00
void reset();
LEElement * parseExpression(const char * line);
int getSize() const;
2015-07-10 06:01:56 -07:00
private:
LEElement* m_pool;
LEElement* m_nextFree;
2015-07-10 06:01:56 -07:00
int size;
};
#define MAX_STACK_DEPTH 32
typedef FLStack<float, MAX_STACK_DEPTH> calc_stack_t;
#define MAX_CALC_LOG 64
class LECalculator {
public:
LECalculator();
2021-02-23 13:57:14 -08:00
float evaluate(float selfValue, const LEElement* element DECLARE_ENGINE_PARAMETER_SUFFIX);
2015-07-10 06:01:56 -07:00
void reset();
// Log history of calculation actions for debugging
2015-07-10 06:01:56 -07:00
le_action_e calcLogAction[MAX_CALC_LOG];
float calcLogValue[MAX_CALC_LOG];
int currentCalculationLogPosition;
2015-07-10 06:01:56 -07:00
private:
void push(le_action_e action, float value);
FsioResult processElement(const LEElement* element DECLARE_ENGINE_PARAMETER_SUFFIX);
2015-07-10 06:01:56 -07:00
float pop(le_action_e action);
2015-07-10 06:01:56 -07:00
calc_stack_t stack;
};
class LENameOrdinalPair {
public:
LENameOrdinalPair(le_action_e action, const char *name);
LENameOrdinalPair *next;
le_action_e action;
const char *name;
};
/**
* 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, const int bufferSize);
bool isNumeric(const char* line);
le_action_e parseAction(const char * line);
bool float2bool(float v);