From 7d4375234fcecdb1e283d65447fb957bdca0ac8c Mon Sep 17 00:00:00 2001 From: zhangsheng Date: Sat, 16 Nov 2024 20:07:07 +0800 Subject: [PATCH 1/2] tmp --- dbaccess/sql_db.cpp | 23 ++++++++++++----------- uart/uart.cpp | 2 +- uart/uart_feature_parse.cpp | 4 ++-- uart/uart_parameter_config.cpp | 4 +++- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/dbaccess/sql_db.cpp b/dbaccess/sql_db.cpp index 2ce05a9..15bb1ee 100644 --- a/dbaccess/sql_db.cpp +++ b/dbaccess/sql_db.cpp @@ -810,7 +810,8 @@ int SqliteDB::CalculateBattery() { memset(selectSql, 0x00, sizeof(selectSql)); char updateSql[1024] = {0}; int res = 0; - sprintf(selectSql, " dataNodeNo,StaticTime,WaveTime,featureInterVal,waveInterVal,samplingRate,batteryPower "); + //数据关联使用MeasurementID字段 + sprintf(selectSql, " dataNodeNo,StaticTime,WaveTime,featureInterVal,waveInterVal,samplingRate,batteryPower,MeasurementID "); array_t vecRes = GetDataMultiLine(T_SENSOR_INFO(TNAME), selectSql, NULL); zlog_info(zct, "Size = %d", vecRes.size()); if (vecRes.size() > 0) { @@ -818,13 +819,13 @@ int SqliteDB::CalculateBattery() { float capacity = 0.0, startCapacity = 0.0; memset(whereCon, 0x00, sizeof(whereCon)); memset(selectSql, 0x00, sizeof(selectSql)); - sprintf(whereCon, " dataNodeNo = '%s' and batteryRemain <> '' order by timeStamp desc limit 0,1 ", vecRes[i][0].c_str()); + sprintf(whereCon, " dataNodeNo = '%s' and batteryRemain <> '' order by timeStamp desc limit 0,1 ", vecRes[i][7].c_str()); vec_t vecResSig = sqlite_db_ctrl::instance().GetDataSingleLine(T_BATTERY_INFO(TNAME), " * ", whereCon); std::vector vParam; boost::split(vParam, vecRes[i][6], boost::is_any_of(","), boost::token_compress_on); if (vParam.size() <= 0 || vecResSig.size() <= 0) { //第一次计算 memset(whereCon, 0x00, sizeof(whereCon)); - sprintf(whereCon, "dataNodeNo = '%s' ", vecRes[i][0].c_str()); + sprintf(whereCon, "dataNodeNo = '%s' ", vecRes[i][7].c_str()); std::string Dip = sqlite_db_ctrl::instance().GetData(T_DATASTATIC_INFO(TNAME), " dip ", whereCon); if (Dip == "") { continue; @@ -840,7 +841,7 @@ int SqliteDB::CalculateBattery() { break; } memset(whereCon, 0x00, sizeof(whereCon)); - sprintf(whereCon, " dataNodeNo = '%s' order by timeStamp asc limit 0,1 ", vecRes[i][0].c_str()); + sprintf(whereCon, " dataNodeNo = '%s' order by timeStamp asc limit 0,1 ", vecRes[i][7].c_str()); vecResSig = sqlite_db_ctrl::instance().GetDataSingleLine(T_BATTERY_INFO(TNAME), " * ", whereCon); if (vecResSig.size() <= 0) { //一条数据都没有 continue; @@ -852,7 +853,7 @@ int SqliteDB::CalculateBattery() { zlog_info(zct, "dip = %d", atoi(vecResSig[1].c_str())); zlog_info(zct, "capacity = %f", capacity); - sprintf(whereCon, " dataNodeNo = '%s' and timeStamp > '%s'", vecRes[i][0].c_str(), vecResSig[8].c_str()); + sprintf(whereCon, " dataNodeNo = '%s' and timeStamp > '%s'", vecRes[i][7].c_str(), vecResSig[8].c_str()); array_t vecResbattery = GetDataMultiLine(T_BATTERY_INFO(TNAME), " * ", whereCon); zlog_info(zct, "vecResbattery size = %d", vecResbattery.size()); if (vecResbattery.size() <= 0) { @@ -904,14 +905,14 @@ int SqliteDB::CalculateBattery() { remainBattery = 10; } - zlog_info(zct, "dataNodeNo = %s,batteryUsage = %f,batteryRemain = %f", vecRes[i][0].c_str(), atof(vecResSig[6].c_str()), remainBattery); + zlog_info(zct, "dataNodeNo = %s,batteryUsage = %f,batteryRemain = %f", vecRes[i][7].c_str(), atof(vecResSig[6].c_str()), remainBattery); memset(whereCon, 0x00, sizeof(whereCon)); - sprintf(whereCon, " dataNodeNo = '%s' order by timeStamp desc limit 0,1 ", vecRes[i][0].c_str()); + sprintf(whereCon, " dataNodeNo = '%s' order by timeStamp desc limit 0,1 ", vecRes[i][7].c_str()); std::string strtimeStamp = GetData(T_BATTERY_INFO(TNAME), " timeStamp ", whereCon); sprintf(updateSql, "batteryUsage='%f',batteryRemain='%f'", usageBattery, remainBattery); memset(whereCon, 0x00, sizeof(whereCon)); - sprintf(whereCon, "dataNodeNo ='%s' and timeStamp = '%s'", vecRes[i][0].c_str(), strtimeStamp.c_str()); + sprintf(whereCon, "dataNodeNo ='%s' and timeStamp = '%s'", vecRes[i][7].c_str(), strtimeStamp.c_str()); res = UpdateTableData(T_BATTERY_INFO(TNAME), updateSql, whereCon); if(res !=0 ){ zlog_error(zct, "res = %d", res); @@ -921,19 +922,19 @@ int SqliteDB::CalculateBattery() { memset(updateSql, 0x00, sizeof(updateSql)); char insertSql[1024] = {0x00}, deleteSql[1024] = {0x00}; - sprintf(insertSql, "insert into t_battery_history select * from t_battery_info where timeStamp < '%s' and dataNodeNo = '%s'", strtimeStamp.c_str(), vecRes[i][0].c_str()); + sprintf(insertSql, "insert into t_battery_history select * from t_battery_info where timeStamp < '%s' and dataNodeNo = '%s'", strtimeStamp.c_str(), vecRes[i][7].c_str()); res = ExeSql(insertSql); if(res !=0 ){ zlog_error(zct, "res = %d", res); break; } - sprintf(deleteSql, "delete from t_battery_info where timeStamp < '%s' and dataNodeNo = '%s'", strtimeStamp.c_str(), vecRes[i][0].c_str()); + sprintf(deleteSql, "delete from t_battery_info where timeStamp < '%s' and dataNodeNo = '%s'", strtimeStamp.c_str(), vecRes[i][7].c_str()); res = ExeSql(deleteSql); if(res !=0 ){ zlog_error(zct, "res = %d", res); break; } - sprintf(whereCon, "dataNodeNo = '%s' ", vecRes[i][0].c_str()); + sprintf(whereCon, "dataNodeNo = '%s' ", vecRes[i][7].c_str()); if (startCapacity > 0) { sprintf(updateSql, "batteryPower = '%f,%f' ", startCapacity, remainBattery); } else { diff --git a/uart/uart.cpp b/uart/uart.cpp index 45f52ac..8739ba6 100644 --- a/uart/uart.cpp +++ b/uart/uart.cpp @@ -226,7 +226,7 @@ int Uart::ZigbeeTest() { } void Uart::WriteToUart(const char *strSend, int pLen) { - if (!bUpdate) + if (bUpdate) { printf( "Write To Uart Start:\n"); for (int i = 0; i < pLen; i++) { diff --git a/uart/uart_feature_parse.cpp b/uart/uart_feature_parse.cpp index 4dc2089..3dca1cc 100644 --- a/uart/uart_feature_parse.cpp +++ b/uart/uart_feature_parse.cpp @@ -228,7 +228,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { if (0 == sqlite_db_ctrl::instance().GetTableRows(T_DATASTATIC_INFO(TNAME), whereCon)) { // First Connect char insertSql[1024] = {0}; - sprintf(insertSql, "'%s','%s','%f','%f','%d','%d','',%ld,'%s','1',%d", strLongAddr.c_str(), (strMeasurementID + "-S").c_str(), dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage, staticIndex, nowTimetamp.c_str(), nodeResend); + sprintf(insertSql, "'%s','%s','%f','%f','%d','%d','',%ld,'%s','1',%d", strMeasurementID.c_str(), (strMeasurementID + "-S").c_str(), dataStatic.TemTop, dataStatic.TemBot, dataStatic.Dip, dataStatic.Voltage, staticIndex, nowTimetamp.c_str(), nodeResend); sqlite_db_ctrl::instance().InsertData(T_DATASTATIC_INFO(TNAME), insertSql); sqlite_db_ctrl::instance().CalculateBattery(); } else { @@ -303,7 +303,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { if ((Count * 3 < SAVE_COUNT && lTime < OneWeek) || strTime.size() == 0) { // 1 week char insertSql[1024] = {0}; memset(insertSql, 0x00, sizeof(insertSql)); - sprintf(insertSql, "'%s','%s','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f',%ld,'%s','1',%d", strLongAddr.c_str(), (strMeasurementID + "-X").c_str(), dataDymX.DiagnosisPk, dataDymX.IntegratPk, dataDymX.IntegratRMS, dataDymX.RmsValues, + sprintf(insertSql, "'%s','%s','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f','%f',%ld,'%s','1',%d", strMeasurementID.c_str(), (strMeasurementID + "-X").c_str(), dataDymX.DiagnosisPk, dataDymX.IntegratPk, dataDymX.IntegratRMS, dataDymX.RmsValues, dataDymX.EnvelopEnergy, dataDymX.Amp1, dataDymX.Amp2, dataDymX.Amp3, dataDymX.Amp4, dataDymX.Amp5, dataDymX.Phase1, dataDymX.Phase2, dataDymX.Phase3, dataDymX.Phase4, staticIndex, nowTimetamp.c_str(), nodeResend); sqlite_db_ctrl::instance().InsertData(szTableName, insertSql); diff --git a/uart/uart_parameter_config.cpp b/uart/uart_parameter_config.cpp index 85083a7..1c2a155 100644 --- a/uart/uart_parameter_config.cpp +++ b/uart/uart_parameter_config.cpp @@ -168,7 +168,9 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) { } Data[99] = tmp; sleep(1); + zlog_info(zct, "thisSize1 = %d", (int)thisSize); WriteToUart((const char*)Data, 100); + zlog_info(zct, "thisSize2 = %d", (int)thisSize); int iRet = CheckZigbeeACK(); if (iRet == 0) { zlog_info(zct, "Packge ACK send success,shortAddr = %02x%02x", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); @@ -474,7 +476,7 @@ int Uart::UpdateConfig(uint16_t ushortAdd) { UpdateData[4] = UINT16_LOW(ushortAdd); UpdateData[5] = 0x0A; UpdateData[6] = 0x01; - UpdateData[7] = 0x02; + UpdateData[7] = 0x00; char hex[200] = {0x00}; stringToHex(strName.c_str(), hex); bytesSize = strlen(hex) / 2; From 1d8dd06e40ede880b74b9439bb236643bb2bb204 Mon Sep 17 00:00:00 2001 From: zhangsheng Date: Sat, 16 Nov 2024 22:03:51 +0800 Subject: [PATCH 2/2] fix update config bugs --- .settings/language.settings.xml | 4 ++-- uart/uart.cpp | 5 +++-- uart/uart_parameter_config.cpp | 8 +++----- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.settings/language.settings.xml b/.settings/language.settings.xml index 915f0d3..3fbc4db 100644 --- a/.settings/language.settings.xml +++ b/.settings/language.settings.xml @@ -5,7 +5,7 @@ - + @@ -16,7 +16,7 @@ - + diff --git a/uart/uart.cpp b/uart/uart.cpp index 8739ba6..f349a96 100644 --- a/uart/uart.cpp +++ b/uart/uart.cpp @@ -226,7 +226,7 @@ int Uart::ZigbeeTest() { } void Uart::WriteToUart(const char *strSend, int pLen) { - if (bUpdate) + if (!bUpdate) { printf( "Write To Uart Start:\n"); for (int i = 0; i < pLen; i++) { @@ -622,7 +622,8 @@ void Uart::DealDataNodeName(const char *pData) { sprintf(whereCon, "zigbeeShortAddr='%s'", szShortAdd); std::string strNodeName(NodeName); zlog_info(zct, "strNodeName = %s", strNodeName.c_str()); - solve(gbkNodeName, NodeName); + //solve(gbkNodeName, NodeName); + hexToAscii(strNodeName.c_str(), gbkNodeName); zlog_info(zct, "gbkNodeName = %s", gbkNodeName); zlog_info(zct, "NodeName = %s", NodeName); zlog_info(zct, "whereCon = %s", whereCon); diff --git a/uart/uart_parameter_config.cpp b/uart/uart_parameter_config.cpp index 1c2a155..a2fb6f1 100644 --- a/uart/uart_parameter_config.cpp +++ b/uart/uart_parameter_config.cpp @@ -168,9 +168,7 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) { } Data[99] = tmp; sleep(1); - zlog_info(zct, "thisSize1 = %d", (int)thisSize); WriteToUart((const char*)Data, 100); - zlog_info(zct, "thisSize2 = %d", (int)thisSize); int iRet = CheckZigbeeACK(); if (iRet == 0) { zlog_info(zct, "Packge ACK send success,shortAddr = %02x%02x", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); @@ -250,10 +248,11 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) { if(value == 49){ gpio_set(GlobalConfig::GPIO_G.zigAckreset,0); mssleep(10000); - if(gpio_read(GlobalConfig::GPIO_G.zigAckrep) == 48) + if(gpio_read(GlobalConfig::GPIO_G.zigAckrep) == 48){ gpio_set(GlobalConfig::GPIO_G.zigAckreset,1); break; } + } mssleep(10000); time += 1; }while(time < 150); @@ -476,7 +475,6 @@ int Uart::UpdateConfig(uint16_t ushortAdd) { UpdateData[4] = UINT16_LOW(ushortAdd); UpdateData[5] = 0x0A; UpdateData[6] = 0x01; - UpdateData[7] = 0x00; char hex[200] = {0x00}; stringToHex(strName.c_str(), hex); bytesSize = strlen(hex) / 2; @@ -486,7 +484,7 @@ int Uart::UpdateConfig(uint16_t ushortAdd) { free(bytes); } else { for (size_t i = 0; i < bytesSize; i++) { - UpdateData[8 + i] = bytes[i]; + UpdateData[7 + i] = bytes[i]; } free(bytes); unsigned char tmp1 = 0x00;