diff --git a/DebugCmd.c b/DebugCmd.c index 5307fff..38edcc3 100644 --- a/DebugCmd.c +++ b/DebugCmd.c @@ -8,7 +8,7 @@ #define DBG_RX_LEN_MAX 128 //#define DBG_LOG(...) rt_kprintf(__VA_ARGS__) -#define DEBUG_CMD_CNT 23 +#define DEBUG_CMD_CNT 30 #define DEBUG_BUFF_SIZE_MAX 512 #define DEBUG_BUFSIZE 200 @@ -259,15 +259,15 @@ void DebugCmdRS485Ctrl(int argc, char *argv[]) return; if(strcmp(argv[1], "?") == 0) { - DBG_LOG("Debug Cmd: rs485 arg1 arg2 arg3 arg4\r\n"); + DBG_LOG("Debug Cmd: rs485 arg1 arg2 arg3\r\n"); DBG_LOG(" brief --> RS485 control command.\r\n"); DBG_LOG(" arg1 --> idx: (1, 2) RS485 channel selection.\r\n"); - DBG_LOG(" arg2 --> scmd:(o, c, v, b)Rs485 subcommand.\r\n"); + DBG_LOG(" arg2 --> scmd:(o, c, v, b, u)Rs485 subcommand.\r\n"); DBG_LOG(" scmd = o, arg3 = (on, off) RS485 Channel On-OFF.\r\n"); DBG_LOG(" scmd = c, arg3 = (on, off) Enable the internal communication unit function.\r\n"); DBG_LOG(" scmd = v, arg3 = (on, off) Set output voltage.\r\n"); - DBG_LOG(" scmd = b, arg3 = (2400~500000) Set baud rate.\r\n\r\n"); - DBG_LOG(" scmd = u, arg4 = (on, off) Set Upgrade symbol.\r\n\r\n"); + DBG_LOG(" scmd = b, arg3 = (2400~500000) Set baud rate.\r\n"); + DBG_LOG(" scmd = u, arg3 = (on, off) Set Upgrade symbol.\r\n\r\n"); return; } @@ -452,11 +452,10 @@ void DebugCmdDelCommUnit(int argc, char *argv[]) return; } GateWay->ConfigPara.CommUnitArray[ret].RegFlag = false; - //memset(&GateWay->ConfigPara.CommUnitArray[ret], 0x00, sizeof(CommUnitData_t)); + DBG_LOG("Device has been deleted!\r\n"); WritePara((uint8_t *)&GateWay->ConfigPara, sizeof(GWConfigPara_t)); } - /***************************************************************************************** * 函数名称: DebugCmdLsCommUnit * 功能描述: 查看通讯单元信息 @@ -521,7 +520,143 @@ void DebugCmdLsCommUnit(int argc, char *argv[]) DBG_LOG("No device is registered.\r\n"); } } +/***************************************************************************************** +* 函数名称: DebugCmdExclCommUnit +* 功能描述: 排除指定的通讯单元MAC +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 +*****************************************************************************************/ +void DebugCmdExclCommUnit(int argc, char *argv[]) +{ + DBG_LOG("\r\n"); + uint8_t mac[6]; + + if(argc < 2) + return; + + if(strcmp(argv[1], "?") == 0) { + DBG_LOG("Debug Cmd: excu arg1\r\n"); + DBG_LOG(" brief --> Exclude communication unit.\r\n"); + DBG_LOG(" arg1 --> mac: communication unit Mac address.\r\n"); + DBG_LOG(" mac = (XX-XX-XX-XX-XX-XX), Exclude the MAC of the specified communication unit.\r\n\r\n"); + return; + } + + int ret = sscanf(argv[1], "%x-%x-%x-%x-%x-%x", + (int *)&mac[0], (int *)&mac[1], (int *)&mac[2], (int *)&mac[3], (int *)&mac[4], (int *)&mac[5]); + if(ret != 6) { + DBG_LOG("cuex Cmd Para Error!\r\n"); + return; + } + + ret = CheckCommUnitExcl(GateWay, mac); + if(ret > -1) { + DBG_LOG("This device has been tested and eliminated at this gateway!\r\n"); + return; + } + for(int i = 0; i < COMMUNIT_NUM_MAX; i++) {//寻找空位 + if(GateWay->ConfigPara.ExclCommUnit[i].ExclFlag == false){ + GateWay->ConfigPara.ExclCommUnit[i].ExclFlag = true; + memcpy(&GateWay->ConfigPara.ExclCommUnit[i].ExclMac, &mac[0], 6); + break; + } + } + + ret = CheckCommUnitReg(GateWay, mac);//删除注册信息 + if(ret > -1) { + GateWay->ConfigPara.CommUnitArray[ret].RegFlag = false; + } + + DBG_LOG("Equipment removal was successful!\r\n"); + WritePara((uint8_t *)&GateWay->ConfigPara, sizeof(GWConfigPara_t)); +} +/***************************************************************************************** +* 函数名称: DebugCmdDelExclCommUnit +* 功能描述: 删除指定的被排除的通信单元MAC +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 +*****************************************************************************************/ +void DebugCmdDelExclCommUnit(int argc, char *argv[]) +{ + DBG_LOG("\r\n"); + uint8_t mac[6]; + + if(argc < 2) + return; + + if(strcmp(argv[1], "?") == 0) { + DBG_LOG("Debug Cmd: exdel arg1\r\n"); + DBG_LOG(" brief --> Delete the excluded communication units.\r\n"); + DBG_LOG(" arg1 --> mac: communication unit Mac address.\r\n"); + DBG_LOG(" mac = (XX-XX-XX-XX-XX-XX), Delete the MAC address of the specified excluded communication unit.\r\n\r\n"); + return; + } + + if(strcmp(argv[1], "all") == 0) { + for(uint8_t i = 0; i < COMMUNIT_NUM_MAX; i++) + { + GateWay->ConfigPara.ExclCommUnit[i].ExclFlag = false; + } + DBG_LOG("All excluded devices have been deleted!\r\n"); + WritePara((uint8_t *)&GateWay->ConfigPara, sizeof(GWConfigPara_t)); + return; + } + + int ret = sscanf(argv[1], "%x-%x-%x-%x-%x-%x", + (int *)&mac[0], (int *)&mac[1], (int *)&mac[2], (int *)&mac[3], (int *)&mac[4], (int *)&mac[5]); + if(ret != 6) { + DBG_LOG("exdel Cmd Para Error!\r\n"); + return; + } + + ret = CheckCommUnitExcl(GateWay, mac); + if(ret < 0) { + DBG_LOG("This equipment has not been ruled out!\r\n"); + return; + } + + GateWay->ConfigPara.ExclCommUnit[ret].ExclFlag = false; + DBG_LOG("The exclusion for this equipment has been cancelled!\r\n"); + WritePara((uint8_t *)&GateWay->ConfigPara, sizeof(GWConfigPara_t)); +} + +/***************************************************************************************** +* 函数名称: DebugCmdLsExclCommUnit +* 功能描述: 查看被排除的通讯单元信息 +* 参 数: argc, 输入参数数量 + argv, 输入参数 +* 返 回 值: 无 +*****************************************************************************************/ +void DebugCmdLsExclCommUnit(int argc, char *argv[]) +{ + DBG_LOG("\r\n"); + if(strcmp(argv[1], "?") == 0) { + DBG_LOG("Debug Cmd: exls\r\n\ + brief --> View the information of the excluded communication units.\r\n\r\n"); + return; + } + + int CUCnt = 0; + for(int i = 0; i < COMMUNIT_NUM_MAX; i++) { + if(GateWay->ConfigPara.ExclCommUnit[i].ExclFlag == true) { + CUCnt++; + DBG_LOG("DevMac: %02X-%02X-%02X-%02X-%02X-%02X\r\n", + GateWay->ConfigPara.ExclCommUnit[i].ExclMac[0], + GateWay->ConfigPara.ExclCommUnit[i].ExclMac[1], + GateWay->ConfigPara.ExclCommUnit[i].ExclMac[2], + GateWay->ConfigPara.ExclCommUnit[i].ExclMac[3], + GateWay->ConfigPara.ExclCommUnit[i].ExclMac[4], + GateWay->ConfigPara.ExclCommUnit[i].ExclMac[5]); + } + } + if(CUCnt ==0) { + DBG_LOG("No device is exclude.\r\n"); + } + DBG_LOG("\r\n\r\n"); +} /***************************************************************************************** * 函数名称: DebugCmdSetComm * 功能描述: 设置网关与服务通讯方式 @@ -758,7 +893,7 @@ void DebugCmdRestoreFactory(int argc, char *argv[]) } DBG_LOG("Restore factory settings, GateWay Restart...\r\n"); - memset((uint8_t *)&GateWay->ConfigPara, 0xFF, sizeof(GWConfigPara_t)); + memset((uint8_t *)&GateWay->ConfigPara, 0x00, sizeof(GWConfigPara_t)); WritePara((uint8_t *)&GateWay->ConfigPara, sizeof(GWConfigPara_t)); rt_thread_delay(1000); NVIC_SystemReset(); @@ -869,7 +1004,7 @@ void DebugCmdTimeSync(int argc, char *argv[]) return; if(strcmp(argv[1], "?") == 0) { - DBG_LOG("Debug Cmd: time\r\n"); + DBG_LOG("Debug Cmd: time args\r\n"); DBG_LOG(" brief --> Time synchronization.\r\n"); DBG_LOG(" args --> (time YYYY-MM-DD,hh:mm:ss)Set system time.\r\n\r\n"); return; @@ -944,7 +1079,7 @@ void DebugCmdSelDebugChannel(int argc, char *argv[]) return; if(strcmp(argv[1], "?") == 0) { - DBG_LOG("Debug Cmd: dch\r\n"); + DBG_LOG("Debug Cmd: dch args\r\n"); DBG_LOG(" brief --> Debug information output channel selection.\r\n"); DBG_LOG(" args --> (dbg|ch1|ch2) default: dbg\r\n"); DBG_LOG(" dbg: On board debugging serial port.\r\n"); @@ -1134,7 +1269,8 @@ static void DebugCmdGetPara(int argc, char *argv[]) DBG_LOG("Baudrate %d\r\n", GateWay->ConfigPara.Rs485Ch2.BaudRate); DBG_LOG("Lora: ch %d, rp %d, fc %d\r\n", GateWay->ConfigPara.Lora.ucChannel, GateWay->ConfigPara.Lora.RegPreamble, GateWay->ConfigPara.Lora.FreqCent); - + DBG_LOG("LpCfg: CI:%dsec, RI:%dmin, EI:%dmin, ET:%dmin\r\n", + LW_DEV_COLLECT_INTERVAL_MAX, LW_DEV_REPORT_INTERVAL_MAX, LW_DEV_ER_INTERVAL_MAX, LW_DEV_ER_TIME_MAX); struct tm *stime; uint32_t dwStamp = TimeTs(); stime = localtime(&dwStamp); @@ -1144,7 +1280,7 @@ static void DebugCmdGetPara(int argc, char *argv[]) DBG_LOG("%d:",stime->tm_hour); DBG_LOG("%d:",stime->tm_min); DBG_LOG("%d\r\n",stime->tm_sec); - DBG_LOG("**********************************************************\r\n"); + DBG_LOG("**********************************************************\r\n"); } /***************************************************************************************** @@ -1167,7 +1303,7 @@ static void DebugCmdCali(int argc, char *argv[]) if(argc > 1) { if(strcmp(argv[1], "?") == 0) { - DBG_LOG("Debug Cmd: cali\r\n"); + DBG_LOG("Debug Cmd: cali arg1\r\n"); DBG_LOG(" brief --> Calibrate the sensor.\r\n\r\n"); DBG_LOG(" arg1 --> mac: communication unit Mac address.\r\n"); DBG_LOG(" mac = (XX-XX-XX-XX-XX-XX), Calibrate specified MAC communication unit.\r\n"); @@ -1296,7 +1432,7 @@ static void DebugLaserConfig(int argc, char *argv[]) if(argc > 1) { if(strcmp(argv[1], "?") == 0) { - DBG_LOG("Debug Cmd: laser\r\n"); + DBG_LOG("Debug Cmd: laser arg1 arg2\r\n"); DBG_LOG(" brief --> Control laser cutting.\r\n"); DBG_LOG(" arg1 --> mac: communication unit Mac address.\r\n"); DBG_LOG(" mac = (XX-XX-XX-XX-XX-XX), Control specified MAC communication unit.\r\n"); @@ -1421,10 +1557,10 @@ static void DebugCmdLPConfig(int argc, char *argv[]) if(strcmp(argv[1], "?") == 0) { DBG_LOG("Debug Cmd: lpcfg arg1 arg2 arg3 arg4\r\n"); DBG_LOG(" brief --> Configure low-power device parameters.\r\n"); - DBG_LOG(" arg1 --> Collect interval\r\n"); - DBG_LOG(" arg2 --> Report interval\r\n"); - DBG_LOG(" arg3 --> Emergency reporting interval\r\n"); - DBG_LOG(" arg4 --> Emergency reporting time\r\n\r\n"); + DBG_LOG(" arg1 --> Collect interval(30~7200 second)\r\n"); + DBG_LOG(" arg2 --> Report interval(5~720 minute)\r\n"); + DBG_LOG(" arg3 --> Emergency reporting interval(1~5 minute)\r\n"); + DBG_LOG(" arg4 --> Emergency reporting time(10~120 minute)\r\n\r\n"); return; } @@ -1593,7 +1729,7 @@ static void DebugLoraConfig(int argc, char *argv[]) return; } } - if(GateWay->ConfigPara.Lora.OnOff) + if(GateWay->ConfigPara.Lora.OnOff == true) LoraInit(); WritePara((uint8_t *)&GateWay->ConfigPara, sizeof(GWConfigPara_t)); DBG_LOG("Lora reinitializes.\r\n"); @@ -1632,7 +1768,19 @@ void DebugCmdHelp(int argc, char *argv[]) len = strlen("culs ?\r\n"); memcpy(Data, "culs ?\r\n", len); DebugAnalyze(GateWay, Data, len); + + len = strlen("excu ?\r\n"); + memcpy(Data, "excu ?\r\n", len); + DebugAnalyze(GateWay, Data, len); + + len = strlen("exdel ?\r\n"); + memcpy(Data, "exdel ?\r\n", len); + DebugAnalyze(GateWay, Data, len); + len = strlen("exls ?\r\n"); + memcpy(Data, "exls ?\r\n", len); + DebugAnalyze(GateWay, Data, len); + len = strlen("comm ?\r\n"); memcpy(Data, "comm ?\r\n", len); DebugAnalyze(GateWay, Data, len); @@ -1706,9 +1854,12 @@ const DBGFunType DebugFun[DEBUG_CMD_CNT] = { "help", DebugCmdHelp, "main", DebugCmdMainOnOff, "cat1", DebugCmdCat1OnOff, - "rs485", DebugCmdRS485Ctrl, - "cudel", DebugCmdDelCommUnit, + "rs485", DebugCmdRS485Ctrl, + "cudel", DebugCmdDelCommUnit, "culs", DebugCmdLsCommUnit, + "excu", DebugCmdExclCommUnit, + "exdel", DebugCmdDelExclCommUnit, + "exls", DebugCmdLsExclCommUnit, "comm", DebugCmdSetComm, "sct", DebugCmdSetCollectTime, "his", DebugCmdReadHisData, @@ -1722,8 +1873,8 @@ const DBGFunType DebugFun[DEBUG_CMD_CNT] = { "mac", DebugCmdSetMac, "para", DebugCmdGetPara, "cali", DebugCmdCali, - "laser", DebugLaserConfig, - "lpcfg", DebugCmdLPConfig, + "laser", DebugLaserConfig, + "lpcfg", DebugCmdLPConfig, "lora", DebugLoraConfig, "reboot", DebugCmdReboot, };