From a7ae340c017de760bc35e3642be090a4d068ef16 Mon Sep 17 00:00:00 2001 From: pandx Date: Thu, 9 Jan 2025 12:00:54 +0800 Subject: [PATCH] fix the bug when there are three wave time slices in one eigen interval and modify version from 5.2 to 5.3 --- platform/platform_init.cpp | 2 +- scheduler/schedule.hpp | 2 +- scheduler/upgrade_cfg.cpp | 13 +++++++++++++ scheduler/wave_feature_set.cpp | 32 ++++++++++++++++---------------- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/platform/platform_init.cpp b/platform/platform_init.cpp index 995dc1b..96d0e1e 100644 --- a/platform/platform_init.cpp +++ b/platform/platform_init.cpp @@ -14,7 +14,7 @@ int GlobalConfig::LinkStatus_G = 0; int GlobalConfig::LinkCount = 0; int GlobalConfig::net0Status = 1; -std::string GlobalConfig::Version = "5.2"; +std::string GlobalConfig::Version = "5.3"; std::string GlobalConfig::MacAddr_G = ""; std::string GlobalConfig::MacAddr_G2 = ""; std::string GlobalConfig::IpAddr_G = ""; diff --git a/scheduler/schedule.hpp b/scheduler/schedule.hpp index 73e0d84..a3a959d 100644 --- a/scheduler/schedule.hpp +++ b/scheduler/schedule.hpp @@ -142,7 +142,7 @@ private: int seconds_in_current_eigen_slice_; // 相对特征值发送间隔的秒数 bool ts_in_eigen_slice_; // 时间位于特征值发送窗口中 int nth_eigen_slice_; // 如果ts_in_eigen_slice_是真的话,此值表明是第几个特征值窗口 - bool nth_wave_slice_; // 如果ts_in_eigen_slice_是假的话,此值表明是第几个波形窗口 + int nth_wave_slice_; // 如果ts_in_eigen_slice_是假的话,此值表明是第几个波形窗口 int current_request_; }; diff --git a/scheduler/upgrade_cfg.cpp b/scheduler/upgrade_cfg.cpp index 1ae8386..eeaf2c2 100644 --- a/scheduler/upgrade_cfg.cpp +++ b/scheduler/upgrade_cfg.cpp @@ -12,6 +12,14 @@ int UpgradeCfg::ReadCfg(std::map &upgrade) { zlog_info(zbt, "[UpgradeCfg] no such file"); return 0; } + upgrade_file.seekg(0, std::ios::end); + std::streampos file_size = upgrade_file.tellg(); + if (file_size > 256000) { + zlog_error(zct, "upgrade file exception, will remove it"); + ClearCfg(); + return 1; + } + upgrade_file.seekg(0, std::ios::beg); Json::Reader reader; Json::Value root; @@ -51,6 +59,11 @@ int UpgradeCfg::ReadCfg(std::map &upgrade) { } int UpgradeCfg::WriteCfg(std::map &upgrade) { + if (upgrade.size() == 0) { + ClearCfg(); + return 0; + } + Json::Value root; for (auto item : upgrade) { Json::Value upgrade_item; diff --git a/scheduler/wave_feature_set.cpp b/scheduler/wave_feature_set.cpp index f9cb8e1..67ef933 100644 --- a/scheduler/wave_feature_set.cpp +++ b/scheduler/wave_feature_set.cpp @@ -33,12 +33,12 @@ WaveFeatureSetting::WaveFeatureSetting() { global_feature_.short_addr = 0; for (size_t i = 0; i < v.size(); ++i) { if (i == 0) { - global_feature_.x = v[i].asInt(); + global_feature_.x = v.get(i, 0).asInt(); } else if (i == 1) { - global_feature_.y = v[i].asInt(); + global_feature_.y = v.get(i, 0).asInt(); } else if (i == 2) { - global_feature_.z = v[i].asInt(); - } + global_feature_.z = v.get(i, 0).asInt(); + } } } else { short_addr = strtol(key.c_str(), &end_ptr, 16); @@ -46,12 +46,12 @@ WaveFeatureSetting::WaveFeatureSetting() { FeatureEntryPrivateCfg item; for (size_t i = 0; i < v.size(); ++i) { if (i == 0) { - item.x = v[i].asInt(); + item.x = v.get(i, 0).asInt(); } else if (i == 1) { - item.y = v[i].asInt(); + item.y = v.get(i, 0).asInt(); } else if (i == 2) { - item.z = v[i].asInt(); - } + item.z = v.get(i, 0).asInt(); + } } eigen_map_[short_addr] = item; } @@ -85,12 +85,12 @@ WaveFeatureSetting::WaveFeatureSetting() { global_wave_.short_addr = 0; for (size_t i = 0; i < v.size(); ++i) { if (i == 0) { - global_wave_.x = v[i].asInt(); + global_wave_.x = v.get(i, 0).asInt(); } else if (i == 1) { - global_wave_.y = v[i].asInt(); + global_wave_.y = v.get(i, 0).asInt(); } else if (i == 2) { - global_wave_.z = v[i].asInt(); - } + global_wave_.z = v.get(i, 0).asInt(); + } } } else { short_addr = strtol(key.c_str(), &end_ptr, 16); @@ -98,12 +98,12 @@ WaveFeatureSetting::WaveFeatureSetting() { FeatureEntryPrivateCfg item; for (size_t i = 0; i < v.size(); ++i) { if (i == 0) { - item.x = v[i].asInt(); + item.x = v.get(i, 0).asInt(); } else if (i == 1) { - item.y = v[i].asInt(); + item.y = v.get(i, 0).asInt(); } else if (i == 2) { - item.z = v[i].asInt(); - } + item.z = v.get(i, 0).asInt(); + } } wave_map_[short_addr] = item;