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:
zhangsheng 2025-04-29 11:26:34 +08:00
commit 050ef1d56b
4 changed files with 94 additions and 63 deletions

10
doc/readme.txt Normal file
View 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, 出参中带有下次启动与任务信息。

View File

@ -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;
if (send_wave_ts + available_ts > 0) { // return min_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());
return max_ts;
} }
// if (send_wave_ts + available_ts > 0) {
// 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());
// 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);

View File

@ -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);

View File

@ -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.特征值