优化特征值时间戳
This commit is contained in:
parent
c6b3475b4a
commit
54f657c9a1
@ -512,9 +512,22 @@ std::string JsonData::JsonCmd_Cgi_58(Param_58 ¶m) {
|
|||||||
jsonVal[JSON_FIELD_CMD] = "58";
|
jsonVal[JSON_FIELD_CMD] = "58";
|
||||||
jsonVal["success"] = true;
|
jsonVal["success"] = true;
|
||||||
jsonVal["message"] = "";
|
jsonVal["message"] = "";
|
||||||
int ret = scheduler::instance().Config(param.featureInterVal,param.waveInterVal,param.featureInterTime,param.waveInterTime,param.maxSensorNum);
|
int ret = 0;
|
||||||
if (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["success"] = false;
|
||||||
jsonVal["message"] = "保存失败!";
|
jsonVal["message"] = "保存失败!";
|
||||||
}
|
}
|
||||||
@ -529,16 +542,12 @@ std::string JsonData::JsonCmd_Cgi_59(Param_59 ¶m) {
|
|||||||
jsonVal["message"] = "";
|
jsonVal["message"] = "";
|
||||||
char table_name[50] ={0};
|
char table_name[50] ={0};
|
||||||
int interval = 0;
|
int interval = 0;
|
||||||
|
char sql[1024]={0};
|
||||||
if (param.mMode == 1)
|
if (param.mMode == 1)
|
||||||
{
|
{
|
||||||
sprintf(table_name,"t_dataStatic_%s",param.DataNodeNo.c_str());
|
sprintf(table_name,"t_dataStatic_%s",param.DataNodeNo.c_str());
|
||||||
interval = 400;
|
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 ("
|
"WITH CTE AS ("
|
||||||
" SELECT timestamp, "
|
" SELECT timestamp, "
|
||||||
@ -552,6 +561,27 @@ std::string JsonData::JsonCmd_Cgi_59(Param_59 ¶m) {
|
|||||||
"WHERE prev_timestamp IS NOT NULL "
|
"WHERE prev_timestamp IS NOT NULL "
|
||||||
" AND (timestamp - prev_timestamp) > %d;",
|
" AND (timestamp - prev_timestamp) > %d;",
|
||||||
table_name,interval);
|
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);
|
array_t arrResult = sqlite_db_ctrl::instance().GetDataMultiLine(sql);
|
||||||
Json::Value valData;
|
Json::Value valData;
|
||||||
@ -567,6 +597,7 @@ std::string JsonData::JsonCmd_Cgi_59(Param_59 ¶m) {
|
|||||||
}
|
}
|
||||||
jsonVal["content"] = valData;
|
jsonVal["content"] = valData;
|
||||||
|
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
jsonVal["success"] = false;
|
jsonVal["success"] = false;
|
||||||
jsonVal["message"] = "获取数据失败!";
|
jsonVal["message"] = "获取数据失败!";
|
||||||
|
|||||||
@ -376,6 +376,13 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
|||||||
case kSchedulingConfiguration:{
|
case kSchedulingConfiguration:{
|
||||||
JsonData jd;
|
JsonData jd;
|
||||||
Param_58 param;
|
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.featureInterVal = recvBody["featureInterVal"].asInt();
|
||||||
param.featureInterTime = recvBody["featureInterTime"].asInt();
|
param.featureInterTime = recvBody["featureInterTime"].asInt();
|
||||||
param.waveInterVal = recvBody["waveInterVal"].asInt();
|
param.waveInterVal = recvBody["waveInterVal"].asInt();
|
||||||
@ -389,6 +396,7 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
|||||||
Param_59 param;
|
Param_59 param;
|
||||||
param.mMode = recvBody["type"].asInt();
|
param.mMode = recvBody["type"].asInt();
|
||||||
param.DataNodeNo = recvBody["DataNodeNo"].asString();
|
param.DataNodeNo = recvBody["DataNodeNo"].asString();
|
||||||
|
param.straxis = recvBody["Raxis"].asString();
|
||||||
std::string data = jd.JsonCmd_Cgi_59(param);
|
std::string data = jd.JsonCmd_Cgi_59(param);
|
||||||
return data;
|
return data;
|
||||||
}break;
|
}break;
|
||||||
|
|||||||
@ -375,8 +375,7 @@ int Uart::DealAskTask(uint16_t ushortAdd){
|
|||||||
int taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration);
|
int taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration);
|
||||||
ScheduleTask scheduleTask;
|
ScheduleTask scheduleTask;
|
||||||
zlog_info(zct, "taskID = %d ", taskID);
|
zlog_info(zct, "taskID = %d ", taskID);
|
||||||
// if (taskID == kScheduleEigenValue) //1.特征值
|
if (taskID == kScheduleEigenValue) //1.特征值
|
||||||
if (taskID == 6)
|
|
||||||
{
|
{
|
||||||
char localtimestamp[32] = {0x00};
|
char localtimestamp[32] = {0x00};
|
||||||
int millisecond = 0;
|
int millisecond = 0;
|
||||||
@ -385,7 +384,6 @@ int Uart::DealAskTask(uint16_t ushortAdd){
|
|||||||
scheduleTask.shortAddr = ushortAdd;
|
scheduleTask.shortAddr = ushortAdd;
|
||||||
scheduleTask.timeStamp = atoi(localtimestamp);
|
scheduleTask.timeStamp = atoi(localtimestamp);
|
||||||
TaskResp(scheduleTask);
|
TaskResp(scheduleTask);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
else if (taskID == kScheduleWaveForm) //2.波形
|
else if (taskID == kScheduleWaveForm) //2.波形
|
||||||
{
|
{
|
||||||
@ -530,8 +528,6 @@ void Uart::DealDataNodeName(const char *pData) {
|
|||||||
char uplCon[200] = {0x00};
|
char uplCon[200] = {0x00};
|
||||||
char nodeWaveSend[10] = {0x00};
|
char nodeWaveSend[10] = {0x00};
|
||||||
|
|
||||||
UpdateWirelessNodeTime((unsigned char *)shortAdd, 1);
|
|
||||||
|
|
||||||
for (int i = 0; i < 64; i++) {
|
for (int i = 0; i < 64; i++) {
|
||||||
sprintf(&NodeName[i * 2], "%02X", pData[7 + i] & 0xFF);
|
sprintf(&NodeName[i * 2], "%02X", pData[7 + i] & 0xFF);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,6 +31,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
|||||||
char updateSql[1024] = {0};
|
char updateSql[1024] = {0};
|
||||||
char buf[20] = {0x00};
|
char buf[20] = {0x00};
|
||||||
int nodeResend = 0, timing = 0;
|
int nodeResend = 0, timing = 0;
|
||||||
|
long staticIndex = 0;
|
||||||
sprintf(buf, "%02x%02x", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]);
|
sprintf(buf, "%02x%02x", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]);
|
||||||
if (flag == 1) {
|
if (flag == 1) {
|
||||||
zlog_info(zct, "DealDataNodeFeature %02x%02x, %d", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1], flag);
|
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") {
|
if (vecResult[0] == "3.0" || vecResult[0] == "4.0") {
|
||||||
return;
|
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};
|
char localtimestamp[32] = {0};
|
||||||
GetTimeNet(localtimestamp, 1);
|
sprintf(localtimestamp,"%ld",nodetimestamp);
|
||||||
std::string nowTimetamp = std::string(localtimestamp);
|
std::string nowTimetamp = std::string(localtimestamp);
|
||||||
strTimetamp = nowTimetamp;
|
strTimetamp = nowTimetamp;
|
||||||
|
|
||||||
@ -157,24 +158,24 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
|
|||||||
dataStatic.nodeSendTime = lowbit * n;
|
dataStatic.nodeSendTime = lowbit * n;
|
||||||
dataStatic.nodeWorkTime = dataStatic.nodeWorkTime - dataStatic.nodeSendTime;
|
dataStatic.nodeWorkTime = dataStatic.nodeWorkTime - dataStatic.nodeSendTime;
|
||||||
|
|
||||||
RecordBattery(strLongAddr, dataStatic, nowTimetamp);
|
RecordBattery(strMeasurementID, dataStatic, nowTimetamp);
|
||||||
|
|
||||||
char szTableName[50] = {0x00}, szTableNameStatic[50] = {0x00}, szTableNameData[50] = {0x00};
|
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));
|
memcpy(szTableNameStatic, szTableName, sizeof(szTableNameStatic));
|
||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
|
|
||||||
sprintf(whereCon, "StaticIndex = %ld", staticIndex);
|
// sprintf(whereCon, "StaticIndex = %ld", staticIndex);
|
||||||
int count = sqlite_db_ctrl::instance().GetTableRows(szTableNameStatic, whereCon); //避免重复数据
|
// int count = sqlite_db_ctrl::instance().GetTableRows(szTableNameStatic, whereCon); //避免重复数据
|
||||||
sprintf(szTableNameData, "t_data_%s", strLongAddr.c_str());
|
// sprintf(szTableNameData, "t_data_%s", strMeasurementID.c_str());
|
||||||
|
|
||||||
int count2 = sqlite_db_ctrl::instance().GetTableRows(szTableNameData, whereCon);
|
// int count2 = sqlite_db_ctrl::instance().GetTableRows(szTableNameData, whereCon);
|
||||||
if (count > 0 || count2 > 0) {
|
// if (count > 0 || count2 > 0) {
|
||||||
char logInfo[100] = {0x00};
|
// char logInfo[100] = {0x00};
|
||||||
sprintf(logInfo, "ShortAddr = %s,staticIndex = %ld,staticData = %d, data = %d", strShortAddr.c_str(), staticIndex, count, count2);
|
// sprintf(logInfo, "ShortAddr = %s,staticIndex = %ld,staticData = %d, data = %d", strShortAddr.c_str(), staticIndex, count, count2);
|
||||||
zlog_info(zct, logInfo);
|
// zlog_info(zct, logInfo);
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
///////////////////////////////////////////////////////////// for V2.0.3 upgrade to V3.0
|
///////////////////////////////////////////////////////////// for V2.0.3 upgrade to V3.0
|
||||||
std::string strTmp = "";
|
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());
|
// 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);
|
// std::string strStaticIndex = sqlite_db_ctrl::instance().GetData(szTableNameStatic, "StaticIndex", whereCon);
|
||||||
if (atol(strStaticIndex.c_str()) - staticIndex > 100) {
|
// if (atol(strStaticIndex.c_str()) - staticIndex > 100) {
|
||||||
sqlite_db_ctrl::instance().Deletetable(szTableNameStatic);
|
// sqlite_db_ctrl::instance().Deletetable(szTableNameStatic);
|
||||||
sqlite_db_ctrl::instance().Deletetable(szTableNameData);
|
// sqlite_db_ctrl::instance().Deletetable(szTableNameData);
|
||||||
zlog_info(zct, "staticIndexNOW = %ld,strStaticIndexLast = %s", staticIndex, strStaticIndex.c_str());
|
// zlog_info(zct, "staticIndexNOW = %ld,strStaticIndexLast = %s", staticIndex, strStaticIndex.c_str());
|
||||||
}
|
// }
|
||||||
zlog_info(zct, "NowstaticIndex = %ld,RecordStaticIndex = %ld", staticIndex, atol(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())) {
|
// 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()));
|
// 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);
|
// vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(szTableNameStatic, "timeStamp,StaticIndex", whereCon);
|
||||||
if (vecResult.size() > 0) {
|
// if (vecResult.size() > 0) {
|
||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
// memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
sprintf(whereCon, "dataNodeNo = '%s'", strLongAddr.c_str());
|
// sprintf(whereCon, "dataNodeNo = '%s'", strLongAddr.c_str());
|
||||||
std::string staticInterval = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), "featureInterval", whereCon);
|
// 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;
|
// long nNowTimetamp = atol(vecResult[0].c_str()) - (atol(staticInterval.c_str()) * (atol(vecResult[1].c_str()) - staticIndex)) * 60;
|
||||||
char tmp[10] = {0x00};
|
// char tmp[10] = {0x00};
|
||||||
sprintf(tmp, "%ld", nNowTimetamp);
|
// sprintf(tmp, "%ld", nNowTimetamp);
|
||||||
nowTimetamp = std::string(tmp);
|
// nowTimetamp = std::string(tmp);
|
||||||
nodeResend = 1;
|
// nodeResend = 1;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
zlog_info(zct, "nowTimetamp = %s", nowTimetamp.c_str());
|
zlog_info(zct, "nowTimetamp = %s", nowTimetamp.c_str());
|
||||||
// save dataStatic of 7 days
|
// save dataStatic of 7 days
|
||||||
char selectCon[128] = {0};
|
char selectCon[128] = {0};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user