fin
This commit is contained in:
@@ -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(_) => {}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user