lorawan_device/region/fixed_channel_plans/us915/mod.rs
1use super::*;
2
3mod frequencies;
4use frequencies::*;
5
6mod datarates;
7use datarates::*;
8
9const US_DBM: i8 = 21;
10const DEFAULT_RX2: u32 = 923_300_000;
11
12/// State struct for the `US915` region. This struct may be created directly if you wish to fine-tune some parameters.
13/// At this time specifying a bias for the subband used during the join process is supported using
14/// [`set_join_bias`](Self::set_join_bias) and [`set_join_bias_and_noncompliant_retries`](Self::set_join_bias_and_noncompliant_retries)
15/// is suppored. This struct can then be turned into a [`Configuration`] as it implements [`Into<Configuration>`].
16///
17/// # Note:
18///
19/// Only [`US915`] and [`AU915`] can be created using this method, because they are the only ones which have
20/// parameters that may be fine-tuned at the region level. To create a [`Configuration`] for other regions, use
21/// [`Configuration::new`] and specify the region using the [`Region`] enum.
22///
23/// # Example: Setting up join bias
24///
25/// ```
26/// use lorawan_device::region::{Configuration, US915, Subband};
27///
28/// let mut us915 = US915::new();
29/// // Subband 2 is commonly used for The Things Network.
30/// us915.set_join_bias(Subband::_2);
31/// let configuration: Configuration = us915.into();
32/// ```
33#[derive(Default, Clone)]
34pub struct US915(pub(crate) FixedChannelPlan<14, US915Region>);
35
36impl US915 {
37 pub fn get_max_payload_length(datarate: DR, repeater_compatible: bool, dwell_time: bool) -> u8 {
38 US915Region::get_max_payload_length(datarate, repeater_compatible, dwell_time)
39 }
40}
41
42#[derive(Default, Clone)]
43pub(crate) struct US915Region;
44
45impl ChannelRegion<14> for US915Region {
46 fn datarates() -> &'static [Option<Datarate>; 14] {
47 &DATARATES
48 }
49}
50
51impl FixedChannelRegion<14> for US915Region {
52 fn uplink_channels() -> &'static [u32; 72] {
53 &UPLINK_CHANNEL_MAP
54 }
55 fn downlink_channels() -> &'static [u32; 8] {
56 &DOWNLINK_CHANNEL_MAP
57 }
58 fn get_default_rx2() -> u32 {
59 DEFAULT_RX2
60 }
61 fn get_rx_datarate(tx_datarate: DR, _frame: &Frame, window: &Window) -> Datarate {
62 let datarate = match window {
63 Window::_1 => {
64 // no support for RX1 DR Offset
65 match tx_datarate {
66 DR::_0 => DR::_10,
67 DR::_1 => DR::_11,
68 DR::_2 => DR::_12,
69 DR::_3 => DR::_13,
70 DR::_4 => DR::_13,
71 _ => panic!("Invalid TX datarate"),
72 }
73 }
74 Window::_2 => DR::_8,
75 };
76 DATARATES[datarate as usize].clone().unwrap()
77 }
78 fn get_dbm() -> i8 {
79 US_DBM
80 }
81}