pub struct Device<R, C, T, G, const N: usize = 256, const D: usize = 1>{ /* 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>
impl<R, C, T, const N: usize> Device<R, C, T, Prng, N>
Sourcepub fn new_with_seed(
region: Configuration,
radio: R,
timer: T,
seed: u64,
) -> Self
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.
Sourcepub fn new_with_seed_and_session(
region: Configuration,
radio: R,
timer: T,
seed: u64,
session: Option<Session>,
) -> Self
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>
impl<R, C, T, G, const N: usize, const D: usize> Device<R, C, T, G, N, D>
Sourcepub fn new(region: Configuration, radio: R, timer: T, rng: G) -> Self
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.
Sourcepub fn new_with_session(
region: Configuration,
radio: R,
timer: T,
rng: G,
session: Option<Session>,
) -> Self
pub fn new_with_session( region: Configuration, radio: R, timer: T, rng: G, session: Option<Session>, ) -> Self
Sourcepub fn enable_class_c(&mut self)
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.
Sourcepub fn disable_class_c(&mut self)
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.
pub fn get_session(&mut self) -> Option<&Session>
pub fn get_region(&mut self) -> &Configuration
pub fn get_radio(&mut self) -> &R
pub fn get_mut_radio(&mut self) -> &mut R
Sourcepub fn get_datarate(&mut self) -> DR
pub fn get_datarate(&mut self) -> DR
Retrieve the current data rate being used by this device.
Sourcepub fn set_datarate(&mut self, datarate: DR)
pub fn set_datarate(&mut self, datarate: DR)
Set the data rate being used by this device. This overrides the region default.
Sourcepub async fn join(
&mut self,
join_mode: &JoinMode,
) -> Result<JoinResponse, Error<R::PhyError>>
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.
Sourcepub async fn send(
&mut self,
data: &[u8],
fport: u8,
confirmed: bool,
) -> Result<SendResponse, Error<R::PhyError>>
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.
Sourcepub fn take_downlink(&mut self) -> Option<Downlink>
pub fn take_downlink(&mut self) -> Option<Downlink>
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.