Merge pull request #316 from cyberman54/development

Timesync 1st precise stable version
This commit is contained in:
Verkehrsrot 2019-03-15 22:49:09 +01:00 committed by GitHub
commit e336d6e0f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View File

@ -6,8 +6,8 @@
#include "timesync.h" #include "timesync.h"
#include "timekeeper.h" #include "timekeeper.h"
#define TIME_SYNC_SAMPLES 5 // number of time requests for averaging #define TIME_SYNC_SAMPLES 3 // number of time requests for averaging
#define TIME_SYNC_CYCLE 60 // seconds between two time requests #define TIME_SYNC_CYCLE 20 // seconds between two time requests
#define TIME_SYNC_TIMEOUT 120 // timeout seconds waiting for timeserver answer #define TIME_SYNC_TIMEOUT 120 // timeout seconds waiting for timeserver answer
#define TIME_SYNC_TRIGGER 100 // time deviation in millisec triggering a sync #define TIME_SYNC_TRIGGER 100 // time deviation in millisec triggering a sync
#define TIME_SYNC_FRAME_LENGTH 0x06 // timeserver answer frame length #define TIME_SYNC_FRAME_LENGTH 0x06 // timeserver answer frame length

View File

@ -140,8 +140,8 @@ void process_timesync_req(void *taskparameter) {
// calculate time offset from collected diffs and set time if necessary // calculate time offset from collected diffs and set time if necessary
ESP_LOGD(TAG, "Avg time diff: %lldms", time_offset.count()); ESP_LOGD(TAG, "Avg time diff: %lldms", time_offset.count());
time_offset /= TIME_SYNC_SAMPLES; time_offset /= TIME_SYNC_SAMPLES;
// 1 sec floor round + 1sec wait for top of second // 1sec wait for top of second
time_to_set = now() + 2 + time_offset.count() / 1000; time_to_set = now() + time_offset.count() / 1000 + 1;
ESP_LOGD(TAG, "Calculated UTC epoch time: %d", time_to_set); ESP_LOGD(TAG, "Calculated UTC epoch time: %d", time_to_set);
// adjust system time // adjust system time
@ -155,17 +155,17 @@ void process_timesync_req(void *taskparameter) {
ESP_LOGD(TAG, "waiting %dms", 1000 - time_offset_msec); ESP_LOGD(TAG, "waiting %dms", 1000 - time_offset_msec);
vTaskDelay(pdMS_TO_TICKS(1000 - time_offset_msec)); vTaskDelay(pdMS_TO_TICKS(1000 - time_offset_msec));
setTime(time_to_set);
// sync timer pps to top of second // sync timer pps to top of second
if (ppsIRQ) if (ppsIRQ)
timerRestart(ppsIRQ); timerWrite(ppsIRQ, 10000); // fire interrupt
setTime(time_to_set);
timeSource = _lora; timeSource = _lora;
timesyncer.attach(TIME_SYNC_INTERVAL * 60, timesyncer.attach(TIME_SYNC_INTERVAL * 60,
timeSync); // set to regular repeat timeSync); // set to regular repeat
ESP_LOGI(TAG, "Timesync finished, time was adjusted"); ESP_LOGI(TAG, "Timesync finished, time adjusted by %lld ms", time_offset.count());
} else } else
ESP_LOGI(TAG, "Timesync finished, time is up to date"); ESP_LOGI(TAG, "Timesync finished, time not adjusted, is up to date");
} else } else
ESP_LOGW(TAG, "Invalid time received from timeserver"); ESP_LOGW(TAG, "Invalid time received from timeserver");