From cab44588c79d1d09ed0de076690942829b3ff88d Mon Sep 17 00:00:00 2001 From: Marius Gripp Date: Tue, 27 Aug 2019 16:00:25 +0200 Subject: [PATCH] start uart timestamp send when time has been synced --- src/timesync.cpp | 2 ++ src/uart.cpp | 18 +++++++++++++++++- src/uart.h | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/timesync.cpp b/src/timesync.cpp index 488561c2..09e28b3b 100644 --- a/src/timesync.cpp +++ b/src/timesync.cpp @@ -12,6 +12,7 @@ algorithm in applications without granted license by the patent holder. #if (TIME_SYNC_LORASERVER) && (HAS_LORA) #include "timesync.h" +#include "uart.h" // Local logging tag static const char TAG[] = __FILE__; @@ -282,6 +283,7 @@ void IRAM_ATTR setMyTime(uint32_t t_sec, uint16_t t_msec, timeSource = mytimesource; // set global variable timesyncer.attach(TIME_SYNC_INTERVAL * 60, timeSync); + time_uart_send_start(); ESP_LOGI(TAG, "[%0.3f] Timesync finished, time was set | source: %c", millis() / 1000.0, timeSetSymbols[timeSource]); } else { diff --git a/src/uart.cpp b/src/uart.cpp index 52ac63f2..1303cbf5 100644 --- a/src/uart.cpp +++ b/src/uart.cpp @@ -5,6 +5,9 @@ #include "globals.h" #include "driver/uart.h" +static const char TAG[] = __FILE__; +TaskHandle_t UartTask = NULL; + void time_uart_send(void * pvParameters) { struct timeval curTime; @@ -25,7 +28,7 @@ void time_uart_send(void * pvParameters) { // gettimeofday(&curTime, &tz); int sleep = 1000 - (curTime.tv_usec/1000); ostime_t now = os_getTime(); - printf("Sleep Time: %d, now: %d\n", sleep, now); + ESP_LOGD(TAG, "Sleep Time: %d, now: %d\n", sleep, now); vTaskDelayUntil( &xLastWakeTime, (TickType_t)(sleep/portTICK_PERIOD_MS) ); // Read UART for testing purposes @@ -43,3 +46,16 @@ void time_uart_send(void * pvParameters) { vTaskDelete(NULL); } + +void time_uart_send_start() { + if (UartTask) { + return; + } + xTaskCreatePinnedToCore(time_uart_send, // task function + "time_uart_send", // name of task + 2048, // stack size of task + (void *)1, // parameter of the task + 2, // priority of the task + &UartTask, // task handle + 1); // CPU core +} diff --git a/src/uart.h b/src/uart.h index 78b81ed5..612aabbe 100644 --- a/src/uart.h +++ b/src/uart.h @@ -1 +1,2 @@ void time_uart_send(void * pvParameters); +void time_uart_send_start();