Skip to main content

DutyCycle

Struct DutyCycle 

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

The silence a radio owes after its transmissions under a duty-cycle limit.

Record each transmission with transmitted, then ask ready or wait_us before the next. A limit of zero forbids transmitting, and the guard never becomes ready.

§Examples

use pamoja_lora::LinkSettings;
use pamoja_radios::duty::DutyCycle;

// SF12 at 125 kHz under a 1% limit.
let link = LinkSettings::new(12, 125_000);
let mut guard = DutyCycle::new(10);
assert!(guard.ready(0));

// A ten-byte reading sent at time zero holds the channel for 991,232 us, and owes
// ninety-nine times that in silence.
assert_eq!(guard.transmitted(0, &link, 10), 991_232);
assert_eq!(guard.wait_us(0), 99_123_200);
assert!(!guard.ready(99_000_000));
assert!(guard.ready(99_123_200));

Implementations§

Source§

impl DutyCycle

Source

pub const fn new(permille: u32) -> Self

Creates a guard for a duty-cycle limit, ready to transmit at once.

§Arguments
  • permille - the limit in parts per thousand, so 10 is 1%; 0 forbids transmitting and 1000 or more imposes no silence.
§Returns

The guard.

Source

pub fn permille(&self) -> u32

Returns the limit the guard enforces.

§Returns

The limit in parts per thousand.

Source

pub fn earliest_us(&self) -> u64

Returns the earliest time the next transmission may start.

§Returns

A time in microseconds on the caller’s clock, or u64::MAX when the limit forbids transmitting.

Source

pub fn wait_us(&self, now_us: u64) -> u64

Returns how long the radio must still stay silent.

§Arguments
  • now_us - the current time in microseconds on the caller’s clock.
§Returns

The remaining silence in microseconds, zero when a transmission may start.

Source

pub fn ready(&self, now_us: u64) -> bool

Reports whether a transmission may start now.

§Arguments
  • now_us - the current time in microseconds on the caller’s clock.
§Returns

true once the silence the last transmission owed has passed.

Source

pub fn transmitted( &mut self, started_us: u64, link: &LinkSettings, payload_len: usize, ) -> u64

Records a transmission and the silence it owes.

§Arguments
  • started_us - when the transmission started, in microseconds on the caller’s clock.
  • link - the settings the frame was sent with.
  • payload_len - the payload length in bytes.
§Returns

The frame’s time on air in microseconds.

Trait Implementations§

Source§

impl Clone for DutyCycle

Source§

fn clone(&self) -> DutyCycle

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 DutyCycle

Source§

impl Debug for DutyCycle

Source§

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

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

impl Eq for DutyCycle

Source§

impl PartialEq for DutyCycle

Source§

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

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.