This repository has been archived on 2024-01-25. You can view files and clone it, but cannot push or open issues or pull requests.
SummerSchool2-Controller/306-controller_interface.X/middleware/alive.h

192 lines
4.4 KiB
C
Raw Permalink Normal View History

/**
* @author R<EFBFBD>mi Heredero
* @version 1.0.0
* @date August 2023
* @file alive.h
*/
#ifndef ALIVE_H
#define ALIVE_H
#include "../xf/xf.h"
2023-09-05 06:52:27 +00:00
#include "../board/led/led.h"
#include "../middleware/blinker.h"
typedef enum {
2023-09-04 17:51:19 +00:00
STAL_INIT = 20,
STAL_SETUP,
STAL_BORN,
STAL_WAIT,
STAL_DEAD,
STAL_ALIVE,
STAL_BREAK
} ALIVE_STATES;
typedef enum {
2023-09-04 17:51:19 +00:00
evALinitChecker = 20,
evALinitSender,
evALborn,
evALready,
evALpoll,
2023-08-31 18:01:39 +00:00
evALstart,
evALresurrect
} 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;
2023-09-05 06:52:27 +00:00
LED debugLed;
BLINKER debugBlinker;
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
*/
2023-09-05 06:52:27 +00:00
void ALIVE_init(ALIVE* me, uint8_t led);
/**
* 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);
2023-08-31 18:01:39 +00:00
/**
* Emit the resurrect 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_emitResurrect(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