diff --git a/dbaccess/sql_db.cpp b/dbaccess/sql_db.cpp index 89a10d0..2fe4e86 100644 --- a/dbaccess/sql_db.cpp +++ b/dbaccess/sql_db.cpp @@ -920,7 +920,12 @@ int SqliteDB::CalculateBattery() { 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) { // 第一次计算 + std::string total_battery = "" , remain_battery = ""; + if(vParam.size() > 1){ + total_battery = vParam[0]; + remain_battery = vParam[1]; + } + if (vParam.size() <= 0 || vecResSig.size() <= 0 || total_battery == "" || remain_battery == "") { // 第一次计算 memset(whereCon, 0x00, sizeof(whereCon)); sprintf(whereCon, "dataNodeNo = '%s' ", vecRes[i][0].c_str()); std::string Dip = sqlite_db_ctrl::instance().GetData(T_DATASTATIC_INFO(TNAME), " dip ", whereCon); @@ -1036,7 +1041,7 @@ int SqliteDB::CalculateBattery() { if (startCapacity > 0) { sprintf(updateSql, "batteryPower = '%f,%f' ", startCapacity, remainBattery); } else { - sprintf(updateSql, "batteryPower = '%s,%f' ", vParam[0].c_str(), remainBattery); + sprintf(updateSql, "batteryPower = '%s,%f' ", total_battery.c_str(), remainBattery); } UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon); @@ -1486,6 +1491,77 @@ int SqliteDB::SaveSystemHardStatus(){ updateTime.c_str()); sqlite_db_ctrl::instance().InsertData("t_system_info", insertSql); } +/* 新电池识别 + 采集计算平均电压:Vc + 特征值发送瞬时最低电压:Ve + 波形发送瞬时最低电压:Vw + 在传感器上线后,第一次波形电压获取到Vw后进行计算,需要同时满足两个条件: + 1. (Vwp+Vcp+Vep)-(Vwn+Vcn+Ven) > 0.6V + 2. Vwp>Vw_min + Vwn、Vcn、Ven : 网关最后记录24小时Vw、Vcn、Ven平均值 + Vwp、Vcp、Vep : 当前Vw、Vc、Ve电压值 + Vw_min : 电池型号相关,如ER34615C=2.8V +*/ + +int SqliteDB::NewBatteryIdentify(){ + char localtimestamp[32] = { 0 }; + GetTimeNet(localtimestamp, 1); + float capacity = 0.0, startCapacity = 0.0; + array_t arrRes; + arrRes = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_INFO(TNAME), "*", NULL); + int count = arrRes.size(); + if (count > 0) { + for (size_t i = 0; i < count; i++) + { + if(atol(localtimestamp) - atol(arrRes[i][38].c_str()) < 90000){ // 每天计算一次,计算前25h内有没有新上线的传感器 + char tablename[100] = {0},whereCon[150] = {0},updateSql[100] = {0}; + sprintf(tablename,"t_dataStatic_%s",arrRes[i][44].c_str()); + sprintf(whereCon, "timeStamp < '%s' ORDER BY timeStamp DESC limit 0,300;", arrRes[i][38].c_str()); // 获取在传感器上线之前的300条电压数据 + array_t voltage_data = sqlite_db_ctrl::instance().GetDataMultiLine(tablename, " voltage,instantaneousBatteryVoltage ", whereCon); + if (voltage_data.size() < 1) { + continue; + } + long total_num = 0; + for (size_t i = 0; i < voltage_data.size(); i++) + { + int temp = atoi(voltage_data[i][0].c_str()) + atoi(voltage_data[i][1].c_str()); + total_num += temp; + } + int mean_voltage = total_num / (voltage_data.size() * 2); + memset(whereCon,0,sizeof(whereCon)); + sprintf(whereCon, "minmumBatteryVoltageType = '2' ORDER BY timeStamp DESC limit 0,1;"); + vec_t voltage_data_new = sqlite_db_ctrl::instance().GetDataSingleLine(tablename, " voltage,instantaneousBatteryVoltage ", whereCon); + memset(whereCon,0,sizeof(whereCon)); + sprintf(whereCon, "minmumBatteryVoltageType = '1' ORDER BY timeStamp DESC limit 0,1;"); + std::string voltage = sqlite_db_ctrl::instance().GetData(tablename, " instantaneousBatteryVoltage ", whereCon); + + if(voltage_data_new.size() > 0){ + int voltage_diff = (atoi(voltage_data_new[0].c_str()) + atoi(voltage_data_new[1].c_str()) + atoi(voltage.c_str())) - mean_voltage; + zlog_info(zct,"mean_voltage = %d,voltage = %d,instantaneousBatteryVoltage = %d,instantaneousBatteryVoltage_s = %d diff = %d ", + mean_voltage,atoi(voltage_data_new[0].c_str()),atoi(voltage_data_new[1].c_str()),voltage_diff); + if(voltage_diff > 600 && (atoi(voltage_data_new[1].c_str()) > 2800)){ + memset(whereCon,0,sizeof(whereCon)); + sprintf(whereCon, "%s= '%s'", T_SENSOR_INFO(DATANODENO), arrRes[i][44].c_str()); + sqlite_db_ctrl::instance().DeleteTableData(T_BATTERY_INFO(TNAME), whereCon); + sqlite_db_ctrl::instance().DeleteTableData(" t_battery_history ", whereCon); + memset(whereCon, 0x00, sizeof(whereCon)); + sprintf(whereCon, "dataNodeNo = '%s' ", arrRes[i][44].c_str()); + std::string Dip = sqlite_db_ctrl::instance().GetData(T_DATASTATIC_INFO(TNAME), " dip ", whereCon); + if (Dip == "") { + continue; + } + capacity = (0.9 + 0.1 * (90 - atoi(Dip.c_str())) / 90) * 19000; // mAh 电池总量 + startCapacity = capacity; + sprintf(updateSql, "batteryPower = '%f,%f' ", startCapacity, startCapacity); + memset(whereCon, 0x00, sizeof(whereCon)); + sprintf(whereCon, "MeasurementID = '%s' ", arrRes[i][44].c_str()); + UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon); + } + } + } + } + } +} int SqliteDB::TransBegin() { return sqlite3_exec(mDBAcess, "begin;", 0, 0, 0); } int SqliteDB::TransRollback() { return sqlite3_exec(mDBAcess, "rollback;", 0, 0, 0); } diff --git a/dbaccess/sql_db.hpp b/dbaccess/sql_db.hpp index 1289982..2e9d32f 100644 --- a/dbaccess/sql_db.hpp +++ b/dbaccess/sql_db.hpp @@ -73,6 +73,7 @@ public: int QueryofflineData(); int ClearExpireData(); int SaveSystemHardStatus(); + int NewBatteryIdentify(); std::string GetNodeConfigureInfor(const char *whereCon); int CloseDB(); diff --git a/threadfunc/check_thread.cpp b/threadfunc/check_thread.cpp index 843f312..9f4f020 100644 --- a/threadfunc/check_thread.cpp +++ b/threadfunc/check_thread.cpp @@ -149,6 +149,15 @@ void CheckThread() { jd.JsonCmd_07(); HardStatus = 0; sqlite_db_ctrl::instance().SaveSystemHardStatus(); + int hour = 0; + struct tm *tm_info = get_current_date(); + hour = tm_info->tm_hour; + int statistics = readIntValue( "config", "statistics",(char*)GlobalConfig::Config_G.c_str()); + if(statistics == 0 && hour > 13 ){ + writeIntValue("config", "statistics",1,(char*)GlobalConfig::Config_G.c_str()); + }else if(statistics == 1 && hour < 13){ + writeIntValue("config", "statistics",0,(char*)GlobalConfig::Config_G.c_str()); + } } if(checkNet0 == 5){ checkNet0 = 0; diff --git a/uart/uart.cpp b/uart/uart.cpp index 7c87034..0ac2175 100644 --- a/uart/uart.cpp +++ b/uart/uart.cpp @@ -1050,11 +1050,9 @@ void Uart::DealDataNodeInfo(const char *pData) { dataNodeInfo.FaultFrequency += ("," + std::to_string(iTemp)); } } - - memset(buf, 0, 32); - sprintf(buf, "%02x%02x%02x%02x", pRecvData->Data[87], pRecvData->Data[88], pRecvData->Data[89], pRecvData->Data[90]); - long lTimeStamp = strtol(buf, NULL, 16); - dataNodeInfo.ConfigDate = std::to_string(lTimeStamp); + char localtimestamp[32] = { 0 }; + GetTimeNet(localtimestamp, 1); + std::string ConfigDate = std::string(localtimestamp); chTemp = pRecvData->Data[91]; memset(buf, 0, 32); diff --git a/uart/uart_feature_parse.cpp b/uart/uart_feature_parse.cpp index 2dd91f4..e54ae56 100644 --- a/uart/uart_feature_parse.cpp +++ b/uart/uart_feature_parse.cpp @@ -76,7 +76,6 @@ void Uart::RecordBattery(std::string &strLongAddr, DataRecvStatic &dataStatic, s zlog_info(zct, "dataNodeNo='%s',zigbeeSignal=%d,zigbeeSignalNode=%d,actualRate=%f,comprehensiveRSSI=%f", strLongAddr.c_str(), zigbeeSignal, zigbeeSignalNode, actualRate, comprehensiveRSSI); } } - void Uart::DataExtract(RecvData *p, int id, unsigned int &lowbit, float &n) { char buf[20] = {0}; sprintf(buf, "%02x%02x", p->Data[id+1], p->Data[id]); @@ -135,8 +134,6 @@ int Uart::DealDataNodeFeature(const char *pData, int flag) { char nodetimestamp[32] = {0}; sprintf(nodetimestamp,"%ld",nodetimestamp_); - // std::string nowTimetamp = std::string(localtimestamp); - // strTimetamp = nowTimetamp; char localtimestamp[32] = { 0 }; GetTimeNet(localtimestamp, 1);