diff --git a/DebugCmd.c b/DebugCmd.c index 34c9b0d..96bc20a 100644 --- a/DebugCmd.c +++ b/DebugCmd.c @@ -9,7 +9,7 @@ #define DBG_RX_LEN_MAX 128 //#define DBG_LOG(...) rt_kprintf(__VA_ARGS__) -#define DEBUG_CMD_CNT 30 +#define DEBUG_CMD_CNT 31 #define DEBUG_BUFF_SIZE_MAX 512 #define DEBUG_BUFSIZE 200 @@ -184,10 +184,11 @@ void DebugAnalyze(GateWayPara GateWay, uint8_t *rData, uint16_t rLen) } for(int i = 0; i < DEBUG_CMD_CNT; i++) { - if(strcmp(argv[0], DebugFun[i].DBGCmd) == 0) + if(strcmp(argv[0], DebugFun[i].DBGCmd) == 0) { DebugFun[i].DBGExec(argc, argv); + break; // 添加break避免继续匹配 + } } - memset(rData, 0x00, rLen); } /***************************************************************************************** @@ -1195,54 +1196,54 @@ void DebugCmdSelDebugChannel(int argc, char *argv[]) } /***************************************************************************************** -* 函数名称: DebugCmdSetSvr -* 功能描述: 设置服务器地址、端口 +* 函数名称: DebugCmdSetLTENet +* 功能描述: 设置Cat1/4G服务器的地址和端口 * 参 数: argc, 输入参数数量 argv, 输入参数 * 返 回 值: 无 *****************************************************************************************/ -static void DebugCmdSetSvr(int argc, char *argv[]) +static void DebugCmdSetLTENet(int argc, char *argv[]) { DBG_LOG("\r\n"); int IP[4]; int port; - + if(argc < 2) return; - + if(strcmp(argv[1], "?") == 0) { - DBG_LOG("Debug Cmd: svr arg1 arg2 arg3\r\n"); - DBG_LOG(" brief --> Set the server IP address and port for 4G communication.\r\n"); + DBG_LOG("Debug Cmd: ltenet arg1 arg2 arg3\r\n"); + DBG_LOG(" brief --> Set the server IP address and port for Cat1/4G communication.\r\n"); DBG_LOG(" arg1 --> password\r\n"); - DBG_LOG(" arg2 --> (xx.xx.xx.xx) ip\r\n"); - DBG_LOG(" arg3 --> port\r\n\r\n"); + DBG_LOG(" arg2 --> (xx.xx.xx.xx) server ip\r\n"); + DBG_LOG(" arg3 --> server port\r\n\r\n"); return; } - + if(strcmp(argv[1], "gxjt") != 0) { DBG_LOG("Password Error\r\n"); return; } - + char *IpStr = argv[2]; int ret = sscanf(IpStr, "%d.%d.%d.%d", &IP[0], &IP[1], &IP[2], &IP[3]); if(ret != 4) return; if(IP[0] > 0xff || IP[1] > 0xff || IP[2] > 0xff || IP[3] > 0xff) return; - + port = atoi(argv[3]); if(port > 0xffff) return; - - GateWay->ConfigPara.SvrAddr[0] = IP[0]; - GateWay->ConfigPara.SvrAddr[1] = IP[1]; - GateWay->ConfigPara.SvrAddr[2] = IP[2]; - GateWay->ConfigPara.SvrAddr[3] = IP[3]; - GateWay->ConfigPara.SvrPort = port; + + GateWay->ConfigPara.LTENet.DestAddr[0] = IP[0]; + GateWay->ConfigPara.LTENet.DestAddr[1] = IP[1]; + GateWay->ConfigPara.LTENet.DestAddr[2] = IP[2]; + GateWay->ConfigPara.LTENet.DestAddr[3] = IP[3]; + GateWay->ConfigPara.LTENet.DestPort = port; WritePara((uint8_t *)&GateWay->ConfigPara, sizeof(GWConfigPara_t)); - DBG_LOG("Set server ip and port completed.\r\n"); + DBG_LOG("Set LTENet server ip and port completed.\r\n"); } /***************************************************************************************** @@ -1287,6 +1288,192 @@ 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; + } + ETHReset(); + ETHResetEx(); + 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) { + 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) { + 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(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) { + 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) { + 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) { + 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) { + 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 @@ -1307,7 +1494,7 @@ static void DebugCmdGetPara(int argc, char *argv[]) } DBG_LOG("\r\n**********************************************************\r\n"); DBG_LOG("SoftWare V:%d.%d, HardWare V:%d.%d\r\n", SOFTWARE_VERSION / 10, SOFTWARE_VERSION % 10, HARDWARE_VERSION / 10, HARDWARE_VERSION % 10); - DBG_LOG("GateWay MAC: %02X-%02X-%02X-%02X-%02X-%02X\r\n", + DBG_LOG("GateWay MAC: %02X-%02X-%02X-%02X-%02X-%02X\r\n", GateWay->ConfigPara.GwMac[0], GateWay->ConfigPara.GwMac[1], GateWay->ConfigPara.GwMac[2], GateWay->ConfigPara.GwMac[3], GateWay->ConfigPara.GwMac[4], GateWay->ConfigPara.GwMac[5]); DBG_LOG("Battery: %d%\r\n", GateWay->Battery); DBG_LOG("CommInf: %s\r\n", (GateWay->ConfigPara.Comm == CATONE_COMM) ? "Cat1" : "Eth"); @@ -1315,15 +1502,39 @@ static void DebugCmdGetPara(int argc, char *argv[]) char Imei[20], Sim[32]; CatReadImeiOrSim(Imei, Sim); DBG_LOG("Cat1 IMEI: %s\r\n", Imei); - DBG_LOG("Cat1 SIM: %s\r\n", Sim); + DBG_LOG("Cat1 SIM: %s\r\n", Sim); } DBG_LOG("CommUnitReadInterval: %d\r\n", GateWay->ConfigPara.CommUnitReadInterval); - DBG_LOG("Svr MAC: %02X-%02X-%02X-%02X-%02X-%02X\r\n", + DBG_LOG("Svr MAC: %02X-%02X-%02X-%02X-%02X-%02X\r\n", GateWay->SvrMac[0], GateWay->SvrMac[1], GateWay->SvrMac[2], GateWay->SvrMac[3], GateWay->SvrMac[4], GateWay->SvrMac[5]); - DBG_LOG("Svr IP: %d.%d.%d.%d\r\n", - GateWay->ConfigPara.SvrAddr[0], GateWay->ConfigPara.SvrAddr[1], GateWay->ConfigPara.SvrAddr[2], GateWay->ConfigPara.SvrAddr[3]); - DBG_LOG("Svr Port: %d\r\n", GateWay->ConfigPara.SvrPort); DBG_LOG("Register Status: %d\r\n", GateWay->SvrRegFlag); + + /* LTENet (Cat1/4G) Parameters */ + DBG_LOG("=== LTENet (Cat1/4G) Parameters ===\r\n"); + DBG_LOG("DestAddr: %d.%d.%d.%d\r\n", + GateWay->ConfigPara.LTENet.DestAddr[0], GateWay->ConfigPara.LTENet.DestAddr[1], GateWay->ConfigPara.LTENet.DestAddr[2], GateWay->ConfigPara.LTENet.DestAddr[3]); + DBG_LOG("DestPort: %d\r\n", GateWay->ConfigPara.LTENet.DestPort); + DBG_LOG("LocalAddr: %d.%d.%d.%d (Reserved)\r\n", + 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], @@ -1890,8 +2101,8 @@ void DebugCmdHelp(int argc, char *argv[]) memcpy(Data, "dch ?\r\n", len); DebugAnalyze(GateWay, Data, len); - len = strlen("svr ?\r\n"); - memcpy(Data, "svr ?\r\n", len); + len = strlen("ltenet ?\r\n"); + memcpy(Data, "ltenet ?\r\n", len); DebugAnalyze(GateWay, Data, len); len = strlen("mac ?\r\n"); @@ -1929,6 +2140,10 @@ void DebugCmdHelp(int argc, char *argv[]) len = strlen("reg ?\r\n"); memcpy(Data, "reg ?\r\n", len); DebugAnalyze(GateWay, Data, len); + + len = strlen("eth ?\r\n"); + memcpy(Data, "eth ?\r\n", len); + DebugAnalyze(GateWay, Data, len); } const DBGFunType DebugFun[DEBUG_CMD_CNT] = { @@ -1950,7 +2165,7 @@ const DBGFunType DebugFun[DEBUG_CMD_CNT] = { "time", DebugCmdTimeSync, "qs", DebugCmdQuerySensor, "dch", DebugCmdSelDebugChannel, - "svr", DebugCmdSetSvr, + "ltenet", DebugCmdSetLTENet, "mac", DebugCmdSetMac, "para", DebugCmdGetPara, "cali", DebugCmdCali, @@ -1960,4 +2175,5 @@ const DBGFunType DebugFun[DEBUG_CMD_CNT] = { "reboot", DebugCmdReboot, "up", DebugCmdUpload, "reg", DebugCmdRegister, + "eth", DebugCmdEthNet, };