pub enum FirmwareCommand {
PackageVersionReq,
PackageVersionAns(PackageVersion),
DevVersionReq,
DevVersionAns {
firmware: u32,
hardware: u32,
},
DevRebootTimeReq {
reboot_time: u32,
},
DevRebootTimeAns {
reboot_time: u32,
},
DevRebootCountdownReq {
countdown: u32,
},
DevRebootCountdownAns {
countdown: u32,
},
DevUpgradeImageReq,
DevUpgradeImageAns {
status: UpImageStatus,
next_version: Option<u32>,
},
DevDeleteImageReq {
version: u32,
},
DevDeleteImageAns(DeleteStatus),
}Expand description
One command of the firmware management package.
Variants§
PackageVersionReq
The server asking which version of this package the device implements.
PackageVersionAns(PackageVersion)
The device’s answer, section 3.1.
DevVersionReq
The server asking what the device is running, section 3.2.
DevVersionAns
The device’s answer, whose two fields the manufacturer allots, section 3.2.
Fields
DevRebootTimeReq
The server programming a reboot at a moment in time, section 3.3.
Fields
reboot_time: u32Seconds since the GPS epoch, REBOOT_NOW for at once, or REBOOT_CANCEL
to cancel.
DevRebootTimeAns
The device’s answer: the seconds until it reboots, zero for a time it cannot keep,
or REBOOT_CANCEL acknowledging a cancellation, section 3.3.
DevRebootCountdownReq
The server programming a reboot after a delay, section 3.4.
Fields
countdown: u32The seconds to wait, COUNTDOWN_NOW for at once, or COUNTDOWN_CANCEL to
cancel. Three octets on the air.
DevRebootCountdownAns
The device’s answer, in the same three octets, section 3.4.
DevUpgradeImageReq
The server asking what upgrade image the device holds, section 3.5.
DevUpgradeImageAns
The device’s answer, which carries a version only for an image it can install.
Fields
status: UpImageStatusWhat the device makes of the image.
next_version: Option<u32>The version it would run, present only for UpImageStatus::Valid.
DevDeleteImageReq
The server asking the device to delete the image it holds, section 3.6.
DevDeleteImageAns(DeleteStatus)
The device’s answer, section 3.6.
Implementations§
Source§impl FirmwareCommand
impl FirmwareCommand
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<(FirmwareCommand, usize), LorawanError>
pub fn parse( direction: Direction, bytes: &[u8], ) -> Result<(FirmwareCommand, 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::firmware::FirmwareCommand;
use pamoja_lorawan::Direction;
// The server schedules a reboot in an hour.
let mut message = [0u8; 8];
let reboot = FirmwareCommand::DevRebootCountdownReq { countdown: 3_600 };
let written = reboot.encode(&mut message)?;
let (command, taken) = FirmwareCommand::parse(Direction::Downlink, &message[..written])?;
assert_eq!((command, taken), (reboot, 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::firmware::{FirmwareCommand, UpImageStatus};
let mut out = [0u8; 8];
let answer = FirmwareCommand::DevUpgradeImageAns {
status: UpImageStatus::None,
next_version: None,
};
assert_eq!(answer.encode(&mut out)?, 2, "a version rides only with a valid image");Trait Implementations§
Source§impl Clone for FirmwareCommand
impl Clone for FirmwareCommand
Source§fn clone(&self) -> FirmwareCommand
fn clone(&self) -> FirmwareCommand
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more