Skip to main content

FirmwareCommand

Enum FirmwareCommand 

Source
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

§firmware: u32

The firmware the device is running.

§hardware: u32

The hardware it is running on.

§

DevRebootTimeReq

The server programming a reboot at a moment in time, section 3.3.

Fields

§reboot_time: u32

Seconds 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.

Fields

§reboot_time: u32

The seconds until the reboot.

§

DevRebootCountdownReq

The server programming a reboot after a delay, section 3.4.

Fields

§countdown: u32

The 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.

Fields

§countdown: u32

The seconds until the reboot.

§

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: UpImageStatus

What 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.

Fields

§version: u32

The version the server believes is there; a device that holds another refuses.

§

DevDeleteImageAns(DeleteStatus)

The device’s answer, section 3.6.

Implementations§

Source§

impl FirmwareCommand

Source

pub const fn cid(&self) -> u8

The identifier this command travels under.

§Returns

The identifier, 0x00 to 0x05.

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<(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));
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::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

Source§

fn clone(&self) -> FirmwareCommand

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 FirmwareCommand

Source§

impl Debug for FirmwareCommand

Source§

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

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

impl Eq for FirmwareCommand

Source§

impl Hash for FirmwareCommand

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 FirmwareCommand

Source§

fn eq(&self, other: &FirmwareCommand) -> 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 FirmwareCommand

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.