mikroSDK Reference Manual
sntp_client.h
Go to the documentation of this file.
1
31#ifndef _SNTP_CLIENT_H
32#define _SNTP_CLIENT_H
33
34//Dependencies
35#include "core/net.h"
36#include "sntp/ntp_common.h"
37
38//SNTP client support
39#ifndef SNTP_CLIENT_SUPPORT
40 #define SNTP_CLIENT_SUPPORT ENABLED
41#elif (SNTP_CLIENT_SUPPORT != ENABLED && SNTP_CLIENT_SUPPORT != DISABLED)
42 #error SNTP_CLIENT_SUPPORT parameter is not valid
43#endif
44
45//Default timeout
46#ifndef SNTP_CLIENT_DEFAULT_TIMEOUT
47 #define SNTP_CLIENT_DEFAULT_TIMEOUT 30000
48#elif (SNTP_CLIENT_DEFAULT_TIMEOUT < 1000)
49 #error SNTP_CLIENT_DEFAULT_TIMEOUT parameter is not valid
50#endif
51
52//Initial retransmission timeout
53#ifndef SNTP_CLIENT_INIT_RETRANSMIT_TIMEOUT
54 #define SNTP_CLIENT_INIT_RETRANSMIT_TIMEOUT 2000
55#elif (SNTP_CLIENT_INIT_RETRANSMIT_TIMEOUT < 1000)
56 #error SNTP_CLIENT_INIT_RETRANSMIT_TIMEOUT parameter is not valid
57#endif
58
59//Maximum retransmission timeout
60#ifndef SNTP_CLIENT_MAX_RETRANSMIT_TIMEOUT
61 #define SNTP_CLIENT_MAX_RETRANSMIT_TIMEOUT 15000
62#elif (SNTP_CLIENT_MAX_RETRANSMIT_TIMEOUT < 1000)
63 #error SNTP_CLIENT_MAX_RETRANSMIT_TIMEOUT parameter is not valid
64#endif
65
66//Application specific context
67#ifndef SNTP_CLIENT_PRIVATE_CONTEXT
68 #define SNTP_CLIENT_PRIVATE_CONTEXT
69#endif
70
71//C++ guard
72#ifdef __cplusplus
73extern "C" {
74#endif
75
76
81typedef enum
82{
83 SNTP_CLIENT_STATE_INIT = 0,
84 SNTP_CLIENT_STATE_SENDING = 2,
85 SNTP_CLIENT_STATE_RECEIVING = 3,
86 SNTP_CLIENT_STATE_COMPLETE = 4
88
89
94typedef struct
95{
97 NetInterface *interface;
99 uint16_t serverPort;
101 Socket *socket;
105 uint8_t message[NTP_MAX_MSG_SIZE];
106 size_t messageLen;
107 uint32_t kissCode;
108 SNTP_CLIENT_PRIVATE_CONTEXT
110
111
112//SNTP client related functions
113error_t sntpClientInit(SntpClientContext *context);
114
115error_t sntpClientSetTimeout(SntpClientContext *context, systime_t timeout);
116
117error_t sntpClientBindToInterface(SntpClientContext *context,
118 NetInterface *interface);
119
120error_t sntpClientSetServerAddr(SntpClientContext *context,
121 const IpAddr *serverIpAddr, uint16_t serverPort);
122
123error_t sntpClientGetTimestamp(SntpClientContext *context,
124 NtpTimestamp *timestamp);
125
126uint32_t sntpClientGetKissCode(SntpClientContext *context);
127
128void sntpClientDeinit(SntpClientContext *context);
129
130//C++ guard
131#ifdef __cplusplus
132}
133#endif
134
135#endif
error_t
Error codes.
Definition error.h:43
TCP/IP stack core.
Definitions common to NTP client and server.
uint32_t systime_t
System time.
Definition os_port_none.h:90
SntpClientState
SNTP client states.
Definition sntp_client.h:82
IP network address.
Definition ip.h:72
SNTP client context.
Definition sntp_client.h:95
systime_t retransmitTimeout
Retransmission timeout.
Definition sntp_client.h:104
systime_t retransmitStartTime
Time at which the last request was sent.
Definition sntp_client.h:103
NetInterface * interface
Underlying network interface.
Definition sntp_client.h:97
IpAddr serverIpAddr
NTP server address.
Definition sntp_client.h:98
size_t messageLen
Length of the NTP message, in bytes.
Definition sntp_client.h:106
Socket * socket
Underlying socket.
Definition sntp_client.h:101
systime_t startTime
Request start time.
Definition sntp_client.h:102
uint16_t serverPort
NTP server port.
Definition sntp_client.h:99
systime_t timeout
Timeout value.
Definition sntp_client.h:100
SntpClientState state
SNTP client state.
Definition sntp_client.h:96
uint32_t kissCode
Kiss code.
Definition sntp_client.h:107