From f5cd347fdd9fe38dc8d9316c8ba8cefabc571b31 Mon Sep 17 00:00:00 2001 From: "haifeng.wang" Date: Fri, 30 May 2025 12:38:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E4=BA=86=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=AE=BE=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Anjiehui7_DTU/User/dwin_form.c | 115 +++++++++++++++++-------- Anjiehui7_DTU/User/modbus_slave.c | 125 ++++++++++++++-------------- Anjiehui7_DTU/User/uart_Ethernet.c | 3 +- Anjiehui7_DTU/User/uart_RFGateway.c | 6 +- 4 files changed, 149 insertions(+), 100 deletions(-) diff --git a/Anjiehui7_DTU/User/dwin_form.c b/Anjiehui7_DTU/User/dwin_form.c index b51d8ae..71b67b8 100644 --- a/Anjiehui7_DTU/User/dwin_form.c +++ b/Anjiehui7_DTU/User/dwin_form.c @@ -130,8 +130,8 @@ void DWIN_ParseFrame(uint8_t c) printf("\n"); // 触摸按键返回 - if(readData.Addr == 0x5000 || readData.Addr == 0x5012 || readData.Addr == 0x5030 - || readData.Addr == 0x5022 || readData.Addr == 0x502C || readData.Addr == 0x502E + if(readData.Addr == 0x5000 || readData.Addr == 0x5012 || readData.Addr == 0x5030|| readData.Addr == 0x9100 + || readData.Addr == 0x5022 || readData.Addr == 0x502C || readData.Addr == 0x502E|| readData.Addr == 0x5038 || readData.Addr == 0x5032|| readData.Addr == 0x5034|| readData.Addr == 0x5036|| readData.Addr == 0x6F00) { LoopBuff_PutItem(&Form_KeyM, (uint8_t *) &readData); @@ -359,19 +359,19 @@ void Form_RefreshGrid2(form_grid2_t *grid) // 加入队列 LoopBuff_PutItem(&Form_DataM, (uint8_t *) &formData); } - //boxCnt.count=12; - formData.oper = DWIN_OPER_WRITE; - formData.Addr = 0x9002; - formData.count = 2; - formData.word[0] = htons((boxCnt.count/30)+1); - LoopBuff_PutItem(&Form_DataM, (uint8_t *) &formData); + //boxCnt.count=12; formData.oper = DWIN_OPER_WRITE; - formData.Addr = 0x9000; - formData.count = 2; - formData.word[0] = htons((topPtr/30)+1); - LoopBuff_PutItem(&Form_DataM, (uint8_t *) &formData); - - + formData.Addr = 0x9002; + formData.count = 2; + formData.word[0] = htons((boxCnt.count/30)+1); + LoopBuff_PutItem(&Form_DataM, (uint8_t *) &formData); + formData.oper = DWIN_OPER_WRITE; + formData.Addr = 0x9000; + formData.count = 2; + formData.word[0] = htons((topPtr/30)+1); + LoopBuff_PutItem(&Form_DataM, (uint8_t *) &formData); + + // 再将备份缓冲作为显示缓冲 for(i = 0; i < 30; i++) { @@ -687,7 +687,7 @@ void Form_Task(void *p_arg) "BOX ", "PSN "," BOX ", "PSN "," BOX ", "PSN "); data.count = strlen(data.str); DWIN_Refresh(&data); - + // data.oper = DWIN_OPER_WRITE; // data.Addr = gridBox.hdrAddr+0x1000; // sprintf(data.str, "%6s", @@ -700,7 +700,7 @@ void Form_Task(void *p_arg) data.oper = DWIN_OPER_WRITE; data.Addr = 0x6580; if(dcBuff.configDisplay.ch_en) - strcpy(data.str, " Level-%"); + strcpy(data.str, "Level-%"); else strcpy(data.str, " 液位-%"); data.count = strlen(data.str); @@ -719,7 +719,7 @@ void Form_Task(void *p_arg) data.oper = DWIN_OPER_WRITE; data.Addr = 0x6590; if(dcBuff.configDisplay.ch_en) - strcpy(data.str, "pressure-%"); + strcpy(data.str, "pres-MPa"); else strcpy(data.str, "压力-MPa"); data.count = strlen(data.str); @@ -738,7 +738,7 @@ void Form_Task(void *p_arg) data.oper = DWIN_OPER_WRITE; data.Addr = 0x65A0; if(dcBuff.configDisplay.ch_en) - strcpy(data.str, "Temperature-%"); + strcpy(data.str, "Temp-℃%"); else strcpy(data.str, "温度-℃"); data.count = strlen(data.str); @@ -1257,8 +1257,8 @@ void Form_RestoreParam() formData.count = 4; formData.dword[0] = htonl(dcBuff.configBottle.offlineSeconds); LoopBuff_PutItem(&Form_DataM, (uint8_t *) &formData); - - formData.Addr = 0x5038; + + formData.Addr = 0x5038; formData.count = 2; formData.dword[0] = htons(dcBuff.configBottle.lora_freq); LoopBuff_PutItem(&Form_DataM, (uint8_t *) &formData); @@ -1292,9 +1292,9 @@ uint8_t Form_SaveParam() return 0; if(!Form_ReadUInt32(0x5020, &offlineSeconds)) return 0; - if(!Form_ReadUInt16(0x5038, &lora_freq)) + if(!Form_ReadUInt16(0x5038, &lora_freq)) return 0; - + if(emptyPct * 100 != dcBuff.configBottle.emptyPct) { dcBuff.configBottle.emptyPct = emptyPct * 100; @@ -1677,8 +1677,8 @@ uint8_t Form_PreQuery() if(formQuery.func == 1) { if(dcBuff.configDisplay.ch_en) - sprintf(formData.str, " %4s %11s %6s %9s %8s %4s %4s %4s %13s %5s %5s %7s", - "Num", " Box_number ", "Percentage", "Press(MPa)", "Temp(℃)", "Alarm", "Err", "Offline", " PSN ", "Date", "Time", "Vol(v)"); + sprintf(formData.str, " %4s %11s %6s %10s %5s %6s %4s%8s %12s %5s %5s %7s", + "Num", "Box_number", "Per.", "Press(MPa)", "Temp", "Alarm", "Err", "Offline", "PSN ", "Date", "Time", "Vol(v)"); else sprintf(formData.str, " %4s %11s %6s %9s %8s %4s %4s %4s %13s %5s %5s %7s", @@ -1687,8 +1687,8 @@ uint8_t Form_PreQuery() else if(formQuery.func == 2) { if(dcBuff.configDisplay.ch_en) - sprintf(formData.str, " %5s %5s %11s %10s %8s %6s %9s %8s %4s %4s %13s", - "Data", "Time", " Box_number ", "Level(mmWC)", "m(kg)", "Percent", "Press(MPa)", "Temp(℃)", "Alarm", "Err", " PSN "); + sprintf(formData.str, " %5s %5s %10s %7s %6s %8s %11s %5s %6s %4s %13s", + "Data", "Time", "Box_number", "Level", "m(kg)", "Percent", "Press(MPa)", "Temp", "Alarm", "Err", " PSN "); else sprintf(formData.str, " %5s %5s %11s %10s %8s %6s %9s %8s %4s %4s %13s", @@ -1719,7 +1719,10 @@ uint8_t Form_PreQuery() // 切换页面 Form_ClearGrid(&gridQuery); - Form_SwitchPage(17 + (formQuery.func - 1)); + if(dcBuff.configDisplay.ch_en) + Form_SwitchPage(67 + (formQuery.func - 1)); + else + Form_SwitchPage(17 + (formQuery.func - 1)); // 用于翻页的序号 gridQuery.topPtr = -1; @@ -2524,10 +2527,10 @@ void Form_BOX_PSN() gridBox.rowCount=boxCnt.count;// rowCount=gridBox.rowCount; if(rowCount>30) - { - rowCount=30; - gridBox.rowCount=30; - } + { + rowCount=30; + gridBox.rowCount=30; + } for(i=0; icmd == 0x02) // 读保持数据 { - cnt = req->index; // 参数个数 + cnt = req->index; // 参数个数 memset(&boxRec, 0, sizeof(ext_box_t)); - memset(&bottleRec, 0, sizeof(ext_bottle_t)); + memset(&bottleRec, 0, sizeof(ext_bottle_t)); boxRec.PSN[0] = req->PSN[0]; boxRec.PSN[1] = req->PSN[1]; boxRec.PSN[2] = req->PSN[2]; boxRec.PSN[3] = req->PSN[3]; boxRec.PSN[4] = req->PSN[4]; boxRec.PSN[5] = req->PSN[5]; - - bottleRec.PSN[0] = req->PSN[0]; - bottleRec.PSN[1] = req->PSN[1]; + + bottleRec.PSN[0] = req->PSN[0]; + bottleRec.PSN[1] = req->PSN[1]; bottleRec.PSN[2] = req->PSN[2]; bottleRec.PSN[3] = req->PSN[3]; bottleRec.PSN[4] = req->PSN[4]; bottleRec.PSN[5] = req->PSN[5]; for(int i=0; i<11; i++) boxRec.TGGU[i]=req->BOX[i]; - boxRec.TGGU[11]=0; + boxRec.TGGU[11]=0; if(req->index>0)count=req->index-1; - - FRAM_BufferWrite(FRAM_BOX_DATA_BASE + sizeof(ext_box_t) * count, (uint8_t *) &boxRec, sizeof(ext_box_t)); + + FRAM_BufferWrite(FRAM_BOX_DATA_BASE + sizeof(ext_box_t) * count, (uint8_t *) &boxRec, sizeof(ext_box_t)); // // 更新索引信息 - bottleRec.lastData = -1; - FRAM_BufferWrite(FRAM_BOTTLE_DATA_BASE + sizeof(ext_bottle_t) * count, (uint8_t *) &bottleRec, sizeof(ext_bottle_t)); + bottleRec.lastData = -1; + FRAM_BufferWrite(FRAM_BOTTLE_DATA_BASE + sizeof(ext_bottle_t) * count, (uint8_t *) &bottleRec, sizeof(ext_bottle_t)); -// strcpy(boxTGGU[count].TGGU, boxRec.TGGU); -// memmove(boxTGGU[count].PSN, boxRec.PSN, 6); -// boxTGGU[count].recNo = count; -// strcpy(boxPSN[count].TGGU, boxRec.TGGU); -// memmove(boxPSN[count].PSN, boxRec.PSN, 6); -// boxPSN[count].recNo = count; + memset(BUFF2, 0, sizeof(BUFF2)); + BUFF2[len++]='L'; + BUFF2[len++]='S'; + BUFF2[len++] = dcBuff.configBottle.addr; // 从机地址 + BUFF2[len++] = 2;//req->cmd; // 命令代码 + BUFF2[len++] = 0; + BUFF2[len++] = 1; //LEN + BUFF2[len++] = 1; - if(req->index==req->all) - { - boxCnt.count=req->all; - bottleCnt.count = req->all; + // 计算CRC + crc = MODBUS_RTU_CRC16(BUFF2, len); + crc = htons(crc); + + memmove(BUFF2 + len, &crc, 2); + len += 2; + RS485_SendDataByte(BUFF2, len); + + if(req->index==req->all) + { + boxCnt.count=req->all; + bottleCnt.count = req->all; FRAM_SaveInfo(FRAM_BOX_INFO_BASE, (uint8_t *) &boxCnt, sizeof(ext_count_t)); - FRAM_SaveInfo(FRAM_BOTTLE_INFO_BASE, (uint8_t *) &bottleCnt, sizeof(ext_count_t)); - } - - memset(BUFF2, 0, sizeof(BUFF2)); - BUFF2[len++]='L'; - BUFF2[len++]='S'; - BUFF2[len++] = dcBuff.configBottle.addr; // 从机地址 - BUFF2[len++] = 2;//req->cmd; // 命令代码 - BUFF2[len++] = 0; - BUFF2[len++] = 1; //LEN - BUFF2[len++] = 1; + FRAM_SaveInfo(FRAM_BOTTLE_INFO_BASE, (uint8_t *) &bottleCnt, sizeof(ext_count_t)); + osDelay(500); + HAL_NVIC_SystemReset(); + } - // 计算CRC - crc = MODBUS_RTU_CRC16(BUFF2, len); - crc = htons(crc); - - memmove(BUFF2 + len, &crc, 2); - len += 2; - RS485_SendDataByte(BUFF2, len); } - else if(req->cmd == 0x05) - { - if(LoopBuff_GetCount(&Modbus_SendM)) + else if(req->cmd == 0x05) + { + if(LoopBuff_GetCount(&Modbus_SendM)) { // 取数据 memmove(&Gprs, LoopBuff_GetDataPtr(&Modbus_SendM, Modbus_SendM.info.rdPtr), sizeof(ext_data_t)); @@ -263,9 +259,9 @@ void MODBUS_RTU_CMD(modbus_request_t *req) // TODO: 发送数据到上位机,不等待返回 RS485_SendDataByte(Modbus_sendBuff, i); } - - } - + + } + } @@ -318,6 +314,7 @@ void ReadModbus_Task(uint8_t c) case 3: BUFF[len]=c; if(c==2) len++; + else if(c==5)len+=2; else len=0; break; case 4: @@ -345,6 +342,7 @@ void ReadModbus_Task(uint8_t c) break; default: len=0; + break; } if((len==0)&&(data_len2>1)) { @@ -355,4 +353,9 @@ void ReadModbus_Task(uint8_t c) } data_len2=0; } + else if(BUFF[3]==5) + { + MODBUS_RTU_CMD((modbus_request_t *) BUFF); + data_len2=0; + } } diff --git a/Anjiehui7_DTU/User/uart_Ethernet.c b/Anjiehui7_DTU/User/uart_Ethernet.c index e80791a..e6788e8 100644 --- a/Anjiehui7_DTU/User/uart_Ethernet.c +++ b/Anjiehui7_DTU/User/uart_Ethernet.c @@ -194,7 +194,8 @@ void Ethernet_Config() if(RF_APP == RF_APP_AJH) { // if(!Ethernet_ATCmd("AT+SOCKA1=TCPC,171.88.5.52,8061", "+OK", "+ERR")) // 公司路由器 - if(!Ethernet_ATCmd("AT+SOCKA1=TCPC,extra.cd-ls.cn,8061", "+OK", "+ERR")) +// if(!Ethernet_ATCmd("AT+SOCKA1=TCPC,extra.cd-ls.cn,8061", "+OK", "+ERR")) + if(!Ethernet_ATCmd("AT+SOCKA1=TCPC,121.89.205.240,41001", "+OK", "+ERR")) // if(!Ethernet_ATCmd("AT+SOCKA1=TCPC,data.ajhiot.com,8088", "+OK", "+ERR")) // if(!Ethernet_ATCmd("AT+SOCKA1=TCPC,114.55.209.85,8088", "+OK", "+ERR")) // data.ajhiot.com // if(!Ethernet_ATCmd("AT+SOCKA1=TCPC,192.168.0.2,8061", "+OK", "+ERR")) // 直连电脑 diff --git a/Anjiehui7_DTU/User/uart_RFGateway.c b/Anjiehui7_DTU/User/uart_RFGateway.c index 6cc6cdd..59b2c13 100644 --- a/Anjiehui7_DTU/User/uart_RFGateway.c +++ b/Anjiehui7_DTU/User/uart_RFGateway.c @@ -741,12 +741,12 @@ void RF_GatewayTask(void *p_arg) if(RTC_offsetSeconds == 0) { printf("\nRTC_offsetSeconds = 0, ignored ...\n"); - //apex continue; +// continue;//apex } // 处理帧 idx = Ext_Lookup_Bottle_PSN(RF_ProcFrame.srcPSN, bottleCnt.count); - if(idx == -1) continue; + if(idx == -1) continue; // 是否需要回应ack if(RF_ProcFrame.mac_ack_req) { @@ -905,7 +905,7 @@ void RF_TranTask(void *p_arg) Ethernet_Config(); } - // 掉电有效,如果未获取到UTC时间,不转发 + // 掉电有效,如果未获取到UTC时间,不转发 //apex if(RTC_offsetSeconds > 0 && LoopBuff_GetCount(&RF_TranM) > 0 && Ethernet_connected) { if(!SFlash_LoadInfo(LoopBuff_GetDataPos(&RF_TranM, RF_TranM.info.rdPtr), (uint8_t *) &Ext_Data_Rec1, sizeof(ext_data_t)))