<修改> 1、调整私有规约的通讯配置

This commit is contained in:
ypc 2026-06-27 16:24:21 +08:00
parent cbe18b0d4e
commit 548d1963bc
7 changed files with 197 additions and 62 deletions

View File

@ -57,32 +57,7 @@ typedef enum
#undef APP_MODULE #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;
// 应用消息队列结构体 // 应用消息队列结构体

View File

@ -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 */

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "myBase.h" #include "myBase.h"
#include "com_channel_def.h"
int com_channel_create(); int com_channel_create();

View File

@ -2,47 +2,135 @@
#include "myComm.h" #include "myComm.h"
#include "myLog.h" #include "myLog.h"
#include "myDatacenter.h" #include "myDatacenter.h"
#include "myFunc.h"
#include "tinyxml2.h"
#include "com_decode.h" #include "com_decode.h"
LOCAL stru_tcp_para g_tcp_para[ENUM_TCP_MAX] = LOCAL stru_tcp_para g_tcp_para[ENUM_TCP_MAX];
{ LOCAL stru_uart_para g_uart_para[ENUM_UART_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_uart_para g_uart_para[ENUM_UART_MAX] = /**
* @brief channel_config.xml
* @details XML mode idx :
* <Channel mode="tcp_server" idx="0" desc="上位机TCP服务器" local_ip="..." local_port="2404"/>
* <Channel mode="uart" idx="0" desc="连接FTU的串口" device="/dev/ttyS3" baud="115200" .../>
*
* mode id 0-based:
* tcp_server g_tcp_para[] id=0SERVER_0, id=1SERVER_1
* tcp_client g_tcp_para[] id=0CLIENT_0
* uart g_uart_para[] id=0UART_0
*/
static int load_channel_config(const char *proc_dir)
{ {
[ENUM_UART_0] = { if(NULL == proc_dir) return -1;
#ifdef RK356x
.device = "/dev/ttyS3", #ifdef RK356x
#else std::string config_path = std::string(proc_dir) + "config/SYSTEM/channel_config_rk.xml";
.device = "/dev/ttyUSB1", #else
#endif std::string config_path = std::string(proc_dir) + "config/SYSTEM/channel_config.xml";
.baudrate = 115200, #endif
.data_bits = 8,
.stop_bits = 1, tinyxml2::XMLDocument doc;
.parity = 'N', 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 typedef struct
{ {
@ -175,6 +263,8 @@ void com_channel_start()
int com_channel_create() int com_channel_create()
{ {
init_tcp_uart_paras();
for(int i = 0; i < ENUM_COMM_MAX; i++) 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) 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)

View File

@ -5072,7 +5072,7 @@ static const unsigned char v8[] = {
}; };
const struct mg_mem_file mg_packed_files[] = { 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}, {"/index.html", v4, sizeof(v4) - 1, 1782440107},
{"/js/app.js", v5, sizeof(v5) - 1, 1782440107}, {"/js/app.js", v5, sizeof(v5) - 1, 1782440107},
{"/js/monitor.js", v6, sizeof(v6) - 1, 1782440107}, {"/js/monitor.js", v6, sizeof(v6) - 1, 1782440107},

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
通信通道配置文件 (x86 平台)
每个 Channel 定义一个物理通信口mode 决定类型:
tcp_server — TCP 服务端监听idx 是该类通道的序号 (0-based)
tcp_client — TCP 客户端(主动连接)
uart — 串口
同类型多个通道通过 idx 区分,例:
mode="tcp_server" idx="0" → 第一路 TCP 服务端 (ENUM_TCP_SERVER_0)
mode="tcp_server" idx="1" → 第二路 TCP 服务端 (ENUM_TCP_SERVER_1)
-->
<Root>
<Channel mode="tcp_server" idx="0" desc="上位机TCP服务器" local_ip="192.168.80.253" local_port="2404"/>
<Channel mode="tcp_client" idx="0" desc="连接FTU的TCP客户端" remote_ip="192.168.80.102" remote_port="2404"/>
<Channel mode="tcp_server" idx="1" desc="对上101104的TCP服务器" local_ip="198.120.10.2" local_port="2404"/>
<Channel mode="uart" idx="0" desc="连接FTU的串口" device="/dev/ttyUSB1" baud="115200" data_bit="8" stop_bit="1" parity="N"/>
</Root>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
通信通道配置文件 (RK3568 平台)
每个 Channel 定义一个物理通信口mode 决定类型:
tcp_server — TCP 服务端监听idx 是该类通道的序号 (0-based)
tcp_client — TCP 客户端(主动连接)
uart — 串口
同类型多个通道通过 idx 区分,例:
mode="tcp_server" idx="0" → 第一路 TCP 服务端 (ENUM_TCP_SERVER_0)
mode="tcp_server" idx="1" → 第二路 TCP 服务端 (ENUM_TCP_SERVER_1)
-->
<Root>
<Channel mode="tcp_server" idx="0" desc="上位机TCP服务器" local_ip="192.168.2.54" local_port="2404"/>
<Channel mode="tcp_client" idx="0" desc="连接FTU的TCP客户端" remote_ip="192.168.80.102" remote_port="2404"/>
<Channel mode="tcp_server" idx="1" desc="对上101104的TCP服务器" local_ip="198.121.0.100" local_port="2404"/>
<Channel mode="uart" idx="0" desc="连接FTU的串口" device="/dev/ttyS3" baud="115200" data_bit="8" stop_bit="1" parity="N"/>
</Root>