From 587511495b6d5ddbdb12d7cdb10c4e7d325138be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl-Petter=20=C3=85kesson?= Date: Fri, 10 Apr 2015 14:12:04 +0200 Subject: [PATCH 1/5] Changed so if the sync provider returns 0 the next call to now() will try to sync. --- Time.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Time.cpp b/Time.cpp index b12baec..9e5b22d 100644 --- a/Time.cpp +++ b/Time.cpp @@ -248,9 +248,9 @@ time_t sysUnsyncedTime = 0; // the time sysTime unadjusted by sync time_t now() { - // calculate number of seconds passed since last call to now() + // calculate number of seconds passed since last call to now() while (millis() - prevMillis >= 1000) { - // millis() and prevMillis are both unsigned ints thus the subtraction will always be the absolute value of the difference + // millis() and prevMillis are both unsigned ints thus the subtraction will always be the absolute value of the difference sysTime++; prevMillis += 1000; #ifdef TIME_DRIFT_INFO @@ -262,9 +262,13 @@ time_t now() { time_t t = getTimePtr(); if (t != 0) { setTime(t); + } else if(timeNotSet == Status) { + // getTimePtr returned 0 and time has not yet been set, i.e. this was not + // a temporarily failure, we have not been able to sync at all. + // Do nothing so a new attempt to sync will be made next time now() is called. } else { nextSyncTime = sysTime + syncInterval; - Status = (Status == timeNotSet) ? timeNotSet : timeNeedsSync; + Status = timeNeedsSync; } } } From 83b2e405917f1ed66d5a6ffbeafb92293b14f70e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl-Petter=20=C3=85kesson?= Date: Thu, 14 May 2015 15:37:03 +0200 Subject: [PATCH 2/5] Fixed an issue with the Thursday abreviation as it did not follow the RFC-2616 standard; now Thursday is correctly abreviated to Thu --- DateStrings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DateStrings.cpp b/DateStrings.cpp index 48d55cf..489bb15 100644 --- a/DateStrings.cpp +++ b/DateStrings.cpp @@ -63,7 +63,7 @@ const PROGMEM char * const PROGMEM dayNames_P[] = dayStr0,dayStr1,dayStr2,dayStr3,dayStr4,dayStr5,dayStr6,dayStr7 }; -const char dayShortNames_P[] PROGMEM = "ErrSunMonTueWedThrFriSat"; +const char dayShortNames_P[] PROGMEM = "ErrSunMonTueWedThuFriSat"; /* functions to return date strings */ From 6a1664c1241c15ad5bca2b42e1a4a33f36ef4df0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl-Petter=20=C3=85kesson?= Date: Thu, 16 Jul 2015 11:52:55 +0200 Subject: [PATCH 3/5] Added method lastSyncTime to find out at what time the last successful time sync was achieved. --- Time.cpp | 8 +++++++- Time.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Time.cpp b/Time.cpp index 9e5b22d..64362d9 100644 --- a/Time.cpp +++ b/Time.cpp @@ -237,6 +237,7 @@ time_t makeTime(tmElements_t &tm){ static uint32_t sysTime = 0; static uint32_t prevMillis = 0; static uint32_t nextSyncTime = 0; +static uint32_t lastSyncTime = 0; static timeStatus_t Status = timeNotSet; getExternalTime getTimePtr; // pointer to external sync function @@ -281,7 +282,8 @@ void setTime(time_t t) { sysUnsyncedTime = t; // store the time of the first call to set a valid Time #endif - sysTime = (uint32_t)t; + sysTime = (uint32_t)t; + lastSyncTime = (uint32_t)t; nextSyncTime = (uint32_t)t + syncInterval; Status = timeSet; prevMillis = millis(); // restart counting from now (thanks to Korman for this fix) @@ -323,3 +325,7 @@ void setSyncInterval(time_t interval){ // set the number of seconds between re-s syncInterval = (uint32_t)interval; nextSyncTime = sysTime + syncInterval; } + +time_t getLastSyncTime(){ + return (time_t)lastSyncTime; +} \ No newline at end of file diff --git a/Time.h b/Time.h index 61519f7..341b867 100644 --- a/Time.h +++ b/Time.h @@ -133,6 +133,7 @@ char* dayShortStr(uint8_t day); timeStatus_t timeStatus(); // indicates if time has been set and recently synchronized void setSyncProvider( getExternalTime getTimeFunction); // identify the external time provider void setSyncInterval(time_t interval); // set the number of seconds between re-sync +time_t getLastSyncTime(); // get time when last successful sync was made /* low level functions to convert to and from system time */ void breakTime(time_t time, tmElements_t &tm); // break time_t into elements From 98250baaa1575d1ba4c7f616079bd7dec01d3c6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl-Petter=20=C3=85kesson?= Date: Fri, 24 Jul 2015 14:55:40 +0200 Subject: [PATCH 4/5] Added versioning information file as a hook and thus ignore the file it generates. --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6702033 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +version.h From c5ad833b189fada3194993a20473a497bb79cf2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl-Petter=20=C3=85kesson?= Date: Fri, 24 Jul 2015 14:57:55 +0200 Subject: [PATCH 5/5] Also added the version.h file so we can utilize the new versioning information --- Time.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Time.h b/Time.h index 341b867..21bda32 100644 --- a/Time.h +++ b/Time.h @@ -15,7 +15,7 @@ #ifndef __AVR__ #include // for __time_t_defined, but avr libc lacks sys/types.h #endif - +#include "version.h" #if !defined(__time_t_defined) // avoid conflict with newlib or other posix libc typedef unsigned long time_t;