diff --git a/common/common_func.cpp b/common/common_func.cpp index 18ab671..dce02f9 100644 --- a/common/common_func.cpp +++ b/common/common_func.cpp @@ -1507,14 +1507,14 @@ void IniWriteValue(const char *section, const char *key, char *val, const char * } int writeStringVlaue(const char *section, const char *key, char *val, const char *file) { -// char sect[SECTION_MAX_LEN]; + char sect[SECTION_MAX_LEN]; zlog_debug(zct, "section = %s, key = %s, file = %s", section, key, file); if (section == NULL || key == NULL || val == NULL || file == NULL) { zlog_error(zct, "input parameter(s) is NULL!"); return -1; } -// memset(sect, 0, SECTION_MAX_LEN); -// sprintf(sect, "[%s]", section); + memset(sect, 0, SECTION_MAX_LEN); + sprintf(sect, "[%s]", section); IniWriteValue(section, key, val, file); return 0; } diff --git a/common/parameter_defination.hpp b/common/parameter_defination.hpp index d9159b9..288d7da 100644 --- a/common/parameter_defination.hpp +++ b/common/parameter_defination.hpp @@ -335,5 +335,12 @@ struct Param_61 { int mPackageFlag; Param_61() : mMode(0),MeasurementID(""),straxis(""),mPackageFlag(0){}; }; +struct Param_62 { + std::string MeasurementID; + std::string timeStart; + std::string timeEnd; + int mPackageFlag; + Param_62() : MeasurementID(""),timeStart(""),timeEnd(""),mPackageFlag(0){}; +}; #endif // PARAMETER_DEFINATION_HPP_ diff --git a/dbaccess/sql_db.cpp b/dbaccess/sql_db.cpp index 3929d64..d9e1cbb 100644 --- a/dbaccess/sql_db.cpp +++ b/dbaccess/sql_db.cpp @@ -37,7 +37,7 @@ void SqliteDB::SqliteInit(const char *pDbName) { //创建传感器信息存储表 memset(sql_exec, 0, 2048); - sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);", + sprintf(sql_exec, "create table if not exists %s(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);", T_SENSOR_INFO(TNAME), T_SENSOR_INFO(DATANODENO), T_SENSOR_INFO(DATANODENAME), @@ -82,8 +82,7 @@ void SqliteDB::SqliteInit(const char *pDbName) { T_SENSOR_INFO(RSSI), "UpdateFlag", "LooseValue", - "batteryPower", - "upgradeStatus"); + "batteryPower"); CreateTable(sql_exec); int iRet = GetTableRows(" sqlite_master "," name = 't_sensor_info' and sql LIKE '%LooseValue%' "); @@ -247,6 +246,7 @@ void SqliteDB::SqliteInit(const char *pDbName) { execute_sql_file("/opt/configenv/firmware_upgrade.sql"); + execute_sql_file("/opt/configenv/receive_wave_status.sql"); } void SqliteDB::Createtable(const char *ptableName) { diff --git a/jsonparse/communication_cmd.hpp b/jsonparse/communication_cmd.hpp index eb75f6b..5ce1019 100644 --- a/jsonparse/communication_cmd.hpp +++ b/jsonparse/communication_cmd.hpp @@ -67,6 +67,7 @@ public: std::string JsonCmd_Cgi_59(Param_59 ¶m); std::string JsonCmd_Cgi_60(Param_60 ¶m); std::string JsonCmd_Cgi_61(Param_61 ¶m); + std::string JsonCmd_Cgi_62(Param_62 ¶m); std::string JsonCmd_Cgi_default(); private: diff --git a/jsonparse/mqtt_cmd_parse.cpp b/jsonparse/mqtt_cmd_parse.cpp index 9c155d2..b85a27b 100644 --- a/jsonparse/mqtt_cmd_parse.cpp +++ b/jsonparse/mqtt_cmd_parse.cpp @@ -44,7 +44,6 @@ std::string JsonData::JsonCmd_20(Param_20 ¶m) { std::string boardtype = GetFileContent(BOARDTYPE, 1); std::string ip = IpAddrInit(); - std::string sn = GetFileContent(SN, 1); jsonVal[JSON_FIELD_CMD] = "20"; jsonVal[JSON_FIELD_dataNodeGatewayNo] = GlobalConfig::MacAddr_G; jsonVal["cmdSerial"] = param.mCmdSerial; @@ -67,7 +66,6 @@ std::string JsonData::JsonCmd_20(Param_20 ¶m) { jsSystemInfo[JSON_FIELD_ADDEDDATE] = ReadStrByOpt(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAddedDate"); jsSystemInfo[JSON_FIELD_DEVICETYPE] = boardtype; jsSystemInfo[JSON_FIELD_IPADDRESS] = ip; - jsSystemInfo[JSON_FIELD_SN] = sn; jsSystemInfo[JSON_FIELD_VERSION] = GlobalConfig::Version; jsSystemInfo[JSON_FIELD_TIMEZONE] = ReadStrByOpt(SYSTEMINFOFILE, "SystemInfo", "timezone"); jsSystemInfo["zigbeePanId"] = GlobalConfig::ZigbeeInfo_G.PanID; diff --git a/jsonparse/web_cmd_parse.cpp b/jsonparse/web_cmd_parse.cpp index 794009c..92f3886 100644 --- a/jsonparse/web_cmd_parse.cpp +++ b/jsonparse/web_cmd_parse.cpp @@ -386,7 +386,6 @@ std::string JsonData::JsonCmd_Cgi_20(Param_20 ¶m) { } std::string ip = IpAddrInit(); - std::string sn = GetFileContent(SN, 1); jsonVal[JSON_FIELD_CMD] = "20"; jsonVal["dataNodeGatewayNo"] = GlobalConfig::MacAddr_G; jsonVal["success"] = true; @@ -402,7 +401,6 @@ std::string JsonData::JsonCmd_Cgi_20(Param_20 ¶m) { jsSystemInfo[JSON_FIELD_ADDEDBY] = ReadStrByOpt(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAddedBy"); jsSystemInfo[JSON_FIELD_ADDEDDATE] = ReadStrByOpt(SYSTEMINFOFILE, "SystemInfo", "dataNodeGatewayAddedDate"); jsSystemInfo[JSON_FIELD_IPADDRESS] = ip; - jsSystemInfo[JSON_FIELD_SN] = sn; jsSystemInfo[JSON_FIELD_VERSION] = GlobalConfig::Version; jsSystemInfo[JSON_FIELD_TIMEZONE] = ReadStrByOpt(SYSTEMINFOFILE, "SystemInfo", "timezone"); jsSystemInfo["zigbeePanId"] = GlobalConfig::ZigbeeInfo_G.PanID; diff --git a/jsonparse/web_cmd_parse3.cpp b/jsonparse/web_cmd_parse3.cpp index 5acdbd6..d037a68 100644 --- a/jsonparse/web_cmd_parse3.cpp +++ b/jsonparse/web_cmd_parse3.cpp @@ -829,3 +829,80 @@ std::string JsonData::JsonCmd_Cgi_61(Param_61 ¶m){ } return show_value_.write(jsonVal); } + +std::string JsonData::JsonCmd_Cgi_62(Param_62 ¶m){ + Json::Value jsonVal; + jsonVal.clear(); + + jsonVal[JSON_FIELD_CMD] = "61"; + jsonVal["success"] = true; + jsonVal["message"] = " "; + vec_t vetRes = sqlite_db_ctrl::instance().GetDataMultiLineOfOneColumn(T_SENSOR_INFO(TNAME), T_SENSOR_INFO(DATANODENO), NULL); + int nSize = vetRes.size(); + if (nSize > 0) { + char szTableName[100] = {0x00}, whereCon[256] = {0x00}; + sprintf(szTableName, " receive_wave_status "); + + sprintf(whereCon, " data_nodeno = '%s' and timeStamp < '%s' and timeStamp > '%s' ", param.MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str()); + + + int rows = sqlite_db_ctrl::instance().GetTableRows(szTableName, whereCon); + int packgeNo = param.mPackageFlag; + int packgeMax = 0; + int packgeNum = 0; + jsonVal["package"] = packgeNo; + int lastSize = rows % 550; + int index = rows / 550; + if (lastSize > 0 && index > 0) { + packgeMax = index + 1; + if (packgeNo + 1 == packgeMax) { + packgeNum = rows - lastSize; + jsonVal["packageMax"] = index + 1; + } else { + packgeNum = (packgeNo)*550; + jsonVal["packageMax"] = index + 1; + } + } else if (lastSize == 0 && index > 0) { + packgeNum = (packgeNo + 1) * 550; + packgeMax = index; + jsonVal["packageMax"] = index; + } else if (lastSize > 0 && index == 0) { + packgeNum = 0; + packgeMax = index + 1; + jsonVal["packageMax"] = index; + } + + memset(whereCon, 0x00, sizeof(whereCon)); + sprintf(whereCon, "data_nodeno = '%s' and timeStamp < '%s' and timeStamp > '%s' order by timeStamp asc LIMIT %d OFFSET %d", param.MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str(), 550, packgeNum); + array_t vecRes; + + vecRes = sqlite_db_ctrl::instance().GetDataMultiLine(szTableName, "*", whereCon); + zlog_info(zct, "vecRes = %d", vecRes.size()); + if (vecRes.size() > 0) { + Json::Value jsStaticData; + for (size_t i = 0; i < vecRes.size(); i++) { + Json::Value iTem; + iTem.append(vecRes[i][2]); + iTem.append(vecRes[i][4]); + iTem.append(vecRes[i][5]); + jsStaticData.append(iTem); + + } + if (jsStaticData.size() == 0) { + jsonVal["success"] = false; + jsonVal["content"].resize(0); + } else { + jsonVal["content"] = (jsStaticData); + } + + zlog_info(zct, "vecRes = %d,channelID = %s", vecRes.size(), vecRes[0][0].c_str()); + } else { + jsonVal["success"] = false; + jsonVal["content"].resize(0); + } + } else { + jsonVal["success"] = false; + jsonVal["content"].resize(0); + } + return show_value_.write(jsonVal); +} diff --git a/platform/platform_init.cpp b/platform/platform_init.cpp index a5a9b46..11eb16b 100644 --- a/platform/platform_init.cpp +++ b/platform/platform_init.cpp @@ -223,9 +223,6 @@ void PlatformInit::SystemInfoInit() { Systeminfo["dataWatchIpAddress"] = GlobalConfig::IpAddr_G; Systeminfo["softVersion"] = GlobalConfig::Version; - std::string strSerialNumber = GetFileContent(SN, 1); - Systeminfo["serialNumber"] = strSerialNumber; - Json::StyledWriter sw; std::ofstream os; os.open(SYSTEMINFOFILE); diff --git a/uart/uart.cpp b/uart/uart.cpp index 7f4aeb8..b0d1e3a 100644 --- a/uart/uart.cpp +++ b/uart/uart.cpp @@ -352,15 +352,10 @@ void int2bytes(int i, unsigned char *bytes, int size) { bytes[2] = (unsigned char)((0xff0000 & i) >> 16); bytes[3] = (unsigned char)((0xff000000 & i) >> 24); } -int Uart::GetLocalZigbeeRSSI(uint16_t ushortAdd){ +void Uart::GetLocalZigbeeRSSI(uint16_t ushortAdd){ zlog_info(zct, "Local Zigbee Signal !\n"); - int Times = 0; mssleep(20000); - while (Times < 3) { - getZigbeeSignal(ushortAdd); - Times++; - mssleep(20000); - } + getZigbeeSignal(ushortAdd); mssleep(10000); } int Uart::DealAskTask(uint16_t ushortAdd){ @@ -488,7 +483,7 @@ int Uart::DealSensorRSSI(const char *pData,uint16_t ushortAdd){ sprintf(whereCon, "zigbeeShortAddr='%02x%02x'", UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd)); vec_t vecDataNodeNo = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " MeasurementID,RSSI ", whereCon); - sprintf(insertSql, "'%s','%s-S','','','','', '%02d','','%s','','','','','' ", vecDataNodeNo[0].c_str(),vecDataNodeNo[0].c_str(),atoi(sensor_rssi),localtimestamp); // zigbeeRSSIType = 0 传感器获取网关信号强度 + sprintf(insertSql, "'%s','%s-S','','','','', '','','%s','','','%02d','','' ", vecDataNodeNo[0].c_str(),vecDataNodeNo[0].c_str(),localtimestamp,atoi(sensor_rssi)); // zigbeeRSSIType = 0 传感器获取网关信号强度 sprintf(tableName, "t_dataStatic_%s", (char *)vecDataNodeNo[0].c_str()); sqlite_db_ctrl::instance().InsertData(tableName, insertSql); @@ -503,6 +498,23 @@ int Uart::DealSensorRSSI(const char *pData,uint16_t ushortAdd){ } return 0; } +int Uart::DealUpgrade(uint16_t ushortAdd,int status){ + + char updateSql[100] = {0}; + char wherecon[100] = {0}; + memset(wherecon,0,sizeof(wherecon)); + memset(updateSql,0,sizeof(updateSql)); + sprintf(wherecon," zigbeeShortAddr = '%02x%02x' ",UINT16_HIGH(ushortAdd), UINT16_LOW(ushortAdd)); + sprintf(updateSql, " upgradeStatus = %d", status); + sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql,wherecon); + memset(updateSql,0,sizeof(updateSql)); + memset(wherecon,0,sizeof(wherecon)); + sprintf(wherecon," short_addr = '%02x%02x' order by start_timestamp DESC",UINT16_HIGH(ushortAdd), UINT16_LOW(ushortAdd)); + sprintf(updateSql, " status = %d",status); + sqlite_db_ctrl::instance().UpdateTableData(" firmware_upgrade ", updateSql,wherecon); + + return 0; +} void Uart::DealRecvData(const char *pData) { uint16_t ushortAdd = BUILD_UINT16(pData[3] & 0xFF, pData[4] & 0xFF); @@ -529,9 +541,11 @@ void Uart::DealRecvData(const char *pData) { break; case UPGRADE: if (recvcode == 0){ + DealUpgrade(ushortAdd,2); scheduler::instance().UpgradeResult(ushortAdd,0); zlog_info(zbt, "[UPGRADE SUCCESS] shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode); }else{ + DealUpgrade(ushortAdd,3); scheduler::instance().UpgradeResult(ushortAdd,recvcode); zlog_error(zbt, "[UPGRADE FAILED] shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode); } @@ -971,7 +985,8 @@ void Uart::ZigbeeParameterConfig() { } int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { - std::string strTime = GetLocalTimeWithMs(); + char localtimestamp[32] = {0}; + GetTimeNet(localtimestamp, 1); char head1[] = {0xAB, 0xBC, 0xCD}; char head2[] = {0xDE, 0xDF, 0xEF}; int lastSize = 0; @@ -1021,6 +1036,15 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { strcat(tmp2, tmp); } zlog_error(zct, "error str = %s", tmp2); + + char insertSql[100] = {0x00}; + char whereCon[50] = {0x00}; + sprintf(whereCon, "zigbeeShortAddr='%s'",strShortAddr.c_str()); + std::string strDataNodeNo = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), " dataNodeNo ", whereCon); + memset(whereCon, 0x00, sizeof(whereCon)); + sprintf(insertSql, "'%s','%s','%s',%d,'%d','%s' ", strDataNodeNo.c_str(),strShortAddr.c_str(),localtimestamp,bytesRead,1,"Index error"); + sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql); + break; } @@ -1043,6 +1067,14 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { g_VecWaveDataX.clear(); g_VecWaveDataY.clear(); g_VecWaveDataZ.clear(); + char insertSql[100] = {0x00}; + char whereCon[50] = {0x00}; + sprintf(whereCon, "zigbeeShortAddr='%s'",strShortAddr.c_str()); + std::string strDataNodeNo = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), " dataNodeNo ", whereCon); + memset(whereCon, 0x00, sizeof(whereCon)); + sprintf(insertSql, "'%s','%s','%s',%d,'%d','%s' ", strDataNodeNo.c_str(),strShortAddr.c_str(),localtimestamp,bytesRead,2,"Crc error"); + sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql); + break; } mlastSize = 0; @@ -1173,11 +1205,11 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) { char tableName[100] = {0x00}; char insertSql[100] = {0x00}; bZigbeeSinal = false; - sprintf(whereCon, "zigbeeShortAddr='%02x%02x'", UartRecvBuf[i + 3] & 0xFF, UartRecvBuf[i + 4] & 0xFF); + sprintf(whereCon, "zigbeeShortAddr='%02x%02x'", UINT16_HIGH(wave_shortAddr),UINT16_LOW(wave_shortAddr)); vec_t vecDataNodeNo = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " dataNodeNo,LooseValue,RSSI ", whereCon); memset(whereCon, 0x00, sizeof(whereCon)); - sprintf(insertSql, "'%s','%s-S','','','','', '','','%s','','','%02d','','' ", vecDataNodeNo[0].c_str(),vecDataNodeNo[0].c_str(),localtimestamp,UartRecvBuf[i + 6] & 0xFF); // zigbeeRSSIType = 0 传感器获取网关信号强度 + sprintf(insertSql, "'%s','%s-S','','','','', '%02d','','%s','','','','','' ", vecDataNodeNo[0].c_str(),vecDataNodeNo[0].c_str(),UartRecvBuf[i + 6] & 0xFF,localtimestamp); // zigbeeRSSIType = 0 传感器获取网关信号强度 sprintf(tableName, "t_dataStatic_%s", (char *)vecDataNodeNo[0].c_str()); sqlite_db_ctrl::instance().InsertData(tableName, insertSql); diff --git a/uart/uart.hpp b/uart/uart.hpp index 8028c58..5fba18e 100644 --- a/uart/uart.hpp +++ b/uart/uart.hpp @@ -172,7 +172,8 @@ public: int DealConfig(uint16_t ushortAdd); int DealWaveCompress(const char *pData,uint16_t ushortAdd); int DealSensorRSSI(const char *pData,uint16_t ushortAdd); - int GetLocalZigbeeRSSI(uint16_t ushortAdd); + int DealUpgrade(uint16_t ushortAdd,int status); + void GetLocalZigbeeRSSI(uint16_t ushortAdd); // feature parse void DealDataNodeFeature(const char* pData, int flag); diff --git a/uart/uart_feature_parse.cpp b/uart/uart_feature_parse.cpp index a4546de..2de52f4 100644 --- a/uart/uart_feature_parse.cpp +++ b/uart/uart_feature_parse.cpp @@ -154,26 +154,8 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { memset(whereCon, 0x00, sizeof(whereCon)); sprintf(szTableNameData, "t_data_%s", strMeasurementID.c_str()); ///////////////////////////////////////////////////////////// for V2.0.3 upgrade to V3.0 - std::string strTmp = ""; - char sztmp[100] = {0x00}; - strTmp = "name = '" + std::string(szTableNameStatic) + "' and sql LIKE '%nodeResend%' "; + - int row = sqlite_db_ctrl::instance().GetTableRows(" sqlite_master ", strTmp.c_str()); - zlog_info(zct, "row1 = %d", row); - if (row == 0) { - memset(sztmp, 0x00, sizeof(sztmp)); - sprintf(sztmp, "ALTER TABLE %s ADD COLUMN 'nodeResend'", szTableNameStatic); - sqlite_db_ctrl::instance().CreateTable(sztmp); - } - - strTmp = "name = '" + std::string(szTableNameData) + "' and sql LIKE '%nodeResend%' "; - row = sqlite_db_ctrl::instance().GetTableRows(" sqlite_master ", strTmp.c_str()); - zlog_info(zct, "row2 = %d", row); - if (row == 0) { - memset(sztmp, 0x00, sizeof(sztmp)); - sprintf(sztmp, "ALTER TABLE %s ADD COLUMN 'nodeResend'", szTableNameData); - sqlite_db_ctrl::instance().CreateTable(sztmp); - } ////////////////////////////////////////////////////////////更换电池判断 // sprintf(whereCon, " dataNodeNo = '%s' and StaticIndex > 0 order by StaticIndex desc LIMIT 0 , 1 ", strLongAddr.c_str()); @@ -199,16 +181,35 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { // } // } zlog_info(zct, "nowTimetamp = %s", nowTimetamp.c_str()); - // save dataStatic of 7 days - char selectCon[128] = {0}; - sprintf(selectCon, "channelID='%s' ORDER BY timeStamp ASC LIMIT 0,1", (strMeasurementID + "-S").c_str()); - std::string strTime = sqlite_db_ctrl::instance().GetData(szTableName, "timeStamp", selectCon); sprintf(whereCon, "channelID='%s' ", (strMeasurementID + "-S").c_str()); int Count = sqlite_db_ctrl::instance().GetTableRows(szTableName, whereCon); if (Count == -1) { sqlite_db_ctrl::instance().CreatedataStatictable(szTableName); sqlite_db_ctrl::instance().Createtable(szTableNameData); } + std::string strTmp = ""; + char sztmp[100] = {0x00}; + strTmp = "name = '" + std::string(szTableNameStatic) + "' and sql LIKE '%nodeResend%' "; + int row = sqlite_db_ctrl::instance().GetTableRows(" sqlite_master ", strTmp.c_str()); + zlog_info(zct, "row1 = %d", row); + if (row == 0) { + memset(sztmp, 0x00, sizeof(sztmp)); + sprintf(sztmp, "ALTER TABLE %s ADD COLUMN 'nodeResend'", szTableNameStatic); + sqlite_db_ctrl::instance().CreateTable(sztmp); + } + + strTmp = "name = '" + std::string(szTableNameData) + "' and sql LIKE '%nodeResend%' "; + row = sqlite_db_ctrl::instance().GetTableRows(" sqlite_master ", strTmp.c_str()); + zlog_info(zct, "row2 = %d", row); + if (row == 0) { + memset(sztmp, 0x00, sizeof(sztmp)); + sprintf(sztmp, "ALTER TABLE %s ADD COLUMN 'nodeResend'", szTableNameData); + sqlite_db_ctrl::instance().CreateTable(sztmp); + } + char selectCon[128] = {0}; + sprintf(selectCon, "channelID='%s' ORDER BY timeStamp ASC LIMIT 0,1", (strMeasurementID + "-S").c_str()); + std::string strTime = sqlite_db_ctrl::instance().GetData(szTableName, "timeStamp", selectCon); + zlog_info(zct, "strLongAddr = %s,strTime = %s", strLongAddr.c_str(), strTime.c_str()); long lTime = atol(nowTimetamp.c_str()) - atol(strTime.c_str()); zlog_info(zct, "lTime = %ld,OneWeek = %d", lTime, OneWeek); @@ -752,9 +753,9 @@ void Uart::DealWave() { std::string strProduct = ""; std::vector vecData; if (wave_trans_) { //对每个传感器的每个通道进行遍历然后处理数据,例如:传感器1x轴的数据处理完后,再去处理y轴的。传感器1的所有数据处理完后,再处理传感器2的 - char getLongAddr_sql[32] = {0}; - sprintf(getLongAddr_sql, "zigbeeShortAddr='%02x%02x'", (wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF); - vec_t res = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", getLongAddr_sql); + char getzigbeeShortAddr[32] = {0}; + sprintf(getzigbeeShortAddr, "zigbeeShortAddr='%02x%02x'", (wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF); + vec_t res = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " * ", getzigbeeShortAddr); if (res.size() < 0) { wave_trans_ = false; @@ -809,6 +810,14 @@ void Uart::DealWave() { g_VecWaveDataZ.clear(); VecWaveDataZ.clear(); } + char localtimestamp[32] = {0}; + GetTimeNet(localtimestamp, 1); + char insertSql[100] = {0x00}; + char whereCon[50] = {0x00}; + sprintf(whereCon, "MeasurementID='%s'",strMeasurementID.c_str()); + memset(whereCon, 0x00, sizeof(whereCon)); + sprintf(insertSql, "'%s','%02x%02x','%s',0,'0','%s' ", strMeasurementID.c_str(),(wave_shortAddr >> 8) & 0xFF,wave_shortAddr & 0xFF,localtimestamp,""); + sqlite_db_ctrl::instance().InsertData(" receive_wave_status ", insertSql); wave_trans_ = false; } } @@ -988,6 +997,7 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan } else { zlog_info(zct, "send data , filename %s,size = %d\n", strFileName.c_str(), vecData.size()); } + #ifdef G2UL_GATEWAY //存储6条波形数据 char whereCon[1024] = {0x00}; char updateSql[1024] = {0x00}; diff --git a/uart/uart_parameter_config.cpp b/uart/uart_parameter_config.cpp index baa33ec..1f0b081 100644 --- a/uart/uart_parameter_config.cpp +++ b/uart/uart_parameter_config.cpp @@ -170,7 +170,7 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) { GetTimeNet(localtimestamp, 1); char insertSql[100] = {0}; char wherecon[50] = {0}; - sprintf(wherecon," shortAddr = '%02x%02x' order by start_timestamp DESC",UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); + sprintf(wherecon," short_Addr = '%02x%02x' order by start_timestamp DESC",UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); std::string spend_count = sqlite_db_ctrl::instance().GetData(" firmware_upgrade ","spend_count",wherecon); if (atoi(spend_count.c_str()) >= 10){ zlog_warn(zbt, "UpdateWirelessNode spend_count %d,shortAddr = %02x%02x", atoi(spend_count.c_str()), UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); @@ -179,13 +179,12 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) { if (spend_count == "")spend_count = "0"; memset(wherecon,0,sizeof(wherecon)); - sprintf(wherecon," shortAddr = '%02x%02x' order by submit_timestamp DESC",UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); + sprintf(wherecon," short_Addr = '%02x%02x' order by submit_timestamp DESC",UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); std::string firmware_name = sqlite_db_ctrl::instance().GetData(" firmware_upgrade ","firmware_name",wherecon); memset(wherecon,0,sizeof(wherecon)); sprintf(wherecon," zigbeeShortAddr = '%02x%02x' ",UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " hardVersion,softVersion,ProductNo,upgradeStatus ", wherecon); - if (vecResult[3] == "2") - { + if (vecResult[3] == "2"){ zlog_warn(zbt, "UpdateWirelessNode already ,shortAddr = %02x%02x", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); return; } @@ -398,12 +397,6 @@ endUpdate: sprintf(updateSql, " end_timestamp = '%s',spend_time = %ld,status = %d",localtimestamp_end,atol(localtimestamp_end)-atol(localtimestamp), upgrade_status); sqlite_db_ctrl::instance().UpdateTableData(" firmware_upgrade ", updateSql,wherecon); - memset(wherecon,0,sizeof(wherecon)); - memset(updateSql,0,sizeof(updateSql)); - sprintf(wherecon," zigbeeShortAddr = '%02x%02x'",UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); - sprintf(updateSql, " upgradeStatus = %d", upgrade_status); - sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql,wherecon); - free(buffer); tcflush(fd, TCIFLUSH); sleep(1);