From 48fa957ab6dbda247ab8ad69c20eeb2ac023b6ad Mon Sep 17 00:00:00 2001 From: Martine Lenders Date: Sat, 4 Mar 2017 22:06:45 +0100 Subject: [PATCH] shell_commands: adapt shell command for new real time types --- sys/shell/commands/sc_sntp.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/sys/shell/commands/sc_sntp.c b/sys/shell/commands/sc_sntp.c index 87cab4abc0..171c519194 100644 --- a/sys/shell/commands/sc_sntp.c +++ b/sys/shell/commands/sc_sntp.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2016 Luminița Lăzărescu + * 2017 Freie Universität Berlin * * This file is subject to the terms and conditions of the GNU Lesser * General Public License v2.1. See the file LICENSE in the top level @@ -14,13 +15,17 @@ * @brief Prints the real time offset from the system time * * @author Luminița Lăzărescu + * @author Martine Lenders */ +#include +#include #include "net/sntp.h" #include "net/ntp_packet.h" #include "net/af.h" #include "net/ipv6/addr.h" +#include "timex.h" #define _DEFAULT_TIMEOUT (5000U); @@ -47,6 +52,21 @@ int _ntpdate(int argc, char **argv) puts("Error in synchronization"); return 1; } - printf("Offset: %i\n", (int)sntp_get_offset()); +#ifdef MODULE_NEWLIB + struct tm *tm; + time_t time = (time_t)(sntp_get_unix_usec() / US_PER_SEC); + + tm = gmtime(&time); + printf("%04i-%02i-%02i %02i:%02i:%02i UTC (%i us)\n", + tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, + tm->tm_hour, tm->tm_min, tm->tm_sec, + (int)sntp_get_offset()); +#else + uint64_t time = sntp_get_unix_usec(); + printf("%" PRIu32 ".%" PRIu32 " (%i us)\n", + (uint32_t)(time / US_PER_SEC), + (uint32_t)(time / US_PER_SEC), + (int)sntp_get_offset()); +#endif return 0; }