2019-02-24 01:44:55 +01:00
|
|
|
#ifndef _timekeeper_H
|
|
|
|
#define _timekeeper_H
|
2019-02-21 23:17:01 +01:00
|
|
|
|
|
|
|
#include "globals.h"
|
|
|
|
#include "rtctime.h"
|
2019-03-03 00:30:57 +01:00
|
|
|
#include "irqhandler.h"
|
2020-03-04 21:54:26 +01:00
|
|
|
#include "timesync.h"
|
2019-02-21 23:17:01 +01:00
|
|
|
#include "gpsread.h"
|
|
|
|
#include "if482.h"
|
|
|
|
#include "dcf77.h"
|
2022-01-23 21:12:28 +01:00
|
|
|
#include "esp_sntp.h"
|
2019-02-21 23:17:01 +01:00
|
|
|
|
2022-03-05 14:07:48 +01:00
|
|
|
#define HAS_LORA_TIME \
|
|
|
|
((HAS_LORA) && ((TIME_SYNC_LORASERVER) || (TIME_SYNC_LORAWAN)))
|
2022-02-21 10:44:13 +01:00
|
|
|
|
2022-01-26 16:21:44 +01:00
|
|
|
#define SECS_YR_2000 (946684800UL) // the time at the start of y2k
|
|
|
|
#define GPS_UTC_DIFF 315964800UL // seconds diff between gps and utc epoch
|
2022-01-13 23:30:18 +01:00
|
|
|
#define LEAP_SECS_SINCE_GPSEPOCH 18UL // state of 2021
|
|
|
|
|
2021-04-07 21:13:16 +02:00
|
|
|
enum timesource_t { _gps, _rtc, _lora, _unsynced, _set };
|
2021-03-31 21:43:51 +02:00
|
|
|
|
2019-02-24 15:08:41 +01:00
|
|
|
extern const char timeSetSymbols[];
|
2019-03-03 00:30:57 +01:00
|
|
|
extern Ticker timesyncer;
|
2021-03-31 21:43:51 +02:00
|
|
|
extern timesource_t timeSource;
|
|
|
|
extern TaskHandle_t ClockTask;
|
2022-02-07 15:38:15 +01:00
|
|
|
extern DRAM_ATTR bool TimePulseTick; // 1sec pps flag set by GPS or RTC
|
2022-02-12 16:26:41 +01:00
|
|
|
extern DRAM_ATTR unsigned long lastPPS;
|
2021-03-31 21:43:51 +02:00
|
|
|
extern hw_timer_t *ppsIRQ;
|
2019-02-23 21:51:24 +01:00
|
|
|
|
2020-10-04 14:29:57 +02:00
|
|
|
void setTimeSyncIRQ(void);
|
2022-03-05 14:07:48 +01:00
|
|
|
void time_init(void);
|
2022-01-13 23:30:18 +01:00
|
|
|
bool timeIsValid(time_t const t);
|
2019-08-03 12:27:24 +02:00
|
|
|
void calibrateTime(void);
|
2022-03-05 14:07:48 +01:00
|
|
|
bool setMyTime(uint32_t t_sec, uint16_t t_msec, timesource_t mytimesource);
|
2022-01-26 16:21:44 +01:00
|
|
|
time_t compileTime(void);
|
2022-01-13 23:30:18 +01:00
|
|
|
time_t mkgmtime(const struct tm *ptm);
|
2019-02-25 20:22:03 +01:00
|
|
|
TickType_t tx_Ticks(uint32_t framesize, unsigned long baud, uint32_t config,
|
|
|
|
int8_t rxPin, int8_t txPins);
|
2019-02-24 01:44:55 +01:00
|
|
|
#endif // _timekeeper_H
|