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
impl Backoff
Sourcepub const fn recommended(version: Version) -> Backoff
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));Sourcepub const fn new(version: Version, limit: u32, delay: u32) -> Backoff
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.
Sourcepub fn uplink(&mut self, standing: Standing) -> Step
pub fn uplink(&mut self, standing: Standing) -> Step
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);Sourcepub fn downlink(&mut self)
pub fn downlink(&mut self)
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.