add protection for upgrade file.
This commit is contained in:
parent
b406513804
commit
95e00f919b
@ -1351,6 +1351,12 @@ int SqliteDB::CalculateData() {
|
|||||||
int planCount = 0, planCountStatistic = 0, StatisticCountTotal = 0, SixCountTotal = 0, TimingCountTotal = 0, CountWaveXTotal = 0, waveInterVal = 0, featureInterVal = 0;
|
int planCount = 0, planCountStatistic = 0, StatisticCountTotal = 0, SixCountTotal = 0, TimingCountTotal = 0, CountWaveXTotal = 0, waveInterVal = 0, featureInterVal = 0;
|
||||||
int CountWaveYTotal = 0, CountWaveZTotal = 0;
|
int CountWaveYTotal = 0, CountWaveZTotal = 0;
|
||||||
for (size_t i = 0; i < vecRet.size(); i++) {
|
for (size_t i = 0; i < vecRet.size(); i++) {
|
||||||
|
featureInterVal = atoi(vecRet[i][3].c_str());
|
||||||
|
waveInterVal = atoi(vecRet[i][4].c_str());
|
||||||
|
if (featureInterVal == 0 || waveInterVal == 0) {
|
||||||
|
zlog_error(zct, "featureInterVal:%d or waveInterVal:%d is 0", featureInterVal, waveInterVal);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
planCount = 1440 / atoi(vecRet[i][4].c_str());
|
planCount = 1440 / atoi(vecRet[i][4].c_str());
|
||||||
planCountStatistic = 1440 / atoi(vecRet[i][3].c_str());
|
planCountStatistic = 1440 / atoi(vecRet[i][3].c_str());
|
||||||
int rate = readIntValue("config", "waveRate", (char *)GlobalConfig::Config_G.c_str());
|
int rate = readIntValue("config", "waveRate", (char *)GlobalConfig::Config_G.c_str());
|
||||||
@ -1473,8 +1479,6 @@ int SqliteDB::CalculateData() {
|
|||||||
zlog_info(zct, "3 update ZigbeePower ");
|
zlog_info(zct, "3 update ZigbeePower ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
featureInterVal = atoi(vecRet[i][3].c_str());
|
|
||||||
waveInterVal = atoi(vecRet[i][4].c_str());
|
|
||||||
}
|
}
|
||||||
zlog_info(zct, "Node Count = %d , featureInterVal = %d , waveInterVal = %d", vecRet.size(), featureInterVal, waveInterVal);
|
zlog_info(zct, "Node Count = %d , featureInterVal = %d , waveInterVal = %d", vecRet.size(), featureInterVal, waveInterVal);
|
||||||
zlog_info(zct, "plan Statistic Count = %d , 06 Count = %d , Timing Count = %d , CountWaveX = %d ", planCountStatistic * vecRet.size(), planCount * vecRet.size(), planCount * vecRet.size(), planCount * vecRet.size());
|
zlog_info(zct, "plan Statistic Count = %d , 06 Count = %d , Timing Count = %d , CountWaveX = %d ", planCountStatistic * vecRet.size(), planCount * vecRet.size(), planCount * vecRet.size(), planCount * vecRet.size());
|
||||||
|
|||||||
@ -24,7 +24,7 @@ int SensorScheduler::StartSchedule(int short_addr, int &next_duration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
current_ts_ = GetLocalTs();
|
current_ts_ = GetLocalTs();
|
||||||
CleanIdleOccupiedSet(current_ts_);
|
CleanIdleOccupiedSet();
|
||||||
|
|
||||||
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_;
|
||||||
@ -167,9 +167,9 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) {
|
|||||||
if (slice_sensor_id_[i+forward_wave_slice_num] == 0) {
|
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_;
|
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) {
|
if (!IdleSliceOccupied(i+forward_wave_slice_num)) {
|
||||||
available_ts = current_wave_slice_ts;
|
available_ts = current_wave_slice_ts;
|
||||||
free_slice_ocuppied_.insert(available_ts);
|
free_slice_ocuppied_.push_back(i+forward_wave_slice_num);
|
||||||
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;
|
||||||
}
|
}
|
||||||
@ -641,12 +641,18 @@ void SensorScheduler::ClearScheduleCfg(int short_addr) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SensorScheduler::CleanIdleOccupiedSet(long ts) {
|
void SensorScheduler::CleanIdleOccupiedSet() {
|
||||||
if (free_slice_ocuppied_.size() > 5) {
|
int min_num = 0;
|
||||||
for (auto it = free_slice_ocuppied_.begin(); it != free_slice_ocuppied_.end();) {
|
while (free_slice_ocuppied_.size() > free_slice_ && free_slice_ > min_num) {
|
||||||
if ((*it) < ts) {
|
free_slice_ocuppied_.pop_front();
|
||||||
it = free_slice_ocuppied_.erase(it);
|
|
||||||
} else ++it;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool SensorScheduler::IdleSliceOccupied(int slice_id) {
|
||||||
|
for (auto item : free_slice_ocuppied_) {
|
||||||
|
if (slice_id == item) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
@ -4,6 +4,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <boost/container/detail/singleton.hpp>
|
#include <boost/container/detail/singleton.hpp>
|
||||||
@ -101,7 +102,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void UpdateUpgradeInfo(int id);
|
void UpdateUpgradeInfo(int id);
|
||||||
void CleanIdleOccupiedSet(long ts);
|
void CleanIdleOccupiedSet();
|
||||||
|
bool IdleSliceOccupied(int slice_id); // 索引号
|
||||||
|
|
||||||
// user config
|
// user config
|
||||||
int eigen_value_send_interval_;
|
int eigen_value_send_interval_;
|
||||||
@ -125,7 +127,7 @@ private:
|
|||||||
std::map<uint16_t, int> short_addr_map_; // base_relation.json
|
std::map<uint16_t, int> short_addr_map_; // base_relation.json
|
||||||
|
|
||||||
// 空闲时间戳被占用
|
// 空闲时间戳被占用
|
||||||
std::unordered_set<long> free_slice_ocuppied_;
|
std::list<int> free_slice_ocuppied_;
|
||||||
|
|
||||||
// sensor config update
|
// sensor config update
|
||||||
std::unordered_set<int> update_;
|
std::unordered_set<int> update_;
|
||||||
|
|||||||
@ -13,6 +13,14 @@ int UpgradeCfg::ReadCfg(std::map<int, UpgradeInfo> &upgrade) {
|
|||||||
return 0;
|
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::Reader reader;
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
if (!reader.parse(upgrade_file, root, false)) {
|
if (!reader.parse(upgrade_file, root, false)) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user