Struct Device

Source
pub struct Device<R, C, T, G, const N: usize = 256, const D: usize = 1>
where R: PhyRxTx + Timings, T: Timer, C: CryptoFactory + Default, G: RngCore,
{ /* private fields */ }
Expand description

Type representing a LoRaWAN capable device.

A device is bound to the following types:

  • R: An asynchronous radio implementation
  • T: An asynchronous timer implementation
  • C: A CryptoFactory implementation
  • RNG: A random number generator implementation. An external RNG may be provided, or you may use a builtin PRNG by providing a random seed
  • N: The size of the radio buffer. Generally, this should be set to 256 to support the largest possible LoRa frames.
  • D: The amount of downlinks that may be buffered. This is used to support Class C operation. See below for more.

Note that the const generics N and D are used to configure the size of the radio buffer and the number of downlinks that may be buffered. The defaults are 256 and 1 respectively which should be fine for Class A devices. For Class C operation, it is recommended to increase D to at least 2, if not 3. This is because during the RX1/RX2 windows after a Class A transmit, it is possible to receive Class C downlinks (in additional to any RX1/RX2 responses!).

Implementations§

Source§

impl<R, C, T, const N: usize> Device<R, C, T, Prng, N>
where R: PhyRxTx + Timings, C: CryptoFactory + Default, T: Timer,

Source

pub fn new_with_seed( region: Configuration, radio: R, timer: T, seed: u64, ) -> Self

Create a new Device by providing your own random seed. Using this method, Device will internally use an algorithmic PRNG. Depending on your use case, this may or may not be faster than using your own hardware RNG.

§⚠️Warning⚠️

This function must always be called with a new randomly generated seed! Never call this function more than once using the same seed. Generate the seed using a true random number generator. Using the same seed will leave you vulnerable to replay attacks.

Source

pub fn new_with_seed_and_session( region: Configuration, radio: R, timer: T, seed: u64, session: Option<Session>, ) -> Self

Create a new Device by providing your own random seed. Also optionally provide your own Session. Using this method, Device will internally use an algorithmic PRNG to generate random numbers. Depending on your use case, this may or may not be faster than using your own hardware RNG.

§⚠️Warning⚠️

This function must always be called with a new randomly generated seed! Never call this function more than once using the same seed. Generate the seed using a true random number generator. Using the same seed will leave you vulnerable to replay attacks.

Source§

impl<R, C, T, G, const N: usize, const D: usize> Device<R, C, T, G, N, D>
where R: PhyRxTx + Timings, C: CryptoFactory + Default, T: Timer, G: RngCore,

Source

pub fn new(region: Configuration, radio: R, timer: T, rng: G) -> Self

Create a new instance of Device with a RNG external to the LoRa chip. You must provide your own RNG implementing RngCore.

See also new_with_seed to let Device use a builtin PRNG by providing a random seed.

Source

pub fn new_with_session( region: Configuration, radio: R, timer: T, rng: G, session: Option<Session>, ) -> Self

Create a new Device and provide an optional Session.

Source

pub fn enable_class_c(&mut self)

Enables Class C behavior. Note that Class C downlinks are not possible until a confirmed uplink is sent to the LNS.

Source

pub fn disable_class_c(&mut self)

Disables Class C behavior. Note that an uplink must be set for the radio to disable Class C listen.

Source

pub fn get_session(&mut self) -> Option<&Session>

Source

pub fn get_region(&mut self) -> &Configuration

Source

pub fn get_radio(&mut self) -> &R

Source

pub fn get_mut_radio(&mut self) -> &mut R

Source

pub fn get_datarate(&mut self) -> DR

Retrieve the current data rate being used by this device.

Source

pub fn set_datarate(&mut self, datarate: DR)

Set the data rate being used by this device. This overrides the region default.

Source

pub async fn join( &mut self, join_mode: &JoinMode, ) -> Result<JoinResponse, Error<R::PhyError>>

Join the LoRaWAN network asynchronously. The returned future completes when the LoRaWAN network has been joined successfully, or an error has occurred.

Repeatedly calling join using OTAA will result in a new LoRaWAN session to be created.

Note that for a Class C enabled device, you must repeatedly send confirmed uplink until LoRaWAN Network Server (LNS) confirmation after joining.

Source

pub async fn send( &mut self, data: &[u8], fport: u8, confirmed: bool, ) -> Result<SendResponse, Error<R::PhyError>>

Send data on a given port with the expected confirmation. If downlink data is provided, the data is copied into the provided byte slice.

The returned future completes when the data have been sent successfully and downlink data, if any, is available by calling take_downlink. Response::DownlinkReceived indicates a downlink is available.

In Class C mode, it is possible to get one or more downlinks and Reponse::DownlinkReceived maybe not even be indicated. It is recommended to call take_downlink after send until it returns None.

Take the downlink data from the device. This is typically called after a Response::DownlinkReceived is returned from send. This call consumes the downlink data. If no downlink data is available, None is returned.

Source

pub async fn rxc_listen(&mut self) -> Result<Response, Error<R::PhyError>>

When not involved in sending and RX1/RX2 windows, a class C configured device will be listening to RXC frames. The caller is expected to be awaiting this message at all times.

Auto Trait Implementations§

§

impl<R, C, T, G, const N: usize, const D: usize> Freeze for Device<R, C, T, G, N, D>
where R: Freeze, G: Freeze, T: Freeze,

§

impl<R, C, T, G, const N: usize, const D: usize> RefUnwindSafe for Device<R, C, T, G, N, D>

§

impl<R, C, T, G, const N: usize, const D: usize> Send for Device<R, C, T, G, N, D>
where R: Send, G: Send, T: Send, C: Send,

§

impl<R, C, T, G, const N: usize, const D: usize> Sync for Device<R, C, T, G, N, D>
where R: Sync, G: Sync, T: Sync, C: Sync,

§

impl<R, C, T, G, const N: usize, const D: usize> Unpin for Device<R, C, T, G, N, D>
where R: Unpin, G: Unpin, T: Unpin, C: Unpin,

§

impl<R, C, T, G, const N: usize, const D: usize> UnwindSafe for Device<R, C, T, G, N, D>

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