Simple time management w/o the Network interface

Committer:
WiredHome
Date:
Thu Apr 30 14:38:57 2020 +0000
Revision:
1:b78c91e34eda
Parent:
0:e8e62dfee5eb
Code cleanup

Who changed what in which revision?

UserRevisionLine numberNew contents of line
WiredHome 0:e8e62dfee5eb 1
WiredHome 0:e8e62dfee5eb 2 #ifndef TIMEINTERFACE_H
WiredHome 0:e8e62dfee5eb 3 #define TIMEINTERFACE_H
WiredHome 0:e8e62dfee5eb 4 #include "mbed.h"
WiredHome 0:e8e62dfee5eb 5 #include <ctime>
WiredHome 0:e8e62dfee5eb 6
WiredHome 0:e8e62dfee5eb 7 //#include "NTPClient.h"
WiredHome 0:e8e62dfee5eb 8
WiredHome 0:e8e62dfee5eb 9 // Special Registers and their usage:
WiredHome 0:e8e62dfee5eb 10 // GPREG0: 32 bits
WiredHome 0:e8e62dfee5eb 11 // low word: time zone offset (-720 to +720)
WiredHome 0:e8e62dfee5eb 12 // high word: 2's complement of low word for integrity checking
WiredHome 0:e8e62dfee5eb 13 // GPREG1: 32 bits
WiredHome 0:e8e62dfee5eb 14 // time_t value when the clock was last set
WiredHome 0:e8e62dfee5eb 15
WiredHome 0:e8e62dfee5eb 16
WiredHome 0:e8e62dfee5eb 17 extern "C" {
WiredHome 0:e8e62dfee5eb 18 #include "time.h" // uses some std::time-functions
WiredHome 0:e8e62dfee5eb 19 }
WiredHome 0:e8e62dfee5eb 20
WiredHome 0:e8e62dfee5eb 21 /// The tm_ex structure is patterned after the traditional tm struct, however
WiredHome 0:e8e62dfee5eb 22 /// it adds an element - the time zone offset in minutes. From this, it is then
WiredHome 0:e8e62dfee5eb 23 /// readily able to create a "local time" instead of simply a UTC time.
WiredHome 0:e8e62dfee5eb 24 ///
WiredHome 0:e8e62dfee5eb 25 struct tm_ex
WiredHome 0:e8e62dfee5eb 26 {
WiredHome 0:e8e62dfee5eb 27 int tm_sec; ///<! seconds, 0 to 59.
WiredHome 0:e8e62dfee5eb 28 int tm_min; ///<! minutes, 0 to 59.
WiredHome 0:e8e62dfee5eb 29 int tm_hour; ///<! hours, 0 to 23.
WiredHome 0:e8e62dfee5eb 30 int tm_mday; ///<! monthday 1 to 31.
WiredHome 0:e8e62dfee5eb 31 int tm_mon; ///<! month 0 to 11.
WiredHome 0:e8e62dfee5eb 32 int tm_year; ///<! years since 1900.
WiredHome 0:e8e62dfee5eb 33 int tm_wday; ///<! days since sunday 0 to 6.
WiredHome 0:e8e62dfee5eb 34 int tm_yday; ///<! days since 1 Jan 0 to 365.
WiredHome 0:e8e62dfee5eb 35 int tm_isdst; ///<! is daylight savings time.
WiredHome 0:e8e62dfee5eb 36 int tm_tzo_min; ///<! localtime zone offset in minutes (_ex element)
WiredHome 0:e8e62dfee5eb 37 };
WiredHome 0:e8e62dfee5eb 38
WiredHome 0:e8e62dfee5eb 39 /// TimeInterface class is much like the normal c-style time.h interface, but
WiredHome 0:e8e62dfee5eb 40 /// is extended with time-zone support, and clock-adjustment support (which
WiredHome 0:e8e62dfee5eb 41 /// permits tuning the clock) for more accuracy.
WiredHome 0:e8e62dfee5eb 42 ///
WiredHome 0:e8e62dfee5eb 43 /// Additionally, strptime was integrated, which can extract the time from
WiredHome 0:e8e62dfee5eb 44 /// a text string. A formatter is used, so it cannot parse an arbitrary string.
WiredHome 0:e8e62dfee5eb 45 ///
WiredHome 0:e8e62dfee5eb 46 /// Within this class are the normal time.h methods, simply
WiredHome 0:e8e62dfee5eb 47 /// exposed here for one consistent interface.
WiredHome 0:e8e62dfee5eb 48 ///
WiredHome 0:e8e62dfee5eb 49 /// @note This class uses the special battery backed registers
WiredHome 0:e8e62dfee5eb 50 /// GPREG0 and GPREG1 for TimeInterface data.
WiredHome 0:e8e62dfee5eb 51 ///
WiredHome 0:e8e62dfee5eb 52 /// @note In mbed library ver 84, the gmtime method is defective,
WiredHome 0:e8e62dfee5eb 53 /// and calls to this function return junk data. The
WiredHome 0:e8e62dfee5eb 54 /// gmtime method in this library actually uses localtime,
WiredHome 0:e8e62dfee5eb 55 /// but manages the time-zone offset as it does so.
WiredHome 0:e8e62dfee5eb 56 ///
WiredHome 0:e8e62dfee5eb 57 /// @code
WiredHome 0:e8e62dfee5eb 58 /// // TimeInterface Architecture and APIs
WiredHome 0:e8e62dfee5eb 59 /// //
WiredHome 0:e8e62dfee5eb 60 /// // +--------+
WiredHome 0:e8e62dfee5eb 61 /// // | clock |----> clock_t clock()
WiredHome 0:e8e62dfee5eb 62 /// // +--------+
WiredHome 0:e8e62dfee5eb 63 /// //
WiredHome 0:e8e62dfee5eb 64 /// // +--------+
WiredHome 0:e8e62dfee5eb 65 /// // | |<------------ setTime(char * server, uint16_t port, uint32_t timeout)
WiredHome 0:e8e62dfee5eb 66 /// // | NTP |<-----------> Ethernet
WiredHome 0:e8e62dfee5eb 67 /// // | |----+
WiredHome 0:e8e62dfee5eb 68 /// // +--------+ |
WiredHome 0:e8e62dfee5eb 69 /// // |
WiredHome 0:e8e62dfee5eb 70 /// // +--------+ |
WiredHome 0:e8e62dfee5eb 71 /// // | RTC |<---+-------- set_time(time_t t, int16_t tzo)
WiredHome 0:e8e62dfee5eb 72 /// // | |<------------ adjust_sec(int32_t)
WiredHome 0:e8e62dfee5eb 73 /// // | |<------------ set_cal(int32_t)
WiredHome 0:e8e62dfee5eb 74 /// // | |------------> int32_t get_cal()
WiredHome 0:e8e62dfee5eb 75 /// // | |------------> time_t time(time_t *)
WiredHome 0:e8e62dfee5eb 76 /// // | |------+
WiredHome 0:e8e62dfee5eb 77 /// // +--------+ |
WiredHome 0:e8e62dfee5eb 78 /// // |
WiredHome 0:e8e62dfee5eb 79 /// // +--------+ |
WiredHome 0:e8e62dfee5eb 80 /// // | |<---- | <---- set_dst(bool dst)
WiredHome 0:e8e62dfee5eb 81 /// // | |<---- | <---- set_dst(char * start_dst, char * end_dst)
WiredHome 0:e8e62dfee5eb 82 /// // | |----- | ----> bool get_dst()
WiredHome 0:e8e62dfee5eb 83 /// // |dst_pair|---+ | +----------+
WiredHome 0:e8e62dfee5eb 84 /// // +--------+ | | | |
WiredHome 0:e8e62dfee5eb 85 /// // | +->| |
WiredHome 0:e8e62dfee5eb 86 /// // +--------+ +---->|time_local|--------> time_t timelocal(time_t *)
WiredHome 0:e8e62dfee5eb 87 /// // | tzo |<--------| |
WiredHome 0:e8e62dfee5eb 88 /// // | | +----------+
WiredHome 0:e8e62dfee5eb 89 /// // | |<------------ set_tzo_min(int16_t)
WiredHome 0:e8e62dfee5eb 90 /// // | |------------> int16_t get_tzo_min()
WiredHome 0:e8e62dfee5eb 91 /// // +--------+
WiredHome 0:e8e62dfee5eb 92 /// //
WiredHome 0:e8e62dfee5eb 93 /// // +--------+ +--------------------------+
WiredHome 0:e8e62dfee5eb 94 /// // | time_t | ---> char * ctime(time_t *) ----> | buffer |
WiredHome 0:e8e62dfee5eb 95 /// // | value | | Www Mmm dd hh:mm:ss yyyy |
WiredHome 0:e8e62dfee5eb 96 /// // +--------+ +- char * asctime(tm_ex *) -> +--------------------------+
WiredHome 0:e8e62dfee5eb 97 /// // ^ | |
WiredHome 0:e8e62dfee5eb 98 /// // | | | +-----------------+
WiredHome 0:e8e62dfee5eb 99 /// // | | +-------------------------------- | tm_ex |
WiredHome 0:e8e62dfee5eb 100 /// // | | | .tm_sec |
WiredHome 0:e8e62dfee5eb 101 /// // | +- tm_ex * gmtime(const time_t *) -----> | .tm_min |
WiredHome 0:e8e62dfee5eb 102 /// // | | | .tm_hour |
WiredHome 0:e8e62dfee5eb 103 /// // | +- tm_ex * localtime(const time_t *) --> | .tm_mday |
WiredHome 0:e8e62dfee5eb 104 /// // | | .tm_mon |
WiredHome 0:e8e62dfee5eb 105 /// // +---- time_t mktime(struct tm_ex *) ------- | .tm_year |
WiredHome 0:e8e62dfee5eb 106 /// // | .tm_wday |
WiredHome 0:e8e62dfee5eb 107 /// // | .tm_yday |
WiredHome 0:e8e62dfee5eb 108 /// // +---------------------------------------------> | .tm_isdst |
WiredHome 0:e8e62dfee5eb 109 /// // | +-------------------------------------------- | .tm_tzo_min |
WiredHome 0:e8e62dfee5eb 110 /// // | | +-----------------+
WiredHome 0:e8e62dfee5eb 111 /// // | | +--------------------------+
WiredHome 0:e8e62dfee5eb 112 /// // | +- strftime(char * ptr, ..., tm_ex *) --> | buffer |
WiredHome 0:e8e62dfee5eb 113 /// // +----strptime(char * buf, ..., tm_ex *) --- | Www Mmm dd hh:mm:ss yyyy |
WiredHome 0:e8e62dfee5eb 114 /// // +--------------------------+
WiredHome 0:e8e62dfee5eb 115 /// // double difftime(time_t end, time_t)
WiredHome 0:e8e62dfee5eb 116 /// //
WiredHome 0:e8e62dfee5eb 117 /// @endcode
WiredHome 0:e8e62dfee5eb 118 ///
WiredHome 0:e8e62dfee5eb 119 class TimeInterface
WiredHome 0:e8e62dfee5eb 120 {
WiredHome 0:e8e62dfee5eb 121 public:
WiredHome 0:e8e62dfee5eb 122 /// Constructor for the TimeInterface class, which does minimal initialization.
WiredHome 0:e8e62dfee5eb 123 ///
WiredHome 0:e8e62dfee5eb 124 /// @param[in] net is optional and provides the EthernetInterface which is
WiredHome 0:e8e62dfee5eb 125 /// used if you want to sync to an NTP server
WiredHome 0:e8e62dfee5eb 126 ///
WiredHome 0:e8e62dfee5eb 127 /// @code
WiredHome 0:e8e62dfee5eb 128 /// EthernetInterface net;
WiredHome 0:e8e62dfee5eb 129 /// TimeInterface ntp(&net);
WiredHome 0:e8e62dfee5eb 130 /// ...
WiredHome 0:e8e62dfee5eb 131 /// ntp.set_tzo_min(-6 * 60);
WiredHome 0:e8e62dfee5eb 132 /// if (NTP_OK == ntp.setTime("time.nist.gov", 123, 10)) {
WiredHome 0:e8e62dfee5eb 133 /// time_t tNow = ntp.timelocal();
WiredHome 0:e8e62dfee5eb 134 /// printf("time is %s\r\n", ntp.ctime(&tNow));
WiredHome 0:e8e62dfee5eb 135 /// }
WiredHome 0:e8e62dfee5eb 136 /// ...
WiredHome 0:e8e62dfee5eb 137 /// @endcode
WiredHome 0:e8e62dfee5eb 138 ///
WiredHome 0:e8e62dfee5eb 139 TimeInterface(void *m_net = NULL);
WiredHome 0:e8e62dfee5eb 140
WiredHome 0:e8e62dfee5eb 141 /// Destructor, normally not used, because it is typically kept for the life
WiredHome 0:e8e62dfee5eb 142 /// of the program.
WiredHome 0:e8e62dfee5eb 143 ///
WiredHome 0:e8e62dfee5eb 144 ~TimeInterface();
WiredHome 0:e8e62dfee5eb 145
WiredHome 0:e8e62dfee5eb 146 /// Gets the system elapsed time in CLOCKS_PER_SEC tics.
WiredHome 0:e8e62dfee5eb 147 ///
WiredHome 0:e8e62dfee5eb 148 /// Divide the returned value by CLOCKS_PER_SEC to get time in seconds.
WiredHome 0:e8e62dfee5eb 149 ///
WiredHome 0:e8e62dfee5eb 150 /// @code
WiredHome 0:e8e62dfee5eb 151 /// clock_t tstart, tend;
WiredHome 0:e8e62dfee5eb 152 /// ...
WiredHome 0:e8e62dfee5eb 153 /// tstart = clock();
WiredHome 0:e8e62dfee5eb 154 /// // do something long
WiredHome 0:e8e62dfee5eb 155 /// tend = clock();
WiredHome 0:e8e62dfee5eb 156 /// printf("Elapsed time is %5.3f\r\n", (float)(tend - tstart)/CLOCKS_PER_SEC);
WiredHome 0:e8e62dfee5eb 157 /// ...
WiredHome 0:e8e62dfee5eb 158 /// @endcode
WiredHome 0:e8e62dfee5eb 159 ///
WiredHome 0:e8e62dfee5eb 160 /// @returns elapsed tics.
WiredHome 0:e8e62dfee5eb 161 ///
WiredHome 0:e8e62dfee5eb 162 clock_t clock(void);
WiredHome 0:e8e62dfee5eb 163
WiredHome 0:e8e62dfee5eb 164 /// Gets the current time as a UTC time value, optionally writing it
WiredHome 0:e8e62dfee5eb 165 /// to a provided buffer.
WiredHome 0:e8e62dfee5eb 166 ///
WiredHome 0:e8e62dfee5eb 167 /// This reads the real time clock and returns the current UTC time.
WiredHome 0:e8e62dfee5eb 168 ///
WiredHome 0:e8e62dfee5eb 169 /// @code
WiredHome 0:e8e62dfee5eb 170 /// time_t t_ref1, t_ref2, t_ref3;
WiredHome 0:e8e62dfee5eb 171 /// t_ref1 = time(NULL);
WiredHome 0:e8e62dfee5eb 172 /// t_ref2 = t.time();
WiredHome 0:e8e62dfee5eb 173 /// (void)t.time(&t_ref3);
WiredHome 0:e8e62dfee5eb 174 /// @endcode
WiredHome 0:e8e62dfee5eb 175 ///
WiredHome 0:e8e62dfee5eb 176 /// @param[out] timer is an optional pointer to a time_t value that will
WiredHome 0:e8e62dfee5eb 177 /// be written with the current time. This pointer is ignored
WiredHome 0:e8e62dfee5eb 178 /// when NULL.
WiredHome 0:e8e62dfee5eb 179 /// @returns the UTC time value.
WiredHome 0:e8e62dfee5eb 180 ///
WiredHome 0:e8e62dfee5eb 181 time_t time(time_t * timer = NULL);
WiredHome 0:e8e62dfee5eb 182
WiredHome 0:e8e62dfee5eb 183 /// Gets the current time as a LOCAL time value, optionally writing it
WiredHome 0:e8e62dfee5eb 184 /// to a provided buffer.
WiredHome 0:e8e62dfee5eb 185 ///
WiredHome 0:e8e62dfee5eb 186 /// This reads the real time clock and returns the current time, adjusted
WiredHome 0:e8e62dfee5eb 187 /// for the local time zone and daylight savings time.
WiredHome 0:e8e62dfee5eb 188 ///
WiredHome 0:e8e62dfee5eb 189 /// @code
WiredHome 0:e8e62dfee5eb 190 /// time_t t_ref2, t_ref3;
WiredHome 0:e8e62dfee5eb 191 /// t_ref2 = t.time();
WiredHome 0:e8e62dfee5eb 192 /// t.timelocal(&t_ref3);
WiredHome 0:e8e62dfee5eb 193 /// @endcode
WiredHome 0:e8e62dfee5eb 194 ///
WiredHome 0:e8e62dfee5eb 195 /// @param[out] timer is an optional pointer to a time_t value that will
WiredHome 0:e8e62dfee5eb 196 /// be written. This pointer is ignored when NULL.
WiredHome 0:e8e62dfee5eb 197 /// @returns the LOCAL time value (UTC adjusted for the LOCAL time zone and dst).
WiredHome 0:e8e62dfee5eb 198 ///
WiredHome 0:e8e62dfee5eb 199 time_t timelocal(time_t * timer = NULL);
WiredHome 0:e8e62dfee5eb 200
WiredHome 0:e8e62dfee5eb 201 /// Convert a time value structure into an ASCII printable time "Www Mmm dd hh:mm:ss yyyy"
WiredHome 0:e8e62dfee5eb 202 ///
WiredHome 0:e8e62dfee5eb 203 /// @note Watch out for race conditions as this returns a pointer to a
WiredHome 0:e8e62dfee5eb 204 /// shared buffer.
WiredHome 0:e8e62dfee5eb 205 /// @note Unlike the standard ctime function, this version DOES NOT append
WiredHome 0:e8e62dfee5eb 206 /// a newline character to the buffer.
WiredHome 0:e8e62dfee5eb 207 ///
WiredHome 0:e8e62dfee5eb 208 /// @code
WiredHome 0:e8e62dfee5eb 209 /// time_t tNow = timelocal();
WiredHome 0:e8e62dfee5eb 210 /// printf("time is %s\r\n", ctime(tNow));
WiredHome 0:e8e62dfee5eb 211 /// @endcode
WiredHome 0:e8e62dfee5eb 212 ///
WiredHome 0:e8e62dfee5eb 213 /// @param[in] timer is a pointer to a time_t value containing the time to convert.
WiredHome 0:e8e62dfee5eb 214 /// @returns a pointer to a buffer containing the string.
WiredHome 0:e8e62dfee5eb 215 ///
WiredHome 0:e8e62dfee5eb 216 char * ctime(const time_t * timer);
WiredHome 0:e8e62dfee5eb 217
WiredHome 0:e8e62dfee5eb 218 /// Convert a tm_ex structure into an ASCII printable "time Www Mmm dd hh:mm:ss yyyy"
WiredHome 0:e8e62dfee5eb 219 ///
WiredHome 0:e8e62dfee5eb 220 /// @note Unlike the standard asctime, this takes a pointer to a tm_ex, which
WiredHome 0:e8e62dfee5eb 221 /// has daylight savings time flag and a time zone offset element.
WiredHome 0:e8e62dfee5eb 222 ///
WiredHome 0:e8e62dfee5eb 223 /// @note Watch out for race conditions as this returns a pointer to a
WiredHome 0:e8e62dfee5eb 224 /// shared buffer.
WiredHome 0:e8e62dfee5eb 225 ///
WiredHome 0:e8e62dfee5eb 226 /// @note Unlike the standard ctime function, this version DOES NOT append
WiredHome 0:e8e62dfee5eb 227 /// a newline character to the buffer.
WiredHome 0:e8e62dfee5eb 228 ///
WiredHome 0:e8e62dfee5eb 229 /// @code
WiredHome 0:e8e62dfee5eb 230 /// time_t tNow = timelocal();
WiredHome 0:e8e62dfee5eb 231 /// tm_ex * tEx = localtime(&tNow);
WiredHome 0:e8e62dfee5eb 232 /// printf("Time is %s\r\n", asctime(tEx));
WiredHome 0:e8e62dfee5eb 233 /// @endcode
WiredHome 0:e8e62dfee5eb 234 ///
WiredHome 0:e8e62dfee5eb 235 /// @param[in] timeptr is a pointer to a tm_ex structure containing the time to convert.
WiredHome 0:e8e62dfee5eb 236 /// @returns a pointer to a private buffer containing the string.
WiredHome 0:e8e62dfee5eb 237 ///
WiredHome 0:e8e62dfee5eb 238 char * asctime(const struct tm_ex *timeptr);
WiredHome 0:e8e62dfee5eb 239
WiredHome 0:e8e62dfee5eb 240 /// Compute the difference in seconds between two time values.
WiredHome 0:e8e62dfee5eb 241 ///
WiredHome 0:e8e62dfee5eb 242 /// @code
WiredHome 0:e8e62dfee5eb 243 /// time_t tstart, tend;
WiredHome 0:e8e62dfee5eb 244 /// ...
WiredHome 0:e8e62dfee5eb 245 /// tstart = time();
WiredHome 0:e8e62dfee5eb 246 /// // do some long process now
WiredHome 0:e8e62dfee5eb 247 /// tend = time();
WiredHome 0:e8e62dfee5eb 248 /// printf("Elapsed time is %5.3f\r\n", tend - tstart);
WiredHome 0:e8e62dfee5eb 249 /// ...
WiredHome 0:e8e62dfee5eb 250 /// @endcode
WiredHome 0:e8e62dfee5eb 251 ///
WiredHome 0:e8e62dfee5eb 252 /// @param[in] end is the end time to compare to the beginning time.
WiredHome 0:e8e62dfee5eb 253 /// @param[in] beginning time is compared to the end time.
WiredHome 0:e8e62dfee5eb 254 /// @return the difference in seconds, as a double.
WiredHome 0:e8e62dfee5eb 255 ///
WiredHome 0:e8e62dfee5eb 256 double difftime(time_t end, time_t beginning);
WiredHome 0:e8e62dfee5eb 257
WiredHome 0:e8e62dfee5eb 258 /// Convert the referenced time_t value to a tm_ex structure in UTC/GMT format.
WiredHome 0:e8e62dfee5eb 259 ///
WiredHome 0:e8e62dfee5eb 260 /// @note Unlike the standard asctime, this return a pointer to a tm_ex, which
WiredHome 0:e8e62dfee5eb 261 /// has a time zone offset element.
WiredHome 0:e8e62dfee5eb 262 ///
WiredHome 0:e8e62dfee5eb 263 /// @note Watch out for race conditions as this returns a pointer to a
WiredHome 0:e8e62dfee5eb 264 /// shared buffer.
WiredHome 0:e8e62dfee5eb 265 ///
WiredHome 0:e8e62dfee5eb 266 /// @param[in] timer is a pointer to a time_t structure to convert.
WiredHome 0:e8e62dfee5eb 267 /// @returns pointer to a tm_ex structure.
WiredHome 0:e8e62dfee5eb 268 ///
WiredHome 0:e8e62dfee5eb 269 struct tm_ex * gmtime(const time_t * timer);
WiredHome 0:e8e62dfee5eb 270
WiredHome 0:e8e62dfee5eb 271
WiredHome 0:e8e62dfee5eb 272 /// Convert the referenced time_t value to a tm structure in local format.
WiredHome 0:e8e62dfee5eb 273 ///
WiredHome 0:e8e62dfee5eb 274 /// This method leverages the time zone offset applied with @see set_tzo()
WiredHome 0:e8e62dfee5eb 275 /// and the daylight savings time flag applied with @see set_dst().
WiredHome 0:e8e62dfee5eb 276 ///
WiredHome 0:e8e62dfee5eb 277 /// @note Watch out for race conditions as this returns a pointer to a
WiredHome 0:e8e62dfee5eb 278 /// shared buffer.
WiredHome 0:e8e62dfee5eb 279 ///
WiredHome 0:e8e62dfee5eb 280 /// @code
WiredHome 0:e8e62dfee5eb 281 /// time_t tNow = timelocal();
WiredHome 0:e8e62dfee5eb 282 /// tm_ex * tEx = localtime(&tNow);
WiredHome 0:e8e62dfee5eb 283 /// @endcode
WiredHome 0:e8e62dfee5eb 284 ///
WiredHome 0:e8e62dfee5eb 285 /// @param[in] timer is a pointer to a time_t structure to convert.
WiredHome 0:e8e62dfee5eb 286 /// @returns pointer to a tm structure.
WiredHome 0:e8e62dfee5eb 287 ///
WiredHome 0:e8e62dfee5eb 288 struct tm_ex * localtime(const time_t * timer);
WiredHome 0:e8e62dfee5eb 289
WiredHome 0:e8e62dfee5eb 290 /// Convert a tm_ex structure (an extended time structure) to a time_t
WiredHome 0:e8e62dfee5eb 291 /// value.
WiredHome 0:e8e62dfee5eb 292 ///
WiredHome 0:e8e62dfee5eb 293 /// This function also sets the tzo_min element of the tm_ex structure
WiredHome 0:e8e62dfee5eb 294 /// from the previously set tzo_min.
WiredHome 0:e8e62dfee5eb 295 ///
WiredHome 0:e8e62dfee5eb 296 /// @param[in] timeptr is a pointer to a tm_ex structure.
WiredHome 0:e8e62dfee5eb 297 /// @returns the computed time_t value.
WiredHome 0:e8e62dfee5eb 298 ///
WiredHome 0:e8e62dfee5eb 299 time_t mktime(struct tm_ex * timeptr);
WiredHome 0:e8e62dfee5eb 300
WiredHome 0:e8e62dfee5eb 301 /// Presents a time value in a user specified format, into a user specified buffer.
WiredHome 0:e8e62dfee5eb 302 ///
WiredHome 0:e8e62dfee5eb 303 /// @param[out] ptr is a pointer to the user buffer.
WiredHome 0:e8e62dfee5eb 304 /// @param[in] maxsize is the size of the user buffer.
WiredHome 0:e8e62dfee5eb 305 /// @param[in] format is a pointer to the special strftime format specification.
WiredHome 0:e8e62dfee5eb 306 /// see format options.
WiredHome 0:e8e62dfee5eb 307 /// @param[in] timeptr is a pointer to the tm_ex structure.
WiredHome 0:e8e62dfee5eb 308 /// @returns the total number of characters copied into the buffer.
WiredHome 0:e8e62dfee5eb 309 ///
WiredHome 0:e8e62dfee5eb 310 /// format options:
WiredHome 0:e8e62dfee5eb 311 /// - %%a Abbreviated weekday name e.g. Thu
WiredHome 0:e8e62dfee5eb 312 /// - %%A Full weekday name e.g. Thursday
WiredHome 0:e8e62dfee5eb 313 /// - %%b Abbreviated month name e.g. Aug
WiredHome 0:e8e62dfee5eb 314 /// - %%B Full month name e.g. August
WiredHome 0:e8e62dfee5eb 315 /// - %%c Date and time representation e.g. Thu Aug 23 14:55:02 2001
WiredHome 0:e8e62dfee5eb 316 /// - %%C Year divided by 100 and truncated to integer (00-99) e.g. 20
WiredHome 0:e8e62dfee5eb 317 /// - %%d Day of the month, zero-padded (01-31) e.g. 23
WiredHome 0:e8e62dfee5eb 318 /// - %%D Short MM/DD/YY date, equivalent to %%m/%%d/%%y e.g. 08/23/01
WiredHome 0:e8e62dfee5eb 319 /// - %%e Day of the month, space-padded ( 1-31) e.g. 23
WiredHome 0:e8e62dfee5eb 320 /// - %%F Short YYYY-MM-DD date, equivalent to %%Y-%%m-%%d e.g. 2001-08-23
WiredHome 0:e8e62dfee5eb 321 /// - %%g Week-based year, last two digits (00-99) e.g. 01
WiredHome 0:e8e62dfee5eb 322 /// - %%G Week-based year e.g. 2001
WiredHome 0:e8e62dfee5eb 323 /// - %%h Abbreviated month name * (same as %%b) e.g. Aug
WiredHome 0:e8e62dfee5eb 324 /// - %%H Hour in 24h format (00-23) e.g. 14
WiredHome 0:e8e62dfee5eb 325 /// - %%I Hour in 12h format (01-12) e.g. 02
WiredHome 0:e8e62dfee5eb 326 /// - %%j Day of the year (001-366) e.g. 235
WiredHome 0:e8e62dfee5eb 327 /// - %%m Month as a decimal number (01-12) e.g. 08
WiredHome 0:e8e62dfee5eb 328 /// - %%M Minute (00-59) e.g. 55
WiredHome 0:e8e62dfee5eb 329 /// - %%n New-line character ('\\n')
WiredHome 0:e8e62dfee5eb 330 /// - %%p AM or PM designation e.g. PM
WiredHome 0:e8e62dfee5eb 331 /// - %%r 12-hour clock time e.g. 02:55:02 pm
WiredHome 0:e8e62dfee5eb 332 /// - %%R 24-hour HH:MM time, equivalent to %%H:%%M e.g. 14:55
WiredHome 0:e8e62dfee5eb 333 /// - %%S Second (00-61) e.g. 02
WiredHome 0:e8e62dfee5eb 334 /// - %%t Horizontal-tab character ('\t')
WiredHome 0:e8e62dfee5eb 335 /// - %%T ISO 8601 time format (HH:MM:SS), equivalent to %%H:%%M:%%S e.g. 14:55:02
WiredHome 0:e8e62dfee5eb 336 /// - %%u ISO 8601 weekday as number with Monday as 1 (1-7) e.g. 4
WiredHome 0:e8e62dfee5eb 337 /// - %%U Week number with the first Sunday as the first day of week one (00-53) e.g. 33
WiredHome 0:e8e62dfee5eb 338 /// - %%V ISO 8601 week number (00-53) e.g. 34
WiredHome 0:e8e62dfee5eb 339 /// - %%w Weekday as a decimal number with Sunday as 0 (0-6) e.g. 4
WiredHome 0:e8e62dfee5eb 340 /// - %%W Week number with the first Monday as the first day of week one (00-53) e.g. 34
WiredHome 0:e8e62dfee5eb 341 /// - %%x Date representation e.g. 08/23/01
WiredHome 0:e8e62dfee5eb 342 /// - %%X Time representation e.g. 14:55:02
WiredHome 0:e8e62dfee5eb 343 /// - %%y Year, last two digits (00-99) e.g. 01
WiredHome 0:e8e62dfee5eb 344 /// - %%Y Year e.g. 2001
WiredHome 0:e8e62dfee5eb 345 /// - %%z ISO 8601 offset from UTC in timezone (1 minute=1, 1 hour=100) (e.g. +100)
WiredHome 0:e8e62dfee5eb 346 /// If timezone cannot be determined, no characters
WiredHome 0:e8e62dfee5eb 347 /// - %%Z Timezone name or abbreviation (e.g. CDT)
WiredHome 0:e8e62dfee5eb 348 /// If timezone cannot be determined, no characters
WiredHome 0:e8e62dfee5eb 349 /// - % A % sign
WiredHome 0:e8e62dfee5eb 350 ///
WiredHome 0:e8e62dfee5eb 351 size_t strftime(char * ptr, size_t maxsize, const char * format, const struct tm_ex * timeptr);
WiredHome 0:e8e62dfee5eb 352
WiredHome 0:e8e62dfee5eb 353
WiredHome 0:e8e62dfee5eb 354 /// Convert a string, in a defined format, to a time value in a tm_ex structure.
WiredHome 0:e8e62dfee5eb 355 ///
WiredHome 0:e8e62dfee5eb 356 /// Most format details leveraged from The Open Group Base Specifications Issue 6
WiredHome 0:e8e62dfee5eb 357 /// IEEE Std 1003.1, 2004 Edition
WiredHome 0:e8e62dfee5eb 358 /// Copyright © 2001-2004 The IEEE and The Open Group, All Rights reserved.
WiredHome 0:e8e62dfee5eb 359 ///
WiredHome 0:e8e62dfee5eb 360 /// Modifications for mbed, and addition of the timezone format option by D. Smart
WiredHome 0:e8e62dfee5eb 361 ///
WiredHome 0:e8e62dfee5eb 362 /// @code
WiredHome 0:e8e62dfee5eb 363 /// char timesample[] = "Jan 22 2017 01:32:48 UTC";
WiredHome 0:e8e62dfee5eb 364 /// tm_ex tm;
WiredHome 0:e8e62dfee5eb 365 /// strptime(timesample, "%b %d %Y %H:%M:%S %Z", &tm);
WiredHome 0:e8e62dfee5eb 366 /// @endcode
WiredHome 0:e8e62dfee5eb 367 ///
WiredHome 0:e8e62dfee5eb 368 /// @param[in] buf is a pointer to the string to be parsed.
WiredHome 0:e8e62dfee5eb 369 /// @param[in] format is a pointer to a format string. See the format options.
WiredHome 0:e8e62dfee5eb 370 /// @param[out] tm is a pointer to a tm_ex struct.
WiredHome 0:e8e62dfee5eb 371 /// @returns a pointer to the character following the last one parsed, or null on failure
WiredHome 0:e8e62dfee5eb 372 ///
WiredHome 0:e8e62dfee5eb 373 /// format options:
WiredHome 0:e8e62dfee5eb 374 /// - %%a The day of the week, using the locale's weekday names; either the abbreviated or
WiredHome 0:e8e62dfee5eb 375 /// full name may be specified.
WiredHome 0:e8e62dfee5eb 376 /// - %%A Equivalent to %%a.
WiredHome 0:e8e62dfee5eb 377 /// - %%b The month, using the locale's month names; either the abbreviated or full name
WiredHome 0:e8e62dfee5eb 378 /// may be specified.
WiredHome 0:e8e62dfee5eb 379 /// - %%B Equivalent to %%b.
WiredHome 0:e8e62dfee5eb 380 /// - %%c Replaced by the locale's appropriate date and time representation.
WiredHome 0:e8e62dfee5eb 381 /// - %%C The century number [00,99]; leading zeros are permitted but not required.
WiredHome 0:e8e62dfee5eb 382 /// - %%d The day of the month [01,31]; leading zeros are permitted but not required.
WiredHome 0:e8e62dfee5eb 383 /// - %%D The date as %%m / %%d / %%y.
WiredHome 0:e8e62dfee5eb 384 /// - %%e Equivalent to %%d.
WiredHome 0:e8e62dfee5eb 385 /// - %%h Equivalent to %%b.
WiredHome 0:e8e62dfee5eb 386 /// - %%H The hour (24-hour clock) [00,23]; leading zeros are permitted but not required.
WiredHome 0:e8e62dfee5eb 387 /// - %%I The hour (12-hour clock) [01,12]; leading zeros are permitted but not required.
WiredHome 0:e8e62dfee5eb 388 /// - %%j The day number of the year [001,366]; leading zeros are permitted but not required.
WiredHome 0:e8e62dfee5eb 389 /// - %%m The month number [01,12]; leading zeros are permitted but not required.
WiredHome 0:e8e62dfee5eb 390 /// - %%M The minute [00,59]; leading zeros are permitted but not required.
WiredHome 0:e8e62dfee5eb 391 /// - %%n Any white space.
WiredHome 0:e8e62dfee5eb 392 /// - %%p The locale's equivalent of a.m or p.m.
WiredHome 0:e8e62dfee5eb 393 /// - %%r 12-hour clock time using the AM/PM notation if t_fmt_ampm is not an empty string
WiredHome 0:e8e62dfee5eb 394 /// in the LC_TIME portion of the current locale; in the POSIX locale, this shall be
WiredHome 0:e8e62dfee5eb 395 /// equivalent to %%I : %%M : %%S %%p.
WiredHome 0:e8e62dfee5eb 396 /// - %%R The time as %%H : %%M.
WiredHome 0:e8e62dfee5eb 397 /// - %%S The seconds [00,60]; leading zeros are permitted but not required.
WiredHome 0:e8e62dfee5eb 398 /// - %%t Any white space.
WiredHome 0:e8e62dfee5eb 399 /// - %%T The time as %%H : %%M : %%S.
WiredHome 0:e8e62dfee5eb 400 /// - %%U The week number of the year (Sunday as the first day of the week) as a decimal
WiredHome 0:e8e62dfee5eb 401 /// number [00,53]; leading zeros are permitted but not required.
WiredHome 0:e8e62dfee5eb 402 /// - %%w The weekday as a decimal number [0,6], with 0 representing Sunday; leading zeros
WiredHome 0:e8e62dfee5eb 403 /// are permitted but not required.
WiredHome 0:e8e62dfee5eb 404 /// - %%W The week number of the year (Monday as the first day of the week) as a decimal
WiredHome 0:e8e62dfee5eb 405 /// number [00,53]; leading zeros are permitted but not required.
WiredHome 0:e8e62dfee5eb 406 /// - %%x The date, using the locale's date format.
WiredHome 0:e8e62dfee5eb 407 /// - %%X The time, using the locale's time format.
WiredHome 0:e8e62dfee5eb 408 /// - %%y The year within century. When a century is not otherwise specified, values in
WiredHome 0:e8e62dfee5eb 409 /// the range [69,99] shall refer to years 1969 to 1999 inclusive, and values in the
WiredHome 0:e8e62dfee5eb 410 /// range [00,68] shall refer to years 2000 to 2068 inclusive; leading zeros shall be
WiredHome 0:e8e62dfee5eb 411 /// permitted but shall not be required.
WiredHome 0:e8e62dfee5eb 412 /// Note: It is expected that in a future version of IEEE Std 1003.1-2001
WiredHome 0:e8e62dfee5eb 413 /// the default century inferred from a 2-digit year will change.
WiredHome 0:e8e62dfee5eb 414 /// (This would apply to all commands accepting a 2-digit year as input.)
WiredHome 0:e8e62dfee5eb 415 /// - %%Y The year, including the century (for example, 1988).
WiredHome 0:e8e62dfee5eb 416 /// - %%Z The timezone offset, as a 3-letter sequence. Only a few whole-hour offsets
WiredHome 0:e8e62dfee5eb 417 /// have been defined.
WiredHome 0:e8e62dfee5eb 418 /// - %% Replaced by %.
WiredHome 0:e8e62dfee5eb 419 ///
WiredHome 1:b78c91e34eda 420 const char * strptime(const char *buf, const char *fmt, struct tm_ex *tm);
WiredHome 0:e8e62dfee5eb 421
WiredHome 0:e8e62dfee5eb 422
WiredHome 0:e8e62dfee5eb 423 // time zone functions
WiredHome 0:e8e62dfee5eb 424
WiredHome 0:e8e62dfee5eb 425 /// Set the internal RTC (clock) to the time value.
WiredHome 0:e8e62dfee5eb 426 ///
WiredHome 0:e8e62dfee5eb 427 /// The time valueshould be UTC time along with an offset of zero,
WiredHome 0:e8e62dfee5eb 428 /// which then permits gmtime and localtime to be used appropriately.
WiredHome 0:e8e62dfee5eb 429 /// Alternately, the time can be in localtime, and the offset is then
WiredHome 0:e8e62dfee5eb 430 /// used to compute UTC to set the clock.
WiredHome 0:e8e62dfee5eb 431 ///
WiredHome 0:e8e62dfee5eb 432 /// @param[in] t should be the UTC time value to set the clock to. If the available
WiredHome 0:e8e62dfee5eb 433 /// time value is local time, the optional time zone offset can
WiredHome 0:e8e62dfee5eb 434 /// be provided so the system clock is UTC.
WiredHome 0:e8e62dfee5eb 435 /// @param[in] tzo is the optional time zone offset in minutes when it is in
WiredHome 0:e8e62dfee5eb 436 /// the range of -720 to +720 (-12 hours to + 12 hours). Any
WiredHome 0:e8e62dfee5eb 437 /// other value is illegal and no change will be made.
WiredHome 0:e8e62dfee5eb 438 ///
WiredHome 0:e8e62dfee5eb 439 void set_time(time_t t, int16_t tzo_min = 0);
WiredHome 0:e8e62dfee5eb 440
WiredHome 0:e8e62dfee5eb 441 /// Set the time zone offset in minutes.
WiredHome 0:e8e62dfee5eb 442 ///
WiredHome 0:e8e62dfee5eb 443 /// This API should be used before any other methods that fetch
WiredHome 0:e8e62dfee5eb 444 /// the RTC info.
WiredHome 0:e8e62dfee5eb 445 ///
WiredHome 0:e8e62dfee5eb 446 /// @param[in] tzo is the time zone offset in minutes when it is in
WiredHome 0:e8e62dfee5eb 447 /// the range of -720 to +720 (-12 hours to + 12 hours). Any
WiredHome 0:e8e62dfee5eb 448 /// other value is illegal and no change will be made.
WiredHome 0:e8e62dfee5eb 449 ///
WiredHome 0:e8e62dfee5eb 450 void set_tzo_min(int16_t tzo_min);
WiredHome 0:e8e62dfee5eb 451
WiredHome 0:e8e62dfee5eb 452 /// Get the time zone offset in minutes.
WiredHome 0:e8e62dfee5eb 453 ///
WiredHome 0:e8e62dfee5eb 454 /// @returns the time zone offset value in minutes. If the tzo was
WiredHome 0:e8e62dfee5eb 455 /// never initialized, this returns zero.
WiredHome 0:e8e62dfee5eb 456 ///
WiredHome 0:e8e62dfee5eb 457 int16_t get_tzo_min(void);
WiredHome 0:e8e62dfee5eb 458
WiredHome 0:e8e62dfee5eb 459 /// Set the clock for local time to report whether the current
WiredHome 0:e8e62dfee5eb 460 /// mode is standard or daylight savings time.
WiredHome 0:e8e62dfee5eb 461 ///
WiredHome 0:e8e62dfee5eb 462 /// return values for localtime will then be adjusted not only
WiredHome 0:e8e62dfee5eb 463 /// for the time zone offset, but for dst.
WiredHome 0:e8e62dfee5eb 464 ///
WiredHome 0:e8e62dfee5eb 465 /// @param[in] dst is a boolean that should be set when dst is
WiredHome 0:e8e62dfee5eb 466 /// the active mode.
WiredHome 0:e8e62dfee5eb 467 /// @returns true, always.
WiredHome 0:e8e62dfee5eb 468 ///
WiredHome 0:e8e62dfee5eb 469 bool set_dst(bool dst);
WiredHome 0:e8e62dfee5eb 470
WiredHome 0:e8e62dfee5eb 471 /// Set the clock for auto-adjust local time based on
WiredHome 0:e8e62dfee5eb 472 /// changing to standard or daylight savings time.
WiredHome 0:e8e62dfee5eb 473 ///
WiredHome 0:e8e62dfee5eb 474 /// return values for localtime will then be adjusted not only
WiredHome 0:e8e62dfee5eb 475 /// for the time zone offset, but for dst.
WiredHome 0:e8e62dfee5eb 476 ///
WiredHome 0:e8e62dfee5eb 477 /// @param[in] dstStart is a string of the form "mm/dd,hh:mm"
WiredHome 0:e8e62dfee5eb 478 /// representing when DST starts.
WiredHome 0:e8e62dfee5eb 479 /// @param[in] dstStop is a string of the form "mm/dd,hh:mm"
WiredHome 0:e8e62dfee5eb 480 /// representing when DST stops.
WiredHome 0:e8e62dfee5eb 481 /// @returns true if the start and stop pair could be successfully
WiredHome 0:e8e62dfee5eb 482 /// parsed.
WiredHome 0:e8e62dfee5eb 483 ///
WiredHome 0:e8e62dfee5eb 484 bool set_dst(const char * dstStart, const char * dstStop);
WiredHome 0:e8e62dfee5eb 485
WiredHome 0:e8e62dfee5eb 486 /// Get the current clock mode for daylight savings time.
WiredHome 0:e8e62dfee5eb 487 ///
WiredHome 0:e8e62dfee5eb 488 /// @returns true if clock is in dst mode.
WiredHome 0:e8e62dfee5eb 489 ///
WiredHome 0:e8e62dfee5eb 490 bool get_dst(void);
WiredHome 0:e8e62dfee5eb 491
WiredHome 0:e8e62dfee5eb 492 /// Get the time value when the clock was last set. This is most
WiredHome 0:e8e62dfee5eb 493 /// often used in calibration of the clock.
WiredHome 0:e8e62dfee5eb 494 ///
WiredHome 0:e8e62dfee5eb 495 /// @returns time last set as a UTC time value.
WiredHome 0:e8e62dfee5eb 496 ///
WiredHome 0:e8e62dfee5eb 497 time_t get_timelastset(void);
WiredHome 0:e8e62dfee5eb 498
WiredHome 0:e8e62dfee5eb 499 /// get_cal will return the calibration register value
WiredHome 0:e8e62dfee5eb 500 ///
WiredHome 0:e8e62dfee5eb 501 /// This is the raw register value as a signed 32-bit value (even though
WiredHome 0:e8e62dfee5eb 502 /// it is actually a 17-bit unsigned value with an additional 'direction' flag).
WiredHome 0:e8e62dfee5eb 503 ///
WiredHome 0:e8e62dfee5eb 504 /// @returns calibration settings ranging from -131071 to +131071
WiredHome 0:e8e62dfee5eb 505 ///
WiredHome 0:e8e62dfee5eb 506 int32_t get_cal();
WiredHome 0:e8e62dfee5eb 507
WiredHome 0:e8e62dfee5eb 508 /// set_cal will set the calibration register value
WiredHome 0:e8e62dfee5eb 509 ///
WiredHome 0:e8e62dfee5eb 510 /// This accepts a signed value to be used to set the calibration
WiredHome 0:e8e62dfee5eb 511 /// registers. Setting the calibration value to zero disables the
WiredHome 0:e8e62dfee5eb 512 /// calibration function.
WiredHome 0:e8e62dfee5eb 513 ///
WiredHome 0:e8e62dfee5eb 514 /// It is important to know the register function in order to use
WiredHome 0:e8e62dfee5eb 515 /// this command, and this API is normally not used by external
WiredHome 0:e8e62dfee5eb 516 /// application code. @See AdjustBySeconds for a user-friendly
WiredHome 0:e8e62dfee5eb 517 /// API.
WiredHome 0:e8e62dfee5eb 518 ///
WiredHome 0:e8e62dfee5eb 519 /// @param[in] calibration value to use ranging from -131071 to +131071
WiredHome 0:e8e62dfee5eb 520 /// @returns nothing
WiredHome 0:e8e62dfee5eb 521 ///
WiredHome 0:e8e62dfee5eb 522 void set_cal(int32_t calibration);
WiredHome 0:e8e62dfee5eb 523
WiredHome 0:e8e62dfee5eb 524 /// adjust_sec adjusts both the time and the calibration by seconds
WiredHome 0:e8e62dfee5eb 525 ///
WiredHome 0:e8e62dfee5eb 526 /// This will take a signed value, which is the current adjustment in seconds
WiredHome 0:e8e62dfee5eb 527 /// to put the clock on the correct time. So, if the clock is behind by
WiredHome 0:e8e62dfee5eb 528 /// 3 seconds, the value should be +3 to advance the clock accordingly.
WiredHome 0:e8e62dfee5eb 529 /// It will then adjust the time, and it will attempt to adjust the
WiredHome 0:e8e62dfee5eb 530 /// calibration factor to make the time more accurate.
WiredHome 0:e8e62dfee5eb 531 ///
WiredHome 0:e8e62dfee5eb 532 /// The adjustment can only be made if it has retained when the clock was
WiredHome 0:e8e62dfee5eb 533 /// last set, in order to know by how much to adjust it. It is also most
WiredHome 0:e8e62dfee5eb 534 /// accurate if several days have elapsed since the time was set.
WiredHome 0:e8e62dfee5eb 535 ///
WiredHome 0:e8e62dfee5eb 536 /// @note The current version only works if the calibration value
WiredHome 0:e8e62dfee5eb 537 /// is zero when this adjustment is made.
WiredHome 0:e8e62dfee5eb 538 ///
WiredHome 0:e8e62dfee5eb 539 /// @param[in] adjustSeconds is the signed value by which to adjust the time to
WiredHome 0:e8e62dfee5eb 540 /// correct it to the current actual time.
WiredHome 0:e8e62dfee5eb 541 /// @returns true if the adjustment was made
WiredHome 0:e8e62dfee5eb 542 /// @returns false if the adjustment could not be made
WiredHome 0:e8e62dfee5eb 543 ///
WiredHome 0:e8e62dfee5eb 544 bool adjust_sec(int32_t adjustSeconds);
WiredHome 0:e8e62dfee5eb 545
WiredHome 0:e8e62dfee5eb 546 /// Set the clock from an internet source (blocking)
WiredHome 0:e8e62dfee5eb 547 ///
WiredHome 0:e8e62dfee5eb 548 /// This function is the interface to NTPClient.
WiredHome 0:e8e62dfee5eb 549 /// Blocks until completion
WiredHome 0:e8e62dfee5eb 550 ///
WiredHome 0:e8e62dfee5eb 551 /// @param[in] host NTP server IPv4 address or hostname (will be resolved via DNS)
WiredHome 0:e8e62dfee5eb 552 /// @param[in] port port to use; defaults to 123
WiredHome 0:e8e62dfee5eb 553 /// @param[in] timeout waiting timeout in ms (osWaitForever for blocking function, not recommended)
WiredHome 0:e8e62dfee5eb 554 /// @returns NTP_OK on success,
WiredHome 0:e8e62dfee5eb 555 /// @returns NTP_CONN if no network interface
WiredHome 0:e8e62dfee5eb 556 /// @returns other NTP error code (<0) on failure
WiredHome 0:e8e62dfee5eb 557 ///
WiredHome 0:e8e62dfee5eb 558 //NTPResult setTime(const char* host, uint16_t port = NTP_DEFAULT_PORT, uint32_t timeout = NTP_DEFAULT_TIMEOUT);
WiredHome 0:e8e62dfee5eb 559
WiredHome 0:e8e62dfee5eb 560 // ntp interface functions
WiredHome 0:e8e62dfee5eb 561 private:
WiredHome 0:e8e62dfee5eb 562 void * m_net;
WiredHome 0:e8e62dfee5eb 563
WiredHome 0:e8e62dfee5eb 564 typedef struct {
WiredHome 0:e8e62dfee5eb 565 uint8_t MM;
WiredHome 0:e8e62dfee5eb 566 uint8_t DD;
WiredHome 0:e8e62dfee5eb 567 uint8_t hh;
WiredHome 0:e8e62dfee5eb 568 uint8_t mm;
WiredHome 0:e8e62dfee5eb 569 } dst_event_t;
WiredHome 0:e8e62dfee5eb 570 typedef struct {
WiredHome 0:e8e62dfee5eb 571 dst_event_t dst_start;
WiredHome 0:e8e62dfee5eb 572 dst_event_t dst_stop;
WiredHome 0:e8e62dfee5eb 573 } dst_event_pair_t;
WiredHome 0:e8e62dfee5eb 574
WiredHome 0:e8e62dfee5eb 575 bool parseDSTstring(dst_event_t * result, const char * dstr);
WiredHome 0:e8e62dfee5eb 576
WiredHome 0:e8e62dfee5eb 577 /// Performs a "simple" computation of two dates into minutes.
WiredHome 0:e8e62dfee5eb 578 ///
WiredHome 0:e8e62dfee5eb 579 /// Does not account for leap years or which month it is. Is
WiredHome 0:e8e62dfee5eb 580 /// useful only for comparing which date/time came first, not for
WiredHome 0:e8e62dfee5eb 581 /// computing the difference between them.
WiredHome 0:e8e62dfee5eb 582 ///
WiredHome 0:e8e62dfee5eb 583 /// @return "normalized" minutes since Jan 1 00:00.
WiredHome 0:e8e62dfee5eb 584 ///
WiredHome 0:e8e62dfee5eb 585 uint32_t minutesSinceJan(int mon, int day, int hr, int min);
WiredHome 0:e8e62dfee5eb 586
WiredHome 0:e8e62dfee5eb 587 dst_event_pair_t dst_pair;
WiredHome 0:e8e62dfee5eb 588 bool dst; // true in dst mode
WiredHome 1:b78c91e34eda 589 char result[33]; // holds the converted to text time string
WiredHome 0:e8e62dfee5eb 590 time_t tresult; // holds the converted time structure.
WiredHome 0:e8e62dfee5eb 591 struct tm_ex tm_ext;
WiredHome 0:e8e62dfee5eb 592 };
WiredHome 0:e8e62dfee5eb 593
WiredHome 0:e8e62dfee5eb 594 #endif // TIMEINTERFACE_H