retry on failure
This commit is contained in:
+22
-8
@@ -166,15 +166,16 @@ fn main() -> ! {
|
||||
) {
|
||||
Ok(uid) => {
|
||||
info!("uid = {uid:?}");
|
||||
for i in (4..=231) {
|
||||
let result = pn532.process(&Request::ntag_read(i), 17, ms_1000).unwrap();
|
||||
let success = result.first().is_some_and(|x| *x == 0);
|
||||
if success {
|
||||
// info!("page {i}: {:02x?}", result);
|
||||
data.extend(&result[1..5]);
|
||||
} else {
|
||||
info!("err {i}: {:02x?}", result);
|
||||
for i in (0x0b..=230) {
|
||||
let mut parse_result = Err(());
|
||||
while parse_result.is_err() {
|
||||
let Ok(result) = pn532.process(&Request::ntag_read(i), 17, ms_1000) else {
|
||||
continue;
|
||||
};
|
||||
parse_result = parse_nfc(i, result);
|
||||
}
|
||||
let bytes = parse_result.unwrap();
|
||||
data.extend(bytes);
|
||||
}
|
||||
info!("Full data: {data:02x?}");
|
||||
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
|
||||
}
|
||||
|
||||
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 {
|
||||
// TODO Is that timer accurate enough?
|
||||
start: Instant,
|
||||
|
||||
Reference in New Issue
Block a user