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; 0 counts as one hertz, as it does across budget.
§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 coding_rate_denominator(&self) -> u8

Returns the coding-rate denominator.

§Returns

The denominator, from 5 to 8, for coding rates 4/5 to 4/8.

Source

pub fn preamble_symbols(&self) -> u16

Returns the preamble length.

§Returns

The number of preamble symbols.

Source

pub fn explicit_header(&self) -> bool

Reports whether each frame carries an explicit header.

§Returns

true for an explicit header, false when the header is implicit.

Source

pub fn crc(&self) -> bool

Reports whether each frame carries a CRC.

§Returns

true when the frame CRC is on.

Source

pub fn low_data_rate_optimization(&self) -> bool

Reports whether the link uses low data rate optimization.

It is on when a symbol lasts longer than 16 ms, which is SF11 and SF12 at 125 kHz and SF12 at 250 kHz. The airtime assumes it, so a radio configured from these settings must enable it too.

§Returns

true when the symbol time exceeds 16 ms.

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. One LoRa frame carries at most 255; the count runs on past that for a caller who asks.
§Returns

The time on air in microseconds, held at u64::MAX rather than overflowing.

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: u64::MAX if the limit is zero, and 0 for a limit of 1000 or more, the whole of the time.

Source

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

Returns how many transmissions of a payload fit in an hour under a duty-cycle limit.

A transmission really costs its airtime plus the silence the limit forces after it, so this is the message budget a deployment plans against.

§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 number of whole transmissions an hour, or 0 when the limit is zero and so forbids transmitting.

§Examples
use pamoja_lora::LinkSettings;

// Ten bytes at SF12 hold the air for just under a second, and 1% of the time
// leaves room for thirty-six of them an hour.
let link = LinkSettings::new(12, 125_000);
assert_eq!(link.messages_per_hour(10, 10), 36);
assert_eq!(link.messages_per_hour(10, 0), 0);

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
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.