This commit is contained in:
Philipp 2025-04-16 16:35:34 +02:00
commit 095887e13d
5 changed files with 1581 additions and 3 deletions

1463
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,11 @@ edition = "2024"
chrono = { version = "0.4.40", features = ["serde"] }
gpio = "0.4.1"
regex = "1.11.1"
<<<<<<< HEAD
rppal = "0.22.1"
serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"
=======
rocket = "0.5.1"
tokio = { version = "1.44.2", features = ["full"] }
>>>>>>> eb39b09632efb1568079352e3d639edc79df65fd

View File

@ -1,3 +1,4 @@
<<<<<<< HEAD
use pm3::run_pm3;
mod parser;
@ -8,3 +9,42 @@ mod buzzer;
fn main() {
run_pm3().unwrap();
}
=======
use pm3::{pm3_mock, run_pm3};
use tokio::sync::mpsc;
use webserver::start_webserver;
mod id_store;
mod parser;
mod pm3;
mod webserver;
#[tokio::main]
async fn main() {
let (tx, mut rx) = mpsc::channel::<String>(32);
tokio::spawn(async move {
match pm3_mock(tx).await {
Ok(()) => {
println!("PM3 exited with an zero error code");
}
Err(e) => {
println!("PM3 failed to run: {}", e);
}
}
});
tokio::spawn(async move {
while let Some(line) = rx.recv().await {
println!("Got from channel: {}", line);
}
});
match start_webserver().await {
Ok(()) => {}
Err(e) => {
eprintln!("Failed to start webserver: {}", e);
}
}
}
>>>>>>> eb39b09632efb1568079352e3d639edc79df65fd

View File

@ -1,3 +1,4 @@
<<<<<<< HEAD
use std::error::Error;
use std::process::{Command, Stdio};
use std::io::{self, BufRead};
@ -36,3 +37,67 @@ pub fn run_pm3() -> Result<(), Box<dyn Error>> {
Err("pm3 had non zero exit code".into())
}
}
=======
use std::error::Error;
use std::io::{self, BufRead};
use std::process::{Command, Stdio};
use tokio::time::{Duration, sleep};
use tokio::sync::mpsc;
pub async fn run_pm3(tx: mpsc::Sender<String>) -> 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::parse_line(&line);
if let Some(uid) = parse_result {
match tx.send(uid).await {
Ok(()) => {}
Err(e) => {
eprintln!("Failed to send to channel: {}", e);
}
}
}
}
Err(e) => {
eprintln!("{}", e);
}
}
}
let status = cmd.wait().expect("Failed to wait on child");
if status.success() {
Ok(())
} else {
Err("pm3 had non zero exit code".into())
}
}
pub async fn pm3_mock(tx: mpsc::Sender<String>) -> Result<(), Box<dyn Error>> {
#![allow(while_true)]
while true {
match tx.send("F1409618".to_owned()).await {
Ok(()) => {}
Err(e) => {
eprintln!("Failed to send to channel: {}", e);
}
}
sleep(Duration::from_millis(1000)).await;
}
Ok(())
}
>>>>>>> eb39b09632efb1568079352e3d639edc79df65fd

11
src/webserver.rs Normal file
View File

@ -0,0 +1,11 @@
use rocket::{get, routes};
pub async fn start_webserver() -> Result<(), rocket::Error> {
rocket::build().mount("/", routes![index]).launch().await?;
Ok(())
}
#[get("/")]
fn index() -> &'static str {
"Hello, world!"
}