merge dg102 refine codes here.
This commit is contained in:
parent
55d1550a4a
commit
c244ec783f
@ -885,7 +885,7 @@ int SqliteDB::CalculateBattery() {
|
|||||||
to_math += cost_h;
|
to_math += cost_h;
|
||||||
}
|
}
|
||||||
|
|
||||||
zlog_info(zct, "自放电 = %f", to_math);
|
zlog_info(zct, "self discharge = %f", to_math);
|
||||||
long sumworkTime = 0.0, sumsendTime = 0.0;
|
long sumworkTime = 0.0, sumsendTime = 0.0;
|
||||||
for (size_t j = 0; j < vecworkTime.size(); j++) {
|
for (size_t j = 0; j < vecworkTime.size(); j++) {
|
||||||
sumworkTime += vecworkTime[j];
|
sumworkTime += vecworkTime[j];
|
||||||
@ -901,7 +901,7 @@ int SqliteDB::CalculateBattery() {
|
|||||||
|
|
||||||
if (to_math < 0) to_math = 0;
|
if (to_math < 0) to_math = 0;
|
||||||
float usageBattery = usageworkTime + usagesendTime + to_math;
|
float usageBattery = usageworkTime + usagesendTime + to_math;
|
||||||
zlog_info(zct, "已经使用 = %f", atof(vecResSig[6].c_str()));
|
zlog_info(zct, "have used = %f", atof(vecResSig[6].c_str()));
|
||||||
|
|
||||||
float remainBattery = capacity - usageBattery * 0.2;
|
float remainBattery = capacity - usageBattery * 0.2;
|
||||||
if (remainBattery < 10) {
|
if (remainBattery < 10) {
|
||||||
@ -1180,7 +1180,7 @@ std::string SqliteDB::GetNodeConfigureInfor(const char *whereCon) {
|
|||||||
} else {
|
} else {
|
||||||
jsArray.resize(0);
|
jsArray.resize(0);
|
||||||
jsonVal["success"] = false;
|
jsonVal["success"] = false;
|
||||||
jsonVal["message"] = "查询失败";
|
jsonVal["message"] = "fail to query";
|
||||||
}
|
}
|
||||||
|
|
||||||
Json::Value jsBody;
|
Json::Value jsBody;
|
||||||
@ -1347,8 +1347,6 @@ int SqliteDB::QueryofflineData() {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int SqliteDB::TransBegin() { return sqlite3_exec(mDBAcess, "begin;", 0, 0, 0); }
|
int SqliteDB::TransBegin() { return sqlite3_exec(mDBAcess, "begin;", 0, 0, 0); }
|
||||||
|
|
||||||
int SqliteDB::TransRollback() { return sqlite3_exec(mDBAcess, "rollback;", 0, 0, 0); }
|
int SqliteDB::TransRollback() { return sqlite3_exec(mDBAcess, "rollback;", 0, 0, 0); }
|
||||||
|
|||||||
@ -24,7 +24,7 @@ int SensorScheduler::StartSchedule(int short_addr, int &next_duration) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
current_ts_ = GetLocalTs();
|
current_ts_ = GetLocalTs();
|
||||||
CleanIdleOccupiedSet();
|
CleanIdleOccupiedSet(current_ts_);
|
||||||
|
|
||||||
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 (!IdleSliceOccupied(i+forward_wave_slice_num)) {
|
if (free_slice_ocuppied_.count(current_wave_slice_ts) == 0) {
|
||||||
available_ts = current_wave_slice_ts;
|
available_ts = current_wave_slice_ts;
|
||||||
free_slice_ocuppied_.push_back(i+forward_wave_slice_num);
|
free_slice_ocuppied_.insert(available_ts);
|
||||||
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;
|
||||||
}
|
}
|
||||||
@ -230,6 +230,20 @@ SensorScheduler::SensorScheduler() {
|
|||||||
}
|
}
|
||||||
start_timestamp_ = std::stol(root["schedule_start_timestamp"].asString());
|
start_timestamp_ = std::stol(root["schedule_start_timestamp"].asString());
|
||||||
start_ts_str_ = root["schedule_start_time"].asString();
|
start_ts_str_ = root["schedule_start_time"].asString();
|
||||||
|
long current_ts = GetLocalTs();
|
||||||
|
if (current_ts < start_timestamp_) {
|
||||||
|
zlog_warn(zbt, "current ts: %ld less than start ts: %ld, go to adjust it", current_ts, start_timestamp_);
|
||||||
|
start_timestamp_ = current_ts;
|
||||||
|
start_ts_str_ = GetUTCTime(current_ts);
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
eigen_value_send_interval_ = root["eigen_value_send_interval"].asInt();
|
eigen_value_send_interval_ = root["eigen_value_send_interval"].asInt();
|
||||||
eigen_value_send_duration_ = root["eigen_value_send_duration"].asInt();
|
eigen_value_send_duration_ = root["eigen_value_send_duration"].asInt();
|
||||||
wave_form_send_interval_ = root["wave_form_send_interval"].asInt();
|
wave_form_send_interval_ = root["wave_form_send_interval"].asInt();
|
||||||
@ -641,19 +655,12 @@ void SensorScheduler::ClearScheduleCfg(int short_addr) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SensorScheduler::CleanIdleOccupiedSet() {
|
void SensorScheduler::CleanIdleOccupiedSet(long ts) {
|
||||||
int min_num = 0;
|
if (free_slice_ocuppied_.size() > 5) {
|
||||||
size_t free_slice = (size_t)free_slice_;
|
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,7 +4,6 @@
|
|||||||
#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>
|
||||||
@ -102,8 +101,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void UpdateUpgradeInfo(int id);
|
void UpdateUpgradeInfo(int id);
|
||||||
void CleanIdleOccupiedSet();
|
void CleanIdleOccupiedSet(long ts);
|
||||||
bool IdleSliceOccupied(int slice_id); // 索引号
|
|
||||||
|
|
||||||
// user config
|
// user config
|
||||||
int eigen_value_send_interval_;
|
int eigen_value_send_interval_;
|
||||||
@ -127,7 +125,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::list<int> free_slice_ocuppied_;
|
std::unordered_set<long> free_slice_ocuppied_;
|
||||||
|
|
||||||
// sensor config update
|
// sensor config update
|
||||||
std::unordered_set<int> update_;
|
std::unordered_set<int> update_;
|
||||||
|
|||||||
@ -36,10 +36,6 @@ int UpdateCfg::ReadCfg(std::unordered_set<int>& update) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int UpdateCfg::WriteCfg(std::unordered_set<int> &update) {
|
int UpdateCfg::WriteCfg(std::unordered_set<int> &update) {
|
||||||
if (update.size() == 0) {
|
|
||||||
ClearCfg();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
for (auto item : update) {
|
for (auto item : update) {
|
||||||
root.append(item);
|
root.append(item);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user