WIP can sender - template done
This commit is contained in:
		| @@ -4,8 +4,8 @@ | ||||
|  * @date August 2023 | ||||
|  * @file can_sender.h | ||||
|  */ | ||||
| #ifndef CAN_SENDER_H | ||||
| #define CAN_SENDER_H | ||||
| #ifndef CANSENDER_H | ||||
| #define CANSENDER_H | ||||
|  | ||||
| #include "../../xf/xf.h" | ||||
|  | ||||
| @@ -13,65 +13,65 @@ typedef enum { | ||||
|     STCS_INIT, | ||||
|     STCS_WAIT, | ||||
|     STCS_SEND | ||||
| } CAN_SENDER_STATES; | ||||
| } CANSENDER_STATES; | ||||
|  | ||||
| typedef enum { | ||||
|     evCSinit = 15, // TODO change this number (< 256) | ||||
|     evCSsend, | ||||
|     evCSdone | ||||
| } CAN_SENDER_EVENTS; | ||||
| } CANSENDER_EVENTS; | ||||
|  | ||||
| typedef void (*CAN_SENDER_CALLBACK_FUNCTION)(void*); | ||||
| typedef void (*CANSENDER_CALLBACK_FUNCTION)(void*); | ||||
| typedef struct { | ||||
|     CAN_SENDER_CALLBACK_FUNCTION f; // function | ||||
|     CANSENDER_CALLBACK_FUNCTION f; // function | ||||
|     void* p; // param(s) | ||||
| } CAN_SENDER_CALLBACK; | ||||
| } CANSENDER_CALLBACK; | ||||
|  | ||||
| typedef struct { | ||||
|     CAN_SENDER_STATES state; | ||||
|     CANSENDER_STATES state; | ||||
|     uint8_t sendingTime; | ||||
|     CAN_SENDER_CALLBACK wait; | ||||
|     CAN_SENDER_CALLBACK send; | ||||
| } CAN_SENDER; | ||||
|     CANSENDER_CALLBACK wait; | ||||
|     CANSENDER_CALLBACK send; | ||||
| } CANSENDER; | ||||
|  | ||||
| /** | ||||
|  * Initialize the CAN_SENDER | ||||
|  * @param me the CAN_SENDER itself | ||||
|  * Initialize the CANSENDER | ||||
|  * @param me the CANSENDER itself | ||||
|  */ | ||||
| void CAN_SENDER_init(CAN_SENDER* me); | ||||
| void CANSENDER_init(CANSENDER* me); | ||||
|  | ||||
| /** | ||||
|  * Start the CAN_SENDER state machine | ||||
|  * @param me the CAN_SENDER itself | ||||
|  * Start the CANSENDER state machine | ||||
|  * @param me the CANSENDER itself | ||||
|  */ | ||||
| void CAN_SENDER_startBehaviour(CAN_SENDER* me); | ||||
| void CANSENDER_startBehaviour(CANSENDER* me); | ||||
|  | ||||
| /** | ||||
|  * Process the event | ||||
|  * @param ev the event to process | ||||
|  * @return true if the event is processed | ||||
|  */ | ||||
| bool CAN_SENDER_processEvent(Event* ev); | ||||
| bool CANSENDER_processEvent(Event* ev); | ||||
|  | ||||
| /************* | ||||
|  * Callbacks * | ||||
|  *************/ | ||||
|  | ||||
| /** | ||||
|  * Set the callback function to call when the CAN_SENDER is entering state wait | ||||
|  * @param me the CAN_SENDER itself | ||||
|  * Set the callback function to call when the CANSENDER is entering state wait | ||||
|  * @param me the CANSENDER itself | ||||
|  * @param f the function to call | ||||
|  * @param p the param(s) to pass to the function | ||||
|  */ | ||||
| void CAN_SENDER_onWait(CAN_SENDER* me, CAN_SENDER_CALLBACK_FUNCTION f, void* p); | ||||
| void CANSENDER_onWait(CANSENDER* me, CANSENDER_CALLBACK_FUNCTION f, void* p); | ||||
|  | ||||
| /** | ||||
|  * Set the callback function to call when the CAN_SENDER is entering state send | ||||
|  * @param me the CAN_SENDER itself | ||||
|  * Set the callback function to call when the CANSENDER is entering state send | ||||
|  * @param me the CANSENDER itself | ||||
|  * @param f the function to call | ||||
|  * @param p the param(s) to pass to the function | ||||
|  */ | ||||
| void CAN_SENDER_onSend(CAN_SENDER* me, CAN_SENDER_CALLBACK_FUNCTION f, void* p); | ||||
| void CANSENDER_onSend(CANSENDER* me, CANSENDER_CALLBACK_FUNCTION f, void* p); | ||||
|  | ||||
| /************ | ||||
|  * EMITTERS * | ||||
| @@ -79,18 +79,22 @@ void CAN_SENDER_onSend(CAN_SENDER* me, CAN_SENDER_CALLBACK_FUNCTION f, void* p); | ||||
|  | ||||
| /** | ||||
|  * Emit the send event | ||||
|  * @param me the CAN_SENDER itself | ||||
|  * @param me the CANSENDER itself | ||||
|  * @param t time to wait in ms before triggering event | ||||
|  */ | ||||
| void CAN_SENDER_emitSend(CAN_SENDER* me, uint16_t t); | ||||
| void CANSENDER_emitSend(CANSENDER* me, uint16_t t); | ||||
|  | ||||
| /** | ||||
|  * Emit the done event | ||||
|  * @param me the CAN_SENDER itself | ||||
|  * @param me the CANSENDER itself | ||||
|  * @param t time to wait in ms before triggering event | ||||
|  */ | ||||
|  void CAN_SENDER_emitDone(CAN_SENDER* me, uint16_t t); | ||||
|  | ||||
|  void CANSENDER_emitDone(CANSENDER* me, uint16_t t); | ||||
|   | ||||
|  void CANSENDER_sendCanMsg(CANSENDER* me, uint8_t id, uint32_t data); | ||||
|  void sendCanMsg(uint32_t id, uint32_t data); | ||||
|   | ||||
|   | ||||
| /*********** | ||||
|  * SETTERS * | ||||
|  ***********/ | ||||
| @@ -100,6 +104,9 @@ void CAN_SENDER_emitSend(CAN_SENDER* me, uint16_t t); | ||||
|  * @param me | ||||
|  * @param v | ||||
|  */ | ||||
| void CAN_SENDER_setSendingTime(CAN_SENDER* me, uint8_t v); | ||||
| void CANSENDER_setSendingTime(CANSENDER* me, uint8_t v); | ||||
|  | ||||
| void CANSENDER_seSender(CANSENDER* me, uint8_t s); | ||||
| void CANSENDER_setRecipient(CANSENDER* me, uint8_t r); | ||||
|  | ||||
| #endif | ||||
|   | ||||
		Reference in New Issue
	
	Block a user