本次重构完成了 433MHz 全链路协议统一:实现了 AA TYPE LEN ID PAYLOAD SUM 统一帧格式;引入了基于 AUX 的 LBT 避让与 TX 优先调度,确保高频发送稳定;完成了端口语义化重命名;并成功集成了 IO 监控、RS485 及 W5500 以太网 的标准化打包转发,实现了多源数据的高效、稳定透传。

This commit is contained in:
edisondeng
2026-05-08 15:25:19 +08:00
parent de67b86952
commit 878379f101
11 changed files with 793 additions and 121 deletions

View File

@ -113,7 +113,7 @@ static uint32_t g_routed_count = 0;
* @brief 当前正在解析的端口ID
* @note 用于在多端口环境下跟踪当前处理哪个端口的数据
*/
static uint8_t g_current_parsing_port = PORT_UART2;
static uint8_t g_current_parsing_port = PORT_DEBUG;
/**
* @brief 接收原始字节日志缓冲区
@ -275,7 +275,7 @@ static void cmd_parser_response_callback(uint8_t source_port, const char *respon
* 1. 重置所有端口的解析状态
* 2. 清零所有日志缓冲区
* 3. 重置统计计数器
* 4. 设置默认解析端口为PORT_UART2
* 4. 设置默认解析端口为PORT_DEBUG
* 5. 注册响应回调函数到解析器
*/
void CmdRouter_Init(void)
@ -299,7 +299,7 @@ void CmdRouter_Init(void)
g_response_handler = NULL;
g_processed_count = 0;
g_routed_count = 0;
g_current_parsing_port = PORT_UART2;
g_current_parsing_port = PORT_DEBUG;
/*----------------------------------------------------------
* 注册响应回调函数
@ -348,7 +348,7 @@ void CmdRouter_Task(void)
* 第一阶段UART1处理(保持原有逻辑)
*----------------------------------------------------------*/
{
port_id_t port_id = PORT_UART1;
port_id_t port_id = PORT_433;
uint16_t rx_count = MultiUART_GetRxCount(port_id);
@ -380,11 +380,11 @@ void CmdRouter_Task(void)
LOG_DEBUG("UART3", "Protocol state: %d", UART3_Protocol_GetState());
uint8_t byte;
while (MultiUART_ReadByte(PORT_UART3, &byte) > 0) {
while (MultiUART_ReadByte(PORT_RS485, &byte) > 0) {
route_result_t route = UART3_Protocol_FeedByte(byte, current_tick);
switch (route) {
case ROUTE_CMD:
CmdParser_SetSourcePort(PORT_UART3);
CmdParser_SetSourcePort(PORT_RS485);
CmdParser_FeedByte(byte, current_tick);
LOG_DEBUG("UART3", "CMD byte: 0x%02X", byte);
break;
@ -422,7 +422,7 @@ void CmdRouter_Task(void)
int appended = snprintf(msg + msg_len, sizeof(msg) - msg_len, "*%02X\r\n", cs);
LOG_DEBUG("UART3", "Constructed message: %s", msg);
// 发送ASCII消息
MultiUART_SendString(PORT_UART1, msg);
MultiUART_SendString(PORT_433, msg);
LOG_INFO("UART3", "PASSTHROUGH: %d bytes sent as ASCII message", (int)length);
} else {
LOG_DEBUG("UART3", "No passthrough data");
@ -433,7 +433,7 @@ void CmdRouter_Task(void)
}
#else
{
port_id_t port_id = PORT_UART3;
port_id_t port_id = PORT_RS485;
uint16_t rx_count = MultiUART_GetRxCount(port_id);
@ -461,7 +461,7 @@ void CmdRouter_Task(void)
* 第三阶段:检查各端口日志缓冲区的超时状态
*----------------------------------------------------------*/
for (port_id_t port_id = 0; port_id < PORT_COUNT; port_id++) {
if (port_id == PORT_UART2) {
if (port_id == PORT_DEBUG) {
continue;
}