fix can receive part for SM

This commit is contained in:
Rémi Heredero 2023-08-22 16:56:01 +02:00
parent 102d4e1992
commit 146fc9011e
3 changed files with 23 additions and 9 deletions

View File

@ -11,7 +11,7 @@
#include "../board/button/button.h" #include "../board/button/button.h"
#include "../board/button/buttonsm.h" #include "../board/button/buttonsm.h"
#include "../app/blcontrol.h" #include "../app/blcontrol.h"
#include "../middleware/can_interface.h" #include "../middleware/can/can_interface.h"
#define BID 1 #define BID 1

View File

@ -30,7 +30,7 @@ void CANINTERFACE_newMsg() {
data = canMsg.frame.data2; data = canMsg.frame.data2;
data = data<<8; data = data<<8;
data = canMsg.frame.data3; 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) { bool CANINTERFACE_processEvent(Event* ev) {
@ -47,14 +47,21 @@ bool CANINTERFACE_processEvent(Event* ev) {
switch (me->state) { // onState switch (me->state) { // onState
case STCA_INIT: case STCA_INIT:
if (ev->id == evCAinit) { if (ev->id == evCAinit) {
me->state = STCA_WAIT;
} }
break; break;
case STCA_WAIT: case STCA_WAIT:
if (ev->id == evCAnewMsg) {
me->state = STCA_READ;
CANINTERFACE_emitDone(0);
}
break; break;
case STCA_READ: case STCA_READ:
if (ev->id == evCAdone) {
me->state = STCA_WAIT;
}
break; break;
} }
@ -121,3 +128,7 @@ void CANINTERFACE_onProcessCan(CANINTERFACE_CALLBACK_CAN f) {
void CANINTERFACE_emitNewMsg(uint16_t t) { void CANINTERFACE_emitNewMsg(uint16_t t) {
POST(&CANINTERFACE_myself, &CANINTERFACE_processEvent, evCAnewMsg, t, 0); POST(&CANINTERFACE_myself, &CANINTERFACE_processEvent, evCAnewMsg, t, 0);
} }
void CANINTERFACE_emitDone(uint16_t t) {
POST(&CANINTERFACE_myself, &CANINTERFACE_processEvent, evCAdone, t, 0);
}

View File

@ -7,7 +7,7 @@
#ifndef CANINTERFACE_H #ifndef CANINTERFACE_H
#define CANINTERFACE_H #define CANINTERFACE_H
#include "../xf/xf.h" #include "../../xf/xf.h"
typedef enum { typedef enum {
STCA_INIT, STCA_INIT,
@ -45,7 +45,6 @@ void CANINTERFACE_init();
/** /**
* Start the CANINTERFACE state machine * Start the CANINTERFACE state machine
* @param me the CANINTERFACE itself
*/ */
void CANINTERFACE_startBehaviour(); 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 * 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 f the function to call
* @param p the param(s) to pass to the function * @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 * 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 f the function to call
* @param p the param(s) to pass to the function * @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 * Emit the NewMsg event
* @param me the CANINTERFACE itself
* @param t time to wait in ms before triggering event * @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 #endif