Properly decode laptimes

This commit is contained in:
Lukas Bachschwell 2020-02-06 19:40:33 +01:00
parent 7b41398937
commit 70c2d2c3b5
Signed by: lbsadmin
GPG Key ID: CCC6AA87CC8DF425
3 changed files with 49 additions and 29 deletions

View File

@ -1,6 +1,6 @@
filemode = false filemode = false
rssi_threshold = 80
enable_websocket = true enable_websocket = true
rssi_threshold = 80
obs_websocket_url = "ws://localhost:4444/" obs_websocket_url = "ws://localhost:4444/"
chorus_udp_url = "192.168.0.141:9000" chorus_udp_url = "192.168.0.141:9000"

View File

@ -1,9 +1,10 @@
# ChorusOBSsync # ChorusOBSsync
- [ ] Finish serde config parsing (more optionals, no filemode flag in clap) - [ ] Finish serde config parsing (more optionals, no filemode flag in clap)
- [x] No OBS Mode - [x] No OBS Mode
- [x] Less errors! - [x] Less errors!
- [x] OBS Error message decodinng - [x] OBS Error message decodinng
- [ ] Initial states for race and beginning - [x] Initial states for race and beginning
- [ ] Could add some disconection handeling of the chorus device in rssi request (if it fails 5 times churus has disconnnected and conenction should be reinitialized ?!) - [ ] make lap decoding inndepedent of amount
- [ ] Make parsing rssi better!
- [ ] Could add some disconection handeling of the chorus device in rssi request (if it fails 5 times churus has disconnnected and conenction should be reinitialized ?!)

View File

@ -141,6 +141,11 @@ async fn udp_comm(appconf: &Conf, senddata: futures::channel::mpsc::UnboundedSen
); );
for i in 0..2 { for i in 0..2 {
set_obs_text(&senddata, &appconf.lap_sources[i], &"0".to_string()); set_obs_text(&senddata, &appconf.lap_sources[i], &"0".to_string());
set_obs_text(
&senddata,
&appconf.laptime_sources[i],
&"00:00.000".to_string(),
);
} }
} else if result_str.contains("S0R0") { } else if result_str.contains("S0R0") {
race_timer_state.store(false, Ordering::Relaxed); race_timer_state.store(false, Ordering::Relaxed);
@ -195,15 +200,20 @@ async fn udp_comm(appconf: &Conf, senddata: futures::channel::mpsc::UnboundedSen
} else if result_str.contains("S0L") { } else if result_str.contains("S0L") {
// zb sS1L0000000DAF // zb sS1L0000000DAF
if let Ok(lap_time) = i64::from_str_radix(&result_str[5..13], 16) { if let Ok(lap_time) = i64::from_str_radix(&result_str[5..13], 16) {
let lap_seconds = (lap_time as f64) / (1000 as f64); let lap_duration = Duration::from_millis(lap_time as u64);
if appconf.filemode { let mut lap_seconds = lap_duration.as_secs();
write_file(lap_seconds.to_string(), "rx1_laptime.txt"); let lap_minutes = lap_seconds / 60;
} lap_seconds = lap_seconds - lap_minutes * 60;
set_obs_text( let laptime_string = format!(
&senddata, "{:0<2}:{:0<2}.{:0<3}",
&appconf.laptime_sources[0], lap_minutes,
&lap_seconds.to_string(), lap_seconds,
lap_duration.subsec_millis()
); );
set_obs_text(&senddata, &appconf.laptime_sources[0], &laptime_string);
if appconf.filemode {
write_file(laptime_string, "rx1_laptime.txt");
}
} }
if let Ok(intval) = &result_str[3..5].parse::<i32>() { if let Ok(intval) = &result_str[3..5].parse::<i32>() {
if appconf.filemode { if appconf.filemode {
@ -217,15 +227,20 @@ async fn udp_comm(appconf: &Conf, senddata: futures::channel::mpsc::UnboundedSen
} }
} else if result_str.contains("S1L") { } else if result_str.contains("S1L") {
if let Ok(lap_time) = i64::from_str_radix(&result_str[5..13], 16) { if let Ok(lap_time) = i64::from_str_radix(&result_str[5..13], 16) {
let lap_seconds = (lap_time as f64) / (1000 as f64); let lap_duration = Duration::from_millis(lap_time as u64);
if appconf.filemode { let mut lap_seconds = lap_duration.as_secs();
write_file(lap_seconds.to_string(), "rx2_laptime.txt"); let lap_minutes = lap_seconds / 60;
} lap_seconds = lap_seconds - lap_minutes * 60;
set_obs_text( let laptime_string = format!(
&senddata, "{:0<2}:{:0<2}.{:0<3}",
&appconf.laptime_sources[1], lap_minutes,
&lap_seconds.to_string(), lap_seconds,
lap_duration.subsec_millis()
); );
set_obs_text(&senddata, &appconf.laptime_sources[1], &laptime_string);
if appconf.filemode {
write_file(laptime_string, "rx2_laptime.txt");
}
} }
if let Ok(intval) = &result_str[3..5].parse::<i32>() { if let Ok(intval) = &result_str[3..5].parse::<i32>() {
@ -240,15 +255,20 @@ async fn udp_comm(appconf: &Conf, senddata: futures::channel::mpsc::UnboundedSen
} }
} else if result_str.contains("S2L") { } else if result_str.contains("S2L") {
if let Ok(lap_time) = i64::from_str_radix(&result_str[5..13], 16) { if let Ok(lap_time) = i64::from_str_radix(&result_str[5..13], 16) {
let lap_seconds = (lap_time as f64) / (1000 as f64); let lap_duration = Duration::from_millis(lap_time as u64);
if appconf.filemode { let mut lap_seconds = lap_duration.as_secs();
write_file(lap_seconds.to_string(), "rx3_laptime.txt"); let lap_minutes = lap_seconds / 60;
} lap_seconds = lap_seconds - lap_minutes * 60;
set_obs_text( let laptime_string = format!(
&senddata, "{:0<2}:{:0<2}.{:0<3}",
&appconf.laptime_sources[2], lap_minutes,
&lap_seconds.to_string(), lap_seconds,
lap_duration.subsec_millis()
); );
set_obs_text(&senddata, &appconf.laptime_sources[2], &laptime_string);
if appconf.filemode {
write_file(laptime_string, "rx3_laptime.txt");
}
} }
if let Ok(intval) = &result_str[3..5].parse::<i32>() { if let Ok(intval) = &result_str[3..5].parse::<i32>() {
@ -362,7 +382,6 @@ async fn main() {
ws_read.for_each(|message| { ws_read.for_each(|message| {
async { async {
let data = message.unwrap().into_data(); let data = message.unwrap().into_data();
// TODO: Parse errors here and filter the rest
let data_string = match std::str::from_utf8(&data) { let data_string = match std::str::from_utf8(&data) {
Ok(v) => v, Ok(v) => v,