Skip to main content

ClockCommand

Enum ClockCommand 

Source
pub enum ClockCommand {
    PackageVersionReq,
    PackageVersionAns(PackageVersion),
    AppTimeReq {
        device_time: u32,
        ans_required: bool,
        token: u8,
    },
    AppTimeAns {
        time_correction: i32,
        token: u8,
    },
    DeviceAppTimePeriodicityReq {
        period: u8,
    },
    DeviceAppTimePeriodicityAns {
        not_supported: bool,
        device_time: u32,
    },
    ForceDeviceResyncCmd {
        transmissions: u8,
    },
}
Expand description

One command of the clock synchronization package.

The identifier names a different command in each direction, so reading one takes the direction the frame traveled.

Variants§

§

PackageVersionReq

The server asking which version of this package the device implements.

§

PackageVersionAns(PackageVersion)

The device’s answer, section 3.1.

§

AppTimeReq

The device asking for a correction, section 3.2.

Fields

§device_time: u32

What the device believes the time is: seconds since the GPS epoch, modulo 2^32, read immediately before the frame goes out.

§ans_required: bool

Whether the server must answer even when the clock is already right.

§token: u8

The four-bit token the answer has to carry back.

§

AppTimeAns

The server’s correction, section 3.2.

Fields

§time_correction: i32

The seconds to add to the device’s clock, which may be negative.

§token: u8

The token of the request being answered.

§

DeviceAppTimePeriodicityReq

The server setting how often the device asks, section 3.3.

Fields

§period: u8

The coded period: 128 * 2^period seconds, plus or minus thirty.

§

DeviceAppTimePeriodicityAns

The device’s answer, which also reports its clock, section 3.3.

Fields

§not_supported: bool

Whether the device refuses a period set by the server and manages its own.

§device_time: u32

What the device believes the time is.

§

ForceDeviceResyncCmd

The server telling the device to synchronize now, section 3.4.

Fields

§transmissions: u8

How many requests to send, at most seven; zero means the command is discarded.

Implementations§

Source§

impl ClockCommand

Source

pub const fn cid(&self) -> u8

The identifier this command travels under.

§Returns

The identifier, 0x00 to 0x03.

Source

pub const fn direction(&self) -> Direction

Which way this command travels.

§Returns

Direction::Uplink for what a device sends, Direction::Downlink for what a server sends.

Source

pub fn parse( direction: Direction, bytes: &[u8], ) -> Result<(ClockCommand, usize), LorawanError>

Reads one command from the front of a message.

§Arguments
  • direction - which way the frame carrying it traveled.
  • bytes - the message, from this command’s identifier on.
§Returns

The command and how many bytes it took.

§Errors

LorawanError::MalformedFrame when the message ends inside the command, and LorawanError::UnknownCommand for an identifier this package does not define.

§Examples
use pamoja_lorawan::packages::clock::ClockCommand;
use pamoja_lorawan::Direction;

// The server tells a device whose clock has drifted to resynchronize, twice over.
let mut message = [0u8; 4];
let resync = ClockCommand::ForceDeviceResyncCmd { transmissions: 2 };
let written = resync.encode(&mut message)?;

let (command, taken) = ClockCommand::parse(Direction::Downlink, &message[..written])?;
assert_eq!((command, taken), (resync, written));
Source

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

Writes this command out.

§Arguments
  • out - where to write it, at least MAX_COMMAND bytes for any command.
§Returns

How many bytes were written.

§Errors

LorawanError::PayloadTooLong when the buffer is too small.

§Examples
use pamoja_lorawan::packages::clock::ClockCommand;
use pamoja_lorawan::Direction;

// A device reports the time it keeps and asks for the correction.
let mut out = [0u8; 8];
let request = ClockCommand::AppTimeReq { device_time: 1, ans_required: true, token: 3 };
let written = request.encode(&mut out)?;
assert_eq!(written, 6, "an identifier, four bytes of time, and one of flags");

// The server reads the same request back.
let (heard, _) = ClockCommand::parse(Direction::Uplink, &out[..written])?;
assert_eq!(heard, request);

Trait Implementations§

Source§

impl Clone for ClockCommand

Source§

fn clone(&self) -> ClockCommand

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 ClockCommand

Source§

impl Debug for ClockCommand

Source§

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

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

impl Eq for ClockCommand

Source§

impl Hash for ClockCommand

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for ClockCommand

Source§

fn eq(&self, other: &ClockCommand) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ClockCommand

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.