add alive_checker
This commit is contained in:
134
306-controller_interface.X/middleware/alive_checker.h
Normal file
134
306-controller_interface.X/middleware/alive_checker.h
Normal file
@@ -0,0 +1,134 @@
|
||||
/**
|
||||
* @author R<>mi Heredero
|
||||
* @version 1.0.0
|
||||
* @date August 2023
|
||||
* @file alive_checker.h
|
||||
*/
|
||||
#ifndef ALIVE_CHECKER_H
|
||||
#define ALIVE_CHECKER_H
|
||||
|
||||
#include "../xf/xf.h"
|
||||
|
||||
typedef enum {
|
||||
STAC_INIT,
|
||||
STAC_SETUP,
|
||||
STAC_BORN,
|
||||
STAC_WAIT,
|
||||
STAC_DEAD
|
||||
} ALIVE_CHECKER_STATES;
|
||||
|
||||
typedef enum {
|
||||
evACinit = 100, // TODO change this number (< 256)
|
||||
evACborn,
|
||||
evACready,
|
||||
evACpoll
|
||||
} ALIVE_CHECKER_EVENTS;
|
||||
|
||||
typedef void (*ALIVE_CHECKER_CALLBACK_FUNCTION)(void*);
|
||||
typedef struct {
|
||||
ALIVE_CHECKER_CALLBACK_FUNCTION f; // function
|
||||
void* p; // param(s)
|
||||
} ALIVE_CHECKER_CALLBACK;
|
||||
|
||||
typedef struct {
|
||||
ALIVE_CHECKER_STATES state;
|
||||
bool isAlive;
|
||||
uint8_t aliveTime;
|
||||
ALIVE_CHECKER_CALLBACK setup;
|
||||
ALIVE_CHECKER_CALLBACK born;
|
||||
ALIVE_CHECKER_CALLBACK wait;
|
||||
ALIVE_CHECKER_CALLBACK dead;
|
||||
} ALIVE_CHECKER;
|
||||
|
||||
/**
|
||||
* Initialize the ALIVE_CHECKER
|
||||
* @param me the ALIVE_CHECKER itself
|
||||
*/
|
||||
void ALIVE_CHECKER_init(ALIVE_CHECKER* me);
|
||||
|
||||
/**
|
||||
* Start the ALIVE_CHECKER state machine
|
||||
* @param me the ALIVE_CHECKER itself
|
||||
*/
|
||||
void ALIVE_CHECKER_startBehaviour(ALIVE_CHECKER* me);
|
||||
|
||||
/**
|
||||
* Process the event
|
||||
* @param ev the event to process
|
||||
* @return true if the event is processed
|
||||
*/
|
||||
bool ALIVE_CHECKER_processEvent(Event* ev);
|
||||
|
||||
/*************
|
||||
* Callbacks *
|
||||
*************/
|
||||
|
||||
/**
|
||||
* Set the callback function to call when the ALIVE_CHECKER is entering state setup
|
||||
* @param me the ALIVE_CHECKER itself
|
||||
* @param f the function to call
|
||||
* @param p the param(s) to pass to the function
|
||||
*/
|
||||
void ALIVE_CHECKER_onSetup(ALIVE_CHECKER* me, ALIVE_CHECKER_CALLBACK_FUNCTION f, void* p);
|
||||
|
||||
/**
|
||||
* Set the callback function to call when the ALIVE_CHECKER is entering state born
|
||||
* @param me the ALIVE_CHECKER itself
|
||||
* @param f the function to call
|
||||
* @param p the param(s) to pass to the function
|
||||
*/
|
||||
void ALIVE_CHECKER_onBorn(ALIVE_CHECKER* me, ALIVE_CHECKER_CALLBACK_FUNCTION f, void* p);
|
||||
|
||||
/**
|
||||
* Set the callback function to call when the ALIVE_CHECKER is entering state wait
|
||||
* @param me the ALIVE_CHECKER itself
|
||||
* @param f the function to call
|
||||
* @param p the param(s) to pass to the function
|
||||
*/
|
||||
void ALIVE_CHECKER_onWait(ALIVE_CHECKER* me, ALIVE_CHECKER_CALLBACK_FUNCTION f, void* p);
|
||||
|
||||
/**
|
||||
* Set the callback function to call when the ALIVE_CHECKER is entering state dead
|
||||
* @param me the ALIVE_CHECKER itself
|
||||
* @param f the function to call
|
||||
* @param p the param(s) to pass to the function
|
||||
*/
|
||||
void ALIVE_CHECKER_onDead(ALIVE_CHECKER* me, ALIVE_CHECKER_CALLBACK_FUNCTION f, void* p);
|
||||
|
||||
/************
|
||||
* EMITTERS *
|
||||
************/
|
||||
|
||||
/**
|
||||
* Emit the born event
|
||||
* @param me the ALIVE_CHECKER itself
|
||||
* @param t time to wait in ms before triggering event
|
||||
* @param data data to put on the event for XF
|
||||
*/
|
||||
void ALIVE_CHECKER_emitBorn(ALIVE_CHECKER* me, uint16_t t, int64_t data);
|
||||
|
||||
/**
|
||||
* Emit the ready event
|
||||
* @param me the ALIVE_CHECKER itself
|
||||
* @param t time to wait in ms before triggering event
|
||||
* @param data data to put on the event for XF
|
||||
*/
|
||||
void ALIVE_CHECKER_emitReady(ALIVE_CHECKER* me, uint16_t t, int64_t data);
|
||||
|
||||
/**
|
||||
* Emit the poll event
|
||||
* @param me the ALIVE_CHECKER itself
|
||||
* @param t time to wait in ms before triggering event
|
||||
* @param data data to put on the event for XF
|
||||
*/
|
||||
void ALIVE_CHECKER_emitPoll(ALIVE_CHECKER* me, uint16_t t, int64_t data);
|
||||
|
||||
/***********
|
||||
* SETTERS *
|
||||
***********/
|
||||
|
||||
void ALIVE_CHECKER_setAliveTime(ALIVE_CHECKER* me, uint8_t v);
|
||||
void ALIVE_CHECKER_setIsAlive(ALIVE_CHECKER* me, bool v);
|
||||
void ALIVE_CHECKER_ISALIVE(ALIVE_CHECKER* me); // Use this one when you receive CAN message
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user