From edfd8b1fac486ccf8fc129dedd0688115e50b552 Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sun, 31 Mar 2019 15:47:19 +0200 Subject: [PATCH 1/2] #if corrections timesync --- src/lorawan.cpp | 6 ++++++ src/timesync.cpp | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lorawan.cpp b/src/lorawan.cpp index 48781d8c..f06ba289 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -12,6 +12,12 @@ static const char TAG[] = "lora"; #warning CLOCK_ERROR_PROCENTAGE value in lmic_config.h is too high; values > 7 will cause side effects #endif +#if (TIME_SYNC_LORAWAN) +#ifndef LMIC_ENABLE_DeviceTimeReq +#define LMIC_ENABLE_DeviceTimeReq 1 +#endif +#endif + osjob_t sendjob; QueueHandle_t LoraSendQueue; diff --git a/src/timesync.cpp b/src/timesync.cpp index b38f8c34..92af0906 100644 --- a/src/timesync.cpp +++ b/src/timesync.cpp @@ -9,7 +9,7 @@ algorithm in applications without granted license by the patent holder. */ -#ifdef TIME_SYNC_TIMESERVER +#if(TIME_SYNC_TIMESERVER) #include "timesync.h" From 6aba3c128b7aa77412a82857faac657511bd7a1e Mon Sep 17 00:00:00 2001 From: Verkehrsrot Date: Sun, 31 Mar 2019 15:56:56 +0200 Subject: [PATCH 2/2] issue #331 --- include/lorawan.h | 2 +- include/rcommand.h | 2 +- include/timesync.h | 4 ++-- src/lorawan.cpp | 4 ++-- src/main.cpp | 2 +- src/paxcounter.conf | 2 +- src/timekeeper.cpp | 10 +++++----- src/timesync.cpp | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/lorawan.h b/include/lorawan.h index cb4158e0..47170b4a 100644 --- a/include/lorawan.h +++ b/include/lorawan.h @@ -4,7 +4,7 @@ #include "globals.h" #include "rcommand.h" #include "timekeeper.h" -#if(TIME_SYNC_TIMESERVER) +#if(TIME_SYNC_LORASERVER) #include "timesync.h" #endif diff --git a/include/rcommand.h b/include/rcommand.h index d708827b..e964eb85 100644 --- a/include/rcommand.h +++ b/include/rcommand.h @@ -11,7 +11,7 @@ #include #include "cyclic.h" #include "timekeeper.h" -#if(TIME_SYNC_TIMESERVER) +#if(TIME_SYNC_LORASERVER) #include "timesync.h" #endif diff --git a/include/timesync.h b/include/timesync.h index 232ac541..80b7b1b1 100644 --- a/include/timesync.h +++ b/include/timesync.h @@ -1,5 +1,5 @@ -#ifndef _TIME_SYNC_TIMESERVER_H -#define _TIME_SYNC_TIMESERVER_H +#ifndef _TIME_SYNC_LORASERVER_H +#define _TIME_SYNC_LORASERVER_H #include #include "globals.h" diff --git a/src/lorawan.cpp b/src/lorawan.cpp index f06ba289..264a3620 100644 --- a/src/lorawan.cpp +++ b/src/lorawan.cpp @@ -239,7 +239,7 @@ void onEvent(ev_t ev) { case EV_TXCOMPLETE: -#if (TIME_SYNC_TIMESERVER) +#if (TIME_SYNC_LORASERVER) // if last packet sent was a timesync request, store TX timestamp if (LMIC.pendTxPort == TIMEPORT) { store_time_sync_req(osticks2ms(LMIC.txend)); // milliseconds @@ -257,7 +257,7 @@ void onEvent(ev_t ev) { if (LMIC.txrxFlags & TXRX_PORT) { // FPort -> use to switch switch (LMIC.frame[LMIC.dataBeg - 1]) { -#if (TIME_SYNC_TIMESERVER) +#if (TIME_SYNC_LORASERVER) case TIMEPORT: // timesync answer -> call timesync processor recv_timesync_ans(LMIC.frame + LMIC.dataBeg, LMIC.dataLen); break; diff --git a/src/main.cpp b/src/main.cpp index 4029cd7f..21a2a946 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -411,7 +411,7 @@ void setup() { #endif // HAS_BUTTON #if (TIME_SYNC_INTERVAL) -#if (!defined(TIME_SYNC_LORAWAN) && !defined(TIME_SYNC_TIMESERVER) && \ +#if (!defined(TIME_SYNC_LORAWAN) && !defined(TIME_SYNC_LORASERVER) && \ !defined HAS_GPS && !defined HAS_RTC) #warning you did not specify a time source, time will not be synched #endif diff --git a/src/paxcounter.conf b/src/paxcounter.conf index 24da1a74..aa441951 100644 --- a/src/paxcounter.conf +++ b/src/paxcounter.conf @@ -70,7 +70,7 @@ #define TIME_SYNC_INTERVAL_RETRY 0 // retry time sync after lost sync each .. minutes [default = 10], 0 means off #define TIME_SYNC_COMPILEDATE 0 // set to 1 to use compile date to initialize RTC after power outage [default = 0] #define TIME_SYNC_LORAWAN 0 // set to 1 to use LORA network as time source, 0 means off [default = 0] -#define TIME_SYNC_TIMESERVER 0 // set to 1 to use LORA timeserver as time source, 0 means off [default = 0] +#define TIME_SYNC_LORASERVER 0 // set to 1 to use LORA timeserver as time source, 0 means off [default = 0] // settings for syncing time with timeserver applications #define TIME_SYNC_SAMPLES 1 // number of time requests for averaging diff --git a/src/timekeeper.cpp b/src/timekeeper.cpp index 53907a98..ef49410b 100644 --- a/src/timekeeper.cpp +++ b/src/timekeeper.cpp @@ -1,8 +1,8 @@ #include "timekeeper.h" -#ifndef HAS_LORA -#if (TIME_SYNC_TIMESERVER) -#error TIME_SYNC_TIMESERVER defined, but device has no LORA configured +#if !(HAS_LORA) +#if (TIME_SYNC_LORASERVER) +#error TIME_SYNC_LORASERVER defined, but device has no LORA configured #elif (TIME_SYNC_LORAWAN) #error TIME_SYNC_LORAWAN defined, but device has no LORA configured #endif @@ -48,10 +48,10 @@ time_t timeProvider(void) { #endif // kick off asychronous Lora timeserver timesync if we have -#if (TIME_SYNC_TIMESERVER) +#if (HAS_LORA) && (TIME_SYNC_LORASERVER) send_timesync_req(); // kick off asychronous lora network sync if we have -#elif (TIME_SYNC_LORAWAN) +#elif (HAS_LORA) && (TIME_SYNC_LORAWAN) LMIC_requestNetworkTime(user_request_network_time_callback, &userUTCTime); #endif diff --git a/src/timesync.cpp b/src/timesync.cpp index 92af0906..066ae9df 100644 --- a/src/timesync.cpp +++ b/src/timesync.cpp @@ -9,7 +9,7 @@ algorithm in applications without granted license by the patent holder. */ -#if(TIME_SYNC_TIMESERVER) +#if(TIME_SYNC_LORASERVER) #include "timesync.h"