initial commit

This commit is contained in:
2025-04-12 13:01:03 +02:00
parent b3af8f76d7
commit 32f3124374
7 changed files with 112 additions and 0 deletions

1
src/id_store.rs Normal file
View File

@@ -0,0 +1 @@

7
src/main.rs Normal file
View File

@@ -0,0 +1,7 @@
mod parser;
mod pm3;
mod id_store;
fn main() {
pm3::RunPm3().unwrap();
}

8
src/parser.rs Normal file
View File

@@ -0,0 +1,8 @@
use regex::Regex;
pub fn ParseLine(line: &str) -> Option<String> {
let regex = Regex::new(r"(?m)^\[\+\] UID.... (.*)$").unwrap();
let result = regex.captures(line);
result.map(|c| c.get(1).unwrap().as_str().to_owned())
}

34
src/pm3.rs Normal file
View File

@@ -0,0 +1,34 @@
use std::error::Error;
use std::process::{Command, Stdio};
use std::io::{self, BufRead};
pub fn RunPm3() -> Result<(), Box<dyn Error>> {
let mut cmd = Command::new("stdbuf")
.arg("-oL")
.arg("pm3")
.arg("-c")
.arg("lf hitag reader -@")
.stdout(Stdio::piped())
.spawn()?;
let stdout = cmd.stdout.take().ok_or("Failed to get stdout")?;
let reader = io::BufReader::new(stdout);
for line_result in reader.lines() {
match line_result {
Ok(line) => {
let parse_result = super::parser::ParseLine(&line);
if let Some(uid) = parse_result {
println!("UID: {}",uid);
}
}
Err(e) => {
eprintln!("{}",e);
}
}
}
let status = cmd.wait().expect("Failed to wait on child");
Ok(())
}