refine codes.

This commit is contained in:
pandx 2024-10-30 21:17:33 +08:00
parent 4cffd67ea5
commit d1b714be78
3 changed files with 26 additions and 20 deletions

View File

@ -72,7 +72,8 @@
"memory_resource": "cpp", "memory_resource": "cpp",
"random": "cpp", "random": "cpp",
"set": "cpp", "set": "cpp",
"*.ipp": "cpp" "*.ipp": "cpp",
"unordered_set": "cpp"
}, },
"C_Cpp.errorSquiggles": "disabled" "C_Cpp.errorSquiggles": "disabled"
} }

View File

@ -152,7 +152,7 @@ SensorScheduler::SensorScheduler() {
int index = 0; int index = 0;
for (const auto &item : root) { for (const auto &item : root) {
short_addr = item["pan_id"].asInt(); short_addr = item["short_addr"].asInt();
index = item["id"].asInt(); index = item["id"].asInt();
zlog_info(zbt, "index:%d, short addr:%d", index, short_addr); zlog_info(zbt, "index:%d, short addr:%d", index, short_addr);
short_addr_map_[short_addr] = index; short_addr_map_[short_addr] = index;
@ -225,11 +225,11 @@ int SensorScheduler::Init()
return 0; return 0;
} }
int SensorScheduler::GetNextDuration(int pan_id) { int SensorScheduler::GetNextDuration(int short_addr) {
int id = 0; 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()) { 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; return 0;
} else { } else {
id = iter->second; id = iter->second;
@ -241,11 +241,11 @@ int SensorScheduler::GetNextDuration(int pan_id) {
return 0; return 0;
} }
long SensorScheduler::GetBaseTimestamp(int pan_id) { long SensorScheduler::GetBaseTimestamp(int short_addr) {
int id = 0; 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()) { 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; return 0;
} else { } else {
id = iter->second; id = iter->second;
@ -314,7 +314,7 @@ long SensorScheduler::CalcNextTimestamp(int id) {
return available_ts; return available_ts;
} }
int SensorScheduler::GetAvailableId(int pan_id) { int SensorScheduler::GetAvailableId(int short_addr) {
int max_support_sensor[128] = {0}; int max_support_sensor[128] = {0};
for (auto it = short_addr_map_.begin(); it != short_addr_map_.end(); ++it) { for (auto it = short_addr_map_.begin(); it != short_addr_map_.end(); ++it) {
max_support_sensor[it->second] = 1; max_support_sensor[it->second] = 1;
@ -326,32 +326,32 @@ int SensorScheduler::GetAvailableId(int pan_id) {
break; 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 root;
Json::Value item; Json::Value item;
item["id"] = available_id; item["id"] = available_id;
item["pan_id"] = pan_id; item["short_addr"] = short_addr;
root.append(item); root.append(item);
for (auto it = short_addr_map_.begin(); it != short_addr_map_.end(); ++it) { for (auto it = short_addr_map_.begin(); it != short_addr_map_.end(); ++it) {
Json::Value item; Json::Value item;
item["id"] = it->second; item["id"] = it->second;
item["pan_id"] = it->first; item["short_addr"] = it->first;
root.append(item); root.append(item);
} }
Json::StyledStreamWriter streamWriter; Json::StyledStreamWriter streamWriter;
std::ofstream out_file(BASE_RELATION); std::ofstream out_file(BASE_RELATION);
streamWriter.write(out_file, root); streamWriter.write(out_file, root);
out_file.close(); out_file.close();
short_addr_map_[pan_id] = available_id; short_addr_map_[short_addr] = available_id;
return 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; 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()) { if (iter == short_addr_map_.end()) {
id = GetAvailableId(pan_id); id = GetAvailableId(short_addr);
} else { } else {
id = iter->second; id = iter->second;
} }

View File

@ -38,9 +38,14 @@ class SensorScheduler {
public: public:
SensorScheduler(); SensorScheduler();
int Init(); 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 GetBaseTimestamp(int id);
long CalcNextTimestamp(int id); long CalcNextTimestamp(int id);
@ -52,7 +57,7 @@ public:
int eigen_value_send_duration, int wave_form_send_duration, int eigen_value_send_duration, int wave_form_send_duration,
int max_sensor_num, int &available_slice, int &free_slice); 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操作开始====== // ======schedule.json操作开始======
// 无线网关程序重启时 // 无线网关程序重启时
@ -68,7 +73,7 @@ public:
long GetLocalTs(); long GetLocalTs();
long GetLocalWorldTime(std::string &world_time); long GetLocalWorldTime(std::string &world_time);
std::string GetUTCTime(long ts); std::string GetUTCTime(long ts);
int GetAvailableId(int pan_id); int GetAvailableId(int short_addr);
private: private: