mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-27 09:17:08 +03:00
Revised time-related functions to get rid of clock_offset for POSIX platform.
* Removed tne preprocessor defines for coap_tick() and coap_clock_init() -- this made the code less readable and seemed to be of little use. * Introduced the new type coap_time_t to represent wall clock time. On POSIX, this is the number of seconds since the epoch, while on embedded systems without a real time clock, this could be the number of seconds since the last reboot. The new function coap_ticks_to_rt() is used to convert coap_tick_t to coap_time.h. Currently, this is a division by COAP_TICKS_PER_SECOND on all platforms. * POSIX: coap_tick_t is now defined as unsigned long to avoid overflows in coap_ticks().
This commit is contained in:
1 parent
a31981b95b
commit
4ca91190d6
6 files changed
+132
-51
No files matched your search
+2
-2
@@ -69,7 +69,7 @@ static char *loglevels[] = {
|
||||
static inline size_t
|
||||
print_timestamp(char *s, size_t len, coap_tick_t t) {
|
||||
struct tm *tmp;
|
||||
time_t now = clock_offset + (t / COAP_TICKS_PER_SECOND);
|
||||
time_t now = coap_ticks_to_rt(t);
|
||||
tmp = localtime(&now);
|
||||
return strftime(s, len, "%b %d %H:%M:%S", tmp);
|
||||
}
|
||||
@@ -80,7 +80,7 @@ static inline size_t
|
||||
print_timestamp(char *s, size_t len, coap_tick_t t) {
|
||||
#ifdef HAVE_SNPRINTF
|
||||
return snprintf(s, len, "%u.%03u",
|
||||
(unsigned int)(clock_offset + (t / COAP_TICKS_PER_SECOND)),
|
||||
(unsigned int)coap_ticks_to_rt(t),
|
||||
(unsigned int)(t % COAP_TICKS_PER_SECOND));
|
||||
#else /* HAVE_SNPRINTF */
|
||||
/* @todo do manual conversion of timestamp */
|
||||
|
||||
Reference in new issue
Block a user