From 9eb8d7d2cd31fe99141c965430ecbc84315216f2 Mon Sep 17 00:00:00 2001 From: Adrian Teuscher Date: Fri, 20 Sep 2019 14:47:14 +0200 Subject: [PATCH 1/4] Fix compiler warnings. --- DCF77.cpp | 1 - utility/Utils.cpp | 4 ++-- utility/Utils.h | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/DCF77.cpp b/DCF77.cpp index ccfb47b..0192f48 100644 --- a/DCF77.cpp +++ b/DCF77.cpp @@ -270,7 +270,6 @@ bool DCF77::processBuffer(void) { // Calculate parities for checking buffer calculateBufferParities(); tmElements_t time; - bool proccessedSucces; struct DCF77Buffer *rx_buffer; rx_buffer = (struct DCF77Buffer *)(unsigned long long)&processingBuffer; diff --git a/utility/Utils.cpp b/utility/Utils.cpp index 5b32bad..29fc643 100644 --- a/utility/Utils.cpp +++ b/utility/Utils.cpp @@ -5,14 +5,14 @@ namespace Utils { #define DEBUG_BLINK_PIN 13 // Connected to debug led //#define VERBOSE_DEBUG 1 // Verbose - void LogLn(char*s) + void LogLn(const char*s) { #ifdef VERBOSE_DEBUG Serial.println(s); #endif } - void Log(char*s) + void Log(const char*s) { #ifdef VERBOSE_DEBUG Serial.print(s); diff --git a/utility/Utils.h b/utility/Utils.h index 0b08811..7cb2da0 100644 --- a/utility/Utils.h +++ b/utility/Utils.h @@ -12,8 +12,8 @@ #define intRestore(sreg) SREG = sreg namespace Utils { - void Log(char*s); - void LogLn(char*s); + void Log(const char*s); + void LogLn(const char*s); void Log(int i,char format); void LogLn(int i,char format); void Log(int i); From 8e779b1b01fa762165c4c1d7baf1c00c2a8a6f90 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Wed, 17 May 2023 19:58:31 +0200 Subject: [PATCH 2/4] set dependencies versions for possible incompatibility issues --- library.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index c3a5cec..28bcbe1 100644 --- a/library.json +++ b/library.json @@ -12,11 +12,13 @@ [ { "name": "Time", - "frameworks": "arduino" + "frameworks": "arduino", + "versions" : "1.6.1" }, { "name": "Timezone", - "frameworks": "arduino" + "frameworks": "arduino", + "versions" : "1.2.4" } ], "frameworks": "arduino" From 8af10d2c90e5001167824b585a925f00286abe82 Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Thu, 18 May 2023 04:01:44 +0200 Subject: [PATCH 3/4] first callback events of buffer messgages and signal --- DCF77.cpp | 28 ++++++++++++++++++---------- DCF77.h | 15 ++++++++++++++- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/DCF77.cpp b/DCF77.cpp index ccfb47b..bc035a1 100644 --- a/DCF77.cpp +++ b/DCF77.cpp @@ -137,15 +137,17 @@ void DCF77::int0handler() { * Add new bit to buffer */ inline void DCF77::appendSignal(unsigned char signal) { - Log(signal, DEC); - runningBuffer = runningBuffer | ((unsigned long long) signal << bufferPosition); - bufferPosition++; - if (bufferPosition > 59) { - // Buffer is full before at end of time-sequence - // this may be due to noise giving additional peaks - LogLn("EoB"); - finalizeBuffer(); - } + Log(signal, DEC); + if (cb != nullptr) cb->onSignal(signal); + runningBuffer = runningBuffer | ((unsigned long long)signal << bufferPosition); + bufferPosition++; + if (bufferPosition > 59) { + // Buffer is full before at end of time-sequence + // this may be due to noise giving additional peaks + LogLn("EoB"); + if (cb != nullptr) cb->onBufferMsg("EoB"); + finalizeBuffer(); + } } /** @@ -164,6 +166,7 @@ inline void DCF77::finalizeBuffer(void) { } else { // Buffer is not yet full at end of time-sequence LogLn("EoM"); + if (cb != nullptr) cb->onBufferMsg("EoM"); // Reset running buffer bufferinit(); } @@ -333,7 +336,11 @@ time_t DCF77::getUTCTime(void) int DCF77::getSummerTime(void) { return (CEST)?1:0; -} +} + +void DCF77::setCallBack(DCF77EventsCallback *pCallBack) { + cb = pCallBack; +} /** * Initialize parameters @@ -366,5 +373,6 @@ time_t DCF77::processingTimestamp= 0; time_t DCF77::previousProcessingTimestamp=0; unsigned char DCF77::CEST=0; DCF77::ParityFlags DCF77::flags = {0,0,0,0}; +DCF77EventsCallback *DCF77::cb = nullptr; diff --git a/DCF77.h b/DCF77.h index bdd0bf1..93e7d0b 100644 --- a/DCF77.h +++ b/DCF77.h @@ -16,6 +16,7 @@ #define DCFSplitTime 180 // Specifications distinguishes pulse width 100 ms and 200 ms. In practice we see 130 ms and 230 #define DCFSyncTime 1500 // Specifications defines 2000 ms pulse for end of sequence +class DCF77EventsCallback; class DCF77 { private: @@ -93,8 +94,20 @@ class DCF77 { static void Start(void); static void Stop(void); static void int0handler(); - static int getSummerTime(); + static int getSummerTime(); + static void setCallBack(DCF77EventsCallback *pCallBack); + + static DCF77EventsCallback *cb; }; +class DCF77EventsCallback { +public: + virtual ~DCF77EventsCallback () {}; + virtual void onGetTime(); + virtual void onParityError(); + virtual void onBufferMsg(const char * msg); + virtual void onSignal(unsigned char signal); +}; + #endif From db7993d49d7abbf3c471d4963be47775e82e9dff Mon Sep 17 00:00:00 2001 From: Hpsaturn Date: Thu, 18 May 2023 15:11:24 +0200 Subject: [PATCH 4/4] added missing callback event calls and some format improvements --- DCF77.cpp | 38 +++++++++++++++++++++----------------- DCF77.h | 2 +- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/DCF77.cpp b/DCF77.cpp index bc035a1..008819d 100644 --- a/DCF77.cpp +++ b/DCF77.cpp @@ -106,7 +106,7 @@ void DCF77::int0handler() { // If the detected pulse is too short it will be an // incorrect pulse that we shall reject as well if ((flankTime-leadingEdge)onBufferMsg("EoB"); finalizeBuffer(); } } @@ -155,21 +154,22 @@ inline void DCF77::appendSignal(unsigned char signal) { */ inline void DCF77::finalizeBuffer(void) { if (bufferPosition == 59) { - // Buffer is full - LogLn("BF"); - // Prepare filled buffer and time stamp for main loop - filledBuffer = runningBuffer; - filledTimestamp = now(); - // Reset running buffer - bufferinit(); - FilledBufferAvailable = true; - } else { - // Buffer is not yet full at end of time-sequence - LogLn("EoM"); + // Buffer is full + LogLn("BF"); + // Prepare filled buffer and time stamp for main loop + filledBuffer = runningBuffer; + filledTimestamp = now(); + // Reset running buffer + bufferinit(); + FilledBufferAvailable = true; + if (cb != nullptr) cb->onBufferMsg("BF"); + } else { + // Buffer is not yet full at end of time-sequence + LogLn("EoM"); if (cb != nullptr) cb->onBufferMsg("EoM"); - // Reset running buffer - bufferinit(); - } + // Reset running buffer + bufferinit(); + } } /** @@ -184,14 +184,15 @@ bool DCF77::receivedTimeUpdate(void) { // if buffer is filled, we will process it and see if this results in valid parity if (!processBuffer()) { LogLn("Invalid parity"); + if (cb != nullptr) cb->onParityError(); return false; } - // Since the received signal is error-prone, and the parity check is not very strong, // we will do some sanity checks on the time time_t processedTime = latestupdatedTime + (now() - processingTimestamp); if (processedTimeMAX_TIME) { LogLn("Time outside of bounds"); + if (cb != nullptr) cb->onParityError(); return false; } @@ -200,6 +201,7 @@ bool DCF77::receivedTimeUpdate(void) { if(difference < 2*SECS_PER_MIN) { LogLn("close to internal clock"); storePreviousTime(); + if (cb != nullptr) cb->onTimeUpdateMsg("Close to internal clock"); return true; } @@ -211,8 +213,10 @@ bool DCF77::receivedTimeUpdate(void) { storePreviousTime(); if(shiftDifference < 2*SECS_PER_MIN) { LogLn("time lag consistent"); + if (cb != nullptr) cb->onTimeUpdateMsg("Time lag consistent"); return true; } else { + if (cb != nullptr) cb->onTimeUpdateMsg("Time lag inconsistent"); LogLn("time lag inconsistent"); } diff --git a/DCF77.h b/DCF77.h index 93e7d0b..c7f68e0 100644 --- a/DCF77.h +++ b/DCF77.h @@ -103,9 +103,9 @@ class DCF77 { class DCF77EventsCallback { public: virtual ~DCF77EventsCallback () {}; - virtual void onGetTime(); virtual void onParityError(); virtual void onBufferMsg(const char * msg); + virtual void onTimeUpdateMsg(const char * msg); virtual void onSignal(unsigned char signal); };