From e3055f0829817c06cb5eb37e9f0027e14acdab97 Mon Sep 17 00:00:00 2001 From: fromost Date: Tue, 15 Sep 2026 18:32:56 +0800 Subject: [PATCH] Fix heapless vec Removed unused lorawan patch --- patches/lorawan-device+0.12.2.patch | 203 +----------------- .../src/protocol/felica/felica_lite_s/mod.rs | 23 +- src/components/card_reader.rs | 2 +- 3 files changed, 15 insertions(+), 213 deletions(-) diff --git a/patches/lorawan-device+0.12.2.patch b/patches/lorawan-device+0.12.2.patch index 317fcc6..9cf00b2 100644 --- a/patches/lorawan-device+0.12.2.patch +++ b/patches/lorawan-device+0.12.2.patch @@ -1,160 +1,8 @@ -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 + Sized + Unpin> { -+ enum RxcWindowResponse + Sized + Unpin> { - Rx(usize, RxQuality, F), - Timeout(u32), - } -@@ -318,7 +318,7 @@ where - timeout_fut: F, - ) -> RxcWindowResponse - where -- F: futures::Future + Sized + Unpin, -+ F: futures::Future + 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; -+crate::async_device::Device; - - #[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; - - impl ChannelRegion<7> -- for AS923Region -+for AS923Region - { - fn datarates() -> &'static [Option; 7] { - &DATARATES -@@ -20,7 +20,7 @@ impl ChannelRegion<7> - } - - impl DynamicChannelRegion<2, 7> -- for AS923Region -+for AS923Region - { - 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 +index 00f9a5d..33f545a 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, -- > DynamicChannelPlan -+ const NUM_JOIN_CHANNELS: usize, -+ const NUM_DATARATES: usize, -+ R: DynamicChannelRegion, -+> DynamicChannelPlan - { - fn get_channel(&self, channel: usize) -> Option { +@@ -55,7 +55,12 @@ impl< if channel < NUM_JOIN_CHANNELS { Some(R::join_channels()[channel]) } else { @@ -168,50 +16,3 @@ index 00f9a5d..3552dce 100644 } } -@@ -87,17 +92,17 @@ impl< - } - - pub(crate) trait DynamicChannelRegion: -- ChannelRegion -+ChannelRegion - { - fn join_channels() -> [u32; NUM_JOIN_CHANNELS]; - fn get_default_rx2() -> u32; - } - - impl< -- const NUM_JOIN_CHANNELS: usize, -- const NUM_DATARATES: usize, -- R: DynamicChannelRegion, -- > RegionHandler for DynamicChannelPlan -+ const NUM_JOIN_CHANNELS: usize, -+ const NUM_DATARATES: usize, -+ R: DynamicChannelRegion, -+> RegionHandler for DynamicChannelPlan - { - fn process_join_accept, 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::(&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::(&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 { diff --git a/pn532/src/protocol/felica/felica_lite_s/mod.rs b/pn532/src/protocol/felica/felica_lite_s/mod.rs index 7ead882..78df0df 100644 --- a/pn532/src/protocol/felica/felica_lite_s/mod.rs +++ b/pn532/src/protocol/felica/felica_lite_s/mod.rs @@ -76,22 +76,23 @@ where let mut wcnt = [0u8; 3]; wcnt.copy_from_slice(&wcnt_block[0][0..3]); + let block_code: u16 = block_code.into(); let maca_block_code: u16 = FelicaLiteSBlock::MACA.clone().into(); - let mut plain = heapless::Vec::::new(); - plain.extend(wcnt); - plain.push(block_code.clone().into() as u8).unwrap(); - plain.push(maca_block_code as u8).unwrap(); - plain.extend(*data); + let mut plain = [0u8; 24]; + plain[0..3].copy_from_slice(&wcnt); + plain[4] = block_code as u8; + plain[6] = maca_block_code as u8; + plain[8..24].copy_from_slice(data); - let mac = self.compute_write_mac(session, plain.into_array().unwrap()); + let mac = self.compute_write_mac(session, plain); - let mut mac_a = heapless::Vec::::new(); - mac_a.extend(mac); - mac_a.extend(wcnt); + let mut mac_a = [0u8; 16]; + mac_a[0..8].copy_from_slice(&mac); + mac_a[8..11].copy_from_slice(&wcnt); - let block_list = [block_code.into(), FelicaLiteSBlock::MACA as u16]; - let block_data = [*data, mac_a.into_array().unwrap()]; + let block_list = [block_code, FelicaLiteSBlock::MACA as u16]; + let block_data = [*data, mac_a]; self.write_block(card, block_list, &block_data) } diff --git a/src/components/card_reader.rs b/src/components/card_reader.rs index 036eea8..52336af 100644 --- a/src/components/card_reader.rs +++ b/src/components/card_reader.rs @@ -5,7 +5,7 @@ use embassy_time::{Delay, Timer}; use esp_hal::gpio; use esp_hal::rng::Trng; use pn532::types::felica::felica_lite_s::auth::{CardKey, CardKeyVersion}; -use pn532::types::felica::felica_lite_s::config::{MemoryConfig, RFParameter}; +use pn532::types::felica::felica_lite_s::config::RFParameter; use pn532::types::felica::{CardSession, FelicaLiteSBlock}; use pn532::Pn532;