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") {
write_file("Race active".to_string(), "racestate.txt");
write_file("00".to_string(), "rx1.txt");
write_file("00".to_string(), "rx2.txt");
write_file("00".to_string(), "rx3.txt");
write_file("0".to_string(), "rx1.txt");
write_file("0".to_string(), "rx2.txt");
write_file("0".to_string(), "rx3.txt");
}
if result_str.contains("S0R0") {
write_file("Race inactive".to_string(), "racestate.txt");
@ -28,17 +28,23 @@ fn listen(socket: &net::UdpSocket) {
if result_str.contains("S0L") {
// zb sS1L0000000DAF
let intval = &result_str[3..5].parse::<i32>().unwrap();
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 intval = &result_str[3..5].parse::<i32>().unwrap();
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 intval = &result_str[3..5].parse::<i32>().unwrap();
let intval = &result_str[3..5].parse::<i32>().unwrap_or(-1);
if *intval != -1 {
write_file((intval + 1).to_string(), "rx3.txt");
}
}
}
fn write_file(text: String, filename: &str) {