Fixed NTPResult values

Dependents:   NTPClient_HelloWorld_WIZ550io LPC11U68_NTPClient_HelloWorld_WIZ550io SNIC-ntpclient-example NTPClient_HelloWorld ... more

Fork of NTPClient by Donatien Garnier

Files at this revision

API Documentation at this revision

Comitter:
ban4jp
Date:
Sun Feb 01 13:43:49 2015 +0000
Parent:
5:c70ed0bfab2e
Commit message:
Fixed overflow. due to the negative offset value.

Changed in this revision

NTPClient.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r c70ed0bfab2e -r 15c04f752381 NTPClient.cpp
--- a/NTPClient.cpp	Sun Dec 22 13:59:33 2013 +0000
+++ b/NTPClient.cpp	Sun Feb 01 13:43:49 2015 +0000
@@ -146,11 +146,11 @@
 
   //Compute offset, see RFC 4330 p.13
   uint32_t destTm_s = (NTP_TIMESTAMP_DELTA + time(NULL));
-  int64_t offset = ( (int64_t)( pkt.rxTm_s - pkt.origTm_s ) + (int64_t) ( pkt.txTm_s - destTm_s ) ) / 2; //Avoid overflow
+  int64_t offset = ( ( (int64_t)pkt.rxTm_s - (int64_t)pkt.origTm_s ) + ( (int64_t)pkt.txTm_s - (int64_t)destTm_s ) ) / 2; //Avoid overflow
   DBG("Sent @%ul", pkt.txTm_s);
   DBG("Offset: %lld", offset);
   //Set time accordingly
-  set_time( time(NULL) + offset );
+  if(offset != 0) set_time( time(NULL) + offset );
 
 #ifdef __DEBUG__
   ctTime = time(NULL);