sntp: extend API for UNIX timestamp
This commit is contained in:
parent
c513eb1027
commit
10ca03aab3
@ -46,6 +46,12 @@ extern "C" {
|
||||
#define NTP_VERSION (4U) /**< NTP version */
|
||||
#define NTP_PORT (123U) /**< NTP port number */
|
||||
|
||||
/**
|
||||
* @brief Offset in seconds of NTP timestamp (seconds from 1990-01-01 00:00:00 UTC)
|
||||
* to UNIX timestamp (seconds from 1970-01-01 00:00:00 UTC).
|
||||
*/
|
||||
#define NTP_UNIX_OFFSET (2208988800)
|
||||
|
||||
/**
|
||||
* @brief NTP modes
|
||||
*/
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Luminița Lăzărescu <cluminita.lazarescu@gmail.com>
|
||||
* Copyright (C) 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
|
||||
@ -23,7 +24,11 @@
|
||||
#define SNTP_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "net/ntp_packet.h"
|
||||
#include "net/sock/udp.h"
|
||||
#include "xtimer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -47,6 +52,16 @@ int sntp_sync(sock_udp_ep_t *server, uint32_t timeout);
|
||||
*/
|
||||
int64_t sntp_get_offset(void);
|
||||
|
||||
/**
|
||||
* @brief Get time in microseconds from 1970-01-01 00:00:00 UTC.
|
||||
*
|
||||
* @return Time in microseconds from 1970-01-01 00:00:00 UTC
|
||||
*/
|
||||
static inline uint64_t sntp_get_unix_usec(void)
|
||||
{
|
||||
return (uint64_t)(sntp_get_offset() - (NTP_UNIX_OFFSET * US_PER_SEC) + xtimer_now_usec64());
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user