SAE Teensy ECU
IIT SAE Microcontroller programming
Loading...
Searching...
No Matches
State.h
Go to the documentation of this file.
1
22#ifndef __ECU_STATE_H__
23#define __ECU_STATE_H__
24
25#include <stdint.h>
26#include <stdlib.h>
27#include <typeinfo>
28
29#include "Log.h"
30#include "PPHelp.h"
31
38namespace State {
39
44enum NotifyValue : int {
60 E_FATAL = 0xFA7A1,
64 E_RESTART = 2357427,
65};
66
70struct State_t {
71protected:
77 int getNotify(void);
78
84 void notify(int notify);
85
86public:
90 int notifyCode = 0;
91
95 LOG_TAG ID = "ID NOT SET";
96
102 virtual State_t *run(void);
103
109 virtual LOG_TAG getID(void);
110
117};
118
124void begin(State_t &entry);
125
126} // namespace State
127
128#endif // __ECU_STATE_H__
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
Compilation of various helpful preprocessor macros.
A state machine implementation, refer to State.h for more info.
Definition State.h:38
NotifyValue
Common codes that can be used by states.
Definition State.h:44
@ E_RESTART
Special code that makes the state machine start from the first state again.
Definition State.h:64
@ E_ERROR
An error has occurred, attempt to skip the state.
Definition State.h:56
@ E_CONTINUE
An error has occurred but we can continue normally.
Definition State.h:52
@ E_NOERR
No error has occurred.
Definition State.h:48
@ E_FATAL
Special code that makes the state machine completely stop.
Definition State.h:60
void begin(State_t &entry)
Begin the state machine with a pointer to a state.
The parent state structure to extend from to create more states.
Definition State.h:70
int notifyCode
Used for receiving values from other states.
Definition State.h:90
void notify(int notify)
Send a code to the next state.
LOG_TAG ID
The unique ID of the state, used for logging.
Definition State.h:95
virtual LOG_TAG getID(void)
Returns the LOG_TAG of the state.
virtual State_t * run(void)
Runs the state.
State_t * getLastState()
Get a pointer of the last state.
int getNotify(void)
Get the code of the previous state.