Skip to content

Commit

Permalink
added rate limited can msg
Browse files Browse the repository at this point in the history
  • Loading branch information
caiodasilva2005 committed Oct 28, 2024
1 parent d87a3e0 commit 2a627ba
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions middleware/include/can_utility.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include "can_handler.h"
#include "FreeRTOS.h"

typedef struct {
can_msg_t can_msg;
osThreadId_t msg_timer;
uint8_t msg_rate; /* in messages per second */
} rl_can_msg_t;

HAL_StatusTypeDef send_rl_can_msg(can_t *can, rl_can_msg_t *rl_can_msg);
18 changes: 18 additions & 0 deletions middleware/src/can_utility.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

#include "can_utility.h"

/**
* Sends a rate limited can message
*/
HAL_StatusTypeDef send_rl_can_msg(can_t *can, rl_can_msg_t *rl_can_msg)
{
if (osTimerIsRunning(rl_can_msg->msg_timer)) {
return HAL_BUSY;
}

can_send_msg(can, &rl_can_msg->can_msg);
osTimerStart(rl_can_msg->msg_timer,
pdMS_TO_TICKS(rl_can_msg->msg_rate * 1000));

return HAL_OK;
}

0 comments on commit 2a627ba

Please sign in to comment.