Skip to main content

ClockSync

Struct ClockSync 

Source
pub struct ClockSync { /* private fields */ }
Expand description

The clock synchronization package running on a device, TS003-2.0.0.

It keeps the token that pairs an answer with its request, the period the server set, and whatever answer the device owes. It holds no clock: the caller passes the device’s own time into each request and applies the correction that comes back.

Implementations§

Source§

impl ClockSync

Source

pub const DEFAULT_PERIOD: u8 = 0

The period a device asks at until its server says otherwise, section 3.3.

Source

pub const fn new() -> ClockSync

Starts the package on a device, with the token at zero.

§Returns

The package, with nothing outstanding.

Source

pub const fn self_managed() -> ClockSync

Starts the package on a device that manages its own periodicity.

Such a device answers a server that tries to set a period with the not-supported bit, section 3.3.

§Returns

The package.

Source

pub const fn token(&self) -> u8

The token the next request will carry.

§Returns

A value 0 to 15, which rises every time a correction is applied.

Source

pub const fn period_s(&self) -> u32

How often the device should ask, as the server last set it.

§Returns

The seconds between requests, before the random spread of thirty seconds either way that section 3.3 asks for.

Source

pub fn app_time_req( &mut self, device_time: u32, ans_required: bool, out: &mut [u8], ) -> Result<usize, LorawanError>

Builds the request that asks for a correction, section 3.2.

§Arguments
  • device_time - what the device believes the time is, in seconds since the GPS epoch, read immediately before the frame goes out.
  • ans_required - whether the server must answer even if the clock is right.
  • out - where to write the command.
§Returns

How many bytes were written.

§Errors

LorawanError::PayloadTooLong when the buffer is too small.

Source

pub fn heard(&mut self, payload: &[u8]) -> Result<Heard, LorawanError>

Reads a downlink on the clock port and acts on it.

A correction whose token does not match the outstanding request is ignored, as section 3.2 asks, and so is any answer with no request waiting on it.

§Arguments
  • payload - what arrived on port PORT.
§Returns

The correction to apply, whether more of one is coming, and what the device now owes.

§Errors

The first error a command in the message raised.

Source

pub fn answer( &mut self, device_time: u32, out: &mut [u8], ) -> Result<usize, LorawanError>

Writes the answer the device owes, if it owes one.

§Arguments
  • device_time - what the device believes the time is, for the answer that reports it.
  • out - where to write the command.
§Returns

How many bytes were written, and zero when nothing is owed.

§Errors

LorawanError::PayloadTooLong when the buffer is too small, leaving the answer owed.

Source

pub const fn answer_due(&self) -> bool

Whether the device owes its server an answer.

§Returns

true when ClockSync::answer would write one.

Trait Implementations§

Source§

impl Clone for ClockSync

Source§

fn clone(&self) -> ClockSync

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ClockSync

Source§

impl Debug for ClockSync

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ClockSync

Source§

fn default() -> ClockSync

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.