优化调度和协议交互,增加web统计成功率

This commit is contained in:
zhangsheng 2025-05-10 11:43:05 +08:00
parent 621fdf21e9
commit fb1de47b00
12 changed files with 553 additions and 192 deletions

View File

@ -430,7 +430,27 @@ vec_t SqliteDB::GetDataSingleLine(const char *tablename, const char *column, con
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
return vecResult; return vecResult;
} }
vec_t SqliteDB::GetDataSingleLine(const char *sql) {
vec_t vecResult;
zlog_info(zct, "[GetDataSingleLine] sql:%s", sql);
sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(mDBAcess, sql, -1, &stmt, 0) != SQLITE_OK) {
zlog_error(zct, "sqlite3_prepare_v2:%s, sql:[%s]", sqlite3_errmsg(mDBAcess), sql);
sqlite3_finalize(stmt);
return vecResult;
}
int retStep = sqlite3_step(stmt);
int column_count = sqlite3_column_count(stmt);
if (retStep == SQLITE_ROW) {
for (int iCol = 0; iCol < column_count; iCol++) {
char *columninfo = (char *)sqlite3_column_text(stmt, iCol);
std::string str = columninfo != NULL ? columninfo : "";
vecResult.push_back(str);
}
}
sqlite3_finalize(stmt);
return vecResult;
}
std::string SqliteDB::GetData(const char *tablename, const char *column, const char *whereCon) { std::string SqliteDB::GetData(const char *tablename, const char *column, const char *whereCon) {
std::string strRes = ""; std::string strRes = "";
std::string strSql = "select "; std::string strSql = "select ";

View File

@ -48,6 +48,7 @@ public:
int GetTableRows(const char *tablename, const char *whereCon); int GetTableRows(const char *tablename, const char *whereCon);
int AlterTable(const char *tablename, const char *column, bool isAdd = true); int AlterTable(const char *tablename, const char *column, bool isAdd = true);
vec_t GetDataSingleLine(const char *tablename, const char *column, const char *whereCon); vec_t GetDataSingleLine(const char *tablename, const char *column, const char *whereCon);
vec_t GetDataSingleLine(const char *sql);
std::string GetData(const char *tablename, const char *column, const char *whereCon); std::string GetData(const char *tablename, const char *column, const char *whereCon);
array_t GetDataMultiLine(const char *sql); array_t GetDataMultiLine(const char *sql);
array_t GetDataMultiLine(const char *tablename, const char *column, const char *whereCon); array_t GetDataMultiLine(const char *tablename, const char *column, const char *whereCon);

View File

@ -73,6 +73,7 @@ public:
std::string JsonCmd_Cgi_62(Param_62 &param); std::string JsonCmd_Cgi_62(Param_62 &param);
std::string JsonCmd_Cgi_63(Param_63 &param); std::string JsonCmd_Cgi_63(Param_63 &param);
std::string JsonCmd_Cgi_64(Param_64 &param); std::string JsonCmd_Cgi_64(Param_64 &param);
std::string JsonCmd_Cgi_65(Param_65 &param);
std::string JsonCmd_Cgi_default(); std::string JsonCmd_Cgi_default();
//CMT tcp //CMT tcp

View File

@ -1083,3 +1083,114 @@ std::string JsonData::JsonCmd_Cgi_64(Param_64 &param)
jsonVal["cmdBody"] = jsBody; jsonVal["cmdBody"] = jsBody;
return show_value_.write(jsonVal); return show_value_.write(jsonVal);
} }
std::string JsonData::JsonCmd_Cgi_65(Param_65 &param){
Json::Value jsonVal;
jsonVal.clear();
jsonVal[JSON_FIELD_CMD] = "65";
jsonVal["success"] = true;
jsonVal["message"] = " ";
array_t vetRes = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(T_SENSOR_INFO(TNAME), " dataNodeName,MeasurementID ", NULL);
size_t nSize = vetRes.size();
std::string MeasurementID = "";
char szTableName[100] = {0x00}, whereCon[256] = {0x00};
if (nSize > 0) {
int interval = atol(param.timeEnd.c_str()) - atol(param.timeStart.c_str());
int featureInterVal = 0,waveInterVal = 0,featureInterTime = 0,waveInterTime = 0,maxSensorNum = 0;
scheduler::instance().GetScheduleConfig(featureInterVal,waveInterVal,featureInterTime,waveInterTime,maxSensorNum);
Json::Value jsBody;
char count_sql[1024] = {0};
int recive_feature = 0, send_feature = 0;
int recive_x = 0, recive_y = 0, recive_z = 0;
int send_x = 0, send_y = 0, send_z = 0;
for (size_t i = 0; i < nSize; i++)
{
Json::Value iTem;
MeasurementID = vetRes[i][1];
iTem.append(vetRes[i][0]);
memset(szTableName,0,sizeof(szTableName));
memset(whereCon,0,sizeof(whereCon));
sprintf(szTableName,"t_data_%s",vetRes[i][1].c_str());
sprintf(whereCon, " channelID = '%s-X' and timeStamp < '%s' and timeStamp > '%s' ", MeasurementID.c_str(), param.timeEnd.c_str(), param.timeStart.c_str());
memset(count_sql,0,sizeof(count_sql));
snprintf(count_sql,sizeof(count_sql),
"SELECT "
"COUNT(*) FILTER (WHERE channelID = '%s-X') AS recive_feature,"
"COUNT(*) FILTER (WHERE channelID = '%s-X' and sendMsg = 1) AS send_feature "
"FROM ( "
"SELECT * FROM %s "
"WHERE timeStamp BETWEEN '%s' AND '%s');",MeasurementID.c_str(),MeasurementID.c_str(),szTableName,param.timeStart.c_str(),param.timeEnd.c_str());
vec_t vecResult1 = sqlite_db_ctrl::instance().GetDataSingleLine(count_sql);
if (vecResult1.size() > 0)
{
recive_feature = atoi(vecResult1[0].c_str());
send_feature = atoi(vecResult1[1].c_str());
}
iTem.append(MeasurementID);
memset(count_sql,0,sizeof(count_sql));
snprintf(count_sql,sizeof(count_sql),
"SELECT "
"COUNT(*) FILTER (WHERE data_nodeno = '%s-X') AS recive_x,"
"COUNT(*) FILTER (WHERE data_nodeno = '%s-Y') AS recive_y,"
"COUNT(*) FILTER (WHERE data_nodeno = '%s-Z') AS recive_z "
"FROM ( "
"SELECT * FROM receive_wave_status "
"WHERE timeStamp BETWEEN '%s' AND '%s');",MeasurementID.c_str(),MeasurementID.c_str(),MeasurementID.c_str(),param.timeStart.c_str(),param.timeEnd.c_str());
vec_t vecResult2 = sqlite_db_ctrl::instance().GetDataSingleLine(count_sql);
if (vecResult2.size() > 0)
{
recive_x = atoi(vecResult2[0].c_str());
recive_y = atoi(vecResult2[1].c_str());
recive_z = atoi(vecResult2[2].c_str());
iTem.append((float(recive_feature)/(interval/featureInterVal)));
iTem.append(recive_feature);
iTem.append((float( recive_x)/(interval/waveInterVal)));
iTem.append(recive_x);
iTem.append((float(recive_y)/(interval/waveInterVal)));
iTem.append(recive_y);
iTem.append((float(recive_z)/(interval/waveInterVal)));
iTem.append(recive_z);
}
memset(count_sql,0,sizeof(count_sql));
snprintf(count_sql,sizeof(count_sql),
"SELECT "
"COUNT(*) FILTER (WHERE channelID = '%s-X') AS send_x,"
"COUNT(*) FILTER (WHERE channelID = '%s-Y') AS send_y,"
"COUNT(*) FILTER (WHERE channelID = '%s-Z') AS send_z "
"FROM ( "
"SELECT * FROM t_data_waveSend "
"WHERE sendMsg = 1 and timeStamp BETWEEN '%s' AND '%s');",MeasurementID.c_str(),MeasurementID.c_str(),MeasurementID.c_str(),param.timeStart.c_str(),param.timeEnd.c_str());
vec_t vecResult3 = sqlite_db_ctrl::instance().GetDataSingleLine(count_sql);
if (vecResult3.size() > 0)
{
send_x = atoi(vecResult3[0].c_str());
send_y = atoi(vecResult3[1].c_str());
send_z = atoi(vecResult3[2].c_str());
iTem.append((float(send_feature)/(interval/featureInterVal)));
iTem.append(send_feature);
iTem.append((float(send_x)/(interval/waveInterVal)));
iTem.append(send_x);
iTem.append((float(send_y)/(interval/waveInterVal)));
iTem.append(send_y);
iTem.append((float(send_z)/(interval/waveInterVal)));
iTem.append(send_z);
}
jsBody.append(iTem);
}
if (jsBody.size() == 0) {
jsonVal["success"] = false;
jsonVal["content"].resize(0);
} else {
jsonVal["content"] = (jsBody);
}
} else {
jsonVal["success"] = false;
jsonVal["content"].resize(0);
}
return show_value_.write(jsonVal);
}

View File

@ -54,6 +54,7 @@ enum WebCommand {
kWaveReceive = 62, kWaveReceive = 62,
kWaveSend = 63, kWaveSend = 63,
kFeatureSend = 64, kFeatureSend = 64,
kFeatureWaveCount = 65,
//CMT TCP //CMT TCP
kGateWayVersion = 80, kGateWayVersion = 80,

View File

@ -512,6 +512,16 @@ std::string LocalServer::HandleCgi_cmd(std::string &pData) {
std::string data = jd.JsonCmd_Cgi_64(param); std::string data = jd.JsonCmd_Cgi_64(param);
return data; return data;
}break; }break;
case kFeatureWaveCount:{
JsonData jd;
Param_65 param;
param.mPackageFlag = recvBody["package"].asInt();
param.timeStart = recvBody["timeStart"].asString();
param.timeEnd = recvBody["timeEnd"].asString();
std::string data = jd.JsonCmd_Cgi_65(param);
return data;
}
break;
default: default:
JsonData jd; JsonData jd;
std::string data = jd.JsonCmd_Cgi_default(); std::string data = jd.JsonCmd_Cgi_default();

View File

@ -17,7 +17,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(int short_addr, int &next_duration) { int SensorScheduler::StartSchedule(int short_addr, int &next_duration, 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()) {
@ -59,17 +59,17 @@ int SensorScheduler::StartSchedule(int short_addr, int &next_duration) {
current_request_ = kScheduleConfigSensor; current_request_ = kScheduleConfigSensor;
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_warn(zct, "[%d:%x] send eigen value in eigen slice", id, short_addr); // zlog_warn(zct, "[%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, next_task_id);
zlog_warn(zct, "[%d:%x] no need for eigen", id, short_addr); zlog_warn(zct, "[%d:%x] no need for eigen", id, short_addr);
return kScheduleWrongTime; return kScheduleResultNone;
} // }
} }
// } else { // } else {
// zlog_warn(zct, "[%d:%x] Invalid request, revive in %d eigen slice", id, short_addr, nth_eigen_slice_ + 1); // zlog_warn(zct, "[%d:%x] Invalid request, revive in %d eigen slice", id, short_addr, nth_eigen_slice_ + 1);
@ -107,22 +107,16 @@ int SensorScheduler::StartSchedule(int short_addr, int &next_duration) {
} }
} }
// if (update_.count(id)) { // wave_feature_set_inst::instance().GetWaveCfg(short_addr, g_x, g_y, g_z);
// // execute config // if (g_x || g_y || g_z) {
// zlog_warn(zct, "[%d:%x] in wave slice to update config", id, short_addr); // zlog_warn(zct, "[%d:%x] it is wave time", id, short_addr);
// current_request_ = kScheduleConfigSensor; // current_request_ = kScheduleWaveForm;
// return kScheduleConfigSensor; // return kScheduleWaveForm;
// } // } else {
wave_feature_set_inst::instance().GetWaveCfg(short_addr, g_x, g_y, g_z); next_duration = GetNextDuration(short_addr, next_task_id);
if (g_x || g_y || g_z) {
zlog_warn(zct, "[%d:%x] it is wave time", id, short_addr);
current_request_ = kScheduleWaveForm;
return kScheduleWaveForm;
} else {
next_duration = GetNextDuration(short_addr);
zlog_warn(zct, "[%d:%x] no need for wave", id, short_addr); zlog_warn(zct, "[%d:%x] no need for wave", id, short_addr);
return kScheduleWrongTime; return kScheduleResultNone;
} // }
} else { } else {
if (slice_sensor_id_[nth_wave_slice-1] == 0) { if (slice_sensor_id_[nth_wave_slice-1] == 0) {
zlog_warn(zct, "[%d:%x] in idle time", id, short_addr); zlog_warn(zct, "[%d:%x] in idle time", id, short_addr);
@ -139,33 +133,28 @@ int SensorScheduler::StartSchedule(int short_addr, int &next_duration) {
} }
} }
if (RetransferWave(short_addr)) { // if (RetransferWave(short_addr)) {
zlog_warn(zct, "[%d:%x] it is retransfer wave time", id, short_addr); // zlog_warn(zct, "[%d:%x] it is retransfer wave time", id, short_addr);
current_request_ = kScheduleWaveForm; // current_request_ = kScheduleWaveForm;
return kScheduleWaveForm; // return kScheduleWaveForm;
} else if (MissedWave(short_addr)) { // } else if (MissedWave(short_addr)) {
zlog_warn(zct, "[%d:%x] it is patch wave time", id, short_addr); // zlog_warn(zct, "[%d:%x] it is patch wave time", id, short_addr);
current_request_ = kScheduleWaveForm; // current_request_ = kScheduleWaveForm;
patch_set_.erase(short_addr); // patch_set_.erase(short_addr);
return kScheduleWaveForm; // return kScheduleWaveForm;
} // }
// if (update_.count(id)) {
// // execute config
// zlog_warn(zct, "[%d:%x] in idle time to update config", id, short_addr);
// current_request_ = kScheduleConfigSensor;
// return kScheduleConfigSensor;
// }
} }
// wrong time to come // wrong time to come
long available_ts = current_wave_start_ts_ + (nth_eigen_value_slice_ + 1) * eigen_value_send_interval_ + (id - 1) * eigen_value_send_duration_; long available_ts = current_wave_start_ts_ + (nth_eigen_value_slice_ + 1) * eigen_value_send_interval_ + (id - 1) * eigen_value_send_duration_;
next_duration = available_ts - current_ts_; next_duration = available_ts - current_ts_;
next_task_id = kScheduleEigenValue;
zlog_warn(zct, "[%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_warn(zct, "[%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 kScheduleResultNone;
} }
} }
} }
long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) { long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr, int& next_task_id) {
// current_ts_ = GetLocalTs(); // current_ts_ = GetLocalTs();
// nth_wave_start_slice_ = (current_ts_ - start_timestamp_) / wave_form_send_interval_; // nth_wave_start_slice_ = (current_ts_ - start_timestamp_) / wave_form_send_interval_;
// current_wave_start_ts_ = nth_wave_start_slice_ * wave_form_send_interval_ + start_timestamp_; // current_wave_start_ts_ = nth_wave_start_slice_ * wave_form_send_interval_ + start_timestamp_;
@ -177,6 +166,16 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) {
// if (seconds_in_current_eigen_slice_ < eigen_value_slice_total_seconds_ - 3) { // if (seconds_in_current_eigen_slice_ < eigen_value_slice_total_seconds_ - 3) {
// ts_in_eigen_slice_ = true; // ts_in_eigen_slice_ = true;
// } // }
nth_wave_start_slice_ = (current_ts_ - start_timestamp_) / wave_form_send_interval_;
current_wave_start_ts_ = nth_wave_start_slice_ * wave_form_send_interval_ + start_timestamp_;
seconds_in_current_wave_slice_ = current_ts_ - current_wave_start_ts_;
nth_eigen_value_slice_ = seconds_in_current_wave_slice_ / eigen_value_send_interval_;
seconds_in_current_eigen_slice_ = seconds_in_current_wave_slice_ % eigen_value_send_interval_;
ts_in_eigen_slice_ = false;
if (seconds_in_current_eigen_slice_ < eigen_value_slice_total_seconds_ - 3) {
ts_in_eigen_slice_ = true;
}
if (ts_in_eigen_slice_) { if (ts_in_eigen_slice_) {
int forward_wave_slice_num = nth_eigen_value_slice_ * wave_slice_num_per_eigen_interval_; int forward_wave_slice_num = nth_eigen_value_slice_ * wave_slice_num_per_eigen_interval_;
@ -185,6 +184,7 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) {
zlog_error(zct, "[Nxt] invaild id:%d, not find wave slice id", id); zlog_error(zct, "[Nxt] invaild id:%d, not find wave slice id", id);
long available_ts = current_wave_start_ts_ + eigen_value_send_interval_ + nth_eigen_slice_ * eigen_value_send_duration_; long available_ts = current_wave_start_ts_ + eigen_value_send_interval_ + nth_eigen_slice_ * eigen_value_send_duration_;
zlog_error(zct, "[Nxt] [%d] next feature send utc time:[%s]", id, GetUTCTime(available_ts).c_str()); zlog_error(zct, "[Nxt] [%d] next feature send utc time:[%s]", id, GetUTCTime(available_ts).c_str());
next_task_id = kScheduleEigenValue;
return available_ts; return available_ts;
} }
int wave_slice = wave_slice_iter->second; // 从1开始 int wave_slice = wave_slice_iter->second; // 从1开始
@ -230,7 +230,9 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) {
available_ts = current_wave_slice_ts; available_ts = current_wave_slice_ts;
free_slice_ocuppied_.insert(available_ts); free_slice_ocuppied_.insert(available_ts);
zlog_warn(zct, "[Nxt][%d:%x] %d nth free wave slice will be used to upgrade, utc time:[%s]", id, short_addr, i+forward_wave_slice_num, GetUTCTime(available_ts).c_str()); zlog_warn(zct, "[Nxt][%d:%x] %d nth free wave slice will be used to upgrade, utc time:[%s]", id, short_addr, i+forward_wave_slice_num, GetUTCTime(available_ts).c_str());
break; // break;
next_task_id = kScheduleUpgrade;
return available_ts;
} }
} }
} }
@ -246,7 +248,9 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) {
available_ts = current_wave_slice_ts; available_ts = current_wave_slice_ts;
free_slice_ocuppied_.insert(available_ts); free_slice_ocuppied_.insert(available_ts);
zlog_warn(zct, "[Nxt][%d:%x] %d nth free wave slice will be used to retransfer wave, utc time:[%s]", id, short_addr, i+forward_wave_slice_num, GetUTCTime(available_ts).c_str()); zlog_warn(zct, "[Nxt][%d:%x] %d nth free wave slice will be used to retransfer wave, utc time:[%s]", id, short_addr, i+forward_wave_slice_num, GetUTCTime(available_ts).c_str());
break; // break;
next_task_id = kScheduleWaveForm;
return available_ts;
} }
} }
} }
@ -259,32 +263,37 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) {
available_ts = current_wave_slice_ts; available_ts = current_wave_slice_ts;
free_slice_ocuppied_.insert(available_ts); free_slice_ocuppied_.insert(available_ts);
zlog_warn(zct, "[Nxt][%d:%x] %d nth free wave slice will be used to patch wave, utc time:[%s]", id, short_addr, i+forward_wave_slice_num, GetUTCTime(available_ts).c_str()); zlog_warn(zct, "[Nxt][%d:%x] %d nth free wave slice will be used to patch wave, utc time:[%s]", id, short_addr, i+forward_wave_slice_num, GetUTCTime(available_ts).c_str());
break; // break;
next_task_id = kScheduleWaveForm;
return available_ts;
} }
} }
} }
} }
} }
} }
if (send_wave_ts > 0 && available_ts > 0) { if (send_wave_ts > 0) {
long min_ts = std::min(send_wave_ts, available_ts); // long min_ts = std::min(send_wave_ts, available_ts);
zlog_warn(zct, "[Nxt] [%d:%x] next feature send utc time1:%s", id, short_addr, GetUTCTime(min_ts).c_str()); zlog_warn(zct, "[Nxt] [%d:%x] next wave send utc time1:%s", id, short_addr, GetUTCTime(send_wave_ts).c_str());
return min_ts; next_task_id = kScheduleWaveForm;
return send_wave_ts;
// return min_ts;
} }
if (send_wave_ts + available_ts > 0) { // if (send_wave_ts + available_ts > 0) {
long max_ts = std::max(send_wave_ts, available_ts); // long max_ts = std::max(send_wave_ts, available_ts);
zlog_warn(zct, "[Nxt] [%d:%x] next feature send utc time2:%s", id, short_addr, GetUTCTime(max_ts).c_str()); // zlog_warn(zct, "[Nxt] [%d:%x] next feature send utc time2:%s", id, short_addr, GetUTCTime(max_ts).c_str());
return max_ts; // return max_ts;
} // }
} }
// 如果是在当前波形时间窗中,不管是空闲时间窗,还是发送波形的时间窗,下一个时间窗是特征值 // 如果是在当前波形时间窗中,不管是空闲时间窗,还是发送波形的时间窗,下一个时间窗是特征值
long available_ts = current_wave_start_ts_ + (nth_eigen_value_slice_ + 1)* eigen_value_send_interval_ + (id - 1) * eigen_value_send_duration_; long available_ts = current_wave_start_ts_ + (nth_eigen_value_slice_ + 1)* eigen_value_send_interval_ + (id - 1) * eigen_value_send_duration_;
zlog_warn(zct, "[Nxt] [%d:%x] next feature send utc time3:[%s]", id, short_addr, GetUTCTime(available_ts).c_str()); zlog_warn(zct, "[Nxt] [%d:%x] next feature send utc time3:[%s]", id, short_addr, GetUTCTime(available_ts).c_str());
next_task_id = kScheduleEigenValue;
return available_ts; return available_ts;
} }
int SensorScheduler::GetNextDuration(int short_addr) { int SensorScheduler::GetNextDuration(int short_addr, 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()) {
@ -293,17 +302,44 @@ int SensorScheduler::GetNextDuration(int short_addr) {
} else { } else {
id = iter->second; id = iter->second;
} }
long current_ts = GetLocalTs(); current_ts_ = GetLocalTs();
long next_ts = CalcNextTimestamp(id, short_addr); // nth_wave_start_slice_ = (current_ts_ - start_timestamp_) / wave_form_send_interval_;
int duration = next_ts - current_ts; // current_wave_start_ts_ = nth_wave_start_slice_ * wave_form_send_interval_ + start_timestamp_;
// seconds_in_current_wave_slice_ = current_ts_ - current_wave_start_ts_;
// nth_eigen_value_slice_ = seconds_in_current_wave_slice_ / eigen_value_send_interval_;
long next_ts = CalcNextTimestamp(id, short_addr, next_task_id);
int duration = next_ts - current_ts_;
if (duration < 0 || duration > eigen_value_send_interval_) { if (duration < 0 || duration > eigen_value_send_interval_) {
zlog_warn(zct, "[Nxt] exception duration: %d", duration); zlog_warn(zct, "[Nxt] exception duration: %d", duration);
duration = eigen_value_send_interval_; duration = eigen_value_send_interval_;
}else if(duration < 9){
zlog_warn(zct, "[Nxt] exception duration: %d", duration);
duration = 10;
} }
zlog_warn(zct, "[Nxt] [%d:%x] next duration is %d", id, short_addr, duration); zlog_warn(zct, "[Nxt] [%d:%x] next duration: %d, taskid: %d", id, short_addr, duration, next_task_id);
return duration; return duration;
} }
// int SensorScheduler::GetNextDuration(int short_addr) {
// int id = 0;
// auto iter = short_addr_map_.find(short_addr);
// if (iter == short_addr_map_.end()) {
// zlog_error(zct, "cannot find id for short_addr %x", short_addr);
// return 0;
// } else {
// id = iter->second;
// }
// long current_ts = GetLocalTs();
// long next_ts = CalcNextTimestamp(id, short_addr);
// int duration = next_ts - current_ts;
// if (duration < 0 || duration > eigen_value_send_interval_) {
// zlog_warn(zct, "[Nxt] exception duration: %d", duration);
// duration = eigen_value_send_interval_;
// }
// zlog_warn(zct, "[Nxt] [%d:%x] next duration is %d", id, short_addr, duration);
// return duration;
// }
SensorScheduler::SensorScheduler() { SensorScheduler::SensorScheduler() {
support_modification_ = true; support_modification_ = true;
std::ifstream schedule_file(SCHEDULE_CONFIG); std::ifstream schedule_file(SCHEDULE_CONFIG);
@ -414,7 +450,9 @@ bool SensorScheduler::MissedWave(uint16_t short_addr) {
} }
void SensorScheduler::WaveSuccess(uint16_t short_addr) { void SensorScheduler::WaveSuccess(uint16_t short_addr) {
zlog_warn(zct, "[WaveSuccess][%x]", short_addr);
success_set_.insert(short_addr); success_set_.insert(short_addr);
patch_set_.erase(short_addr);
auto iter = failure_map_.find(short_addr); auto iter = failure_map_.find(short_addr);
if (iter != failure_map_.end()) { if (iter != failure_map_.end()) {
zlog_warn(zct, "[WaveSuccess][%x] try %d times success", short_addr, 4 - iter->second); zlog_warn(zct, "[WaveSuccess][%x] try %d times success", short_addr, 4 - iter->second);

View File

@ -38,13 +38,14 @@ public:
// kScheduleEigenValue kScheduleWaveForm // kScheduleEigenValue kScheduleWaveForm
// 上面4个结束调GetNextDuration()获取休眠时间 // 上面4个结束调GetNextDuration()获取休眠时间
// 如果是kScheduleWrongTime, 此函数next_duration表明休眠时间 // 如果是kScheduleWrongTime, 此函数next_duration表明休眠时间
int StartSchedule(int short_addr, int &next_duration); int StartSchedule(int short_addr, int &next_duration, int &next_task_id);
int GetNextDuration(int short_addr); int GetNextDuration(int short_addr,int &next_task_id);
// int GetNextDuration(int short_addr);
int WaveError(uint16_t short_addr); int WaveError(uint16_t short_addr);
void WaveSuccess(uint16_t short_addr); void WaveSuccess(uint16_t short_addr);
long GetBaseTimestamp(int id); long GetBaseTimestamp(int id);
long CalcNextTimestamp(int id, uint16_t short_addr); long CalcNextTimestamp(int id, uint16_t short_addr, int& next_task_id);
// 当有传感器需要更新配置时调用 // 当有传感器需要更新配置时调用
int UpdateSensorConfig(int short_addr); int UpdateSensorConfig(int short_addr);
@ -160,4 +161,4 @@ private:
typedef boost::container::dtl::singleton_default<SensorScheduler> scheduler; typedef boost::container::dtl::singleton_default<SensorScheduler> scheduler;
#endif // SCHEDULE_HPP_ #endif // SCHEDULE_HPP_

View File

@ -44,7 +44,7 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) {
ret = read_data(fd, buff, BUF_LENGTH, 10); ret = read_data(fd, buff, BUF_LENGTH, 10);
if (ret <= 0) { if (ret <= 0) {
timeoutflag++; timeoutflag++;
if (timeoutflag > 300) { if (timeoutflag > 200) {
DealReviveDuration(wave_shortAddr); DealReviveDuration(wave_shortAddr);
zlog_warn(zct, "===============0x9999 timeout= %d offSize = %d===============shortAddr = %02x%02x", timeoutflag, offSize,UINT16_HIGH(wave_shortAddr),UINT16_LOW(wave_shortAddr)); zlog_warn(zct, "===============0x9999 timeout= %d offSize = %d===============shortAddr = %02x%02x", timeoutflag, offSize,UINT16_HIGH(wave_shortAddr),UINT16_LOW(wave_shortAddr));
zlog_warn(zct, "0x9999 timeout %d===============Size = %d", timeoutflag, offSize); zlog_warn(zct, "0x9999 timeout %d===============Size = %d", timeoutflag, offSize);
@ -73,7 +73,7 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) {
memcpy(mUartRecvTmpBuf + offSize, buff, ret); memcpy(mUartRecvTmpBuf + offSize, buff, ret);
offSize = offSize + ret; offSize = offSize + ret;
if (offSize > BUF_LENGTH * 15) { if (offSize > BUF_LENGTH * 15) {
zlog_warn(zct, "maxSize = %d", offSize); zlog_info(zct, "maxSize = %d", offSize);
memset(mUartRecvTmpBuf, 0, BUF_LENGTH); memset(mUartRecvTmpBuf, 0, BUF_LENGTH);
timeoutflag = 0; timeoutflag = 0;
offSize = 0; offSize = 0;
@ -84,8 +84,8 @@ int Uart::UartRecv(int fd, char srcshow, char *buffer) {
} }
} else { } else {
memset(buff, 0x00, sizeof(buff)); memset(buff, 0, sizeof(buff));
ret = read_data(fd, buff, BUF_LENGTH, 50); ret = read_data(fd, buff, BUF_LENGTH, 10);
if (ret <= 0) { if (ret <= 0) {
timeoutflag++; timeoutflag++;
if (timeoutflag > 5) { if (timeoutflag > 5) {
@ -144,6 +144,9 @@ Uart::Uart() : mUart(mIoSev), mStrand(mIoSev) {
VecWaveDataX.reserve(1000); VecWaveDataX.reserve(1000);
VecWaveDataY.reserve(1000); VecWaveDataY.reserve(1000);
VecWaveDataZ.reserve(1500); VecWaveDataZ.reserve(1500);
memset(send_data, 0, sizeof(send_data));
last_short_addr = 0;
last_time = 0;
} }
Uart::~Uart() { Uart::~Uart() {
@ -254,7 +257,7 @@ int Uart::ZigbeeTest() {
void Uart::WriteToUart(const char *strSend, int pLen) { void Uart::WriteToUart(const char *strSend, int pLen) {
if (!bUpdate) if (!bUpdate)
{ {
printf( "Write To Uart Start:\n"); printf( "\nWrite To Uart Start: %s\n",GetCurrentTime().c_str());
for (int i = 0; i < pLen; i++) { for (int i = 0; i < pLen; i++) {
printf("%02X ", *(strSend + i) & 0xFF); printf("%02X ", *(strSend + i) & 0xFF);
} }
@ -348,7 +351,9 @@ void Uart::GetLocalZigbeeRSSI(uint16_t ushortAdd){
zlog_info(zct, "Local Zigbee Signal !\n"); zlog_info(zct, "Local Zigbee Signal !\n");
mssleep(20000); mssleep(20000);
getZigbeeSignal(ushortAdd); getZigbeeSignal(ushortAdd);
mssleep(10000); mssleep(20000);
getZigbeeSignal(ushortAdd);
mssleep(20000);
} }
int Uart::DealAskTask(uint16_t ushortAdd){ int Uart::DealAskTask(uint16_t ushortAdd){
char wherecon[50]={0}; char wherecon[50]={0};
@ -359,57 +364,69 @@ int Uart::DealAskTask(uint16_t ushortAdd){
zlog_warn(zct, "device info not found %02x%02x ", UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd)); zlog_warn(zct, "device info not found %02x%02x ", UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd));
return 1; return 1;
} }
ModifyDistAddr(ushortAdd); int next_duration = 0,next_task_id = 0;
int next_duration = 0; int taskID;
int taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration);
ScheduleTask scheduleTask; ScheduleTask scheduleTask;
zlog_info(zct, "taskID = %d ", taskID); taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration, next_task_id);
if (taskID == kScheduleEigenValue) //1.特征值 zlog_info(zct, "taskID = %d next_duration = %d next_task_id = %d", taskID, next_duration, next_task_id);
{ if (taskID == kScheduleConfigSensor)
char localtimestamp[32] = {0x00};
int millisecond = 0;
GetTimeNet(localtimestamp, 1);
scheduleTask.cmd = MEAS_EVAL;
scheduleTask.shortAddr = ushortAdd;
scheduleTask.timeStamp = atoi(localtimestamp);
TaskResp(scheduleTask);
}
else if (taskID == kScheduleWaveForm) //2.波形
{
wave_shortAddr = ushortAdd;
GetLocalZigbeeRSSI(ushortAdd);
scheduleTask.cmd = SIGNAL_STRENGTH;
scheduleTask.shortAddr = ushortAdd;
scheduleTask.duration = next_duration;
TaskResp(scheduleTask);
}
else if (taskID == kScheduleUpgrade) //3.升级
{
UpdateWirelessNode(ushortAdd);
}else if (taskID == kScheduleConfigSensor) //4.更新配置
{ {
scheduleTask.cmd = CONFIG; scheduleTask.cmd = CONFIG;
scheduleTask.duration = next_duration;
scheduleTask.next_taskID = next_task_id;
scheduleTask.shortAddr = ushortAdd; scheduleTask.shortAddr = ushortAdd;
mssleep(50000);
TaskResp(scheduleTask); TaskResp(scheduleTask);
mssleep(50000); mssleep(50000);
UpdateConfig(ushortAdd); UpdateConfig(ushortAdd);
}else if (taskID == kScheduleWrongTime) //5.异常连接 }
{ if(next_task_id == kScheduleWaveForm){
scheduleTask.cmd = REVIVE_DURATION; scheduleTask.cmd = REVIVE_DURATION;
scheduleTask.shortAddr = ushortAdd; scheduleTask.shortAddr = ushortAdd;
scheduleTask.duration = next_duration; scheduleTask.duration = next_duration;
zlog_info(zct, "next_duration = %d ", next_duration); scheduleTask.next_taskID = WAVE_CMD;
TaskResp(scheduleTask); TaskResp(scheduleTask);
}else if (taskID == 13) //6.RSSI }else if (next_task_id == kScheduleEigenValue) {
{ scheduleTask.cmd = REVIVE_DURATION;
scheduleTask.cmd = SIGNAL_STRENGTH;
scheduleTask.shortAddr = ushortAdd; scheduleTask.shortAddr = ushortAdd;
scheduleTask.duration = next_duration; scheduleTask.duration = next_duration;
scheduleTask.next_taskID = MEAS_EVAL;
TaskResp(scheduleTask);
}else if(next_task_id == kScheduleUpgrade){
scheduleTask.cmd = REVIVE_DURATION;
scheduleTask.shortAddr = ushortAdd;
scheduleTask.duration = next_duration;
scheduleTask.next_taskID = UPGRADE;
TaskResp(scheduleTask); TaskResp(scheduleTask);
} }
// if (next_task_id == kScheduleEigenValue) //1.特征值
// {
// }
// else if (next_task_id == kScheduleWaveForm) //2.波形
// {
// DealReviveDuration(ushortAdd);
// }
// else if (next_task_id == kScheduleUpgrade) //3.升级
// {
// UpdateWirelessNode(ushortAdd);
// }else if (taskID == kScheduleConfigSensor) //4.更新配置
// {
// scheduleTask.cmd = CONFIG;
// scheduleTask.shortAddr = ushortAdd;
// mssleep(50000);
// TaskResp(scheduleTask);
// mssleep(50000);
// UpdateConfig(ushortAdd);
// }else if (taskID == kScheduleWrongTime) //5.异常连接
// {
// scheduleTask.cmd = REVIVE_DURATION;
// scheduleTask.shortAddr = ushortAdd;
// scheduleTask.duration = next_duration;
// zlog_info(zct, "next_duration = %d ", next_duration);
// TaskResp(scheduleTask);
// }
zlog_info(zct, " DealAskTask end" );
return 0; return 0;
} }
@ -420,12 +437,13 @@ int Uart::DealException(const char* pData){
int Uart::DealReviveDuration(uint16_t ushortAdd){ int Uart::DealReviveDuration(uint16_t ushortAdd){
ScheduleTask scheduleTask; ScheduleTask scheduleTask;
uint16_t next_duration = scheduler::instance().GetNextDuration(ushortAdd); int next_taskID = 0;
zlog_info(zct, "next_duration = %d ", next_duration); uint16_t next_duration = scheduler::instance().GetNextDuration(ushortAdd,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;
scheduleTask.duration = next_duration; scheduleTask.duration = next_duration;
scheduleTask.next_taskID = next_taskID & 0xFF;
TaskResp(scheduleTask); TaskResp(scheduleTask);
return 0; return 0;
} }
@ -443,6 +461,8 @@ int Uart::DealConfig(uint16_t ushortAdd){
int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){ int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){
zlog_info(zct, "DealWaveCompress "); zlog_info(zct, "DealWaveCompress ");
now_task = WAVE_CMD;
WaveResp(ushortAdd);
char buf[20] = {0x00}; char buf[20] = {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);
@ -456,7 +476,38 @@ int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){
tempchannel.CountZ = BUILD_UINT32(pData[21], pData[20],pData[19],pData[18]); tempchannel.CountZ = BUILD_UINT32(pData[21], pData[20],pData[19],pData[18]);
g_mapCompress[strShortAddr] = tempchannel; g_mapCompress[strShortAddr] = tempchannel;
wave_shortAddr = ushortAdd;
char sensor_rssi[10] = {0x00};
sprintf(sensor_rssi, "%02d", pData[22] & 0xFF);
if (!strcmp(sensor_rssi, "00") || !strcmp(sensor_rssi, "0")) {
char errorInfo[100] = {0x00};
sprintf(errorInfo, "No RSSI %s", sensor_rssi);
zlog_error(zct, errorInfo);
} else {
char tableName[100] = {0x00};
char whereCon[100] = {0};
char updateSql[100] = {0};
sprintf(whereCon, "zigbeeShortAddr='%02x%02x'", UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd));
vec_t vecDataNodeNo = sqlite_db_ctrl::instance().GetDataSingleLine(T_SENSOR_INFO(TNAME), " MeasurementID,RSSI ", whereCon);
sprintf(tableName, "t_dataStatic_%s", (char *)vecDataNodeNo[0].c_str());
memset(whereCon,0,sizeof(whereCon));
sprintf(whereCon, "dataNodeNo='%s' order by timeStamp desc limit 1", vecDataNodeNo[0].c_str());
std::string timestamp_last = sqlite_db_ctrl::instance().GetData(tableName, " timeStamp ", whereCon);
sprintf(updateSql, "zigbeeSignalNode = '%02d' ",atoi(sensor_rssi));
memset(whereCon,0,sizeof(whereCon));
sprintf(whereCon, "dataNodeNo='%s' and timeStamp = '%s'", (char*)vecDataNodeNo[0].c_str(),timestamp_last.c_str());
sqlite_db_ctrl::instance().UpdateTableData(tableName, updateSql, whereCon);
std::vector<std::string> vParamRSSI;
boost::split(vParamRSSI, vecDataNodeNo[1], boost::is_any_of(","), boost::token_compress_on);
memset(updateSql,0,sizeof(updateSql));
memset(whereCon,0,sizeof(whereCon));
if (vParamRSSI.size() > 0) {
sprintf(updateSql, "RSSI = '%s,%02d' ", vParamRSSI[0].c_str(), pData[22] & 0xFF);
sprintf(whereCon, "dataNodeNo='%s'", (char *)vecDataNodeNo[0].c_str());
sqlite_db_ctrl::instance().UpdateTableData(T_SENSOR_INFO(TNAME), updateSql, whereCon);
}
}
zlog_info(zct, "count X = %d,Y = %d,Z = %d ", tempchannel.CountX, tempchannel.CountY, tempchannel.CountZ); zlog_info(zct, "count X = %d,Y = %d,Z = %d ", tempchannel.CountX, tempchannel.CountY, tempchannel.CountZ);
zlog_info(zct, "compress X = %d,Y = %d,Z = %d ", tempchannel.compressChannelX, tempchannel.compressChannelY, tempchannel.compressChannelZ); zlog_info(zct, "compress X = %d,Y = %d,Z = %d ", tempchannel.compressChannelX, tempchannel.compressChannelY, tempchannel.compressChannelZ);
return 0; return 0;
@ -530,13 +581,43 @@ int Uart::DealUpgrade(uint16_t ushortAdd,int status){
return 0; return 0;
} }
int Uart::DealFeatureValue(const char *pData,uint16_t ushortAdd){
zlog_info(zct, "DealFeatureValue ");
char localtimestamp[32] = {0};
GetTimeNet(localtimestamp, 1);
std::string nowTimetamp = std::string(localtimestamp);
long now_time = atol(nowTimetamp.c_str());
if(ushortAdd == last_short_addr && (now_time - last_time) < 5){
zlog_info(zct, "DealFeatureValue short_addr_last = %02x%02x,timestamp_last = %ld,nowTime = %ld",UINT16_HIGH(ushortAdd), UINT16_LOW(ushortAdd),last_time,now_time);
int iRet = DealDataNodeFeature(pData, 0);
if (iRet != 0)
{
return -1;
}
DealAskTask(ushortAdd);
}else {
DealAskTask(ushortAdd);
DealDataNodeFeature(pData, 0);
}
GetTimeNet(localtimestamp, 1);
nowTimetamp = std::string(localtimestamp);
last_time = atol(nowTimetamp.c_str());
return 0;
}
void Uart::DealRecvData(const char *pData) { void Uart::DealRecvData(const char *pData) {
uint16_t ushortAdd = BUILD_UINT16(pData[3] & 0xFF, pData[4] & 0xFF); uint16_t ushortAdd = BUILD_UINT16(pData[3] & 0xFF, pData[4] & 0xFF);
uint8_t command = pData[5] & 0xFF; uint8_t command = pData[5] & 0xFF;
uint8_t recvcode = pData[7] & 0xFF; uint8_t recvcode = pData[7] & 0xFF;
int next_duration = 0,next_task_id = 0;
int taskID = 0;
ScheduleTask scheduleTask;
zlog_info(zct, "shortAdd = %02x%02x,command = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command); zlog_info(zct, "shortAdd = %02x%02x,command = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command);
if (ushortAdd != last_short_addr){
mssleep(50000);
ModifyDistAddr(ushortAdd);
mssleep(50000);
}
switch (command) { switch (command) {
case DEVICE_INF: case DEVICE_INF:
DealDataNodeInfo(pData); DealDataNodeInfo(pData);
@ -544,31 +625,28 @@ void Uart::DealRecvData(const char *pData) {
case DEVICE_INF2: case DEVICE_INF2:
DealDataNodeName(pData); DealDataNodeName(pData);
break; break;
case ASK_TASK: // case ASK_TASK:
DealAskTask(ushortAdd); // DealAskTask(ushortAdd);
break; // break;
case DEVICE_EXCEPTION: case DEVICE_EXCEPTION:
DealException(pData); DealException(pData);
break; break;
case MEAS_EVAL: case MEAS_EVAL:
DealDataNodeFeature(pData, 0); DealFeatureValue(pData, ushortAdd);
DealReviveDuration(ushortAdd);
break; break;
case UPGRADE: case UPGRADE:
if (recvcode == 0){ if (recvcode == 0){
DealUpgrade(ushortAdd,2); zlog_info(zbt, "[UPLOAD SUCCESS] shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode);
scheduler::instance().UpgradeResult(ushortAdd,0);
zlog_info(zbt, "[UPGRADE SUCCESS] shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode);
}else if (recvcode == 5) }else if (recvcode == 5)
{ {
DealUpgrade(ushortAdd,2); DealUpgrade(ushortAdd,2);
scheduler::instance().UpgradeResult(ushortAdd,0); scheduler::instance().UpgradeResult(ushortAdd,0);
zlog_warn(zbt, "[UPGRADE ALREADY] shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode); zlog_warn(zbt, "[UPLOAD ALREADY] shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode);
}else }else
{ {
DealUpgrade(ushortAdd,3); DealUpgrade(ushortAdd,3);
scheduler::instance().UpgradeResult(ushortAdd,recvcode); scheduler::instance().UpgradeResult(ushortAdd,recvcode);
zlog_warn(zbt, "[UPGRADE FAILED] shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode); zlog_warn(zbt, "[UPLOAD FAILED] shortAdd = %02x%02x,command = %d,recvcode = %d ",UINT16_HIGH(ushortAdd),UINT16_LOW(ushortAdd),command,recvcode);
} }
break; break;
case CONFIG: case CONFIG:
@ -581,13 +659,27 @@ void Uart::DealRecvData(const char *pData) {
} }
break; break;
case WAVE_COMPRESS: case WAVE_COMPRESS:
GetLocalZigbeeRSSI(ushortAdd);
DealWaveCompress(pData,ushortAdd); DealWaveCompress(pData,ushortAdd);
break; break;
case SIGNAL_STRENGTH: case UPGRADE_ASK:
DealSensorRSSI(pData,ushortAdd); mssleep(50000);
taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration, next_task_id);
taskID = kScheduleUpgrade;
if (taskID == kScheduleUpgrade){
UpdateWirelessNode(ushortAdd);
}else if(taskID == kScheduleResultNone){
scheduleTask.cmd = REVIVE_DURATION;
scheduleTask.shortAddr = ushortAdd;
scheduleTask.duration = next_duration;
scheduleTask.next_taskID = next_task_id;
TaskResp(scheduleTask);
}
break; break;
default: break; default: break;
} }
last_short_addr = ushortAdd;
} }
void Uart::DealDataNodeName(const char *pData) { void Uart::DealDataNodeName(const char *pData) {
@ -599,7 +691,7 @@ void Uart::DealDataNodeName(const char *pData) {
sprintf(szShortAdd, "%02x%02x", pData[3] & 0xFF, pData[4] & 0xFF); sprintf(szShortAdd, "%02x%02x", pData[3] & 0xFF, pData[4] & 0xFF);
memcpy(NodeName, &pData[7], 64); memcpy(NodeName, &pData[7], 64);
memcpy(shortAdd, &pData[3], 2); memcpy(shortAdd, &pData[3], 2);
char whereCon[128] = {0}; char whereCon[64] = {0};
char uplCon[200] = {0x00}; char uplCon[200] = {0x00};
char nodeWaveSend[10] = {0x00}; char nodeWaveSend[10] = {0x00};
@ -608,11 +700,13 @@ void Uart::DealDataNodeName(const char *pData) {
} }
char MeasurementID[100] = {0x00}; char MeasurementID[100] = {0x00};
sprintf(MeasurementID, "%02x%02x%02x%02x%02x%02x%02x%02x", pData[71], pData[72], pData[73], pData[74], pData[75], pData[76], pData[77], pData[78]); sprintf(MeasurementID, "%02x%02x%02x%02x%02x%02x%02x%02x", pData[71], pData[72], pData[73], pData[74], pData[75], pData[76], pData[77], pData[78]);
sprintf(nodeWaveSend, "%d,%d,%d", GET_BIT(pData[79], 0), GET_BIT(pData[79], 1), GET_BIT(pData[79], 2));
char gbkNodeName[128] = {0x00}; char gbkNodeName[128] = {0x00};
sprintf(whereCon, "zigbeeShortAddr='%s'", szShortAdd); sprintf(whereCon, "zigbeeShortAddr='%s'", szShortAdd);
zlog_info(zct, "whereCon = %s", whereCon); zlog_info(zct, "whereCon = %s", whereCon);
array_t vecRes = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_INFO(TNAME), " dataNodeNo, MeasurementID,hardVersion,softVersion", whereCon); array_t vecRes = sqlite_db_ctrl::instance().GetDataMultiLine(T_SENSOR_INFO(TNAME), " dataNodeNo, MeasurementID,hardVersion,softVersion", whereCon);
zlog_info(zct, "vecRes = %d", vecRes.size());
if (vecRes.size() > 1) { if (vecRes.size() > 1) {
for (size_t i = 0; i < vecRes.size(); i++) { for (size_t i = 0; i < vecRes.size(); i++) {
if (vecRes[i][1] != "") { if (vecRes[i][1] != "") {
@ -642,6 +736,8 @@ void Uart::DealDataNodeName(const char *pData) {
} }
} }
} }
zlog_info(zct, "vecRes22 = %d", vecRes.size());
zlog_info(zct, "hardVersion = %s,softVersion = %s", vecRes[0][2].c_str(),vecRes[0][3].c_str());
std::string hardVersion = vecRes[0][2]; std::string hardVersion = vecRes[0][2];
std::string softVersion = vecRes[0][3]; std::string softVersion = vecRes[0][3];
if ((hardVersion == "3.0" && compareVersions(softVersion, "3.6") == -1) || (hardVersion == "4.0" && compareVersions(softVersion, "4.6") == -1)|| (hardVersion == "1.0" && compareVersions(softVersion,"1.2") == -1)) { if ((hardVersion == "3.0" && compareVersions(softVersion, "3.6") == -1) || (hardVersion == "4.0" && compareVersions(softVersion, "4.6") == -1)|| (hardVersion == "1.0" && compareVersions(softVersion,"1.2") == -1)) {
@ -651,7 +747,8 @@ void Uart::DealDataNodeName(const char *pData) {
sprintf(whereCon, "zigbeeShortAddr='%s'", szShortAdd); sprintf(whereCon, "zigbeeShortAddr='%s'", szShortAdd);
std::string strNodeName(NodeName); std::string strNodeName(NodeName);
zlog_info(zct, "strNodeName = %s", strNodeName.c_str()); zlog_info(zct, "strNodeName = %s", strNodeName.c_str());
solve(gbkNodeName, NodeName); //solve(gbkNodeName, NodeName);
hexToAscii(strNodeName.c_str(), gbkNodeName);
zlog_info(zct, "gbkNodeName = %s", gbkNodeName); zlog_info(zct, "gbkNodeName = %s", gbkNodeName);
zlog_info(zct, "NodeName = %s", NodeName); zlog_info(zct, "NodeName = %s", NodeName);
zlog_info(zct, "whereCon = %s", whereCon); zlog_info(zct, "whereCon = %s", whereCon);
@ -687,6 +784,8 @@ void Uart::DealDataNodeInfo(const char *pData) {
RecvData *pRecvData = (RecvData *)pData; RecvData *pRecvData = (RecvData *)pData;
zlog_warn(zct, "recv remote zigbee module info shortAddr %02x%02x", pRecvData->Data[46], pRecvData->Data[47]); zlog_warn(zct, "recv remote zigbee module info shortAddr %02x%02x", pRecvData->Data[46], pRecvData->Data[47]);
char buf[32] = {0}; char buf[32] = {0};
char whereCon[64] = {0};
uint16_t ushortAdd = BUILD_UINT16(pData[3] & 0xFF, pData[4] & 0xFF);
char chTemp = pRecvData->Data[0]; //设备状态标志 1 byte char chTemp = pRecvData->Data[0]; //设备状态标志 1 byte
DataNodeInfo dataNodeInfo; DataNodeInfo dataNodeInfo;
dataNodeInfo.EquipSta = GET_BIT(chTemp, 2); dataNodeInfo.EquipSta = GET_BIT(chTemp, 2);
@ -829,6 +928,9 @@ void Uart::DealDataNodeInfo(const char *pData) {
dataNodeInfo.SamplingRate = 192000; dataNodeInfo.SamplingRate = 192000;
} }
} }
int upgrade = GET_BIT(chTemp, 7);
// 54=》序号25 ACC采样时间 // 54=》序号25 ACC采样时间
memset(buf, 0, 32); memset(buf, 0, 32);
sprintf(buf, "%u", pRecvData->Data[54]); // ACC 采样时间 1 byte sprintf(buf, "%u", pRecvData->Data[54]); // ACC 采样时间 1 byte
@ -889,8 +991,9 @@ void Uart::DealDataNodeInfo(const char *pData) {
memset(buf, 0, 32); memset(buf, 0, 32);
sprintf(buf, "%d", chTemp); sprintf(buf, "%d", chTemp);
dataNodeInfo.VIntegralFilterFrequency = atoi(buf); dataNodeInfo.VIntegralFilterFrequency = atoi(buf);
sprintf(whereCon, "dataNodeNo='%s'", dataNodeInfo.ZigbeeLongAddr.c_str());
char whereCon[64] = {0}; std::string soft_version = sqlite_db_ctrl::instance().GetData(T_SENSOR_INFO(TNAME), " softVersion ", whereCon);
sprintf(whereCon, "dataNodeNo='%s'", dataNodeInfo.ZigbeeLongAddr.c_str()); sprintf(whereCon, "dataNodeNo='%s'", dataNodeInfo.ZigbeeLongAddr.c_str());
if (sqlite_db_ctrl::instance().GetTableRows(T_SENSOR_INFO(TNAME), whereCon) > 0) { if (sqlite_db_ctrl::instance().GetTableRows(T_SENSOR_INFO(TNAME), whereCon) > 0) {
char updateSql[1024] = {0}; char updateSql[1024] = {0};
@ -928,7 +1031,18 @@ void Uart::DealDataNodeInfo(const char *pData) {
zlog_error(zct, "res = %d", res); zlog_error(zct, "res = %d", res);
} }
} }
zlog_info(zct, "upgrade = %d", upgrade);
if (upgrade == 1)
{
zlog_info(zct, "soft_version = %s,dataNodeInfo.SoftVersion = %s", soft_version.c_str(),dataNodeInfo.SoftVersion.c_str());
if (dataNodeInfo.SoftVersion != soft_version) {
DealUpgrade(ushortAdd,2);
scheduler::instance().UpgradeResult(ushortAdd,0);
}else{
DealUpgrade(ushortAdd,3);
scheduler::instance().UpgradeResult(ushortAdd,3);
}
}
Json::Value jsonVal; Json::Value jsonVal;
jsonVal.clear(); jsonVal.clear();
jsonVal["cmd"] = "26"; jsonVal["cmd"] = "26";
@ -1177,9 +1291,9 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
memcpy(RecvBuf, (char *)&UartRecvBuf[i], 100); memcpy(RecvBuf, (char *)&UartRecvBuf[i], 100);
DealDataNodeWave(RecvBuf, command); DealDataNodeWave(RecvBuf, command);
mPackgeIndex = (unsigned int)UartRecvBuf[i + 6]; mPackgeIndex = (unsigned int)UartRecvBuf[i + 6];
} else if (now_task != WAVE_CMD && (command == ASK_TASK || command == DEVICE_INF || command == MEAS_EVAL || command == CONFIG || command == UPGRADE || command == DEVICE_INF2 || command == SIGNAL_STRENGTH || command == DEVICE_EXCEPTION || command == WAVE_COMPRESS)) { } else if (now_task != WAVE_CMD && ( command == DEVICE_INF || command == MEAS_EVAL || command == CONFIG || command == UPGRADE || command == DEVICE_INF2 || command == SIGNAL_STRENGTH || command == DEVICE_EXCEPTION || command == UPGRADE_ASK)) {
char RecvBuf[100] = {0x00}; char RecvBuf[100] = {0x00};
if (command == ASK_TASK ) if (command == UPGRADE_ASK)
{ {
memcpy(RecvBuf, &UartRecvBuf[i], 8); memcpy(RecvBuf, &UartRecvBuf[i], 8);
if (!CheckCrc(RecvBuf, 7)) { if (!CheckCrc(RecvBuf, 7)) {
@ -1187,7 +1301,7 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
break; break;
} }
} }
if (command == CONFIG || command == CONFIG_INF2 || command == UPGRADE || command == SIGNAL_STRENGTH || command == DEVICE_EXCEPTION || command == WAVE_COMPRESS) if (command == CONFIG || command == CONFIG_INF2 || command == UPGRADE || command == SIGNAL_STRENGTH || command == DEVICE_EXCEPTION)
{ {
memcpy(RecvBuf, &UartRecvBuf[i], 9); memcpy(RecvBuf, &UartRecvBuf[i], 9);
if (!CheckCrc(RecvBuf, 8)) { if (!CheckCrc(RecvBuf, 8)) {
@ -1205,19 +1319,19 @@ int Uart::FindRecvPackage(int bytesRead, char *mUartRecvBuf, char *head) {
} }
DealRecvData(RecvBuf); DealRecvData(RecvBuf);
}else if(now_task == WAVE_CMD && command == WAVE_COMPRESS){ }else if( command == WAVE_COMPRESS && now_task != WAVE_CMD) {
memcpy(RecvBuf, &UartRecvBuf[i], 23); memcpy(RecvBuf, &UartRecvBuf[i], 24);
if (!CheckCrc(RecvBuf, 22)) { if (!CheckCrc(RecvBuf, 23)) {
zlog_warn(zct, "CheckCrc error ShortAddr :%s command = %d ", strShortAddr.c_str(), command); zlog_warn(zct, "CheckCrc error ShortAddr :%s command = %d ", strShortAddr.c_str(), command);
break; break;
} }
char tmp[23] = {0x00}; // char tmp[23] = {0x00};
char tmp2[23] = {0x00}; // char tmp2[23] = {0x00};
for (int j = 0; j < 23; j++) { // for (int j = 0; j < 23; j++) {
sprintf(tmp, "%02x ", UartRecvBuf[i + j] & 0xff); // sprintf(tmp, "%02x ", UartRecvBuf[i + j] & 0xff);
strcat(tmp2, tmp); // strcat(tmp2, tmp);
} // }
zlog_info(zct, "str = %s", tmp2); // zlog_info(zct, "str = %s", tmp2);
DealRecvData(RecvBuf); DealRecvData(RecvBuf);
} else if (command == 35) { } else if (command == 35) {
char signalNode[10] = {0x00}; char signalNode[10] = {0x00};

View File

@ -26,10 +26,12 @@ enum InteractiveCommand {
CONFIG_INF2 = 10, // 配置 只从无线网关发出 测点名称,测点编号 CONFIG_INF2 = 10, // 配置 只从无线网关发出 测点名称,测点编号
DEVICE_INF2 = 11, // 测点名称,测点编号 DEVICE_INF2 = 11, // 测点名称,测点编号
UPGRADE = 12, // 升级, 升级给这条信息 UPGRADE = 12, // 升级, 升级给这条信息
SIGNAL_STRENGTH = 13, // 信号强度 SIGNAL_STRENGTH = 13, // 信号强度 --不再使用
DEVICE_EXCEPTION = 14, // 异常: 外设 DEVICE_EXCEPTION = 14, // 异常: 外设
WAVE_COMPRESS = 15, // 波形数据压缩 WAVE_COMPRESS = 15, // 波形数据压缩
UPGRADE_FIRMWARE = 16 //固件升级内容 UPGRADE_FIRMWARE = 16, //固件升级内容
UPGRADE_ASK = 17, //固件升级请求
WAVE_RESP = 18 // 波形数据回复
}; };
// 无线传感器请求任务 // 无线传感器请求任务
@ -118,11 +120,17 @@ typedef struct ScheduleTask_{
uint16_t shortAddr; uint16_t shortAddr;
uint16_t duration; uint16_t duration;
uint32_t timeStamp; uint32_t timeStamp;
uint16_t millisecond;
uint8_t next_taskID;
uint8_t acc_z;
ScheduleTask_(){ ScheduleTask_(){
cmd = 0; cmd = 0;
shortAddr = 0; shortAddr = 0;
duration = 0; duration = 0;
timeStamp = 0; timeStamp = 0;
millisecond = 0;
next_taskID = 0;
acc_z = 0;
} }
} ScheduleTask; } ScheduleTask;
@ -167,6 +175,7 @@ public:
int FindRecvPackage(int bytesRead, char* mUartRecvBuf, char* head); int FindRecvPackage(int bytesRead, char* mUartRecvBuf, char* head);
int DealAskTask(uint16_t ushortAdd); int DealAskTask(uint16_t ushortAdd);
int DealFeatureValue(const char* pData, uint16_t ushortAdd);
int DealException(const char* pData); int DealException(const char* pData);
int DealReviveDuration(uint16_t ushortAdd); int DealReviveDuration(uint16_t ushortAdd);
int DealConfig(uint16_t ushortAdd); int DealConfig(uint16_t ushortAdd);
@ -176,7 +185,7 @@ public:
void GetLocalZigbeeRSSI(uint16_t ushortAdd); void GetLocalZigbeeRSSI(uint16_t ushortAdd);
// feature parse // feature parse
void DealDataNodeFeature(const char* pData, int flag); int DealDataNodeFeature(const char* pData, int flag);
void RecordBattery(std::string& strLongAddr, DataRecvStatic& dataStatic, std::string& nowTimetamp); void RecordBattery(std::string& strLongAddr, DataRecvStatic& dataStatic, std::string& nowTimetamp);
void DealDataNodeWave(const char* pData, int comand); void DealDataNodeWave(const char* pData, int comand);
void DealWaveThread(); void DealWaveThread();
@ -212,6 +221,7 @@ public:
int UpdateConfig(uint16_t ushortAdd); int UpdateConfig(uint16_t ushortAdd);
int TaskResp(ScheduleTask scheduleTask); int TaskResp(ScheduleTask scheduleTask);
int SendReviveDuration(ReviveDuration recvDuration); int SendReviveDuration(ReviveDuration recvDuration);
int WaveResp(uint16_t shortAddr);
void openSwitch(); void openSwitch();
int CheckZigbeeACK(); int CheckZigbeeACK();
@ -253,6 +263,11 @@ private:
std::vector<RecvData> VecWaveDataX; std::vector<RecvData> VecWaveDataX;
std::vector<RecvData> VecWaveDataY; std::vector<RecvData> VecWaveDataY;
std::vector<RecvData> VecWaveDataZ; std::vector<RecvData> VecWaveDataZ;
uint8_t send_data[100];
uint16_t last_short_addr;
long last_time;
std::map<uint16_t, std::vector<uint8_t>> map_send_data;
}; };
typedef boost::container::dtl::singleton_default<Uart> uart_inst; typedef boost::container::dtl::singleton_default<Uart> uart_inst;

View File

@ -43,7 +43,7 @@ void Uart::DataExtract(RecvData *p, int id, unsigned int &lowbit, float &n) {
n = ScaleConvert(highbit); n = ScaleConvert(highbit);
} }
void Uart::DealDataNodeFeature(const char *pData, int flag) { int Uart::DealDataNodeFeature(const char *pData, int flag) {
RecvData *pRecvData = (RecvData *)pData; RecvData *pRecvData = (RecvData *)pData;
char whereCon[1024] = {0}; char whereCon[1024] = {0};
char updateSql[1024] = {0}; char updateSql[1024] = {0};
@ -67,7 +67,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
if (vecResult.size() < 1) { if (vecResult.size() < 1) {
zlog_warn(zct, "device info not found %02x%02x ", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]); zlog_warn(zct, "device info not found %02x%02x ", pRecvData->ShortAddr[0], pRecvData->ShortAddr[1]);
return; return -1;
} }
zlog_info(zct, "--------->the remote sensor short addr:%s strLongAddr=%s,softVersion = %s", buf, vecResult[1].c_str(), vecResult[0].c_str()); zlog_info(zct, "--------->the remote sensor short addr:%s strLongAddr=%s,softVersion = %s", buf, vecResult[1].c_str(), vecResult[0].c_str());
@ -83,7 +83,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
if (vecResult[0] == "3.0" || vecResult[0] == "4.0") { if (vecResult[0] == "3.0" || vecResult[0] == "4.0") {
return; return -2;
} }
long nodetimestamp = BUILD_UINT32(pRecvData->Data[29], pRecvData->Data[28], pRecvData->Data[27], pRecvData->Data[26]); long nodetimestamp = BUILD_UINT32(pRecvData->Data[29], pRecvData->Data[28], pRecvData->Data[27], pRecvData->Data[26]);
@ -144,17 +144,21 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
memcpy(szTableNameStatic, szTableName, sizeof(szTableNameStatic)); memcpy(szTableNameStatic, szTableName, sizeof(szTableNameStatic));
memset(whereCon, 0x00, sizeof(whereCon)); memset(whereCon, 0x00, sizeof(whereCon));
// sprintf(whereCon, "StaticIndex = %ld", staticIndex); //时间戳判断,是否重包
// int count = sqlite_db_ctrl::instance().GetTableRows(szTableNameStatic, whereCon); //避免重复数据 sprintf(whereCon, "timeStamp = '%s'", localtimestamp);
// sprintf(szTableNameData, "t_data_%s", strMeasurementID.c_str()); int count = sqlite_db_ctrl::instance().GetTableRows(szTableNameStatic, whereCon); //避免重复数据
sprintf(szTableNameData, "t_data_%s", strMeasurementID.c_str());
// int count2 = sqlite_db_ctrl::instance().GetTableRows(szTableNameData, whereCon); int count2 = sqlite_db_ctrl::instance().GetTableRows(szTableNameData, whereCon);
// if (count > 0 || count2 > 0) { if (count > 0 || count2 > 0) {
// char logInfo[100] = {0x00}; char logInfo[100] = {0x00};
// sprintf(logInfo, "ShortAddr = %s,staticIndex = %ld,staticData = %d, data = %d", strShortAddr.c_str(), staticIndex, count, count2); sprintf(logInfo, "ShortAddr = %s,localtimestamp = %s,staticData = %d, data = %d", strShortAddr.c_str(), localtimestamp, count, count2);
// zlog_info(zct, logInfo); zlog_info(zct, logInfo);
// return; std::vector<uint8_t>& data_vec = map_send_data[u_short_addr];
// } const uint8_t* send_data = data_vec.data();
WriteToUart((const char*)send_data, 100);
return -3;
}
memset(whereCon, 0x00, sizeof(whereCon)); memset(whereCon, 0x00, sizeof(whereCon));
sprintf(szTableNameData, "t_data_%s", strMeasurementID.c_str()); sprintf(szTableNameData, "t_data_%s", strMeasurementID.c_str());
///////////////////////////////////////////////////////////// for V2.0.3 upgrade to V3.0 ///////////////////////////////////////////////////////////// for V2.0.3 upgrade to V3.0
@ -599,6 +603,7 @@ void Uart::DealDataNodeFeature(const char *pData, int flag) {
} }
JsonData jd; JsonData jd;
jd.JsonCmd_32(strMeasurementID,0,0,strMeasurementID,""); jd.JsonCmd_32(strMeasurementID,0,0,strMeasurementID,"");
return 0;
} }
float Uart::ScaleConvert(int highbit) { return 0.0001f * pow(100.0f, highbit); } float Uart::ScaleConvert(int highbit) { return 0.0001f * pow(100.0f, highbit); }
@ -987,8 +992,7 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
} }
} }
} }
zlog_info(zct, "fopen file vecData.size : %d end ", vecData.size());
zlog_info(zct, "fopen FIle vecData.size : %d end ", vecData.size());
wave_channel.wave_timestamp = nowTimetamp; wave_channel.wave_timestamp = nowTimetamp;
g_mapWaveChannel[strMeasurementID] = wave_channel; g_mapWaveChannel[strMeasurementID] = wave_channel;
Json::Value valWaveData; Json::Value valWaveData;
@ -1003,11 +1007,12 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan
Json::FastWriter WaveValue; Json::FastWriter WaveValue;
std::string WaveData = WaveValue.write(valWaveData); std::string WaveData = WaveValue.write(valWaveData);
char selectCon[128] = {0}; char selectCon[128] = {0},whereCon[128] = {0};
sprintf(selectCon, "channelID='%s' ORDER BY timeStamp ASC LIMIT 0,1", strChannelID.c_str()); sprintf(selectCon, "channelID='%s' ORDER BY timeStamp ASC LIMIT 0,1", strChannelID.c_str());
std::string strTime = sqlite_db_ctrl::instance().GetData("t_data_waveSend", "timeStamp", selectCon); std::string strTime = sqlite_db_ctrl::instance().GetData("t_data_waveSend", "timeStamp", selectCon);
long lTime = atol(nowTimetamp.c_str()) - atol(strTime.c_str()); long lTime = atol(nowTimetamp.c_str()) - atol(strTime.c_str());
int Count = sqlite_db_ctrl::instance().GetTableRows("t_data_waveSend", NULL); sprintf(whereCon, "channelID like '%%%s%%'", strMeasurementID.c_str());
int Count = sqlite_db_ctrl::instance().GetTableRows("t_data_waveSend", whereCon);
std::string strFileName_Record = strFileName + "_" + nowTimetamp; std::string strFileName_Record = strFileName + "_" + nowTimetamp;
if ((Count * 3 < SAVE_COUNT && lTime < OneWeek) || strTime.size() == 0) { if ((Count * 3 < SAVE_COUNT && lTime < OneWeek) || strTime.size() == 0) {
char insertSql[128] = {0x00}; char insertSql[128] = {0x00};

View File

@ -51,7 +51,7 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) {
GetTimeNet(localtimestamp, 1); GetTimeNet(localtimestamp, 1);
char insertSql[100] = {0}; char insertSql[100] = {0};
char wherecon[100] = {0}; char wherecon[100] = {0};
sprintf(wherecon," short_Addr = '%02x%02x' and status = 3 order by start_timestamp DESC",UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); sprintf(wherecon," short_Addr = '%02x%02x' and status = 3 and start_timestamp > ( SELECT MAX(submit_timestamp) FROM firmware_upgrade ) order by start_timestamp DESC",UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
std::string spend_count = sqlite_db_ctrl::instance().GetData(" firmware_upgrade ","spend_count",wherecon); std::string spend_count = sqlite_db_ctrl::instance().GetData(" firmware_upgrade ","spend_count",wherecon);
if (atoi(spend_count.c_str()) >= 10){ if (atoi(spend_count.c_str()) >= 10){
zlog_warn(zbt, "UpdateWirelessNode spend_count %d,shortAddr = %02x%02x", atoi(spend_count.c_str()), UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); zlog_warn(zbt, "UpdateWirelessNode spend_count %d,shortAddr = %02x%02x", atoi(spend_count.c_str()), UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
@ -176,12 +176,12 @@ void Uart::UpdateWirelessNode(uint16_t shortAdd) {
} else { } else {
zlog_warn(zct, "Packge ACK send failed,shortAddr = %02x%02x", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); zlog_warn(zct, "Packge ACK send failed,shortAddr = %02x%02x", UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
} }
mssleep(10000); mssleep(50000);
int Count = thisSize / 92; int Count = thisSize / 92;
int lastSize = thisSize % 92; int lastSize = thisSize % 92;
unsigned char UpdateData[100] = {0x00}; unsigned char UpdateData[100] = {0x00};
//帧头[3byte] 节点地址[2byte] 数据类型[1byte] 序号[1byte] 数据包[92byte] CRC校验[1byte] //帧头[3byte] 节点地址[2byte] 数据类型[1byte] 序号[1byte] 数据包[92byte] CRC校验[1byte]
zlog_warn(zbt, "Start Update!!! file Size = %d,fileName = %s,Count = %d,lastSize = %d,shortAddr = %02x%02x", (int)thisSize,DataNodeUpdateFile.c_str(),Count,lastSize,UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd)); zlog_warn(zbt, "Start Upgrade!!! file Size = %d,fileName = %s,Count = %d,lastSize = %d,shortAddr = %02x%02x", (int)thisSize,DataNodeUpdateFile.c_str(),Count,lastSize,UINT16_HIGH(shortAdd), UINT16_LOW(shortAdd));
tmp = 0x00; tmp = 0x00;
gpio_set(GlobalConfig::GPIO_G.zigAckreset, 0); gpio_set(GlobalConfig::GPIO_G.zigAckreset, 0);
mssleep(1000); mssleep(1000);
@ -548,41 +548,58 @@ int Uart::UpdateWirelessNodeTime(unsigned char* pDestShortAddr, int modifyaddr /
} }
int Uart::TaskResp(ScheduleTask scheduleTask){ int Uart::TaskResp(ScheduleTask scheduleTask){
unsigned char UpdateData[100] = {0}; memset(send_data,0,sizeof(send_data));
UpdateData[0] = 0xAA; send_data[0] = 0xAA;
UpdateData[1] = 0x55; send_data[1] = 0x55;
UpdateData[2] = 0xAA; send_data[2] = 0xAA;
UpdateData[3] = (scheduleTask.shortAddr >> 8) & 0xFF; send_data[3] = (scheduleTask.shortAddr >> 8) & 0xFF;
UpdateData[4] = scheduleTask.shortAddr & 0xFF; send_data[4] = scheduleTask.shortAddr & 0xFF;
UpdateData[5] = scheduleTask.cmd & 0xFF; send_data[5] = scheduleTask.cmd & 0xFF;
UpdateData[6] = 0x00; send_data[6] = 0x00;
if (scheduleTask.cmd == REVIVE_DURATION) char localtimestamp[32] = {0x00};
{ int millisecond = 0;
UpdateData[7] = UINT16_LOW(scheduleTask.duration); std::string rtcTime = GetRTC(localtimestamp, millisecond);
UpdateData[8] = UINT16_HIGH(scheduleTask.duration); scheduleTask.timeStamp = atoi(localtimestamp);
}else if (scheduleTask.cmd == MEAS_EVAL) zlog_info(zct,"next taskID = %d\n",scheduleTask.next_taskID);
{
UpdateData[9] = UINT32_LOW_2(scheduleTask.timeStamp); send_data[7] = UINT16_LOW(scheduleTask.duration);
UpdateData[10] = UINT32_LOW_1(scheduleTask.timeStamp); send_data[8] = UINT16_HIGH(scheduleTask.duration);
UpdateData[11] = UINT32_HIGH_2(scheduleTask.timeStamp); send_data[9] = UINT32_LOW_2(scheduleTask.timeStamp);
UpdateData[12] = UINT32_HIGH_1(scheduleTask.timeStamp); send_data[10] = UINT32_LOW_1(scheduleTask.timeStamp);
}else if (scheduleTask.cmd == WAVE_CMD) send_data[11] = UINT32_HIGH_2(scheduleTask.timeStamp);
send_data[12] = UINT32_HIGH_1(scheduleTask.timeStamp);
send_data[20] = scheduleTask.acc_z;
send_data[21] = scheduleTask.next_taskID & 0xFF;
send_data[22] = UINT16_LOW(scheduleTask.millisecond);
send_data[23] = UINT16_HIGH(scheduleTask.millisecond);
if (scheduleTask.next_taskID == WAVE_CMD)
{ {
uint8_t x,y,z; uint8_t x,y,z;
wave_feature_set_inst::instance().GetWaveCfg(scheduleTask.shortAddr,x,y,z); wave_feature_set_inst::instance().GetWaveCfg(scheduleTask.shortAddr,x,y,z);
zlog_info(zct,"wave x = %d,y = %d,z = %d\n",x,y,z); zlog_info(zct,"wave x = %d,y = %d,z = %d\n",x,y,z);
UpdateData[17] = (x^1) & 0xFF; send_data[17] = (x^1) & 0xFF;
UpdateData[18] = (y^1) & 0xFF; send_data[18] = (y^1) & 0xFF;
UpdateData[19] = (z^1) & 0xFF; send_data[19] = (z^1) & 0xFF;
} }
unsigned char tmp = 0x00; unsigned char tmp = 0x00;
for (int k = 0; k < 99; k++) { for (int k = 0; k < 99; k++) {
tmp += UpdateData[k]; tmp += send_data[k];
} }
UpdateData[99] = tmp; send_data[99] = tmp;
mssleep(10000); if (scheduleTask.cmd != REVIVE_DURATION)
WriteToUart((const char*)UpdateData, 100); {
mssleep(50000);
WriteToUart((const char*)send_data, 100);
mssleep(50000);
WriteToUart((const char*)send_data, 100);
}else {
map_send_data[scheduleTask.shortAddr] = std::vector<uint8_t>(send_data, send_data + 100);
}
mssleep(50000);
WriteToUart((const char*)send_data, 100);
int iRet = CheckZigbeeACK(); int iRet = CheckZigbeeACK();
if (iRet == 0) { if (iRet == 0) {
zlog_info(zct, "TaskResp ACK send success,shortAddr = %02x%02x", UINT16_HIGH(scheduleTask.shortAddr),UINT16_LOW(scheduleTask.shortAddr)); zlog_info(zct, "TaskResp ACK send success,shortAddr = %02x%02x", UINT16_HIGH(scheduleTask.shortAddr),UINT16_LOW(scheduleTask.shortAddr));
@ -618,6 +635,33 @@ int Uart::SendReviveDuration(ReviveDuration recvDuration){
} }
return iRet; return iRet;
} }
int Uart::WaveResp(uint16_t shortAddr){
unsigned char sendData[8] = {0};
sendData[0] = 0xAA;
sendData[1] = 0x55;
sendData[2] = 0xAA;
sendData[3] = (shortAddr >> 8) & 0xFF;
sendData[4] = shortAddr & 0xFF;
sendData[5] = 0x12;
sendData[6] = 0x00;
unsigned char tmp = 0x00;
for (int k = 0; k < 7; k++) {
tmp += sendData[k];
}
sendData[7] = tmp;
WriteToUart((const char*)sendData, 8);
mssleep(50000);
WriteToUart((const char*)sendData, 8);
mssleep(50000);
WriteToUart((const char*)sendData, 8);
int iRet = CheckZigbeeACK();
if (iRet == 0) {
zlog_info(zct, "WaveResp ACK send success,shortAddr = %x", shortAddr);
} else {
zlog_warn(zct, "WaveResp ACK send failed,shortAddr = %x", shortAddr);
}
return iRet;
}
int Uart::CheckZigbeeACK() { int Uart::CheckZigbeeACK() {
if (gpio_read(GlobalConfig::GPIO_G.zigAckrep) == 48) gpio_set(GlobalConfig::GPIO_G.zigAckreset, 1); if (gpio_read(GlobalConfig::GPIO_G.zigAckrep) == 48) gpio_set(GlobalConfig::GPIO_G.zigAckreset, 1);
int time = 0, value = 0, iRet = -1; int time = 0, value = 0, iRet = -1;