From f50c3e35de8dbd6293a7df52fa36c52523b47afc Mon Sep 17 00:00:00 2001 From: zhangsheng Date: Fri, 30 May 2025 18:31:15 +0800 Subject: [PATCH] fix bugs --- common/global.hpp | 2 +- scheduler/schedule.cpp | 6 +++--- uart/uart.cpp | 4 ++-- uart/uart_feature_parse.cpp | 18 ++++++++++++++++-- wifi_5g/scan_blueteeth.cpp | 14 +++++++++++--- 5 files changed, 33 insertions(+), 11 deletions(-) diff --git a/common/global.hpp b/common/global.hpp index 3567c20..0f9d618 100644 --- a/common/global.hpp +++ b/common/global.hpp @@ -21,7 +21,7 @@ enum enumZigBeeTransmitStatus { //#define Q4G_MODULE //#define WIFI_MODULE //#define NR5G_MEIGE -//#define BLUETEETH_MODULE +#define BLUETEETH_MODULE class GlobalConfig diff --git a/scheduler/schedule.cpp b/scheduler/schedule.cpp index fe03a95..465d8ab 100644 --- a/scheduler/schedule.cpp +++ b/scheduler/schedule.cpp @@ -421,16 +421,16 @@ int SensorScheduler::WaveError(uint16_t short_addr) { if (iter == failure_map_.end()) { failure_map_[short_addr] = 3; // 重试次数 zlog_warn(zct, "[WaveError][%x] will try 3 times", short_addr); - return 0; + return 1; } if (iter->second == 0) { zlog_warn(zct, "[WaveError][%x] no try times", short_addr); failure_map_.erase(short_addr); - return -1; + return 3; } iter->second = iter->second - 1; zlog_warn(zct, "[WaveError][%x] remain try %d times", short_addr, iter->second); - return 0; + return 3 - iter->second; } bool SensorScheduler::RetransferWave(uint16_t short_addr) { diff --git a/uart/uart.cpp b/uart/uart.cpp index 64aa3fc..20ffc86 100644 --- a/uart/uart.cpp +++ b/uart/uart.cpp @@ -1245,7 +1245,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { } zlog_error(zct, "WaveError error ShortAddr :%s", strShortAddr.c_str()); - sprintf(insertSql, "'%s','%s','%s',%d,'%d','%s' ", strChannelID.c_str(),strShortAddr.c_str(),localtimestamp,bytesRead,0,error_msg.c_str()); + sprintf(insertSql, "'%s','%s','%s',%d,'%d','%s','' ", strChannelID.c_str(),strShortAddr.c_str(),localtimestamp,bytesRead,0,error_msg.c_str()); sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql); @@ -1287,7 +1287,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { } zlog_error(zct, "WaveError error ShortAddr :%s", strShortAddr.c_str()); - sprintf(insertSql, "'%s','%s','%s',%d,'%d','%s' ", strChannelID.c_str(),strShortAddr.c_str(),localtimestamp,bytesRead,0,error_msg.c_str()); + sprintf(insertSql, "'%s','%s','%s',%d,'%d','%s','' ", strChannelID.c_str(),strShortAddr.c_str(),localtimestamp,bytesRead,0,error_msg.c_str()); sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql); JsonData jd; diff --git a/uart/uart_feature_parse.cpp b/uart/uart_feature_parse.cpp index b847eff..45e70ea 100644 --- a/uart/uart_feature_parse.cpp +++ b/uart/uart_feature_parse.cpp @@ -865,7 +865,14 @@ void Uart::DealWave() { (vecDataY.size() <= 0 && g_mapCompress[strShortAddr].CountY > 0) || (vecDataZ.size() <= 0 && g_mapCompress[strShortAddr].CountZ > 0)) { - scheduler::instance().WaveError(wave_shortAddr); + int iRet = scheduler::instance().WaveError(wave_shortAddr); + if (iRet != 0) { + memset(whereCon, 0x00, sizeof(whereCon)); + char updateSql[1024] = { 0 }; + sprintf(updateSql, "resend = '%d'", iRet); + sprintf(whereCon, "short_addr='%02x%02x' and timestamp = '%s'", (wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF,localtimestamp); + sqlite_db_ctrl::instance().UpdateTableData(" receive_wave_status ", updateSql, whereCon); + } }else if ((vecDataX.size() > 0 && g_mapCompress[strShortAddr].CountX > 0) || (vecDataY.size() > 0 && g_mapCompress[strShortAddr].CountY > 0) || (vecDataZ.size() > 0 && g_mapCompress[strShortAddr].CountZ > 0)) @@ -881,7 +888,14 @@ void Uart::DealWave() { } if (g_mapCompress[strShortAddr].CountX <= 0 && g_mapCompress[strShortAddr].CountY <= 0 && g_mapCompress[strShortAddr].CountZ <= 0) { - scheduler::instance().WaveError(wave_shortAddr); + int iRet = scheduler::instance().WaveError(wave_shortAddr); + if (iRet != 0) { + memset(whereCon, 0x00, sizeof(whereCon)); + char updateSql[1024] = { 0 }; + sprintf(updateSql, "resend = '%d'", iRet); + sprintf(whereCon, "short_addr='%02x%02x' and timestamp = '%s'", (wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF,localtimestamp); + sqlite_db_ctrl::instance().UpdateTableData(" receive_wave_status ", updateSql, whereCon); + } } g_mapCompress[strShortAddr].CountX = 0; g_mapCompress[strShortAddr].CountY = 0; diff --git a/wifi_5g/scan_blueteeth.cpp b/wifi_5g/scan_blueteeth.cpp index 00262a9..fefc862 100644 --- a/wifi_5g/scan_blueteeth.cpp +++ b/wifi_5g/scan_blueteeth.cpp @@ -176,11 +176,19 @@ void ScanBlueteeth::ParseData(unsigned char *data, int len,int8_t rssi){ //printf("time %s Bluetooth temp :%f ℃ , NST 1001 temp: %f ℃\n",GetCurrentTime().c_str(),(float)temp*0.01, ((float)temp1*0.0625) - 50.0625); //printf(" volt : %f v\n", (double)volt * 0.03125 ); - char insertSql[512] = {0}; + char insertSql[512] = {0},whereCon[128] = {0}; char localtimestamp[32] = {0}; + memset(whereCon,0,sizeof(whereCon)); + sprintf(whereCon, "mac='%s' order by timeStamp desc limit 1", mac); + std::string timestamp_last = sqlite_db_ctrl::instance().GetData(" blueteeth_info ", " timeStamp ", whereCon); GetTimeNet(localtimestamp, 1); - sprintf(insertSql,"'%s','%s','%d',%d,'%.1f','%.1f','%.1f','%.1f','%s'",device_id,mac,rssi,count,volt_,blueteeth_temp,chip_temp,env_temp,localtimestamp); - sqlite_db_ctrl::instance().InsertData(" blueteeth_info ", insertSql); + if (atol(localtimestamp) - atol(timestamp_last.c_str()) < 10) { + zlog_info(zct, "blueteeth_info already exist, mac = %s, timeStamp = %s", mac, timestamp_last.c_str()); + return; + } else { + sprintf(insertSql,"'%s','%s','%d',%d,'%.1f','%.1f','%.1f','%.1f','%s'",device_id,mac,rssi,count,volt_,blueteeth_temp,chip_temp,env_temp,localtimestamp); + sqlite_db_ctrl::instance().InsertData(" blueteeth_info ", insertSql); + } return; } }