2020-10-07 23:28:57 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "configuration.h"
|
|
|
|
#include "sys/time.h"
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
2020-10-07 23:46:20 +00:00
|
|
|
enum RTCQuality {
|
2022-04-27 09:05:08 +00:00
|
|
|
|
2020-10-07 23:46:20 +00:00
|
|
|
/// We haven't had our RTC set yet
|
|
|
|
RTCQualityNone = 0,
|
|
|
|
|
2022-04-27 09:05:08 +00:00
|
|
|
/// We got time from an onboard peripheral after boot.
|
|
|
|
RTCQualityDevice = 1,
|
|
|
|
|
2020-10-07 23:46:20 +00:00
|
|
|
/// Some other node gave us a time we can use
|
2022-04-27 09:05:08 +00:00
|
|
|
RTCQualityFromNet = 2,
|
2020-10-07 23:46:20 +00:00
|
|
|
|
2021-12-29 03:24:10 +00:00
|
|
|
/// Our time is based on NTP
|
2022-10-15 00:12:55 +00:00
|
|
|
RTCQualityNTP = 3,
|
2021-12-29 03:24:10 +00:00
|
|
|
|
2020-10-07 23:46:20 +00:00
|
|
|
/// Our time is based on our own GPS
|
2022-04-27 09:05:08 +00:00
|
|
|
RTCQualityGPS = 4
|
2020-10-07 23:46:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
RTCQuality getRTCQuality();
|
2020-10-07 23:28:57 +00:00
|
|
|
|
|
|
|
/// If we haven't yet set our RTC this boot, set it from a GPS derived time
|
2020-10-07 23:46:20 +00:00
|
|
|
bool perhapsSetRTC(RTCQuality q, const struct timeval *tv);
|
|
|
|
bool perhapsSetRTC(RTCQuality q, struct tm &t);
|
2020-10-07 23:28:57 +00:00
|
|
|
|
2020-10-07 23:46:20 +00:00
|
|
|
/// Return time since 1970 in secs. While quality is RTCQualityNone we will be returning time based at zero
|
2020-10-07 23:28:57 +00:00
|
|
|
uint32_t getTime();
|
|
|
|
|
2020-10-07 23:46:20 +00:00
|
|
|
/// Return time since 1970 in secs. If quality is RTCQualityNone return zero
|
2020-10-09 02:01:13 +00:00
|
|
|
uint32_t getValidTime(RTCQuality minQuality);
|
2020-10-07 23:28:57 +00:00
|
|
|
|
2021-03-20 02:22:06 +00:00
|
|
|
void readFromRTC();
|
|
|
|
|
|
|
|
#define SEC_PER_DAY 86400
|
|
|
|
#define SEC_PER_HOUR 3600
|
|
|
|
#define SEC_PER_MIN 60
|