add web cmd65
This commit is contained in:
parent
762b1e4899
commit
011221569e
@ -360,4 +360,12 @@ struct Param_64 {
|
||||
std::vector<FeatureEntryUploadCfg> cfg;
|
||||
Param_64() : mMode(0),partial(false){};
|
||||
};
|
||||
struct Param_65 {
|
||||
|
||||
int mMode;
|
||||
int mPackageFlag;
|
||||
std::string timeStart;
|
||||
std::string timeEnd;
|
||||
Param_65() : mMode(0),mPackageFlag(0),timeStart(""),timeEnd(""){};
|
||||
};
|
||||
#endif // PARAMETER_DEFINATION_HPP_
|
||||
|
||||
@ -421,7 +421,27 @@ vec_t SqliteDB::GetDataSingleLine(const char *tablename, const char *column, con
|
||||
sqlite3_finalize(stmt);
|
||||
return vecResult;
|
||||
}
|
||||
|
||||
vec_t SqliteDB::GetDataSingleLine(const char *sql) {
|
||||
vec_t vecResult;
|
||||
zlog_info(zct, "[GetDataSingleLine] sql:%s", sql);
|
||||
sqlite3_stmt *stmt;
|
||||
if (sqlite3_prepare_v2(mDBAcess, sql, -1, &stmt, 0) != SQLITE_OK) {
|
||||
zlog_error(zct, "sqlite3_prepare_v2:%s, sql:[%s]", sqlite3_errmsg(mDBAcess), sql);
|
||||
sqlite3_finalize(stmt);
|
||||
return vecResult;
|
||||
}
|
||||
int retStep = sqlite3_step(stmt);
|
||||
int column_count = sqlite3_column_count(stmt);
|
||||
if (retStep == SQLITE_ROW) {
|
||||
for (int iCol = 0; iCol < column_count; iCol++) {
|
||||
char *columninfo = (char *)sqlite3_column_text(stmt, iCol);
|
||||
std::string str = columninfo != NULL ? columninfo : "";
|
||||
vecResult.push_back(str);
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
return vecResult;
|
||||
}
|
||||
std::string SqliteDB::GetData(const char *tablename, const char *column, const char *whereCon) {
|
||||
std::string strRes = "";
|
||||
std::string strSql = "select ";
|
||||
|
||||
@ -48,6 +48,7 @@ public:
|
||||
int GetTableRows(const char *tablename, const char *whereCon);
|
||||
int AlterTable(const char *tablename, const char *column, bool isAdd = true);
|
||||
vec_t GetDataSingleLine(const char *tablename, const char *column, const char *whereCon);
|
||||
vec_t GetDataSingleLine(const char *sql);
|
||||
std::string GetData(const char *tablename, const char *column, const char *whereCon);
|
||||
array_t GetDataMultiLine(const char *sql);
|
||||
array_t GetDataMultiLine(const char *tablename, const char *column, const char *whereCon);
|
||||
|
||||
@ -73,6 +73,7 @@ public:
|
||||
std::string JsonCmd_Cgi_62(Param_62 ¶m);
|
||||
std::string JsonCmd_Cgi_63(Param_63 ¶m);
|
||||
std::string JsonCmd_Cgi_64(Param_64 ¶m);
|
||||
std::string JsonCmd_Cgi_65(Param_65 ¶m);
|
||||
std::string JsonCmd_Cgi_default();
|
||||
|
||||
//CMT tcp
|
||||
|
||||
@ -239,13 +239,13 @@ std::string JsonData::JsonCmd_Cgi_27(Param_27 ¶m) {
|
||||
sqlite_db_ctrl::instance().DeleteTableData(T_BATTERY_INFO(TNAME), whereCon);
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_battery_history ", whereCon);
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
sprintf(whereCon, "channelID like'%s'", param.mDataNodeNo.c_str());
|
||||
sprintf(whereCon, "channelID like '%%%s%%'", param.mMeasurementID.c_str());
|
||||
sqlite_db_ctrl::instance().DeleteTableData(" t_data_waveSend ", whereCon);
|
||||
char szTableName[50] = {0x00};
|
||||
sprintf(szTableName, "DROP TABLE t_data_%s", param.mDataNodeNo.c_str());
|
||||
sprintf(szTableName, "DROP TABLE t_data_%s", param.mMeasurementID.c_str());
|
||||
sqlite_db_ctrl::instance().CreateTable(szTableName);
|
||||
memset(szTableName, 0x00, sizeof(szTableName));
|
||||
sprintf(szTableName, "DROP TABLE t_dataStatic_%s", param.mDataNodeNo.c_str());
|
||||
sprintf(szTableName, "DROP TABLE t_dataStatic_%s", param.mMeasurementID.c_str());
|
||||
sqlite_db_ctrl::instance().CreateTable(szTableName);
|
||||
uint16_t short_addr;
|
||||
char *end_ptr = NULL;
|
||||
|
||||
@ -1087,3 +1087,179 @@ std::string JsonData::JsonCmd_Cgi_64(Param_64 ¶m)
|
||||
jsonVal["cmdBody"] = jsBody;
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
std::string JsonData::JsonCmd_Cgi_65(Param_65 ¶m){
|
||||
Json::Value jsonVal;
|
||||
jsonVal.clear();
|
||||
jsonVal[JSON_FIELD_CMD] = "65";
|
||||
jsonVal["success"] = true;
|
||||
jsonVal["message"] = " ";
|
||||
array_t vetRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(T_SENSOR_INFO(TNAME), " dataNodeName,MeasurementID ", NULL);
|
||||
size_t nSize = vetRes.size();
|
||||
std::string MeasurementID = "";
|
||||
char szTableName[100] = {0x00}, whereCon[256] = {0x00};
|
||||
if (nSize > 0) {
|
||||
int packgeNo = param.mPackageFlag;
|
||||
int packgeMax = 0;
|
||||
int packgeNum = 0;
|
||||
jsonVal["package"] = packgeNo;
|
||||
int lastSize = nSize % 5;
|
||||
int index = nSize / 5;
|
||||
if (lastSize > 0 && index > 0) {
|
||||
packgeMax = index + 1;
|
||||
if (packgeNo + 1 == packgeMax) {
|
||||
packgeNum = nSize;
|
||||
jsonVal["packageMax"] = index + 1;
|
||||
} else {
|
||||
packgeNum = (packgeNo + 1)*5;
|
||||
jsonVal["packageMax"] = index + 1;
|
||||
}
|
||||
} else if (lastSize == 0 && index > 0) {
|
||||
packgeNum = (packgeNo + 1) * 5;
|
||||
packgeMax = index;
|
||||
jsonVal["packageMax"] = index;
|
||||
} else if (lastSize > 0 && index == 0) {
|
||||
packgeNum = 0;
|
||||
packgeMax = index + 1;
|
||||
jsonVal["packageMax"] = index;
|
||||
}
|
||||
int interval = atol(param.timeEnd.c_str()) - atol(param.timeStart.c_str());
|
||||
int featureInterVal = 0,waveInterVal = 0,featureInterTime = 0,waveInterTime = 0,maxSensorNum = 0;
|
||||
scheduler::instance().GetScheduleConfig(featureInterVal,waveInterVal,featureInterTime,waveInterTime,maxSensorNum);
|
||||
Json::Value jsBody;
|
||||
zlog_info(zct, "packgeNo = %d,packgeMax = %d,packgeNum = %d", packgeNo, packgeMax, packgeNum);
|
||||
char count_sql[1024] = {0};
|
||||
for (size_t i = 0; i < nSize; i++)
|
||||
{
|
||||
Json::Value iTem;
|
||||
MeasurementID = vetRes[i][1];
|
||||
iTem.append(vetRes[i][0]);
|
||||
memset(szTableName,0,sizeof(szTableName));
|
||||
memset(whereCon,0,sizeof(whereCon));
|
||||
|
||||
sprintf(szTableName,"t_data_%s",vetRes[i][1].c_str());
|
||||
sprintf(whereCon, " channelID = '%s-X' and timeStamp < '%s' and timeStamp > '%s' ", MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str());
|
||||
//int recive_feature = sqlite_db_ctrl::instance().GetTableRows(szTableName, whereCon);
|
||||
int recive_feature = 0, send_feature = 0;
|
||||
memset(count_sql,0,sizeof(count_sql));
|
||||
snprintf(count_sql,sizeof(count_sql),
|
||||
"SELECT "
|
||||
"COUNT(*) FILTER (WHERE channelID = '%s-X') AS recive_feature,"
|
||||
"COUNT(*) FILTER (WHERE channelID = '%s-X' and sendMsg = 1) AS send_feature "
|
||||
"FROM ( "
|
||||
"SELECT * FROM %s "
|
||||
"WHERE timeStamp BETWEEN '%s' AND '%s');",MeasurementID.c_str(),MeasurementID.c_str(),szTableName,param.timeStart.c_str(),param.timeEnd.c_str());
|
||||
vec_t vecResult1 = sqlite_db_ctrl::instance().GetDataSingleLine(count_sql);
|
||||
if (vecResult1.size() > 0)
|
||||
{
|
||||
recive_feature = atoi(vecResult1[0].c_str());
|
||||
send_feature = atoi(vecResult1[1].c_str());
|
||||
}
|
||||
iTem.append(MeasurementID);
|
||||
// memset(szTableName,0,sizeof(szTableName));
|
||||
// memset(whereCon,0,sizeof(whereCon));
|
||||
// sprintf(szTableName,"receive_wave_status");
|
||||
// sprintf(whereCon, " data_nodeno = '%s-X' and timeStamp < '%s' and timeStamp > '%s' ", MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str());
|
||||
|
||||
// int recive_x = sqlite_db_ctrl::instance().GetTableRows(szTableName, whereCon);
|
||||
// memset(szTableName,0,sizeof(szTableName));
|
||||
// memset(whereCon,0,sizeof(whereCon));
|
||||
// sprintf(szTableName,"receive_wave_status");
|
||||
// sprintf(whereCon, " data_nodeno = '%s-Y' and timeStamp < '%s' and timeStamp > '%s' ", MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str());
|
||||
|
||||
// int recive_y = sqlite_db_ctrl::instance().GetTableRows(szTableName, whereCon);
|
||||
// memset(szTableName,0,sizeof(szTableName));
|
||||
// memset(whereCon,0,sizeof(whereCon));
|
||||
// sprintf(szTableName,"receive_wave_status");
|
||||
// sprintf(whereCon, " data_nodeno = '%s-Z' and timeStamp < '%s' and timeStamp > '%s' ", MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str());
|
||||
|
||||
// int recive_z = sqlite_db_ctrl::instance().GetTableRows(szTableName, whereCon);
|
||||
int recive_x = 0, recive_y = 0, recive_z = 0;
|
||||
memset(count_sql,0,sizeof(count_sql));
|
||||
snprintf(count_sql,sizeof(count_sql),
|
||||
"SELECT "
|
||||
"COUNT(*) FILTER (WHERE data_nodeno = '%s-X') AS recive_x,"
|
||||
"COUNT(*) FILTER (WHERE data_nodeno = '%s-Y') AS recive_y,"
|
||||
"COUNT(*) FILTER (WHERE data_nodeno = '%s-Z') AS recive_z "
|
||||
"FROM ( "
|
||||
"SELECT * FROM receive_wave_status "
|
||||
"WHERE timeStamp BETWEEN '%s' AND '%s');",MeasurementID.c_str(),MeasurementID.c_str(),MeasurementID.c_str(),param.timeStart.c_str(),param.timeEnd.c_str());
|
||||
vec_t vecResult2 = sqlite_db_ctrl::instance().GetDataSingleLine(count_sql);
|
||||
if (vecResult2.size() > 0)
|
||||
{
|
||||
recive_x = atoi(vecResult2[0].c_str());
|
||||
recive_y = atoi(vecResult2[1].c_str());
|
||||
recive_z = atoi(vecResult2[2].c_str());
|
||||
}
|
||||
iTem.append((float(recive_feature)/(interval/featureInterVal)));
|
||||
iTem.append(recive_feature);
|
||||
iTem.append((float( recive_x)/(interval/waveInterVal)));
|
||||
iTem.append(recive_x);
|
||||
iTem.append((float(recive_y)/(interval/waveInterVal)));
|
||||
iTem.append(recive_y);
|
||||
iTem.append((float(recive_z)/(interval/waveInterVal)));
|
||||
iTem.append(recive_z);
|
||||
|
||||
// memset(szTableName,0,sizeof(szTableName));
|
||||
// memset(whereCon,0,sizeof(whereCon));
|
||||
// sprintf(szTableName,"t_data_%s",vetRes[i][1].c_str());
|
||||
// sprintf(whereCon, " channelID = '%s-X' and timeStamp < '%s' and timeStamp > '%s' and sendMsg = 1", MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str());
|
||||
// int send_feature = sqlite_db_ctrl::instance().GetTableRows(szTableName, whereCon);
|
||||
|
||||
// memset(szTableName,0,sizeof(szTableName));
|
||||
// memset(whereCon,0,sizeof(whereCon));
|
||||
// sprintf(szTableName," t_data_waveSend ");
|
||||
// sprintf(whereCon, " channelID = '%s-X' and timeStamp < '%s' and timeStamp > '%s' and sendMsg = 1", MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str());
|
||||
// int send_x = sqlite_db_ctrl::instance().GetTableRows(szTableName, whereCon);
|
||||
|
||||
// memset(szTableName,0,sizeof(szTableName));
|
||||
// memset(whereCon,0,sizeof(whereCon));
|
||||
// sprintf(szTableName," t_data_waveSend ");
|
||||
// sprintf(whereCon, " channelID = '%s-Y' and timeStamp < '%s' and timeStamp > '%s' and sendMsg = 1", MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str());
|
||||
// int send_y = sqlite_db_ctrl::instance().GetTableRows(szTableName, whereCon);
|
||||
|
||||
// memset(szTableName,0,sizeof(szTableName));
|
||||
// memset(whereCon,0,sizeof(whereCon));
|
||||
// sprintf(szTableName," t_data_waveSend ");
|
||||
// sprintf(whereCon, " channelID = '%s-Z' and timeStamp < '%s' and timeStamp > '%s' and sendMsg = 1", MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str());
|
||||
// int send_z = sqlite_db_ctrl::instance().GetTableRows(szTableName, whereCon);
|
||||
int send_x = 0, send_y = 0, send_z = 0;
|
||||
memset(count_sql,0,sizeof(count_sql));
|
||||
snprintf(count_sql,sizeof(count_sql),
|
||||
"SELECT "
|
||||
"COUNT(*) FILTER (WHERE channelID = '%s-X') AS send_x,"
|
||||
"COUNT(*) FILTER (WHERE channelID = '%s-Y') AS send_y,"
|
||||
"COUNT(*) FILTER (WHERE channelID = '%s-Z') AS send_z "
|
||||
"FROM ( "
|
||||
"SELECT * FROM t_data_waveSend "
|
||||
"WHERE sendMsg = 1 and timeStamp BETWEEN '%s' AND '%s');",MeasurementID.c_str(),MeasurementID.c_str(),MeasurementID.c_str(),param.timeStart.c_str(),param.timeEnd.c_str());
|
||||
vec_t vecResult3 = sqlite_db_ctrl::instance().GetDataSingleLine(count_sql);
|
||||
if (vecResult3.size() > 0)
|
||||
{
|
||||
send_x = atoi(vecResult3[0].c_str());
|
||||
send_y = atoi(vecResult3[1].c_str());
|
||||
send_z = atoi(vecResult3[2].c_str());
|
||||
}
|
||||
|
||||
iTem.append((float(send_feature)/(interval/featureInterVal)));
|
||||
iTem.append(send_feature);
|
||||
iTem.append((float(send_x)/(interval/waveInterVal)));
|
||||
iTem.append(send_x);
|
||||
iTem.append((float(send_y)/(interval/waveInterVal)));
|
||||
iTem.append(send_y);
|
||||
iTem.append((float(send_z)/(interval/waveInterVal)));
|
||||
iTem.append(send_z);
|
||||
|
||||
jsBody.append(iTem);
|
||||
}
|
||||
if (jsBody.size() == 0) {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["content"].resize(0);
|
||||
} else {
|
||||
jsonVal["content"] = (jsBody);
|
||||
}
|
||||
} else {
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["content"].resize(0);
|
||||
}
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
|
||||
@ -54,6 +54,7 @@ enum WebCommand {
|
||||
kWaveReceive = 62,
|
||||
kWaveSend = 63,
|
||||
kFeatureSend = 64,
|
||||
kFeatureWaveCount = 65,
|
||||
|
||||
//CMT TCP
|
||||
kGateWayVersion = 80,
|
||||
|
||||
@ -512,6 +512,17 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
||||
std::string data = jd.JsonCmd_Cgi_64(param);
|
||||
return data;
|
||||
}break;
|
||||
case kFeatureWaveCount:{
|
||||
JsonData jd;
|
||||
Param_65 param;
|
||||
param.mPackageFlag = recvBody["package"].asInt();
|
||||
param.timeStart = recvBody["timeStart"].asString();
|
||||
param.timeEnd = recvBody["timeEnd"].asString();
|
||||
std::string data = jd.JsonCmd_Cgi_65(param);
|
||||
printf("return data = %s\n", data.c_str());
|
||||
return data;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
JsonData jd;
|
||||
std::string data = jd.JsonCmd_Cgi_default();
|
||||
|
||||
@ -452,6 +452,7 @@ bool SensorScheduler::MissedWave(uint16_t short_addr) {
|
||||
void SensorScheduler::WaveSuccess(uint16_t short_addr) {
|
||||
zlog_warn(zct, "[WaveSuccess][%x]", short_addr);
|
||||
success_set_.insert(short_addr);
|
||||
patch_set_.erase(short_addr);
|
||||
auto iter = failure_map_.find(short_addr);
|
||||
if (iter != failure_map_.end()) {
|
||||
zlog_warn(zct, "[WaveSuccess][%x] try %d times success", short_addr, 4 - iter->second);
|
||||
|
||||
@ -572,7 +572,6 @@ int Uart::DealFeatureValue(const char *pData,uint16_t ushortAdd){
|
||||
DealAskTask(ushortAdd);
|
||||
DealDataNodeFeature(pData, 0);
|
||||
}
|
||||
last_short_addr = ushortAdd;
|
||||
GetTimeNet(localtimestamp, 1);
|
||||
nowTimetamp = std::string(localtimestamp);
|
||||
last_time = atol(nowTimetamp.c_str());
|
||||
@ -587,10 +586,11 @@ void Uart::DealRecvData(const char *pData) {
|
||||
int taskID = 0;
|
||||
ScheduleTask scheduleTask;
|
||||
zlog_info(zct, "shortAdd = %02x%02x,command = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command);
|
||||
if (ushortAdd != last_short_addr){
|
||||
mssleep(50000);
|
||||
ModifyDistAddr(ushortAdd);
|
||||
mssleep(50000);
|
||||
|
||||
}
|
||||
switch (command) {
|
||||
case DEVICE_INF:
|
||||
DealDataNodeInfo(pData);
|
||||
@ -652,6 +652,7 @@ void Uart::DealRecvData(const char *pData) {
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
last_short_addr = ushortAdd;
|
||||
}
|
||||
|
||||
void Uart::DealDataNodeName(const char *pData) {
|
||||
|
||||
@ -1025,11 +1025,12 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
|
||||
Json::FastWriter WaveValue;
|
||||
std::string WaveData = WaveValue.write(valWaveData);
|
||||
|
||||
char selectCon[128] = {0};
|
||||
char selectCon[128] = {0},whereCon[128] = {0};
|
||||
sprintf(selectCon, "channelID='%s' ORDER BY timeStamp ASC LIMIT 0,1", strChannelID.c_str());
|
||||
std::string strTime = sqlite_db_ctrl::instance().GetData("t_data_waveSend", "timeStamp", selectCon);
|
||||
long lTime = atol(nowTimetamp.c_str()) - atol(strTime.c_str());
|
||||
int Count = sqlite_db_ctrl::instance().GetTableRows("t_data_waveSend", NULL);
|
||||
sprintf(whereCon, "channelID like '%%%s%%'", strMeasurementID.c_str());
|
||||
int Count = sqlite_db_ctrl::instance().GetTableRows("t_data_waveSend", whereCon);
|
||||
std::string strFileName_Record = strFileName + "_" + nowTimetamp;
|
||||
if ((Count * 3 < SAVE_COUNT && lTime < OneWeek) || strTime.size() == 0) {
|
||||
char insertSql[128] = {0x00};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user