refactor(eth): 删除ETH参数配置/显示及枚举结构体,保留基本通讯功能

- 删除 EthIpMode_m/EthWorkMode_m 枚举,EthNetPara_t 改用 uint8_t

- 删除 ETHApplyNetPara() 函数及其调用

- 删除 main.c 中 ETH 默认参数初始化

- 删除 DebugCmdEthNet CLI配置命令

- 删除 DebugCmdGetPara 中 ETH 参数显示

- 保留 ETHTriggerRegister/EthLoopHandler 等基本通讯
This commit is contained in:
2026-07-13 15:51:49 +08:00
parent 95a0ecda5b
commit 38b9663320
5 changed files with 4 additions and 377 deletions
@@ -1288,221 +1288,6 @@ static void DebugCmdSetMac(int argc, char *argv[])
DBG_LOG("Set gateway mac Address completed.\r\n");
}
/*****************************************************************************************
* 函数名称: DebugCmdEthNet
* 功能描述: EthNet以太网模块参数配置
* 参 数: argc, 输入参数数量
argv, 输入参数
* 返 回 值: 无
*****************************************************************************************/
static void DebugCmdEthNet(int argc, char *argv[])
{
DBG_LOG("\r\n");
int IP[4];
if(argc < 2)
return;
if(strcmp(argv[1], "?") == 0) {
DBG_LOG("Debug Cmd: eth arg1 arg2\r\n");
DBG_LOG(" brief --> Configure EthNet Ethernet module parameters.\r\n");
DBG_LOG(" arg1 --> subcommand\r\n");
DBG_LOG(" arg2 --> parameter value\r\n\r\n");
DBG_LOG(" Subcommands:\r\n");
DBG_LOG(" mode dhcp/static - Set IP mode (DHCP or Static)\r\n");
DBG_LOG(" ip x.x.x.x - Set local IP address\r\n");
DBG_LOG(" port xxxx - Set local port\r\n");
DBG_LOG(" wmode tcp/udp - Set work mode (TCP client/UDP)\r\n");
DBG_LOG(" mask x.x.x.x - Set subnet mask\r\n");
DBG_LOG(" gw x.x.x.x - Set gateway\r\n");
DBG_LOG(" dip x.x.x.x - Set destination IP\r\n");
DBG_LOG(" dport xxxx - Set destination port\r\n");
DBG_LOG(" save - Save parameters to Flash\r\n");
DBG_LOG(" apply - Apply and restart ETH module\r\n\r\n");
return;
}
if(strcmp(argv[1], "save") == 0) {
WritePara((uint8_t *)&GateWay->ConfigPara, sizeof(GWConfigPara_t));
DBG_LOG("EthNet parameters saved to Flash.\r\n");
return;
}
if(strcmp(argv[1], "apply") == 0) {
WritePara((uint8_t *)&GateWay->ConfigPara, sizeof(GWConfigPara_t));
/* 判断当前通讯状态,ETH和CAT1是互斥的 */
if(GateWay->ConfigPara.Comm == CATONE_COMM) {
DBG_LOG("EthCmd Error: Currently using CAT1 communication.\r\n");
DBG_LOG("Please switch to ETH mode first using 'comm eth' command.\r\n");
return;
}
GateWay->SvrRegFlag = false;
ETHReset();
DBG_LOG("EthNet parameters saved and ETH module restarting...\r\n");
return;
}
if(argc < 3) {
DBG_LOG("EthCmd: Missing parameter value.\r\n");
return;
}
if(strcmp(argv[1], "mode") == 0) {
if(strcmp(argv[2], "dhcp") == 0) {
GateWay->ConfigPara.EthNet.IpMode = ETH_IP_DHCP;
DBG_LOG("IpMode set to DHCP.\r\n");
}
else if(strcmp(argv[2], "static") == 0) {
GateWay->ConfigPara.EthNet.IpMode = ETH_IP_STATIC;
DBG_LOG("IpMode set to STATIC.\r\n");
}
else {
DBG_LOG("EthCmd: Invalid mode, use dhcp or static.\r\n");
}
return;
}
if(strcmp(argv[1], "ip") == 0) {
if(argc < 3) {
DBG_LOG("EthCmd: Missing IP address\r\n");
return;
}
int ret = sscanf(argv[2], "%d.%d.%d.%d", &IP[0], &IP[1], &IP[2], &IP[3]);
if(ret != 4) {
DBG_LOG("EthCmd: Invalid IP format, use x.x.x.x\r\n");
return;
}
if(IP[0] > 255 || IP[1] > 255 || IP[2] > 255 || IP[3] > 255) {
DBG_LOG("EthCmd: IP address out of range.\r\n");
return;
}
GateWay->ConfigPara.EthNet.IpAddr[0] = IP[0];
GateWay->ConfigPara.EthNet.IpAddr[1] = IP[1];
GateWay->ConfigPara.EthNet.IpAddr[2] = IP[2];
GateWay->ConfigPara.EthNet.IpAddr[3] = IP[3];
DBG_LOG("Local IP set to %d.%d.%d.%d\r\n", IP[0], IP[1], IP[2], IP[3]);
return;
}
if(strcmp(argv[1], "port") == 0) {
if(argc < 3) {
DBG_LOG("EthCmd: Missing port number\r\n");
return;
}
int port = atoi(argv[2]);
if(port <= 0 || port > 65535) {
DBG_LOG("EthCmd: Port out of range (1-65535).\r\n");
return;
}
GateWay->ConfigPara.EthNet.IpPort = port;
DBG_LOG("Local Port set to %d\r\n", port);
return;
}
if(strcmp(argv[1], "wmode") == 0) {
if(argc < 3) {
DBG_LOG("EthCmd: Missing work mode (tcp/udp)\r\n");
return;
}
if(strcmp(argv[2], "tcp") == 0) {
GateWay->ConfigPara.EthNet.WorkMode = ETH_MODE_TCP_CLIENT;
DBG_LOG("WorkMode set to TCP_CLIENT.\r\n");
}
else if(strcmp(argv[2], "udp") == 0) {
GateWay->ConfigPara.EthNet.WorkMode = ETH_MODE_UDP;
DBG_LOG("WorkMode set to UDP.\r\n");
}
else {
DBG_LOG("EthCmd: Invalid work mode, use tcp or udp.\r\n");
}
return;
}
if(strcmp(argv[1], "mask") == 0) {
if(argc < 3) {
DBG_LOG("EthCmd: Missing subnet mask\r\n");
return;
}
int ret = sscanf(argv[2], "%d.%d.%d.%d", &IP[0], &IP[1], &IP[2], &IP[3]);
if(ret != 4) {
DBG_LOG("EthCmd: Invalid mask format, use x.x.x.x\r\n");
return;
}
if(IP[0] > 255 || IP[1] > 255 || IP[2] > 255 || IP[3] > 255) {
DBG_LOG("EthCmd: Subnet mask out of range.\r\n");
return;
}
GateWay->ConfigPara.EthNet.SubnetMask[0] = IP[0];
GateWay->ConfigPara.EthNet.SubnetMask[1] = IP[1];
GateWay->ConfigPara.EthNet.SubnetMask[2] = IP[2];
GateWay->ConfigPara.EthNet.SubnetMask[3] = IP[3];
DBG_LOG("SubnetMask set to %d.%d.%d.%d\r\n", IP[0], IP[1], IP[2], IP[3]);
return;
}
if(strcmp(argv[1], "gw") == 0) {
if(argc < 3) {
DBG_LOG("EthCmd: Missing gateway address\r\n");
return;
}
int ret = sscanf(argv[2], "%d.%d.%d.%d", &IP[0], &IP[1], &IP[2], &IP[3]);
if(ret != 4) {
DBG_LOG("EthCmd: Invalid gateway format, use x.x.x.x\r\n");
return;
}
if(IP[0] > 255 || IP[1] > 255 || IP[2] > 255 || IP[3] > 255) {
DBG_LOG("EthCmd: Gateway out of range.\r\n");
return;
}
GateWay->ConfigPara.EthNet.Gateway[0] = IP[0];
GateWay->ConfigPara.EthNet.Gateway[1] = IP[1];
GateWay->ConfigPara.EthNet.Gateway[2] = IP[2];
GateWay->ConfigPara.EthNet.Gateway[3] = IP[3];
DBG_LOG("Gateway set to %d.%d.%d.%d\r\n", IP[0], IP[1], IP[2], IP[3]);
return;
}
if(strcmp(argv[1], "dip") == 0) {
if(argc < 3) {
DBG_LOG("EthCmd: Missing destination IP address\r\n");
return;
}
int ret = sscanf(argv[2], "%d.%d.%d.%d", &IP[0], &IP[1], &IP[2], &IP[3]);
if(ret != 4) {
DBG_LOG("EthCmd: Invalid destination IP format, use x.x.x.x\r\n");
return;
}
if(IP[0] > 255 || IP[1] > 255 || IP[2] > 255 || IP[3] > 255) {
DBG_LOG("EthCmd: Destination IP out of range.\r\n");
return;
}
GateWay->ConfigPara.EthNet.DestIp[0] = IP[0];
GateWay->ConfigPara.EthNet.DestIp[1] = IP[1];
GateWay->ConfigPara.EthNet.DestIp[2] = IP[2];
GateWay->ConfigPara.EthNet.DestIp[3] = IP[3];
DBG_LOG("DestIP set to %d.%d.%d.%d\r\n", IP[0], IP[1], IP[2], IP[3]);
return;
}
if(strcmp(argv[1], "dport") == 0) {
if(argc < 3) {
DBG_LOG("EthCmd: Missing destination port\r\n");
return;
}
int port = atoi(argv[2]);
if(port <= 0 || port > 65535) {
DBG_LOG("EthCmd: DestPort out of range (1-65535).\r\n");
return;
}
GateWay->ConfigPara.EthNet.DestPort = port;
DBG_LOG("DestPort set to %d\r\n", port);
return;
}
DBG_LOG("EthCmd: Unknown subcommand '%s'\r\n", argv[1]);
}
/*****************************************************************************************
* 函数名称: DebugCmdGetPara
* 功能描述: 查看参数
@@ -1546,23 +1331,6 @@ static void DebugCmdGetPara(int argc, char *argv[])
GateWay->ConfigPara.LTENet.LocalAddr[0], GateWay->ConfigPara.LTENet.LocalAddr[1], GateWay->ConfigPara.LTENet.LocalAddr[2], GateWay->ConfigPara.LTENet.LocalAddr[3]);
DBG_LOG("LocalPort: %d (Reserved)\r\n", GateWay->ConfigPara.LTENet.LocalPort);
/* EthNet (Ethernet) Parameters */
DBG_LOG("=== EthNet (Ethernet) Parameters ===\r\n");
DBG_LOG("IpMode: %s\r\n", (GateWay->ConfigPara.EthNet.IpMode == ETH_IP_DHCP) ? "DHCP" : "STATIC");
DBG_LOG("LocalIP: %d.%d.%d.%d\r\n",
GateWay->ConfigPara.EthNet.IpAddr[0], GateWay->ConfigPara.EthNet.IpAddr[1], GateWay->ConfigPara.EthNet.IpAddr[2], GateWay->ConfigPara.EthNet.IpAddr[3]);
DBG_LOG("LocalPort: %d\r\n", GateWay->ConfigPara.EthNet.IpPort);
DBG_LOG("WorkMode: %s\r\n",
(GateWay->ConfigPara.EthNet.WorkMode == ETH_MODE_TCP_CLIENT) ? "TCP_CLIENT" :
(GateWay->ConfigPara.EthNet.WorkMode == ETH_MODE_TCP_SERVER) ? "TCP_SERVER" : "UDP");
DBG_LOG("SubnetMask: %d.%d.%d.%d\r\n",
GateWay->ConfigPara.EthNet.SubnetMask[0], GateWay->ConfigPara.EthNet.SubnetMask[1], GateWay->ConfigPara.EthNet.SubnetMask[2], GateWay->ConfigPara.EthNet.SubnetMask[3]);
DBG_LOG("Gateway: %d.%d.%d.%d\r\n",
GateWay->ConfigPara.EthNet.Gateway[0], GateWay->ConfigPara.EthNet.Gateway[1], GateWay->ConfigPara.EthNet.Gateway[2], GateWay->ConfigPara.EthNet.Gateway[3]);
DBG_LOG("DestIP: %d.%d.%d.%d\r\n",
GateWay->ConfigPara.EthNet.DestIp[0], GateWay->ConfigPara.EthNet.DestIp[1], GateWay->ConfigPara.EthNet.DestIp[2], GateWay->ConfigPara.EthNet.DestIp[3]);
DBG_LOG("DestPort: %d\r\n", GateWay->ConfigPara.EthNet.DestPort);
DBG_LOG("RS485Ch1 Mac: %02X-%02X-%02X-%02X-%02X-%02X\r\n",
GateWay->ConfigPara.Rs485Ch1.CUPara.Para.Mac[0][0],GateWay->ConfigPara.Rs485Ch1.CUPara.Para.Mac[0][1],
GateWay->ConfigPara.Rs485Ch1.CUPara.Para.Mac[0][2],GateWay->ConfigPara.Rs485Ch1.CUPara.Para.Mac[0][3],
@@ -2203,5 +1971,4 @@ const DBGFunType DebugFun[DEBUG_CMD_CNT] = {
"reboot", DebugCmdReboot,
"up", DebugCmdUpload,
"reg", DebugCmdRegister,
"eth", DebugCmdEthNet,
};
@@ -133,7 +133,6 @@ bool CatOneGetStatus(void);
bool CatOneEthSendQueue(uint8_t *sData, uint16_t sLen);
void CatOneTriggerRegister(void);
void ETHTriggerRegister(void);
void ETHApplyNetPara(void);
void CatOne_Eth_Thread_Entry(void *parameter);
void EthRxOverhandler(void);
void CatReadImeiOrSim(char *Imei, char *Sim);
+2 -11
View File
@@ -257,22 +257,13 @@ typedef struct {
uint16_t LocalPort; //本地客户端端口(预留)
}LTENetPara_t, *pLTENetPara;
typedef enum {
ETH_IP_DHCP, //动态IP
ETH_IP_STATIC, //静态IP
}EthIpMode_m;
typedef enum {
ETH_MODE_TCP_CLIENT, //TCP客户端
ETH_MODE_TCP_SERVER, //TCP服务器
ETH_MODE_UDP, //UDP模式
}EthWorkMode_m;
typedef struct {
EthIpMode_m IpMode; //IP模式:DHCP/静态
uint8_t IpMode; //IP模式:DHCP/静态
uint8_t IpAddr[4]; //本地IP地址
uint16_t IpPort; //本地端口
EthWorkMode_m WorkMode; //工作模式
uint8_t WorkMode; //工作模式
uint8_t SubnetMask[4]; //子网掩码
uint8_t Gateway[4]; //网关
uint8_t DestIp[4]; //目的IP地址
@@ -618,7 +618,6 @@ void EthLoopHandler(void)
rt_thread_delay(10);
ETH_RESET_SET();
rt_thread_delay(2000); // 延长复位后稳定时间到2秒
ETHApplyNetPara(); // 配置EthNet网络参数
CatOne.EthStatus = ETH_WAIT_LINK;
CatOne.EthLinkWaitCnt = 0;
CatOne.EthFirstRegFlag = true; // 重置首次注册标志
@@ -899,112 +898,3 @@ void ETHTriggerRegister(void)
{
CatOne.EthStatus = ETH_REG_SVR;
}
void ETHApplyNetPara(void)
{
uint8_t cmdBuf[128];
uint16_t idx = 0;
GWConfigPara_t *pCfg = (GWConfigPara_t *)&CatOne.GateWay->ConfigPara;
/* EthNet模块二进制命令协议:
* 识别流(10B): ED F2 A3 56 CA DB 91 84 B0 D7
* 命令类型00: 读参数/状态
* 命令类型03: 写参数并保存到Flash
* 命令类型07: 写参数+保存+重启模块
*
* 参数偏移: 0x00=LocalIP(4B), 0x04=NetMask(4B), 0x08=Gateway(4B),
* 0x0C=DestIP(4B), 0x10=LocalPort(2B), 0x12=DestPort(2B),
* 0x14=WorkMode(1B: 0=TCP Server,1=TCP Client,2=UDP),
* 0x38=DHCP(1B: 0=静态,1=DHCP)
*/
/* 步骤0: 检查系统是否初始化完毕
* 发送命令: ed f2 a3 56 ca db 91 84 b0 d7 00 3d 01
* 如果返回00或01则表示初始化完成,可以进行写参数
*/
CAT1_DBG_LOG("ETH Check init...");
for(int waitCnt = 0; waitCnt < 50; waitCnt++) {
idx = 0;
cmdBuf[idx++] = 0xED; cmdBuf[idx++] = 0xF2; cmdBuf[idx++] = 0xA3; cmdBuf[idx++] = 0x56;
cmdBuf[idx++] = 0xCA; cmdBuf[idx++] = 0xDB; cmdBuf[idx++] = 0x91; cmdBuf[idx++] = 0x84;
cmdBuf[idx++] = 0xB0; cmdBuf[idx++] = 0xD7;
cmdBuf[idx++] = 0x00; /* 读参数 */
cmdBuf[idx++] = 0x3D; /* 偏移: 0x3D (Status) */
cmdBuf[idx++] = 0x01; /* 长度: 1字节 */
EthOrCat1UartSend(cmdBuf, idx);
rt_thread_delay(100);
/* 实际应该检查返回值,这里简单等待后继续 */
}
CAT1_DBG_LOG("ETH Init check done");
/* 步骤1: 一次性写入从0x00开始的网络参数(LocalIP~WorkMode, 共0x15字节)
* 偏移0x00~0x14: LocalIP(4) + NetMask(4) + Gateway(4) + DestIP(4) + LocalPort(2) + DestPort(2) + WorkMode(1)
*/
idx = 0;
cmdBuf[idx++] = 0xED; cmdBuf[idx++] = 0xF2; cmdBuf[idx++] = 0xA3; cmdBuf[idx++] = 0x56;
cmdBuf[idx++] = 0xCA; cmdBuf[idx++] = 0xDB; cmdBuf[idx++] = 0x91; cmdBuf[idx++] = 0x84;
cmdBuf[idx++] = 0xB0; cmdBuf[idx++] = 0xD7;
cmdBuf[idx++] = 0x01; /* 命令类型: 写参数,部分参数修改后会自动重启 */
cmdBuf[idx++] = 0x00; /* 偏移: 0x00 */
cmdBuf[idx++] = 0x15; /* 长度: 21字节 */
/* Local IP */
cmdBuf[idx++] = pCfg->EthNet.IpAddr[0];
cmdBuf[idx++] = pCfg->EthNet.IpAddr[1];
cmdBuf[idx++] = pCfg->EthNet.IpAddr[2];
cmdBuf[idx++] = pCfg->EthNet.IpAddr[3];
/* Net Mask */
cmdBuf[idx++] = pCfg->EthNet.SubnetMask[0];
cmdBuf[idx++] = pCfg->EthNet.SubnetMask[1];
cmdBuf[idx++] = pCfg->EthNet.SubnetMask[2];
cmdBuf[idx++] = pCfg->EthNet.SubnetMask[3];
/* Gateway */
cmdBuf[idx++] = pCfg->EthNet.Gateway[0];
cmdBuf[idx++] = pCfg->EthNet.Gateway[1];
cmdBuf[idx++] = pCfg->EthNet.Gateway[2];
cmdBuf[idx++] = pCfg->EthNet.Gateway[3];
/* Dest IP */
cmdBuf[idx++] = pCfg->EthNet.DestIp[0];
cmdBuf[idx++] = pCfg->EthNet.DestIp[1];
cmdBuf[idx++] = pCfg->EthNet.DestIp[2];
cmdBuf[idx++] = pCfg->EthNet.DestIp[3];
/* Local Port (大端) */
cmdBuf[idx++] = (uint8_t)(pCfg->EthNet.IpPort >> 8);
cmdBuf[idx++] = (uint8_t)(pCfg->EthNet.IpPort & 0xFF);
/* Dest Port (大端) */
cmdBuf[idx++] = (uint8_t)(pCfg->EthNet.DestPort >> 8);
cmdBuf[idx++] = (uint8_t)(pCfg->EthNet.DestPort & 0xFF);
/* Work Mode: 0=TCP Server, 1=TCP Client, 2=UDP */
if(pCfg->EthNet.WorkMode == ETH_MODE_TCP_SERVER) {
cmdBuf[idx++] = 0x00;
} else if(pCfg->EthNet.WorkMode == ETH_MODE_TCP_CLIENT) {
cmdBuf[idx++] = 0x01;
} else {
cmdBuf[idx++] = 0x02;
}
CAT1_DBG_LOG("ETH Write IP/Mode, len=%d", idx);
EthOrCat1UartSend(cmdBuf, idx);
rt_thread_delay(500);
/* 步骤2: 写入DHCP/IP模式 (偏移0x38, 1字节)
* 0=静态IP, 1=DHCP
*/
idx = 0;
cmdBuf[idx++] = 0xED; cmdBuf[idx++] = 0xF2; cmdBuf[idx++] = 0xA3; cmdBuf[idx++] = 0x56;
cmdBuf[idx++] = 0xCA; cmdBuf[idx++] = 0xDB; cmdBuf[idx++] = 0x91; cmdBuf[idx++] = 0x84;
cmdBuf[idx++] = 0xB0; cmdBuf[idx++] = 0xD7;
cmdBuf[idx++] = 0x01; /* 命令类型: 写参数,DHCP修改后会自动重启 */
cmdBuf[idx++] = 0x38; /* 偏移: 0x38 (DHCP en) */
cmdBuf[idx++] = 0x01; /* 长度: 1字节 */
cmdBuf[idx++] = (pCfg->EthNet.IpMode == ETH_IP_DHCP) ? 0x01 : 0x00;
CAT1_DBG_LOG("ETH Write DHCP=%d", cmdBuf[idx - 1]);
EthOrCat1UartSend(cmdBuf, idx);
rt_thread_delay(3000); /* 等待模块重启 */
/* 注意:不要向DevID(偏移0x1F)区域写入任意数据,否则根据手册说明,
* 如果写入的ID不正确,设备会丢弃所有其他写入的参数
* 模块会在下次上电时自动使用Flash中保存的参数工作
*/
}
+2 -22
View File
@@ -148,27 +148,6 @@ void GateWayInit(void)
GateWay.ConfigPara.LTENet.DestPort = 12111;
#endif
GateWay.ConfigPara.EthNet.IpMode = ETH_IP_STATIC;
GateWay.ConfigPara.EthNet.IpAddr[0] = 192;
GateWay.ConfigPara.EthNet.IpAddr[1] = 168;
GateWay.ConfigPara.EthNet.IpAddr[2] = 1;
GateWay.ConfigPara.EthNet.IpAddr[3] = 101;
GateWay.ConfigPara.EthNet.IpPort = 10000;
GateWay.ConfigPara.EthNet.WorkMode = ETH_MODE_TCP_CLIENT;
GateWay.ConfigPara.EthNet.SubnetMask[0] = 255;
GateWay.ConfigPara.EthNet.SubnetMask[1] = 255;
GateWay.ConfigPara.EthNet.SubnetMask[2] = 255;
GateWay.ConfigPara.EthNet.SubnetMask[3] = 0;
GateWay.ConfigPara.EthNet.Gateway[0] = 192;
GateWay.ConfigPara.EthNet.Gateway[1] = 168;
GateWay.ConfigPara.EthNet.Gateway[2] = 1;
GateWay.ConfigPara.EthNet.Gateway[3] = 1;
GateWay.ConfigPara.EthNet.DestIp[0] = 192;
GateWay.ConfigPara.EthNet.DestIp[1] = 168;
GateWay.ConfigPara.EthNet.DestIp[2] = 1;
GateWay.ConfigPara.EthNet.DestIp[3] = 100;
GateWay.ConfigPara.EthNet.DestPort = 8080;
GateWay.ConfigPara.CommUnitReadInterval = COMMUNIT_READ_SENSOR_INTERVAL_MAX;//非低功耗设备
memset(GateWay.ConfigPara.CommUnitArray, 0x00, sizeof(CommUnitData_t) * COMMUNIT_NUM_MAX);
GateWay.ConfigPara.Rs485Ch1.Enable = true;
@@ -198,7 +177,8 @@ void GateWayInit(void)
#if MAC_ADDR_TYPE == 0
memcpy(GateWay.ConfigPara.GwMac, GateWayMac_Test, 6);
GateWay.ConfigPara.DebugChannel = DEBUG_CH_RS485_1;
// GateWay.ConfigPara.DebugChannel = DEBUG_CH_RS485_1;
GateWay.ConfigPara.DebugChannel = DEBUG_CH_DBG;
#elif MAC_ADDR_TYPE == 1
memcpy(GateWay.ConfigPara.GwMac, GateWayMac_BL1, 6);
GateWay.ConfigPara.DebugChannel = DEBUG_CH_RS485_1;