From ef5cdda82cda7863fea43982a76903fbc5cca7b0 Mon Sep 17 00:00:00 2001 From: Kidenygood <2979564623@qq.com> Date: Mon, 3 Apr 2023 18:40:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=BD=BD=E5=85=A5=E7=BC=93?= =?UTF-8?q?=E5=86=B2=E5=8C=BA=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/referee/rm_referee.c | 19 ++++++++++++++++--- modules/referee/rm_referee.h | 15 +++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/modules/referee/rm_referee.c b/modules/referee/rm_referee.c index 8650fa0..818abed 100644 --- a/modules/referee/rm_referee.c +++ b/modules/referee/rm_referee.c @@ -16,8 +16,8 @@ #define RE_RX_BUFFER_SIZE 200 -static USARTInstance *referee_usart_instance; // 暂时改为非静态变量 - +static USARTInstance *referee_usart_instance; +static referee_tx_buffer_t referee_tx_buffer={{0},0}; static referee_info_t referee_info; static void JudgeReadData(uint8_t *ReadFromUsart); static void RefereeRxCallback(); @@ -35,16 +35,29 @@ referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle) return &referee_info; } +/** + * @brief 载入缓存区函数 + * @param send 待载入的数据 + */ +void RefereeLoadToBuffer(uint8_t *send, uint16_t tx_len) +{ + memcpy((uint8_t *)(&referee_tx_buffer.buffer)+referee_tx_buffer.pos,send,tx_len); + referee_tx_buffer.pos+=tx_len; +} + + /** * @brief 发送函数 * @param send 待发送数据 */ void RefereeSend(uint8_t *send, uint16_t tx_len) { - USARTSend(referee_usart_instance, send, tx_len); + USARTSend(referee_usart_instance, send, tx_len);//syhtodo此函数需要重写 /* syhtodo DMA请求过快会导致数据发送丢失,考虑数据尽可能打成一个整包以及队列发送,并且发送函数添加缓冲区 */ } + + /*裁判系统串口接收回调函数,解析数据 */ static void RefereeRxCallback() { diff --git a/modules/referee/rm_referee.h b/modules/referee/rm_referee.h index 16fb381..08d9a01 100644 --- a/modules/referee/rm_referee.h +++ b/modules/referee/rm_referee.h @@ -7,6 +7,14 @@ extern uint8_t UI_Seq; #pragma pack(1) +#define RE_TX_BUFFER_SIZE 1024 +//发送缓冲区结构体定义 +typedef struct +{ + uint8_t buffer[RE_TX_BUFFER_SIZE]; + uint8_t pos; +} referee_tx_buffer_t; + typedef struct { uint8_t Robot_Color; //机器人颜色 @@ -50,6 +58,13 @@ typedef struct */ referee_info_t *RefereeInit(UART_HandleTypeDef *referee_usart_handle); + +/** + * @brief 载入缓存区函数 + * @param send 待载入的数据 + */ +void RefereeLoadToBuffer(uint8_t *send, uint16_t tx_len); + /** * @brief 发送函数 * @todo