lorawan_device/
lib.rs

1#![cfg_attr(not(test), no_std)]
2#![cfg_attr(docsrs, feature(doc_cfg))]
3
4//! ## Feature flags
5#![doc = document_features::document_features!(feature_label = r#"<span class="stab portability"><code>{feature}</code></span>"#)]
6#![doc = include_str!("../README.md")]
7
8use core::default::Default;
9use heapless::Vec;
10
11mod radio;
12
13pub mod mac;
14use mac::NetworkCredentials;
15
16pub mod region;
17pub use region::Region;
18
19#[cfg(test)]
20mod test_util;
21
22pub mod async_device;
23
24pub mod nb_device;
25use nb_device::state::State;
26
27use core::marker::PhantomData;
28#[cfg(feature = "default-crypto")]
29#[cfg_attr(docsrs, doc(cfg(feature = "default-crypto")))]
30pub use lorawan::default_crypto;
31pub use lorawan::{
32    keys::{AppEui, AppKey, AppSKey, CryptoFactory, DevEui, NewSKey},
33    parser::DevAddr,
34};
35
36pub use rand_core::RngCore;
37mod rng;
38pub use rng::Prng;
39
40mod log;
41
42/// Provides the application payload and FPort of a downlink message.
43pub struct Downlink {
44    pub data: Vec<u8, 256>,
45    pub fport: u8,
46}
47
48#[cfg(feature = "defmt")]
49impl defmt::Format for Downlink {
50    fn format(&self, f: defmt::Formatter) {
51        defmt::write!(f, "Downlink {{ fport: {}, data: ", self.fport,);
52
53        for byte in self.data.iter() {
54            defmt::write!(f, "{:02x}", byte);
55        }
56        defmt::write!(f, " }}")
57    }
58}
59
60/// Allows to fine-tune the beginning and end of the receive windows for a specific board.
61pub trait Timings {
62    /// The offset in milliseconds from the beginning of the receive windows. For example, settings this to 100
63    /// tell the LoRaWAN stack to begin configuring the receive window 100 ms before the window needs to start.
64    fn get_rx_window_offset_ms(&self) -> i32;
65
66    /// How long to leave the receive window open in milliseconds. For example, if offset was set to 100 and duration
67    /// was set to 200, the window would be open 100 ms before and close 100 ms after the target time.
68    fn get_rx_window_duration_ms(&self) -> u32;
69}
70
71#[derive(Debug, Clone, Copy, PartialEq, Eq)]
72#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
73/// Join the network using either OTAA or ABP.
74pub enum JoinMode {
75    OTAA { deveui: DevEui, appeui: AppEui, appkey: AppKey },
76    ABP { newskey: NewSKey, appskey: AppSKey, devaddr: DevAddr<[u8; 4]> },
77}