Compare commits
2
Commits
c8ea94a3ca
...
rust-nfc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
78fc70bd31
|
||
|
|
76dc34b115
|
Generated
+30
@@ -125,6 +125,7 @@ dependencies = [
|
|||||||
"esp-rtos",
|
"esp-rtos",
|
||||||
"ili9341",
|
"ili9341",
|
||||||
"log",
|
"log",
|
||||||
|
"ndef",
|
||||||
"pn532",
|
"pn532",
|
||||||
"smoltcp",
|
"smoltcp",
|
||||||
]
|
]
|
||||||
@@ -255,6 +256,26 @@ dependencies = [
|
|||||||
"syn 2.0.119",
|
"syn 2.0.119",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "derive_more"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4a9b99b9cbbe49445b21764dc0625032a89b145a2642e67603e1c936f5458d05"
|
||||||
|
dependencies = [
|
||||||
|
"derive_more-impl",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "derive_more-impl"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cb7330aeadfbe296029522e6c40f315320aba36fc43a5b3632f3795348f3bd22"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 2.0.119",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "digest"
|
name = "digest"
|
||||||
version = "0.10.7"
|
version = "0.10.7"
|
||||||
@@ -1186,6 +1207,15 @@ version = "1.1.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d"
|
checksum = "8d5439c4ad607c3c23abf66de8c8bf57ba8adcd1f129e699851a6e43935d339d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ndef"
|
||||||
|
version = "0.5.0"
|
||||||
|
dependencies = [
|
||||||
|
"derive_more",
|
||||||
|
"heapless 0.8.0",
|
||||||
|
"rustversion",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "num-derive"
|
name = "num-derive"
|
||||||
version = "0.4.2"
|
version = "0.4.2"
|
||||||
|
|||||||
@@ -52,6 +52,7 @@ embedded-hal-bus = "0.3.0"
|
|||||||
embedded-graphics = "0.8.2"
|
embedded-graphics = "0.8.2"
|
||||||
embedded-graphics-core = "0.4.1"
|
embedded-graphics-core = "0.4.1"
|
||||||
pn532 = "0.5.0"
|
pn532 = "0.5.0"
|
||||||
|
ndef = { version = "0.5.0", path = "./ndef-rs" }
|
||||||
|
|
||||||
|
|
||||||
# For fine tuning these settings, please refer to https://doc.rust-lang.org/cargo/reference/profiles.html
|
# For fine tuning these settings, please refer to https://doc.rust-lang.org/cargo/reference/profiles.html
|
||||||
|
|||||||
+26
-8
@@ -166,17 +166,22 @@ fn main() -> ! {
|
|||||||
) {
|
) {
|
||||||
Ok(uid) => {
|
Ok(uid) => {
|
||||||
info!("uid = {uid:?}");
|
info!("uid = {uid:?}");
|
||||||
for i in (4..=231) {
|
for i in (0x04..=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?}");
|
||||||
|
match ndef::Message::try_from(&data[4..4 + 883]) {
|
||||||
|
Ok(m) => info!("Parsed: {m:02x?}"),
|
||||||
|
Err(e) => info!("Failed to parse: {e:?}"),
|
||||||
|
}
|
||||||
data.clear();
|
data.clear();
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@@ -191,6 +196,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,
|
||||||
|
|||||||
Reference in New Issue
Block a user