-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
402 additions
and
20 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
use crate::nfc::Uid; | ||
use alloc::collections::BTreeMap; | ||
use alloc::string::String; | ||
|
||
/// Extra NFC card uids to add | ||
static EXTRA_UIDS: [(Uid, UserId); 2] = [ | ||
// Test card #1 (Mifare Classic 1k) | ||
(Uid::Single([0x13, 0xbd, 0x5b, 0x2a]), 1271), | ||
// Test token #1 (Mifare Classic 1k) | ||
(Uid::Single([0xb7, 0xd3, 0x65, 0x26]), 1271), | ||
]; | ||
|
||
/// User id | ||
/// Equivalent to the Vereinsflieger `memberid` attribute | ||
#[allow(clippy::module_name_repetitions)] | ||
pub type UserId = u32; | ||
|
||
/// User information | ||
#[derive(Debug, Clone, PartialEq)] | ||
pub struct User { | ||
// pub uids: Vec<Uid>, | ||
// pub id: UserId, | ||
pub name: String, | ||
} | ||
|
||
/// User lookup table | ||
/// Provides a look up of user information (member id and name) by NFC uid. | ||
#[derive(Debug)] | ||
pub struct Users { | ||
/// Look up NFC uid to user id | ||
ids: BTreeMap<Uid, UserId>, | ||
/// Look up user id to user details | ||
users: BTreeMap<UserId, User>, | ||
} | ||
|
||
impl Users { | ||
/// Create new user lookup table | ||
pub fn new() -> Self { | ||
let mut this = Self { | ||
ids: BTreeMap::new(), | ||
users: BTreeMap::new(), | ||
}; | ||
this.clear(); | ||
this | ||
} | ||
|
||
/// Clear all user information | ||
pub fn clear(&mut self) { | ||
self.ids.clear(); | ||
self.users.clear(); | ||
|
||
// Add extra uids and user for testing | ||
for (uid, id) in &EXTRA_UIDS { | ||
self.ids.insert(uid.clone(), *id); | ||
self.users.entry(*id).or_insert_with(|| User { | ||
name: String::from("Test-User"), | ||
}); | ||
} | ||
} | ||
|
||
/// Add/update NFC uid for given user id | ||
pub fn update_uid(&mut self, uid: Uid, id: UserId) { | ||
self.ids.insert(uid, id); | ||
} | ||
|
||
/// Add/update user with given user id | ||
pub fn update_user(&mut self, id: UserId, name: String) { | ||
self.users.insert(id, User { name }); | ||
} | ||
|
||
/// Number of users | ||
pub fn count(&self) -> usize { | ||
self.users.len() | ||
} | ||
|
||
/// Look up user id by NFC uid | ||
pub fn id(&self, uid: &Uid) -> Option<UserId> { | ||
self.ids.get(uid).copied() | ||
} | ||
|
||
/// Look up user by user id | ||
pub fn get(&self, id: UserId) -> Option<&User> { | ||
self.users.get(&id) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.