picofuse

ntp.h
Go to the documentation of this file.
1 
39 #pragma once
40 #include <picofuse/hid/device.h>
41 #include <picofuse/net/types.h>
42 #include <picofuse/sys/date.h>
43 #include <stdint.h>
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
54 #define NET_NTP_PORT 123
55 
65 #ifndef NET_NTP_DEFAULT_ADDR
66 #define NET_NTP_DEFAULT_ADDR 162, 159, 200, 1
67 #endif
68 
70 // TYPES
71 
76 typedef struct net_ntp_t net_ntp_t;
77 
79 // LIFECYCLE
80 
96 net_ntp_t *net_ntp_init(const net_addr_t *addr, uint16_t port,
97  uint32_t timeout_ms);
98 
104 void net_ntp_deinit(net_ntp_t *ntp);
105 
108 // METHODS
110 
130 bool net_ntp_read(net_ntp_t *ntp, sys_date_t *date);
131 
134 // HID INTEGRATION
136 
161  uint32_t polling_interval_ms,
162  void *userdata);
163 
166 #ifdef __cplusplus
167 }
168 #endif
void net_ntp_deinit(net_ntp_t *ntp)
Release a handle from net_ntp_init().
net_ntp_t * net_ntp_init(const net_addr_t *addr, uint16_t port, uint32_t timeout_ms)
Identify an NTP server to query with net_ntp_read().
hid_device_t * net_ntp_register_hid(hid_t *instance, net_ntp_t *ntp, uint32_t polling_interval_ms, void *userdata)
Register an NTP connection as a polling HID time source.
struct net_ntp_t net_ntp_t
Opaque handle identifying an SNTP server to query.
Definition: ntp.h:76
struct hid_device_t hid_device_t
HID child-device descriptor tracked by a HID instance.
Definition: device.h:46
struct hid_t hid_t
Opaque HID instance handle.
Definition: device.h:40
bool net_ntp_read(net_ntp_t *ntp, sys_date_t *date)
Query the server for the current time.
HID device lifecycle and polling interface.
Represents a system date and time.
Definition: date.h:25
An IPv4 or IPv6 address.
Definition: types.h:48
Defines date and wall-clock time APIs.