From 890fcb6736150d5b3b4f3580cc85ce53432b1d3a Mon Sep 17 00:00:00 2001 From: pandx Date: Tue, 1 Apr 2025 14:40:47 +0800 Subject: [PATCH] add wave missed schedule. --- scheduler/schedule.cpp | 72 ++++++++++++++++++++++++++++++++++-------- scheduler/schedule.hpp | 4 ++- 2 files changed, 61 insertions(+), 15 deletions(-) diff --git a/scheduler/schedule.cpp b/scheduler/schedule.cpp index b48aec1..c80bb3c 100644 --- a/scheduler/schedule.cpp +++ b/scheduler/schedule.cpp @@ -139,17 +139,15 @@ int SensorScheduler::StartSchedule(int short_addr, int &next_duration) { } } - if (RetransferWave(short_addr)) { - wave_feature_set_inst::instance().GetWaveCfg(short_addr, g_x, g_y, g_z); - if (g_x || g_y || g_z) { - zlog_warn(zct, "[%d:%x] it is retransfer 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); - return kScheduleWrongTime; - } + if (RetransferWave(short_addr)) { + zlog_warn(zct, "[%d:%x] it is retransfer wave time", id, short_addr); + current_request_ = kScheduleWaveForm; + return kScheduleWaveForm; + } else if (MissedWave(short_addr)) { + zlog_warn(zct, "[%d:%x] it is patch wave time", id, short_addr); + current_request_ = kScheduleWaveForm; + patch_set_.erase(short_addr); + return kScheduleWaveForm; } // if (update_.count(id)) { // // execute config @@ -169,6 +167,17 @@ int SensorScheduler::StartSchedule(int short_addr, int &next_duration) { long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) { // current_ts_ = GetLocalTs(); + // 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_) { int forward_wave_slice_num = nth_eigen_value_slice_ * wave_slice_num_per_eigen_interval_; auto wave_slice_iter = sensor_id_nth_slice_.find(id); @@ -193,6 +202,19 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) { } } } + + if (send_wave_ts == 0) { + // add for patch wave + int nth_wave_slice = nth_eigen_value_slice_ * wave_slice_num_per_eigen_interval_ + nth_wave_slice_ + 1; + auto wave_slice_iter = sensor_id_nth_slice_.find(id); + if (wave_slice_iter != sensor_id_nth_slice_.end()) { + if (nth_wave_slice > wave_slice_iter->second) { + if (success_set_.count(short_addr) == 0 && !RetransferWave(short_addr)) { + patch_set_.insert(short_addr); + } + } + } + } } long available_ts = 0; @@ -227,6 +249,19 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) { } } } + } else if (MissedWave(short_addr)) { + for (int i = 0; i < wave_slice_num_per_eigen_interval_; ++i) { + if (slice_sensor_id_[i+forward_wave_slice_num] == 0) { + // 判断此空闲位置是否被占用 + long current_wave_slice_ts = current_wave_start_ts_ + nth_eigen_value_slice_ * eigen_value_send_interval_ + eigen_value_slice_total_seconds_ + i * seconds_per_wave_slice_; + if (free_slice_ocuppied_.count(current_wave_slice_ts) == 0) { + available_ts = current_wave_slice_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()); + break; + } + } + } } } } @@ -366,7 +401,7 @@ void SensorScheduler::WaveError(int short_addr) { return; } if (iter->second == 0) { - zlog_warn(zct, "[WaveError][%x] no try times"); + zlog_warn(zct, "[WaveError][%x] no try times", short_addr); failure_map_.erase(short_addr); return; } @@ -383,8 +418,16 @@ bool SensorScheduler::RetransferWave(uint16_t short_addr) { return false; } +bool SensorScheduler::MissedWave(uint16_t short_addr) { + if (patch_set_.count(short_addr) > 0) { + return true; + } + + return false; +} + void SensorScheduler::WaveSuccess(int short_addr) { - success_map_[short_addr] = 1; + success_set_.insert(short_addr); auto iter = failure_map_.find(short_addr); if (iter != failure_map_.end()) { zlog_warn(zct, "[WaveSuccess][%x] try %d times success", short_addr, 4 - iter->second); @@ -396,7 +439,8 @@ void SensorScheduler::WaveSuccess(int short_addr) { void SensorScheduler::ClearFailureSuccessMap() { failure_map_.clear(); - success_map_.clear(); + success_set_.clear(); + patch_set_.clear(); } long SensorScheduler::GetBaseTimestamp(int short_addr) { diff --git a/scheduler/schedule.hpp b/scheduler/schedule.hpp index fbe893c..08be944 100644 --- a/scheduler/schedule.hpp +++ b/scheduler/schedule.hpp @@ -128,9 +128,11 @@ private: // 存储当前2小时内失败与成功的传感器 std::map failure_map_; - std::map success_map_; + std::unordered_set success_set_; + std::unordered_set patch_set_; // 漏传的补传 void ClearFailureSuccessMap(); bool RetransferWave(uint16_t short_addr); + bool MissedWave(uint16_t short_addr); // 空闲时间戳被占用 std::unordered_set free_slice_ocuppied_;