mirror of
				https://github.com/Djeeberjr/fw-anwesenheit.git
				synced 2025-11-03 23:24:10 +00:00 
			
		
		
		
	initial commit
This commit is contained in:
		
							parent
							
								
									b3af8f76d7
								
							
						
					
					
						commit
						32f3124374
					
				
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
			
		||||
/target
 | 
			
		||||
							
								
								
									
										54
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
										Normal file
									
								
							@ -0,0 +1,54 @@
 | 
			
		||||
# This file is automatically @generated by Cargo.
 | 
			
		||||
# It is not intended for manual editing.
 | 
			
		||||
version = 4
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "aho-corasick"
 | 
			
		||||
version = "1.1.3"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "memchr",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "fw-anwesenheit"
 | 
			
		||||
version = "0.1.0"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "regex",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "memchr"
 | 
			
		||||
version = "2.7.4"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "regex"
 | 
			
		||||
version = "1.11.1"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "aho-corasick",
 | 
			
		||||
 "memchr",
 | 
			
		||||
 "regex-automata",
 | 
			
		||||
 "regex-syntax",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "regex-automata"
 | 
			
		||||
version = "0.4.9"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "aho-corasick",
 | 
			
		||||
 "memchr",
 | 
			
		||||
 "regex-syntax",
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "regex-syntax"
 | 
			
		||||
version = "0.8.5"
 | 
			
		||||
source = "registry+https://github.com/rust-lang/crates.io-index"
 | 
			
		||||
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
 | 
			
		||||
							
								
								
									
										7
									
								
								Cargo.toml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								Cargo.toml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,7 @@
 | 
			
		||||
[package]
 | 
			
		||||
name = "fw-anwesenheit"
 | 
			
		||||
version = "0.1.0"
 | 
			
		||||
edition = "2024"
 | 
			
		||||
 | 
			
		||||
[dependencies]
 | 
			
		||||
regex = "1.11.1"
 | 
			
		||||
							
								
								
									
										1
									
								
								src/id_store.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								src/id_store.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1 @@
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										7
									
								
								src/main.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								src/main.rs
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,7 @@
 | 
			
		||||
mod parser;
 | 
			
		||||
mod pm3;
 | 
			
		||||
mod id_store;
 | 
			
		||||
 | 
			
		||||
fn main() {
 | 
			
		||||
    pm3::RunPm3().unwrap();
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										8
									
								
								src/parser.rs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								src/parser.rs
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										34
									
								
								src/pm3.rs
									
									
									
									
									
										Normal 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(())
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user