parse time too

This commit is contained in:
Lukas Bachschwell 2020-01-11 12:38:22 +01:00
parent 86b895c009
commit 972f111f1d
Signed by: lbsadmin
GPG Key ID: CCC6AA87CC8DF425

View File

@ -1,3 +1,4 @@
use std::i64;
use std::io::Write;
use std::net;
@ -28,18 +29,33 @@ fn listen(socket: &net::UdpSocket) {
if result_str.contains("S0L") {
// zb sS1L0000000DAF
let lap_time = i64::from_str_radix(&result_str[5..13], 16).unwrap_or(-1);
if lap_time != -1 {
let lap_seconds = (lap_time as f64) / (1000 as f64);
write_file(lap_seconds.to_string(), "rx1_laptime.txt");
}
let intval = &result_str[3..5].parse::<i32>().unwrap_or(-1);
if *intval != -1 {
write_file((intval + 1).to_string(), "rx1.txt");
}
}
if result_str.contains("S1L") {
let lap_time = i64::from_str_radix(&result_str[5..13], 16).unwrap_or(-1);
if lap_time != -1 {
let lap_seconds = (lap_time as f64) / (1000 as f64);
write_file(lap_seconds.to_string(), "rx2_laptime.txt");
}
let intval = &result_str[3..5].parse::<i32>().unwrap_or(-1);
if *intval != -1 {
write_file((intval + 1).to_string(), "rx2.txt");
}
}
if result_str.contains("S2L") {
let lap_time = i64::from_str_radix(&result_str[5..13], 16).unwrap_or(-1);
if lap_time != -1 {
let lap_seconds = (lap_time as f64) / (1000 as f64);
write_file(lap_seconds.to_string(), "rx3_laptime.txt");
}
let intval = &result_str[3..5].parse::<i32>().unwrap_or(-1);
if *intval != -1 {
write_file((intval + 1).to_string(), "rx3.txt");
@ -59,6 +75,10 @@ fn main() {
write_file("0".to_string(), "rx2.txt");
write_file("0".to_string(), "rx3.txt");
write_file("-.-".to_string(), "rx1_laptime.txt");
write_file("-.-".to_string(), "rx2_laptime.txt");
write_file("-.-".to_string(), "rx3_laptime.txt");
let socket = net::UdpSocket::bind("0.0.0.0:0").expect("failed to bind host socket"); // local bind port
let msg = String::from("ok").into_bytes();