diff --git a/jsonparse/web_cmd_parse3.cpp b/jsonparse/web_cmd_parse3.cpp index bb42be4..596e68c 100644 --- a/jsonparse/web_cmd_parse3.cpp +++ b/jsonparse/web_cmd_parse3.cpp @@ -512,9 +512,22 @@ std::string JsonData::JsonCmd_Cgi_58(Param_58 ¶m) { jsonVal[JSON_FIELD_CMD] = "58"; jsonVal["success"] = true; jsonVal["message"] = ""; - int ret = scheduler::instance().Config(param.featureInterVal,param.waveInterVal,param.featureInterTime,param.waveInterTime,param.maxSensorNum); - if (ret != 0) + int ret = 0; + if (param.mMode == 1) { + ret = scheduler::instance().Config(param.featureInterVal,param.waveInterVal,param.featureInterTime,param.waveInterTime,param.maxSensorNum); + }else if (param.mMode == 0) + { + ret = scheduler::instance().GetScheduleConfig(param.featureInterVal,param.waveInterVal,param.featureInterTime,param.waveInterTime,param.maxSensorNum); + } + if (ret == 0) + { + jsBody["featureInterVal"] = param.featureInterVal; + jsBody["featureInterTime"] = param.featureInterTime; + jsBody["waveInterVal"] = param.waveInterVal; + jsBody["waveInterTime"] = param.waveInterTime; + jsBody["maxSensorNum"] = param.maxSensorNum; + }else{ jsonVal["success"] = false; jsonVal["message"] = "保存失败!"; } @@ -529,17 +542,13 @@ std::string JsonData::JsonCmd_Cgi_59(Param_59 ¶m) { jsonVal["message"] = ""; char table_name[50] ={0}; int interval = 0; + char sql[1024]={0}; if (param.mMode == 1) { sprintf(table_name,"t_dataStatic_%s",param.DataNodeNo.c_str()); interval = 400; - }else if (param.mMode == 2) - { - sprintf(table_name,"t_data_waveSend"); - interval = 7300; - } - char sql[1024]={0}; - snprintf(sql, sizeof(sql), + + snprintf(sql, sizeof(sql), "WITH CTE AS (" " SELECT timestamp, " " LAG(timestamp) OVER (ORDER BY timestamp) AS prev_timestamp " @@ -552,6 +561,27 @@ std::string JsonData::JsonCmd_Cgi_59(Param_59 ¶m) { "WHERE prev_timestamp IS NOT NULL " " AND (timestamp - prev_timestamp) > %d;", table_name,interval); + }else if (param.mMode == 2) + { + sprintf(table_name,"t_data_waveSend"); + interval = 7300; + snprintf(sql, sizeof(sql), + "WITH CTE AS (" + " SELECT timestamp, " + " LAG(timestamp) OVER (ORDER BY timestamp) AS prev_timestamp " + " FROM %s WHERE channelID = '%s-%s'" + ") " + "SELECT timestamp, " + " prev_timestamp, " + " timestamp - prev_timestamp AS interval_seconds " + "FROM CTE " + "WHERE prev_timestamp IS NOT NULL " + " AND (timestamp - prev_timestamp) > %d;", + table_name,param.DataNodeNo.c_str(),param.straxis.c_str(),interval); + + jsonVal["Raxis"] = param.straxis; + } + array_t arrResult = sqlite_db_ctrl::instance().GetDataMultiLine(sql); Json::Value valData; @@ -567,6 +597,7 @@ std::string JsonData::JsonCmd_Cgi_59(Param_59 ¶m) { } jsonVal["content"] = valData; + }else{ jsonVal["success"] = false; jsonVal["message"] = "获取数据失败!"; diff --git a/localserver/web_cmd.cpp b/localserver/web_cmd.cpp index b63ed1f..eed2a37 100644 --- a/localserver/web_cmd.cpp +++ b/localserver/web_cmd.cpp @@ -376,6 +376,13 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) { case kSchedulingConfiguration:{ JsonData jd; Param_58 param; + std::string type = recvBody["type"].asString(); + if (0 == type.compare("SET")) { + param.mMode = 1; + } + if (0 == type.compare("GET")) { + param.mMode = 0; + } param.featureInterVal = recvBody["featureInterVal"].asInt(); param.featureInterTime = recvBody["featureInterTime"].asInt(); param.waveInterVal = recvBody["waveInterVal"].asInt(); @@ -389,6 +396,7 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) { Param_59 param; param.mMode = recvBody["type"].asInt(); param.DataNodeNo = recvBody["DataNodeNo"].asString(); + param.straxis = recvBody["Raxis"].asString(); std::string data = jd.JsonCmd_Cgi_59(param); return data; }break; diff --git a/uart/uart.cpp b/uart/uart.cpp index fbf1bee..808af67 100644 --- a/uart/uart.cpp +++ b/uart/uart.cpp @@ -375,8 +375,7 @@ int Uart::DealAskTask(uint16_t ushortAdd){ int taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration); ScheduleTask scheduleTask; zlog_info(zct, "taskID = %d ", taskID); - // if (taskID == kScheduleEigenValue) //1.特征值 - if (taskID == 6) + if (taskID == kScheduleEigenValue) //1.特征值 { char localtimestamp[32] = {0x00}; int millisecond = 0; @@ -385,7 +384,6 @@ int Uart::DealAskTask(uint16_t ushortAdd){ scheduleTask.shortAddr = ushortAdd; scheduleTask.timeStamp = atoi(localtimestamp); TaskResp(scheduleTask); - return 0; } else if (taskID == kScheduleWaveForm) //2.波形 { @@ -530,8 +528,6 @@ void Uart::DealDataNodeName(const char *pData) { char uplCon[200] = {0x00}; char nodeWaveSend[10] = {0x00}; - UpdateWirelessNodeTime((unsigned char *)shortAdd, 1); - for (int i = 0; i < 64; i++) { sprintf(&NodeName[i * 2], "%02X", pData[7 + i] & 0xFF); } diff --git a/uart/uart_feature_parse.cpp b/uart/uart_feature_parse.cpp index dbcf749..382c56f 100644 --- a/uart/uart_feature_parse.cpp +++ b/uart/uart_feature_parse.cpp @@ -31,6 +31,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { char updateSql[1024] = {0}; char buf[20] = {0x00}; int nodeResend = 0, timing = 0; + long staticIndex = 0; sprintf(buf, "%02x%02x", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]); if (flag == 1) { zlog_info(zct, "DealDataNodeFeature %02x%02x, %d", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1], flag); @@ -94,10 +95,10 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { if (vecResult[0] == "3.0" || vecResult[0] == "4.0") { return; } - long staticIndex = BUILD_UINT32(pRecvData->Data[29], pRecvData->Data[28], pRecvData->Data[27], pRecvData->Data[26]); + long nodetimestamp = BUILD_UINT32(pRecvData->Data[29], pRecvData->Data[28], pRecvData->Data[27], pRecvData->Data[26]); char localtimestamp[32] = {0}; - GetTimeNet(localtimestamp, 1); + sprintf(localtimestamp,"%ld",nodetimestamp); std::string nowTimetamp = std::string(localtimestamp); strTimetamp = nowTimetamp; @@ -157,24 +158,24 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { dataStatic.nodeSendTime = lowbit * n; dataStatic.nodeWorkTime = dataStatic.nodeWorkTime - dataStatic.nodeSendTime; - RecordBattery(strLongAddr, dataStatic, nowTimetamp); + RecordBattery(strMeasurementID, dataStatic, nowTimetamp); char szTableName[50] = {0x00}, szTableNameStatic[50] = {0x00}, szTableNameData[50] = {0x00}; - sprintf(szTableName, "t_dataStatic_%s", strLongAddr.c_str()); + sprintf(szTableName, "t_dataStatic_%s", strMeasurementID.c_str()); memcpy(szTableNameStatic, szTableName, sizeof(szTableNameStatic)); memset(whereCon, 0x00, sizeof(whereCon)); - sprintf(whereCon, "StaticIndex = %ld", staticIndex); - int count = sqlite_db_ctrl::instance().GetTableRows(szTableNameStatic, whereCon); //避免重复数据 - sprintf(szTableNameData, "t_data_%s", strLongAddr.c_str()); + // sprintf(whereCon, "StaticIndex = %ld", staticIndex); + // int count = sqlite_db_ctrl::instance().GetTableRows(szTableNameStatic, whereCon); //避免重复数据 + // sprintf(szTableNameData, "t_data_%s", strMeasurementID.c_str()); - int count2 = sqlite_db_ctrl::instance().GetTableRows(szTableNameData, whereCon); - if (count > 0 || count2 > 0) { - char logInfo[100] = {0x00}; - sprintf(logInfo, "ShortAddr = %s,staticIndex = %ld,staticData = %d, data = %d", strShortAddr.c_str(), staticIndex, count, count2); - zlog_info(zct, logInfo); - return; - } + // int count2 = sqlite_db_ctrl::instance().GetTableRows(szTableNameData, whereCon); + // if (count > 0 || count2 > 0) { + // char logInfo[100] = {0x00}; + // sprintf(logInfo, "ShortAddr = %s,staticIndex = %ld,staticData = %d, data = %d", strShortAddr.c_str(), staticIndex, count, count2); + // zlog_info(zct, logInfo); + // return; + // } memset(whereCon, 0x00, sizeof(whereCon)); ///////////////////////////////////////////////////////////// for V2.0.3 upgrade to V3.0 std::string strTmp = ""; @@ -199,28 +200,28 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) { } ////////////////////////////////////////////////////////////更换电池判断 - sprintf(whereCon, " dataNodeNo = '%s' and StaticIndex > 0 order by StaticIndex desc LIMIT 0 , 1 ", strLongAddr.c_str()); - std::string strStaticIndex = sqlite_db_ctrl::instance().GetData(szTableNameStatic, "StaticIndex", whereCon); - if (atol(strStaticIndex.c_str()) - staticIndex > 100) { - sqlite_db_ctrl::instance().Deletetable(szTableNameStatic); - sqlite_db_ctrl::instance().Deletetable(szTableNameData); - zlog_info(zct, "staticIndexNOW = %ld,strStaticIndexLast = %s", staticIndex, strStaticIndex.c_str()); - } - zlog_info(zct, "NowstaticIndex = %ld,RecordStaticIndex = %ld", staticIndex, atol(strStaticIndex.c_str())); - if (staticIndex != atol(strStaticIndex.c_str() + 1) && strStaticIndex != "" && staticIndex < atol(strStaticIndex.c_str())) { - sprintf(whereCon, "StaticIndex = %ld order by StaticIndex desc LIMIT 0 , 1", atol(strStaticIndex.c_str())); - vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(szTableNameStatic, "timeStamp,StaticIndex", whereCon); - if (vecResult.size() > 0) { - memset(whereCon, 0x00, sizeof(whereCon)); - sprintf(whereCon, "dataNodeNo = '%s'", strLongAddr.c_str()); - std::string staticInterval = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), "featureInterval", whereCon); - long nNowTimetamp = atol(vecResult[0].c_str()) - (atol(staticInterval.c_str()) * (atol(vecResult[1].c_str()) - staticIndex)) * 60; - char tmp[10] = {0x00}; - sprintf(tmp, "%ld", nNowTimetamp); - nowTimetamp = std::string(tmp); - nodeResend = 1; - } - } + // sprintf(whereCon, " dataNodeNo = '%s' and StaticIndex > 0 order by StaticIndex desc LIMIT 0 , 1 ", strLongAddr.c_str()); + // std::string strStaticIndex = sqlite_db_ctrl::instance().GetData(szTableNameStatic, "StaticIndex", whereCon); + // if (atol(strStaticIndex.c_str()) - staticIndex > 100) { + // sqlite_db_ctrl::instance().Deletetable(szTableNameStatic); + // sqlite_db_ctrl::instance().Deletetable(szTableNameData); + // zlog_info(zct, "staticIndexNOW = %ld,strStaticIndexLast = %s", staticIndex, strStaticIndex.c_str()); + // } + // zlog_info(zct, "NowstaticIndex = %ld,RecordStaticIndex = %ld", staticIndex, atol(strStaticIndex.c_str())); + // if (staticIndex != atol(strStaticIndex.c_str() + 1) && strStaticIndex != "" && staticIndex < atol(strStaticIndex.c_str())) { + // sprintf(whereCon, "StaticIndex = %ld order by StaticIndex desc LIMIT 0 , 1", atol(strStaticIndex.c_str())); + // vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(szTableNameStatic, "timeStamp,StaticIndex", whereCon); + // if (vecResult.size() > 0) { + // memset(whereCon, 0x00, sizeof(whereCon)); + // sprintf(whereCon, "dataNodeNo = '%s'", strLongAddr.c_str()); + // std::string staticInterval = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), "featureInterval", whereCon); + // long nNowTimetamp = atol(vecResult[0].c_str()) - (atol(staticInterval.c_str()) * (atol(vecResult[1].c_str()) - staticIndex)) * 60; + // char tmp[10] = {0x00}; + // sprintf(tmp, "%ld", nNowTimetamp); + // nowTimetamp = std::string(tmp); + // nodeResend = 1; + // } + // } zlog_info(zct, "nowTimetamp = %s", nowTimetamp.c_str()); // save dataStatic of 7 days char selectCon[128] = {0};