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(""){};
|
||||
};
|
||||
struct Param_60 {
|
||||
int mMode;
|
||||
std::string fileName;
|
||||
int product;
|
||||
std::string mShortAddr;
|
||||
std::vector<std::string> dataNodeNo;
|
||||
Param_60() : fileName(""),product(0),mShortAddr(""){};
|
||||
Param_60() :mMode(0), fileName(""),product(0),mShortAddr(""){};
|
||||
};
|
||||
struct Param_61 {
|
||||
int mMode;
|
||||
@ -397,8 +398,9 @@ struct Param_68 {
|
||||
int signalThreshold;
|
||||
int lowBatteryLevel;
|
||||
int batteryLevelThreshold;
|
||||
int shutdownDetection;
|
||||
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{
|
||||
|
||||
@ -643,123 +643,127 @@ std::string JsonData::JsonCmd_Cgi_60(Param_60 ¶m){
|
||||
jsonVal[JSON_FIELD_CMD] = "60";
|
||||
jsonVal["success"] = true;
|
||||
jsonVal["message"] = "";
|
||||
char file_path[64]={0};
|
||||
char cmd[128]={0};
|
||||
sprintf(cmd, "mv /opt/%s /opt/DataNode/",param.fileName.c_str());
|
||||
system(cmd);
|
||||
sprintf(file_path, "/opt/DataNode/%s",param.fileName.c_str());
|
||||
zlog_info(zct,"file_path = %s",file_path);
|
||||
FILE * pFile=NULL;
|
||||
size_t thisSize = 0;
|
||||
char *buffer=NULL;
|
||||
pFile = fopen (file_path,"rb");
|
||||
if (pFile==NULL) {
|
||||
zlog_error(zct,"Error opening file");
|
||||
jsonVal["success"] = false;
|
||||
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){
|
||||
if(param.mMode == 0){
|
||||
char file_path[64]={0};
|
||||
char cmd[128]={0};
|
||||
sprintf(cmd, "mv /opt/%s /opt/DataNode/",param.fileName.c_str());
|
||||
system(cmd);
|
||||
sprintf(file_path, "/opt/DataNode/%s",param.fileName.c_str());
|
||||
zlog_info(zct,"file_path = %s",file_path);
|
||||
FILE * pFile=NULL;
|
||||
size_t thisSize = 0;
|
||||
char *buffer=NULL;
|
||||
pFile = fopen (file_path,"rb");
|
||||
if (pFile==NULL) {
|
||||
zlog_error(zct,"Error opening file");
|
||||
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);
|
||||
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);
|
||||
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;
|
||||
zlog_info(zct,"sum = %x\n",sum % 256);
|
||||
char localtimestamp[32] = {0};
|
||||
GetTimeNet(localtimestamp, 1);
|
||||
std::vector<UpgradeParameter> param_list;
|
||||
char wherecon[100] = {0};
|
||||
char insertSql[200] = {0};
|
||||
char updateSql[100] = {0};
|
||||
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()))
|
||||
for (size_t i = 0; i < param.dataNodeNo.size(); i++)
|
||||
{
|
||||
jsonVal["success"] = false;
|
||||
jsonVal["message"] = "hardVersion error";
|
||||
free(buffer);
|
||||
return show_value_.write(jsonVal);
|
||||
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());
|
||||
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());
|
||||
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);
|
||||
int res = scheduler::instance().UpgradeSensor(param_list);
|
||||
if (res != 0)
|
||||
{
|
||||
jsonVal["success"] = false;
|
||||
@ -767,7 +771,14 @@ std::string JsonData::JsonCmd_Cgi_60(Param_60 ¶m){
|
||||
free(buffer);
|
||||
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);
|
||||
|
||||
}
|
||||
@ -1095,7 +1106,7 @@ std::string JsonData::JsonCmd_Cgi_65(Param_65 ¶m){
|
||||
jsonVal[JSON_FIELD_CMD] = "65";
|
||||
jsonVal["success"] = true;
|
||||
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();
|
||||
std::string MeasurementID = "";
|
||||
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((float(recive_z)/(interval/waveInterVal)));
|
||||
iTem.append(recive_z);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// memset(count_sql,0,sizeof(count_sql));
|
||||
// snprintf(count_sql,sizeof(count_sql),
|
||||
// "SELECT "
|
||||
@ -1205,8 +1217,16 @@ std::string JsonData::JsonCmd_Cgi_65(Param_65 ¶m){
|
||||
}
|
||||
iTem.append(resend_feature);
|
||||
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);
|
||||
|
||||
|
||||
}
|
||||
if (jsBody.size() == 0) {
|
||||
jsonVal["success"] = false;
|
||||
@ -1246,9 +1266,16 @@ std::string JsonData::JsonCmd_Cgi_67(Param_67 ¶m){
|
||||
jsonVal[JSON_FIELD_CMD] = "67";
|
||||
jsonVal["success"] = true;
|
||||
jsonVal["message"] = " ";
|
||||
char whereCon[512] = {0};
|
||||
char selectCon[128] = {0};
|
||||
char column[128] = {0};
|
||||
char tablename[256] = {0};
|
||||
if(param.mMode == 0){
|
||||
array_t arrResAll = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_INFO(TNAME), " dataNodeNo,MeasurementID,zigbeeShortAddr ", NULL);
|
||||
int nSize = arrResAll.size();
|
||||
sprintf(selectCon, " t_sensor_info.MeasurementID = t_debug_info.MeasurementID ");
|
||||
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) {
|
||||
int packgeNo = param.mPackageFlag;
|
||||
int packgeMax = 0;
|
||||
@ -1275,36 +1302,20 @@ std::string JsonData::JsonCmd_Cgi_67(Param_67 ¶m){
|
||||
jsonVal["packageMax"] = index + 1;
|
||||
}
|
||||
Json::Value jsSensor;
|
||||
for (int i = packgeNo * 10; i < packgeNum; i++) {
|
||||
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;
|
||||
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);
|
||||
}
|
||||
}
|
||||
for (int j = packgeNo * 10; j < packgeNum; j++) {
|
||||
Json::Value jsChannelData;
|
||||
jsChannelData["dataNodeName"] = arrRes[j][10];
|
||||
jsChannelData["zigbeeAddr"] = arrRes[j][1];
|
||||
jsChannelData["MeasurementID"] = arrRes[j][0];
|
||||
jsChannelData["status"] = atoi(arrRes[j][9].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) {
|
||||
jsonVal["success"] = false;
|
||||
@ -1332,7 +1343,22 @@ std::string JsonData::JsonCmd_Cgi_67(Param_67 ¶m){
|
||||
//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);
|
||||
}
|
||||
@ -1344,7 +1370,7 @@ std::string JsonData::JsonCmd_Cgi_68(Param_68 ¶m){
|
||||
jsonVal[JSON_FIELD_CMD] = "68";
|
||||
jsonVal["success"] = true;
|
||||
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 updateSql[256] = {0};
|
||||
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());
|
||||
lowBatteryLevel = writeIntValue("config", "lowBatteryLevel", param.lowBatteryLevel, (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){
|
||||
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));
|
||||
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);
|
||||
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) {
|
||||
@ -1368,7 +1394,8 @@ std::string JsonData::JsonCmd_Cgi_68(Param_68 ¶m){
|
||||
signalThreshold = readIntValue("config", "signalThreshold", (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());
|
||||
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) {
|
||||
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][3].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);
|
||||
}
|
||||
}
|
||||
@ -1385,12 +1412,12 @@ std::string JsonData::JsonCmd_Cgi_68(Param_68 ¶m){
|
||||
jsonVal["success"] = false;
|
||||
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;
|
||||
return show_value_.write(jsonVal);
|
||||
}
|
||||
@ -1453,8 +1480,8 @@ std::string JsonData::JsonCmd_Cgi_70(Param_70 ¶m){
|
||||
jsonVal["success"] = true;
|
||||
jsonVal["message"] = " ";
|
||||
char selectCon[256] = {0}, szTableName[100] = {0x00}, whereCon[256] = {0x00};
|
||||
sprintf(szTableName,"t_abnormal_info");
|
||||
int rows = sqlite_db_ctrl::instance().GetTableRows(szTableName, whereCon);
|
||||
sprintf(szTableName,"t_process_info");
|
||||
int rows = sqlite_db_ctrl::instance().GetTableRows(szTableName, NULL);
|
||||
int packgeNo = param.mPackageFlag;
|
||||
int packgeMax = 0;
|
||||
int packgeNum = 0;
|
||||
@ -1515,7 +1542,7 @@ std::string JsonData::JsonCmd_Cgi_71(Param_71 ¶m){
|
||||
jsonVal["message"] = " ";
|
||||
char selectCon[256] = {0}, szTableName[100] = {0x00}, whereCon[256] = {0x00};
|
||||
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 packgeMax = 0;
|
||||
int packgeNum = 0;
|
||||
|
||||
@ -408,9 +408,16 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
||||
case kTransducerUpgrade:{
|
||||
JsonData jd;
|
||||
Param_60 param;
|
||||
param.fileName = recvBody["fileName"].asString();
|
||||
param.product = recvBody["product"].asInt();
|
||||
param.mShortAddr = recvBody["shortAddr"].asString();
|
||||
std::string type = recvBody["type"].asString();
|
||||
if (0 == type.compare("UPDATE")) {
|
||||
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"];
|
||||
if (recvDataNodeNo.size() > 0)
|
||||
{
|
||||
@ -558,6 +565,9 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
||||
if (0 == type.compare("GET")) {
|
||||
param.mMode = 0;
|
||||
}
|
||||
if (0 == type.compare("STOP")) {
|
||||
param.mMode = 2;
|
||||
}
|
||||
std::string data = jd.JsonCmd_Cgi_67(param);
|
||||
return data;
|
||||
}
|
||||
@ -575,21 +585,22 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
||||
param.signalThreshold = recvBody["signalThreshold"].asInt();
|
||||
param.lowBatteryLevel = recvBody["lowBatteryLevel"].asInt();
|
||||
param.batteryLevelThreshold = recvBody["batteryLevelThreshold"].asInt();
|
||||
param.shutdownDetection = recvBody["shutdownDetection"].asInt();
|
||||
Json::Value recvDataNodeNo = recvBody["DataNodeNo"];
|
||||
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;
|
||||
for (size_t j = 0; j < recvDataNodeNo[i].size(); j++)
|
||||
{
|
||||
vecParam.measurementID = recvDataNodeNo[i][j].asString();
|
||||
vecParam.status = recvDataNodeNo[i][j].asInt();
|
||||
vecParam.statisticType = recvDataNodeNo[i][j].asInt();
|
||||
vecParam.threshold = recvDataNodeNo[i][j].asDouble();
|
||||
}
|
||||
Json::Value node = recvDataNodeNo[i];
|
||||
|
||||
vecParam.measurementID = node[0u].asString();
|
||||
vecParam.status = node[1u].asInt();
|
||||
vecParam.statisticType = node[2u].asInt();
|
||||
vecParam.threshold = node[3u].asDouble();
|
||||
param.vecParam68.push_back(vecParam);
|
||||
}
|
||||
}
|
||||
|
||||
std::string data = jd.JsonCmd_Cgi_68(param);
|
||||
return data;
|
||||
}break;
|
||||
@ -624,6 +635,8 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
||||
case KProcessLog:{
|
||||
JsonData jd;
|
||||
Param_70 param;
|
||||
param.timeStart = recvBody["timeStart"].asString();
|
||||
param.timeEnd = recvBody["timeEnd"].asString();
|
||||
param.mPackageFlag = recvBody["package"].asInt();
|
||||
std::string data = jd.JsonCmd_Cgi_70(param);
|
||||
return data;
|
||||
@ -634,6 +647,8 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
|
||||
case kGetSensorInfo:{
|
||||
JsonData jd;
|
||||
Param_71 param;
|
||||
param.timeStart = recvBody["timeStart"].asString();
|
||||
param.timeEnd = recvBody["timeEnd"].asString();
|
||||
param.mPackageFlag = recvBody["package"].asInt();
|
||||
std::string data = jd.JsonCmd_Cgi_71(param);
|
||||
return data;
|
||||
|
||||
@ -18,7 +18,7 @@ extern zlog_category_t *zbt;
|
||||
|
||||
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;
|
||||
auto iter = short_addr_map_.find(short_addr);
|
||||
if (iter == short_addr_map_.end()) {
|
||||
@ -60,21 +60,22 @@ int SensorScheduler::StartSchedule(uint16_t short_addr, int &next_duration, bool
|
||||
return kScheduleConfigSensor;
|
||||
} else {
|
||||
wave_feature_set_inst::instance().GetFeatureCfg(short_addr, 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);
|
||||
current_request_ = kScheduleEigenValue;
|
||||
return kScheduleEigenValue;
|
||||
} else {
|
||||
next_duration = GetNextDuration(short_addr);
|
||||
// if (g_x || g_y || g_z) {
|
||||
// // 执行上送特征值任务
|
||||
// zlog_debug(zbt, "[%d:%x] send eigen value in eigen slice", id, short_addr);
|
||||
// current_request_ = kScheduleEigenValue;
|
||||
// return kScheduleEigenValue;
|
||||
// } else {
|
||||
next_duration = GetNextDuration(short_addr, z, next_task_id);
|
||||
zlog_warn(zbt, "[%d:%x] no need for eigen", id, short_addr);
|
||||
return kScheduleWrongTime;
|
||||
}
|
||||
return kScheduleResultNone;
|
||||
// }
|
||||
}
|
||||
} else {
|
||||
if (current_schedule_status_ == kScheduleStatusDebug) {
|
||||
if (debug_list_.count(short_addr) == 0) {
|
||||
next_duration = GetDebugUpgradeNextDuration(short_addr);
|
||||
next_task_id = kScheduleEigenValue;
|
||||
zlog_debug(zbt, "[%d:%x] not in debug list", id, short_addr);
|
||||
return kScheduleWrongTime;
|
||||
} 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);
|
||||
next_duration = 120;
|
||||
}
|
||||
z = true;
|
||||
next_task_id = kScheduleWaveForm;
|
||||
return kScheduleWrongTime;
|
||||
}
|
||||
}
|
||||
|
||||
next_duration = GetDebugUpgradeNextDuration(short_addr);
|
||||
next_task_id = kScheduleEigenValue;
|
||||
zlog_debug(zbt, "[%d:%x] debug wrong time", id, short_addr);
|
||||
return kScheduleWrongTime;
|
||||
}
|
||||
@ -110,16 +114,18 @@ int SensorScheduler::StartSchedule(uint16_t short_addr, int &next_duration, bool
|
||||
} else if (current_schedule_status_ == kScheduleStatusUpgrade) {
|
||||
if (upgrade_list_.count(short_addr) == 0) {
|
||||
next_duration = GetDebugUpgradeNextDuration(short_addr);
|
||||
next_task_id = kScheduleEigenValue;
|
||||
zlog_debug(zbt, "[%d:%x] not in upgrade list", id, short_addr);
|
||||
return kScheduleWrongTime;
|
||||
} else {
|
||||
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) {
|
||||
current_request_ = kScheduleUpgrade;
|
||||
upgrade_list_.erase(short_addr);
|
||||
// upgrade_list_.erase(short_addr);
|
||||
return kScheduleUpgrade;
|
||||
} else {
|
||||
next_duration = GetDebugUpgradeNextDuration(short_addr);
|
||||
next_task_id = kScheduleEigenValue;
|
||||
zlog_debug(zbt, "[%d:%x] in wrong time", id, short_addr);
|
||||
return kScheduleWrongTime;
|
||||
}
|
||||
@ -140,7 +146,7 @@ int SensorScheduler::StartSchedule(uint16_t short_addr, int &next_duration, bool
|
||||
z = true;
|
||||
return kScheduleWaveForm;
|
||||
} 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);
|
||||
return kScheduleWrongTime;
|
||||
}
|
||||
@ -151,7 +157,7 @@ int SensorScheduler::StartSchedule(uint16_t short_addr, int &next_duration, bool
|
||||
z = false;
|
||||
return kScheduleWaveForm;
|
||||
} 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);
|
||||
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);
|
||||
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);
|
||||
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 (current_schedule_status_ == kScheduleStatusDebug) {
|
||||
if (debug_list_.count(short_addr) == 0) {
|
||||
next_task_id = kScheduleEigenValue;
|
||||
return GetDebugUpgradeNextTS(short_addr);
|
||||
} 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) {
|
||||
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;
|
||||
next_task_id = kScheduleWaveForm;
|
||||
z = true;
|
||||
return nxt_ts;
|
||||
}
|
||||
}
|
||||
|
||||
next_task_id = kScheduleEigenValue;
|
||||
return GetDebugUpgradeNextTS(short_addr);
|
||||
}
|
||||
} else if (current_schedule_status_ == kScheduleStatusUpgrade) {
|
||||
if (upgrade_list_.count(short_addr) == 0) {
|
||||
next_task_id = kScheduleEigenValue;
|
||||
return GetDebugUpgradeNextTS(short_addr);
|
||||
} 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) {
|
||||
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;
|
||||
next_task_id = kScheduleUpgrade;
|
||||
return nxt_ts;
|
||||
}
|
||||
}
|
||||
next_task_id = kScheduleEigenValue;
|
||||
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;
|
||||
long send_wave_ts = 0;
|
||||
long available_ts = 0;
|
||||
next_task_id = kScheduleWaveForm;
|
||||
wave_feature_set_inst::instance().GetWaveCfg(short_addr, g_x, g_y, g_z);
|
||||
if (g_x || g_y || g_z) {
|
||||
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) {
|
||||
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());
|
||||
next_task_id = kScheduleWaveForm;
|
||||
z = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -263,6 +280,8 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) {
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -277,6 +296,7 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t 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);
|
||||
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)) {
|
||||
zlog_debug(zbt, "[Nxt] [%d:%x] add xy to patch set", id, 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) {
|
||||
available_ts = current_wave_slice_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());
|
||||
break;
|
||||
}
|
||||
@ -323,6 +349,7 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) {
|
||||
} else {
|
||||
if (current_schedule_status_ == kScheduleStatusDebug) {
|
||||
if (debug_list_.count(short_addr) == 0) {
|
||||
next_task_id = kScheduleEigenValue;
|
||||
return GetDebugUpgradeNextTS(short_addr);
|
||||
} 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) {
|
||||
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;
|
||||
next_task_id = kScheduleWaveForm;
|
||||
z = true;
|
||||
return nxt_ts;
|
||||
}
|
||||
}
|
||||
|
||||
next_task_id = kScheduleEigenValue;
|
||||
return GetDebugUpgradeNextTS(short_addr);
|
||||
}
|
||||
} else if (current_schedule_status_ == kScheduleStatusUpgrade) {
|
||||
if (upgrade_list_.count(short_addr) == 0) {
|
||||
next_task_id = kScheduleEigenValue;
|
||||
return GetDebugUpgradeNextDuration(short_addr);
|
||||
} 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) {
|
||||
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;
|
||||
zlog_debug(zbt, "[Nxt] [%d:%x] next feature send utc time3:[%s]", id, short_addr, GetUTCTime(available_ts).c_str());
|
||||
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;
|
||||
auto iter = short_addr_map_.find(short_addr);
|
||||
if (iter == short_addr_map_.end()) {
|
||||
zlog_error(zbt, "cannot find id for short_addr %x", short_addr);
|
||||
next_task_id = kScheduleEigenValue;
|
||||
return 0;
|
||||
} else {
|
||||
id = iter->second;
|
||||
}
|
||||
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;
|
||||
if (duration < 10) {
|
||||
zlog_debug(zbt, "[%d:%x] [Nxt] exception duration:%d, adjust to 25", id, short_addr);
|
||||
|
||||
@ -53,14 +53,14 @@ public:
|
||||
// kScheduleEigenValue kScheduleWaveForm
|
||||
// 上面4个结束,调GetNextDuration()获取休眠时间
|
||||
// 如果是kScheduleWrongTime, 此函数next_duration表明休眠时间
|
||||
int StartSchedule(uint16_t short_addr, int &next_duration, bool &z);
|
||||
int GetNextDuration(uint16_t short_addr);
|
||||
int StartSchedule(uint16_t short_addr, int &next_duration, bool &z, int &next_task_id);
|
||||
int GetNextDuration(uint16_t short_addr, bool &z, int &next_task_id);
|
||||
|
||||
// z用于说明是z轴波形,还是xy轴波形
|
||||
int WaveError(uint16_t short_addr, bool z);
|
||||
void WaveSuccess(uint16_t short_addr, bool z);
|
||||
// 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);
|
||||
|
||||
@ -4,41 +4,36 @@
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
#include <json/json.h>
|
||||
#include <json/reader.h>
|
||||
#include <ctime>
|
||||
#include <iomanip>
|
||||
#include <zlog.h>
|
||||
|
||||
extern zlog_category_t *zct;
|
||||
extern zlog_category_t *zbt;
|
||||
|
||||
ScheduleStatus get_schedule_status() {
|
||||
// std::ifstream status_file("/opt/configenv/status.json");
|
||||
// Json::Value json_data;
|
||||
// Json::CharReaderBuilder reader;
|
||||
// std::string errs;
|
||||
std::ifstream status_file("/opt/configenv/status.json");
|
||||
if (!status_file.good()) {
|
||||
zlog_info(zbt, "[ShortAddrCfg] no file /opt/configenv/status.json");
|
||||
return kScheduleStatusNormal;
|
||||
}
|
||||
Json::Value json_data;
|
||||
Json::Reader reader;
|
||||
|
||||
// if (status_file.is_open()) {
|
||||
// if (Json::parseFromStream(reader, status_file, &json_data, &errs)) {
|
||||
// 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 (reader.parse(status_file, json_data, false)) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
status_file.close();
|
||||
return kScheduleStatusNormal;
|
||||
}
|
||||
|
||||
@ -70,13 +65,12 @@ void set_schedule_status(ScheduleStatus status) {
|
||||
|
||||
// Append to status_history.json
|
||||
Json::Value history_data;
|
||||
// std::ifstream history_file("/opt/configenv/status_history.json");
|
||||
// if (history_file.is_open()) {
|
||||
// if (Json::parseFromStream(Json::CharReaderBuilder(), history_file, &history_data, nullptr)) {
|
||||
// // successfully read existing history
|
||||
// }
|
||||
// history_file.close();
|
||||
// }
|
||||
std::ifstream history_file("/opt/configenv/status_history.json");
|
||||
if (history_file.good()) {
|
||||
Json::Reader reader;
|
||||
reader.parse(history_file, history_data, false);
|
||||
history_file.close();
|
||||
}
|
||||
|
||||
// Get the current time
|
||||
auto now = std::chrono::system_clock::now();
|
||||
@ -117,7 +111,7 @@ std::string get_status_desc(ScheduleStatus status) {
|
||||
break;
|
||||
default:
|
||||
status_str = "normal";
|
||||
zlog_error(zct, "fail to get status desc:%d", status);
|
||||
zlog_error(zbt, "fail to get status desc:%d", status);
|
||||
break;
|
||||
}
|
||||
return status_str;
|
||||
|
||||
@ -378,7 +378,7 @@ int Uart::DealAskTask(uint16_t ushortAdd){
|
||||
int taskID;
|
||||
ScheduleTask scheduleTask;
|
||||
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);
|
||||
if (taskID == kScheduleConfigSensor)
|
||||
{
|
||||
@ -449,7 +449,8 @@ int Uart::DealReviveDuration(uint16_t ushortAdd){
|
||||
|
||||
ScheduleTask scheduleTask;
|
||||
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);
|
||||
scheduleTask.cmd = REVIVE_DURATION;
|
||||
scheduleTask.shortAddr = ushortAdd;
|
||||
@ -474,35 +475,50 @@ int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){
|
||||
zlog_info(zct, "DealWaveCompress ");
|
||||
now_task = WAVE_CMD;
|
||||
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);
|
||||
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;
|
||||
tempchannel.compressChannelX = pData[8];
|
||||
tempchannel.compressChannelY = pData[9];
|
||||
tempchannel.compressChannelZ = pData[10];
|
||||
tempchannel.compressChannelVolX = pData[23];
|
||||
tempchannel.compressChannelVolY = pData[24];
|
||||
tempchannel.compressChannelVolZ = pData[25];
|
||||
if (compareVersions(softVersion, "2.6")){
|
||||
tempchannel.compressChannelX = pData[7];
|
||||
tempchannel.compressChannelY = pData[8];
|
||||
tempchannel.compressChannelZ = pData[9];
|
||||
|
||||
tempchannel.CountX = BUILD_UINT32(pData[14], pData[13],pData[12],pData[11]);
|
||||
tempchannel.CountY = BUILD_UINT32(pData[18], pData[17],pData[16],pData[15]);
|
||||
tempchannel.CountZ = BUILD_UINT32(pData[22], pData[21],pData[20],pData[19]);
|
||||
tempchannel.CountVolX = BUILD_UINT32(pData[29], pData[28],pData[27],pData[26]);
|
||||
tempchannel.CountVolY = BUILD_UINT32(pData[33], pData[32],pData[31],pData[30]);
|
||||
tempchannel.CountVolZ = BUILD_UINT32(pData[37], pData[36],pData[35],pData[34]);
|
||||
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.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.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]);
|
||||
tempchannel.CountX = BUILD_UINT32(pData[14], pData[13],pData[12],pData[11]);
|
||||
tempchannel.CountY = BUILD_UINT32(pData[18], pData[17],pData[16],pData[15]);
|
||||
tempchannel.CountZ = BUILD_UINT32(pData[22], pData[21],pData[20],pData[19]);
|
||||
tempchannel.CountVolX = BUILD_UINT32(pData[29], pData[28],pData[27],pData[26]);
|
||||
tempchannel.CountVolY = BUILD_UINT32(pData[33], pData[32],pData[31],pData[30]);
|
||||
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;
|
||||
wave_shortAddr = ushortAdd;
|
||||
char sensor_rssi[10] = {0x00};
|
||||
sprintf(sensor_rssi, "%02d", pData[7] & 0xFF);
|
||||
|
||||
|
||||
if (!strcmp(sensor_rssi, "00") || !strcmp(sensor_rssi, "0")) {
|
||||
char errorInfo[100] = {0x00};
|
||||
sprintf(errorInfo, "No RSSI %s", sensor_rssi);
|
||||
@ -641,7 +657,7 @@ int Uart::DealAskTaskOld(uint16_t ushortAdd){
|
||||
int taskID;
|
||||
ScheduleTask scheduleTask;
|
||||
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);
|
||||
if(next_task_id == kScheduleUpgrade){
|
||||
scheduleTask.cmd = REVIVE_DURATION;
|
||||
@ -733,7 +749,7 @@ void Uart::DealRecvData(const char *pData) {
|
||||
break;
|
||||
case UPGRADE_ASK:
|
||||
mssleep(50000);
|
||||
taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration, z);
|
||||
taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration,z, next_task_id);
|
||||
taskID = kScheduleUpgrade;
|
||||
if (taskID == kScheduleUpgrade){
|
||||
UpdateWirelessNode(ushortAdd);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user