nfc read: print error instead of panic on invalid data
This commit is contained in:
+10
-6
@@ -16,7 +16,7 @@ use creaturedex::drivers::nfc_pn532::NfcPn532Driver;
|
|||||||
use creaturedex::navigation::inputs::Inputs;
|
use creaturedex::navigation::inputs::Inputs;
|
||||||
use creaturedex::navigation::navigation::{self, CARD_DATA};
|
use creaturedex::navigation::navigation::{self, CARD_DATA};
|
||||||
use creaturedex::network::wifi::setup_wifi;
|
use creaturedex::network::wifi::setup_wifi;
|
||||||
use creaturedex::storage::cardstore::{CardStore, CardStoreError};
|
use creaturedex::storage::cardstore::CardStore;
|
||||||
use creaturedex::storage::store::Store;
|
use creaturedex::storage::store::Store;
|
||||||
use embassy_executor::Spawner;
|
use embassy_executor::Spawner;
|
||||||
use embassy_time::Instant;
|
use embassy_time::Instant;
|
||||||
@@ -108,7 +108,7 @@ async fn main(spawner: Spawner) {
|
|||||||
let store = Store::new(peripherals.FLASH).expect("Could not initialize Flash Store");
|
let store = Store::new(peripherals.FLASH).expect("Could not initialize Flash Store");
|
||||||
let card_store = CardStore::new(store).expect("Could not initialize Card Store");
|
let card_store = CardStore::new(store).expect("Could not initialize Card Store");
|
||||||
|
|
||||||
let mut rtc = Rtc::new(peripherals.LPWR);
|
let rtc = Rtc::new(peripherals.LPWR);
|
||||||
//setup_wifi(peripherals.WIFI, peripherals.FLASH, &spawner).await;
|
//setup_wifi(peripherals.WIFI, peripherals.FLASH, &spawner).await;
|
||||||
|
|
||||||
let mut nfc_driver = NfcPn532Driver::new(AtomicDevice::new(shared_i2c));
|
let mut nfc_driver = NfcPn532Driver::new(AtomicDevice::new(shared_i2c));
|
||||||
@@ -150,10 +150,14 @@ async fn nfc_driver_task(
|
|||||||
log::error!("Failed to split NFC card data");
|
log::error!("Failed to split NFC card data");
|
||||||
continue;
|
continue;
|
||||||
};
|
};
|
||||||
CARD_DATA
|
let card = match Card::try_from(split_data) {
|
||||||
.lock()
|
Ok(card) => card,
|
||||||
.await
|
Err(err) => {
|
||||||
.replace(Card::try_from(split_data).expect("Invalid card data"));
|
log::error!("Invalid card data: {err}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
CARD_DATA.lock().await.replace(card);
|
||||||
|
|
||||||
match card_store.save_raw_card(split_data, rtc.current_time_us()) {
|
match card_store.save_raw_card(split_data, rtc.current_time_us()) {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
|
|||||||
Reference in New Issue
Block a user