NTP Client for the mbed networking libraries. The small change to this version is that there can be only one cause for the return value zero.
Fork of NTPClient by
Diff: NTPClient.h
- Revision:
- 8:802277794640
- Parent:
- 6:bef14adc58c4
- Child:
- 9:2f607bafc29e
diff -r 170915215fd4 -r 802277794640 NTPClient.h --- a/NTPClient.h Tue Jul 07 17:09:36 2015 +0000 +++ b/NTPClient.h Thu Nov 26 18:20:56 2015 +0000 @@ -36,13 +36,12 @@ #define NTP_DEFAULT_TIMEOUT 4000 ///NTP client results -enum NTPResult -{ - NTP_OK = 0, ///<Success - NTP_DNS, ///<Could not resolve name - NTP_PRTCL, ///<Protocol error - NTP_TIMEOUT, ///<Connection timeout - NTP_CONN, ///<Connection error +enum NTPResult { + NTP_OK = 0, ///<Success + NTP_DNS, ///<Could not resolve name + NTP_PRTCL, ///<Protocol error + NTP_TIMEOUT, ///<Connection timeout + NTP_CONN, ///<Connection error }; /** NTP Client to update the mbed's RTC using a remote time server @@ -51,51 +50,49 @@ class NTPClient { public: - /** - Instantiate the NTP client - */ - NTPClient(); + /** + Instantiate the NTP client + */ + NTPClient(); - /**Get current time (blocking) - Update the time using the server host - Blocks until completion - @param[in] host NTP server IPv4 address or hostname (will be resolved via DNS) - @param[in] port port to use; defaults to 123 - @param[in] timeout waiting timeout in ms (osWaitForever for blocking function, not recommended) - @return 0 on success, NTP error code (<0) on failure - */ - NTPResult setTime(const char* host, uint16_t port = NTP_DEFAULT_PORT, uint32_t timeout = NTP_DEFAULT_TIMEOUT); //Blocking + /**Get current time (blocking) + Update the time using the server host + Blocks until completion + @param[in] host NTP server IPv4 address or hostname (will be resolved via DNS) + @param[in] port port to use; defaults to 123 + @param[in] timeout waiting timeout in ms (osWaitForever for blocking function, not recommended) + @return 0 on success, NTP error code (<0) on failure + */ + NTPResult setTime(const char* host, uint16_t port = NTP_DEFAULT_PORT, uint32_t timeout = NTP_DEFAULT_TIMEOUT); //Blocking private: - struct NTPPacket //See RFC 4330 for Simple NTP - { - //WARN: We are in LE! Network is BE! - //LSb first - unsigned mode : 3; - unsigned vn : 3; - unsigned li : 2; + struct NTPPacket { //See RFC 4330 for Simple NTP + //WARN: We are in LE! Network is BE! + //LSb first + unsigned mode : 3; + unsigned vn : 3; + unsigned li : 2; - uint8_t stratum; - uint8_t poll; - uint8_t precision; - //32 bits header + uint8_t stratum; + uint8_t poll; + uint8_t precision; + //32 bits header - uint32_t rootDelay; - uint32_t rootDispersion; - uint32_t refId; + uint32_t rootDelay; + uint32_t rootDispersion; + uint32_t refId; - uint32_t refTm_s; - uint32_t refTm_f; - uint32_t origTm_s; - uint32_t origTm_f; - uint32_t rxTm_s; - uint32_t rxTm_f; - uint32_t txTm_s; - uint32_t txTm_f; - } __attribute__ ((packed)); - - UDPSocket m_sock; + uint32_t refTm_s; + uint32_t refTm_f; + uint32_t origTm_s; + uint32_t origTm_f; + uint32_t rxTm_s; + uint32_t rxTm_f; + uint32_t txTm_s; + uint32_t txTm_f; + } __attribute__ ((packed)); + UDPSocket m_sock; };