mirror of
https://github.com/Djeeberjr/fw-anwesenheit.git
synced 2025-07-03 01:24:17 +00:00
minor improvements in pm3.rs
- use trace instead of debug - use a loop instead of while true - ? operator on child.wait()
This commit is contained in:
parent
8aa6714697
commit
fda61c1a5a
11
src/pm3.rs
11
src/pm3.rs
@ -1,4 +1,4 @@
|
|||||||
use log::{debug, error, info};
|
use log::{debug, error, info, trace};
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::io::{self, BufRead};
|
use std::io::{self, BufRead};
|
||||||
@ -32,7 +32,7 @@ pub async fn run_pm3(tx: mpsc::Sender<String>) -> Result<(), Box<dyn Error>> {
|
|||||||
for line_result in reader.lines() {
|
for line_result in reader.lines() {
|
||||||
match line_result {
|
match line_result {
|
||||||
Ok(line) => {
|
Ok(line) => {
|
||||||
debug!("PM3: {}", line);
|
trace!("PM3: {}", line);
|
||||||
let parse_result = super::parser::parse_line(&line);
|
let parse_result = super::parser::parse_line(&line);
|
||||||
if let Some(uid) = parse_result {
|
if let Some(uid) = parse_result {
|
||||||
debug!("Read ID: {}", uid);
|
debug!("Read ID: {}", uid);
|
||||||
@ -50,7 +50,7 @@ pub async fn run_pm3(tx: mpsc::Sender<String>) -> Result<(), Box<dyn Error>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let status = cmd.wait().expect("Failed to wait on child");
|
let status = cmd.wait()?;
|
||||||
|
|
||||||
if status.success() {
|
if status.success() {
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -61,8 +61,7 @@ pub async fn run_pm3(tx: mpsc::Sender<String>) -> Result<(), Box<dyn Error>> {
|
|||||||
|
|
||||||
/// Mocks the `run_pm3` command. Outputs the same ID every second.
|
/// Mocks the `run_pm3` command. Outputs the same ID every second.
|
||||||
pub async fn pm3_mock(tx: mpsc::Sender<String>) -> Result<(), Box<dyn Error>> {
|
pub async fn pm3_mock(tx: mpsc::Sender<String>) -> Result<(), Box<dyn Error>> {
|
||||||
#![allow(while_true)]
|
loop {
|
||||||
while true {
|
|
||||||
match tx.send("F1409618".to_owned()).await {
|
match tx.send("F1409618".to_owned()).await {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@ -72,6 +71,4 @@ pub async fn pm3_mock(tx: mpsc::Sender<String>) -> Result<(), Box<dyn Error>> {
|
|||||||
|
|
||||||
sleep(Duration::from_millis(1000)).await;
|
sleep(Duration::from_millis(1000)).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user