Browse Source

AP_HAL_Linux: tidy set/get of hw RTC

gps-1.3.1
Peter Barker 3 years ago committed by Peter Barker
parent
commit
d8e4669e07
  1. 19
      libraries/AP_HAL_Linux/Util.cpp
  2. 4
      libraries/AP_HAL_Linux/Util.h

19
libraries/AP_HAL_Linux/Util.cpp

@ -62,12 +62,23 @@ void Util::commandline_arguments(uint8_t &argc, char * const *&argv) @@ -62,12 +62,23 @@ void Util::commandline_arguments(uint8_t &argc, char * const *&argv)
argv = saved_argv;
}
uint64_t Util::get_hw_rtc() const
{
struct timespec ts;
clock_gettime(CLOCK_REALTIME, &ts);
const uint64_t seconds = ts.tv_sec;
const uint64_t nanoseconds = ts.tv_nsec;
return (seconds * 1000000ULL + nanoseconds/1000ULL);
}
void Util::set_hw_rtc(uint64_t time_utc_usec)
{
// don't reset the HW clock time on people's laptops.
#if CONFIG_HAL_BOARD_SUBTYPE != HAL_BOARD_SUBTYPE_LINUX_NONE
// call superclass method to set time. We've guarded this so we
// don't reset the HW clock time on people's laptops.
AP_HAL::Util::set_hw_rtc(time_utc_usec);
timespec ts;
ts.tv_sec = time_utc_usec/1000000ULL;
ts.tv_nsec = (time_utc_usec % 1000000ULL) * 1000ULL;
clock_settime(CLOCK_REALTIME, &ts);
#endif
}
@ -342,4 +353,4 @@ bool Util::parse_cpu_set(const char *str, cpu_set_t *cpu_set) const @@ -342,4 +353,4 @@ bool Util::parse_cpu_set(const char *str, cpu_set_t *cpu_set) const
} while (*endptr != '\0');
return true;
}
}

4
libraries/AP_HAL_Linux/Util.h

@ -37,9 +37,11 @@ public: @@ -37,9 +37,11 @@ public:
void commandline_arguments(uint8_t &argc, char * const *&argv) override;
/*
set system clock in UTC microseconds
get/set system clock in UTC microseconds
*/
void set_hw_rtc(uint64_t time_utc_usec) override;
uint64_t get_hw_rtc() const override;
const char *get_custom_log_directory() const override final { return custom_log_directory; }
const char *get_custom_terrain_directory() const override final { return custom_terrain_directory; }
const char *get_custom_storage_directory() const override final { return custom_storage_directory; }

Loading…
Cancel
Save