merge alive_checker and watchdog to alive class
This commit is contained in:
		
							
								
								
									
										178
									
								
								306-controller_interface.X/middleware/alive.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										178
									
								
								306-controller_interface.X/middleware/alive.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,178 @@ | ||||
| /** | ||||
|  * @author R<>mi Heredero | ||||
|  * @version 1.0.0 | ||||
|  * @date August 2023 | ||||
|  * @file alive.h | ||||
|  */ | ||||
| #ifndef ALIVE_H | ||||
| #define ALIVE_H | ||||
|  | ||||
| #include "../xf/xf.h" | ||||
|  | ||||
| typedef enum { | ||||
|     STAL_INIT, | ||||
|     STAL_SETUP, | ||||
|     STAL_BORN, | ||||
|     STAL_WAIT, | ||||
|     STAL_DEAD, | ||||
|     STAL_ALIVE, | ||||
|     STAL_BREAK | ||||
| } ALIVE_STATES; | ||||
|  | ||||
| typedef enum { | ||||
|     evALinitChecker = 15, | ||||
|     evALinitSender, | ||||
|     evALborn, | ||||
|     evALready, | ||||
|     evALpoll, | ||||
|     evALstart | ||||
| } ALIVE_EVENTS; | ||||
|  | ||||
| typedef void (*ALIVE_CALLBACK_FUNCTION)(void*); | ||||
| typedef struct { | ||||
|     ALIVE_CALLBACK_FUNCTION f; // function | ||||
|     void* p; // param(s) | ||||
| } ALIVE_CALLBACK; | ||||
|  | ||||
| typedef struct { | ||||
|     ALIVE_STATES state; | ||||
|     bool isAlive; | ||||
|     bool checker; | ||||
|     bool sender; | ||||
|     bool haveBreak; | ||||
|     uint8_t aliveTime; | ||||
|     ALIVE_CALLBACK setup; | ||||
|     ALIVE_CALLBACK born; | ||||
|     ALIVE_CALLBACK wait; | ||||
|     ALIVE_CALLBACK dead; | ||||
|     ALIVE_CALLBACK alive; | ||||
|     ALIVE_CALLBACK break_cb; | ||||
| } ALIVE; | ||||
|  | ||||
| /** | ||||
|  * Initialize the ALIVE | ||||
|  * @param me the ALIVE itself | ||||
|  */ | ||||
| void ALIVE_init(ALIVE* me); | ||||
|  | ||||
| /** | ||||
|  * Start the ALIVE state machine for checker part | ||||
|  * @param me the ALIVE itself | ||||
|  */ | ||||
| void ALIVE_startBehaviourChecker(ALIVE* me); | ||||
|  | ||||
| /** | ||||
|  * Start the ALIVE state machine for sender part | ||||
|  * @param me the ALIVE itself | ||||
|  */ | ||||
| void ALIVE_startBehaviourSender(ALIVE* me); | ||||
|  | ||||
| /** | ||||
|  * Process the event | ||||
|  * @param ev the event to process | ||||
|  * @return true if the event is processed | ||||
|  */ | ||||
| bool ALIVE_processEvent(Event* ev); | ||||
|  | ||||
| /************* | ||||
|  * Callbacks * | ||||
|  *************/ | ||||
|  | ||||
| /** | ||||
|  * Set the callback function to call when the ALIVE is entering state setup | ||||
|  * @param me the ALIVE itself | ||||
|  * @param f the function to call | ||||
|  * @param p the param(s) to pass to the function | ||||
|  */ | ||||
| void ALIVE_onSetup(ALIVE* me, ALIVE_CALLBACK_FUNCTION f, void* p); | ||||
|  | ||||
| /** | ||||
|  * Set the callback function to call when the ALIVE is entering state born | ||||
|  * @param me the ALIVE itself | ||||
|  * @param f the function to call | ||||
|  * @param p the param(s) to pass to the function | ||||
|  */ | ||||
| void ALIVE_onBorn(ALIVE* me, ALIVE_CALLBACK_FUNCTION f, void* p); | ||||
|  | ||||
| /** | ||||
|  * Set the callback function to call when the ALIVE is entering state wait | ||||
|  * @param me the ALIVE itself | ||||
|  * @param f the function to call | ||||
|  * @param p the param(s) to pass to the function | ||||
|  */ | ||||
| void ALIVE_onWait(ALIVE* me, ALIVE_CALLBACK_FUNCTION f, void* p); | ||||
|  | ||||
| /** | ||||
|  * Set the callback function to call when the ALIVE is entering state dead | ||||
|  * @param me the ALIVE itself | ||||
|  * @param f the function to call | ||||
|  * @param p the param(s) to pass to the function | ||||
|  */ | ||||
| void ALIVE_onDead(ALIVE* me, ALIVE_CALLBACK_FUNCTION f, void* p); | ||||
|  | ||||
| /** | ||||
|  * Set the callback function to call when the ALIVE is entering state alive | ||||
|  * @param me the ALIVE itself | ||||
|  * @param f the function to call | ||||
|  * @param p the param(s) to pass to the function | ||||
|  */ | ||||
| void ALIVE_onAlive(ALIVE* me, ALIVE_CALLBACK_FUNCTION f, void* p); | ||||
|  | ||||
| /** | ||||
|  * Set the callback function to call when the ALIVE is entering state break | ||||
|  * @param me the ALIVE itself | ||||
|  * @param f the function to call | ||||
|  * @param p the param(s) to pass to the function | ||||
|  */ | ||||
| void ALIVE_onBreak(ALIVE* me, ALIVE_CALLBACK_FUNCTION f, void* p); | ||||
|  | ||||
| /************ | ||||
|  * EMITTERS * | ||||
|  ************/ | ||||
|  | ||||
| /** | ||||
|  * Emit the born event | ||||
|  * @param me the ALIVE itself | ||||
|  * @param t time to wait in ms before triggering event | ||||
|  * @param data data to put on the event for XF | ||||
|  */ | ||||
| void ALIVE_emitBorn(ALIVE* me, uint16_t t, int64_t data); | ||||
|  | ||||
| /** | ||||
|  * Emit the ready event | ||||
|  * @param me the ALIVE itself | ||||
|  * @param t time to wait in ms before triggering event | ||||
|  * @param data data to put on the event for XF | ||||
|  */ | ||||
| void ALIVE_emitReady(ALIVE* me, uint16_t t, int64_t data); | ||||
|  | ||||
| /** | ||||
|  * Emit the poll event | ||||
|  * @param me the ALIVE itself | ||||
|  * @param t time to wait in ms before triggering event | ||||
|  * @param data data to put on the event for XF | ||||
|  */ | ||||
| void ALIVE_emitPoll(ALIVE* me, uint16_t t, int64_t data); | ||||
|  | ||||
| /** | ||||
|  * Emit the start event | ||||
|  * @param me the ALIVE itself | ||||
|  * @param t time to wait in ms before triggering event | ||||
|  * @param data data to put on the event for XF | ||||
|  */ | ||||
| void ALIVE_emitStart(ALIVE* me, uint16_t t, int64_t data); | ||||
|  | ||||
|  | ||||
| /*********** | ||||
|  * SETTERS * | ||||
|  ***********/ | ||||
|  | ||||
| void ALIVE_setIsAlive(ALIVE* me, bool v); | ||||
|  | ||||
| void ALIVE_setHaveBreak(ALIVE* me, bool v); | ||||
|  | ||||
| void ALIVE_setAliveTime(ALIVE* me, uint8_t v); | ||||
|  | ||||
| void ALIVE_ISALIVE(ALIVE* me); | ||||
|  | ||||
| #endif | ||||
		Reference in New Issue
	
	Block a user