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

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