bugfix reagard leap seconds in network time sync
This commit is contained in:
parent
f876edfe36
commit
335d646fe7
@ -10,6 +10,7 @@
|
|||||||
#define TIME_SYNC_MAX_SEQNO 0xfe // threshold for wrap around time_sync_seqNo
|
#define TIME_SYNC_MAX_SEQNO 0xfe // threshold for wrap around time_sync_seqNo
|
||||||
#define TIME_SYNC_END_FLAG (TIME_SYNC_MAX_SEQNO + 1) // end of handshake marker
|
#define TIME_SYNC_END_FLAG (TIME_SYNC_MAX_SEQNO + 1) // end of handshake marker
|
||||||
#define GPS_UTC_DIFF 315964800 // seconds diff between gps and utc epoch
|
#define GPS_UTC_DIFF 315964800 // seconds diff between gps and utc epoch
|
||||||
|
#define LEAP_SECS_SINCE_GPSEPOCH 18 // state of 2021
|
||||||
|
|
||||||
enum timesync_t {
|
enum timesync_t {
|
||||||
timesync_tx,
|
timesync_tx,
|
||||||
|
@ -120,7 +120,7 @@ time_t get_gpstime(uint16_t *msec) {
|
|||||||
t = makeTime(tm);
|
t = makeTime(tm);
|
||||||
|
|
||||||
ESP_LOGD(TAG, "GPS date/time: %s",
|
ESP_LOGD(TAG, "GPS date/time: %s",
|
||||||
UTC.dateTime(t, "d.M Y H:i:s T").c_str());
|
UTC.dateTime(t, "d.M Y H:i:s.v T").c_str());
|
||||||
|
|
||||||
// add protocol delay with millisecond precision
|
// add protocol delay with millisecond precision
|
||||||
t += delay_ms / 1000 - 1; // whole seconds
|
t += delay_ms / 1000 - 1; // whole seconds
|
||||||
|
@ -121,6 +121,7 @@ void setup() {
|
|||||||
// set time zone to user value from paxcounter.conf
|
// set time zone to user value from paxcounter.conf
|
||||||
#ifdef TIME_SYNC_TIMEZONE
|
#ifdef TIME_SYNC_TIMEZONE
|
||||||
myTZ.setPosix(TIME_SYNC_TIMEZONE);
|
myTZ.setPosix(TIME_SYNC_TIMEZONE);
|
||||||
|
ESP_LOGD(TAG, "Timezone set to %s", myTZ.getPosix().c_str());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// hash 6 byte device MAC to 4 byte clientID
|
// hash 6 byte device MAC to 4 byte clientID
|
||||||
|
@ -143,7 +143,7 @@ void IRAM_ATTR timesync_processReq(void *taskparameter) {
|
|||||||
time_offset_ms %= 1000;
|
time_offset_ms %= 1000;
|
||||||
|
|
||||||
ESP_LOGD(TAG, "LORA date/time: %s",
|
ESP_LOGD(TAG, "LORA date/time: %s",
|
||||||
myTZ.dateTime(time_offset_sec, "d.M Y H:i:s T").c_str());
|
myTZ.dateTime(time_offset_sec, "d.M Y H:i:s.v T").c_str());
|
||||||
|
|
||||||
setMyTime(time_offset_sec, time_offset_ms, _lora);
|
setMyTime(time_offset_sec, time_offset_ms, _lora);
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ void IRAM_ATTR timesync_processReq(void *taskparameter) {
|
|||||||
|
|
||||||
// store incoming timestamps
|
// store incoming timestamps
|
||||||
void timesync_store(uint32_t timestamp, timesync_t timestamp_type) {
|
void timesync_store(uint32_t timestamp, timesync_t timestamp_type) {
|
||||||
ESP_LOGD(TAG, "[%0.3f] seq#%d[%d]: t%d=%d", _seconds(), time_sync_seqNo,
|
ESP_LOGD(TAG, "[%0.3f] seq#%d[%d]: t%d=%d", _seconds(), time_sync_seqNo - 1,
|
||||||
sample_idx, timestamp_type, timestamp);
|
sample_idx, timestamp_type, timestamp);
|
||||||
timesync_timestamp[sample_idx][timestamp_type] = timestamp;
|
timesync_timestamp[sample_idx][timestamp_type] = timestamp;
|
||||||
}
|
}
|
||||||
@ -239,14 +239,16 @@ void IRAM_ATTR timesync_serverAnswer(void *pUserData, int flag) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Populate lmic_time_reference
|
// Populate lmic_time_reference
|
||||||
if ((LMIC_getNetworkTimeReference(&lmicTime)) != 1) {
|
flag = LMIC_getNetworkTimeReference(&lmicTime);
|
||||||
|
if (flag != 1) {
|
||||||
ESP_LOGW(TAG, "[%0.3f] Network time request failed", _seconds());
|
ESP_LOGW(TAG, "[%0.3f] Network time request failed", _seconds());
|
||||||
goto Exit;
|
goto Exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate UTCTime, considering the difference between GPS and UTC time
|
// Calculate UTCTime, considering the difference between GPS and UTC time
|
||||||
// epoch, and the leap seconds
|
// epoch, and the leap seconds
|
||||||
timestamp_sec = lmicTime.tNetwork + GPS_UTC_DIFF;
|
timestamp_sec = lmicTime.tNetwork + GPS_UTC_DIFF - LEAP_SECS_SINCE_GPSEPOCH;
|
||||||
|
ESP_LOGD(TAG, "lmicTime.tNetwork = %d", timestamp_sec);
|
||||||
|
|
||||||
// Add the delay between the instant the time was transmitted and
|
// Add the delay between the instant the time was transmitted and
|
||||||
// the current time
|
// the current time
|
||||||
|
Loading…
Reference in New Issue
Block a user