From 6bc73fa166744e91af4bdc92a2f181c3a86c9642 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Tue, 29 Aug 2023 14:11:48 +0200 Subject: [PATCH] merge alive_checker and watchdog to alive class --- 306-controller_interface.X/app/can_message.c | 14 +- .../app/factory/factory.c | 34 ++- .../app/factory/factory.h | 11 +- 306-controller_interface.X/middleware/alive.c | 259 ++++++++++++++++ 306-controller_interface.X/middleware/alive.h | 178 +++++++++++ .../middleware/alive_checker.c | 176 ----------- .../middleware/alive_checker.h | 134 -------- .../middleware/watchdog.c | 90 ------ .../middleware/watchdog.h | 83 ----- .../nbproject/configurations.xml | 8 +- UML/alive.pdf | Bin 2639 -> 3736 bytes UML/alive.uxf | 287 +++++++++++------- 12 files changed, 650 insertions(+), 624 deletions(-) create mode 100644 306-controller_interface.X/middleware/alive.c create mode 100644 306-controller_interface.X/middleware/alive.h delete mode 100644 306-controller_interface.X/middleware/alive_checker.c delete mode 100644 306-controller_interface.X/middleware/alive_checker.h delete mode 100644 306-controller_interface.X/middleware/watchdog.c delete mode 100644 306-controller_interface.X/middleware/watchdog.h diff --git a/306-controller_interface.X/app/can_message.c b/306-controller_interface.X/app/can_message.c index 05f929a..2e5cca0 100644 --- a/306-controller_interface.X/app/can_message.c +++ b/306-controller_interface.X/app/can_message.c @@ -37,7 +37,7 @@ void CM_processIncome(uint8_t idSender, uint8_t idMsg, uint32_t data){ CAR_CST.CONTROL_ALIVE_TIME = tmpData.separate.byte3; MEM_write_1_byte(MEMADD_CONTROL_STEERING_MODE, CAR_CST.CONTROL_STEERING_MODE); MEM_write_1_byte(MEMADD_CONTROL_ALIVE_TIME, CAR_CST.CONTROL_ALIVE_TIME); - WATCHDOG_setTime(WDcontroller(), CAR_CST.CONTROL_ALIVE_TIME); + ALIVE_setAliveTime(ALcontroller(), CAR_CST.CONTROL_ALIVE_TIME); } if(idMsg == 0x1) { // CONTROL_SPEED_FACTOR @@ -78,7 +78,7 @@ void CM_processIncome(uint8_t idSender, uint8_t idMsg, uint32_t data){ MEM_write_1_byte(MEMADD_JOYSTICK_PARAM2, CAR_CST.JOYSTICK_PARAM2); MEM_write_1_byte(MEMADD_JOYSTICK_ALIVE_TIME, CAR_CST.JOYSTICK_ALIVE_TIME); - ALIVE_CHECKER_setAliveTime(ACjoy(), CAR_CST.JOYSTICK_ALIVE_TIME); + ALIVE_setAliveTime(ALjoy(), CAR_CST.JOYSTICK_ALIVE_TIME); CM_JOY_SETUP(NULL); } @@ -107,15 +107,15 @@ void CM_processIncome(uint8_t idSender, uint8_t idMsg, uint32_t data){ if(idMsg == 0xF) { // JOY_ALIVE // - - - - - ALIVE_CHECKER_ISALIVE(ACjoy()); - if(ACjoy()->state == STAC_DEAD){ + ALIVE_ISALIVE(ALjoy()); + if(ALjoy()->state == STAL_DEAD){ CAR_CST.JOYSTICK_MODE = MEM_read_1_byte(MEMADD_JOYSTICK_MODE); CAR_CST.JOYSTICK_PARAM1 = MEM_read_1_byte(MEMADD_JOYSTICK_PARAM1); CAR_CST.JOYSTICK_PARAM2 = MEM_read_1_byte(MEMADD_JOYSTICK_PARAM2); CAR_CST.JOYSTICK_ALIVE_TIME = MEM_read_1_byte(MEMADD_JOYSTICK_ALIVE_TIME); - ALIVE_CHECKER_setAliveTime(ACjoy(), CAR_CST.JOYSTICK_ALIVE_TIME); - ALIVE_CHECKER_emitBorn(ACjoy(), 0, 0); - ALIVE_CHECKER_emitReady(ACjoy(), 100, 0); + ALIVE_setAliveTime(ALjoy(), CAR_CST.JOYSTICK_ALIVE_TIME); + ALIVE_emitBorn(ALjoy(), 0, 0); + ALIVE_emitReady(ALjoy(), 100, 0); } } break; diff --git a/306-controller_interface.X/app/factory/factory.c b/306-controller_interface.X/app/factory/factory.c index 11b5ec4..fe819c8 100644 --- a/306-controller_interface.X/app/factory/factory.c +++ b/306-controller_interface.X/app/factory/factory.c @@ -30,12 +30,12 @@ LED* l8() { return &theFactory.l8_; } -WATCHDOG* WDcontroller(){ - return &theFactory.WDcontroller_; +ALIVE* ALcontroller(){ + return &theFactory.ALcontroller_; } -ALIVE_CHECKER* ACjoy() { - return &theFactory.ACjoy_; +ALIVE* ALjoy(){ + return &theFactory.ALjoy_; } @@ -67,10 +67,10 @@ void Factory_init() { MEM_init(); // TODO init watchdog with EPROM CST - WATCHDOG_init(WDcontroller()); - WATCHDOG_setTime(WDcontroller(), CAR_CST.CONTROL_ALIVE_TIME); + ALIVE_init(ALcontroller()); + ALIVE_setAliveTime(ALcontroller(), CAR_CST.CONTROL_ALIVE_TIME); - ALIVE_CHECKER_init(ACjoy()); + ALIVE_init(ALjoy()); } //connect objects if required @@ -78,20 +78,22 @@ void Factory_build() { ECAN_SetRXBnInterruptHandler(CAN_newMsg); CAN_onReceiveCan(CM_processIncome); - WATCHDOG_onAlive(WDcontroller(), CM_CONTROLLER_ALIVE, NULL); - ALIVE_CHECKER_onSetup(ACjoy(), CM_JOY_SETUP, NULL); - ALIVE_CHECKER_setAliveTime(ACjoy(), CAR_CST.JOYSTICK_ALIVE_TIME); - ALIVE_CHECKER_onBorn(ACjoy(), LED_on, l1()); - ALIVE_CHECKER_onDead(ACjoy(), LED_off, l1()); + ALIVE_onAlive(ALcontroller(), CM_CONTROLLER_ALIVE, NULL); + + ALIVE_onSetup(ALjoy(), CM_JOY_SETUP, NULL); + ALIVE_setAliveTime(ALjoy(), CAR_CST.JOYSTICK_ALIVE_TIME); + ALIVE_onBorn(ALjoy(), LED_on, l1()); + ALIVE_onDead(ALjoy(), LED_off, l1()); } //start all state machines void Factory_start() { CAN_startBehaviour(); - WATCHDOG_startBehaviour(WDcontroller()); - ALIVE_CHECKER_startBehaviour(ACjoy()); - ALIVE_CHECKER_emitBorn(ACjoy(), 100, 0); - ALIVE_CHECKER_emitReady(ACjoy(), 200, 0); + + ALIVE_startBehaviourSender(ALcontroller()); + ALIVE_startBehaviourChecker(ALjoy()); + ALIVE_emitBorn(ALjoy(), 100, 0); + ALIVE_emitReady(ALjoy(), 200, 0); } diff --git a/306-controller_interface.X/app/factory/factory.h b/306-controller_interface.X/app/factory/factory.h index b847d38..bcbc830 100644 --- a/306-controller_interface.X/app/factory/factory.h +++ b/306-controller_interface.X/app/factory/factory.h @@ -16,9 +16,8 @@ #include "../can_message.h" #include "../../board/led/led.h" #include "../../board/button/button.h" -#include "../../middleware/alive_checker.h" +#include "../../middleware/alive.h" #include "../../middleware/can_interface.h" -#include "../../middleware/watchdog.h" #include "../../middleware/eeprom.h" @@ -32,8 +31,8 @@ typedef struct { LED l7_; LED l8_; - WATCHDOG WDcontroller_; - ALIVE_CHECKER ACjoy_; + ALIVE ALcontroller_; + ALIVE ALjoy_; } Factory; @@ -52,8 +51,8 @@ LED* l6(); LED* l7(); LED* l8(); -WATCHDOG* WDcontroller(); -ALIVE_CHECKER* ACjoy(); +ALIVE* ALcontroller(); +ALIVE* ALjoy(); #endif \ No newline at end of file diff --git a/306-controller_interface.X/middleware/alive.c b/306-controller_interface.X/middleware/alive.c new file mode 100644 index 0000000..146e9f3 --- /dev/null +++ b/306-controller_interface.X/middleware/alive.c @@ -0,0 +1,259 @@ +/** + * @author Rémi Heredero + * @version 1.0.0 + * @date August 2023 + * @file alive.c + */ + +#include "alive.h" + +void ALIVE_init(ALIVE* me){ + me->state = STAL_INIT; + me->isAlive = false; + me->checker = false; + me->sender = false; + me->haveBreak = true; + me->aliveTime = 10; + me->setup.f = NULL; + me->born.f = NULL; + me->wait.f = NULL; + me->dead.f = NULL; + me->alive.f = NULL; + me->break_cb.f = NULL; +} + +void ALIVE_startBehaviourChecker(ALIVE* me){ + POST(me, &ALIVE_processEvent, evALinitChecker, 0, 0); +} + +void ALIVE_startBehaviourSender(ALIVE* me){ + POST(me, &ALIVE_processEvent, evALinitSender, 0, 0); +} + +bool ALIVE_processEvent(Event* ev) { + bool processed = false; + ALIVE* me = (ALIVE*)Event_getTarget(ev); + ALIVE_STATES oldState = me->state; + evIDT evid = Event_getId(ev); + uint64_t data = Event_getData(ev); + + switch (me->state) { // onState + case STAL_INIT: + if (ev->id == evALinitChecker) { + me->state = STAL_SETUP; + } + if (ev->id == evALinitSender) { + me->state = STAL_ALIVE; + ALIVE_emitPoll(me, me->aliveTime*10, 0); + } + break; + + case STAL_SETUP: + if (ev->id == evALborn) { + me->state = STAL_BORN; + } + break; + + case STAL_BORN: + if (ev->id == evALready) { + me->state = STAL_WAIT; + ALIVE_emitPoll(me, me->aliveTime*10, 0); + } + break; + + case STAL_WAIT: + if (ev->id == evALpoll) { + + if (me->aliveTime == 0) { + if (me->haveBreak){ + me->state = STAL_BREAK; + } + } else if (me->isAlive){ + me->state = STAL_WAIT; + ALIVE_emitPoll(me, me->aliveTime*10, 0); + } else { + me->state = STAL_DEAD; + } + me->isAlive = false; + + } + break; + + case STAL_DEAD: + if (ev->id == evALborn) { + me->state = STAL_BORN; + } + break; + + case STAL_ALIVE: + if (ev->id == evALpoll) { + if (me->alive.f != NULL) { + me->alive.f(me->alive.p); + } + if (me->aliveTime == 0) { + if (me->haveBreak){ + me->state == STAL_BREAK; + } + } else { + ALIVE_emitPoll(me, me->aliveTime*10, 0); + } + } + break; + + case STAL_BREAK: + if (ev->id == evALstart) { + ALIVE_emitPoll(me, me->aliveTime*10, 0); + if (me->checker) { + me->state = STAL_WAIT; + } + if (me->sender) { + me->state = STAL_ALIVE; + } + } + break; + } + + if(oldState != me->state){ + switch (oldState) { // onExit + case STAL_INIT: + break; + + case STAL_SETUP: + break; + + case STAL_BORN: + break; + + case STAL_WAIT: + break; + + case STAL_DEAD: + break; + + case STAL_ALIVE: + break; + + case STAL_BREAK: + break; + } + + switch (me->state) { // onEntry + case STAL_INIT: + break; + + case STAL_SETUP: + if (me->setup.f != NULL) { + me->setup.f(me->setup.p); + } + break; + + case STAL_BORN: + if (me->born.f != NULL) { + me->born.f(me->born.p); + } + break; + + case STAL_WAIT: + if (me->wait.f != NULL) { + me->wait.f(me->wait.p); + } + break; + + case STAL_DEAD: + if (me->dead.f != NULL) { + me->dead.f(me->dead.p); + } + break; + + case STAL_ALIVE: + break; + + case STAL_BREAK: + if (me->break_cb.f != NULL) { + me->break_cb.f(me->break_cb.p); + } + break; + } + + processed = true; + } + return processed; +} + +/************* + * Callbacks * + *************/ + +void ALIVE_onSetup(ALIVE* me, ALIVE_CALLBACK_FUNCTION f, void* p) { + me->setup.f = f; + me->setup.p = p; +} + +void ALIVE_onBorn(ALIVE* me, ALIVE_CALLBACK_FUNCTION f, void* p) { + me->born.f = f; + me->born.p = p; +} + +void ALIVE_onWait(ALIVE* me, ALIVE_CALLBACK_FUNCTION f, void* p) { + me->wait.f = f; + me->wait.p = p; +} + +void ALIVE_onDead(ALIVE* me, ALIVE_CALLBACK_FUNCTION f, void* p) { + me->dead.f = f; + me->dead.p = p; +} + +void ALIVE_onAlive(ALIVE* me, ALIVE_CALLBACK_FUNCTION f, void* p) { + me->alive.f = f; + me->alive.p = p; +} + +void ALIVE_onBreak(ALIVE* me, ALIVE_CALLBACK_FUNCTION f, void* p) { + me->break_cb.f = f; + me->break_cb.p = p; +} + +/************ + * EMITTERS * + ************/ + +void ALIVE_emitInitSender(ALIVE* me, uint16_t t, int64_t data) { + POST(me, &ALIVE_processEvent, evALinitSender, t, data); +} + +void ALIVE_emitBorn(ALIVE* me, uint16_t t, int64_t data) { + POST(me, &ALIVE_processEvent, evALborn, t, data); +} + +void ALIVE_emitReady(ALIVE* me, uint16_t t, int64_t data) { + POST(me, &ALIVE_processEvent, evALready, t, data); +} + +void ALIVE_emitPoll(ALIVE* me, uint16_t t, int64_t data) { + POST(me, &ALIVE_processEvent, evALpoll, t, data); +} + +void ALIVE_emitStart(ALIVE* me, uint16_t t, int64_t data) { + POST(me, &ALIVE_processEvent, evALstart, t, data); +} + +/*********** + * SETTERS * + ***********/ + +void ALIVE_setIsAlive(ALIVE* me, bool v) { + me->isAlive = v; +} + +void ALIVE_setHaveBreak(ALIVE* me, bool v) { + me->haveBreak = v; +} + +void ALIVE_setAliveTime(ALIVE* me, uint8_t v) { + me->aliveTime = v; +} + +void ALIVE_ISALIVE(ALIVE* me) { + ALIVE_setIsAlive(me, true); +} diff --git a/306-controller_interface.X/middleware/alive.h b/306-controller_interface.X/middleware/alive.h new file mode 100644 index 0000000..749d9a9 --- /dev/null +++ b/306-controller_interface.X/middleware/alive.h @@ -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 diff --git a/306-controller_interface.X/middleware/alive_checker.c b/306-controller_interface.X/middleware/alive_checker.c deleted file mode 100644 index 00466a4..0000000 --- a/306-controller_interface.X/middleware/alive_checker.c +++ /dev/null @@ -1,176 +0,0 @@ -/** - * @author Rémi Heredero - * @version 1.0.0 - * @date August 2023 - * @file alive_checker.c - */ - -#include "alive_checker.h" - -void ALIVE_CHECKER_init(ALIVE_CHECKER* me){ - me->state = STAC_INIT; - me->isAlive = false; - me->aliveTime = 10; - me->setup.f = NULL; - me->born.f = NULL; - me->wait.f = NULL; - me->dead.f = NULL; -} - -void ALIVE_CHECKER_startBehaviour(ALIVE_CHECKER* me){ - POST(me, &ALIVE_CHECKER_processEvent, evACinit, 0, 0); -} - -bool ALIVE_CHECKER_processEvent(Event* ev) { - bool processed = false; - ALIVE_CHECKER* me = (ALIVE_CHECKER*)Event_getTarget(ev); - ALIVE_CHECKER_STATES oldState = me->state; - evIDT evid = Event_getId(ev); - uint64_t data = Event_getData(ev); - - switch (me->state) { // onState - case STAC_INIT: - if (ev->id == evACinit) { - me->state = STAC_SETUP; - } - break; - - case STAC_SETUP: - if (ev->id == evACborn) { - me->state = STAC_BORN; - } - break; - - case STAC_BORN: - if (ev->id == evACready) { - me->state = STAC_WAIT; - ALIVE_CHECKER_emitPoll(me, me->aliveTime*10, 0); - } - break; - - case STAC_WAIT: - if (ev->id == evACpoll) { - if (me->isAlive) { - me->state = STAC_WAIT; - ALIVE_CHECKER_emitPoll(me, me->aliveTime*10, 0); - } else { - me->state = STAC_DEAD; - } - me->isAlive = false; - } - break; - - case STAC_DEAD: - if(ev->id == evACborn) { - me->state = STAC_BORN; - } - break; - } - - if(oldState != me->state){ - switch (oldState) { // onExit - case STAC_INIT: - break; - - case STAC_SETUP: - break; - - case STAC_BORN: - break; - - case STAC_WAIT: - break; - - case STAC_DEAD: - break; - } - - switch (me->state) { // onEntry - case STAC_INIT: - break; - - case STAC_SETUP: - if (me->setup.f != NULL) { - me->setup.f(me->setup.p); - } - break; - - case STAC_BORN: - if (me->born.f != NULL) { - me->born.f(me->born.p); - } - break; - - case STAC_WAIT: - if (me->wait.f != NULL) { - me->wait.f(me->wait.p); - } - break; - - case STAC_DEAD: - if (me->dead.f != NULL) { - me->dead.f(me->dead.p); - } - break; - } - - processed = true; - } - return processed; -} - -/************* - * Callbacks * - *************/ - -void ALIVE_CHECKER_onSetup(ALIVE_CHECKER* me, ALIVE_CHECKER_CALLBACK_FUNCTION f, void* p) { - me->setup.f = f; - me->setup.p = p; -} - -void ALIVE_CHECKER_onBorn(ALIVE_CHECKER* me, ALIVE_CHECKER_CALLBACK_FUNCTION f, void* p) { - me->born.f = f; - me->born.p = p; -} - -void ALIVE_CHECKER_onWait(ALIVE_CHECKER* me, ALIVE_CHECKER_CALLBACK_FUNCTION f, void* p) { - me->wait.f = f; - me->wait.p = p; -} - -void ALIVE_CHECKER_onDead(ALIVE_CHECKER* me, ALIVE_CHECKER_CALLBACK_FUNCTION f, void* p) { - me->dead.f = f; - me->dead.p = p; -} - -/************ - * EMITTERS * - ************/ - -void ALIVE_CHECKER_emitBorn(ALIVE_CHECKER* me, uint16_t t, int64_t data) { - POST(me, &ALIVE_CHECKER_processEvent, evACborn, t, data); -} - -void ALIVE_CHECKER_emitReady(ALIVE_CHECKER* me, uint16_t t, int64_t data) { - POST(me, &ALIVE_CHECKER_processEvent, evACready, t, data); -} - -void ALIVE_CHECKER_emitPoll(ALIVE_CHECKER* me, uint16_t t, int64_t data) { - POST(me, &ALIVE_CHECKER_processEvent, evACpoll, t, data); -} - -/*********** - * SETTERS * - ***********/ - -void ALIVE_CHECKER_setAliveTime(ALIVE_CHECKER* me, uint8_t v) { - me->aliveTime = v; -} - -void ALIVE_CHECKER_setIsAlive(ALIVE_CHECKER* me, bool v) { - me->isAlive = v; -} - -void ALIVE_CHECKER_ISALIVE(ALIVE_CHECKER* me) { - ALIVE_CHECKER_setIsAlive(me, true); -} diff --git a/306-controller_interface.X/middleware/alive_checker.h b/306-controller_interface.X/middleware/alive_checker.h deleted file mode 100644 index 6b57ac7..0000000 --- a/306-controller_interface.X/middleware/alive_checker.h +++ /dev/null @@ -1,134 +0,0 @@ -/** - * @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 = 15, - 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 diff --git a/306-controller_interface.X/middleware/watchdog.c b/306-controller_interface.X/middleware/watchdog.c deleted file mode 100644 index 5840bf5..0000000 --- a/306-controller_interface.X/middleware/watchdog.c +++ /dev/null @@ -1,90 +0,0 @@ -/** - * @author Rémi Heredero - * @version 1.0.0 - * @date August 2023 - * @file watchdog.c - */ - -#include "watchdog.h" - -void WATCHDOG_init(WATCHDOG* me){ - me->state = STWD_INIT; - me->time = 10; - me->alive.f = NULL; -} - -void WATCHDOG_startBehaviour(WATCHDOG* me){ - POST(me, &WATCHDOG_processEvent, evWDinit, 0, 0); -} - -bool WATCHDOG_processEvent(Event* ev) { - bool processed = false; - WATCHDOG* me = (WATCHDOG*)Event_getTarget(ev); - WATCHDOG_STATES oldState = me->state; - evIDT evid = Event_getId(ev); - uint64_t data = Event_getData(ev); - - switch (me->state) { // onState - case STWD_INIT: - if (ev->id == evWDinit) { - me->state = STWD_ALIVE; - WATCHDOG_emitPoll(me, 10*me->time, 0); - } - break; - - case STWD_ALIVE: - if (ev->id == evWDpoll) { - WATCHDOG_emitPoll(me, 10*me->time, 0); - if (me->alive.f != NULL) { - me->alive.f(me->alive.p); - } - } - break; - } - - if(oldState != me->state){ - switch (oldState) { // onExit - case STWD_INIT: - break; - - case STWD_ALIVE: - break; - } - - switch (me->state) { // onEntry - case STWD_INIT: - break; - - case STWD_ALIVE: - break; - } - - processed = true; - } - return processed; -} - -/************* - * Callbacks * - *************/ - -void WATCHDOG_onAlive(WATCHDOG* me, WATCHDOG_CALLBACK_FUNCTION f, void* p) { - me->alive.f = f; - me->alive.p = p; -} - -/************ - * EMITTERS * - ************/ - -void WATCHDOG_emitPoll(WATCHDOG* me, uint16_t t, int64_t data) { - POST(me, &WATCHDOG_processEvent, evWDpoll, t, data); -} - -/*********** - * SETTERS * - ***********/ - -void WATCHDOG_setTime(WATCHDOG* me, uint8_t v) { - me->time = v; -} diff --git a/306-controller_interface.X/middleware/watchdog.h b/306-controller_interface.X/middleware/watchdog.h deleted file mode 100644 index ed2d184..0000000 --- a/306-controller_interface.X/middleware/watchdog.h +++ /dev/null @@ -1,83 +0,0 @@ -/** - * @author Rémi Heredero - * @version 1.0.0 - * @date August 2023 - * @file watchdog.h - */ -#ifndef WATCHDOG_H -#define WATCHDOG_H - -#include "../xf/xf.h" - -typedef enum { - STWD_INIT, - STWD_ALIVE -} WATCHDOG_STATES; - -typedef enum { - evWDinit = 20, - evWDpoll -} WATCHDOG_EVENTS; - -typedef void (*WATCHDOG_CALLBACK_FUNCTION)(void*); -typedef struct { - WATCHDOG_CALLBACK_FUNCTION f; // function - void* p; // param(s) -} WATCHDOG_CALLBACK; - -typedef struct { - WATCHDOG_STATES state; - uint8_t time; - WATCHDOG_CALLBACK alive; -} WATCHDOG; - -/** - * Initialize the WATCHDOG - * @param me the WATCHDOG itself - */ -void WATCHDOG_init(WATCHDOG* me); - -/** - * Start the WATCHDOG state machine - * @param me the WATCHDOG itself - */ -void WATCHDOG_startBehaviour(WATCHDOG* me); - -/** - * Process the event - * @param ev the event to process - * @return true if the event is processed - */ -bool WATCHDOG_processEvent(Event* ev); - -/************* - * Callbacks * - *************/ - -/** - * Set the callback function to call when the WATCHDOG is entering state alive - * @param me the WATCHDOG itself - * @param f the function to call - * @param p the param(s) to pass to the function - */ -void WATCHDOG_onAlive(WATCHDOG* me, WATCHDOG_CALLBACK_FUNCTION f, void* p); - -/************ - * EMITTERS * - ************/ - -/** - * Emit the poll event - * @param me the WATCHDOG itself - * @param t time to wait in ms before triggering event - * @param data data to put on the event for XF - */ -void WATCHDOG_emitPoll(WATCHDOG* me, uint16_t t, int64_t data); - -/*********** - * SETTERS * - ***********/ - -void WATCHDOG_setTime(WATCHDOG* me, uint8_t v); - -#endif diff --git a/306-controller_interface.X/nbproject/configurations.xml b/306-controller_interface.X/nbproject/configurations.xml index 3dc5c26..d5e1e13 100644 --- a/306-controller_interface.X/nbproject/configurations.xml +++ b/306-controller_interface.X/nbproject/configurations.xml @@ -26,8 +26,7 @@ middleware/can_interface.h - middleware/alive_checker.h - middleware/watchdog.h + middleware/alive.h xf/event.h @@ -63,8 +62,7 @@ middleware/can_interface.c - middleware/alive_checker.c - middleware/watchdog.c + middleware/alive.c xf/event.c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3k}4zs-^;7i$-J2#nxFArw8{&)SE^mRkq_ zrLc&^f0JXOy)ZI#LPZB6sOUn?FkMJlu03HY&>{>DrO5G&TwAHAK!z%+kU&M(2~ZGF zzcK*muQTLO%qh^?g~p+sU@_zs8DP|kf`AS5jVgUD9v}c1G!{Cks`nq9rK%@CfIxK% z53t3_%P0g9fq?xEPyilS=_CA!5C12*I9r<)e71Pp3LoA^;nVoP!gw5XQO$%05PpyT zZxCaPUBN=Y%kNwvUw4m2{dX>hO*?i1WGlw*!DF!?0>D`Nu~_ogQQW1UwP!>)OFoGI zz^;fu`%oYhz&K#T!EhQT9Iy#RqwuzP+b}|SI0}mf>2xgdk0pPx0y+iPS3v^=EX>r@ I?SMP%U-YhZJ^%m! diff --git a/UML/alive.uxf b/UML/alive.uxf index e54aa37..859c367 100644 --- a/UML/alive.uxf +++ b/UML/alive.uxf @@ -1,13 +1,13 @@ - 15 + 14 UMLSpecialState - 510 - 30 - 30 - 30 + 714 + 28 + 56 + 56 type=initial @@ -15,47 +15,48 @@ Relation - 510 - 45 - 90 - 105 + 462 + 70 + 308 + 154 lt=-> -evInit - 10.0;10.0;10.0;50.0 +evInitChecker + 200.0;10.0;200.0;50.0;10.0;50.0;10.0;90.0 UMLState - 390 - 120 - 285 - 90 + 350 + 196 + 266 + 112 SETUP -- -/entry: sendParamsOnCan +/entry: sendParamsOnCan +/entry: checker = true Relation - 510 - 195 - 105 - 105 + 462 + 294 + 98 + 98 lt=-> -evBorn +m1=evBorn 10.0;10.0;10.0;50.0 UMLState - 390 - 270 - 285 - 90 + 350 + 364 + 266 + 84 BORN -- @@ -65,10 +66,10 @@ evBorn UMLState - 390 - 420 - 285 - 120 + 350 + 504 + 266 + 112 WAIT -- @@ -80,22 +81,22 @@ isAlive = false Relation - 510 - 345 - 120 - 105 + 462 + 434 + 112 + 98 lt=-> -evReady +m1=evReady 10.0;10.0;10.0;50.0 UMLState - 390 - 720 - 285 - 90 + 350 + 784 + 266 + 84 DEAD -- @@ -105,94 +106,166 @@ evReady Relation - 510 - 525 - 105 - 105 - - lt=-> -evPoll - 10.0;10.0;10.0;50.0 - - - UMLSpecialState - - 495 - 600 - 60 - 60 - - type=decision - - - - Relation - - 510 - 645 - 90 - 105 - - lt=-> -m1=[else] - 10.0;10.0;10.0;50.0 - - - Relation - - 315 - 465 + 280 + 546 210 - 210 + 182 lt=-> -m1=[isAlive] - 120.0;110.0;10.0;110.0;10.0;10.0;50.0;10.0 +m1=evPoll\n[isAlive] + 80.0;50.0;80.0;110.0;10.0;110.0;10.0;10.0;50.0;10.0 Relation - 660 - 135 - 210 - 405 + 224 + 392 + 336 + 560 lt=-> -evDisable - 10.0;250.0;60.0;250.0;60.0;10.0;10.0;10.0 - - - Relation - - 255 - 300 - 300 - 600 - - lt=-> -evBorn +m1=evBorn 180.0;340.0;180.0;380.0;10.0;380.0;10.0;10.0;90.0;10.0 Relation - 660 - 495 - 120 - 315 + 462 + 602 + 112 + 210 - lt=- - 10.0;190.0;60.0;190.0;60.0;10.0 + lt=-> +m1=evPoll\n[default] + 10.0;10.0;10.0;130.0 Relation - 660 - 315 - 120 - 45 + 728 + 70 + 308 + 154 - lt=- - 10.0;10.0;60.0;10.0 + lt=-> +evInitSender + 10.0;10.0;10.0;50.0;200.0;50.0;200.0;90.0 + + + Relation + + 784 + 252 + 224 + 140 + + lt=-> +m1=evPoll\n[else] + 100.0;40.0;100.0;70.0;10.0;70.0;10.0;10.0;60.0;10.0 + + + UMLNote + + 784 + 28 + 140 + 56 + + read time on +EPROM + + + + UMLState + + 868 + 196 + 266 + 112 + + ALIVE +-- +\entry: sender = true +-- +sendAliveOnCan + + + + UMLState + + 868 + 518 + 266 + 84 + + lt=.. +BREAK +-.. + + + + + Relation + + 994 + 294 + 210 + 252 + + lt=..> +m1=evPoll\n[time==0]\n[haveBreak] + 60.0;10.0;60.0;110.0;10.0;110.0;10.0;160.0 + + + Relation + + 560 + 546 + 336 + 182 + + lt=..> +m1=evPoll\n[time==0]\n[haveBreak] + 10.0;50.0;10.0;110.0;90.0;110.0;180.0;10.0;220.0;10.0 + + + Relation + + 602 + 546 + 420 + 182 + + lt=..> +m1=evStart\n[checker] + 220.0;40.0;220.0;110.0;150.0;110.0;60.0;10.0;10.0;10.0 + + + Relation + + 1078 + 252 + 182 + 476 + + lt=..> +m1=evStart\n[sender] + 10.0;250.0;10.0;320.0;110.0;320.0;110.0;10.0;40.0;10.0 + + + UMLNote + + 868 + 728 + 266 + 154 + + lt=.. +break part can be disable +with setHaveBreak(false) + +not all childrens have a break +for time at 0 +