Skip to main content

LinkSettings

Struct LinkSettings 

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

The radio settings of a LoRa link, enough to compute its time-on-air.

A LoRa transmission’s duration is fixed by the spreading factor, the bandwidth, the coding rate, and the frame options, not by the data itself beyond its length. This struct gathers those settings and computes the two numbers a long-range deployment lives by: the airtime of a payload, and the off time a duty-cycle limit then forces before the next transmission.

A higher spreading factor reaches much further but spends far longer on air, so the same payload that takes tens of milliseconds at SF7 can take most of a second at SF12, with a correspondingly longer mandatory silence. The arithmetic is exact and integer-only, so it runs on the smallest node.

§Examples

use pamoja_lora::LinkSettings;

// The default European long-range setup: SF12, 125 kHz, coding rate 4/5.
let link = LinkSettings::new(12, 125_000);

// A 10-byte payload takes just under a second on air at SF12.
assert_eq!(link.airtime_us(10), 991_232);

Implementations§

Source§

impl LinkSettings

Source

pub fn new(spreading_factor: u8, bandwidth_hz: u32) -> Self

Creates link settings from a spreading factor and bandwidth, with LoRa defaults.

The defaults are coding rate 4/5, an 8-symbol preamble, an explicit header, and CRC on, matching a typical uplink.

§Arguments
  • spreading_factor - the spreading factor; clamped to the LoRa range 5 to 12. SF5 and SF6 carry the data rates RP002-1.0.5 added to several regions.
  • bandwidth_hz - the channel bandwidth in hertz, such as 125_000.
§Returns

The link settings.

Source

pub fn with_coding_rate(self, denominator: u8) -> Self

Sets the coding rate by its denominator, from 4/5 to 4/8.

§Arguments
  • denominator - the coding-rate denominator, clamped to 5 to 8 for 4/5 to 4/8.
§Returns

The updated settings, for chaining.

Source

pub fn with_preamble(self, symbols: u16) -> Self

Sets the number of preamble symbols.

§Arguments
  • symbols - the preamble length in symbols; the LoRa default is 8.
§Returns

The updated settings, for chaining.

Source

pub fn implicit_header(self) -> Self

Uses an implicit header, which omits the header symbols from each frame.

§Returns

The updated settings, for chaining.

Source

pub fn without_crc(self) -> Self

Turns the frame CRC off.

§Returns

The updated settings, for chaining.

Source

pub fn spreading_factor(&self) -> u8

Returns the spreading factor.

§Returns

The spreading factor, from 5 to 12.

Source

pub fn bandwidth_hz(&self) -> u32

Returns the channel bandwidth in hertz.

§Returns

The bandwidth in hertz.

Source

pub fn symbol_time_us(&self) -> u64

Returns the duration of one symbol in microseconds.

§Returns

The symbol time, 2^spreading_factor / bandwidth, in microseconds.

Source

pub fn airtime_us(&self, payload_len: usize) -> u64

Returns the time on air of a payload in microseconds.

This is the channel occupancy the transmission costs: how long the radio holds the air, which sets both the duty-cycle budget and a large part of the energy the transmission spends.

§Arguments
  • payload_len - the payload length in bytes.
§Returns

The time on air in microseconds.

Source

pub fn min_off_time_us( &self, payload_len: usize, duty_cycle_permille: u32, ) -> u64

Returns the minimum silence after a transmission to honor a duty-cycle limit.

A duty-cycle limit caps the fraction of time a node may transmit, so after a transmission of a given airtime the node must stay quiet for long enough that the airtime is no more than that fraction of the whole cycle.

§Arguments
  • payload_len - the payload length in bytes.
  • duty_cycle_permille - the duty-cycle limit in parts per thousand, so 10 is 1%.
§Returns

The required off time in microseconds, or u64::MAX if the limit is zero.

Trait Implementations§

Source§

impl Clone for LinkSettings

Source§

fn clone(&self) -> LinkSettings

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 LinkSettings

Source§

impl Debug for LinkSettings

Source§

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

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

impl Eq for LinkSettings

Source§

impl PartialEq for LinkSettings

Source§

fn eq(&self, other: &LinkSettings) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for LinkSettings

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