12#if DETWS_ENABLE_NTP_SERVER
20 p[0] = (uint8_t)(v >> 24);
21 p[1] = (uint8_t)(v >> 16);
22 p[2] = (uint8_t)(v >> 8);
28 uint32_t ntp_frac, uint8_t *out,
size_t out_cap)
34 uint8_t vn = (uint8_t)((req[0] >> 3) & 0x7);
36 out[0] = (uint8_t)((0u << 6) | (vn << 3) | 4u);
38 out[2] = req[2] ? req[2] : 6;
39 out[3] = (uint8_t)(-6);
45 memcpy(out + 24, req + 40, 8);
71void ntp_server_udp_handler(
const uint8_t *data,
size_t len,
struct DetUdpPeer *peer,
void *ctx)
79 uint32_t frac = (uint32_t)(((uint64_t)(
detws_millis() % 1000u) << 32) / 1000u);
91 s_ntp.stratum = stratum;
User-facing configuration for DeterministicESPAsyncWebServer.
#define DETWS_NTP_SERVER_STRATUM
Stratum the NTP server advertises (distance from a reference clock; 1-15).
Pluggable monotonic clock for all library timing.
uint32_t detws_millis(void)
The library's monotonic time at 1000 Hz (milliseconds).
void put_be32(uint8_t *p, uint32_t v)
NTP/SNTP time server (RFC 5905 / RFC 4330 server mode) on UDP/123.
#define NTP_REFID_LOCL
Reference ID "LOCL" - an undisciplined local clock (RFC 5905 sec 7.3).
#define NTP_UNIX_OFFSET
Seconds between the NTP epoch (1900-01-01) and the Unix epoch (1970-01-01).
bool ntp_server_begin(uint8_t stratum, uint32_t refid=NTP_REFID_LOCL)
Start answering NTP requests on UDP/123 from the device's own clock.
#define NTP_PACKET_LEN
One NTP packet on the wire is exactly 48 octets (no extension/auth fields).
size_t ntp_server_build_response(const uint8_t *req, size_t req_len, uint8_t stratum, uint32_t refid, uint32_t ntp_secs, uint32_t ntp_frac, uint8_t *out, size_t out_cap)
Build a server (mode 4) reply to a client NTP request. Pure - no clock, no I/O.
uint32_t detws_time_now(void)
Current best time.
Multi-source time fallback matrix (DETWS_ENABLE_TIME_SOURCE).
bool det_udp_send(struct DetUdpPeer *peer, const uint8_t *data, size_t len)
Send a datagram back to the peer captured during the handler call.
bool det_udp_listen(uint16_t port, DetUdpHandler handler, void *ctx)
Bind a UDP port and route incoming datagrams to handler.
Layer 4 (Transport) - connectionless UDP datagram service.