start uart timestamp send when time has been synced

This commit is contained in:
Marius Gripp 2019-08-27 16:00:25 +02:00
parent 6894d718e6
commit cab44588c7
3 changed files with 20 additions and 1 deletions

View File

@ -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 {

View File

@ -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
}

View File

@ -1 +1,2 @@
void time_uart_send(void * pvParameters);
void time_uart_send_start();