refine codes.
This commit is contained in:
parent
4cffd67ea5
commit
d1b714be78
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -72,7 +72,8 @@
|
||||
"memory_resource": "cpp",
|
||||
"random": "cpp",
|
||||
"set": "cpp",
|
||||
"*.ipp": "cpp"
|
||||
"*.ipp": "cpp",
|
||||
"unordered_set": "cpp"
|
||||
},
|
||||
"C_Cpp.errorSquiggles": "disabled"
|
||||
}
|
||||
@ -152,7 +152,7 @@ SensorScheduler::SensorScheduler() {
|
||||
int index = 0;
|
||||
|
||||
for (const auto &item : root) {
|
||||
short_addr = item["pan_id"].asInt();
|
||||
short_addr = item["short_addr"].asInt();
|
||||
index = item["id"].asInt();
|
||||
zlog_info(zbt, "index:%d, short addr:%d", index, short_addr);
|
||||
short_addr_map_[short_addr] = index;
|
||||
@ -225,11 +225,11 @@ int SensorScheduler::Init()
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SensorScheduler::GetNextDuration(int pan_id) {
|
||||
int SensorScheduler::GetNextDuration(int short_addr) {
|
||||
int id = 0;
|
||||
auto iter = short_addr_map_.find(pan_id);
|
||||
auto iter = short_addr_map_.find(short_addr);
|
||||
if (iter == short_addr_map_.end()) {
|
||||
zlog_error(zct, "cannot find id for pan_id %d", pan_id);
|
||||
zlog_error(zct, "cannot find id for short_addr %d", short_addr);
|
||||
return 0;
|
||||
} else {
|
||||
id = iter->second;
|
||||
@ -241,11 +241,11 @@ int SensorScheduler::GetNextDuration(int pan_id) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
long SensorScheduler::GetBaseTimestamp(int pan_id) {
|
||||
long SensorScheduler::GetBaseTimestamp(int short_addr) {
|
||||
int id = 0;
|
||||
auto iter = short_addr_map_.find(pan_id);
|
||||
auto iter = short_addr_map_.find(short_addr);
|
||||
if (iter == short_addr_map_.end()) {
|
||||
zlog_error(zct, "cannot find id for pan_id %d", pan_id);
|
||||
zlog_error(zct, "cannot find id for short_addr %d", short_addr);
|
||||
return 0;
|
||||
} else {
|
||||
id = iter->second;
|
||||
@ -314,7 +314,7 @@ long SensorScheduler::CalcNextTimestamp(int id) {
|
||||
return available_ts;
|
||||
}
|
||||
|
||||
int SensorScheduler::GetAvailableId(int pan_id) {
|
||||
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;
|
||||
@ -326,32 +326,32 @@ int SensorScheduler::GetAvailableId(int pan_id) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
zlog_warn(zct, "[GetAvailableId][%d] pan id : %d", available_id, pan_id);
|
||||
zlog_warn(zct, "[GetAvailableId][%d] pan id : %d", available_id, short_addr);
|
||||
Json::Value root;
|
||||
Json::Value item;
|
||||
item["id"] = available_id;
|
||||
item["pan_id"] = pan_id;
|
||||
item["short_addr"] = short_addr;
|
||||
root.append(item);
|
||||
|
||||
for (auto it = short_addr_map_.begin(); it != short_addr_map_.end(); ++it) {
|
||||
Json::Value item;
|
||||
item["id"] = it->second;
|
||||
item["pan_id"] = it->first;
|
||||
item["short_addr"] = it->first;
|
||||
root.append(item);
|
||||
}
|
||||
Json::StyledStreamWriter streamWriter;
|
||||
std::ofstream out_file(BASE_RELATION);
|
||||
streamWriter.write(out_file, root);
|
||||
out_file.close();
|
||||
short_addr_map_[pan_id] = available_id;
|
||||
short_addr_map_[short_addr] = available_id;
|
||||
return available_id;
|
||||
}
|
||||
|
||||
int SensorScheduler::StartSchedule(int pan_id, int &next_duration) {
|
||||
int SensorScheduler::StartSchedule(int short_addr, int &next_duration) {
|
||||
int id = 0;
|
||||
auto iter = short_addr_map_.find(pan_id);
|
||||
auto iter = short_addr_map_.find(short_addr);
|
||||
if (iter == short_addr_map_.end()) {
|
||||
id = GetAvailableId(pan_id);
|
||||
id = GetAvailableId(short_addr);
|
||||
} else {
|
||||
id = iter->second;
|
||||
}
|
||||
|
||||
@ -38,9 +38,14 @@ class SensorScheduler {
|
||||
public:
|
||||
SensorScheduler();
|
||||
int Init();
|
||||
int StartSchedule(int pan_id, int &next_duration);
|
||||
|
||||
int GetNextDuration(int pan_id);
|
||||
// kScheduleConfigSensor kScheduleUpgrade 等有结果,调我接口通知结果
|
||||
// kScheduleEigenValue kScheduleWaveForm
|
||||
// 上面4个结束,调GetNextDuration()获取休眠时间
|
||||
// 如果是kScheduleWrongTime, 此函数next_duration表明休眠时间
|
||||
int StartSchedule(int short_addr, int &next_duration);
|
||||
int GetNextDuration(int short_addr);
|
||||
|
||||
long GetBaseTimestamp(int id);
|
||||
long CalcNextTimestamp(int id);
|
||||
|
||||
@ -52,7 +57,7 @@ public:
|
||||
int eigen_value_send_duration, int wave_form_send_duration,
|
||||
int max_sensor_num, int &available_slice, int &free_slice);
|
||||
|
||||
void GetSensorTs(int pan_id, long &eigen_ts, long &wave_ts);
|
||||
void GetSensorTs(int short_addr, long &eigen_ts, long &wave_ts);
|
||||
|
||||
// ======schedule.json操作开始======
|
||||
// 无线网关程序重启时
|
||||
@ -68,7 +73,7 @@ public:
|
||||
long GetLocalTs();
|
||||
long GetLocalWorldTime(std::string &world_time);
|
||||
std::string GetUTCTime(long ts);
|
||||
int GetAvailableId(int pan_id);
|
||||
int GetAvailableId(int short_addr);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user