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
AppTimeAns
The server’s correction, section 3.2.
Fields
DeviceAppTimePeriodicityReq
The server setting how often the device asks, section 3.3.
DeviceAppTimePeriodicityAns
The device’s answer, which also reports its clock, section 3.3.
Fields
ForceDeviceResyncCmd
The server telling the device to synchronize now, section 3.4.
Implementations§
Source§impl ClockCommand
impl ClockCommand
Sourcepub const fn direction(&self) -> Direction
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.
Sourcepub fn parse(
direction: Direction,
bytes: &[u8],
) -> Result<(ClockCommand, usize), LorawanError>
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));Sourcepub fn encode(&self, out: &mut [u8]) -> Result<usize, LorawanError>
pub fn encode(&self, out: &mut [u8]) -> Result<usize, LorawanError>
Writes this command out.
§Arguments
out- where to write it, at leastMAX_COMMANDbytes 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
impl Clone for ClockCommand
Source§fn clone(&self) -> ClockCommand
fn clone(&self) -> ClockCommand
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more