From f0ade9888d304fb036d5dd43d1668ab02c23aa52 Mon Sep 17 00:00:00 2001 From: pandx Date: Fri, 8 Nov 2024 14:23:09 +0800 Subject: [PATCH] add interface to clear cfg file. --- scheduler/schedule.cpp | 491 ++++++++++++++++++----------------- scheduler/schedule.hpp | 8 +- scheduler/short_addr_cfg.cpp | 6 + scheduler/short_addr_cfg.hpp | 1 + scheduler/update_cfg.cpp | 6 + scheduler/update_cfg.hpp | 1 + scheduler/upgrade_cfg.cpp | 6 + scheduler/upgrade_cfg.hpp | 1 + 8 files changed, 286 insertions(+), 234 deletions(-) diff --git a/scheduler/schedule.cpp b/scheduler/schedule.cpp index 7460b5b..f86d060 100644 --- a/scheduler/schedule.cpp +++ b/scheduler/schedule.cpp @@ -14,238 +14,6 @@ extern zlog_category_t *zct; extern zlog_category_t *zbt; -// 当一个传感器来进行通信时 - -int SensorScheduler::WriteScheduleCfg(long &ts, std::string &world_time) { - Json::Value root; - - root["schedule_start_timestamp"] = std::to_string(ts); - root["schedule_start_time"] = world_time; - root["eigen_value_send_interval"] = eigen_value_send_interval_; - root["eigen_value_send_duration"] = eigen_value_send_duration_; - root["wave_form_send_interval"] = wave_form_send_interval_; - root["wave_form_send_duration"] = wave_form_send_duration_; - root["max_sensor_num"] = max_sensor_num_; - root["available_slice"] = available_slice_; - root["free_slice"] = free_slice_; - root["support_modification"] = true; - - int *slice_allocation = new int[available_slice_]; - int slice_index = 0; // 有时间片的索引 - int no_slice_index = 0; // 没有时间片的索引 - int k = 1; - slice_sensor_id_.clear(); - - for (int i = 0; i < available_slice_; ++i) { - if (slice_index < max_sensor_num_ && (i % 2 == 0 || no_slice_index >= free_slice_)) { - slice_allocation[i] = k; - sensor_id_nth_slice_[k] = i + 1; - slice_sensor_id_.push_back(k); - k = k + 1; - slice_index++; - } else if (no_slice_index < free_slice_) { - slice_sensor_id_.push_back(0); - slice_allocation[i] = 0; - no_slice_index++; - } - } - - Json::Value ids; - for (int i = 0; i < available_slice_; ++i) { - ids.append(slice_allocation[i]); - } - delete []slice_allocation; - root["id"] = ids; - Json::StyledStreamWriter streamWriter; - std::ofstream out_file(SCHEDULE_CONFIG); - streamWriter.write(out_file, root); - out_file.close(); - return 0; -} - -SensorScheduler::SensorScheduler() { - support_modification_ = true; - std::ifstream schedule_file(SCHEDULE_CONFIG); - if (schedule_file.good()) { - zlog_info(zbt, "exist configuration file"); - Json::Reader reader; - Json::Value root; - if (!reader.parse(schedule_file, root, false)) { - zlog_error(zbt, "invalid format, fail to parse %s", SCHEDULE_CONFIG); - schedule_file.close(); - return; - } - schedule_file.close(); - if (!root.isObject()) { - zlog_error(zbt, "invalid format, not an object: %s", SCHEDULE_CONFIG); - return; - } - start_timestamp_ = std::stol(root["schedule_start_timestamp"].asString()); - start_ts_str_ = root["schedule_start_timestamp"].asString(); - eigen_value_send_interval_ = root["eigen_value_send_interval"].asInt(); - eigen_value_send_duration_ = root["eigen_value_send_duration"].asInt(); - wave_form_send_interval_ = root["wave_form_send_interval"].asInt(); - wave_form_send_duration_ = root["wave_form_send_duration"].asInt(); - max_sensor_num_ = root["max_sensor_num"].asInt(); - available_slice_ = root["available_slice"].asInt(); - free_slice_ = root["free_slice"].asInt(); - support_modification_ = root["support_modification"].asBool(); - - const Json::Value ids = root["id"]; - int sensor_id = 0; - int i = 0; - for (const auto& id : ids) { - sensor_id = id.asInt(); - slice_sensor_id_.push_back(sensor_id); - if (sensor_id != 0) { - sensor_id_nth_slice_[sensor_id] = i+1; - } - ++i; - } - - eigen_value_slice_total_seconds_ = eigen_value_send_duration_ * max_sensor_num_; - int rest_duration = eigen_value_send_interval_ - eigen_value_slice_total_seconds_; - wave_slice_num_per_eigen_interval_ = rest_duration / wave_form_send_duration_; - seconds_per_wave_slice_ = rest_duration / wave_slice_num_per_eigen_interval_; - } else { - zlog_info(zbt, "use default configuration"); - // int eigen_value_send_interval = 300; - // int wave_form_send_interval = 7200; - // int eigen_value_send_duration = 6; - // int wave_form_send_duration = 50; - // int max_sensor_num = 32; - - int eigen_value_send_interval = 120; - int wave_form_send_interval = 240; - int eigen_value_send_duration = 6; - int wave_form_send_duration = 40; - int max_sensor_num = 4; - std::string error_msg; - Config(eigen_value_send_interval, - wave_form_send_interval, - eigen_value_send_duration, - wave_form_send_duration, - max_sensor_num, - error_msg); - } - - short_addr_map_.clear(); - ShortAddrCfg::ReadCfg(short_addr_map_); - - // read upgrade config file: UPGRADE_CONFIG - UpgradeCfg::ReadCfg(upgrade_); - - // read config update file: CONFIG_UPDATE - UpdateCfg::ReadCfg(update_); -} - -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); - int duration = next_ts - current_ts; - zlog_warn(zct, "[%d] next duration is %d", id, duration); - return duration; -} - -long SensorScheduler::GetBaseTimestamp(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; - } - return start_timestamp_ + (id - 1) * eigen_value_send_duration_; -} - -long SensorScheduler::CalcNextTimestamp(int id) { - // current_ts_ = GetLocalTs(); - 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); - if (wave_slice_iter == sensor_id_nth_slice_.end()) { - zlog_error(zct, "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_; - zlog_error(zct, "[%d] next feature send utc time:[%s]", id, GetUTCTime(available_ts).c_str()); - return available_ts; - } - int wave_slice = wave_slice_iter->second; // 从1开始 - long send_wave_ts = 0; - if (wave_slice > forward_wave_slice_num && - wave_slice <= forward_wave_slice_num + wave_slice_num_per_eigen_interval_) { - // 发送波的时间窗也在本次特征值发送间隔中 - for (int i = forward_wave_slice_num; i <= forward_wave_slice_num + wave_slice_num_per_eigen_interval_; ++i) { - if (wave_slice - 1 == i) { - send_wave_ts = current_wave_start_ts_ + nth_eigen_value_slice_ * eigen_value_send_interval_ + eigen_value_slice_total_seconds_ + (i - forward_wave_slice_num) * seconds_per_wave_slice_; - zlog_debug(zct, "[%d] send wave time:[%s]\n", id, GetUTCTime(send_wave_ts).c_str()); - break; - } - } - } - - long available_ts = 0; - auto upgrade_iter = upgrade_.find(id); - if (upgrade_iter != upgrade_.end()) { - if (upgrade_iter->second.try_times < 10) { - 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_debug(zct, "[%d] %d nth free wave slice will be used to upgrade, utc time:[%s]", id, i+forward_wave_slice_num, GetUTCTime(available_ts).c_str()); - break; - } - } - } - } - } - if (send_wave_ts > 0 && available_ts > 0) { - long min_ts = std::min(send_wave_ts, available_ts); - zlog_warn(zct, "[%d] next feature send utc time1:%s", id, GetUTCTime(min_ts).c_str()); - return min_ts; - } - if (send_wave_ts + available_ts > 0) { - long max_ts = std::max(send_wave_ts, available_ts); - zlog_warn(zct, "[%d] next feature send utc time2:%s", id, GetUTCTime(max_ts).c_str()); - 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_; - zlog_warn(zct, "[%d] next feature send utc time3:[%s]", id, GetUTCTime(available_ts).c_str()); - return available_ts; -} - -int SensorScheduler::GetAvailableId(int short_addr) { - int max_support_sensor[128] = {0}; - for (auto it = short_addr_map_.begin(); it != short_addr_map_.end(); ++it) { - max_support_sensor[it->second] = 1; - } - int available_id = 0; - for (int i = 1; i < 128; ++i) { - if (max_support_sensor[i] == 0) { - available_id = i; - break; - } - } - zlog_warn(zct, "[GetAvailableId][%d] short addr : %x", available_id, short_addr); - short_addr_map_[short_addr] = available_id; - ShortAddrCfg::WriteCfg(short_addr_map_); - return available_id; -} - int SensorScheduler::StartSchedule(int short_addr, int &next_duration) { int id = 0; auto iter = short_addr_map_.find(short_addr); @@ -363,6 +131,236 @@ int SensorScheduler::StartSchedule(int short_addr, int &next_duration) { } } +long SensorScheduler::CalcNextTimestamp(int id) { + // current_ts_ = GetLocalTs(); + 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); + if (wave_slice_iter == sensor_id_nth_slice_.end()) { + zlog_error(zct, "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_; + zlog_error(zct, "[%d] next feature send utc time:[%s]", id, GetUTCTime(available_ts).c_str()); + return available_ts; + } + int wave_slice = wave_slice_iter->second; // 从1开始 + long send_wave_ts = 0; + if (wave_slice > forward_wave_slice_num && + wave_slice <= forward_wave_slice_num + wave_slice_num_per_eigen_interval_) { + // 发送波的时间窗也在本次特征值发送间隔中 + for (int i = forward_wave_slice_num; i <= forward_wave_slice_num + wave_slice_num_per_eigen_interval_; ++i) { + if (wave_slice - 1 == i) { + send_wave_ts = current_wave_start_ts_ + nth_eigen_value_slice_ * eigen_value_send_interval_ + eigen_value_slice_total_seconds_ + (i - forward_wave_slice_num) * seconds_per_wave_slice_; + zlog_debug(zct, "[%d] send wave time:[%s]\n", id, GetUTCTime(send_wave_ts).c_str()); + break; + } + } + } + + long available_ts = 0; + auto upgrade_iter = upgrade_.find(id); + if (upgrade_iter != upgrade_.end()) { + if (upgrade_iter->second.try_times < 10) { + 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_debug(zct, "[%d] %d nth free wave slice will be used to upgrade, utc time:[%s]", id, i+forward_wave_slice_num, GetUTCTime(available_ts).c_str()); + break; + } + } + } + } + } + if (send_wave_ts > 0 && available_ts > 0) { + long min_ts = std::min(send_wave_ts, available_ts); + zlog_warn(zct, "[%d] next feature send utc time1:%s", id, GetUTCTime(min_ts).c_str()); + return min_ts; + } + if (send_wave_ts + available_ts > 0) { + long max_ts = std::max(send_wave_ts, available_ts); + zlog_warn(zct, "[%d] next feature send utc time2:%s", id, GetUTCTime(max_ts).c_str()); + 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_; + zlog_warn(zct, "[%d] next feature send utc time3:[%s]", id, GetUTCTime(available_ts).c_str()); + return available_ts; +} + +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); + int duration = next_ts - current_ts; + zlog_warn(zct, "[%d] next duration is %d", id, duration); + return duration; +} + +SensorScheduler::SensorScheduler() { + support_modification_ = true; + std::ifstream schedule_file(SCHEDULE_CONFIG); + if (schedule_file.good()) { + zlog_info(zbt, "exist configuration file"); + Json::Reader reader; + Json::Value root; + if (!reader.parse(schedule_file, root, false)) { + zlog_error(zbt, "invalid format, fail to parse %s", SCHEDULE_CONFIG); + schedule_file.close(); + return; + } + schedule_file.close(); + if (!root.isObject()) { + zlog_error(zbt, "invalid format, not an object: %s", SCHEDULE_CONFIG); + return; + } + start_timestamp_ = std::stol(root["schedule_start_timestamp"].asString()); + start_ts_str_ = root["schedule_start_time"].asString(); + eigen_value_send_interval_ = root["eigen_value_send_interval"].asInt(); + eigen_value_send_duration_ = root["eigen_value_send_duration"].asInt(); + wave_form_send_interval_ = root["wave_form_send_interval"].asInt(); + wave_form_send_duration_ = root["wave_form_send_duration"].asInt(); + max_sensor_num_ = root["max_sensor_num"].asInt(); + available_slice_ = root["available_slice"].asInt(); + free_slice_ = root["free_slice"].asInt(); + support_modification_ = root["support_modification"].asBool(); + + const Json::Value ids = root["id"]; + int sensor_id = 0; + int i = 0; + for (const auto& id : ids) { + sensor_id = id.asInt(); + slice_sensor_id_.push_back(sensor_id); + if (sensor_id != 0) { + sensor_id_nth_slice_[sensor_id] = i+1; + } + ++i; + } + + eigen_value_slice_total_seconds_ = eigen_value_send_duration_ * max_sensor_num_; + int rest_duration = eigen_value_send_interval_ - eigen_value_slice_total_seconds_; + wave_slice_num_per_eigen_interval_ = rest_duration / wave_form_send_duration_; + seconds_per_wave_slice_ = rest_duration / wave_slice_num_per_eigen_interval_; + } else { + zlog_info(zbt, "use default configuration"); + // int eigen_value_send_interval = 300; + // int wave_form_send_interval = 7200; + // int eigen_value_send_duration = 6; + // int wave_form_send_duration = 50; + // int max_sensor_num = 32; + + int eigen_value_send_interval = 120; + int wave_form_send_interval = 240; + int eigen_value_send_duration = 6; + int wave_form_send_duration = 40; + int max_sensor_num = 4; + std::string error_msg; + Config(eigen_value_send_interval, + wave_form_send_interval, + eigen_value_send_duration, + wave_form_send_duration, + max_sensor_num, + error_msg); + } + + short_addr_map_.clear(); + ShortAddrCfg::ReadCfg(short_addr_map_); + + // read upgrade config file: UPGRADE_CONFIG + UpgradeCfg::ReadCfg(upgrade_); + + // read config update file: CONFIG_UPDATE + UpdateCfg::ReadCfg(update_); +} + +long SensorScheduler::GetBaseTimestamp(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; + } + return start_timestamp_ + (id - 1) * eigen_value_send_duration_; +} + +int SensorScheduler::GetAvailableId(int short_addr) { + int max_support_sensor[128] = {0}; + for (auto it = short_addr_map_.begin(); it != short_addr_map_.end(); ++it) { + max_support_sensor[it->second] = 1; + } + int available_id = 0; + for (int i = 1; i < 128; ++i) { + if (max_support_sensor[i] == 0) { + available_id = i; + break; + } + } + zlog_warn(zct, "[GetAvailableId][%d] short addr : %x", available_id, short_addr); + short_addr_map_[short_addr] = available_id; + ShortAddrCfg::WriteCfg(short_addr_map_); + return available_id; +} + +int SensorScheduler::WriteScheduleCfg(long &ts, std::string &world_time) { + Json::Value root; + + root["schedule_start_timestamp"] = std::to_string(ts); + root["schedule_start_time"] = world_time; + root["eigen_value_send_interval"] = eigen_value_send_interval_; + root["eigen_value_send_duration"] = eigen_value_send_duration_; + root["wave_form_send_interval"] = wave_form_send_interval_; + root["wave_form_send_duration"] = wave_form_send_duration_; + root["max_sensor_num"] = max_sensor_num_; + root["available_slice"] = available_slice_; + root["free_slice"] = free_slice_; + root["support_modification"] = true; + + int *slice_allocation = new int[available_slice_]; + int slice_index = 0; // 有时间片的索引 + int no_slice_index = 0; // 没有时间片的索引 + int k = 1; + slice_sensor_id_.clear(); + + for (int i = 0; i < available_slice_; ++i) { + if (slice_index < max_sensor_num_ && (i % 2 == 0 || no_slice_index >= free_slice_)) { + slice_allocation[i] = k; + sensor_id_nth_slice_[k] = i + 1; + slice_sensor_id_.push_back(k); + k = k + 1; + slice_index++; + } else if (no_slice_index < free_slice_) { + slice_sensor_id_.push_back(0); + slice_allocation[i] = 0; + no_slice_index++; + } + } + + Json::Value ids; + for (int i = 0; i < available_slice_; ++i) { + ids.append(slice_allocation[i]); + } + delete []slice_allocation; + root["id"] = ids; + Json::StyledStreamWriter streamWriter; + std::ofstream out_file(SCHEDULE_CONFIG); + streamWriter.write(out_file, root); + out_file.close(); + return 0; +} + int SensorScheduler::Config(int eigen_value_send_interval, int wave_form_send_interval, int eigen_value_send_duration, int wave_form_send_duration, int max_sensor_num, std::string &error_msg) { if (!support_modification_) { @@ -594,3 +592,32 @@ void SensorScheduler::UpdateUpgradeInfo(int id) { upgrade_iter->second.try_world_time1.push_back(GetUTCTime(ts)); UpgradeCfg::WriteCfg(upgrade_); } + +void SensorScheduler::ModifyScheduleTs(int diff_ts) { + zlog_warn(zbt, "[ModifyScheduleTs] adjust ts:%d, from:%ld to:%ld", diff_ts, start_timestamp_, start_timestamp_ + diff_ts); + start_timestamp_ += diff_ts; + start_ts_str_ = GetUTCTime(start_timestamp_); + std::ifstream schedule_file(SCHEDULE_CONFIG); + Json::Reader reader; + Json::Value root; + if (!reader.parse(schedule_file, root, false)) { + zlog_error(zbt, "[ModifyScheduleTs] invalid format, fail to parse %s", SCHEDULE_CONFIG); + schedule_file.close(); + return; + } + schedule_file.close(); + root["schedule_start_timestamp"] = std::to_string(start_timestamp_); + root["schedule_start_time"] = start_ts_str_; + + Json::StyledStreamWriter streamWriter; + std::ofstream out_file(SCHEDULE_CONFIG); + streamWriter.write(out_file, root); + out_file.close(); +} + +void SensorScheduler::ClearScheduleCfg() { + zlog_warn(zbt, "[ClearScheduleCfg] clear all schedule config"); + ShortAddrCfg::ClearCfg(); + UpdateCfg::ClearCfg(); + UpgradeCfg::ClearCfg(); +} \ No newline at end of file diff --git a/scheduler/schedule.hpp b/scheduler/schedule.hpp index 13857bb..645d81b 100644 --- a/scheduler/schedule.hpp +++ b/scheduler/schedule.hpp @@ -84,12 +84,16 @@ public: // void ReadScheduleCfg(); // 配置完成后 int WriteScheduleCfg(long &ts, std::string &world_time); - // 当系统进行校时时,修改时间戳信息, "slices"字段 - void ModifyScheduleTs(long start_ts); + + // 当系统进行校时时,输入参数为新的时间戳与以前时间戳的差值 + void ModifyScheduleTs(int diff_ts); + // 当接入传感器时,设置为不可修改; 当停用所有传感器后,修改为可修改 void AdjustSupportModification(bool support_modification); // ======schedule.json操作结束====== + void ClearScheduleCfg(); + long GetLocalTs(); long GetLocalWorldTime(std::string &world_time); std::string GetUTCTime(long ts); diff --git a/scheduler/short_addr_cfg.cpp b/scheduler/short_addr_cfg.cpp index a3529f7..55edefd 100644 --- a/scheduler/short_addr_cfg.cpp +++ b/scheduler/short_addr_cfg.cpp @@ -54,3 +54,9 @@ int ShortAddrCfg::WriteCfg(std::map &short_addr_map) { streamWriter.write(out_file, root); return 0; } + +void ShortAddrCfg::ClearCfg() { + std::string clear_cmd = "rm -rf "; + clear_cmd.append(BASE_RELATION); + system(clear_cmd.c_str()); +} diff --git a/scheduler/short_addr_cfg.hpp b/scheduler/short_addr_cfg.hpp index 4c18603..1839d42 100644 --- a/scheduler/short_addr_cfg.hpp +++ b/scheduler/short_addr_cfg.hpp @@ -9,6 +9,7 @@ class ShortAddrCfg { public: static int ReadCfg(std::map &short_addr_map); static int WriteCfg(std::map &short_addr_map); + static void ClearCfg(); }; #endif // SHORT_ADDR_CFG_HPP_ \ No newline at end of file diff --git a/scheduler/update_cfg.cpp b/scheduler/update_cfg.cpp index 4f40eca..341d1d9 100644 --- a/scheduler/update_cfg.cpp +++ b/scheduler/update_cfg.cpp @@ -46,3 +46,9 @@ int UpdateCfg::WriteCfg(std::unordered_set &update) { out_file.close(); return 0; } + +void UpdateCfg::ClearCfg() { + std::string clear_cmd = "rm -rf "; + clear_cmd.append(CONFIG_UPDATE); + system(clear_cmd.c_str()); +} diff --git a/scheduler/update_cfg.hpp b/scheduler/update_cfg.hpp index 8b1ef53..03d3bb3 100644 --- a/scheduler/update_cfg.hpp +++ b/scheduler/update_cfg.hpp @@ -8,6 +8,7 @@ class UpdateCfg { public: static int ReadCfg(std::unordered_set &update); static int WriteCfg(std::unordered_set &update); + static void ClearCfg(); }; diff --git a/scheduler/upgrade_cfg.cpp b/scheduler/upgrade_cfg.cpp index 3ff331b..2beb7cb 100644 --- a/scheduler/upgrade_cfg.cpp +++ b/scheduler/upgrade_cfg.cpp @@ -74,3 +74,9 @@ int UpgradeCfg::WriteCfg(std::map &upgrade) { out_file.close(); return 0; } + +void UpgradeCfg::ClearCfg() { + std::string clear_cmd = "rm -rf "; + clear_cmd.append(UPGRADE_CONFIG); + system(clear_cmd.c_str()); +} diff --git a/scheduler/upgrade_cfg.hpp b/scheduler/upgrade_cfg.hpp index d69c285..da00c94 100644 --- a/scheduler/upgrade_cfg.hpp +++ b/scheduler/upgrade_cfg.hpp @@ -20,6 +20,7 @@ class UpgradeCfg { public: static int ReadCfg(std::map &upgrade); static int WriteCfg(std::map &upgrade); + static void ClearCfg(); }; #endif // UPGRADE_CFG_HPP_ \ No newline at end of file