From 2104f4f33ce6e8cb2620cc37095f7eb91621bf76 Mon Sep 17 00:00:00 2001 From: Andreas Neuhaus Date: Thu, 19 Dec 2024 13:25:03 +0100 Subject: [PATCH] Support to write NFC uids directly to JSON --- firmware/src/nfc.rs | 12 ++++++++++++ firmware/src/telemetry.rs | 5 ++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/firmware/src/nfc.rs b/firmware/src/nfc.rs index c37ed52..c414e63 100644 --- a/firmware/src/nfc.rs +++ b/firmware/src/nfc.rs @@ -1,6 +1,8 @@ // Use custom pn532 driver instead of pn532 crate use crate::pn532; +use crate::json::{self, ToJson}; +use alloc::string::ToString; use const_hex::FromHex; use core::convert::Infallible; use core::fmt::{self, Debug}; @@ -8,6 +10,7 @@ use core::str::FromStr; use embassy_time::{Duration, Timer}; use embedded_hal_async::digital::Wait; use embedded_hal_async::i2c::I2c; +use embedded_io_async::Write; use log::{debug, info, warn}; use pn532::{Error as Pn532Error, I2CInterfaceWithIrq, Pn532, Request, SAMMode}; @@ -267,3 +270,12 @@ impl AsRef<[u8]> for Uid { } } } + +impl ToJson for Uid { + async fn to_json( + &self, + json: &mut json::Writer, + ) -> Result<(), json::Error> { + json.write(self.to_string()).await + } +} diff --git a/firmware/src/telemetry.rs b/firmware/src/telemetry.rs index d05f6b1..410e92e 100644 --- a/firmware/src/telemetry.rs +++ b/firmware/src/telemetry.rs @@ -2,7 +2,6 @@ use crate::http::Http; use crate::mixpanel::{self, Mixpanel}; use crate::{article, json, nfc, user}; use alloc::collections::VecDeque; -use alloc::string::ToString; use embassy_time::{Duration, Instant}; use embedded_io_async::Write; use log::{debug, info, warn}; @@ -72,10 +71,10 @@ impl Event { .await?; } Event::AuthenticationFailed(uid) => { - object.field("uid", uid.to_string()).await?; + object.field("uid", uid).await?; } Event::UserAuthenticated(_user_id, uid) => { - object.field("uid", uid.to_string()).await?; + object.field("uid", uid).await?; } Event::ArticlePurchased(_user_id, article_id, amount, total_price) => { object