From de3b026b347adbfcdc1f18d886b94e2aabc99302 Mon Sep 17 00:00:00 2001 From: YuanHongbin <975559679@qq.com> Date: Fri, 31 Jul 2026 11:01:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(cat1,rs485,culs):=20=E4=BF=AE=E5=A4=8D8?= =?UTF-8?q?=E9=A1=B9Bug+culs=E6=98=BE=E7=A4=BA=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复: - Cat1OverHandler短AT应答阈值>5->>0, 修复OK/ERROR等4字节响应丢弃 - +LIPURC短数据双重解析, 去重只保留接收线程拦截 - Auch模式CAT_ONE_REV_DATA信号量残留, 加rt_sem_take(0)消费 - sscanf %s限宽%119s防rData[120]栈溢出 - Cat1接收线程先清零CatOneRxLen再处理, 防ISR数据丢失 - RS485同样快照长度先清零再memcpy, 防竞态 - RS485 ch1 upgrade off误写Ch2 - LoraIRQ线程栈512->1024 culs显示优化: - DevType+SensorNum一行, 每个传感器Master/Slave MAC Type [Laser] - Bat/Rssi/Snr汇总一行, Online末行 - 空Type填null, 激光设备显示Laser On/Off --- .../source/Module/GateWay_Debug/DebugCmd.c | 47 ++++++++++--------- Project/GateWay/source/User/Src/CatOneTask.c | 24 ++++++++-- Project/GateWay/source/User/Src/LoraTask.c | 2 +- Project/GateWay/source/User/Src/RS485Task.c | 3 +- 4 files changed, 48 insertions(+), 28 deletions(-) diff --git a/Project/GateWay/source/Module/GateWay_Debug/DebugCmd.c b/Project/GateWay/source/Module/GateWay_Debug/DebugCmd.c index 11fcaea..297573d 100644 --- a/Project/GateWay/source/Module/GateWay_Debug/DebugCmd.c +++ b/Project/GateWay/source/Module/GateWay_Debug/DebugCmd.c @@ -389,7 +389,7 @@ void DebugCmdRS485Ctrl(int argc, char *argv[]) } else if(strstr(argv[3], "off") != NULL){ if(idx == 1) { - GateWay->ConfigPara.Rs485Ch2.UpgradeEnable = false; + GateWay->ConfigPara.Rs485Ch1.UpgradeEnable = false; DBG_LOG("RS485Ch%d Upgrade Off!\r\n", idx); } else if(idx == 2) { @@ -499,24 +499,21 @@ void DebugCmdLsCommUnit(int argc, char *argv[]) for(int i = 0; i < COMMUNIT_NUM_MAX; i++) { if(GateWay->ConfigPara.CommUnitArray[i].RegFlag == true) { CUCnt++; - CommUnitPara_t CU; - memcpy(&CU, &GateWay->ConfigPara.CommUnitArray[i], sizeof(CommUnitPara_t)); - DBG_LOG("DevType: %04X\r\n", GateWay->ConfigPara.CommUnitArray[i].CUType); - DBG_LOG("DevMac: %02X-%02X-%02X-%02X-%02X-%02X\r\n", - GateWay->ConfigPara.CommUnitArray[i].Mac[0][0], - GateWay->ConfigPara.CommUnitArray[i].Mac[0][1], - GateWay->ConfigPara.CommUnitArray[i].Mac[0][2], - GateWay->ConfigPara.CommUnitArray[i].Mac[0][3], - GateWay->ConfigPara.CommUnitArray[i].Mac[0][4], - GateWay->ConfigPara.CommUnitArray[i].Mac[0][5]); - DBG_LOG("SensorNum: %d\r\n", GateWay->ConfigPara.CommUnitArray[i].SensorN); - DBG_LOG("SensorType: "); - for(int j = 0; j < GateWay->ConfigPara.CommUnitArray[i].SensorN; j++) { - DBG_LOG("%04X ", GateWay->ConfigPara.CommUnitArray[i].SensorType[j]); + CommUnitPara_t *CU = &GateWay->ConfigPara.CommUnitArray[i]; + DBG_LOG("DevType: %04X, SensorNum: %d\r\n", CU->CUType, CU->SensorN); + for(int j = 0; j < CU->SensorN; j++) { + DBG_LOG(" %s", j == 0 ? "Master" : "Slave"); + DBG_LOG(" Mac:%02X-%02X-%02X-%02X-%02X-%02X", + CU->Mac[j][0], CU->Mac[j][1], CU->Mac[j][2], + CU->Mac[j][3], CU->Mac[j][4], CU->Mac[j][5]); + if(CU->SensorType[j] != 0x0000) + DBG_LOG(" Type:%04X", CU->SensorType[j]); + if(CU->SensorType[j] == 0x0009 || CU->SensorType[j] == 0x0011) + DBG_LOG(" Laser:%s", CU->LaserOnOff ? "On" : "Off"); + DBG_LOG("\r\n"); } - DBG_LOG("\r\n"); - DBG_LOG("Online: %s\r\n", GateWay->ConfigPara.CommUnitArray[i].CommStatus ? "Yes" : "No"); - DBG_LOG("\r\n"); + DBG_LOG(" Bat:%d%% Rssi:%d Snr:%d\r\n", CU->BatLevel, CU->RSSI, CU->Nsr); + DBG_LOG(" Online:%s\r\n\r\n", CU->CommStatus ? "Yes" : "No"); } } if(CUCnt ==0) { @@ -752,9 +749,10 @@ static void DebugCmdSetAuch(int argc, char *argv[]) return; } + GateWay->AuchRegFlag = false; GateWay->ConfigPara.Auch = ch; - if(ch == CH_CAT1) CatOneReset(); - if(ch == CH_ETH) ETHReset(); + if(ch == CH_CAT1) { CatOneReset(); CatOneTriggerRegister(); } + if(ch == CH_ETH) { ETHReset(); ETHTriggerRegister(); } DBG_LOG("Set Auch to %s.\r\n", ChannelName(ch)); WritePara((uint8_t *)&GateWay->ConfigPara, sizeof(GWConfigPara_t)); } @@ -1270,10 +1268,16 @@ void DebugCmdSelDebugChannel(int argc, char *argv[]) DBG_LOG("USART1 occupied by dbg/cat1 pair.\r\n"); return; } + if(ChannelIsActive(GateWay->ConfigPara, ch) + && GateWay->ConfigPara.Duch != ch) { + DBG_LOG("Channel %s is occupied.\r\n", ChannelName(ch)); + return; + } GateWay->ConfigPara.Duch = ch; if(ch == CH_ETH) ETHReset(); if(ch == CH_CAT1) { + CatOneReset(); DbgOrCat1Uart_Config(115200); CAT1_ON(); } @@ -1418,7 +1422,8 @@ static void DebugCmdGetPara(int argc, char *argv[]) DBG_LOG("CommUnitReadInterval: %d\r\n", GateWay->ConfigPara.CommUnitReadInterval); 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("MuchReg: %d\r\n", GateWay->MuchRegFlag); + DBG_LOG("MuchReg: %s\r\n", GateWay->ConfigPara.Much == CH_NULL ? "null" : + (GateWay->MuchRegFlag ? "true" : "false")); DBG_LOG("AuchReg: %s\r\n", GateWay->ConfigPara.Auch == CH_NULL ? "null" : (GateWay->AuchRegFlag ? "true" : "false")); diff --git a/Project/GateWay/source/User/Src/CatOneTask.c b/Project/GateWay/source/User/Src/CatOneTask.c index 5c43518..5aaddb4 100644 --- a/Project/GateWay/source/User/Src/CatOneTask.c +++ b/Project/GateWay/source/User/Src/CatOneTask.c @@ -299,7 +299,7 @@ void CatOneAtCmdAnalyze(char *RxBuff) return; } - ret = sscanf(p, "+LIPURC: 0,1,%d,%s\r\n", &rLen, rData); + ret = sscanf(p, "+LIPURC: 0,1,%d,%119s\r\n", &rLen, rData); if(ret == 2) { if(rLen < 24) return; @@ -317,6 +317,10 @@ void CatOneAtCmdAnalyze(char *RxBuff) rt_sem_release(CatOneRev_Sem); return; } + if(CatOne.TcpConnFlag && RxBuff[0] > ' ') { + DebugAnalyze(CatOne.GateWay, (uint8_t *)RxBuff, strlen(RxBuff)); + return; + } default: CatOne.ATCmdRet = CAT_ONE_RET_ERR; @@ -512,6 +516,7 @@ void CatOneLoopHandler(void) case CAT_ONE_REV_DATA: if(CatOne.GateWay->ConfigPara.Much != CH_CAT1) { + rt_sem_take(CatOneRev_Sem, 0); CatOne.Cat1Status = CAT_ONE_WAIT_SEND; break; } @@ -597,7 +602,8 @@ void CatOneLoopHandler(void) bool UploadSend(uint8_t *sData, uint16_t sLen) { - rt_mq_send(ChannelMQ(*CatOne.GateWay, CatOne.GateWay->ConfigPara.Much), sData, sLen); + if(CatOne.GateWay->ConfigPara.Much != CH_NULL) + rt_mq_send(ChannelMQ(*CatOne.GateWay, CatOne.GateWay->ConfigPara.Much), sData, sLen); if(CatOne.GateWay->ConfigPara.Auch != CH_NULL && CatOne.GateWay->ConfigPara.Auch != CatOne.GateWay->ConfigPara.Much) { rt_mq_send(ChannelMQ(*CatOne.GateWay, CatOne.GateWay->ConfigPara.Auch), sData, sLen); } @@ -627,9 +633,19 @@ void CatOneRev_Thread_Entry(void *parameter) if(result == RT_EOK) { memcpy(RxBuffTemp, CatOneRxBuff, CatOneRxLen); RxBuffTemp[CatOneRxLen] = 0; + CatOneRxLen = 0; + char *urc = strstr(RxBuffTemp, "+LIPURC: 0,1,"); + if(urc) { + int dLen; + if(sscanf(urc, "+LIPURC: 0,1,%d", &dLen) == 1 && dLen < 24) { + char *data = strchr(strchr(strchr(urc, ',')+1, ',')+1, ',') + 1; + char *end = strchr(data, '\r'); + if(end) *end = 0; + DebugAnalyze(GateWay, (uint8_t *)data, strlen(data)); + } + } CatOneAtCmdAnalyze(RxBuffTemp); memset(CatOneRxBuff, 0x00, CAT_ONE_REV_LEN_MAX); - CatOneRxLen = 0; } } } @@ -686,7 +702,7 @@ void Cat1OverHandler(void) if(Cat1RevTimeOutCnt > 0) Cat1RevTimeOutCnt--; - if(CatOneRxLen > 5 && Cat1RevTimeOutCnt == 0) { + if(CatOneRxLen > 0 && Cat1RevTimeOutCnt == 0) { Cat1RevTimeOutCnt = 20; rt_sem_release(CatOneIRQ_Sem); } diff --git a/Project/GateWay/source/User/Src/LoraTask.c b/Project/GateWay/source/User/Src/LoraTask.c index ecbbb9d..b21443f 100644 --- a/Project/GateWay/source/User/Src/LoraTask.c +++ b/Project/GateWay/source/User/Src/LoraTask.c @@ -92,7 +92,7 @@ void Lora_Thread_Entry(void *parameter) Debug_Printf("CatOneIRQ Sem Create Failed!\r\n"); } - LoraIRQ_Thread = rt_thread_create("LoraIRQ", LoraIRQ_Thread_Entry, NULL, 512, 3, 20); + LoraIRQ_Thread = rt_thread_create("LoraIRQ", LoraIRQ_Thread_Entry, NULL, 1024, 3, 20); if (LoraIRQ_Thread != RT_NULL) rt_thread_startup(LoraIRQ_Thread); diff --git a/Project/GateWay/source/User/Src/RS485Task.c b/Project/GateWay/source/User/Src/RS485Task.c index fac9433..64035b1 100644 --- a/Project/GateWay/source/User/Src/RS485Task.c +++ b/Project/GateWay/source/User/Src/RS485Task.c @@ -362,10 +362,9 @@ void RS485LoopHandler(GateWayPara GateWay, RS485Para RS485Ch, SensorCommPara SCP result = rt_sem_take(SCPara->RS485Rev_Sem, 200); if(result == RT_EOK) { - memcpy(RxBuffTemp, SCPara->RS485RxBuff, SCPara->RS485RxLen); RxLenTemp = SCPara->RS485RxLen; -// memset(SCPara->RS485RxBuff, 0x00, RS485_RX_BUFF_LEN_MAX); SCPara->RS485RxLen = 0; + memcpy(RxBuffTemp, SCPara->RS485RxBuff, RxLenTemp); if(RxBuffTemp[0] == 0x7A && RS485Ch->UpgradeEnable == true) { //升级 update_process(RxBuffTemp,RxLenTemp); }