You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

54 lines
1.3 KiB

#include "tjc_screen_receive.h"
#include "tick.h"
#include <string.h>
#include <stdio.h>
/***********************************************************************************************************************
* 接收数据变量 *
***********************************************************************************************************************/
static uint8_t rxbuf[BUF_MAX_LEN];
static uint8_t rxCache;
static uint16_t size;
static uint32_t ticktime;
static UART_HandleTypeDef* m_uart;
static uint8_t rxCache;
void tjc_receive_init(UART_HandleTypeDef* uart) {
HAL_UART_Receive_IT(uart, &rxCache, 1);
m_uart = uart;
}
/*
*
* @brief 串口数据接收
*
*/
void tjc_uart_receive(void) {
if (size >= BUF_MAX_LEN) {
return;
}
rxbuf[size] = rxCache;
size++;
ticktime = HAL_GetTick();
}
void tjc_date_pack(packet_t* packet) {
if (size != 0 && pass_time(ticktime) > OVERTIME) {
__disable_irq();
if (size != 0 && pass_time(ticktime) > OVERTIME) {
printf("buf:%s\n", rxbuf);
memcpy(packet->date, rxbuf, sizeof(packet->date));
packet->len = size;
memset(rxbuf, 0, sizeof(rxbuf));
size = 0;
}
__enable_irq();
}
}