From 80d84f927fa5f2179f3d455134f2c9d5a8598a29 Mon Sep 17 00:00:00 2001 From: zhangsheng Date: Sat, 7 Mar 2026 16:38:24 +0800 Subject: [PATCH] modify bugs --- uart/uart.cpp | 10 +++++++--- uart/uart_cmd.cpp | 12 ++++++------ uart/uart_feature_parse.cpp | 14 +++++++------- uart/uart_parameter_config.cpp | 27 ++++++++++++++++----------- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/uart/uart.cpp b/uart/uart.cpp index b94afe3..cc52a6e 100644 --- a/uart/uart.cpp +++ b/uart/uart.cpp @@ -256,7 +256,7 @@ int Uart::ZigbeeTest() { } void Uart::WriteToUart(const char *strSend, int pLen) { - if (!bUpdate) + //if (!bUpdate) { printf( "\nWrite To Uart Start: %s\n",GetCurrentTime().c_str()); for (int i = 0; i < pLen; i++) { @@ -265,7 +265,8 @@ void Uart::WriteToUart(const char *strSend, int pLen) { printf( "\nWrite To Uart End.\n"); } - write_data(fd, (char *)strSend, pLen); + int iRet = write_data(fd, (char *)strSend, pLen); + printf( "WriteToUart iRet = %d, pLen = %d\n", iRet, pLen); } int Uart::ReadFromUart() { @@ -288,7 +289,10 @@ int Uart::ReadFromAlarm(){ zlog_info(zct, "==========ReadFromAlarm========len = %d", len); if (len > 0) { - if(buffer[5] == 0x02 && buffer[6] == 0x00){ + for (int i = 0; i < len; i++) { + printf( "%02x ", buffer[i] & 0xff); + } + if(buffer[5] == 0x02 && buffer[6] == 0x01){ return 0 ; }else{ return 1 ; diff --git a/uart/uart_cmd.cpp b/uart/uart_cmd.cpp index 2d68c52..b71ac07 100644 --- a/uart/uart_cmd.cpp +++ b/uart/uart_cmd.cpp @@ -136,7 +136,7 @@ void Uart::WriteChanl2Zigbee(unsigned char pad) { GlobalConfig::Zigbee_G.Chan = pad1; modify_info(tmp, (char *)&GlobalConfig::Zigbee_G); - //resetZigbee(); + resetZigbee(); } void Uart::WritePanId2Zigbee(unsigned short pad) { @@ -147,7 +147,7 @@ void Uart::WritePanId2Zigbee(unsigned short pad) { GlobalConfig::Zigbee_G.PanID = pad1; modify_info(tmp, (char *)&GlobalConfig::Zigbee_G); - //resetZigbee(); + resetZigbee(); } void Uart::WriteSpeed2Zigbee() { GlobalConfig::Zigbee_G.Serial_Rate = 0x07; @@ -156,7 +156,7 @@ void Uart::WriteSpeed2Zigbee() { unsigned short tmp; tmp = GlobalConfig::Zigbee_G.MyAddr; modify_info(tmp, (char *)&GlobalConfig::Zigbee_G); - //resetZigbee(); + resetZigbee(); } void Uart::WriteTranTimeout2Zigbee(unsigned char Time) { @@ -168,7 +168,7 @@ void Uart::WriteTranTimeout2Zigbee(unsigned char Time) { GlobalConfig::Zigbee_G.TranTimeout = Time; modify_info(tmp, (char *)&GlobalConfig::Zigbee_G); - //resetZigbee(); + resetZigbee(); } void Uart::WriteShortAddr2Zigbee(unsigned short pad) { @@ -179,7 +179,7 @@ void Uart::WriteShortAddr2Zigbee(unsigned short pad) { GlobalConfig::Zigbee_G.MyAddr = pad1; modify_info(tmp, (char *)&GlobalConfig::Zigbee_G); - //resetZigbee(); + resetZigbee(); sleep(1); } @@ -198,7 +198,7 @@ void Uart::WriteShortAddr_DistAddr2Zigbee(unsigned short pad, unsigned char *pDe GlobalConfig::ZigbeeInfo_G.MyAddr = "9999"; modify_info(tmp, (char *)&GlobalConfig::Zigbee_G); - //resetZigbee(); + resetZigbee(); } void Uart::getGPIOStatus() diff --git a/uart/uart_feature_parse.cpp b/uart/uart_feature_parse.cpp index a681595..f4266c2 100644 --- a/uart/uart_feature_parse.cpp +++ b/uart/uart_feature_parse.cpp @@ -161,13 +161,13 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) { char logInfo[100] = {0x00}; sprintf(logInfo, "ShortAddr = %s,localtimestamp = %s,staticData = %d, data = %d", strShortAddr.c_str(), localtimestamp, count, count2); zlog_info(zct, logInfo); - std::vector& data_vec = map_send_data[u_short_addr]; - const uint8_t* send_data = data_vec.data(); - WriteToUart((const char*)send_data, 100); - mssleep(50000); - WriteToUart((const char*)send_data, 100); - mssleep(50000); - WriteToUart((const char*)send_data, 100); + // std::vector& data_vec = map_send_data[u_short_addr]; + // const uint8_t* send_data = data_vec.data(); + // WriteToUart((const char*)send_data, 100); + // mssleep(50000); + // WriteToUart((const char*)send_data, 100); + // mssleep(50000); + // WriteToUart((const char*)send_data, 100); } memset(whereCon, 0x00, sizeof(whereCon)); sprintf(szTableNameData, "t_data_%s", strMeasurementID.c_str()); diff --git a/uart/uart_parameter_config.cpp b/uart/uart_parameter_config.cpp index 03da7a6..10b926c 100644 --- a/uart/uart_parameter_config.cpp +++ b/uart/uart_parameter_config.cpp @@ -140,7 +140,7 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) { // zlog_warn(zct,"This block contains incompressible data.out_len = %lu,thisSize = %lu",out_len,thisSize); // memcpy(fw_senddata,buffer,thisSize); // } - memcpy(fw_senddata,buffer,thisSize); + // memcpy(fw_senddata,buffer,thisSize); unsigned char Data[100] = {0x00}; unsigned char size[4] = {0x00}; zlog_info(zct, "thisSize = %d", (int)thisSize); @@ -170,16 +170,17 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) { Data[99] = tmp; sleep(1); WriteToUart((const char*)Data, 100); - int iRet = CheckZigbeeACK(); - if (iRet == 0) { - zlog_info(zct, "Packge ACK send success,shortAddr = %02x%02x", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); - } else { - zlog_warn(zct, "Packge ACK send failed,shortAddr = %02x%02x", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); - } + // int iRet = CheckZigbeeACK(); + // if (iRet == 0) { + // zlog_info(zct, "Packge ACK send success,shortAddr = %02x%02x", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); + // } else { + // zlog_warn(zct, "Packge ACK send failed,shortAddr = %02x%02x", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); + // } mssleep(50000); int Count = thisSize / 92; int lastSize = thisSize % 92; unsigned char UpdateData[100] = {0x00}; + unsigned char command[11] = {0xA5,0x5A,0xA5,0x02,0x02,0x02,0x02,0x00,0x00,0x00,0xAC}; //帧头[3byte] 节点地址[2byte] 数据类型[1byte] 序号[1byte] 数据包[92byte] CRC校验[1byte] zlog_warn(zbt, "Start Upgrade!!! file Size = %d,fileName = %s,Count = %d,lastSize = %d,shortAddr = %02x%02x", (int)thisSize,DataNodeUpdateFile.c_str(),Count,lastSize,UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); tmp = 0x00; @@ -192,14 +193,16 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) { UpdateData[4]=UINT16_LOW(shortAdd); UpdateData[5]=0x10; UpdateData[6]=0xff & j; - memcpy(&UpdateData[7],fw_senddata + 92 * j,92); + memcpy(&UpdateData[7],buffer + 92 * j,92); tmp = 0x00; for(int k = 0; k < 99;k++){ tmp +=UpdateData[k]; } UpdateData[99] = tmp; WriteToUart((const char*)UpdateData,100); - mssleep(1000); + mssleep(100000); + WriteToUart((const char*)command,11); + mssleep(100000); if (ReadFromAlarm() == 0) { zlog_info(zct, "Packge %d ACK send success,shortAddr = %02x%02x", j, UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); } else { @@ -222,14 +225,16 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) { UpdateData[4] = UINT16_LOW(shortAdd); UpdateData[5] = 0x10; UpdateData[6] = 0xff & Count; - memcpy(&UpdateData[7], fw_senddata + 92 * Count, lastSize); + memcpy(&UpdateData[7], buffer + 92 * Count, lastSize); tmp = 0x00; for (int k = 0; k < 99; k++) { tmp += UpdateData[k]; } UpdateData[99] = tmp; WriteToUart((const char*)UpdateData, 100); - mssleep(1000); + mssleep(100000); + getGPIOStatus(); + mssleep(100000); if (ReadFromAlarm() == 0) { zlog_info(zct, "ACK send success,shortAddr = %02x%02x", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); } else {