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
Diff: NTPClient.cpp
- Revision:
- 6:240ec02c4bc3
- Parent:
- 5:76d570815832
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