2018-04-10 08:43:03 -03:00
|
|
|
#pragma once
|
|
|
|
|
2023-10-05 20:44:43 -03:00
|
|
|
#include "AP_RTC_config.h"
|
|
|
|
|
2023-10-05 20:45:02 -03:00
|
|
|
#if AP_RTC_ENABLED
|
|
|
|
|
2018-06-13 23:16:41 -03:00
|
|
|
#include <AP_Param/AP_Param.h>
|
|
|
|
|
2018-04-10 08:43:03 -03:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
class AP_RTC {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2018-06-13 23:16:41 -03:00
|
|
|
AP_RTC();
|
|
|
|
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
|
|
|
AP_Int8 allowed_types;
|
2019-10-07 03:46:25 -03:00
|
|
|
AP_Int16 tz_min;
|
2018-04-10 08:43:03 -03:00
|
|
|
|
|
|
|
// ordering is important in source_type; lower-numbered is
|
2018-06-13 23:16:41 -03:00
|
|
|
// considered a better time source. These values are documented
|
|
|
|
// and used in the parameters!
|
2018-04-10 08:43:03 -03:00
|
|
|
enum source_type : uint8_t {
|
2018-06-13 23:16:41 -03:00
|
|
|
SOURCE_GPS = 0,
|
|
|
|
SOURCE_MAVLINK_SYSTEM_TIME = 1,
|
|
|
|
SOURCE_HW = 2,
|
2018-04-10 08:43:03 -03:00
|
|
|
SOURCE_NONE,
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
get clock in UTC microseconds. Returns false if it is not available.
|
|
|
|
*/
|
|
|
|
bool get_utc_usec(uint64_t &usec) const;
|
|
|
|
|
|
|
|
// set the system time. If the time has already been set by
|
|
|
|
// something better (according to source_type), this set will be
|
|
|
|
// ignored.
|
|
|
|
void set_utc_usec(uint64_t time_utc_usec, source_type type);
|
|
|
|
|
|
|
|
/*
|
|
|
|
get time in UTC hours, minutes, seconds and milliseconds
|
|
|
|
*/
|
2021-02-01 12:26:33 -04:00
|
|
|
bool get_system_clock_utc(uint8_t &hour, uint8_t &min, uint8_t &sec, uint16_t &ms) const;
|
2019-10-07 03:46:25 -03:00
|
|
|
|
2021-02-01 12:26:33 -04:00
|
|
|
bool get_local_time(uint8_t &hour, uint8_t &min, uint8_t &sec, uint16_t &ms) const;
|
2018-04-10 08:43:03 -03:00
|
|
|
|
|
|
|
uint32_t get_time_utc(int32_t hour, int32_t min, int32_t sec, int32_t ms);
|
|
|
|
|
2023-06-26 22:36:58 -03:00
|
|
|
// get date and time. Returns true on success and fills in year, month, day, hour, min, sec and ms
|
2023-07-12 09:10:59 -03:00
|
|
|
// 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
|
|
|
|
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;
|
2023-06-26 22:36:58 -03:00
|
|
|
|
2018-04-10 08:43:03 -03:00
|
|
|
// get singleton instance
|
|
|
|
static AP_RTC *get_singleton() {
|
|
|
|
return _singleton;
|
|
|
|
}
|
|
|
|
|
2020-01-03 20:05:51 -04:00
|
|
|
// allow threads to lock against RTC update
|
|
|
|
HAL_Semaphore &get_semaphore(void) {
|
|
|
|
return rsem;
|
|
|
|
}
|
|
|
|
|
2018-04-10 08:43:03 -03:00
|
|
|
private:
|
|
|
|
|
|
|
|
static AP_RTC *_singleton;
|
2020-01-18 17:57:27 -04:00
|
|
|
HAL_Semaphore rsem;
|
2018-04-10 08:43:03 -03:00
|
|
|
|
|
|
|
source_type rtc_source_type = SOURCE_NONE;
|
|
|
|
int64_t rtc_shift;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace AP {
|
|
|
|
AP_RTC &rtc();
|
|
|
|
};
|
2023-10-05 20:45:02 -03:00
|
|
|
|
|
|
|
#endif // AP_RTC_ENABLED
|