SAE Teensy ECU
IIT SAE Microcontroller programming
Loading...
Searching...
No Matches
ECUStates.hpp
1#include <stdint.h>
2#include <stdlib.h>
3
4#include "WProgram.h"
5
6#include "Canbus.h"
7#include "Log.h"
8#include "Pins.h"
9#include "State.h"
10
14namespace ECUStates {
15
20static struct Initialize_State : State::State_t {
21 LOG_TAG ID = "Teensy Initializing State";
22 State::State_t *run(void);
23 LOG_TAG getID(void) { return ID; }
24} Initialize_State;
25
30static struct PreCharge_State : State::State_t {
31private: // NOTE: defining as a number runs Buffer constructor to 'convert' it to a Buffer struct
32 Canbus::Buffer BMS_DATA_Buffer = ADD_BMS_DATA;
33 Canbus::Buffer MC0_VOLT_Buffer = ADD_MC0_VOLT;
34 Canbus::Buffer MC1_VOLT_Buffer = ADD_MC1_VOLT;
35 State::State_t *PreCharFault();
36 bool voltageCheck();
37
38public:
39 LOG_TAG ID = "PreCharge State";
40 State::State_t *run(void);
41 LOG_TAG getID(void) { return ID; }
42} PreCharge_State;
43
49static struct Idle_State : State::State_t {
50 LOG_TAG ID = "Idle State";
51 State::State_t *run(void);
52 LOG_TAG getID(void) { return ID; }
53} Idle_State;
54
59static struct Charging_State : State::State_t {
60 LOG_TAG ID = "Charging State";
61 bool ChargingOn;
62 bool fault = false;
63 String Voltage_Data = " ";
64
65 State::State_t *run(void);
66 LOG_TAG getID(void) { return ID; }
67
68} Charging_State;
69
74static struct Button_State : State::State_t {
75 LOG_TAG ID = "Button State";
76 State::State_t *run(void);
77 LOG_TAG getID(void) { return ID; }
78
79} Button_State;
80
86static struct Driving_Mode_State : State::State_t {
87private:
88 Canbus::Buffer MC0_VOLT_Buffer = ADD_MC0_VOLT;
89 Canbus::Buffer MC1_VOLT_Buffer = ADD_MC1_VOLT;
90 void carCooling(bool enable);
91 State::State_t *DrivingModeFault(void);
92
93public:
94 LOG_TAG ID = "Driving Mode State";
95 bool MessageIncoming = false;
96 bool Fault = false;
97 String info = " ";
98 String Message_Handler = " ";
99
100 State::State_t *run(void);
101 LOG_TAG getID(void) { return ID; }
102
103} Driving_Mode_State;
104
109static struct FaultState : State::State_t {
110 LOG_TAG ID = "Fault State";
111 State::State_t *run(void);
112 LOG_TAG getID(void) { return ID; }
113} FaultState;
114
119static struct Logger_t : State::State_t {
120 LOG_TAG ID = "Logger State";
121 State::State_t *run(void);
122 LOG_TAG getID(void) { return ID; }
123} Logger;
124
128static struct Bounce_t : State::State_t {
129 LOG_TAG ID = "Bouncer State";
130 State::State_t *run(void);
131 LOG_TAG getID(void) { return ID; }
132} Bounce;
133
134} // namespace ECUStates
FlexCAN_T4 wrapper.
Special logging functionality.
const char * LOG_TAG
Type definition of logging tags This typedef is necessary to allow for easier manipulation of code by...
Definition Log.h:48
Update, set, and get predefined pin values.
State library.
The Teensy specific state declarations.
Definition ECUStates.hpp:14
Fault checking functionality.
Definition Faults.h:29
The parent state structure to extend from to create more states.
Definition State.h:70