2 /* Copyright (C) 2012 mbed.org, MIT License
4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
8 * furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice shall be included in all copies or
11 * substantial portions of the Software.
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 NTP Client header file
27 #include "UDPSocket.h"
29 #define NTP_DEFAULT_PORT 123
30 #define NTP_DEFAULT_TIMEOUT 4000
35 NTP_DNS, ///<Could not resolve name
36 NTP_PRTCL, ///<Protocol error
37 NTP_TIMEOUT, ///<Connection timeout
38 NTP_CONN, ///<Connection error
39 NTP_OK = 0, ///<Success
42 /** NTP Client to update the mbed's RTC using a remote time server
49 Instantiate the NTP client
53 /**Get current time (blocking)
54 Update the time using the server host
55 Blocks until completion
56 @param host NTP server IPv4 address or hostname (will be resolved via DNS)
57 @param port port to use; defaults to 123
58 @param timeout waiting timeout in ms (osWaitForever for blocking function, not recommended)
59 @return 0 on success, NTP error code (<0) on failure
61 NTPResult setTime(const char* host, uint16_t port = NTP_DEFAULT_PORT, uint32_t timeout = NTP_DEFAULT_TIMEOUT); //Blocking
64 #if defined (__ICCARM__)
67 struct NTPPacket //See RFC 4330 for Simple NTP
69 //WARN: We are in LE! Network is BE!
81 uint32_t rootDispersion;
92 #if defined (__ICCARM__)
95 } __attribute__ ((packed));
101 #endif /* NTPCLIENT_H_ */