Skip to main content

Backoff

Struct Backoff 

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

A device’s count of how long the network has been silent.

§Examples

A 1.0.4 device that stops hearing its network, starting two rates above its default:

use pamoja_lorawan::adr::{Backoff, Standing};
use pamoja_lorawan::Version;

let mut backoff = Backoff::recommended(Version::V1_0_4);
let mut data_rate = 2;
let mut sent = 0;
let mut steps = Vec::new();

while sent < 200 {
    let step = backoff.uplink(Standing { default_data_rate: data_rate == 0 });
    sent += 1;
    if step.restore_power {
        steps.push((sent, "power"));
    }
    if step.lower_data_rate {
        data_rate -= 1;
        steps.push((sent, "rate"));
    }
    if step.restore_channels {
        steps.push((sent, "channels"));
    }
}

// Power a delay after the limit, then a rate every delay, then the channels.
assert_eq!(steps, [(96, "power"), (128, "rate"), (160, "rate"), (192, "channels")]);
assert!(!backoff.uplink(Standing { default_data_rate: true }).request_ack);

Implementations§

Source§

impl Backoff

Source

pub const fn recommended(version: Version) -> Backoff

A count from zero, with the limit and delay RP002-1.0.5 section 3.3 recommends for every region.

§Arguments
  • version - the revision whose steps to follow.
§Returns

The count, asking after ADR_ACK_LIMIT unanswered uplinks and stepping every ADR_ACK_DELAY after that.

§Examples
use pamoja_lorawan::adr::Backoff;
use pamoja_lorawan::Version;

assert_eq!(Backoff::recommended(Version::V1_0_4), Backoff::new(Version::V1_0_4, 64, 32));
Source

pub const fn new(version: Version, limit: u32, delay: u32) -> Backoff

A count from zero, with a limit and delay a device was commissioned with.

§Arguments
  • version - the revision whose steps to follow.
  • limit - how many unanswered uplinks before it starts asking.
  • delay - how many more before its first step, and between each step after that. Treated as one if given as zero, since a step every zero uplinks is not a thing a device can do.
§Returns

The count.

Counts one new uplink, and says what to do before sending it.

Call this once per uplink the frame counter moves for. A repeated transmission of the same uplink is not a new one and does not count, which is the same rule the frame counter itself follows.

§Arguments
  • standing - where the device stands against its defaults right now.
§Returns

Whether to ask the network for an answer, and which step, if any, this uplink takes.

§Examples
use pamoja_lorawan::adr::{Backoff, Standing};
use pamoja_lorawan::Version;

let mut backoff = Backoff::recommended(Version::V1_0_3);
let above = Standing { default_data_rate: false };
for _ in 0..63 {
    assert!(!backoff.uplink(above).request_ack);
}

// The sixty-fourth unanswered uplink is the one that starts asking.
assert!(backoff.uplink(above).request_ack);

Counts a Class A downlink, which proves the network still hears the device.

Any such downlink resets the count, whatever it carried; it does not need to acknowledge anything.

Source

pub const fn counter(&self) -> u32

How many uplinks have gone unanswered.

§Returns

The counter.

Source

pub const fn version(&self) -> Version

The revision whose steps this count follows.

§Returns

The revision.

Trait Implementations§

Source§

impl Clone for Backoff

Source§

fn clone(&self) -> Backoff

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 Backoff

Source§

impl Debug for Backoff

Source§

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

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

impl Eq for Backoff

Source§

impl PartialEq for Backoff

Source§

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

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.