/** * @author Rémi Heredero * @version 1.0.0 * @date August 2023 * @file can_sender.c */ #include "can_sender.h" void CAN_SENDER_init(CAN_SENDER* me){ me->state = STCS_INIT; me->sendingTime = 1; me->wait.f = NULL; me->send.f = NULL; } void CAN_SENDER_startBehaviour(CAN_SENDER* me){ POST(me, &CAN_SENDER_processEvent, evCSinit, 0, 0); } bool CAN_SENDER_processEvent(Event* ev) { bool processed = false; CAN_SENDER* me = (CAN_SENDER*)Event_getTarget(ev); CAN_SENDER_STATES oldState = me->state; evIDT evid = Event_getId(ev); switch (me->state) { // onState case STCS_INIT: if (ev->id == evCSinit) { } break; case STCS_WAIT: break; case STCS_SEND: break; } if(oldState != me->state){ switch (oldState) { // onExit case STCS_INIT: break; case STCS_WAIT: break; case STCS_SEND: break; } switch (me->state) { // onEntry case STCS_INIT: break; case STCS_WAIT: if (me->wait.f != NULL) { me->wait.f(me->wait.p); } break; case STCS_SEND: if (me->send.f != NULL) { me->send.f(me->send.p); } break; } processed = true; } return processed; } /************* * Callbacks * *************/ void CAN_SENDER_onWait(CAN_SENDER* me, CAN_SENDER_CALLBACK_FUNCTION f, void* p) { me->wait.f = f; me->wait.p = p; } void CAN_SENDER_onSend(CAN_SENDER* me, CAN_SENDER_CALLBACK_FUNCTION f, void* p) { me->send.f = f; me->send.p = p; } /************ * EMITTERS * ************/ void CAN_SENDER_emitSend(CAN_SENDER* me, uint16_t t) { POST(me, &CAN_SENDER_processEvent, evCSsend, t, 0); } void CAN_SENDER_emitDone(CAN_SENDER* me, uint16_t t) { POST(me, &CAN_SENDER_processEvent, evCSdone, t, 0); } /*********** * SETTERS * ***********/ void CAN_SENDER_setSendingTime(CAN_SENDER* me, uint8_t v) { me->sendingTime = v; }