retry on failure

This commit is contained in:
2026-07-31 23:20:55 +02:00
parent c8ea94a3ca
commit 76dc34b115
+22 -8
View File
@@ -166,15 +166,16 @@ fn main() -> ! {
) { ) {
Ok(uid) => { Ok(uid) => {
info!("uid = {uid:?}"); info!("uid = {uid:?}");
for i in (4..=231) { for i in (0x0b..=230) {
let result = pn532.process(&Request::ntag_read(i), 17, ms_1000).unwrap(); let mut parse_result = Err(());
let success = result.first().is_some_and(|x| *x == 0); while parse_result.is_err() {
if success { let Ok(result) = pn532.process(&Request::ntag_read(i), 17, ms_1000) else {
// info!("page {i}: {:02x?}", result); continue;
data.extend(&result[1..5]); };
} else { parse_result = parse_nfc(i, result);
info!("err {i}: {:02x?}", result);
} }
let bytes = parse_result.unwrap();
data.extend(bytes);
} }
info!("Full data: {data:02x?}"); info!("Full data: {data:02x?}");
data.clear(); data.clear();
@@ -191,6 +192,19 @@ fn main() -> ! {
// for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.1.0/examples // for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.1.0/examples
} }
fn parse_nfc(iteration: u8, bytes: &[u8]) -> Result<[u8; 4], ()> {
let success = bytes.first().is_some_and(|x| *x == 0);
if success {
// info!("page {i}: {:02x?}", result);
let mut arr = [0; 4];
arr.copy_from_slice(&bytes[1..5]);
Ok(arr)
} else {
info!("err {iteration}: {:02x?}", bytes);
Err(())
}
}
struct TimerWrapper { struct TimerWrapper {
// TODO Is that timer accurate enough? // TODO Is that timer accurate enough?
start: Instant, start: Instant,