Skip to main content

Crate rusty_rtos_sntp

Crate rusty_rtos_sntp 

Source
Expand description

rusty_rtos_sntp — coreSNTP remade in Rust.

What is here: core_sntp_serializer.c — the SNTPv4 packet codec, the response validation, the clock-offset arithmetic across the 2036 era wrap, the poll-interval calculation and the UNIX time conversion. Every one of them diffed against the C, call for call.

What is not: core_sntp_client.c, the state machine that drives a UDP transport and an authentication interface. It needs a seam this package does not have yet, and this crate does not pretend otherwise.

Integer arithmetic throughout, because coreSNTP targets parts with no floating-point unit. Zero allocation, no_std, forbid(unsafe).

This is the facade: it re-exports the no_std core. Depend on this crate; reach into the sub-crates only when you are building a port or a backend.

Part of Kairos (Remade With Rust). Plan: docs/plans/rusty_rtos_sntp.md.

Modules§

client
core_sntp_client.c: the polling client over a UDP transport. core_sntp_client.c remade: the polling client over a UDP transport.
prelude
The names a firmware wants in scope.
rtos_core
rusty_rtos_core — the shared vocabulary of the Kairos family.
serializer
core_sntp_serializer.c: the SNTPv4 packet codec and its arithmetic. core_sntp_serializer.c remade: the SNTPv4 packet codec and its arithmetic.
types
The types that cross the SNTP surface. The types that cross the SNTP surface.

Structs§

Accepted
A server response that carried a usable time.
Client
A long-running SNTP client: one server at a time, rotating on refusal.
NetworkError
Something went wrong in the transport itself.
NoAuth
No authentication, which is what most SNTP deployments use.
Rejected
A Kiss-o’-Death: the server answered, and the answer was no.
ServerInfo
A time server: a name to resolve, and a port to reach it on.
Timestamp
An SNTP timestamp: seconds and fractions since 1 January 1900 UTC.

Enums§

AuthError
Why an authentication callback refused.
DeserializeError
Why a response could not be read.
InitError
Why a client could not be built.
LeapSecond
SntpLeapSecondInfo_t: what the server says about the coming month.
PollIntervalError
Why a poll interval could not be calculated.
ReceiveError
Why a response could not be used.
Reception
What happened while waiting for a response.
Rejection
Why a server refused to give the time.
SendError
Why a time request could not be sent.
SerializeError
Why a request could not be serialized.
Verdict
What a well-formed response turned out to say.

Constants§

FRACTION_VALUE_PER_MICROSECOND
SNTP_FRACTION_VALUE_PER_MICROSECOND. The fractions field is 32 bits over one second, so one tick is about 232 picoseconds and a microsecond is 4,295 of them.
KISS_OF_DEATH_CODE_LENGTH
SNTP_KISS_OF_DEATH_CODE_LENGTH: a kiss code is four ASCII characters.
PACKET_BASE_SIZE
SNTP_PACKET_BASE_SIZE: a packet without authentication data.
TIME_AT_UNIX_EPOCH_SECS
SNTP_TIME_AT_UNIX_EPOCH_SECS: 70 years, in seconds, between the SNTP epoch (1 Jan 1900) and the UNIX epoch (1 Jan 1970).
UNIX_TIME_SECS_AT_SNTP_ERA_1_SMALLEST_TIME
UNIX_TIME_SECS_AT_SNTP_ERA_1_SMALLEST_TIME: the UNIX time at the moment SNTP’s seconds field wraps, 7 Feb 2036 06:28:16 UTC.
VERSION
Crate version, for manifests and logs.

Traits§

Authenticator
Symmetric-key or NTS-style authentication, if the deployment uses it.
SntpHost
Everything the client needs from the system it runs on.

Functions§

calculate_poll_interval
Sntp_CalculatePollInterval: how often to ask, for a wanted accuracy.
convert_to_unix_time
Sntp_ConvertToUnixTime: an SNTP timestamp as UNIX seconds and microseconds.
deserialize_response
Sntp_DeserializeResponse: validate a server response and time the clock.
serialize_request
Sntp_SerializeRequest: build an SNTP request packet.