implement card storing
This commit is contained in:
+3
-3
@@ -1,14 +1,14 @@
|
||||
use core::fmt::Display;
|
||||
|
||||
use crate::card::model::NfcPayload;
|
||||
use crate::card::model::RawCard;
|
||||
use alloc::string::{String, ToString};
|
||||
|
||||
pub fn split_nfc_hex(payload: &[u8]) -> Option<NfcPayload> {
|
||||
pub fn split_nfc_hex(payload: &[u8]) -> Option<RawCard> {
|
||||
if payload.len() < 0x35A {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(NfcPayload {
|
||||
Some(RawCard {
|
||||
event_encoding: payload[0..2].try_into().ok()?,
|
||||
card_type: payload[2],
|
||||
card_uuid: payload[3..5].try_into().ok()?,
|
||||
|
||||
+3
-3
@@ -10,7 +10,7 @@ use binary_serde::BinarySerde;
|
||||
|
||||
#[derive(Debug, BinarySerde, PartialEq, Eq, Clone, Copy)]
|
||||
#[repr(C)]
|
||||
pub struct NfcPayload {
|
||||
pub struct RawCard {
|
||||
pub event_encoding: [u8; 2],
|
||||
pub card_type: u8,
|
||||
pub card_uuid: [u8; 2],
|
||||
@@ -238,10 +238,10 @@ pub struct Card {
|
||||
pub sprite: Sprite,
|
||||
}
|
||||
|
||||
impl<'a> TryFrom<NfcPayload> for Card {
|
||||
impl<'a> TryFrom<RawCard> for Card {
|
||||
type Error = &'static str;
|
||||
|
||||
fn try_from(payload: NfcPayload) -> Result<Self, Self::Error> {
|
||||
fn try_from(payload: RawCard) -> Result<Self, Self::Error> {
|
||||
let uuid: String = "empty for now".into(); //str::from_utf8(payload.card_uuid).unwrap().into();
|
||||
let event = decode_known_event(&payload.event_encoding);
|
||||
let cardtype = CardType::from(payload.card_type);
|
||||
|
||||
Reference in New Issue
Block a user