NTP Client for the mbed networking libraries
Dependents: WiFiDip-KitchenSink WiFiDip-UsbKitchenSink WiFiDipCortexSensor
Fork of NTPClient by
This is a temporary fork of NTPClient by Donatien Garnier
Revision 6:240ec02c4bc3, committed 2013-11-04
- Comitter:
- SolderSplashLabs
- Date:
- Mon Nov 04 19:49:02 2013 +0000
- Parent:
- 5:76d570815832
- Commit message:
- Added accessor for the collected time
Changed in this revision
NTPClient.cpp | Show annotated file Show diff for this revision Revisions of this file |
NTPClient.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 76d570815832 -r 240ec02c4bc3 NTPClient.cpp --- a/NTPClient.cpp Mon Oct 07 21:16:20 2013 +0000 +++ b/NTPClient.cpp Mon Nov 04 19:49:02 2013 +0000 @@ -44,11 +44,14 @@ #define NTP_CLIENT_PORT 0 //Random port #define NTP_TIMESTAMP_DELTA 2208988800ull //Diff btw a UNIX timestamp (Starting Jan, 1st 1970) and a NTP timestamp (Starting Jan, 1st 1900) +//uint32_t LastNtpResult = 0; + NTPClient::NTPClient() : m_sock() { +} -} + NTPResult NTPClient::setTime(const char* host, uint16_t port, uint32_t timeout) { @@ -146,6 +149,7 @@ //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 + NTPLastResult = offset; DBG("Sent @%ul", pkt.txTm_s); DBG("Offset: %lld", offset); //Set time accordingly
diff -r 76d570815832 -r 240ec02c4bc3 NTPClient.h --- a/NTPClient.h Mon Oct 07 21:16:20 2013 +0000 +++ b/NTPClient.h Mon Nov 04 19:49:02 2013 +0000 @@ -55,6 +55,8 @@ Instantiate the NTP client */ NTPClient(); + + uint32_t NTPLastResult; /**Get current time (blocking) Update the time using the server host