This commit is contained in:
2025-01-16 22:10:18 +01:00
parent c42d550acf
commit 05b4f35d52
5 changed files with 274 additions and 50 deletions

View File

@@ -1,3 +1,36 @@
fn get_port() {}
use std::time::Duration;
use serialport::SerialPortInfo;
fn read_messages() {}
fn get_port(ports: Vec<SerialPortInfo>) -> Option<SerialPortInfo> {
for p in ports {
if p.port_name.contains("ttyACM") {
return Some(p);
}
}
None
}
pub fn read_messages(mut request: curl::easy::Easy, data: &str) {
let ports = serialport::available_ports().expect("No ports found!");
let r = get_port(ports).unwrap().port_name;
let mut connection = serialport::new(r, 9600)
.timeout(Duration::from_millis(1000))
.open().expect("Failed to open the port");
let mut serial_buf: Vec<u8> = vec![0; 1024];
loop {
match connection.read(serial_buf.as_mut_slice()) {
Ok(t) => {
let output = String::from_utf8_lossy(&serial_buf[..t]);
if output.contains("1") {
// send curl request
let res = crate::curl::request(&mut request, &data);
println!("Response code: {}", res.unwrap());
}
},
Err(_) => {}
}
}
}