From 7cc03ad7e818f292cfec49a198cb547e52a30381 Mon Sep 17 00:00:00 2001 From: pandx Date: Wed, 27 Nov 2024 11:20:08 +0800 Subject: [PATCH] fix ts is negative issue. --- scheduler/schedule.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/scheduler/schedule.cpp b/scheduler/schedule.cpp index aa115b4..7731204 100644 --- a/scheduler/schedule.cpp +++ b/scheduler/schedule.cpp @@ -228,8 +228,22 @@ SensorScheduler::SensorScheduler() { zlog_error(zbt, "invalid format, not an object: %s", SCHEDULE_CONFIG); return; } - 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(); + 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_duration_ = root["eigen_value_send_duration"].asInt(); wave_form_send_interval_ = root["wave_form_send_interval"].asInt();