From 548d1963bcd28e5a8e307bfd9ed0d14c1286f406 Mon Sep 17 00:00:00 2001
From: ypc <15051963820@163.com>
Date: Sat, 27 Jun 2026 16:24:21 +0800
Subject: [PATCH] =?UTF-8?q?<=E4=BF=AE=E6=94=B9>=201=E3=80=81=E8=B0=83?=
=?UTF-8?q?=E6=95=B4=E7=A7=81=E6=9C=89=E8=A7=84=E7=BA=A6=E7=9A=84=E9=80=9A?=
=?UTF-8?q?=E8=AE=AF=E9=85=8D=E7=BD=AE?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
release/inc/mySystem.h | 27 +--
.../libcom_decode/inc/com_channel_def.h | 35 ++++
src/system/libcom_decode/inc/com_decode.h | 1 +
.../libcom_decode/src/decode_channel_mgr.cpp | 160 ++++++++++++++----
src/system/libweb_server/src/packed_fs.c | 2 +-
test/config/SYSTEM/channel_config.xml | 17 ++
test/config/SYSTEM/channel_config_rk.xml | 17 ++
7 files changed, 197 insertions(+), 62 deletions(-)
create mode 100644 src/system/libcom_decode/inc/com_channel_def.h
create mode 100644 test/config/SYSTEM/channel_config.xml
create mode 100644 test/config/SYSTEM/channel_config_rk.xml
diff --git a/release/inc/mySystem.h b/release/inc/mySystem.h
index 7c8bf87..cad813c 100644
--- a/release/inc/mySystem.h
+++ b/release/inc/mySystem.h
@@ -57,32 +57,7 @@ typedef enum
#undef APP_MODULE
-// 通讯枚举
-typedef enum
-{
- ENUM_COMM_TCP_S_0, // 上位机TCP服务器
- ENUM_COMM_TCP_C_0, // 连接FTU的TCP客户端
- ENUM_COMM_UART_0, // 连接FTU的UART,接收FTU的数据
- ENUM_COMM_TCP_S_1, // 对上的101104 TCP服务器
- ENUM_COMM_MAX
-}enum_comm;
-
-// 网络枚举
-typedef enum
-{
- ENUM_TCP_SERVER_0,
- ENUM_TCP_CLIENT_0,
- ENUM_TCP_SERVER_1, // 104s
- ENUM_TCP_MAX
-}enum_tcp;
-
-// 串口枚举
-typedef enum
-{
- ENUM_UART_0,
- ENUM_UART_MAX
-}enum_uart;
-
+
// 应用消息队列结构体
diff --git a/src/system/libcom_decode/inc/com_channel_def.h b/src/system/libcom_decode/inc/com_channel_def.h
new file mode 100644
index 0000000..f73e49a
--- /dev/null
+++ b/src/system/libcom_decode/inc/com_channel_def.h
@@ -0,0 +1,35 @@
+/**
+ * @file com_channel_def.h
+ * @brief 通信通道配置常量 — libcom_decode 模块内部使用
+ * @details 通道数量与索引枚举,供 decode_channel_mgr / decode_data_router 使用
+ */
+#ifndef COM_CHANNEL_DEF_H
+#define COM_CHANNEL_DEF_H
+
+/* 通讯通道枚举 */
+typedef enum
+{
+ ENUM_COMM_TCP_S_0, // 上位机 TCP 服务器
+ ENUM_COMM_TCP_C_0, // 连接 FTU 的 TCP 客户端
+ ENUM_COMM_UART_0, // 连接 FTU 的串口
+ ENUM_COMM_TCP_S_1, // 对上 101/104 TCP 服务器
+ ENUM_COMM_MAX
+} enum_comm;
+
+/* TCP 通道参数数组索引(与 g_tcp_para[] 对应)*/
+typedef enum
+{
+ ENUM_TCP_SERVER_0, // TCP server: 上位机
+ ENUM_TCP_CLIENT_0, // TCP client: 连接 FTU
+ ENUM_TCP_SERVER_1, // TCP server: 对上 104
+ ENUM_TCP_MAX
+} enum_tcp;
+
+/* 串口通道参数数组索引(与 g_uart_para[] 对应)*/
+typedef enum
+{
+ ENUM_UART_0,
+ ENUM_UART_MAX
+} enum_uart;
+
+#endif /* COM_CHANNEL_DEF_H */
diff --git a/src/system/libcom_decode/inc/com_decode.h b/src/system/libcom_decode/inc/com_decode.h
index 646e4a7..ed222c2 100644
--- a/src/system/libcom_decode/inc/com_decode.h
+++ b/src/system/libcom_decode/inc/com_decode.h
@@ -1,6 +1,7 @@
#pragma once
#include "myBase.h"
+#include "com_channel_def.h"
int com_channel_create();
diff --git a/src/system/libcom_decode/src/decode_channel_mgr.cpp b/src/system/libcom_decode/src/decode_channel_mgr.cpp
index bec2a5d..c7c01d6 100644
--- a/src/system/libcom_decode/src/decode_channel_mgr.cpp
+++ b/src/system/libcom_decode/src/decode_channel_mgr.cpp
@@ -2,47 +2,135 @@
#include "myComm.h"
#include "myLog.h"
#include "myDatacenter.h"
+#include "myFunc.h"
+#include "tinyxml2.h"
#include "com_decode.h"
-LOCAL stru_tcp_para g_tcp_para[ENUM_TCP_MAX] =
-{
- [ENUM_TCP_SERVER_0] = {
- #ifdef RK356x
- .local_ip = "192.168.2.54",
- #else
- .local_ip = "192.168.80.253",
- #endif
- .local_port = 2404,
- },
- [ENUM_TCP_CLIENT_0] = {
- .remote_ip = "192.168.80.102",
- .remote_port = 2404,
- },
- [ENUM_TCP_SERVER_1] = {
- #ifdef RK356x
- .local_ip = "198.121.0.100",
- #else
- .local_ip = "198.120.10.2",
- #endif
- .local_port = 2404,
- }
-};
+LOCAL stru_tcp_para g_tcp_para[ENUM_TCP_MAX];
+LOCAL stru_uart_para g_uart_para[ENUM_UART_MAX];
-LOCAL stru_uart_para g_uart_para[ENUM_UART_MAX] =
+/**
+ * @brief 从 channel_config.xml 解析通信通道配置
+ * @details XML 格式(扁平属性,mode 在前 idx 在后):
+ *
+ *
+ *
+ * mode 决定通道类型,id 是同类通道的序号(0-based):
+ * tcp_server → g_tcp_para[] id=0→SERVER_0, id=1→SERVER_1
+ * tcp_client → g_tcp_para[] id=0→CLIENT_0
+ * uart → g_uart_para[] id=0→UART_0
+ */
+static int load_channel_config(const char *proc_dir)
{
- [ENUM_UART_0] = {
- #ifdef RK356x
- .device = "/dev/ttyS3",
- #else
- .device = "/dev/ttyUSB1",
- #endif
- .baudrate = 115200,
- .data_bits = 8,
- .stop_bits = 1,
- .parity = 'N',
+ if(NULL == proc_dir) return -1;
+
+#ifdef RK356x
+ std::string config_path = std::string(proc_dir) + "config/SYSTEM/channel_config_rk.xml";
+#else
+ std::string config_path = std::string(proc_dir) + "config/SYSTEM/channel_config.xml";
+#endif
+
+ tinyxml2::XMLDocument doc;
+ if(tinyxml2::XML_SUCCESS != doc.LoadFile(config_path.c_str()))
+ {
+ MY_LOG_I("channel config not found: %s, using defaults", config_path.c_str());
+ return -1;
}
-};
+
+ tinyxml2::XMLElement *root = doc.RootElement();
+ if(NULL == root)
+ {
+ MY_LOG_E("channel config has no root element");
+ return -1;
+ }
+
+ for(tinyxml2::XMLElement *ch = root->FirstChildElement("Channel");
+ NULL != ch;
+ ch = ch->NextSiblingElement("Channel"))
+ {
+ int idx = ch->IntAttribute("idx", -1);
+ if(idx < 0)
+ {
+ LOG_E("Channel missing or invalid idx, skipping");
+ continue;
+ }
+ const char *mode = ch->Attribute("mode");
+
+ if(mode && 0 == strcmp(mode, "tcp_server"))
+ {
+ int slot = (int)ENUM_TCP_SERVER_0 + idx;
+ if(slot >= ENUM_TCP_MAX) continue;
+ const char *ip = ch->Attribute("local_ip");
+ const char *port = ch->Attribute("local_port");
+ if(ip) strncpy(g_tcp_para[slot].local_ip, ip, COMM_IP_LEN - 1);
+ if(port) g_tcp_para[slot].local_port = (uint16_t)atoi(port);
+ }
+ else if(mode && 0 == strcmp(mode, "tcp_client"))
+ {
+ int slot = (int)ENUM_TCP_CLIENT_0 + idx;
+ if(slot >= ENUM_TCP_MAX) continue;
+ const char *ip = ch->Attribute("remote_ip");
+ const char *port = ch->Attribute("remote_port");
+ if(ip) strncpy(g_tcp_para[slot].remote_ip, ip, COMM_IP_LEN - 1);
+ if(port) g_tcp_para[slot].remote_port = (uint16_t)atoi(port);
+ }
+ else if(mode && 0 == strcmp(mode, "uart"))
+ {
+ if(idx >= ENUM_UART_MAX) continue;
+ const char *dev = ch->Attribute("device");
+ const char *baud = ch->Attribute("baud");
+ const char *db = ch->Attribute("data_bit");
+ const char *sb = ch->Attribute("stop_bit");
+ const char *par = ch->Attribute("parity");
+
+ if(dev) strncpy(g_uart_para[idx].device, dev, COMM_DEV_LEN - 1);
+ if(baud) g_uart_para[idx].baudrate = (uint32_t)atoi(baud);
+ if(db) g_uart_para[idx].data_bits = (uint8_t)atoi(db);
+ if(sb) g_uart_para[idx].stop_bits = (uint8_t)atoi(sb);
+ if(par && par[0]) g_uart_para[idx].parity = par[0];
+ }
+ }
+
+ MY_LOG_I("channel config loaded from %s", config_path.c_str());
+ return 0;
+}
+
+/**
+ * @brief 历史遗留:load_channel_config 前先用默认值兜底
+ */
+static void init_default_paras(void)
+{
+ // TCP Server 0 — 上位机
+ strncpy(g_tcp_para[ENUM_TCP_SERVER_0].local_ip, "0.0.0.0", COMM_IP_LEN - 1);
+ g_tcp_para[ENUM_TCP_SERVER_0].local_port = 2404;
+
+ // TCP Client 0 — FTU
+ strncpy(g_tcp_para[ENUM_TCP_CLIENT_0].remote_ip, "0.0.0.0", COMM_IP_LEN - 1);
+ g_tcp_para[ENUM_TCP_CLIENT_0].remote_port = 2404;
+
+ // TCP Server 1 — 104s 对上
+ strncpy(g_tcp_para[ENUM_TCP_SERVER_1].local_ip, "0.0.0.0", COMM_IP_LEN - 1);
+ g_tcp_para[ENUM_TCP_SERVER_1].local_port = 2404;
+
+ // UART 0
+ g_uart_para[ENUM_UART_0].baudrate = 115200;
+ g_uart_para[ENUM_UART_0].data_bits = 8;
+ g_uart_para[ENUM_UART_0].stop_bits = 1;
+ g_uart_para[ENUM_UART_0].parity = 'N';
+}
+
+static void init_tcp_uart_paras(void)
+{
+ char proc_dir[256] = {0};
+
+ init_default_paras();
+
+ if(0 == func_get_process_self_dir(proc_dir, sizeof(proc_dir)))
+ {
+ load_channel_config(proc_dir);
+ }
+}
typedef struct
{
@@ -175,6 +263,8 @@ void com_channel_start()
int com_channel_create()
{
+ init_tcp_uart_paras();
+
for(int i = 0; i < ENUM_COMM_MAX; i++)
{
if((g_channel_para[i].id = comm_create(g_channel_para[i].type, g_channel_para[i].debug_show, g_channel_para[i].p_para)) < 0)
diff --git a/src/system/libweb_server/src/packed_fs.c b/src/system/libweb_server/src/packed_fs.c
index b0bba20..ec2f3d2 100644
--- a/src/system/libweb_server/src/packed_fs.c
+++ b/src/system/libweb_server/src/packed_fs.c
@@ -5072,7 +5072,7 @@ static const unsigned char v8[] = {
};
const struct mg_mem_file mg_packed_files[] = {
- {"/css/style.css", v3, sizeof(v3) - 1, 1782465409},
+ {"/css/style.css", v3, sizeof(v3) - 1, 1782467023},
{"/index.html", v4, sizeof(v4) - 1, 1782440107},
{"/js/app.js", v5, sizeof(v5) - 1, 1782440107},
{"/js/monitor.js", v6, sizeof(v6) - 1, 1782440107},
diff --git a/test/config/SYSTEM/channel_config.xml b/test/config/SYSTEM/channel_config.xml
new file mode 100644
index 0000000..5b445f3
--- /dev/null
+++ b/test/config/SYSTEM/channel_config.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+
diff --git a/test/config/SYSTEM/channel_config_rk.xml b/test/config/SYSTEM/channel_config_rk.xml
new file mode 100644
index 0000000..72c8eaa
--- /dev/null
+++ b/test/config/SYSTEM/channel_config_rk.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
+
+