LCOV - code coverage report
Current view: top level - AP_RTC - AP_RTC.h (source / functions) Hit Total Coverage
Test: lcov.info Lines: 3 5 60.0 %
Date: 2026-09-09 11:02:08 Functions: 2 3 66.7 %

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include "AP_RTC_config.h"
       4             : 
       5             : #if AP_RTC_ENABLED
       6             : 
       7             : #include <AP_Param/AP_Param.h>
       8             : 
       9             : #include <stdint.h>
      10             : 
      11             : class AP_RTC {
      12             : 
      13             : public:
      14             : 
      15             :     AP_RTC();
      16             : 
      17             :     static const struct AP_Param::GroupInfo var_info[];
      18             : 
      19             :     AP_Int8 allowed_types;
      20             :     AP_Int16 tz_min;
      21             : 
      22             :     // ordering is important in source_type; lower-numbered is
      23             :     // considered a better time source.  These values are documented
      24             :     // and used in the parameters!
      25             :     enum source_type : uint8_t {
      26             :         SOURCE_GPS = 0,
      27             :         SOURCE_MAVLINK_SYSTEM_TIME = 1,
      28             :         SOURCE_HW = 2,
      29             :         SOURCE_NONE = 3,
      30             :     };
      31             : 
      32             :     /*
      33             :       get clock in UTC microseconds.  Returns false if it is not available.
      34             :      */
      35             :     bool get_utc_usec(uint64_t &usec) const;
      36             : 
      37             :     // set the system time.  If the time has already been set by
      38             :     // something better (according to source_type), this set will be
      39             :     // ignored.
      40             :     void set_utc_usec(uint64_t time_utc_usec, source_type type);
      41             : 
      42             :     // return source type currently in use
      43        9095 :     source_type get_source_type() const { return rtc_source_type; }
      44             : 
      45             :     /*
      46             :       get time in UTC hours, minutes, seconds and milliseconds
      47             :      */
      48             :     bool get_system_clock_utc(uint8_t &hour, uint8_t &min, uint8_t &sec, uint16_t &ms) const;
      49             :     
      50             :     bool get_local_time(uint8_t &hour, uint8_t &min, uint8_t &sec, uint16_t &ms) const;
      51             : 
      52             :     uint32_t get_time_utc(int32_t hour, int32_t min, int32_t sec, int32_t ms);
      53             : 
      54             :     // get date and time.  Returns true on success and fills in year, month, day, hour, min, sec and ms
      55             :     // year is the regular Gregorian year, month is 0~11, day is 1~31, hour is 0~23, minute is 0~59, second is 0~60 (1 leap second), ms is 0~999
      56             :     bool get_date_and_time_utc(uint16_t& year, uint8_t& month, uint8_t& day, uint8_t &hour, uint8_t &min, uint8_t &sec, uint16_t &ms) const;
      57             : 
      58             :     // get singleton instance
      59     9320216 :     static AP_RTC *get_singleton() {
      60     9320216 :         return _singleton;
      61             :     }
      62             : 
      63             :     // allow threads to lock against RTC update
      64           0 :     HAL_Semaphore &get_semaphore(void) {
      65           0 :         return rsem;
      66             :     }
      67             : 
      68             :     bool clock_s_to_date_fields(const uint32_t utc_sec32, uint16_t& year, uint8_t& month, uint8_t& day, uint8_t &hour, uint8_t &min, uint8_t &sec, uint8_t &wday) const;
      69             :     uint32_t date_fields_to_clock_s(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t min, uint8_t sec) const;
      70             : 
      71             :     // emit an RTC message to the onboard logs
      72             :     void Log_RTC();
      73             : 
      74             : private:
      75             : 
      76             :     static AP_RTC *_singleton;
      77             :     HAL_Semaphore rsem;
      78             : 
      79             :     source_type rtc_source_type = SOURCE_NONE;
      80             :     int64_t rtc_shift;
      81             : 
      82             :     void clock_ms_to_hms_fields(const uint64_t time_ms, uint8_t &hour, uint8_t &min, uint8_t &sec, uint16_t &ms) const;
      83             : 
      84             :     static bool _is_leap(uint32_t y);
      85             :     static uint32_t _timegm(struct tm &tm);
      86             : };
      87             : 
      88             : namespace AP {
      89             :     AP_RTC &rtc();
      90             : };
      91             : 
      92             : #endif  // AP_RTC_ENABLED

Generated by: LCOV version 1.14