Merge branch 'dg101_feature_new_process' of http://192.168.0.10:3000/pandx/WLG into dg101_feature_new_process
This commit is contained in:
commit
050ef1d56b
10
doc/readme.txt
Normal file
10
doc/readme.txt
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
2025-4-29
|
||||||
|
1 场景1: 传感器发送特征值过来时,表明这是特征值发送时间或随机启动的,调用StartSchedule,
|
||||||
|
(1) 如果在特征值时间窗里,如果有配置需要更新的话,返回值为kScheduleConfigSensor,表明要进行配置更新,更新完成后调用GetNextDuration来获取下次启动时间与任务。
|
||||||
|
(2) 如果在特征值时间窗里,如果没有配置需要更新的话,函数的出参StartSchedule(int short_addr, int &next_duration, int &next_task_id)会说明下次启动时间与任务,
|
||||||
|
如果是波形任务,自行查找需要哪些波形,此函数返回值为kScheduleResultNone。
|
||||||
|
|
||||||
|
2 场景2:传感器发送波形过来时,处理完波形,调用int GetNextDuration(int short_addr,int &next_task_id)来获取下次启动时间与任务
|
||||||
|
|
||||||
|
3 场景3:传感器认为此时是升级时间,发送请求,网关调用StartSchedule,如果确实有升级任务,返回kScheduleUpgrade,如果没有升级任务,
|
||||||
|
返回值为kScheduleResultNone, 出参中带有下次启动与任务信息。
|
||||||
@ -17,7 +17,7 @@ extern zlog_category_t *zbt;
|
|||||||
|
|
||||||
uint8_t g_x, g_y, g_z;
|
uint8_t g_x, g_y, g_z;
|
||||||
|
|
||||||
int SensorScheduler::StartSchedule(int short_addr, int &next_duration) {
|
int SensorScheduler::StartSchedule(int short_addr, int &next_duration, int &next_task_id) {
|
||||||
int id = 0;
|
int id = 0;
|
||||||
auto iter = short_addr_map_.find(short_addr);
|
auto iter = short_addr_map_.find(short_addr);
|
||||||
if (iter == short_addr_map_.end()) {
|
if (iter == short_addr_map_.end()) {
|
||||||
@ -59,17 +59,17 @@ int SensorScheduler::StartSchedule(int short_addr, int &next_duration) {
|
|||||||
current_request_ = kScheduleConfigSensor;
|
current_request_ = kScheduleConfigSensor;
|
||||||
return kScheduleConfigSensor;
|
return kScheduleConfigSensor;
|
||||||
} else {
|
} else {
|
||||||
wave_feature_set_inst::instance().GetFeatureCfg(short_addr, g_x, g_y, g_z);
|
// wave_feature_set_inst::instance().GetFeatureCfg(short_addr, g_x, g_y, g_z);
|
||||||
if (g_x || g_y || g_z) {
|
// if (g_x || g_y || g_z) {
|
||||||
// 执行上送特征值任务
|
// // 执行上送特征值任务
|
||||||
zlog_warn(zct, "[%d:%x] send eigen value in eigen slice", id, short_addr);
|
// zlog_warn(zct, "[%d:%x] send eigen value in eigen slice", id, short_addr);
|
||||||
current_request_ = kScheduleEigenValue;
|
// current_request_ = kScheduleEigenValue;
|
||||||
return kScheduleEigenValue;
|
// return kScheduleEigenValue;
|
||||||
} else {
|
// } else {
|
||||||
next_duration = GetNextDuration(short_addr);
|
next_duration = GetNextDuration(short_addr, next_task_id);
|
||||||
zlog_warn(zct, "[%d:%x] no need for eigen", id, short_addr);
|
zlog_warn(zct, "[%d:%x] no need for eigen", id, short_addr);
|
||||||
return kScheduleWrongTime;
|
return kScheduleResultNone;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
// } else {
|
// } else {
|
||||||
// zlog_warn(zct, "[%d:%x] Invalid request, revive in %d eigen slice", id, short_addr, nth_eigen_slice_ + 1);
|
// zlog_warn(zct, "[%d:%x] Invalid request, revive in %d eigen slice", id, short_addr, nth_eigen_slice_ + 1);
|
||||||
@ -107,22 +107,16 @@ int SensorScheduler::StartSchedule(int short_addr, int &next_duration) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (update_.count(id)) {
|
// wave_feature_set_inst::instance().GetWaveCfg(short_addr, g_x, g_y, g_z);
|
||||||
// // execute config
|
// if (g_x || g_y || g_z) {
|
||||||
// zlog_warn(zct, "[%d:%x] in wave slice to update config", id, short_addr);
|
// zlog_warn(zct, "[%d:%x] it is wave time", id, short_addr);
|
||||||
// current_request_ = kScheduleConfigSensor;
|
// current_request_ = kScheduleWaveForm;
|
||||||
// return kScheduleConfigSensor;
|
// return kScheduleWaveForm;
|
||||||
// }
|
// } else {
|
||||||
wave_feature_set_inst::instance().GetWaveCfg(short_addr, g_x, g_y, g_z);
|
next_duration = GetNextDuration(short_addr, next_task_id);
|
||||||
if (g_x || g_y || g_z) {
|
|
||||||
zlog_warn(zct, "[%d:%x] it is wave time", id, short_addr);
|
|
||||||
current_request_ = kScheduleWaveForm;
|
|
||||||
return kScheduleWaveForm;
|
|
||||||
} else {
|
|
||||||
next_duration = GetNextDuration(short_addr);
|
|
||||||
zlog_warn(zct, "[%d:%x] no need for wave", id, short_addr);
|
zlog_warn(zct, "[%d:%x] no need for wave", id, short_addr);
|
||||||
return kScheduleWrongTime;
|
return kScheduleResultNone;
|
||||||
}
|
// }
|
||||||
} else {
|
} else {
|
||||||
if (slice_sensor_id_[nth_wave_slice-1] == 0) {
|
if (slice_sensor_id_[nth_wave_slice-1] == 0) {
|
||||||
zlog_warn(zct, "[%d:%x] in idle time", id, short_addr);
|
zlog_warn(zct, "[%d:%x] in idle time", id, short_addr);
|
||||||
@ -139,33 +133,28 @@ int SensorScheduler::StartSchedule(int short_addr, int &next_duration) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RetransferWave(short_addr)) {
|
// if (RetransferWave(short_addr)) {
|
||||||
zlog_warn(zct, "[%d:%x] it is retransfer wave time", id, short_addr);
|
// zlog_warn(zct, "[%d:%x] it is retransfer wave time", id, short_addr);
|
||||||
current_request_ = kScheduleWaveForm;
|
// current_request_ = kScheduleWaveForm;
|
||||||
return kScheduleWaveForm;
|
// return kScheduleWaveForm;
|
||||||
} else if (MissedWave(short_addr)) {
|
// } else if (MissedWave(short_addr)) {
|
||||||
zlog_warn(zct, "[%d:%x] it is patch wave time", id, short_addr);
|
// zlog_warn(zct, "[%d:%x] it is patch wave time", id, short_addr);
|
||||||
current_request_ = kScheduleWaveForm;
|
// current_request_ = kScheduleWaveForm;
|
||||||
patch_set_.erase(short_addr);
|
// patch_set_.erase(short_addr);
|
||||||
return kScheduleWaveForm;
|
// return kScheduleWaveForm;
|
||||||
}
|
// }
|
||||||
// if (update_.count(id)) {
|
|
||||||
// // execute config
|
|
||||||
// zlog_warn(zct, "[%d:%x] in idle time to update config", id, short_addr);
|
|
||||||
// current_request_ = kScheduleConfigSensor;
|
|
||||||
// return kScheduleConfigSensor;
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
// wrong time to come
|
// wrong time to come
|
||||||
long available_ts = current_wave_start_ts_ + (nth_eigen_value_slice_ + 1) * eigen_value_send_interval_ + (id - 1) * eigen_value_send_duration_;
|
long available_ts = current_wave_start_ts_ + (nth_eigen_value_slice_ + 1) * eigen_value_send_interval_ + (id - 1) * eigen_value_send_duration_;
|
||||||
next_duration = available_ts - current_ts_;
|
next_duration = available_ts - current_ts_;
|
||||||
|
next_task_id = kScheduleEigenValue;
|
||||||
zlog_warn(zct, "[%d:%x] wrong time in wave slice, next feature send utc time:[%s], duration:%d", id, short_addr, GetUTCTime(available_ts).c_str(), next_duration);
|
zlog_warn(zct, "[%d:%x] wrong time in wave slice, next feature send utc time:[%s], duration:%d", id, short_addr, GetUTCTime(available_ts).c_str(), next_duration);
|
||||||
return kScheduleWrongTime;
|
return kScheduleResultNone;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) {
|
long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr, int& next_task_id) {
|
||||||
// current_ts_ = GetLocalTs();
|
// current_ts_ = GetLocalTs();
|
||||||
// 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_;
|
||||||
@ -185,6 +174,7 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) {
|
|||||||
zlog_error(zct, "[Nxt] invaild id:%d, not find wave slice id", id);
|
zlog_error(zct, "[Nxt] invaild id:%d, not find wave slice id", id);
|
||||||
long available_ts = current_wave_start_ts_ + eigen_value_send_interval_ + nth_eigen_slice_ * eigen_value_send_duration_;
|
long available_ts = current_wave_start_ts_ + eigen_value_send_interval_ + nth_eigen_slice_ * eigen_value_send_duration_;
|
||||||
zlog_error(zct, "[Nxt] [%d] next feature send utc time:[%s]", id, GetUTCTime(available_ts).c_str());
|
zlog_error(zct, "[Nxt] [%d] next feature send utc time:[%s]", id, GetUTCTime(available_ts).c_str());
|
||||||
|
next_task_id = kScheduleEigenValue;
|
||||||
return available_ts;
|
return available_ts;
|
||||||
}
|
}
|
||||||
int wave_slice = wave_slice_iter->second; // 从1开始
|
int wave_slice = wave_slice_iter->second; // 从1开始
|
||||||
@ -230,7 +220,9 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) {
|
|||||||
available_ts = current_wave_slice_ts;
|
available_ts = current_wave_slice_ts;
|
||||||
free_slice_ocuppied_.insert(available_ts);
|
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;
|
||||||
|
next_task_id = kScheduleUpgrade;
|
||||||
|
return available_ts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -246,7 +238,9 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) {
|
|||||||
available_ts = current_wave_slice_ts;
|
available_ts = current_wave_slice_ts;
|
||||||
free_slice_ocuppied_.insert(available_ts);
|
free_slice_ocuppied_.insert(available_ts);
|
||||||
zlog_warn(zct, "[Nxt][%d:%x] %d nth free wave slice will be used to retransfer wave, 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 retransfer wave, utc time:[%s]", id, short_addr, i+forward_wave_slice_num, GetUTCTime(available_ts).c_str());
|
||||||
break;
|
// break;
|
||||||
|
next_task_id = kScheduleWaveForm;
|
||||||
|
return available_ts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -259,32 +253,37 @@ long SensorScheduler::CalcNextTimestamp(int id, uint16_t short_addr) {
|
|||||||
available_ts = current_wave_slice_ts;
|
available_ts = current_wave_slice_ts;
|
||||||
free_slice_ocuppied_.insert(available_ts);
|
free_slice_ocuppied_.insert(available_ts);
|
||||||
zlog_warn(zct, "[Nxt][%d:%x] %d nth free wave slice will be used to patch wave, 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 patch wave, utc time:[%s]", id, short_addr, i+forward_wave_slice_num, GetUTCTime(available_ts).c_str());
|
||||||
break;
|
// break;
|
||||||
|
next_task_id = kScheduleWaveForm;
|
||||||
|
return available_ts;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (send_wave_ts > 0 && available_ts > 0) {
|
if (send_wave_ts > 0) {
|
||||||
long min_ts = std::min(send_wave_ts, available_ts);
|
// long min_ts = std::min(send_wave_ts, available_ts);
|
||||||
zlog_warn(zct, "[Nxt] [%d:%x] next feature send utc time1:%s", id, short_addr, GetUTCTime(min_ts).c_str());
|
zlog_warn(zct, "[Nxt] [%d:%x] next wave send utc time1:%s", id, short_addr, GetUTCTime(send_wave_ts).c_str());
|
||||||
return min_ts;
|
next_task_id = kScheduleWaveForm;
|
||||||
|
return send_wave_ts;
|
||||||
|
// return min_ts;
|
||||||
}
|
}
|
||||||
if (send_wave_ts + available_ts > 0) {
|
// if (send_wave_ts + available_ts > 0) {
|
||||||
long max_ts = std::max(send_wave_ts, available_ts);
|
// long max_ts = std::max(send_wave_ts, available_ts);
|
||||||
zlog_warn(zct, "[Nxt] [%d:%x] next feature send utc time2:%s", id, short_addr, GetUTCTime(max_ts).c_str());
|
// zlog_warn(zct, "[Nxt] [%d:%x] next feature send utc time2:%s", id, short_addr, GetUTCTime(max_ts).c_str());
|
||||||
return max_ts;
|
// return max_ts;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果是在当前波形时间窗中,不管是空闲时间窗,还是发送波形的时间窗,下一个时间窗是特征值
|
// 如果是在当前波形时间窗中,不管是空闲时间窗,还是发送波形的时间窗,下一个时间窗是特征值
|
||||||
long available_ts = current_wave_start_ts_ + (nth_eigen_value_slice_ + 1)* eigen_value_send_interval_ + (id - 1) * eigen_value_send_duration_;
|
long available_ts = current_wave_start_ts_ + (nth_eigen_value_slice_ + 1)* eigen_value_send_interval_ + (id - 1) * eigen_value_send_duration_;
|
||||||
zlog_warn(zct, "[Nxt] [%d:%x] next feature send utc time3:[%s]", id, short_addr, GetUTCTime(available_ts).c_str());
|
zlog_warn(zct, "[Nxt] [%d:%x] next feature send utc time3:[%s]", id, short_addr, GetUTCTime(available_ts).c_str());
|
||||||
|
next_task_id = kScheduleEigenValue;
|
||||||
return available_ts;
|
return available_ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SensorScheduler::GetNextDuration(int short_addr,int next_taskID) {
|
int SensorScheduler::GetNextDuration(int short_addr, int &next_task_id) {
|
||||||
int id = 0;
|
int id = 0;
|
||||||
auto iter = short_addr_map_.find(short_addr);
|
auto iter = short_addr_map_.find(short_addr);
|
||||||
if (iter == short_addr_map_.end()) {
|
if (iter == short_addr_map_.end()) {
|
||||||
@ -294,16 +293,36 @@ int SensorScheduler::GetNextDuration(int short_addr,int next_taskID) {
|
|||||||
id = iter->second;
|
id = iter->second;
|
||||||
}
|
}
|
||||||
long current_ts = GetLocalTs();
|
long current_ts = GetLocalTs();
|
||||||
long next_ts = CalcNextTimestamp(id, short_addr);
|
long next_ts = CalcNextTimestamp(id, short_addr, next_task_id);
|
||||||
int duration = next_ts - current_ts;
|
int duration = next_ts - current_ts;
|
||||||
if (duration < 0 || duration > eigen_value_send_interval_) {
|
if (duration < 0 || duration > eigen_value_send_interval_) {
|
||||||
zlog_warn(zct, "[Nxt] exception duration: %d", duration);
|
zlog_warn(zct, "[Nxt] exception duration: %d", duration);
|
||||||
duration = eigen_value_send_interval_;
|
duration = eigen_value_send_interval_;
|
||||||
}
|
}
|
||||||
zlog_warn(zct, "[Nxt] [%d:%x] next duration is %d", id, short_addr, duration);
|
zlog_warn(zct, "[Nxt] [%d:%x] next duration: %d, taskid: %d", id, short_addr, duration, next_task_id);
|
||||||
return duration;
|
return duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// int SensorScheduler::GetNextDuration(int short_addr) {
|
||||||
|
// int id = 0;
|
||||||
|
// auto iter = short_addr_map_.find(short_addr);
|
||||||
|
// if (iter == short_addr_map_.end()) {
|
||||||
|
// zlog_error(zct, "cannot find id for short_addr %x", short_addr);
|
||||||
|
// return 0;
|
||||||
|
// } else {
|
||||||
|
// id = iter->second;
|
||||||
|
// }
|
||||||
|
// long current_ts = GetLocalTs();
|
||||||
|
// long next_ts = CalcNextTimestamp(id, short_addr);
|
||||||
|
// int duration = next_ts - current_ts;
|
||||||
|
// if (duration < 0 || duration > eigen_value_send_interval_) {
|
||||||
|
// zlog_warn(zct, "[Nxt] exception duration: %d", duration);
|
||||||
|
// duration = eigen_value_send_interval_;
|
||||||
|
// }
|
||||||
|
// zlog_warn(zct, "[Nxt] [%d:%x] next duration is %d", id, short_addr, duration);
|
||||||
|
// return duration;
|
||||||
|
// }
|
||||||
|
|
||||||
SensorScheduler::SensorScheduler() {
|
SensorScheduler::SensorScheduler() {
|
||||||
support_modification_ = true;
|
support_modification_ = true;
|
||||||
std::ifstream schedule_file(SCHEDULE_CONFIG);
|
std::ifstream schedule_file(SCHEDULE_CONFIG);
|
||||||
|
|||||||
@ -38,13 +38,14 @@ public:
|
|||||||
// kScheduleEigenValue kScheduleWaveForm
|
// kScheduleEigenValue kScheduleWaveForm
|
||||||
// 上面4个结束,调GetNextDuration()获取休眠时间
|
// 上面4个结束,调GetNextDuration()获取休眠时间
|
||||||
// 如果是kScheduleWrongTime, 此函数next_duration表明休眠时间
|
// 如果是kScheduleWrongTime, 此函数next_duration表明休眠时间
|
||||||
int StartSchedule(int short_addr, int &next_duration);
|
int StartSchedule(int short_addr, int &next_duration, int &next_task_id);
|
||||||
int GetNextDuration(int short_addr,int next_taskID = 3);
|
int GetNextDuration(int short_addr,int &next_task_id);
|
||||||
|
// int GetNextDuration(int short_addr);
|
||||||
|
|
||||||
int WaveError(uint16_t short_addr);
|
int WaveError(uint16_t short_addr);
|
||||||
void WaveSuccess(uint16_t short_addr);
|
void WaveSuccess(uint16_t short_addr);
|
||||||
long GetBaseTimestamp(int id);
|
long GetBaseTimestamp(int id);
|
||||||
long CalcNextTimestamp(int id, uint16_t short_addr);
|
long CalcNextTimestamp(int id, uint16_t short_addr, int& next_task_id);
|
||||||
|
|
||||||
// 当有传感器需要更新配置时调用
|
// 当有传感器需要更新配置时调用
|
||||||
int UpdateSensorConfig(int short_addr);
|
int UpdateSensorConfig(int short_addr);
|
||||||
|
|||||||
@ -334,7 +334,8 @@ int Uart::DealAskTask(uint16_t ushortAdd){
|
|||||||
}
|
}
|
||||||
ModifyDistAddr(ushortAdd);
|
ModifyDistAddr(ushortAdd);
|
||||||
int next_duration = 0;
|
int next_duration = 0;
|
||||||
int taskID = scheduler::instance().StartSchedule(ushortAdd,next_duration);
|
int taskID;
|
||||||
|
scheduler::instance().StartSchedule(ushortAdd,next_duration, taskID);
|
||||||
ScheduleTask scheduleTask;
|
ScheduleTask scheduleTask;
|
||||||
zlog_info(zct, "taskID = %d ", taskID);
|
zlog_info(zct, "taskID = %d ", taskID);
|
||||||
if (taskID == kScheduleEigenValue) //1.特征值
|
if (taskID == kScheduleEigenValue) //1.特征值
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user