This repository has been archived on 2024-01-25. You can view files and clone it, but cannot push or open issues or pull requests.
SummerSchool2-Controller/306-controller_interface.X/middleware/can/can_sender.h

113 lines
2.4 KiB
C
Raw Normal View History

2023-08-22 15:50:49 +00:00
/**
* @author R<EFBFBD>mi Heredero
* @version 1.0.0
* @date August 2023
* @file can_sender.h
*/
2023-08-23 05:29:12 +00:00
#ifndef CANSENDER_H
#define CANSENDER_H
2023-08-22 15:50:49 +00:00
#include "../../xf/xf.h"
typedef enum {
STCS_INIT,
STCS_WAIT,
STCS_SEND
2023-08-23 05:29:12 +00:00
} CANSENDER_STATES;
2023-08-22 15:50:49 +00:00
typedef enum {
evCSinit = 15, // TODO change this number (< 256)
evCSsend,
evCSdone
2023-08-23 05:29:12 +00:00
} CANSENDER_EVENTS;
2023-08-22 15:50:49 +00:00
2023-08-23 05:29:12 +00:00
typedef void (*CANSENDER_CALLBACK_FUNCTION)(void*);
2023-08-22 15:50:49 +00:00
typedef struct {
2023-08-23 05:29:12 +00:00
CANSENDER_CALLBACK_FUNCTION f; // function
2023-08-22 15:50:49 +00:00
void* p; // param(s)
2023-08-23 05:29:12 +00:00
} CANSENDER_CALLBACK;
2023-08-22 15:50:49 +00:00
typedef struct {
2023-08-23 05:29:12 +00:00
CANSENDER_STATES state;
2023-08-22 15:50:49 +00:00
uint8_t sendingTime;
2023-08-23 05:29:12 +00:00
CANSENDER_CALLBACK wait;
CANSENDER_CALLBACK send;
} CANSENDER;
2023-08-22 15:50:49 +00:00
/**
2023-08-23 05:29:12 +00:00
* Initialize the CANSENDER
* @param me the CANSENDER itself
2023-08-22 15:50:49 +00:00
*/
2023-08-23 05:29:12 +00:00
void CANSENDER_init(CANSENDER* me);
2023-08-22 15:50:49 +00:00
/**
2023-08-23 05:29:12 +00:00
* Start the CANSENDER state machine
* @param me the CANSENDER itself
2023-08-22 15:50:49 +00:00
*/
2023-08-23 05:29:12 +00:00
void CANSENDER_startBehaviour(CANSENDER* me);
2023-08-22 15:50:49 +00:00
/**
* Process the event
* @param ev the event to process
* @return true if the event is processed
*/
2023-08-23 05:29:12 +00:00
bool CANSENDER_processEvent(Event* ev);
2023-08-22 15:50:49 +00:00
/*************
* Callbacks *
*************/
/**
2023-08-23 05:29:12 +00:00
* Set the callback function to call when the CANSENDER is entering state wait
* @param me the CANSENDER itself
2023-08-22 15:50:49 +00:00
* @param f the function to call
* @param p the param(s) to pass to the function
*/
2023-08-23 05:29:12 +00:00
void CANSENDER_onWait(CANSENDER* me, CANSENDER_CALLBACK_FUNCTION f, void* p);
2023-08-22 15:50:49 +00:00
/**
2023-08-23 05:29:12 +00:00
* Set the callback function to call when the CANSENDER is entering state send
* @param me the CANSENDER itself
2023-08-22 15:50:49 +00:00
* @param f the function to call
* @param p the param(s) to pass to the function
*/
2023-08-23 05:29:12 +00:00
void CANSENDER_onSend(CANSENDER* me, CANSENDER_CALLBACK_FUNCTION f, void* p);
2023-08-22 15:50:49 +00:00
/************
* EMITTERS *
************/
/**
* Emit the send event
2023-08-23 05:29:12 +00:00
* @param me the CANSENDER itself
2023-08-22 15:50:49 +00:00
* @param t time to wait in ms before triggering event
*/
2023-08-23 05:29:12 +00:00
void CANSENDER_emitSend(CANSENDER* me, uint16_t t);
2023-08-22 15:50:49 +00:00
/**
* Emit the done event
2023-08-23 05:29:12 +00:00
* @param me the CANSENDER itself
2023-08-22 15:50:49 +00:00
* @param t time to wait in ms before triggering event
*/
2023-08-23 05:29:12 +00:00
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);
2023-08-22 15:50:49 +00:00
/***********
* SETTERS *
***********/
/**
*
* @param me
* @param v
*/
2023-08-23 05:29:12 +00:00
void CANSENDER_setSendingTime(CANSENDER* me, uint8_t v);
void CANSENDER_seSender(CANSENDER* me, uint8_t s);
void CANSENDER_setRecipient(CANSENDER* me, uint8_t r);
2023-08-22 15:50:49 +00:00
#endif