modify web code , new scheduler

This commit is contained in:
zhangsheng 2026-01-28 19:26:45 +08:00
parent 7fc05f4818
commit 5d05252454
7 changed files with 348 additions and 253 deletions

View File

@ -322,11 +322,12 @@ struct Param_59 {
Param_59() : mMode(0),DataNodeNo(""),straxis(""){}; Param_59() : mMode(0),DataNodeNo(""),straxis(""){};
}; };
struct Param_60 { struct Param_60 {
int mMode;
std::string fileName; std::string fileName;
int product; int product;
std::string mShortAddr; std::string mShortAddr;
std::vector<std::string> dataNodeNo; std::vector<std::string> dataNodeNo;
Param_60() : fileName(""),product(0),mShortAddr(""){}; Param_60() :mMode(0), fileName(""),product(0),mShortAddr(""){};
}; };
struct Param_61 { struct Param_61 {
int mMode; int mMode;
@ -397,8 +398,9 @@ struct Param_68 {
int signalThreshold; int signalThreshold;
int lowBatteryLevel; int lowBatteryLevel;
int batteryLevelThreshold; int batteryLevelThreshold;
int shutdownDetection;
std::vector<Param_68_info> vecParam68; std::vector<Param_68_info> vecParam68;
Param_68():lowSignal(0),signalThreshold(0),lowBatteryLevel(0),batteryLevelThreshold(0){}; Param_68():lowSignal(0),signalThreshold(0),lowBatteryLevel(0),batteryLevelThreshold(0),shutdownDetection(0){};
}; };
struct Param_69_info{ struct Param_69_info{

View File

@ -643,6 +643,7 @@ std::string JsonData::JsonCmd_Cgi_60(Param_60 &param){
jsonVal[JSON_FIELD_CMD] = "60"; jsonVal[JSON_FIELD_CMD] = "60";
jsonVal["success"] = true; jsonVal["success"] = true;
jsonVal["message"] = ""; jsonVal["message"] = "";
if(param.mMode == 0){
char file_path[64]={0}; char file_path[64]={0};
char cmd[128]={0}; char cmd[128]={0};
sprintf(cmd, "mv /opt/%s /opt/DataNode/",param.fileName.c_str()); sprintf(cmd, "mv /opt/%s /opt/DataNode/",param.fileName.c_str());
@ -726,12 +727,15 @@ std::string JsonData::JsonCmd_Cgi_60(Param_60 &param){
char localtimestamp[32] = {0}; char localtimestamp[32] = {0};
GetTimeNet(localtimestamp, 1); GetTimeNet(localtimestamp, 1);
std::vector<UpgradeParameter> param_list; std::vector<UpgradeParameter> param_list;
for (size_t i = 0; i < param.dataNodeNo.size(); i++)
{
UpgradeParameter upgrade_parameter;
char wherecon[100] = {0}; char wherecon[100] = {0};
char insertSql[200] = {0}; char insertSql[200] = {0};
char updateSql[100] = {0}; char updateSql[100] = {0};
for (size_t i = 0; i < param.dataNodeNo.size(); i++)
{
UpgradeParameter upgrade_parameter;
memset(wherecon,0,sizeof(wherecon));
memset(insertSql,0,sizeof(insertSql));
memset(updateSql,0,sizeof(updateSql));
sprintf(wherecon," dataNodeNo = '%s' ",param.dataNodeNo[i].c_str()); sprintf(wherecon," dataNodeNo = '%s' ",param.dataNodeNo[i].c_str());
vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " hardVersion,softVersion,ProductNo,zigbeeShortAddr ", wherecon); vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " hardVersion,softVersion,ProductNo,zigbeeShortAddr ", wherecon);
if (hw_ver != atoi(vecResult[0].c_str())) if (hw_ver != atoi(vecResult[0].c_str()))
@ -768,6 +772,13 @@ std::string JsonData::JsonCmd_Cgi_60(Param_60 &param){
return show_value_.write(jsonVal); return show_value_.write(jsonVal);
} }
free(buffer); free(buffer);
}else if(param.mMode == 1){
for (size_t i = 0; i < param.dataNodeNo.size(); i++)
{
}
}
return show_value_.write(jsonVal); return show_value_.write(jsonVal);
} }
@ -1095,7 +1106,7 @@ std::string JsonData::JsonCmd_Cgi_65(Param_65 &param){
jsonVal[JSON_FIELD_CMD] = "65"; jsonVal[JSON_FIELD_CMD] = "65";
jsonVal["success"] = true; jsonVal["success"] = true;
jsonVal["message"] = " "; jsonVal["message"] = " ";
array_t vetRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(T_SENSOR_INFO(TNAME), " dataNodeName,MeasurementID,RSSI ", NULL); array_t vetRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(T_SENSOR_INFO(TNAME), " dataNodeName,MeasurementID,RSSI,batteryPower ", NULL);
size_t nSize = vetRes.size(); size_t nSize = vetRes.size();
std::string MeasurementID = ""; std::string MeasurementID = "";
char szTableName[100] = {0x00}, whereCon[256] = {0x00}; char szTableName[100] = {0x00}, whereCon[256] = {0x00};
@ -1163,8 +1174,9 @@ std::string JsonData::JsonCmd_Cgi_65(Param_65 &param){
iTem.append(recive_y); iTem.append(recive_y);
iTem.append((float(recive_z)/(interval/waveInterVal))); iTem.append((float(recive_z)/(interval/waveInterVal)));
iTem.append(recive_z); iTem.append(recive_z);
} }
// memset(count_sql,0,sizeof(count_sql)); // memset(count_sql,0,sizeof(count_sql));
// snprintf(count_sql,sizeof(count_sql), // snprintf(count_sql,sizeof(count_sql),
// "SELECT " // "SELECT "
@ -1205,8 +1217,16 @@ std::string JsonData::JsonCmd_Cgi_65(Param_65 &param){
} }
iTem.append(resend_feature); iTem.append(resend_feature);
iTem.append(resend_z); iTem.append(resend_z);
iTem.append(60); //信号
iTem.append(vetRes[i][3]); //电池
sprintf(whereCon,"timeStamp <> '' order by timeStamp desc limit 0,1 ",MeasurementID.c_str());
memset(szTableName,0,sizeof(szTableName));
sprintf(szTableName,"t_dataStatic_%s",vetRes[i][1].c_str());
std::string voltage = sqlite_db_ctrl::instance().GetData(szTableName, "voltage", whereCon);
iTem.append(voltage); //电压
jsBody.append(iTem); jsBody.append(iTem);
} }
if (jsBody.size() == 0) { if (jsBody.size() == 0) {
jsonVal["success"] = false; jsonVal["success"] = false;
@ -1246,9 +1266,16 @@ std::string JsonData::JsonCmd_Cgi_67(Param_67 &param){
jsonVal[JSON_FIELD_CMD] = "67"; jsonVal[JSON_FIELD_CMD] = "67";
jsonVal["success"] = true; jsonVal["success"] = true;
jsonVal["message"] = " "; jsonVal["message"] = " ";
char whereCon[512] = {0};
char selectCon[128] = {0};
char column[128] = {0};
char tablename[256] = {0};
if(param.mMode == 0){ if(param.mMode == 0){
array_t arrResAll = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_INFO(TNAME), " dataNodeNo,MeasurementID,zigbeeShortAddr ", NULL); sprintf(selectCon, " t_sensor_info.MeasurementID = t_debug_info.MeasurementID ");
int nSize = arrResAll.size(); sprintf(column, " t_debug_info.*,t_sensor_info.status,t_sensor_info.dataNodeName ");
sprintf(tablename, " t_debug_info LEFT JOIN t_sensor_info ");
array_t arrRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(tablename, column, selectCon);
int nSize = arrRes.size();
if (nSize > 0) { if (nSize > 0) {
int packgeNo = param.mPackageFlag; int packgeNo = param.mPackageFlag;
int packgeMax = 0; int packgeMax = 0;
@ -1275,26 +1302,12 @@ std::string JsonData::JsonCmd_Cgi_67(Param_67 &param){
jsonVal["packageMax"] = index + 1; jsonVal["packageMax"] = index + 1;
} }
Json::Value jsSensor; Json::Value jsSensor;
for (int i = packgeNo * 10; i < packgeNum; i++) { for (int j = packgeNo * 10; j < packgeNum; j++) {
std::string strMeasurementID = arrResAll[i][1];
std::string strShortAddr = arrResAll[i][2];
char whereCon[512] = {0};
char selectCon[128] = {0};
char column[128] = {0};
char tablename[256] = {0};
sprintf(selectCon, " t_sensor_info.MeasurementID='%s' ", strMeasurementID.c_str());
sprintf(column, " t_debug_info.*,t_sensor_info.status,t_sensor_info.dataNodeName ");
sprintf(tablename, " t_debug_info LEFT JOIN t_sensor_info ");
array_t arrRes;
arrRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(tablename, "*", selectCon);
int iResult = arrRes.size();
if (iResult > 0) {
for (int j = 0; j < iResult; j++) {
Json::Value jsChannelData; Json::Value jsChannelData;
jsChannelData["dataNodeName"] = arrRes[j][10]; jsChannelData["dataNodeName"] = arrRes[j][10];
jsChannelData["zigbeeAddr"] = arrRes[j][1]; jsChannelData["zigbeeAddr"] = arrRes[j][1];
jsChannelData["MeasurementID"] = arrRes[j][0]; jsChannelData["MeasurementID"] = arrRes[j][0];
jsChannelData["status"] = atoi(arrRes[j][0].c_str()); jsChannelData["status"] = atoi(arrRes[j][9].c_str());
jsChannelData["gatewayRssi"] = atoi(arrRes[j][2].c_str()); jsChannelData["gatewayRssi"] = atoi(arrRes[j][2].c_str());
jsChannelData["dataNodeRssi"] = atoi(arrRes[j][3].c_str()); jsChannelData["dataNodeRssi"] = atoi(arrRes[j][3].c_str());
jsChannelData["comprehensiveRssi"] = atof(arrRes[j][4].c_str()); jsChannelData["comprehensiveRssi"] = atof(arrRes[j][4].c_str());
@ -1304,8 +1317,6 @@ std::string JsonData::JsonCmd_Cgi_67(Param_67 &param){
jsChannelData["TimeStamp"] = arrRes[j][8]; jsChannelData["TimeStamp"] = arrRes[j][8];
jsSensor.append(jsChannelData); jsSensor.append(jsChannelData);
} }
}
}
if (jsSensor.size() == 0) { if (jsSensor.size() == 0) {
jsonVal["success"] = false; jsonVal["success"] = false;
jsonVal["content"].resize(0); jsonVal["content"].resize(0);
@ -1332,7 +1343,22 @@ std::string JsonData::JsonCmd_Cgi_67(Param_67 &param){
//scheduler::instance().StartSensorDebug(short_addr); //scheduler::instance().StartSensorDebug(short_addr);
} }
} }
}else if(param.mMode == 2){ // 停止调试
if(param.measurementID.size() > 0){
for (size_t i = 0; i < param.measurementID.size(); i++)
{
char whereCon[512] = {0};
char updateSql[256] = {0};
sprintf(whereCon, " MeasurementID = '%s' ", param.measurementID[i].c_str());
sprintf(updateSql, " status = '%d' ", 1);// 0 未调试1 调试中2 调试完成
sqlite_db_ctrl::instance().UpdateTableData("t_debug_info", updateSql, whereCon);
//uint16_t short_addr;
//char *end_ptr = NULL;
//vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " zigbeeShortAddr ", whereCon);
//short_addr = strtol(vecResult[0].c_str(), &end_ptr, 16);
//scheduler::instance().StartSensorDebug(short_addr);
}
}
} }
return show_value_.write(jsonVal); return show_value_.write(jsonVal);
} }
@ -1344,7 +1370,7 @@ std::string JsonData::JsonCmd_Cgi_68(Param_68 &param){
jsonVal[JSON_FIELD_CMD] = "68"; jsonVal[JSON_FIELD_CMD] = "68";
jsonVal["success"] = true; jsonVal["success"] = true;
jsonVal["message"] = " "; jsonVal["message"] = " ";
int lowSignal = -1, signalThreshold = -1, lowBatteryLevel = -1, batteryLevelThreshold = -1; int lowSignal = -1, signalThreshold = -1, lowBatteryLevel = -1, batteryLevelThreshold = -1,shutdownDetection = -1;
char whereCon[512] = {0}; char whereCon[512] = {0};
char updateSql[256] = {0}; char updateSql[256] = {0};
if (param.mMode == 1) { if (param.mMode == 1) {
@ -1352,7 +1378,7 @@ std::string JsonData::JsonCmd_Cgi_68(Param_68 &param){
signalThreshold = writeIntValue("config", "signalThreshold", param.signalThreshold, (char *)GlobalConfig::Config_G.c_str()); signalThreshold = writeIntValue("config", "signalThreshold", param.signalThreshold, (char *)GlobalConfig::Config_G.c_str());
lowBatteryLevel = writeIntValue("config", "lowBatteryLevel", param.lowBatteryLevel, (char *)GlobalConfig::Config_G.c_str()); lowBatteryLevel = writeIntValue("config", "lowBatteryLevel", param.lowBatteryLevel, (char *)GlobalConfig::Config_G.c_str());
batteryLevelThreshold = writeIntValue("config", "batteryLevelThreshold", param.batteryLevelThreshold, (char *)GlobalConfig::Config_G.c_str()); batteryLevelThreshold = writeIntValue("config", "batteryLevelThreshold", param.batteryLevelThreshold, (char *)GlobalConfig::Config_G.c_str());
shutdownDetection = writeIntValue("config", "shutdownDetection", param.shutdownDetection, (char *)GlobalConfig::Config_G.c_str());
if(param.vecParam68.size() > 0){ if(param.vecParam68.size() > 0){
for (size_t i = 0; i < param.vecParam68.size(); i++) for (size_t i = 0; i < param.vecParam68.size(); i++)
{ {
@ -1360,7 +1386,7 @@ std::string JsonData::JsonCmd_Cgi_68(Param_68 &param){
memset(updateSql,0,sizeof(updateSql)); memset(updateSql,0,sizeof(updateSql));
sprintf(whereCon, " MeasurementID = '%s' ", param.vecParam68[i].measurementID.c_str()); sprintf(whereCon, " MeasurementID = '%s' ", param.vecParam68[i].measurementID.c_str());
sprintf(updateSql, " status = '%d',statisticType = '%d', threshold = '%f'",param.vecParam68[i].status,param.vecParam68[i].statisticType,param.vecParam68[i].threshold); sprintf(updateSql, " status = '%d',statisticType = '%d', threshold = '%f'",param.vecParam68[i].status,param.vecParam68[i].statisticType,param.vecParam68[i].threshold);
sqlite_db_ctrl::instance().UpdateTableData(" t_waveUploadRule_info ", updateSql, whereCon); sqlite_db_ctrl::instance().UpdateTableData(" t_wave_upload_rule_info ", updateSql, whereCon);
} }
} }
} else if (param.mMode == 0) { } else if (param.mMode == 0) {
@ -1368,7 +1394,8 @@ std::string JsonData::JsonCmd_Cgi_68(Param_68 &param){
signalThreshold = readIntValue("config", "signalThreshold", (char *)GlobalConfig::Config_G.c_str()); signalThreshold = readIntValue("config", "signalThreshold", (char *)GlobalConfig::Config_G.c_str());
lowBatteryLevel = readIntValue("config", "lowBatteryLevel", (char *)GlobalConfig::Config_G.c_str()); lowBatteryLevel = readIntValue("config", "lowBatteryLevel", (char *)GlobalConfig::Config_G.c_str());
batteryLevelThreshold = readIntValue("config", "batteryLevelThreshold", (char *)GlobalConfig::Config_G.c_str()); batteryLevelThreshold = readIntValue("config", "batteryLevelThreshold", (char *)GlobalConfig::Config_G.c_str());
array_t arrRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(" t_waveUploadRule_info LEFT JOIN t_sensor_info ", " t_waveUploadRule_info.*,t_sensor_info.dataNodeName ", "t_waveUploadRule_info.MeasurementID = t_sensor_info.MeasurementID"); shutdownDetection = readIntValue("config", "shutdownDetection", (char *)GlobalConfig::Config_G.c_str());
array_t arrRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(" t_wave_upload_rule_info LEFT JOIN t_sensor_info ", " t_wave_upload_rule_info.*,t_sensor_info.dataNodeName ", "t_wave_upload_rule_info.MeasurementID = t_sensor_info.MeasurementID");
if (arrRes.size() > 0) { if (arrRes.size() > 0) {
for (size_t i = 0; i < arrRes.size(); i++) for (size_t i = 0; i < arrRes.size(); i++)
{ {
@ -1377,7 +1404,7 @@ std::string JsonData::JsonCmd_Cgi_68(Param_68 &param){
iTem.append(atoi(arrRes[i][2].c_str())); iTem.append(atoi(arrRes[i][2].c_str()));
iTem.append(atoi(arrRes[i][3].c_str())); iTem.append(atoi(arrRes[i][3].c_str()));
iTem.append(atof(arrRes[i][4].c_str())); iTem.append(atof(arrRes[i][4].c_str()));
iTem.append(atof(arrRes[i][5].c_str())); iTem.append(arrRes[i][5]);
dataNodeArray.append(iTem); dataNodeArray.append(iTem);
} }
} }
@ -1385,12 +1412,12 @@ std::string JsonData::JsonCmd_Cgi_68(Param_68 &param){
jsonVal["success"] = false; jsonVal["success"] = false;
jsonVal["content"].resize(0); jsonVal["content"].resize(0);
} }
}
jsonVal["content"]["lowSignal"] = lowSignal; jsonVal["content"]["lowSignal"] = lowSignal;
jsonVal["content"]["signalThreshold"] = signalThreshold; jsonVal["content"]["signalThreshold"] = signalThreshold;
jsonVal["content"]["lowBatteryLevel"] = lowBatteryLevel; jsonVal["content"]["lowBatteryLevel"] = lowBatteryLevel;
jsonVal["content"]["batteryLevelThreshold"] = batteryLevelThreshold; jsonVal["content"]["batteryLevelThreshold"] = batteryLevelThreshold;
jsonVal["content"]["shutdownDetection"] = shutdownDetection;
}
jsonVal["content"]["dataNodeArray"] = dataNodeArray; jsonVal["content"]["dataNodeArray"] = dataNodeArray;
return show_value_.write(jsonVal); return show_value_.write(jsonVal);
} }
@ -1453,8 +1480,8 @@ std::string JsonData::JsonCmd_Cgi_70(Param_70 &param){
jsonVal["success"] = true; jsonVal["success"] = true;
jsonVal["message"] = " "; jsonVal["message"] = " ";
char selectCon[256] = {0}, szTableName[100] = {0x00}, whereCon[256] = {0x00}; char selectCon[256] = {0}, szTableName[100] = {0x00}, whereCon[256] = {0x00};
sprintf(szTableName,"t_abnormal_info"); sprintf(szTableName,"t_process_info");
int rows = sqlite_db_ctrl::instance().GetTableRows(szTableName, whereCon); int rows = sqlite_db_ctrl::instance().GetTableRows(szTableName, NULL);
int packgeNo = param.mPackageFlag; int packgeNo = param.mPackageFlag;
int packgeMax = 0; int packgeMax = 0;
int packgeNum = 0; int packgeNum = 0;
@ -1515,7 +1542,7 @@ std::string JsonData::JsonCmd_Cgi_71(Param_71 &param){
jsonVal["message"] = " "; jsonVal["message"] = " ";
char selectCon[256] = {0}, szTableName[100] = {0x00}, whereCon[256] = {0x00}; char selectCon[256] = {0}, szTableName[100] = {0x00}, whereCon[256] = {0x00};
sprintf(szTableName,"t_system_info"); sprintf(szTableName,"t_system_info");
int rows = sqlite_db_ctrl::instance().GetTableRows(szTableName, whereCon); int rows = sqlite_db_ctrl::instance().GetTableRows(szTableName, NULL);
int packgeNo = param.mPackageFlag; int packgeNo = param.mPackageFlag;
int packgeMax = 0; int packgeMax = 0;
int packgeNum = 0; int packgeNum = 0;

View File

@ -408,9 +408,16 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
case kTransducerUpgrade:{ case kTransducerUpgrade:{
JsonData jd; JsonData jd;
Param_60 param; Param_60 param;
std::string type = recvBody["type"].asString();
if (0 == type.compare("UPDATE")) {
param.mMode = 0;
param.fileName = recvBody["fileName"].asString(); param.fileName = recvBody["fileName"].asString();
param.product = recvBody["product"].asInt(); param.product = recvBody["product"].asInt();
param.mShortAddr = recvBody["shortAddr"].asString(); param.mShortAddr = recvBody["shortAddr"].asString();
}
if (0 == type.compare("STOP")) {
param.mMode = 1;
}
Json::Value recvDataNodeNo = recvBody["DataNodeNo"]; Json::Value recvDataNodeNo = recvBody["DataNodeNo"];
if (recvDataNodeNo.size() > 0) if (recvDataNodeNo.size() > 0)
{ {
@ -558,6 +565,9 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
if (0 == type.compare("GET")) { if (0 == type.compare("GET")) {
param.mMode = 0; param.mMode = 0;
} }
if (0 == type.compare("STOP")) {
param.mMode = 2;
}
std::string data = jd.JsonCmd_Cgi_67(param); std::string data = jd.JsonCmd_Cgi_67(param);
return data; return data;
} }
@ -575,21 +585,22 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
param.signalThreshold = recvBody["signalThreshold"].asInt(); param.signalThreshold = recvBody["signalThreshold"].asInt();
param.lowBatteryLevel = recvBody["lowBatteryLevel"].asInt(); param.lowBatteryLevel = recvBody["lowBatteryLevel"].asInt();
param.batteryLevelThreshold = recvBody["batteryLevelThreshold"].asInt(); param.batteryLevelThreshold = recvBody["batteryLevelThreshold"].asInt();
param.shutdownDetection = recvBody["shutdownDetection"].asInt();
Json::Value recvDataNodeNo = recvBody["DataNodeNo"]; Json::Value recvDataNodeNo = recvBody["DataNodeNo"];
if (recvDataNodeNo.size() > 0) if (recvDataNodeNo.size() > 0)
{ {
for (size_t i = 0; i < recvDataNodeNo.size(); i++) { for (int i = 0; i < recvDataNodeNo.size(); ++i) {
Param_68_info vecParam; Param_68_info vecParam;
for (size_t j = 0; j < recvDataNodeNo[i].size(); j++) Json::Value node = recvDataNodeNo[i];
{
vecParam.measurementID = recvDataNodeNo[i][j].asString(); vecParam.measurementID = node[0u].asString();
vecParam.status = recvDataNodeNo[i][j].asInt(); vecParam.status = node[1u].asInt();
vecParam.statisticType = recvDataNodeNo[i][j].asInt(); vecParam.statisticType = node[2u].asInt();
vecParam.threshold = recvDataNodeNo[i][j].asDouble(); vecParam.threshold = node[3u].asDouble();
}
param.vecParam68.push_back(vecParam); param.vecParam68.push_back(vecParam);
} }
} }
std::string data = jd.JsonCmd_Cgi_68(param); std::string data = jd.JsonCmd_Cgi_68(param);
return data; return data;
}break; }break;
@ -624,6 +635,8 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
case KProcessLog:{ case KProcessLog:{
JsonData jd; JsonData jd;
Param_70 param; Param_70 param;
param.timeStart = recvBody["timeStart"].asString();
param.timeEnd = recvBody["timeEnd"].asString();
param.mPackageFlag = recvBody["package"].asInt(); param.mPackageFlag = recvBody["package"].asInt();
std::string data = jd.JsonCmd_Cgi_70(param); std::string data = jd.JsonCmd_Cgi_70(param);
return data; return data;
@ -634,6 +647,8 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
case kGetSensorInfo:{ case kGetSensorInfo:{
JsonData jd; JsonData jd;
Param_71 param; Param_71 param;
param.timeStart = recvBody["timeStart"].asString();
param.timeEnd = recvBody["timeEnd"].asString();
param.mPackageFlag = recvBody["package"].asInt(); param.mPackageFlag = recvBody["package"].asInt();
std::string data = jd.JsonCmd_Cgi_71(param); std::string data = jd.JsonCmd_Cgi_71(param);
return data; return data;

View File

@ -18,7 +18,7 @@ extern zlog_category_t *zbt;
uint8_t g_x, g_y, g_z; uint8_t g_x, g_y, g_z;
int SensorScheduler::StartSchedule(uint16_t short_addr, int &next_duration, bool &z) { int SensorScheduler::StartSchedule(uint16_t short_addr, int &next_duration, bool &z, int &next_task_id) {
int id = 0; int id = 0;
auto iter = short_addr_map_.find(short_addr); auto iter = short_addr_map_.find(short_addr);
if (iter == short_addr_map_.end()) { if (iter == short_addr_map_.end()) {
@ -60,21 +60,22 @@ int SensorScheduler::StartSchedule(uint16_t short_addr, int &next_duration, bool
return kScheduleConfigSensor; return kScheduleConfigSensor;
} else { } else {
wave_feature_set_inst::instance().GetFeatureCfg(short_addr, g_x, g_y, g_z); wave_feature_set_inst::instance().GetFeatureCfg(short_addr, g_x, g_y, g_z);
if (g_x || g_y || g_z) { // if (g_x || g_y || g_z) {
// 执行上送特征值任务 // // 执行上送特征值任务
zlog_debug(zbt, "[%d:%x] send eigen value in eigen slice", id, short_addr); // zlog_debug(zbt, "[%d:%x] send eigen value in eigen slice", id, short_addr);
current_request_ = kScheduleEigenValue; // current_request_ = kScheduleEigenValue;
return kScheduleEigenValue; // return kScheduleEigenValue;
} else { // } else {
next_duration = GetNextDuration(short_addr); next_duration = GetNextDuration(short_addr, z, next_task_id);
zlog_warn(zbt, "[%d:%x] no need for eigen", id, short_addr); zlog_warn(zbt, "[%d:%x] no need for eigen", id, short_addr);
return kScheduleWrongTime; return kScheduleResultNone;
} // }
} }
} else { } else {
if (current_schedule_status_ == kScheduleStatusDebug) { if (current_schedule_status_ == kScheduleStatusDebug) {
if (debug_list_.count(short_addr) == 0) { if (debug_list_.count(short_addr) == 0) {
next_duration = GetDebugUpgradeNextDuration(short_addr); next_duration = GetDebugUpgradeNextDuration(short_addr);
next_task_id = kScheduleEigenValue;
zlog_debug(zbt, "[%d:%x] not in debug list", id, short_addr); zlog_debug(zbt, "[%d:%x] not in debug list", id, short_addr);
return kScheduleWrongTime; return kScheduleWrongTime;
} else { } else {
@ -97,11 +98,14 @@ int SensorScheduler::StartSchedule(uint16_t short_addr, int &next_duration, bool
zlog_debug(zbt, "[%d:%x] [Nxt] debug exception duration:%d, adjust to 120", id, short_addr); zlog_debug(zbt, "[%d:%x] [Nxt] debug exception duration:%d, adjust to 120", id, short_addr);
next_duration = 120; next_duration = 120;
} }
z = true;
next_task_id = kScheduleWaveForm;
return kScheduleWrongTime; return kScheduleWrongTime;
} }
} }
next_duration = GetDebugUpgradeNextDuration(short_addr); next_duration = GetDebugUpgradeNextDuration(short_addr);
next_task_id = kScheduleEigenValue;
zlog_debug(zbt, "[%d:%x] debug wrong time", id, short_addr); zlog_debug(zbt, "[%d:%x] debug wrong time", id, short_addr);
return kScheduleWrongTime; return kScheduleWrongTime;
} }
@ -110,16 +114,18 @@ int SensorScheduler::StartSchedule(uint16_t short_addr, int &next_duration, bool
} else if (current_schedule_status_ == kScheduleStatusUpgrade) { } else if (current_schedule_status_ == kScheduleStatusUpgrade) {
if (upgrade_list_.count(short_addr) == 0) { if (upgrade_list_.count(short_addr) == 0) {
next_duration = GetDebugUpgradeNextDuration(short_addr); next_duration = GetDebugUpgradeNextDuration(short_addr);
next_task_id = kScheduleEigenValue;
zlog_debug(zbt, "[%d:%x] not in upgrade list", id, short_addr); zlog_debug(zbt, "[%d:%x] not in upgrade list", id, short_addr);
return kScheduleWrongTime; return kScheduleWrongTime;
} else { } else {
int nth_wave_slice = nth_eigen_value_slice_ * wave_slice_num_per_eigen_interval_ + nth_wave_slice_ + 1; int nth_wave_slice = nth_eigen_value_slice_ * wave_slice_num_per_eigen_interval_ + nth_wave_slice_ + 1;
if (upgrade_slice_sensor_id_[nth_wave_slice] == short_addr) { if (upgrade_slice_sensor_id_[nth_wave_slice] == short_addr) {
current_request_ = kScheduleUpgrade; current_request_ = kScheduleUpgrade;
upgrade_list_.erase(short_addr); // upgrade_list_.erase(short_addr);
return kScheduleUpgrade; return kScheduleUpgrade;
} else { } else {
next_duration = GetDebugUpgradeNextDuration(short_addr); next_duration = GetDebugUpgradeNextDuration(short_addr);
next_task_id = kScheduleEigenValue;
zlog_debug(zbt, "[%d:%x] in wrong time", id, short_addr); zlog_debug(zbt, "[%d:%x] in wrong time", id, short_addr);
return kScheduleWrongTime; return kScheduleWrongTime;
} }
@ -140,7 +146,7 @@ int SensorScheduler::StartSchedule(uint16_t short_addr, int &next_duration, bool
z = true; z = true;
return kScheduleWaveForm; return kScheduleWaveForm;
} else { } else {
next_duration = GetNextDuration(short_addr); next_duration = GetNextDuration(short_addr, z, next_task_id);
zlog_debug(zbt, "[%d:%x] no need for wave", id, short_addr); zlog_debug(zbt, "[%d:%x] no need for wave", id, short_addr);
return kScheduleWrongTime; return kScheduleWrongTime;
} }
@ -151,7 +157,7 @@ int SensorScheduler::StartSchedule(uint16_t short_addr, int &next_duration, bool
z = false; z = false;
return kScheduleWaveForm; return kScheduleWaveForm;
} else { } else {
next_duration = GetNextDuration(short_addr); next_duration = GetNextDuration(short_addr, z, next_task_id);
zlog_debug(zbt, "[%d:%x] no need for wave", id, short_addr); zlog_debug(zbt, "[%d:%x] no need for wave", id, short_addr);
return kScheduleWrongTime; return kScheduleWrongTime;
} }
@ -194,16 +200,19 @@ int SensorScheduler::StartSchedule(uint16_t short_addr, int &next_duration, bool
zlog_debug(zbt, "[%d:%x] invalid next duration:%d, adjust to 120", id, short_addr, next_duration); zlog_debug(zbt, "[%d:%x] invalid next duration:%d, adjust to 120", id, short_addr, next_duration);
next_duration = 120; next_duration = 120;
} }
next_task_id = kScheduleEigenValue;
zlog_debug(zbt, "[%d:%x] wrong time in wave slice, next feature send utc time:[%s], duration:%d", id, short_addr, GetUTCTime(available_ts).c_str(), next_duration); zlog_debug(zbt, "[%d:%x] wrong time in wave slice, next feature send utc time:[%s], duration:%d", id, short_addr, GetUTCTime(available_ts).c_str(), next_duration);
return kScheduleWrongTime; return kScheduleWrongTime;
} }
} }
} }
long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) { long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr, bool &z, int& next_task_id) {
z = false;
if (ts_in_eigen_slice_) { if (ts_in_eigen_slice_) {
if (current_schedule_status_ == kScheduleStatusDebug) { if (current_schedule_status_ == kScheduleStatusDebug) {
if (debug_list_.count(short_addr) == 0) { if (debug_list_.count(short_addr) == 0) {
next_task_id = kScheduleEigenValue;
return GetDebugUpgradeNextTS(short_addr); return GetDebugUpgradeNextTS(short_addr);
} else { } else {
// 计算发送波形是否在后面的波形时间窗口中 // 计算发送波形是否在后面的波形时间窗口中
@ -211,14 +220,17 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) {
for (int i = nth_wave_slice; i <= nth_wave_slice + wave_slice_num_per_eigen_interval_; ++i) { for (int i = nth_wave_slice; i <= nth_wave_slice + wave_slice_num_per_eigen_interval_; ++i) {
if (debug_slice_sensor_id_[i] == short_addr) { if (debug_slice_sensor_id_[i] == short_addr) {
long nxt_ts = current_wave_start_ts_ + nth_eigen_value_slice_ * eigen_value_send_interval_ + 60 + (i-nth_wave_slice)*60; long nxt_ts = current_wave_start_ts_ + nth_eigen_value_slice_ * eigen_value_send_interval_ + 60 + (i-nth_wave_slice)*60;
next_task_id = kScheduleWaveForm;
z = true;
return nxt_ts; return nxt_ts;
} }
} }
next_task_id = kScheduleEigenValue;
return GetDebugUpgradeNextTS(short_addr); return GetDebugUpgradeNextTS(short_addr);
} }
} else if (current_schedule_status_ == kScheduleStatusUpgrade) { } else if (current_schedule_status_ == kScheduleStatusUpgrade) {
if (upgrade_list_.count(short_addr) == 0) { if (upgrade_list_.count(short_addr) == 0) {
next_task_id = kScheduleEigenValue;
return GetDebugUpgradeNextTS(short_addr); return GetDebugUpgradeNextTS(short_addr);
} else { } else {
// 计算升级是否在后面的波形时间窗口中 // 计算升级是否在后面的波形时间窗口中
@ -226,9 +238,11 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) {
for (int i = nth_wave_slice; i <= nth_wave_slice + wave_slice_num_per_eigen_interval_; ++i) { for (int i = nth_wave_slice; i <= nth_wave_slice + wave_slice_num_per_eigen_interval_; ++i) {
if (upgrade_slice_sensor_id_[i] == short_addr) { if (upgrade_slice_sensor_id_[i] == short_addr) {
long nxt_ts = current_wave_start_ts_ + nth_eigen_value_slice_ * eigen_value_send_interval_ + 60 + (i-nth_wave_slice)*60; long nxt_ts = current_wave_start_ts_ + nth_eigen_value_slice_ * eigen_value_send_interval_ + 60 + (i-nth_wave_slice)*60;
next_task_id = kScheduleUpgrade;
return nxt_ts; return nxt_ts;
} }
} }
next_task_id = kScheduleEigenValue;
return GetDebugUpgradeNextTS(short_addr); return GetDebugUpgradeNextTS(short_addr);
} }
} }
@ -244,6 +258,7 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) {
int second_wave_slice = wave_slice_iter->second.second; int second_wave_slice = wave_slice_iter->second.second;
long send_wave_ts = 0; long send_wave_ts = 0;
long available_ts = 0; long available_ts = 0;
next_task_id = kScheduleWaveForm;
wave_feature_set_inst::instance().GetWaveCfg(short_addr, g_x, g_y, g_z); wave_feature_set_inst::instance().GetWaveCfg(short_addr, g_x, g_y, g_z);
if (g_x || g_y || g_z) { if (g_x || g_y || g_z) {
if (g_z && first_wave_slice > forward_wave_slice_num && if (g_z && first_wave_slice > forward_wave_slice_num &&
@ -253,6 +268,8 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) {
if (first_wave_slice == i) { if (first_wave_slice == i) {
send_wave_ts = current_wave_start_ts_ + nth_eigen_value_slice_ * eigen_value_send_interval_ + 60 + (i - forward_wave_slice_num - 1) * 60; send_wave_ts = current_wave_start_ts_ + nth_eigen_value_slice_ * eigen_value_send_interval_ + 60 + (i - forward_wave_slice_num - 1) * 60;
zlog_debug(zbt, "[Nxt] [%d:%x] send wave time:[%s]", id, short_addr, GetUTCTime(send_wave_ts).c_str()); zlog_debug(zbt, "[Nxt] [%d:%x] send wave time:[%s]", id, short_addr, GetUTCTime(send_wave_ts).c_str());
next_task_id = kScheduleWaveForm;
z = true;
break; break;
} }
} }
@ -263,6 +280,8 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) {
if (second_wave_slice == i) { if (second_wave_slice == i) {
send_wave_ts = current_wave_start_ts_ + nth_eigen_value_slice_ * eigen_value_send_interval_ + 60 + (i - forward_wave_slice_num - 1) * 60; send_wave_ts = current_wave_start_ts_ + nth_eigen_value_slice_ * eigen_value_send_interval_ + 60 + (i - forward_wave_slice_num - 1) * 60;
zlog_debug(zbt, "[Nxt] [%d:%x] send wave time:[%s]", id, short_addr, GetUTCTime(send_wave_ts).c_str()); zlog_debug(zbt, "[Nxt] [%d:%x] send wave time:[%s]", id, short_addr, GetUTCTime(send_wave_ts).c_str());
next_task_id = kScheduleWaveForm;
z = false;
break; break;
} }
} }
@ -277,6 +296,7 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) {
if (z_success_set_.count(short_addr) == 0 && !ZRetransferWave(short_addr)) { if (z_success_set_.count(short_addr) == 0 && !ZRetransferWave(short_addr)) {
zlog_debug(zbt, "[Nxt] [%d:%x] add z to patch set", id, short_addr); zlog_debug(zbt, "[Nxt] [%d:%x] add z to patch set", id, short_addr);
z_patch_set_.insert(short_addr); z_patch_set_.insert(short_addr);
z = true;
} }
} }
} }
@ -289,6 +309,7 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) {
if (xy_success_set_.count(short_addr) == 0 && !XYRetransferWave(short_addr)) { if (xy_success_set_.count(short_addr) == 0 && !XYRetransferWave(short_addr)) {
zlog_debug(zbt, "[Nxt] [%d:%x] add xy to patch set", id, short_addr); zlog_debug(zbt, "[Nxt] [%d:%x] add xy to patch set", id, short_addr);
xy_patch_set_.insert(short_addr); xy_patch_set_.insert(short_addr);
z = false;
} }
} }
} }
@ -302,6 +323,11 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) {
if (free_slice_ocuppied_.count(current_wave_slice_ts) == 0) { if (free_slice_ocuppied_.count(current_wave_slice_ts) == 0) {
available_ts = current_wave_slice_ts; available_ts = current_wave_slice_ts;
free_slice_ocuppied_.insert(available_ts); free_slice_ocuppied_.insert(available_ts);
if (ZRetransferWave(short_addr) || ZMissedWave(short_addr)) {
z = true;
} else {
z = false;
}
zlog_debug(zbt, "[Nxt][%d:%x] %d nth free wave slice will be used to retransfer or patch wave, utc time:[%s]", id, short_addr, i+forward_wave_slice_num, GetUTCTime(available_ts).c_str()); zlog_debug(zbt, "[Nxt][%d:%x] %d nth free wave slice will be used to retransfer or patch wave, utc time:[%s]", id, short_addr, i+forward_wave_slice_num, GetUTCTime(available_ts).c_str());
break; break;
} }
@ -323,6 +349,7 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) {
} else { } else {
if (current_schedule_status_ == kScheduleStatusDebug) { if (current_schedule_status_ == kScheduleStatusDebug) {
if (debug_list_.count(short_addr) == 0) { if (debug_list_.count(short_addr) == 0) {
next_task_id = kScheduleEigenValue;
return GetDebugUpgradeNextTS(short_addr); return GetDebugUpgradeNextTS(short_addr);
} else { } else {
// 计算发送波形是否在后面的波形时间窗口中 // 计算发送波形是否在后面的波形时间窗口中
@ -330,17 +357,29 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) {
for (int i = nth_wave_slice; i <= nth_wave_slice + wave_slice_num_per_eigen_interval_; ++i) { for (int i = nth_wave_slice; i <= nth_wave_slice + wave_slice_num_per_eigen_interval_; ++i) {
if (debug_slice_sensor_id_[i] == short_addr) { if (debug_slice_sensor_id_[i] == short_addr) {
long nxt_ts = current_wave_start_ts_ + nth_eigen_value_slice_ * eigen_value_send_interval_ + 60 + (i-nth_eigen_value_slice_ * wave_slice_num_per_eigen_interval_-1)*60; long nxt_ts = current_wave_start_ts_ + nth_eigen_value_slice_ * eigen_value_send_interval_ + 60 + (i-nth_eigen_value_slice_ * wave_slice_num_per_eigen_interval_-1)*60;
next_task_id = kScheduleWaveForm;
z = true;
return nxt_ts; return nxt_ts;
} }
} }
next_task_id = kScheduleEigenValue;
return GetDebugUpgradeNextTS(short_addr); return GetDebugUpgradeNextTS(short_addr);
} }
} else if (current_schedule_status_ == kScheduleStatusUpgrade) { } else if (current_schedule_status_ == kScheduleStatusUpgrade) {
if (upgrade_list_.count(short_addr) == 0) { if (upgrade_list_.count(short_addr) == 0) {
next_task_id = kScheduleEigenValue;
return GetDebugUpgradeNextDuration(short_addr); return GetDebugUpgradeNextDuration(short_addr);
} else { } else {
// 计算升级是否在后面的波形时间窗口中 // 计算升级是否在后面的波形时间窗口中
int nth_wave_slice = nth_eigen_value_slice_ * wave_slice_num_per_eigen_interval_ + 2;
for (int i = nth_wave_slice; i <= nth_wave_slice + wave_slice_num_per_eigen_interval_; ++i) {
if (upgrade_slice_sensor_id_[i] == short_addr) {
long nxt_ts = current_wave_start_ts_ + nth_eigen_value_slice_ * eigen_value_send_interval_ + 60 + (i-nth_eigen_value_slice_ * wave_slice_num_per_eigen_interval_-1)*60;
next_task_id = kScheduleUpgrade;
return nxt_ts;
}
}
next_task_id = kScheduleEigenValue;
} }
} }
} }
@ -350,22 +389,24 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) {
if (eigen_send_ts > 57) { if (eigen_send_ts > 57) {
eigen_send_ts = eigen_send_ts % 57; eigen_send_ts = eigen_send_ts % 57;
} }
next_task_id = kScheduleEigenValue;
long available_ts = current_wave_start_ts_ + (nth_eigen_value_slice_ + 1)* eigen_value_send_interval_ + eigen_send_ts; long available_ts = current_wave_start_ts_ + (nth_eigen_value_slice_ + 1)* eigen_value_send_interval_ + eigen_send_ts;
zlog_debug(zbt, "[Nxt] [%d:%x] next feature send utc time3:[%s]", id, short_addr, GetUTCTime(available_ts).c_str()); zlog_debug(zbt, "[Nxt] [%d:%x] next feature send utc time3:[%s]", id, short_addr, GetUTCTime(available_ts).c_str());
return available_ts; return available_ts;
} }
int SensorScheduler::GetNextDuration(uint16_t short_addr) { int SensorScheduler::GetNextDuration(uint16_t short_addr, bool &z, int &next_task_id) {
int id = 0; int id = 0;
auto iter = short_addr_map_.find(short_addr); auto iter = short_addr_map_.find(short_addr);
if (iter == short_addr_map_.end()) { if (iter == short_addr_map_.end()) {
zlog_error(zbt, "cannot find id for short_addr %x", short_addr); zlog_error(zbt, "cannot find id for short_addr %x", short_addr);
next_task_id = kScheduleEigenValue;
return 0; return 0;
} else { } else {
id = iter->second; id = iter->second;
} }
long current_ts = GetLocalTs(); long current_ts = GetLocalTs();
long next_ts = CalcNextTimestamp(id, short_addr); long next_ts = CalcNextTimestamp(id, short_addr, z, next_task_id);
int duration = next_ts - current_ts; int duration = next_ts - current_ts;
if (duration < 10) { if (duration < 10) {
zlog_debug(zbt, "[%d:%x] [Nxt] exception duration:%d, adjust to 25", id, short_addr); zlog_debug(zbt, "[%d:%x] [Nxt] exception duration:%d, adjust to 25", id, short_addr);

View File

@ -53,14 +53,14 @@ public:
// kScheduleEigenValue kScheduleWaveForm // kScheduleEigenValue kScheduleWaveForm
// 上面4个结束调GetNextDuration()获取休眠时间 // 上面4个结束调GetNextDuration()获取休眠时间
// 如果是kScheduleWrongTime, 此函数next_duration表明休眠时间 // 如果是kScheduleWrongTime, 此函数next_duration表明休眠时间
int StartSchedule(uint16_t short_addr, int &next_duration, bool &z); int StartSchedule(uint16_t short_addr, int &next_duration, bool &z, int &next_task_id);
int GetNextDuration(uint16_t short_addr); int GetNextDuration(uint16_t short_addr, bool &z, int &next_task_id);
// z用于说明是z轴波形还是xy轴波形 // z用于说明是z轴波形还是xy轴波形
int WaveError(uint16_t short_addr, bool z); int WaveError(uint16_t short_addr, bool z);
void WaveSuccess(uint16_t short_addr, bool z); void WaveSuccess(uint16_t short_addr, bool z);
// long GetBaseTimestamp(int id); // long GetBaseTimestamp(int id);
long CalcNextTimestamp(int id, uint16_t short_addr); long CalcNextTimestamp(int id, uint16_t short_addr, bool &z, int& next_task_id);
// 当有传感器需要更新配置时调用 // 当有传感器需要更新配置时调用
int UpdateSensorConfig(uint16_t short_addr); int UpdateSensorConfig(uint16_t short_addr);

View File

@ -4,41 +4,36 @@
#include <chrono> #include <chrono>
#include <string> #include <string>
#include <json/json.h> #include <json/json.h>
#include <json/reader.h>
#include <ctime> #include <ctime>
#include <iomanip> #include <iomanip>
#include <zlog.h> #include <zlog.h>
extern zlog_category_t *zct; extern zlog_category_t *zbt;
ScheduleStatus get_schedule_status() { ScheduleStatus get_schedule_status() {
// std::ifstream status_file("/opt/configenv/status.json"); std::ifstream status_file("/opt/configenv/status.json");
// Json::Value json_data; if (!status_file.good()) {
// Json::CharReaderBuilder reader; zlog_info(zbt, "[ShortAddrCfg] no file /opt/configenv/status.json");
// std::string errs; return kScheduleStatusNormal;
}
Json::Value json_data;
Json::Reader reader;
// if (status_file.is_open()) { if (reader.parse(status_file, json_data, false)) {
// if (Json::parseFromStream(reader, status_file, &json_data, &errs)) { std::string status = json_data["status"].asString();
// std::string status = json_data["status"].asString();
// if (status == "debug") {
// status_file.close();
// return kScheduleStatusDebug;
// } else if (status == "normal") {
// status_file.close();
// return kScheduleStatusNormal;
// } else if (status == "upgrade") {
// status_file.close();
// return kScheduleStatusUpgrade;
// }
// } else {
// std::cerr << "Failed to parse JSON: " << errs << std::endl;
// }
// status_file.close();
// } else {
// std::cerr << "Unable to open status.json" << std::endl;
// }
if (status == "debug") {
status_file.close();
return kScheduleStatusDebug;
} else if (status == "normal") {
status_file.close();
return kScheduleStatusNormal;
} else if (status == "upgrade") {
status_file.close();
return kScheduleStatusUpgrade;
}
}
status_file.close();
return kScheduleStatusNormal; return kScheduleStatusNormal;
} }
@ -70,13 +65,12 @@ void set_schedule_status(ScheduleStatus status) {
// Append to status_history.json // Append to status_history.json
Json::Value history_data; Json::Value history_data;
// std::ifstream history_file("/opt/configenv/status_history.json"); std::ifstream history_file("/opt/configenv/status_history.json");
// if (history_file.is_open()) { if (history_file.good()) {
// if (Json::parseFromStream(Json::CharReaderBuilder(), history_file, &history_data, nullptr)) { Json::Reader reader;
// // successfully read existing history reader.parse(history_file, history_data, false);
// } history_file.close();
// history_file.close(); }
// }
// Get the current time // Get the current time
auto now = std::chrono::system_clock::now(); auto now = std::chrono::system_clock::now();
@ -117,7 +111,7 @@ std::string get_status_desc(ScheduleStatus status) {
break; break;
default: default:
status_str = "normal"; status_str = "normal";
zlog_error(zct, "fail to get status desc:%d", status); zlog_error(zbt, "fail to get status desc:%d", status);
break; break;
} }
return status_str; return status_str;

View File

@ -378,7 +378,7 @@ int Uart::DealAskTask(uint16_t ushortAdd){
int taskID; int taskID;
ScheduleTask scheduleTask; ScheduleTask scheduleTask;
bool z = false; bool z = false;
taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration, z); taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration,z, next_task_id);
zlog_info(zct, "taskID = %d next_duration = %d next_task_id = %d", taskID, next_duration, next_task_id); zlog_info(zct, "taskID = %d next_duration = %d next_task_id = %d", taskID, next_duration, next_task_id);
if (taskID == kScheduleConfigSensor) if (taskID == kScheduleConfigSensor)
{ {
@ -449,7 +449,8 @@ int Uart::DealReviveDuration(uint16_t ushortAdd){
ScheduleTask scheduleTask; ScheduleTask scheduleTask;
int next_taskID = 0; int next_taskID = 0;
uint16_t next_duration = scheduler::instance().GetNextDuration(ushortAdd); bool z = false;
uint16_t next_duration = scheduler::instance().GetNextDuration(ushortAdd,z,next_taskID);
zlog_info(zct, "next_duration = %d next_taskID = %d", next_duration,next_taskID); zlog_info(zct, "next_duration = %d next_taskID = %d", next_duration,next_taskID);
scheduleTask.cmd = REVIVE_DURATION; scheduleTask.cmd = REVIVE_DURATION;
scheduleTask.shortAddr = ushortAdd; scheduleTask.shortAddr = ushortAdd;
@ -474,10 +475,24 @@ int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){
zlog_info(zct, "DealWaveCompress "); zlog_info(zct, "DealWaveCompress ");
now_task = WAVE_CMD; now_task = WAVE_CMD;
WaveResp(ushortAdd); WaveResp(ushortAdd);
char buf[20] = {0x00}; char buf[20] = {0x00},whereCon[100] = {0};
char sensor_rssi[10] = {0x00};
sprintf(buf, "%02x%02x", (ushortAdd >> 8) & 0xFF, ushortAdd & 0xFF); sprintf(buf, "%02x%02x", (ushortAdd >> 8) & 0xFF, ushortAdd & 0xFF);
std::string strShortAddr = std::string(buf); std::string strShortAddr = std::string(buf);
sprintf(whereCon,"zigbeeShortAddr = '%s' ",buf);
std::string softVersion = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), "softVersion", whereCon);
compressWaveChannel tempchannel; compressWaveChannel tempchannel;
if (compareVersions(softVersion, "2.6")){
tempchannel.compressChannelX = pData[7];
tempchannel.compressChannelY = pData[8];
tempchannel.compressChannelZ = pData[9];
tempchannel.CountX = BUILD_UINT32(pData[13], pData[12],pData[11],pData[10]);
tempchannel.CountY = BUILD_UINT32(pData[17], pData[16],pData[15],pData[14]);
tempchannel.CountZ = BUILD_UINT32(pData[21], pData[20],pData[19],pData[18]);
sprintf(sensor_rssi, "%02d", pData[22] & 0xFF);
}else{
sprintf(sensor_rssi, "%02d", pData[7] & 0xFF);
tempchannel.compressChannelX = pData[8]; tempchannel.compressChannelX = pData[8];
tempchannel.compressChannelY = pData[9]; tempchannel.compressChannelY = pData[9];
tempchannel.compressChannelZ = pData[10]; tempchannel.compressChannelZ = pData[10];
@ -498,11 +513,12 @@ int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){
tempchannel.samplerateVolX = BUILD_UINT32(pData[53], pData[52],pData[51],pData[50]); tempchannel.samplerateVolX = BUILD_UINT32(pData[53], pData[52],pData[51],pData[50]);
tempchannel.samplerateVolY = BUILD_UINT32(pData[57], pData[56],pData[55],pData[54]); tempchannel.samplerateVolY = BUILD_UINT32(pData[57], pData[56],pData[55],pData[54]);
tempchannel.samplerateVolZ = BUILD_UINT32(pData[61], pData[60],pData[59],pData[58]); tempchannel.samplerateVolZ = BUILD_UINT32(pData[61], pData[60],pData[59],pData[58]);
}
g_mapCompress[strShortAddr] = tempchannel; g_mapCompress[strShortAddr] = tempchannel;
wave_shortAddr = ushortAdd; wave_shortAddr = ushortAdd;
char sensor_rssi[10] = {0x00};
sprintf(sensor_rssi, "%02d", pData[7] & 0xFF);
if (!strcmp(sensor_rssi, "00") || !strcmp(sensor_rssi, "0")) { if (!strcmp(sensor_rssi, "00") || !strcmp(sensor_rssi, "0")) {
char errorInfo[100] = {0x00}; char errorInfo[100] = {0x00};
sprintf(errorInfo, "No RSSI %s", sensor_rssi); sprintf(errorInfo, "No RSSI %s", sensor_rssi);
@ -641,7 +657,7 @@ int Uart::DealAskTaskOld(uint16_t ushortAdd){
int taskID; int taskID;
ScheduleTask scheduleTask; ScheduleTask scheduleTask;
bool z = false; bool z = false;
taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration, z); taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration,z, next_task_id);
zlog_info(zct, "DealAskTaskOld taskID = %d next_duration = %d next_task_id = %d", taskID, next_duration, next_task_id); zlog_info(zct, "DealAskTaskOld taskID = %d next_duration = %d next_task_id = %d", taskID, next_duration, next_task_id);
if(next_task_id == kScheduleUpgrade){ if(next_task_id == kScheduleUpgrade){
scheduleTask.cmd = REVIVE_DURATION; scheduleTask.cmd = REVIVE_DURATION;
@ -733,7 +749,7 @@ void Uart::DealRecvData(const char *pData) {
break; break;
case UPGRADE_ASK: case UPGRADE_ASK:
mssleep(50000); mssleep(50000);
taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration, z); taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration,z, next_task_id);
taskID = kScheduleUpgrade; taskID = kScheduleUpgrade;
if (taskID == kScheduleUpgrade){ if (taskID == kScheduleUpgrade){
UpdateWirelessNode(ushortAdd); UpdateWirelessNode(ushortAdd);