less unwrap

This commit is contained in:
Lukas Bachschwell 2020-01-02 22:14:38 +01:00
parent 87f06e9e12
commit 86b895c009
Signed by: lbsadmin
GPG Key ID: CCC6AA87CC8DF425

View File

@ -18,9 +18,9 @@ fn listen(socket: &net::UdpSocket) {
if result_str.contains("S0R1") { if result_str.contains("S0R1") {
write_file("Race active".to_string(), "racestate.txt"); write_file("Race active".to_string(), "racestate.txt");
write_file("00".to_string(), "rx1.txt"); write_file("0".to_string(), "rx1.txt");
write_file("00".to_string(), "rx2.txt"); write_file("0".to_string(), "rx2.txt");
write_file("00".to_string(), "rx3.txt"); write_file("0".to_string(), "rx3.txt");
} }
if result_str.contains("S0R0") { if result_str.contains("S0R0") {
write_file("Race inactive".to_string(), "racestate.txt"); write_file("Race inactive".to_string(), "racestate.txt");
@ -28,16 +28,22 @@ fn listen(socket: &net::UdpSocket) {
if result_str.contains("S0L") { if result_str.contains("S0L") {
// zb sS1L0000000DAF // zb sS1L0000000DAF
let intval = &result_str[3..5].parse::<i32>().unwrap(); let intval = &result_str[3..5].parse::<i32>().unwrap_or(-1);
write_file((intval + 1).to_string(), "rx1.txt"); if *intval != -1 {
write_file((intval + 1).to_string(), "rx1.txt");
}
} }
if result_str.contains("S1L") { if result_str.contains("S1L") {
let intval = &result_str[3..5].parse::<i32>().unwrap(); let intval = &result_str[3..5].parse::<i32>().unwrap_or(-1);
write_file((intval + 1).to_string(), "rx2.txt"); if *intval != -1 {
} write_file((intval + 1).to_string(), "rx2.txt");
}
}
if result_str.contains("S2L") { if result_str.contains("S2L") {
let intval = &result_str[3..5].parse::<i32>().unwrap(); let intval = &result_str[3..5].parse::<i32>().unwrap_or(-1);
write_file((intval + 1).to_string(), "rx3.txt"); if *intval != -1 {
write_file((intval + 1).to_string(), "rx3.txt");
}
} }
} }