merge dg102 refine codes here.
This commit is contained in:
parent
55d1550a4a
commit
c244ec783f
@ -846,7 +846,7 @@ int SqliteDB::CalculateBattery() {
|
|||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
sprintf(whereCon, " dataNodeNo = '%s' order by timeStamp asc limit 0,1 ", vecRes[i][7].c_str());
|
sprintf(whereCon, " dataNodeNo = '%s' order by timeStamp asc limit 0,1 ", vecRes[i][7].c_str());
|
||||||
vecResSig = sqlite_db_ctrl::instance().GetDataSingleLine(T_BATTERY_INFO(TNAME), " * ", whereCon);
|
vecResSig = sqlite_db_ctrl::instance().GetDataSingleLine(T_BATTERY_INFO(TNAME), " * ", whereCon);
|
||||||
if (vecResSig.size() <= 0) { //一条数据都没有
|
if (vecResSig.size() <= 0) { // 一条数据都没有
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -877,15 +877,15 @@ int SqliteDB::CalculateBattery() {
|
|||||||
|
|
||||||
for (size_t j = 0; j < vecResbattery.size(); j++) {
|
for (size_t j = 0; j < vecResbattery.size(); j++) {
|
||||||
float b = 2 - 25 * k;
|
float b = 2 - 25 * k;
|
||||||
float dpm = k * atoi(vecResbattery[j][2].c_str()) + b; //温度
|
float dpm = k * atoi(vecResbattery[j][2].c_str()) + b; // 温度
|
||||||
float cost_e = dpm * atoi(vecRes[i][3].c_str()); //特征值时间间隔
|
float cost_e = dpm * atoi(vecRes[i][3].c_str()); // 特征值时间间隔
|
||||||
float cost_h = cost_e / 60;
|
float cost_h = cost_e / 60;
|
||||||
vecworkTime.push_back(atol(vecResbattery[j][3].c_str()));
|
vecworkTime.push_back(atol(vecResbattery[j][3].c_str()));
|
||||||
vecsendTime.push_back(atol(vecResbattery[j][4].c_str()));
|
vecsendTime.push_back(atol(vecResbattery[j][4].c_str()));
|
||||||
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) {
|
||||||
@ -990,9 +990,9 @@ int SqliteDB::CalculateDip() {
|
|||||||
memset(whereCon, 0x00, sizeof(whereCon));
|
memset(whereCon, 0x00, sizeof(whereCon));
|
||||||
if (vParam[1] == "2") { //人工干预
|
if (vParam[1] == "2") { //人工干预
|
||||||
sprintf(whereCon, " timeStamp > '%ld' ", atol(vParam[2].c_str()));
|
sprintf(whereCon, " timeStamp > '%ld' ", atol(vParam[2].c_str()));
|
||||||
} else if (vParam[1] == "0") { //正常状态
|
} else if (vParam[1] == "0") { // 正常状态
|
||||||
sprintf(whereCon, " timeStamp > '%ld' ", atol(localtimestamp) - 86400); //一天数据
|
sprintf(whereCon, " timeStamp > '%ld' ", atol(localtimestamp) - 86400); // 一天数据
|
||||||
} else if (vParam[1] == "1") { //松动状态
|
} else if (vParam[1] == "1") { // 松动状态
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
zlog_info(zct, "vParam[0]=%s,vParam[1]=%s", vParam[0].c_str(), vParam[1].c_str());
|
zlog_info(zct, "vParam[0]=%s,vParam[1]=%s", vParam[0].c_str(), vParam[1].c_str());
|
||||||
@ -1038,7 +1038,7 @@ int SqliteDB::CalculateDip() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int SqliteDB::InintGateway() {
|
int SqliteDB::InintGateway() {
|
||||||
//更新网关配置表
|
// 更新网关配置表
|
||||||
std::string strIP = GetGwIp_("eth0");
|
std::string strIP = GetGwIp_("eth0");
|
||||||
std::string strServerIP = ReadStrByOpt(SERVERCONFIG, "Server", "localServerIpAddress");
|
std::string strServerIP = ReadStrByOpt(SERVERCONFIG, "Server", "localServerIpAddress");
|
||||||
std::string strServerPort = ReadStrByOpt(SERVERCONFIG, "Server", "localServerPort");
|
std::string strServerPort = ReadStrByOpt(SERVERCONFIG, "Server", "localServerPort");
|
||||||
@ -1074,7 +1074,7 @@ int SqliteDB::InintGateway() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//上传网关配置到MQTT
|
// 上传网关配置到MQTT
|
||||||
Json::Value jsSystemSetting;
|
Json::Value jsSystemSetting;
|
||||||
Json::Value jsBody;
|
Json::Value jsBody;
|
||||||
Json::FastWriter showValue;
|
Json::FastWriter showValue;
|
||||||
@ -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;
|
||||||
@ -1231,7 +1231,7 @@ int SqliteDB::QueryofflineData() {
|
|||||||
valNodeData.append(valNodeFeature);
|
valNodeData.append(valNodeFeature);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//无线传感器信息
|
// 无线传感器信息
|
||||||
Json::Value root;
|
Json::Value root;
|
||||||
Json::Value valdatastatic;
|
Json::Value valdatastatic;
|
||||||
Json::Value valNodeData;
|
Json::Value valNodeData;
|
||||||
@ -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