Add card detection
This commit is contained in:
@@ -0,0 +1,217 @@
|
||||
diff --git a/src/async_device/mod.rs b/src/async_device/mod.rs
|
||||
index 362c3b4..aac0e75 100644
|
||||
--- a/src/async_device/mod.rs
|
||||
+++ b/src/async_device/mod.rs
|
||||
@@ -305,7 +305,7 @@ where
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
- enum RxcWindowResponse<F: futures::Future<Output = ()> + Sized + Unpin> {
|
||||
+ enum RxcWindowResponse<F: futures::Future<Output=()> + Sized + Unpin> {
|
||||
Rx(usize, RxQuality, F),
|
||||
Timeout(u32),
|
||||
}
|
||||
@@ -318,7 +318,7 @@ where
|
||||
timeout_fut: F,
|
||||
) -> RxcWindowResponse<F>
|
||||
where
|
||||
- F: futures::Future<Output = ()> + Sized + Unpin,
|
||||
+ F: futures::Future<Output=()> + Sized + Unpin,
|
||||
R: radio::PhyRxTx + Timings,
|
||||
{
|
||||
let rx_fut = radio.rx_continuous(rx_buf.as_mut());
|
||||
@@ -356,7 +356,7 @@ where
|
||||
duration,
|
||||
timeout_fut,
|
||||
)
|
||||
- .await
|
||||
+ .await
|
||||
{
|
||||
RxcWindowResponse::Rx(sz, _, timeout_fut) => {
|
||||
log::debug!("RXC window received {} bytes.", sz);
|
||||
diff --git a/src/async_device/test/mod.rs b/src/async_device/test/mod.rs
|
||||
index 4d8c9b4..e90ba2d 100644
|
||||
--- a/src/async_device/test/mod.rs
|
||||
+++ b/src/async_device/test/mod.rs
|
||||
@@ -18,7 +18,7 @@ mod util;
|
||||
use util::{setup, setup_with_session, setup_with_session_class_c};
|
||||
|
||||
type Device =
|
||||
- crate::async_device::Device<TestRadio, DefaultFactory, TestTimer, rand_core::OsRng, 512, 4>;
|
||||
+crate::async_device::Device<TestRadio, DefaultFactory, TestTimer, rand_core::OsRng, 512, 4>;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_join_rx1() {
|
||||
diff --git a/src/async_device/test/radio.rs b/src/async_device/test/radio.rs
|
||||
index e0be1d3..827a408 100644
|
||||
--- a/src/async_device/test/radio.rs
|
||||
+++ b/src/async_device/test/radio.rs
|
||||
@@ -1,4 +1,3 @@
|
||||
-use super::*;
|
||||
use crate::async_device::radio::{PhyRxTx, RxConfig, RxStatus};
|
||||
use std::sync::Arc;
|
||||
use tokio::{
|
||||
diff --git a/src/async_device/test/util.rs b/src/async_device/test/util.rs
|
||||
index d289d32..c758271 100644
|
||||
--- a/src/async_device/test/util.rs
|
||||
+++ b/src/async_device/test/util.rs
|
||||
@@ -1,4 +1,4 @@
|
||||
-use super::{get_dev_addr, get_key, radio::*, region, timer::*, Device, SendResponse};
|
||||
+use super::{get_dev_addr, get_key, region, Device, SendResponse};
|
||||
|
||||
use crate::mac::Session;
|
||||
use crate::test_util::handle_class_c_uplink_after_join;
|
||||
diff --git a/src/lib.rs b/src/lib.rs
|
||||
index ad1ddda..539a0ed 100644
|
||||
--- a/src/lib.rs
|
||||
+++ b/src/lib.rs
|
||||
@@ -48,7 +48,7 @@ pub struct Downlink {
|
||||
#[cfg(feature = "defmt")]
|
||||
impl defmt::Format for Downlink {
|
||||
fn format(&self, f: defmt::Formatter) {
|
||||
- defmt::write!(f, "Downlink {{ fport: {}, data: ", self.fport,);
|
||||
+ defmt::write!(f, "Downlink {{ fport: {}, data: ", self.fport, );
|
||||
|
||||
for byte in self.data.iter() {
|
||||
defmt::write!(f, "{:02x}", byte);
|
||||
diff --git a/src/mac/session.rs b/src/mac/session.rs
|
||||
index 6ff62fa..d946a1f 100644
|
||||
--- a/src/mac/session.rs
|
||||
+++ b/src/mac/session.rs
|
||||
@@ -60,7 +60,7 @@ impl Session {
|
||||
decrypt.dev_addr().as_ref()[2],
|
||||
decrypt.dev_addr().as_ref()[3],
|
||||
])
|
||||
- .unwrap(),
|
||||
+ .unwrap(),
|
||||
)
|
||||
}
|
||||
|
||||
diff --git a/src/nb_device/test/mod.rs b/src/nb_device/test/mod.rs
|
||||
index 51cd67f..0430947 100644
|
||||
--- a/src/nb_device/test/mod.rs
|
||||
+++ b/src/nb_device/test/mod.rs
|
||||
@@ -1,7 +1,5 @@
|
||||
use super::*;
|
||||
mod util;
|
||||
-use crate::test_util::*;
|
||||
-use util::*;
|
||||
|
||||
use crate::nb_device::Event;
|
||||
#[test]
|
||||
diff --git a/src/nb_device/test/util.rs b/src/nb_device/test/util.rs
|
||||
index 6d1e12c..ab676be 100644
|
||||
--- a/src/nb_device/test/util.rs
|
||||
+++ b/src/nb_device/test/util.rs
|
||||
@@ -1,11 +1,9 @@
|
||||
-use super::*;
|
||||
use crate::radio::{RfConfig, RxQuality};
|
||||
|
||||
use crate::nb_device::{
|
||||
radio::{Event, PhyRxTx, Response},
|
||||
Device, Timings,
|
||||
};
|
||||
-use crate::test_util::*;
|
||||
use lorawan::default_crypto;
|
||||
use region::{Configuration, Region};
|
||||
|
||||
diff --git a/src/region/dynamic_channel_plans/as923.rs b/src/region/dynamic_channel_plans/as923.rs
|
||||
index 4a48b67..9fb571d 100644
|
||||
--- a/src/region/dynamic_channel_plans/as923.rs
|
||||
+++ b/src/region/dynamic_channel_plans/as923.rs
|
||||
@@ -12,7 +12,7 @@ pub(crate) type AS923_4 = DynamicChannelPlan<2, 7, AS923Region<917_300_000, 5900
|
||||
pub struct AS923Region<const DEFAULT_RX2: u32, const O: u32>;
|
||||
|
||||
impl<const DEFAULT_RX2: u32, const OFFSET: u32> ChannelRegion<7>
|
||||
- for AS923Region<DEFAULT_RX2, OFFSET>
|
||||
+for AS923Region<DEFAULT_RX2, OFFSET>
|
||||
{
|
||||
fn datarates() -> &'static [Option<Datarate>; 7] {
|
||||
&DATARATES
|
||||
@@ -20,7 +20,7 @@ impl<const DEFAULT_RX2: u32, const OFFSET: u32> ChannelRegion<7>
|
||||
}
|
||||
|
||||
impl<const DEFAULT_RX2: u32, const OFFSET: u32> DynamicChannelRegion<2, 7>
|
||||
- for AS923Region<DEFAULT_RX2, OFFSET>
|
||||
+for AS923Region<DEFAULT_RX2, OFFSET>
|
||||
{
|
||||
fn join_channels() -> [u32; 2] {
|
||||
[JOIN_CHANNELS[0] + OFFSET, JOIN_CHANNELS[1] + OFFSET]
|
||||
diff --git a/src/region/dynamic_channel_plans/mod.rs b/src/region/dynamic_channel_plans/mod.rs
|
||||
index 00f9a5d..3552dce 100644
|
||||
--- a/src/region/dynamic_channel_plans/mod.rs
|
||||
+++ b/src/region/dynamic_channel_plans/mod.rs
|
||||
@@ -46,16 +46,21 @@ pub(crate) struct DynamicChannelPlan<
|
||||
}
|
||||
|
||||
impl<
|
||||
- const NUM_JOIN_CHANNELS: usize,
|
||||
- const NUM_DATARATES: usize,
|
||||
- R: DynamicChannelRegion<NUM_JOIN_CHANNELS, NUM_DATARATES>,
|
||||
- > DynamicChannelPlan<NUM_JOIN_CHANNELS, NUM_DATARATES, R>
|
||||
+ const NUM_JOIN_CHANNELS: usize,
|
||||
+ const NUM_DATARATES: usize,
|
||||
+ R: DynamicChannelRegion<NUM_JOIN_CHANNELS, NUM_DATARATES>,
|
||||
+> DynamicChannelPlan<NUM_JOIN_CHANNELS, NUM_DATARATES, R>
|
||||
{
|
||||
fn get_channel(&self, channel: usize) -> Option<u32> {
|
||||
if channel < NUM_JOIN_CHANNELS {
|
||||
Some(R::join_channels()[channel])
|
||||
} else {
|
||||
- self.additional_channels[channel - NUM_JOIN_CHANNELS]
|
||||
+ let index = channel - NUM_JOIN_CHANNELS;
|
||||
+ if index < self.additional_channels.len() {
|
||||
+ self.additional_channels[index]
|
||||
+ } else {
|
||||
+ None
|
||||
+ }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,17 +92,17 @@ impl<
|
||||
}
|
||||
|
||||
pub(crate) trait DynamicChannelRegion<const NUM_JOIN_CHANNELS: usize, const NUM_DATARATES: usize>:
|
||||
- ChannelRegion<NUM_DATARATES>
|
||||
+ChannelRegion<NUM_DATARATES>
|
||||
{
|
||||
fn join_channels() -> [u32; NUM_JOIN_CHANNELS];
|
||||
fn get_default_rx2() -> u32;
|
||||
}
|
||||
|
||||
impl<
|
||||
- const NUM_JOIN_CHANNELS: usize,
|
||||
- const NUM_DATARATES: usize,
|
||||
- R: DynamicChannelRegion<NUM_JOIN_CHANNELS, NUM_DATARATES>,
|
||||
- > RegionHandler for DynamicChannelPlan<NUM_JOIN_CHANNELS, NUM_DATARATES, R>
|
||||
+ const NUM_JOIN_CHANNELS: usize,
|
||||
+ const NUM_DATARATES: usize,
|
||||
+ R: DynamicChannelRegion<NUM_JOIN_CHANNELS, NUM_DATARATES>,
|
||||
+> RegionHandler for DynamicChannelPlan<NUM_JOIN_CHANNELS, NUM_DATARATES, R>
|
||||
{
|
||||
fn process_join_accept<T: AsRef<[u8]>, C>(
|
||||
&mut self,
|
||||
diff --git a/src/region/fixed_channel_plans/join_channels.rs b/src/region/fixed_channel_plans/join_channels.rs
|
||||
index 297cce3..d0ee5e1 100644
|
||||
--- a/src/region/fixed_channel_plans/join_channels.rs
|
||||
+++ b/src/region/fixed_channel_plans/join_channels.rs
|
||||
@@ -330,8 +330,7 @@ mod test {
|
||||
buf.clear();
|
||||
buf.extend_from_slice(&rx_buf[..len]).unwrap();
|
||||
let response = mac.handle_rx::<DefaultFactory, 255, 3>(&mut buf, &mut downlinks);
|
||||
- if let Response::JoinSuccess = response {
|
||||
- } else {
|
||||
+ if let Response::JoinSuccess = response {} else {
|
||||
panic!("Did not receive join success");
|
||||
}
|
||||
let (tx_config, _len) = mac
|
||||
@@ -391,8 +390,7 @@ mod test {
|
||||
buf.clear();
|
||||
buf.extend_from_slice(&rx_buf[..len]).unwrap();
|
||||
let response = mac.handle_rx::<DefaultFactory, 255, 3>(&mut buf, &mut downlinks);
|
||||
- if let Response::JoinSuccess = response {
|
||||
- } else {
|
||||
+ if let Response::JoinSuccess = response {} else {
|
||||
panic!("Did not receive JoinSuccess")
|
||||
}
|
||||
for _ in 0..8 {
|
||||
Reference in New Issue
Block a user