From 146fc9011e144f4376cd5c30cae6082b3bb4626d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Tue, 22 Aug 2023 16:56:01 +0200 Subject: [PATCH] fix can receive part for SM --- 306-controller_interface.X/factory/factory.h | 2 +- .../middleware/{ => can}/can_interface.c | 15 +++++++++++++-- .../middleware/{ => can}/can_interface.h | 15 +++++++++------ 3 files changed, 23 insertions(+), 9 deletions(-) rename 306-controller_interface.X/middleware/{ => can}/can_interface.c (85%) rename 306-controller_interface.X/middleware/{ => can}/can_interface.h (90%) diff --git a/306-controller_interface.X/factory/factory.h b/306-controller_interface.X/factory/factory.h index ff0752d..fa65abc 100644 --- a/306-controller_interface.X/factory/factory.h +++ b/306-controller_interface.X/factory/factory.h @@ -11,7 +11,7 @@ #include "../board/button/button.h" #include "../board/button/buttonsm.h" #include "../app/blcontrol.h" -#include "../middleware/can_interface.h" +#include "../middleware/can/can_interface.h" #define BID 1 diff --git a/306-controller_interface.X/middleware/can_interface.c b/306-controller_interface.X/middleware/can/can_interface.c similarity index 85% rename from 306-controller_interface.X/middleware/can_interface.c rename to 306-controller_interface.X/middleware/can/can_interface.c index 65fa2d1..b48d487 100644 --- a/306-controller_interface.X/middleware/can_interface.c +++ b/306-controller_interface.X/middleware/can/can_interface.c @@ -30,7 +30,7 @@ void CANINTERFACE_newMsg() { data = canMsg.frame.data2; data = data<<8; data = canMsg.frame.data3; - POST(&CANINTERFACE_myself, &CANINTERFACE_processEvent, evCAinit, 0, data); + POST(&CANINTERFACE_myself, &CANINTERFACE_processEvent, evCAnewMsg, 0, data); } bool CANINTERFACE_processEvent(Event* ev) { @@ -47,14 +47,21 @@ bool CANINTERFACE_processEvent(Event* ev) { switch (me->state) { // onState case STCA_INIT: if (ev->id == evCAinit) { - + me->state = STCA_WAIT; } break; case STCA_WAIT: + if (ev->id == evCAnewMsg) { + me->state = STCA_READ; + CANINTERFACE_emitDone(0); + } break; case STCA_READ: + if (ev->id == evCAdone) { + me->state = STCA_WAIT; + } break; } @@ -121,3 +128,7 @@ void CANINTERFACE_onProcessCan(CANINTERFACE_CALLBACK_CAN f) { void CANINTERFACE_emitNewMsg(uint16_t t) { POST(&CANINTERFACE_myself, &CANINTERFACE_processEvent, evCAnewMsg, t, 0); } + +void CANINTERFACE_emitDone(uint16_t t) { + POST(&CANINTERFACE_myself, &CANINTERFACE_processEvent, evCAdone, t, 0); +} diff --git a/306-controller_interface.X/middleware/can_interface.h b/306-controller_interface.X/middleware/can/can_interface.h similarity index 90% rename from 306-controller_interface.X/middleware/can_interface.h rename to 306-controller_interface.X/middleware/can/can_interface.h index fe5281f..5508af3 100644 --- a/306-controller_interface.X/middleware/can_interface.h +++ b/306-controller_interface.X/middleware/can/can_interface.h @@ -7,7 +7,7 @@ #ifndef CANINTERFACE_H #define CANINTERFACE_H -#include "../xf/xf.h" +#include "../../xf/xf.h" typedef enum { STCA_INIT, @@ -45,7 +45,6 @@ void CANINTERFACE_init(); /** * Start the CANINTERFACE state machine - * @param me the CANINTERFACE itself */ void CANINTERFACE_startBehaviour(); @@ -68,7 +67,6 @@ bool CANINTERFACE_processEvent(Event* ev); /** * Set the callback function to call when the CANINTERFACE is entering state wait - * @param me the CANINTERFACE itself * @param f the function to call * @param p the param(s) to pass to the function */ @@ -76,7 +74,6 @@ void CANINTERFACE_onWait(CANINTERFACE_CALLBACK_FUNCTION f, void* p); /** * Set the callback function to call when the CANINTERFACE is entering state read - * @param me the CANINTERFACE itself * @param f the function to call * @param p the param(s) to pass to the function */ @@ -94,8 +91,14 @@ void CANINTERFACE_onProcessCan(CANINTERFACE_CALLBACK_CAN f); /** * Emit the NewMsg event - * @param me the CANINTERFACE itself * @param t time to wait in ms before triggering event - */void CANINTERFACE_emitNewMsg(uint16_t t); + */ +void CANINTERFACE_emitNewMsg(uint16_t t); + +/** + * Emit the Done event + * @param t time to wait in ms before triggering event + */ +void CANINTERFACE_emitDone(uint16_t t); #endif