modify web code , new scheduler
This commit is contained in:
parent
7fc05f4818
commit
5d05252454
@ -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{
|
||||||
|
|||||||
@ -643,123 +643,127 @@ std::string JsonData::JsonCmd_Cgi_60(Param_60 ¶m){
|
|||||||
jsonVal[JSON_FIELD_CMD] = "60";
|
jsonVal[JSON_FIELD_CMD] = "60";
|
||||||
jsonVal["success"] = true;
|
jsonVal["success"] = true;
|
||||||
jsonVal["message"] = "";
|
jsonVal["message"] = "";
|
||||||
char file_path[64]={0};
|
if(param.mMode == 0){
|
||||||
char cmd[128]={0};
|
char file_path[64]={0};
|
||||||
sprintf(cmd, "mv /opt/%s /opt/DataNode/",param.fileName.c_str());
|
char cmd[128]={0};
|
||||||
system(cmd);
|
sprintf(cmd, "mv /opt/%s /opt/DataNode/",param.fileName.c_str());
|
||||||
sprintf(file_path, "/opt/DataNode/%s",param.fileName.c_str());
|
system(cmd);
|
||||||
zlog_info(zct,"file_path = %s",file_path);
|
sprintf(file_path, "/opt/DataNode/%s",param.fileName.c_str());
|
||||||
FILE * pFile=NULL;
|
zlog_info(zct,"file_path = %s",file_path);
|
||||||
size_t thisSize = 0;
|
FILE * pFile=NULL;
|
||||||
char *buffer=NULL;
|
size_t thisSize = 0;
|
||||||
pFile = fopen (file_path,"rb");
|
char *buffer=NULL;
|
||||||
if (pFile==NULL) {
|
pFile = fopen (file_path,"rb");
|
||||||
zlog_error(zct,"Error opening file");
|
if (pFile==NULL) {
|
||||||
jsonVal["success"] = false;
|
zlog_error(zct,"Error opening file");
|
||||||
jsonVal["message"] = "Error opening file";
|
|
||||||
return show_value_.write(jsonVal);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
while (fgetc(pFile) != EOF) {
|
|
||||||
++thisSize;
|
|
||||||
}
|
|
||||||
rewind(pFile);
|
|
||||||
buffer = (char*)malloc(thisSize);
|
|
||||||
fread (buffer, sizeof (char), thisSize, pFile);
|
|
||||||
fclose (pFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
zlog_info(zct,"Read %zu bytes", thisSize);
|
|
||||||
char sensor_type[6] = {0};
|
|
||||||
char sf_version[10] = {0};
|
|
||||||
memcpy(sensor_type, buffer, 5);
|
|
||||||
zlog_info(zct,"model:%s", sensor_type);
|
|
||||||
if (param.product == 1 ){
|
|
||||||
if (strcmp(sensor_type,"DN101") != 0){
|
|
||||||
jsonVal["success"] = false;
|
jsonVal["success"] = false;
|
||||||
jsonVal["message"] = "product error";
|
jsonVal["message"] = "Error opening file";
|
||||||
|
return show_value_.write(jsonVal);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (fgetc(pFile) != EOF) {
|
||||||
|
++thisSize;
|
||||||
|
}
|
||||||
|
rewind(pFile);
|
||||||
|
buffer = (char*)malloc(thisSize);
|
||||||
|
fread (buffer, sizeof (char), thisSize, pFile);
|
||||||
|
fclose (pFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
zlog_info(zct,"Read %zu bytes", thisSize);
|
||||||
|
char sensor_type[6] = {0};
|
||||||
|
char sf_version[10] = {0};
|
||||||
|
memcpy(sensor_type, buffer, 5);
|
||||||
|
zlog_info(zct,"model:%s", sensor_type);
|
||||||
|
if (param.product == 1 ){
|
||||||
|
if (strcmp(sensor_type,"DN101") != 0){
|
||||||
|
jsonVal["success"] = false;
|
||||||
|
jsonVal["message"] = "product error";
|
||||||
|
free(buffer);
|
||||||
|
return show_value_.write(jsonVal);
|
||||||
|
}
|
||||||
|
}else if(param.product == 2){
|
||||||
|
if (strcmp(sensor_type,"DN102") != 0){
|
||||||
|
jsonVal["success"] = false;
|
||||||
|
jsonVal["message"] = "product error";
|
||||||
|
free(buffer);
|
||||||
|
return show_value_.write(jsonVal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char c[2] = {0};
|
||||||
|
c[0] = buffer[5];
|
||||||
|
uint8_t hw_ver = atoi(c);
|
||||||
|
c[0] = buffer[6];
|
||||||
|
uint8_t sf_ver_m = atoi(c);
|
||||||
|
c[0] = buffer[7];
|
||||||
|
uint8_t sf_ver_s = atoi(c);
|
||||||
|
sprintf(sf_version,"%d.%d",sf_ver_m,sf_ver_s);
|
||||||
|
unsigned char ch_crc = 0x00;
|
||||||
|
int packgeSize = 0;
|
||||||
|
ch_crc = buffer[12];
|
||||||
|
packgeSize = BUILD_UINT32(buffer[8],buffer[9],buffer[10],buffer[11]);
|
||||||
|
zlog_info(zct,"sf_ver_m = %d",sf_ver_m);
|
||||||
|
zlog_info(zct,"sf_ver_s = %d",sf_ver_s);
|
||||||
|
zlog_info(zct,"hw_ver = %d",hw_ver);
|
||||||
|
zlog_info(zct,"sensor_type = %s",sensor_type);
|
||||||
|
zlog_info(zct,"packgeSize = %d",packgeSize);
|
||||||
|
zlog_info(zct,"ch_crc = %02x",ch_crc);
|
||||||
|
unsigned char sum = 0x00;
|
||||||
|
for(size_t i = 13; i < thisSize;i++){
|
||||||
|
sum += buffer[i];
|
||||||
|
}
|
||||||
|
if (sum % 256 != ch_crc)
|
||||||
|
{
|
||||||
|
jsonVal["success"] = false;
|
||||||
|
jsonVal["message"] = "package CRC error";
|
||||||
free(buffer);
|
free(buffer);
|
||||||
return show_value_.write(jsonVal);
|
return show_value_.write(jsonVal);
|
||||||
}
|
}
|
||||||
}else if(param.product == 2){
|
|
||||||
if (strcmp(sensor_type,"DN102") != 0){
|
|
||||||
jsonVal["success"] = false;
|
|
||||||
jsonVal["message"] = "product error";
|
|
||||||
free(buffer);
|
|
||||||
return show_value_.write(jsonVal);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char c[2] = {0};
|
zlog_info(zct,"sum = %x\n",sum % 256);
|
||||||
c[0] = buffer[5];
|
char localtimestamp[32] = {0};
|
||||||
uint8_t hw_ver = atoi(c);
|
GetTimeNet(localtimestamp, 1);
|
||||||
c[0] = buffer[6];
|
std::vector<UpgradeParameter> param_list;
|
||||||
uint8_t sf_ver_m = atoi(c);
|
|
||||||
c[0] = buffer[7];
|
|
||||||
uint8_t sf_ver_s = atoi(c);
|
|
||||||
sprintf(sf_version,"%d.%d",sf_ver_m,sf_ver_s);
|
|
||||||
unsigned char ch_crc = 0x00;
|
|
||||||
int packgeSize = 0;
|
|
||||||
ch_crc = buffer[12];
|
|
||||||
packgeSize = BUILD_UINT32(buffer[8],buffer[9],buffer[10],buffer[11]);
|
|
||||||
zlog_info(zct,"sf_ver_m = %d",sf_ver_m);
|
|
||||||
zlog_info(zct,"sf_ver_s = %d",sf_ver_s);
|
|
||||||
zlog_info(zct,"hw_ver = %d",hw_ver);
|
|
||||||
zlog_info(zct,"sensor_type = %s",sensor_type);
|
|
||||||
zlog_info(zct,"packgeSize = %d",packgeSize);
|
|
||||||
zlog_info(zct,"ch_crc = %02x",ch_crc);
|
|
||||||
unsigned char sum = 0x00;
|
|
||||||
for(size_t i = 13; i < thisSize;i++){
|
|
||||||
sum += buffer[i];
|
|
||||||
}
|
|
||||||
if (sum % 256 != ch_crc)
|
|
||||||
{
|
|
||||||
jsonVal["success"] = false;
|
|
||||||
jsonVal["message"] = "package CRC error";
|
|
||||||
free(buffer);
|
|
||||||
return show_value_.write(jsonVal);
|
|
||||||
}
|
|
||||||
|
|
||||||
zlog_info(zct,"sum = %x\n",sum % 256);
|
|
||||||
char localtimestamp[32] = {0};
|
|
||||||
GetTimeNet(localtimestamp, 1);
|
|
||||||
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};
|
||||||
sprintf(wherecon," dataNodeNo = '%s' ",param.dataNodeNo[i].c_str());
|
for (size_t i = 0; i < param.dataNodeNo.size(); i++)
|
||||||
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()))
|
|
||||||
{
|
{
|
||||||
jsonVal["success"] = false;
|
UpgradeParameter upgrade_parameter;
|
||||||
jsonVal["message"] = "hardVersion error";
|
memset(wherecon,0,sizeof(wherecon));
|
||||||
free(buffer);
|
memset(insertSql,0,sizeof(insertSql));
|
||||||
return show_value_.write(jsonVal);
|
memset(updateSql,0,sizeof(updateSql));
|
||||||
|
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);
|
||||||
|
if (hw_ver != atoi(vecResult[0].c_str()))
|
||||||
|
{
|
||||||
|
jsonVal["success"] = false;
|
||||||
|
jsonVal["message"] = "hardVersion error";
|
||||||
|
free(buffer);
|
||||||
|
return show_value_.write(jsonVal);
|
||||||
|
}
|
||||||
|
sprintf(insertSql, " '%s','%s','','','','','%d.%d','%s',1,'%s'",vecResult[3].c_str(),localtimestamp,sf_ver_m,sf_ver_s,vecResult[1].c_str(),param.fileName.c_str());
|
||||||
|
sqlite_db_ctrl::instance().InsertData(" firmware_upgrade ", insertSql);
|
||||||
|
//0 默认状态,1 升级中,2 升级成功,3 升级失败
|
||||||
|
memset(wherecon,0,sizeof(wherecon));
|
||||||
|
memset(updateSql,0,sizeof(updateSql));
|
||||||
|
sprintf(wherecon," zigbeeShortAddr = '%s'",vecResult[3].c_str());
|
||||||
|
sprintf(updateSql, " upgradeStatus = %d ", 1);
|
||||||
|
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql,wherecon);
|
||||||
|
uint16_t short_addr;
|
||||||
|
char *end_ptr = NULL;
|
||||||
|
short_addr = strtol(vecResult[3].c_str(), &end_ptr, 16);
|
||||||
|
upgrade_parameter.short_addr = short_addr;
|
||||||
|
upgrade_parameter.sensor_type = std::string(sensor_type);
|
||||||
|
upgrade_parameter.hw_version = atoi(vecResult[0].c_str());
|
||||||
|
upgrade_parameter.current_sw_version = vecResult[1];
|
||||||
|
upgrade_parameter.upgrade_sw_version = std::string(sf_version);
|
||||||
|
param_list.push_back(upgrade_parameter);
|
||||||
}
|
}
|
||||||
sprintf(insertSql, " '%s','%s','','','','','%d.%d','%s',1,'%s'",vecResult[3].c_str(),localtimestamp,sf_ver_m,sf_ver_s,vecResult[1].c_str(),param.fileName.c_str());
|
int res = scheduler::instance().UpgradeSensor(param_list);
|
||||||
sqlite_db_ctrl::instance().InsertData(" firmware_upgrade ", insertSql);
|
|
||||||
//0 默认状态,1 升级中,2 升级成功,3 升级失败
|
|
||||||
memset(wherecon,0,sizeof(wherecon));
|
|
||||||
memset(updateSql,0,sizeof(updateSql));
|
|
||||||
sprintf(wherecon," zigbeeShortAddr = '%s'",vecResult[3].c_str());
|
|
||||||
sprintf(updateSql, " upgradeStatus = %d ", 1);
|
|
||||||
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql,wherecon);
|
|
||||||
uint16_t short_addr;
|
|
||||||
char *end_ptr = NULL;
|
|
||||||
short_addr = strtol(vecResult[3].c_str(), &end_ptr, 16);
|
|
||||||
upgrade_parameter.short_addr = short_addr;
|
|
||||||
upgrade_parameter.sensor_type = std::string(sensor_type);
|
|
||||||
upgrade_parameter.hw_version = atoi(vecResult[0].c_str());
|
|
||||||
upgrade_parameter.current_sw_version = vecResult[1];
|
|
||||||
upgrade_parameter.upgrade_sw_version = std::string(sf_version);
|
|
||||||
param_list.push_back(upgrade_parameter);
|
|
||||||
}
|
|
||||||
int res = scheduler::instance().UpgradeSensor(param_list);
|
|
||||||
if (res != 0)
|
if (res != 0)
|
||||||
{
|
{
|
||||||
jsonVal["success"] = false;
|
jsonVal["success"] = false;
|
||||||
@ -767,7 +771,14 @@ std::string JsonData::JsonCmd_Cgi_60(Param_60 ¶m){
|
|||||||
free(buffer);
|
free(buffer);
|
||||||
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 ¶m){
|
|||||||
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 ¶m){
|
|||||||
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 ¶m){
|
|||||||
}
|
}
|
||||||
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 ¶m){
|
|||||||
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,36 +1302,20 @@ std::string JsonData::JsonCmd_Cgi_67(Param_67 ¶m){
|
|||||||
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];
|
Json::Value jsChannelData;
|
||||||
std::string strShortAddr = arrResAll[i][2];
|
jsChannelData["dataNodeName"] = arrRes[j][10];
|
||||||
char whereCon[512] = {0};
|
jsChannelData["zigbeeAddr"] = arrRes[j][1];
|
||||||
char selectCon[128] = {0};
|
jsChannelData["MeasurementID"] = arrRes[j][0];
|
||||||
char column[128] = {0};
|
jsChannelData["status"] = atoi(arrRes[j][9].c_str());
|
||||||
char tablename[256] = {0};
|
jsChannelData["gatewayRssi"] = atoi(arrRes[j][2].c_str());
|
||||||
sprintf(selectCon, " t_sensor_info.MeasurementID='%s' ", strMeasurementID.c_str());
|
jsChannelData["dataNodeRssi"] = atoi(arrRes[j][3].c_str());
|
||||||
sprintf(column, " t_debug_info.*,t_sensor_info.status,t_sensor_info.dataNodeName ");
|
jsChannelData["comprehensiveRssi"] = atof(arrRes[j][4].c_str());
|
||||||
sprintf(tablename, " t_debug_info LEFT JOIN t_sensor_info ");
|
jsChannelData["minimumVoltage"] = atof(arrRes[j][5].c_str());
|
||||||
array_t arrRes;
|
jsChannelData["currentBatteryLevel"] = atof(arrRes[j][6].c_str());
|
||||||
arrRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(tablename, "*", selectCon);
|
jsChannelData["debugStatus"] = atoi(arrRes[j][7].c_str());
|
||||||
int iResult = arrRes.size();
|
jsChannelData["TimeStamp"] = arrRes[j][8];
|
||||||
if (iResult > 0) {
|
jsSensor.append(jsChannelData);
|
||||||
for (int j = 0; j < iResult; j++) {
|
|
||||||
Json::Value jsChannelData;
|
|
||||||
jsChannelData["dataNodeName"] = arrRes[j][10];
|
|
||||||
jsChannelData["zigbeeAddr"] = arrRes[j][1];
|
|
||||||
jsChannelData["MeasurementID"] = arrRes[j][0];
|
|
||||||
jsChannelData["status"] = atoi(arrRes[j][0].c_str());
|
|
||||||
jsChannelData["gatewayRssi"] = atoi(arrRes[j][2].c_str());
|
|
||||||
jsChannelData["dataNodeRssi"] = atoi(arrRes[j][3].c_str());
|
|
||||||
jsChannelData["comprehensiveRssi"] = atof(arrRes[j][4].c_str());
|
|
||||||
jsChannelData["minimumVoltage"] = atof(arrRes[j][5].c_str());
|
|
||||||
jsChannelData["currentBatteryLevel"] = atof(arrRes[j][6].c_str());
|
|
||||||
jsChannelData["debugStatus"] = atoi(arrRes[j][7].c_str());
|
|
||||||
jsChannelData["TimeStamp"] = arrRes[j][8];
|
|
||||||
jsSensor.append(jsChannelData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (jsSensor.size() == 0) {
|
if (jsSensor.size() == 0) {
|
||||||
jsonVal["success"] = false;
|
jsonVal["success"] = false;
|
||||||
@ -1332,7 +1343,22 @@ std::string JsonData::JsonCmd_Cgi_67(Param_67 ¶m){
|
|||||||
//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 ¶m){
|
|||||||
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 ¶m){
|
|||||||
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 ¶m){
|
|||||||
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 ¶m){
|
|||||||
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 ¶m){
|
|||||||
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 ¶m){
|
|||||||
jsonVal["success"] = false;
|
jsonVal["success"] = false;
|
||||||
jsonVal["content"].resize(0);
|
jsonVal["content"].resize(0);
|
||||||
}
|
}
|
||||||
|
jsonVal["content"]["lowSignal"] = lowSignal;
|
||||||
|
jsonVal["content"]["signalThreshold"] = signalThreshold;
|
||||||
|
jsonVal["content"]["lowBatteryLevel"] = lowBatteryLevel;
|
||||||
|
jsonVal["content"]["batteryLevelThreshold"] = batteryLevelThreshold;
|
||||||
|
jsonVal["content"]["shutdownDetection"] = shutdownDetection;
|
||||||
}
|
}
|
||||||
jsonVal["content"]["lowSignal"] = lowSignal;
|
|
||||||
jsonVal["content"]["signalThreshold"] = signalThreshold;
|
|
||||||
jsonVal["content"]["lowBatteryLevel"] = lowBatteryLevel;
|
|
||||||
jsonVal["content"]["batteryLevelThreshold"] = batteryLevelThreshold;
|
|
||||||
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 ¶m){
|
|||||||
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 ¶m){
|
|||||||
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;
|
||||||
|
|||||||
@ -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;
|
||||||
param.fileName = recvBody["fileName"].asString();
|
std::string type = recvBody["type"].asString();
|
||||||
param.product = recvBody["product"].asInt();
|
if (0 == type.compare("UPDATE")) {
|
||||||
param.mShortAddr = recvBody["shortAddr"].asString();
|
param.mMode = 0;
|
||||||
|
param.fileName = recvBody["fileName"].asString();
|
||||||
|
param.product = recvBody["product"].asInt();
|
||||||
|
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;
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
@ -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);
|
||||||
|
|||||||
@ -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;
|
||||||
|
|||||||
@ -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,35 +475,50 @@ 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;
|
||||||
tempchannel.compressChannelX = pData[8];
|
if (compareVersions(softVersion, "2.6")){
|
||||||
tempchannel.compressChannelY = pData[9];
|
tempchannel.compressChannelX = pData[7];
|
||||||
tempchannel.compressChannelZ = pData[10];
|
tempchannel.compressChannelY = pData[8];
|
||||||
tempchannel.compressChannelVolX = pData[23];
|
tempchannel.compressChannelZ = pData[9];
|
||||||
tempchannel.compressChannelVolY = pData[24];
|
|
||||||
tempchannel.compressChannelVolZ = pData[25];
|
|
||||||
|
|
||||||
tempchannel.CountX = BUILD_UINT32(pData[14], pData[13],pData[12],pData[11]);
|
tempchannel.CountX = BUILD_UINT32(pData[13], pData[12],pData[11],pData[10]);
|
||||||
tempchannel.CountY = BUILD_UINT32(pData[18], pData[17],pData[16],pData[15]);
|
tempchannel.CountY = BUILD_UINT32(pData[17], pData[16],pData[15],pData[14]);
|
||||||
tempchannel.CountZ = BUILD_UINT32(pData[22], pData[21],pData[20],pData[19]);
|
tempchannel.CountZ = BUILD_UINT32(pData[21], pData[20],pData[19],pData[18]);
|
||||||
tempchannel.CountVolX = BUILD_UINT32(pData[29], pData[28],pData[27],pData[26]);
|
sprintf(sensor_rssi, "%02d", pData[22] & 0xFF);
|
||||||
tempchannel.CountVolY = BUILD_UINT32(pData[33], pData[32],pData[31],pData[30]);
|
}else{
|
||||||
tempchannel.CountVolZ = BUILD_UINT32(pData[37], pData[36],pData[35],pData[34]);
|
sprintf(sensor_rssi, "%02d", pData[7] & 0xFF);
|
||||||
|
tempchannel.compressChannelX = pData[8];
|
||||||
|
tempchannel.compressChannelY = pData[9];
|
||||||
|
tempchannel.compressChannelZ = pData[10];
|
||||||
|
tempchannel.compressChannelVolX = pData[23];
|
||||||
|
tempchannel.compressChannelVolY = pData[24];
|
||||||
|
tempchannel.compressChannelVolZ = pData[25];
|
||||||
|
|
||||||
tempchannel.samplerateX = BUILD_UINT32(pData[41], pData[40],pData[39],pData[38]);
|
tempchannel.CountX = BUILD_UINT32(pData[14], pData[13],pData[12],pData[11]);
|
||||||
tempchannel.samplerateY = BUILD_UINT32(pData[45], pData[44],pData[43],pData[42]);
|
tempchannel.CountY = BUILD_UINT32(pData[18], pData[17],pData[16],pData[15]);
|
||||||
tempchannel.samplerateZ = BUILD_UINT32(pData[49], pData[48],pData[47],pData[46]);
|
tempchannel.CountZ = BUILD_UINT32(pData[22], pData[21],pData[20],pData[19]);
|
||||||
tempchannel.samplerateVolX = BUILD_UINT32(pData[53], pData[52],pData[51],pData[50]);
|
tempchannel.CountVolX = BUILD_UINT32(pData[29], pData[28],pData[27],pData[26]);
|
||||||
tempchannel.samplerateVolY = BUILD_UINT32(pData[57], pData[56],pData[55],pData[54]);
|
tempchannel.CountVolY = BUILD_UINT32(pData[33], pData[32],pData[31],pData[30]);
|
||||||
tempchannel.samplerateVolZ = BUILD_UINT32(pData[61], pData[60],pData[59],pData[58]);
|
tempchannel.CountVolZ = BUILD_UINT32(pData[37], pData[36],pData[35],pData[34]);
|
||||||
|
|
||||||
|
tempchannel.samplerateX = BUILD_UINT32(pData[41], pData[40],pData[39],pData[38]);
|
||||||
|
tempchannel.samplerateY = BUILD_UINT32(pData[45], pData[44],pData[43],pData[42]);
|
||||||
|
tempchannel.samplerateZ = BUILD_UINT32(pData[49], pData[48],pData[47],pData[46]);
|
||||||
|
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.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);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user