A time interface class. This class replicates the normal time functions, but goes a couple of steps further. mbed library 82 and prior has a defective gmtime function. Also, this class enables access to setting the time, and adjusting the accuracy of the RTC.
Dependents: CI-data-logger-server WattEye X10Svr SSDP_Server
Diff: TimeInterface.h
- Revision:
- 2:65e0a25c7551
- Parent:
- 1:2ee90f546f54
- Child:
- 3:49f36b489b64
--- a/TimeInterface.h Sat Jun 14 12:34:53 2014 +0000 +++ b/TimeInterface.h Sun Jun 22 21:00:01 2014 +0000 @@ -3,6 +3,8 @@ #define TIMEINTERFACE_H #include "mbed.h" +#include "NTPClient.h" // ver 4 Donatien Garnier + // Special Registers and their usage: // GPREG0: 32 bits // low word: time zone offset (-720 to +720) @@ -180,9 +182,9 @@ /// should be the UTC time, which then permits gmtime and /// localtime to be used appropriately. /// - /// @param[in] t is the UTC time value to set the clock to. If the available + /// @param[in] t should be the UTC time value to set the clock to. If the available /// time value is local time, the optional time zone offset can - /// be provided. + /// be provided so the system clock is UTC. /// @param[in] tzo is the optional time zone offset in minutes when it is in /// the range of -720 to +720 (-12 hours to + 12 hours). Any /// other value is illegal and no change will be made. @@ -261,9 +263,19 @@ /// bool adjust_sec(int32_t adjustSeconds); - - // ntp interface functions - + /// Set the clock from an internet source (blocking) + /// + /// This function is the interface to NTPClient. + /// 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); + + // ntp interface functions private: char result[30]; // holds the converted to text time string time_t tresult; // holds the converted time structure.