V1.5: 485排障加帧提交/缓冲丢弃两条日志(定位9字节去向)

This commit is contained in:
helei 2026-08-22 12:45:11 +08:00
parent d2104fd90f
commit eb2b27ddbc
1 changed files with 12 additions and 0 deletions

View File

@ -1,5 +1,6 @@
#include "uart.h" #include "uart.h"
#include "network.h" #include "network.h"
#include "log.h"
#include "hlw8032.h" #include "hlw8032.h"
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
@ -274,6 +275,12 @@ uint16_t USART2_GetRxIndex(void) { return uart2_cmd_index; } /*
void USART2_FlushRxBuf(void) void USART2_FlushRxBuf(void)
{ {
if (uart2_cmd_index > 0) {
char hex[3 * 24 + 1] = {0};
uint16_t n = uart2_cmd_index < 24 ? uart2_cmd_index : 24;
for (uint16_t i = 0; i < n; i++) snprintf(hex + i * 3, 4, "%02X ", uart2_cmd_buf[i]);
log_warn("> UART2: 清缓冲丢弃 %d 字节: %s", (int)uart2_cmd_index, hex);
}
uart2_rx_ready = 0; uart2_rx_ready = 0;
uart2_cmd_index = 0; uart2_cmd_index = 0;
/* 兜底接收中断意外停摆时ORE 后状态卡 BUSY_RX拉起来。不 Abort不动正常状态 */ /* 兜底接收中断意外停摆时ORE 后状态卡 BUSY_RX拉起来。不 Abort不动正常状态 */
@ -366,6 +373,11 @@ void USART2_Tick(void)
{ {
if (uart2_cmd_index > 0 && if (uart2_cmd_index > 0 &&
(HAL_GetTick() - uart2_last_rx_tick) > UART2_CMD_TIMEOUT_MS) { (HAL_GetTick() - uart2_last_rx_tick) > UART2_CMD_TIMEOUT_MS) {
/* 排障帧提交时打印内容485 丢帧定位) */
char hex[3 * 24 + 1] = {0};
uint16_t n = uart2_cmd_index < 24 ? uart2_cmd_index : 24;
for (uint16_t i = 0; i < n; i++) snprintf(hex + i * 3, 4, "%02X ", uart2_cmd_buf[i]);
log_info("> UART2: 帧提交 %d 字节: %s", (int)uart2_cmd_index, hex);
uart2_rx_ready = 1; uart2_rx_ready = 1;
} }
} }