diff --git a/dbaccess/sql_db.cpp b/dbaccess/sql_db.cpp index 457bfa3..986c559 100644 --- a/dbaccess/sql_db.cpp +++ b/dbaccess/sql_db.cpp @@ -1555,6 +1555,12 @@ void SqliteDB::NewBatteryIdentify(){ } } void SqliteDB::ShutdownCheck(){ + int shutdownDetection = readIntValue("config", "shutdownDetection", (char *)GlobalConfig::Config_G.c_str()); + if (!shutdownDetection) + { + return ; + } + int checkNumber = readIntValue("config", "shutdownNumber", (char *)GlobalConfig::Config_G.c_str()); char whereCon[1024] = {0}; char updateSql[1024] = {0}; diff --git a/jsonparse/web_cmd_parse3.cpp b/jsonparse/web_cmd_parse3.cpp index f45331e..c3fa310 100644 --- a/jsonparse/web_cmd_parse3.cpp +++ b/jsonparse/web_cmd_parse3.cpp @@ -1528,7 +1528,7 @@ std::string JsonData::JsonCmd_Cgi_68(Param_68 ¶m){ memset(whereCon,0,sizeof(whereCon)); 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); + sprintf(updateSql, " status = '%d',statisticType = '%d', threshold = '%f',effect = '0' ",param.vecParam68[i].status,param.vecParam68[i].statisticType,param.vecParam68[i].threshold); sqlite_db_ctrl::instance().UpdateTableData(" t_shutdown_info ", updateSql, whereCon); } } @@ -1584,7 +1584,7 @@ std::string JsonData::JsonCmd_Cgi_69(Param_69 ¶m){ memset(whereCon,0,sizeof(whereCon)); memset(updateSql,0,sizeof(updateSql)); sprintf(whereCon, " MeasurementID = '%s' ", param.vecParam69[i].measurementID.c_str()); - sprintf(updateSql, " status = '%d',trigerType = '%d',statisticType = '%d', threshold = '%f'",param.vecParam69[i].status,param.vecParam69[i].trigerType,param.vecParam69[i].statisticType,param.vecParam69[i].threshold); + sprintf(updateSql, " status = '%d',trigerType = '%d',statisticType = '%d', threshold = '%f' , effect = '0'",param.vecParam69[i].status,param.vecParam69[i].trigerType,param.vecParam69[i].statisticType,param.vecParam69[i].threshold); sqlite_db_ctrl::instance().UpdateTableData(" t_wave_triger_info ", updateSql, whereCon); } } @@ -1737,4 +1737,4 @@ std::string JsonData::JsonCmd_Cgi_71(Param_71 ¶m){ jsonVal["content"].resize(0); } return show_value_.write(jsonVal); -} \ No newline at end of file +} diff --git a/platform/platform_init.cpp b/platform/platform_init.cpp index 0276549..a484d5d 100644 --- a/platform/platform_init.cpp +++ b/platform/platform_init.cpp @@ -84,12 +84,45 @@ void PlatformInit::Init() { zlog_error(zbt, "PlatFormInit exception happend."); std::string errorinfo = "系统初始化异常"; } + char whereCon[128] = {0}; + char insertSql[128] = {0}; + int rows = 0; + std::string MeasurementID = "0"; + std::string ShortAdd = "0"; array_t arrResult = sqlite_db_ctrl::instance().GetDataMultiLineTransaction(T_SENSOR_INFO(TNAME), " MeasurementID,zigbeeShortAddr ", NULL); - for (size_t i = 0; i < arrResult.size(); i++) { - compressWaveChannel tempchannel; - WaveChannel tempwavechannel; - g_mapCompress.insert(std::make_pair(arrResult[i][1], tempchannel)); - g_mapWaveChannel.insert(std::make_pair(arrResult[i][0], tempwavechannel)); + if (arrResult.size() > 1) + { + for (size_t i = 0; i < arrResult.size(); i++) { + compressWaveChannel tempchannel; + WaveChannel tempwavechannel; + g_mapCompress.insert(std::make_pair(arrResult[i][1], tempchannel)); + g_mapWaveChannel.insert(std::make_pair(arrResult[i][0], tempwavechannel)); + MeasurementID = arrResult[i][0]; + ShortAdd = arrResult[i][1]; + sprintf(whereCon, "MeasurementID = '%s' ", arrResult[i][0].c_str()); + rows = sqlite_db_ctrl::instance().GetTableRows("t_shutdown_info",whereCon); + zlog_info(zbt, "MeasurementID = %s,ShortAdd = %s,rows = %d", MeasurementID.c_str(), ShortAdd.c_str(), rows); + if(rows < 1){ + memset(insertSql,0,sizeof(insertSql)); + sprintf(insertSql, " '%s','%s','0','0','0','0'", + MeasurementID.c_str(), ShortAdd.c_str()); + sqlite_db_ctrl::instance().InsertData("t_shutdown_info", insertSql); + } + rows = sqlite_db_ctrl::instance().GetTableRows("t_debug_info",whereCon); + if(rows < 1){ + memset(insertSql,0,sizeof(insertSql)); + sprintf(insertSql, " '%s','%s','','','','','','0',''", + MeasurementID.c_str(), ShortAdd.c_str()); + sqlite_db_ctrl::instance().InsertData("t_debug_info", insertSql); + } + rows = sqlite_db_ctrl::instance().GetTableRows("t_wave_triger_info",whereCon); + if(rows < 1){ + memset(insertSql,0,sizeof(insertSql)); + sprintf(insertSql, " '%s','%s','0','0','0','0','0'", + MeasurementID.c_str(), ShortAdd.c_str()); + sqlite_db_ctrl::instance().InsertData("t_wave_triger_info", insertSql); + } + } } } diff --git a/scheduler/schedule.cpp b/scheduler/schedule.cpp index abe1939..fe24b20 100644 --- a/scheduler/schedule.cpp +++ b/scheduler/schedule.cpp @@ -69,164 +69,166 @@ int SensorScheduler::StartSchedule(uint16_t short_addr, int &next_duration, bool // 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); + // next_duration = GetNextDuration(short_addr, z, next_task_id); + // zlog_warn(zbt, "[%d:%x] no need for eigen", id, short_addr); 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 { - // z wave - int nth_wave_slice = nth_eigen_value_slice_ * wave_slice_num_per_eigen_interval_ + nth_wave_slice_ + 1; - if (debug_slice_sensor_id_[nth_wave_slice] == short_addr) { - current_request_ = kScheduleWaveForm; - z = true; - return kScheduleWaveForm; - } else { - // 当前特征值间隔内是否存在此传感器的波形区间 - for (int i = nth_wave_slice + 1; i <= (nth_eigen_value_slice_+1) * 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_duration = nxt_ts - current_ts_; - if (next_duration < 10) { - zlog_debug(zbt, "[%d:%x] [Nxt] debug exception duration:%d, adjust to 25", id, short_addr,next_duration); - next_duration = 25; - } else if (next_duration > eigen_value_send_interval_) { - zlog_debug(zbt, "[%d:%x] [Nxt] debug exception duration:%d, adjust to 120", id, short_addr,next_duration); - next_duration = 120; - } - z = true; - next_task_id = kScheduleWaveForm; - 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 { + // // z wave + // int nth_wave_slice = nth_eigen_value_slice_ * wave_slice_num_per_eigen_interval_ + nth_wave_slice_ + 1; + // if (debug_slice_sensor_id_[nth_wave_slice] == short_addr) { + // current_request_ = kScheduleWaveForm; + // z = true; + // return kScheduleWaveForm; + // } else { + // // 当前特征值间隔内是否存在此传感器的波形区间 + // for (int i = nth_wave_slice + 1; i <= (nth_eigen_value_slice_+1) * 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_duration = nxt_ts - current_ts_; + // if (next_duration < 10) { + // zlog_debug(zbt, "[%d:%x] [Nxt] debug exception duration:%d, adjust to 25", id, short_addr,next_duration); + // next_duration = 25; + // } else if (next_duration > eigen_value_send_interval_) { + // zlog_debug(zbt, "[%d:%x] [Nxt] debug exception duration:%d, adjust to 120", id, short_addr,next_duration); + // 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; - } - } - return 0; - } 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); - 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; - } - } - } - int nth_wave_slice = nth_eigen_value_slice_ * wave_slice_num_per_eigen_interval_ + nth_wave_slice_ + 1; // 从1开始编号 - auto wave_slice_iter = sensor_id_nth_slice_.find(id); - if (wave_slice_iter == sensor_id_nth_slice_.end()) { - zlog_error(zbt, "[%d:%x] invaild id, not find wave slice id, need to check further", id, short_addr); - return kScheduleUnknownSensor; - } + // next_duration = GetDebugUpgradeNextDuration(short_addr); + // next_task_id = kScheduleEigenValue; + // zlog_debug(zbt, "[%d:%x] debug wrong time", id, short_addr); + // return kScheduleWrongTime; + // } + // } + // return 0; + // } 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); + // 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; + // } + // } + // } + // int nth_wave_slice = nth_eigen_value_slice_ * wave_slice_num_per_eigen_interval_ + nth_wave_slice_ + 1; // 从1开始编号 + // auto wave_slice_iter = sensor_id_nth_slice_.find(id); + // if (wave_slice_iter == sensor_id_nth_slice_.end()) { + // zlog_error(zbt, "[%d:%x] invaild id, not find wave slice id, need to check further", id, short_addr); + // return kScheduleUnknownSensor; + // } - wave_feature_set_inst::instance().GetWaveCfg(short_addr, g_x, g_y, g_z); - if (nth_wave_slice == wave_slice_iter->second.first) { // Z轴 - if (g_z) { - zlog_debug(zbt, "[%d:%x] it is wave z time", id, short_addr); - current_request_ = kScheduleWaveForm; - z = true; - return kScheduleWaveForm; - } else { - next_duration = GetNextDuration(short_addr, z, next_task_id); - zlog_debug(zbt, "[%d:%x] no need for wave", id, short_addr); - return kScheduleWrongTime; - } - } else if (nth_wave_slice == wave_slice_iter->second.second) { // XY轴 - if (g_x || g_y) { - zlog_debug(zbt, "[%d:%x] it is wave xy time", id, short_addr); - current_request_ = kScheduleWaveForm; - z = false; - return kScheduleWaveForm; - } else { - next_duration = GetNextDuration(short_addr, z, next_task_id); - zlog_debug(zbt, "[%d:%x] no need for wave", id, short_addr); - return kScheduleWrongTime; - } - } - else { - if (slice_sensor_id_[nth_wave_slice] == 0) { // idle time - zlog_debug(zbt, "[%d:%x] in idle time", id, short_addr); - if (trigger_wave_record_.find(short_addr) != trigger_wave_record_.end()) { - auto iter = trigger_wave_record_.find(short_addr); - if (iter->second.first != 0) { - current_request_ = kScheduleWaveForm; - z = true; - zlog_debug(zbt, "[%d:%x] trigger z wave time", id, short_addr); - iter->second.first = 0; - WriteTriggerWaveRecord(); - return kScheduleWaveForm; - } else if (iter->second.second != 0) { - current_request_ = kScheduleWaveForm; - z = false; - iter->second.second = 0; - WriteTriggerWaveRecord(); - zlog_debug(zbt, "[%d:%x] trigger xy wave time", id, short_addr); - return kScheduleWaveForm; - } - } + // wave_feature_set_inst::instance().GetWaveCfg(short_addr, g_x, g_y, g_z); + // if (nth_wave_slice == wave_slice_iter->second.first) { // Z轴 + // if (g_z) { + // zlog_debug(zbt, "[%d:%x] it is wave z time", id, short_addr); + // current_request_ = kScheduleWaveForm; + // z = true; + // return kScheduleWaveForm; + // } else { + // next_duration = GetNextDuration(short_addr, z, next_task_id); + // zlog_debug(zbt, "[%d:%x] no need for wave", id, short_addr); + // return kScheduleWrongTime; + // } + // } else if (nth_wave_slice == wave_slice_iter->second.second) { // XY轴 + // if (g_x || g_y) { + // zlog_debug(zbt, "[%d:%x] it is wave xy time", id, short_addr); + // current_request_ = kScheduleWaveForm; + // z = false; + // return kScheduleWaveForm; + // } else { + // next_duration = GetNextDuration(short_addr, z, next_task_id); + // zlog_debug(zbt, "[%d:%x] no need for wave", id, short_addr); + // return kScheduleWrongTime; + // } + // } + // else { + // if (slice_sensor_id_[nth_wave_slice] == 0) { // idle time + // zlog_debug(zbt, "[%d:%x] in idle time", id, short_addr); + // if (trigger_wave_record_.find(short_addr) != trigger_wave_record_.end()) { + // auto iter = trigger_wave_record_.find(short_addr); + // if (iter->second.first != 0) { + // current_request_ = kScheduleWaveForm; + // z = true; + // zlog_debug(zbt, "[%d:%x] trigger z wave time", id, short_addr); + // iter->second.first = 0; + // WriteTriggerWaveRecord(); + // return kScheduleWaveForm; + // } else if (iter->second.second != 0) { + // current_request_ = kScheduleWaveForm; + // z = false; + // iter->second.second = 0; + // WriteTriggerWaveRecord(); + // zlog_debug(zbt, "[%d:%x] trigger xy wave time", id, short_addr); + // return kScheduleWaveForm; + // } + // } - if (ZRetransferWave(short_addr)) { - zlog_debug(zbt, "[%d:%x] z retransfer wave time", id, short_addr); - current_request_ = kScheduleWaveForm; - z = true; - return kScheduleWaveForm; - } else if (ZMissedWave(short_addr)) { - zlog_debug(zbt, "[%d:%x] z patch wave time", id, short_addr); - current_request_ = kScheduleWaveForm; - z = true; - z_patch_set_.erase(short_addr); - return kScheduleWaveForm; - } else if (XYRetransferWave(short_addr)) { - zlog_debug(zbt, "[%d:%x] xy retransfer wave time", id, short_addr); - current_request_ = kScheduleWaveForm; - z = false; - return kScheduleWaveForm; - } else if (XYMissedWave(short_addr)) { - zlog_debug(zbt, "[%d:%x] xy patch wave time", id, short_addr); - current_request_ = kScheduleWaveForm; - xy_patch_set_.erase(short_addr); - z = false; - return kScheduleWaveForm; - } - } - // wrong time to come - int eigen_send_ts = (id - 1) * 2; - if (eigen_send_ts > 57) { - eigen_send_ts = eigen_send_ts % 57; - } - long available_ts = current_wave_start_ts_ + (nth_eigen_value_slice_ + 1) * eigen_value_send_interval_ + eigen_send_ts; - next_duration = available_ts - current_ts_; - if (next_duration < 10 || next_duration > eigen_value_send_interval_) { - 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; - } - } + // if (ZRetransferWave(short_addr)) { + // zlog_debug(zbt, "[%d:%x] z retransfer wave time", id, short_addr); + // current_request_ = kScheduleWaveForm; + // z = true; + // return kScheduleWaveForm; + // } else if (ZMissedWave(short_addr)) { + // zlog_debug(zbt, "[%d:%x] z patch wave time", id, short_addr); + // current_request_ = kScheduleWaveForm; + // z = true; + // z_patch_set_.erase(short_addr); + // return kScheduleWaveForm; + // } else if (XYRetransferWave(short_addr)) { + // zlog_debug(zbt, "[%d:%x] xy retransfer wave time", id, short_addr); + // current_request_ = kScheduleWaveForm; + // z = false; + // return kScheduleWaveForm; + // } else if (XYMissedWave(short_addr)) { + // zlog_debug(zbt, "[%d:%x] xy patch wave time", id, short_addr); + // current_request_ = kScheduleWaveForm; + // xy_patch_set_.erase(short_addr); + // z = false; + // return kScheduleWaveForm; + // } + // } + // // wrong time to come + // int eigen_send_ts = (id - 1) * 2; + // if (eigen_send_ts > 57) { + // eigen_send_ts = eigen_send_ts % 57; + // } + // long available_ts = current_wave_start_ts_ + (nth_eigen_value_slice_ + 1) * eigen_value_send_interval_ + eigen_send_ts; + // next_duration = available_ts - current_ts_; + // if (next_duration < 10 || next_duration > eigen_value_send_interval_) { + // 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, bool &z, int& next_task_id) { @@ -244,9 +246,11 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr, bool &z, in 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; + zlog_debug(zbt, "[%d:%x] debug wave", id, short_addr); return nxt_ts; } } + zlog_debug(zbt, "[%d:%x] check wave_slice_num_per_eigen_interval_:%d, nth_wave_slice:%d", id, short_addr, wave_slice_num_per_eigen_interval_, nth_wave_slice); next_task_id = kScheduleEigenValue; return GetDebugUpgradeNextTS(short_addr); } @@ -256,14 +260,14 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr, bool &z, in return GetDebugUpgradeNextTS(short_addr); } else { // 计算升级是否在后面的波形时间窗口中 - int nth_wave_slice = nth_eigen_value_slice_ * wave_slice_num_per_eigen_interval_ + 1; - 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; - } - } + // int nth_wave_slice = nth_eigen_value_slice_ * wave_slice_num_per_eigen_interval_ + 1; + // 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); } @@ -309,24 +313,25 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr, bool &z, in } } - if ((g_z || g_x || g_y) && send_wave_ts == 0) { + if (send_wave_ts == 0) { if (trigger_wave_record_.find(short_addr) != trigger_wave_record_.end()) { auto iter = trigger_wave_record_.find(short_addr); if (iter->second.first != 0 || iter->second.second != 0) { for (int i = forward_wave_slice_num+1; i <= forward_wave_slice_num + wave_slice_num_per_eigen_interval_; ++i) { - if (slice_sensor_id_[i] == 0) { - send_wave_ts = current_wave_start_ts_ + nth_eigen_value_slice_ * eigen_value_send_interval_ + 60 + (i - forward_wave_slice_num - 1) * 60; - + if (slice_sensor_id_[i] == 0 || short_addr_map_.find(slice_sensor_id_[i]) == short_addr_map_.end()) { + send_wave_ts = current_wave_start_ts_ + nth_eigen_value_slice_ * eigen_value_send_interval_ + 60 + (i - forward_wave_slice_num - 1) * 60; if (free_slice_ocuppied_.count(send_wave_ts) == 0) { available_ts = send_wave_ts; free_slice_ocuppied_.insert(available_ts); next_task_id = kScheduleWaveForm; if (iter->second.first != 0) { z = true; + iter->second.first = 0; } else { z = false; + iter->second.second = 0; } - + WriteTriggerWaveRecord(); zlog_debug(zbt, "[Nxt][%d:%x] %d nth free wave slice will be used to trigger z : %d wave, utc time:[%s]", id, short_addr, i+forward_wave_slice_num, z, GetUTCTime(available_ts).c_str()); break; } else { @@ -370,7 +375,7 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr, bool &z, in if (ZRetransferWave(short_addr) || XYRetransferWave(short_addr) || ZMissedWave(short_addr) || XYMissedWave(short_addr)) { for (int i = 1; i <= wave_slice_num_per_eigen_interval_; ++i) { - if (slice_sensor_id_[i+forward_wave_slice_num] == 0) { + if (slice_sensor_id_[i+forward_wave_slice_num] == 0 || short_addr_map_.find(slice_sensor_id_[i+forward_wave_slice_num]) == short_addr_map_.end()) { // 判断此空闲位置是否被占用 long current_wave_slice_ts = current_wave_start_ts_ + nth_eigen_value_slice_ * eigen_value_send_interval_ + 60 + (i-1) * seconds_per_wave_slice_; if (free_slice_ocuppied_.count(current_wave_slice_ts) == 0) { @@ -410,6 +415,40 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr, bool &z, in zlog_debug(zbt, "[Nxt] [%d:%x] next feature send utc time2:%s", id, short_addr, GetUTCTime(max_ts).c_str()); return max_ts; } + + // for (int i = forward_wave_slice_num+1; i <= forward_wave_slice_num + wave_slice_num_per_eigen_interval_; ++i) { + // if (slice_sensor_id_[i] == 0) { // idle time + // send_wave_ts = current_wave_start_ts_ + nth_eigen_value_slice_ * eigen_value_send_interval_ + 60 + (i - forward_wave_slice_num - 1) * 60; + // if (free_slice_ocuppied_.count(send_wave_ts) != 0) { + // continue; + // } + // zlog_debug(zbt, "[%d:%x] in idle time for trigger wave", id, short_addr); + // if (trigger_wave_record_.find(short_addr) != trigger_wave_record_.end()) { + // auto iter = trigger_wave_record_.find(short_addr); + // if (iter->second.first != 0) { + // current_request_ = kScheduleWaveForm; + // z = true; + // zlog_debug(zbt, "[%d:%x] trigger z wave time", id, short_addr); + // iter->second.first = 0; + // next_task_id = kScheduleWaveForm; + // free_slice_ocuppied_.insert(send_wave_ts); + // WriteTriggerWaveRecord(); + // return send_wave_ts; + // } else if (iter->second.second != 0) { + // current_request_ = kScheduleWaveForm; + // z = false; + // iter->second.second = 0; + // WriteTriggerWaveRecord(); + // next_task_id = kScheduleWaveForm; + // zlog_debug(zbt, "[%d:%x] trigger xy wave time", id, short_addr); + // free_slice_ocuppied_.insert(send_wave_ts); + // return send_wave_ts; + // } + // } else { + // break; + // } + // } + // } } else { if (current_schedule_status_ == kScheduleStatusDebug) { if (debug_list_.count(short_addr) == 0) { @@ -417,15 +456,15 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr, bool &z, in return GetDebugUpgradeNextTS(short_addr); } else { // 计算发送波形是否在后面的波形时间窗口中 - int nth_wave_slice = nth_eigen_value_slice_ * wave_slice_num_per_eigen_interval_ + nth_wave_slice_ + 2; - 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; - } - } + // int nth_wave_slice = nth_eigen_value_slice_ * wave_slice_num_per_eigen_interval_ + nth_wave_slice_ + 2; + // 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); } @@ -449,7 +488,7 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr, bool &z, in } // 如果是在当前波形时间窗中,不管是空闲时间窗,还是发送波形的时间窗,下一个时间窗是特征值 - int eigen_send_ts = (id - 1) * 2; + int eigen_send_ts = (id - 1) * 4; if (eigen_send_ts > 57) { eigen_send_ts = eigen_send_ts % 57; } @@ -470,7 +509,7 @@ int SensorScheduler::GetNextDuration(uint16_t short_addr, bool &z, int &next_tas id = iter->second; } current_ts_ = GetLocalTs(); - // CleanIdleOccupiedSet(current_ts_); + CleanIdleOccupiedSet(current_ts_); 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_; @@ -479,10 +518,19 @@ int SensorScheduler::GetNextDuration(uint16_t short_addr, bool &z, int &next_tas 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_ < 60 - 3) { + if (seconds_in_current_eigen_slice_ < 57) { ts_in_eigen_slice_ = true; } + // if (ts_in_eigen_slice_) { + // // nth_eigen_slice_ = (seconds_in_current_eigen_slice_ + 2) / eigen_value_send_duration_; + // if (nth_eigen_value_slice_ == 0) { + // ClearFailureSuccessMap(); + // } + // } + + zlog_debug(zbt, "[%d:%x] ts:%ld, current utc:%s, nth eigen_value slice:%d, seconds in eigen slice:%d, eigen slice:%d", + id, short_addr, current_ts_, GetUTCTime(current_ts_).c_str(), nth_eigen_value_slice_+1, seconds_in_current_eigen_slice_, ts_in_eigen_slice_); // long current_ts = GetLocalTs(); long next_ts = CalcNextTimestamp(id, short_addr, z, next_task_id); int duration = next_ts - current_ts_; @@ -495,7 +543,8 @@ int SensorScheduler::GetNextDuration(uint16_t short_addr, bool &z, int &next_tas duration = 120; return duration; } - zlog_debug(zbt, "[Nxt] [%d:%x] next duration is %d", id, short_addr, duration); + zlog_debug(zbt, "[Nxt] [%d:%x] next duration is %d,next_task_id = %d,z = %d,ScheduleStatus = %d", id, short_addr, duration,next_task_id,z,GetScheduleStatus()); + return duration; } @@ -615,6 +664,18 @@ SensorScheduler::SensorScheduler() { } else { xy_wave_start_id = max_sensor_num_ + 1; } + + if (max_sensor_num_ == 2 && free_slice_ == 0) { + xy_wave_start_id = 2; + } + + if (max_sensor_num_ == 1 && free_slice_ == 0) { + if (available_slice_ == 2) { + xy_wave_start_id = 1; + } else if (available_slice_ == 4) { + xy_wave_start_id = 2; + } + } for (int i = 1; i <= max_sensor_num_; ++i) { sensor_id_nth_slice_[i] = { i, i + xy_wave_start_id }; slice_sensor_id_[i] = i; @@ -669,6 +730,9 @@ init_config: std::cout << value.asInt() << std::endl; // 转换并输出每个整数 zlog_debug(zbt, "[%d] debug sensor:%x", value.asInt()); debug_slice_sensor_id_[i] = value.asInt(); + if (debug_slice_sensor_id_[i] != 0) { + debug_list_.insert(debug_slice_sensor_id_[i]); + } ++i; } if (i == 1) { @@ -897,6 +961,18 @@ int SensorScheduler::WriteScheduleCfg(long &ts, std::string &world_time) { xy_wave_start_id = max_sensor_num_ + 1; } + if (max_sensor_num_ == 2 && free_slice_ == 0) { + xy_wave_start_id = 2; + } + + if (max_sensor_num_ == 1 && free_slice_ == 0) { + if (available_slice_ == 2) { + xy_wave_start_id = 1; + } else if (available_slice_ == 4) { + xy_wave_start_id = 2; + } + } + for (int i = 1; i <= max_sensor_num_; ++i) { sensor_id_nth_slice_[i] = { i, i + xy_wave_start_id }; slice_sensor_id_[i] = i; @@ -1319,6 +1395,7 @@ void SensorScheduler::GenerateDebugSchedule(std::vector short_addr_lis } if (debug_size == 1) { // 只有一个传感器的话,两分钟一次波形 + zlog_debug(zbt, "one sensor debug"); int j = 0; for (int i = previous_wave_slice+1; i < previous_wave_slice+1+available_slice_; i = i + 3) { j = i % available_slice_; @@ -1328,6 +1405,7 @@ void SensorScheduler::GenerateDebugSchedule(std::vector short_addr_lis debug_slice_sensor_id_[j] = short_addr_list[0]; } } else { + zlog_debug(zbt, "%d sensor debug", debug_list_.size()); int j = 0; int k = 0; for (int i = previous_wave_slice+1; i < previous_wave_slice+1+available_slice_; ++i) { diff --git a/uart/uart.cpp b/uart/uart.cpp index 8a6f7fb..03bc034 100644 --- a/uart/uart.cpp +++ b/uart/uart.cpp @@ -354,7 +354,6 @@ int Uart::DealAskTask(uint16_t ushortAdd){ ScheduleTask scheduleTask; bool z = false; //taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration,z, next_task_id); - current_z = z; if (scheduler::instance().StartSchedule(ushortAdd,next_duration_,z, next_task_id) == kScheduleConfigSensor) { scheduleTask.cmd = CONFIG; @@ -366,13 +365,14 @@ int Uart::DealAskTask(uint16_t ushortAdd){ UpdateConfig(ushortAdd); } uint16_t next_duration = scheduler::instance().GetNextDuration(ushortAdd,z,next_task_id); + current_z = z; zlog_info(zct, "taskID = %d next_duration = %d next_task_id = %d,current_z = %d", taskID, next_duration, next_task_id,current_z); - + if(next_task_id == kScheduleWaveForm){ scheduleTask.cmd = REVIVE_DURATION; scheduleTask.shortAddr = ushortAdd; scheduleTask.duration = next_duration; - scheduleTask.z = z; + scheduleTask.z = current_z; scheduleTask.next_taskID = WAVE_CMD; TaskResp(scheduleTask); }else if (next_task_id == kScheduleEigenValue) { @@ -432,6 +432,7 @@ int Uart::DealReviveDuration(uint16_t ushortAdd){ scheduleTask.cmd = REVIVE_DURATION; scheduleTask.shortAddr = ushortAdd; scheduleTask.duration = next_duration; + scheduleTask.z = z; scheduleTask.next_taskID = next_taskID & 0xFF; TaskResp(scheduleTask); return 0; @@ -449,6 +450,11 @@ int Uart::DealConfig(uint16_t ushortAdd){ } // 判断综合信号强度,低电量,停机状态,任一条件满足都不调度波形 int Uart::WaveSendCondition(char* shortAddr){ + if (schedule_status == kScheduleStatusDebug) + { + return 0; + } + int lowSignal = -1, signalThreshold = -1, lowBatteryLevel = -1, batteryLevelThreshold = -1; char whereCon[100] = {0}; std::string effect = "",rssi = "",batteryPower = ""; @@ -470,7 +476,7 @@ int Uart::WaveSendCondition(char* shortAddr){ sprintf(whereCon,"shortAddr = '%s' ",shortAddr); vec_t vecResult = sqlite_db_ctrl::instance().GetDataSingleLine("t_shutdown_info","*",whereCon); effect = vecResult[5]; - if((lowSignal == 1 && atof(rssi.c_str()) < signalThreshold) || (lowBatteryLevel == 1 && fBatteryPower < batteryLevelThreshold) || effect == "1"){ + if((lowSignal == 1 && (atof(rssi.c_str())*100) < signalThreshold) || (lowBatteryLevel == 1 && fBatteryPower < batteryLevelThreshold) || effect == "1"){ zlog_warn(zct, "WaveSendCondition not meet condition shortAddr = %s,rssi = %s,batteryPower = %s,effect = %s",shortAddr,rssi.c_str(),batteryPower.c_str(),effect.c_str()); return 1; } @@ -490,8 +496,8 @@ int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){ std::string softVersion = res[9]; std::string productNo = res[17]; compressWaveChannel tempchannel; + schedule_status = scheduler::instance().GetScheduleStatus(); if ((compareVersions(softVersion, "2.6") == -1 && productNo == "02") || productNo == "01"){ // DN101所有版本和DN102 2.6以前版本 - schedule_status = scheduler::instance().GetScheduleStatus(); if(schedule_status == kScheduleStatusDebug || schedule_status == kScheduleStatusUpgrade){ zlog_warn(zct, "ScheduleStatus not meet condition ,shortAddr = %s,schedule_status = %d",shortAdd,schedule_status); scheduler::instance().WaveSuccess(ushortAdd,true); @@ -506,14 +512,14 @@ int Uart::DealWaveCompress(const char *pData,uint16_t ushortAdd){ 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{ + }else + { int ret = WaveSendCondition(shortAdd); if(ret == 1){ zlog_warn(zct, "WaveSendCondition not meet condition ,shortAddr = %s",shortAdd); scheduler::instance().WaveSuccess(ushortAdd,true); return 1; }else{ - schedule_status = scheduler::instance().GetScheduleStatus(); if(schedule_status == kScheduleStatusUpgrade){ zlog_warn(zct, "ScheduleStatus not meet condition ,shortAddr = %s,schedule_status = %d",shortAdd,schedule_status); scheduler::instance().WaveSuccess(ushortAdd,true); @@ -773,9 +779,8 @@ void Uart::DealRecvData(const char *pData) { } break; case WAVE_COMPRESS: - - GetLocalZigbeeRSSI(ushortAdd); - DealWaveCompress(pData,ushortAdd); + GetLocalZigbeeRSSI(ushortAdd); + DealWaveCompress(pData,ushortAdd); break; case UPGRADE_ASK: mssleep(50000); diff --git a/uart/uart_feature_parse.cpp b/uart/uart_feature_parse.cpp index 4932211..92d90f2 100644 --- a/uart/uart_feature_parse.cpp +++ b/uart/uart_feature_parse.cpp @@ -30,6 +30,7 @@ unsigned char data[96000] = {0x00}; unsigned char outdata[96000] = {0x00}; unsigned char dealdata[96000] = {0x00}; char mqttData[1024000] = {0}; +char mqttData_vel[10240] = {0}; void Uart::RecordBattery(std::string &strLongAddr, DataRecvStatic &dataStatic, std::string &nowTimetamp) { char insertSql[1024] = {0}; @@ -68,12 +69,13 @@ void Uart::RecordBattery(std::string &strLongAddr, DataRecvStatic &dataStatic, s if (dataStatic.nodeSendTime > 0){ actualRate = (wave_dataLen / 1024.0f) / (dataStatic.nodeSendTime / 1000.0f); //单位:KB/s } - float comprehensiveRSSI = (zigbeeSignal + zigbeeSignalNode) * (actualRate / standardRate); + float comprehensiveRSSI = (((zigbeeSignal + zigbeeSignalNode) / 255.0) / 2.0) * (standardRate / actualRate); if (comprehensiveRSSI > 1.0f) { comprehensiveRSSI = 1.0f; //综合信号强度最大为1 } - zlog_info(zct, "dataNodeNo='%s',wave_dataLen=%d,nodeSendTime=%f,actualRate=%f", strLongAddr.c_str(), wave_dataLen, dataStatic.nodeSendTime, actualRate); + zlog_info(zct, "dataNodeNo='%s',zigbeeSignal = '%d',zigbeeSignalNode = '%d',wave_dataLen=%d,nodeSendTime=%f,actualRate=%f,comprehensiveRSSI = %f", + strLongAddr.c_str(),zigbeeSignal, zigbeeSignalNode,wave_dataLen, dataStatic.nodeSendTime, actualRate,comprehensiveRSSI); //更新综合信号强度到数据库 char updateSql[256] = {0}; memset(whereCon, 0x00, sizeof(whereCon)); @@ -104,39 +106,82 @@ void Uart::DealTriger(uint16_t ushortAdd,std::string & measurementID){ sprintf(whereCon, "MeasurementID='%s' and status ='1' ", measurementID.c_str()); sprintf(tablename,"t_data_%s",measurementID.c_str()); vecTrigger = sqlite_db_ctrl::instance().GetDataSingleLine(" t_wave_triger_info ", " * ", whereCon); + int triger_x = 0,triger_y = 0,triger_z = 0; if (vecTrigger.size() > 0){// 加速度有效值 memset(whereCon, 0x00, sizeof(whereCon)); sprintf(whereCon,"dataNodeNo = '%s' order by timeStamp desc limit 0,3;",measurementID.c_str()); if(vecTrigger[3] == "0"){ array_t arrValue = sqlite_db_ctrl::instance().GetDataMultiLine(tablename, " channelID,rmsValues ", whereCon); if(arrValue.size()){ + triger_x = 0,triger_y = 0,triger_z = 0; for (size_t i = 0; i < arrValue.size(); i++) { float rmsValue_f = atof(arrValue[i][1].c_str()); - if (rmsValue_f >= atof(vecTrigger[4].c_str()) && (arrValue[i][0].find("X") != std::string::npos || arrValue[i][0].find("Y") != std::string::npos)) { - zlog_warn(zct, "measurementID='%s' trigger activated, rmsValue=%f,ushortAdd %04x", measurementID.c_str(), rmsValue_f,ushortAdd); - scheduler::instance().TriggerWave(ushortAdd, 0, 1); - }else if (rmsValue_f >= atof(vecTrigger[4].c_str()) && (arrValue[i][0].find("Z") != std::string::npos)) + if(rmsValue_f >= atof(vecTrigger[4].c_str()) && (arrValue[i][0].find("X") != std::string::npos)){ + triger_x = 1; + zlog_warn(zct, "X measurementID='%s' trigger activated, rmsValue=%f,ushortAdd %04x", measurementID.c_str(), rmsValue_f,ushortAdd); + + } + if(rmsValue_f >= atof(vecTrigger[4].c_str()) && (arrValue[i][0].find("Y") != std::string::npos)) { + zlog_warn(zct, "Y measurementID='%s' trigger activated, rmsValue=%f,ushortAdd %04x", measurementID.c_str(), rmsValue_f,ushortAdd); + triger_y = 1; + } + if (rmsValue_f >= atof(vecTrigger[4].c_str()) && (arrValue[i][0].find("Z") != std::string::npos)) { - zlog_warn(zct, "measurementID='%s' trigger activated, rmsValue=%f,ushortAdd %04x", measurementID.c_str(), rmsValue_f,ushortAdd); - scheduler::instance().TriggerWave(ushortAdd, 1, 0); - } + zlog_warn(zct, "Z measurementID='%s' trigger activated, rmsValue=%f,ushortAdd %04x", measurementID.c_str(), rmsValue_f,ushortAdd); + triger_z = 1; + } + } + zlog_info(zct, "triger_x=%d,triger_y=%d,triger_z=%d", triger_x, triger_y, triger_z); + if((triger_x == 1 || triger_y == 1) && triger_z == 1){ + scheduler::instance().TriggerWave(ushortAdd, 1, 1); + }else if((triger_x == 1 || triger_y == 1) && triger_z != 1){ + scheduler::instance().TriggerWave(ushortAdd, 0, 1); + }else if(triger_x != 1 && triger_y != 1 && triger_z == 1){ + scheduler::instance().TriggerWave(ushortAdd, 1, 0); + } + if (vecTrigger[4] == "0") + { + memset(whereCon, 0x00, sizeof(whereCon)); + sprintf(whereCon,"MeasurementID = '%s'",measurementID.c_str()); + sqlite_db_ctrl::instance().UpdateTableData(" t_wave_triger_info ", " status = '0' ", whereCon); } } }else if (vecTrigger[3] == "1"){// 速度有效值 array_t arrValue = sqlite_db_ctrl::instance().GetDataMultiLine(tablename, " channelID,integratRMS ", whereCon); if(arrValue.size()){ + triger_x = 0,triger_y = 0,triger_z = 0; for (size_t i = 0; i < arrValue.size(); i++) { float integratRMS_f = atof(arrValue[i][1].c_str()); - if (integratRMS_f >= atof(vecTrigger[4].c_str()) && (arrValue[i][0].find("X") != std::string::npos || arrValue[i][0].find("Y") != std::string::npos)) { - zlog_warn(zct, "measurementID='%s' trigger activated, integratRMS=%f,ushortAdd %04x", measurementID.c_str(), integratRMS_f,ushortAdd); - scheduler::instance().TriggerWave(ushortAdd, 0, 1); - }else if (integratRMS_f >= atof(vecTrigger[4].c_str()) && (arrValue[i][0].find("Z") != std::string::npos)) + if (integratRMS_f >= atof(vecTrigger[4].c_str()) && (arrValue[i][0].find("X") != std::string::npos)){ + zlog_warn(zct, "X measurementID='%s' trigger activated, rmsValue=%f,ushortAdd %04x", measurementID.c_str(), integratRMS_f,ushortAdd); + triger_x = 1; + } + if(integratRMS_f >= atof(vecTrigger[4].c_str()) && (arrValue[i][0].find("Y") != std::string::npos)) { + zlog_warn(zct, "Y measurementID='%s' trigger activated, integratRMS=%f,ushortAdd %04x", measurementID.c_str(), integratRMS_f,ushortAdd); + triger_y = 1; + } + if (integratRMS_f >= atof(vecTrigger[4].c_str()) && (arrValue[i][0].find("Z") != std::string::npos)) { - zlog_warn(zct, "measurementID='%s' trigger activated, integratRMS=%f,ushortAdd %04x", measurementID.c_str(), integratRMS_f,ushortAdd); - scheduler::instance().TriggerWave(ushortAdd, 1, 0); - } + zlog_warn(zct, "Z measurementID='%s' trigger activated, integratRMS=%f,ushortAdd %04x", measurementID.c_str(), integratRMS_f,ushortAdd); + triger_z = 1; + } + + } + zlog_info(zct, "triger_x=%d,triger_y=%d,triger_z=%d", triger_x, triger_y, triger_z); + if((triger_x == 1 || triger_y == 1) && triger_z == 1){ + scheduler::instance().TriggerWave(ushortAdd, 1, 1); + }else if((triger_x == 1 || triger_y == 1) && triger_z != 1){ + scheduler::instance().TriggerWave(ushortAdd, 0, 1); + }else if(triger_x != 1 && triger_y != 1 && triger_z == 1){ + scheduler::instance().TriggerWave(ushortAdd, 1, 0); + } + if (vecTrigger[4] == "0") + { + memset(whereCon, 0x00, sizeof(whereCon)); + sprintf(whereCon,"MeasurementID = '%s'",measurementID.c_str()); + sqlite_db_ctrl::instance().UpdateTableData(" t_wave_triger_info ", " status = '0' ", whereCon); } } } @@ -1353,11 +1398,12 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan zlog_info(zct, " product = %s,version = %d ,iChannel = %d", product.c_str(),version,iChannel); if ((product == "02" && sampleRate == 24000 && iChannel == WAVE_Z && version == 1) || (iChannel == WAVE_Z && version == 0) || - ((iChannel == WAVE_LF_X || iChannel == WAVE_LF_Y|| iChannel == WAVE_LF_Z) && version == 0)){ + ((iChannel == WAVE_LF_X || iChannel == WAVE_LF_Y|| iChannel == WAVE_LF_Z) && version == 0) || + ((iChannel == WAVE_X || iChannel == WAVE_Y) && version == 0)){ sampleRate = 25600; zlog_info(zct, " sampleRate = %d,product = %s,ACCSampleTime = %f ", sampleRate,product.c_str(),ACCSampleTime); size_t outSize = 25600; - std::vector outputData,outputData2; + std::vector outputData,outputData2,IntegrationWave; float epsilon = 1e-6f; if (std::fabs(ACCSampleTime - 1) < epsilon){ outputData = Calculation::fftInterpolate(vecData, outSize); @@ -1371,26 +1417,32 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan outputData.push_back(outputData2[i]); } }else if(std::fabs(ACCSampleTime - 1.28) < epsilon){ + outSize = 32768; + sampleRate = 25600; outputData = Calculation::fftInterpolate(vecData, outSize); - zlog_info(zct, " outputData_size %zu ,ACCSampleTime %f", outputData.size(),ACCSampleTime); + zlog_info(zct, "1.28 outputData_size %zu ,ACCSampleTime %f", outputData.size(),ACCSampleTime); }else if(std::fabs(ACCSampleTime - 3.2) < epsilon){ outSize = 8192; + sampleRate = 2560; outputData = Calculation::fftInterpolate(vecData, outSize); - zlog_info(zct, " outputData_size %zu ,ACCSampleTime %f", outputData.size(),ACCSampleTime); + + zlog_info(zct, "3.2 outputData_size %zu ,ACCSampleTime %f", outputData.size(),ACCSampleTime); }else if(std::fabs(ACCSampleTime - 1.6) < epsilon){ - outSize = 5120; + outSize = 8192; + sampleRate = 5120; outputData = Calculation::fftInterpolate(vecData, outSize); - zlog_info(zct, " outputData_size %zu ,ACCSampleTime %f", outputData.size(),ACCSampleTime); + zlog_info(zct, "1.6 outputData_size %zu ,ACCSampleTime %f", outputData.size(),ACCSampleTime); } - zlog_info(zct, " outputData_size %d ", outputData.size()); + zlog_info(zct, " outputData_size %zu ", outputData.size()); float mean = Calculation::mean(outputData); memset(mqttData,0,sizeof(mqttData)); + memset(mqttData_vel,0,sizeof(mqttData_vel)); id = 0; for (size_t i = 0; i < outputData.size(); i++) { frTemp = outputData[i] - mean; memset(buf, 0x00, sizeof(buf)); sprintf(buf, "%.2f", frTemp); - if(i != outputData.size() -1){ + if (i != outputData.size() -1){ strncpy(mqttData + id ,buf,strlen(buf)); id = id + strlen(buf); strncpy(mqttData + id,",",1); @@ -1399,6 +1451,29 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan strncpy(mqttData + id ,buf,strlen(buf)); } } + if(iChannel == WAVE_LF_X || iChannel == WAVE_LF_Y|| iChannel == WAVE_LF_Z){ + double resolution = 1 / 3.2 ; + //积分 + id = 0; + std::vector outputDataAC(outputData.size()); + for (size_t i = 0; i < outputData.size(); i++) + { + outputDataAC[i] = outputData[i] - mean; + } + Calculation::Integration(outputDataAC, IntegrationWave, resolution); + for (size_t i = 0; i < IntegrationWave.size(); i++) { + memset(buf, 0x00, sizeof(buf)); + sprintf(buf, "%.2f", IntegrationWave[i]); + if (i != IntegrationWave.size() -1){ + strncpy(mqttData_vel + id ,buf,strlen(buf)); + id = id + strlen(buf); + strncpy(mqttData_vel + id,",",1); + id = id + 1; + }else{ + strncpy(mqttData_vel + id ,buf,strlen(buf)); + } + } + } } zlog_info(zct, "fopen file vecData.size : %d end ", vecData.size()); wave_channel.wave_timestamp = nowTimetamp; @@ -1413,6 +1488,10 @@ void Uart::WriteDatFile(int sampleRate, std::string &strMeasurementID, int iChan valWaveData["waveData"] = mqttData; valWaveData["mean"] = mean; valWaveData["waveType"] = wave_type; + if(iChannel == WAVE_LF_X || iChannel == WAVE_LF_Y|| iChannel == WAVE_LF_Z){ + valWaveData["waveDataVel"] = mqttData_vel; + } + valWaveData["seconds"] = ACCSampleTime; Json::FastWriter WaveValue; std::string WaveData = WaveValue.write(valWaveData); diff --git a/uart/uart_parameter_config.cpp b/uart/uart_parameter_config.cpp index 0935270..ae51a11 100644 --- a/uart/uart_parameter_config.cpp +++ b/uart/uart_parameter_config.cpp @@ -594,7 +594,7 @@ int Uart::TaskResp(ScheduleTask scheduleTask){ y = 1; z = 0; } - zlog_info(zct,"wave x = %d,y = %d,z = %d\n",x,y,z); + zlog_info(zct,"wave x = %d,y = %d,z = %d,scheduleTask.z = %d\n",x,y,z,scheduleTask.z); send_data[17] = x; send_data[18] = y; send_data[19] = z;