应注意,前一段报文接收后,下一段报文的首字节位置将位于前报文尾,故增加超时判定,超时时,重置字节接收对应缓冲区位置,并将首字节转移。
/* UART rx callback for continuous reception, byte by byte */
void rxCallback(void *driverState, uart_event_t event, void *userData)
{
/* Unused parameters */
(void)driverState;
(void)userData;
/* Check the event type */
if (event == UART_EVENT_RX_FULL){
/* The reception stops when newline is received or the buffer is full */
if(TIMER_HAL_IsUart2msTickTimeout()){
Rx_buffer[0] = Rx_buffer[u8bufferIdx];
u8bufferIdx = 0;
TIMER_HAL_ClearTickTimeout();
}
if(u8bufferIdx <= BUFFER_SIZE - 2){
u8bufferIdx++;
LPUART_DRV_SetRxBuffer(INST_LPUART1, &Rx_buffer[u8bufferIdx], 1U);
TIMER_HAL_ClearTickTimeout();
}else{
u8bufferIdx = 0;
LPUART_DRV_SetRxBuffer(INST_LPUART1, &Rx_buffer[0], 1U);
}
}
}