mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-06-27 10:10:34 +08:00
apply utc offset and handle underflow
This commit is contained in:
@@ -1296,6 +1296,16 @@ int Logger::get_log_file_name(LogType type, char *file_name, size_t file_name_si
|
||||
px4_clock_gettime(CLOCK_REALTIME, &ts);
|
||||
timestamp_utc = ts.tv_sec + (ts.tv_nsec / 1e9);
|
||||
|
||||
// Apply UTC offset parameter and handle potential underflow
|
||||
int32_t utc_offset_seconds = _param_sdlog_utc_offset.get() * 60;
|
||||
|
||||
if (utc_offset_seconds < 0 && timestamp_utc < (uint32_t)abs(utc_offset_seconds)) {
|
||||
timestamp_utc = 0;
|
||||
|
||||
} else {
|
||||
timestamp_utc += utc_offset_seconds;
|
||||
}
|
||||
|
||||
const char *replay_suffix = "";
|
||||
|
||||
if (_replay_file_name) {
|
||||
@@ -1315,7 +1325,6 @@ int Logger::get_log_file_name(LogType type, char *file_name, size_t file_name_si
|
||||
|
||||
// Check if time is non-zero for valid UTC timestamp
|
||||
if (timestamp_utc > 0) {
|
||||
timestamp_utc += _param_sdlog_utc_offset.get() * 60;
|
||||
|
||||
tm tt = {};
|
||||
gmtime_r(×tamp_utc, &tt);
|
||||
|
||||
Reference in New Issue
Block a user