Browse Source

AP_Logger: fix timestamp on log files opened before GPS lock

master
Andrew Tridgell 6 years ago
parent
commit
8e58cb993d
  1. 22
      libraries/AP_Logger/AP_Logger_File.cpp
  2. 1
      libraries/AP_Logger/AP_Logger_File.h

22
libraries/AP_Logger/AP_Logger_File.cpp

@ -883,6 +883,11 @@ uint16_t AP_Logger_File::start_new_log(void) @@ -883,6 +883,11 @@ uint16_t AP_Logger_File::start_new_log(void)
write_fd_semaphore.give();
return 0xFFFF;
}
// remember if we had utc time when we opened the file
uint64_t utc_usec;
_need_rtc_update = !AP::rtc().get_utc_usec(utc_usec);
EXPECT_DELAY_MS(3000);
#if HAL_OS_POSIX_IO
_write_fd = ::open(_write_filename, O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0666);
@ -1058,7 +1063,24 @@ void AP_Logger_File::_io_timer(void) @@ -1058,7 +1063,24 @@ void AP_Logger_File::_io_timer(void)
::fsync(_write_fd);
last_io_operation = "";
#endif
#if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
// ChibiOS does not update mtime on writes, so if we opened
// without knowing the time we should update it later
if (_need_rtc_update) {
uint64_t utc_usec;
if (AP::rtc().get_utc_usec(utc_usec)) {
struct utimbuf t {};
t.modtime = utc_usec / (1000UL * 1000UL);
t.actime = t.modtime;
// we ignore return on utime() as there is nothing useful we can do
(void)utime(_write_filename, &t);
_need_rtc_update = false;
}
}
#endif
}
write_fd_semaphore.give();
hal.util->perf_end(_perf_write);
}

1
libraries/AP_Logger/AP_Logger_File.h

@ -67,6 +67,7 @@ private: @@ -67,6 +67,7 @@ private:
int _write_fd;
char *_write_filename;
uint32_t _last_write_ms;
bool _need_rtc_update;
int _read_fd;
uint16_t _read_fd_log_num;

Loading…
Cancel
Save