AP_RTC.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. #include <AP_Param/AP_Param.h>
  3. #include <stdint.h>
  4. class AP_RTC {
  5. public:
  6. AP_RTC();
  7. static const struct AP_Param::GroupInfo var_info[];
  8. AP_Int8 allowed_types;
  9. // ordering is important in source_type; lower-numbered is
  10. // considered a better time source. These values are documented
  11. // and used in the parameters!
  12. enum source_type : uint8_t {
  13. SOURCE_GPS = 0,
  14. SOURCE_MAVLINK_SYSTEM_TIME = 1,
  15. SOURCE_HW = 2,
  16. SOURCE_NONE,
  17. };
  18. /*
  19. get clock in UTC microseconds. Returns false if it is not available.
  20. */
  21. bool get_utc_usec(uint64_t &usec) const;
  22. // set the system time. If the time has already been set by
  23. // something better (according to source_type), this set will be
  24. // ignored.
  25. void set_utc_usec(uint64_t time_utc_usec, source_type type);
  26. /*
  27. get time in UTC hours, minutes, seconds and milliseconds
  28. */
  29. bool get_system_clock_utc(uint8_t &hour, uint8_t &min, uint8_t &sec, uint16_t &ms);
  30. uint32_t get_time_utc(int32_t hour, int32_t min, int32_t sec, int32_t ms);
  31. // get singleton instance
  32. static AP_RTC *get_singleton() {
  33. return _singleton;
  34. }
  35. private:
  36. static AP_RTC *_singleton;
  37. source_type rtc_source_type = SOURCE_NONE;
  38. int64_t rtc_shift;
  39. };
  40. namespace AP {
  41. AP_RTC &rtc();
  42. };