8static Canbus::Buffer MC0_VOLT_Buffer(ADD_MC0_VOLT);
9static Canbus::Buffer MC1_VOLT_Buffer(ADD_MC1_VOLT);
10static Canbus::Buffer MC0_CURR_Buffer(ADD_MC0_CURR);
11static Canbus::Buffer MC1_CURR_Buffer(ADD_MC1_CURR);
12static Canbus::Buffer MC0_TEMP2_Buffer(ADD_MC0_TEMP2);
13static Canbus::Buffer MC1_TEMP2_Buffer(ADD_MC1_TEMP2);
14static Canbus::Buffer MC0_TEMP3_Buffer(ADD_MC0_TEMP3);
15static Canbus::Buffer MC1_TEMP3_Buffer(ADD_MC1_TEMP3);
17static Canbus::Buffer BMS_DATA_Buffer(ADD_BMS_DATA);
18static Canbus::Buffer BMS_BATT_TEMP_Buffer(ADD_BMS_BATT_TEMP);
19static Canbus::Buffer BMS_CURR_LIMIT_Buffer(ADD_BMS_CURR_LIMIT);
21static uint8_t BMSSOC() {
22 return BMS_DATA_Buffer.getUByte(4) / 2;
25static uint16_t BMSVOLT() {
26 return BMS_DATA_Buffer.getShort(2) / 10;
29static uint16_t BMSAMP() {
30 return BMS_DATA_Buffer.getShort(0);
33static uint8_t BMSTempHigh() {
34 return BMS_BATT_TEMP_Buffer.getByte(4);
37static uint8_t BMSTempLow() {
38 return BMS_BATT_TEMP_Buffer.getByte(5);
41static uint16_t BMSDischargeCurrentLimit() {
42 return BMS_CURR_LIMIT_Buffer.getShort(0);
45static uint16_t BMSChargeCurrentLimit() {
46 return BMS_CURR_LIMIT_Buffer.getShort(2);
49static uint16_t MC0BoardTemp() {
50 return MC0_TEMP2_Buffer.getShort(0) / 10;
53static uint16_t MC1BoardTemp() {
54 return MC1_TEMP2_Buffer.getShort(0) / 10;
57static uint16_t MC0MotorTemp() {
58 return MC0_TEMP3_Buffer.getShort(4) / 10;
61static uint16_t MC1MotorTemp() {
62 return MC1_TEMP3_Buffer.getShort(4) / 10;
65static uint16_t MC0Voltage() {
66 return MC0_VOLT_Buffer.getShort(0) / 10;
69static uint16_t MC1Voltage() {
70 return MC1_VOLT_Buffer.getShort(0) / 10;
73static uint16_t MC0Current() {
74 return MC0_CURR_Buffer.getShort(6) / 10;
77static uint16_t MC1Current() {
78 return MC0_CURR_Buffer.getShort(6) / 10;
81static uint32_t MCPowerValue() {
82 int MC0_PWR = MC0Voltage() * MC0Current();
83 int MC1_PWR = MC1Voltage() * MC1Current();
84 return (MC0_PWR + MC1_PWR) / 1000;
88 &ECUStates::Initialize_State,
89 &ECUStates::PreCharge_State,
90 &ECUStates::Idle_State,
91 &ECUStates::Charging_State,
92 &ECUStates::Button_State,
93 &ECUStates::Driving_Mode_State,
94 &ECUStates::FaultState,
97std::map<uint32_t, struct State::State_t *> stateMap;
101 Log.
i(ID,
"Loading State Map");
102 for (
auto state : states) {
104 Log.
d(ID,
"State Pointer", (uintptr_t)state);
105 stateMap[
TAG2NUM(state->getID())] = state;
111 Log.
p(
"state",
"Current State", currState, INTERVAL_MED_LOW_PRIORITY);
112 currentState = stateMap[currState];
116 static bool on =
false;
117 if (hasBeat && (currentState == &ECUStates::Idle_State)) {
122 Log(
"start_light",
"Start Light", on,
true);
132 Log.
p(
"mc0_dc_v",
"MC0 DC BUS Voltage", MC0Voltage(), INTERVAL_LOW_PRIORITY);
133 Log.
p(
"mc1_dc_v",
"MC1 DC BUS Voltage", MC1Voltage(), INTERVAL_LOW_PRIORITY);
134 Log.
p(
"mc0_dc_i",
"MC0 DC BUS Current", MC0Current(), INTERVAL_LOW_PRIORITY);
135 Log.
p(
"mc1_dc_i",
"MC1 DC BUS Current", MC1Current(), INTERVAL_LOW_PRIORITY);
136 Log.
p(
"mc0_brd_tmp",
"MC0 Board Temp", MC0BoardTemp(), INTERVAL_LOW_PRIORITY);
137 Log.
p(
"mc1_brd_tmp",
"MC1 Board Temp", MC1BoardTemp(), INTERVAL_LOW_PRIORITY);
138 Log.
p(
"mc0_mtr_tmp",
"MC0 Motor Temp", MC0MotorTemp(), INTERVAL_LOW_PRIORITY);
139 Log.
p(
"mc1_mtr_tmp",
"MC1 Motor Temp", MC1MotorTemp(), INTERVAL_LOW_PRIORITY);
140 Log.
p(
"mc_curr_pwr",
"MC Current Power", MCPowerValue(), INTERVAL_LOW_PRIORITY);
143 Log.
p(
"bms_soc",
"BMS State Of Charge", BMSSOC(), INTERVAL_LOW_PRIORITY);
144 Log.
p(
"bms_v",
"BMS Immediate Voltage", BMSVOLT(), INTERVAL_LOW_PRIORITY);
145 Log.
p(
"bms_avg_i",
"BMS Pack Average Current", BMSAMP(), INTERVAL_LOW_PRIORITY);
146 Log.
p(
"bms_h_tmp",
"BMS Pack Highest Temp", BMSTempHigh(), INTERVAL_LOW_PRIORITY);
147 Log.
p(
"bms_l_tmp",
"BMS Pack Lowest Temp", BMSTempLow(), INTERVAL_LOW_PRIORITY);
148 Log.
p(
"bms_dis_i_lim",
"BMS Discharge current limit", BMSDischargeCurrentLimit(), INTERVAL_LOW_PRIORITY);
149 Log.
p(
"bms_chr_i_lim",
"BMS Charge current limit", BMSChargeCurrentLimit(), INTERVAL_LOW_PRIORITY);
155static double lastBrake = 0.0, lastSteer = 0.0, lastPedal0 = 0.0, lastPedal1 = 0.0;
167 Log.
p(
"pdl_avg",
"Pedal AVG", (pedal0 + pedal1) / 2,
true);
uint32_t TAG2NUM(LOG_TAG tagValue)
Return the final numbervalue of a LOG_TAG.
Logging::Log_t Log
The global logging object.
double EMAvg(double lastVal, double newVal, int memCount)
Exponential moving average.
Various utility functions.
Name space used solely for front ECU logic.
void setChargeSignal()
Enables the charging signal dependent on the current state.
void lowPriorityValues()
Outputs values that are of lower priority.
void highPriorityValues()
Outputs values that are of higher priority.
void updateStartLight(bool hasBeat)
Update the startlight.
void loadStateMap()
Load values that ID each unique state.
void updateCurrentState()
Update and outputs the current state.
int32_t motorSpeed(int motor=-1)
Get the avg motorspeed.
void setPinValue(uint8_t GPIO_Pin, int value)
Set the pin value of a predefined pin.
int getCanPinValue(uint8_t CAN_GPIO_Pin)
Get the pin value of a predefined canbus pin.
int getPinValue(uint8_t GPIO_Pin)
Get the pin value of a predefined pin.
void setInternalValue(uint8_t Internal_Pin, int value)
Set the value of an internal pin.
void d(LOG_TAG TAG, LOG_MSG message)
Log a string using a debug tag.
void i(LOG_TAG TAG, LOG_MSG message)
Log a string using an info tag.
void p(LOG_TAG name, LOG_MSG prettyName, const uint32_t number, int mediate=false)
Post a monitored value.
The parent state structure to extend from to create more states.