Optimised failed test

This commit is contained in:
Martino Ferrari
2026-02-25 21:07:27 +01:00
parent dfb399bbba
commit f8f04856ed
17 changed files with 1842 additions and 557 deletions

View File

@@ -342,7 +342,7 @@ fn tcp_command_worker(shared_config: Arc<Mutex<ConnectionConfig>>, rx_cmd: Recei
let trimmed = line.trim();
if trimmed.is_empty() { line.clear(); continue; }
if !in_json && trimmed.starts_with("{") { in_json = true; json_acc.clear(); }
if !in_json && (trimmed.starts_with("{") || trimmed.starts_with("[")) { in_json = true; json_acc.clear(); }
if in_json {
json_acc.push_str(trimmed);
@@ -439,6 +439,7 @@ fn udp_worker(shared_config: Arc<Mutex<ConnectionConfig>>, id_to_meta: Arc<Mutex
let mut socket: Option<UdpSocket> = None;
let mut last_seq: Option<u32> = None;
let mut last_warning_time = std::time::Instant::now();
let mut first_packet = true;
loop {
let (ver, port) = { let config = shared_config.lock().unwrap(); (config.version, config.udp_port.clone()) };
@@ -460,6 +461,7 @@ fn udp_worker(shared_config: Arc<Mutex<ConnectionConfig>>, id_to_meta: Arc<Mutex
if !bound { thread::sleep(std::time::Duration::from_secs(5)); continue; }
let _ = socket.as_ref().unwrap().set_read_timeout(Some(std::time::Duration::from_millis(500)));
last_seq = None;
first_packet = true;
}
let s = if let Some(sock) = socket.as_ref() { sock } else { thread::sleep(std::time::Duration::from_secs(1)); continue; };
let mut buf = [0u8; 4096];
@@ -468,9 +470,14 @@ fn udp_worker(shared_config: Arc<Mutex<ConnectionConfig>>, id_to_meta: Arc<Mutex
if shared_config.lock().unwrap().version != current_version { break; }
if let Ok(n) = s.recv(&mut buf) {
total_packets += 1;
if (total_packets % 500) == 0 { let _ = tx_events.send(InternalEvent::UdpStats(total_packets)); }
if (total_packets % 10) == 0 { let _ = tx_events.send(InternalEvent::UdpStats(total_packets)); }
if first_packet {
let _ = tx_events.send(InternalEvent::InternalLog("First UDP packet received!".to_string()));
first_packet = false;
}
if n < 20 { continue; }
if u32::from_le_bytes(buf[0..4].try_into().unwrap()) != 0xDA7A57AD { continue; }
let magic = u32::from_le_bytes(buf[0..4].try_into().unwrap());
if magic != 0xDA7A57AD { continue; }
let seq = u32::from_le_bytes(buf[4..8].try_into().unwrap());
if let Some(last) = last_seq { if seq != last + 1 && seq > last { let _ = tx_events.send(InternalEvent::UdpDropped(seq - last - 1)); } }
last_seq = Some(seq);
@@ -482,7 +489,7 @@ fn udp_worker(shared_config: Arc<Mutex<ConnectionConfig>>, id_to_meta: Arc<Mutex
let metas = id_to_meta.lock().unwrap();
if metas.is_empty() && count > 0 && last_warning_time.elapsed().as_secs() > 5 {
let _ = tx_events.send(InternalEvent::InternalLog("UDP received but Metadata empty. Still discovering?".to_string()));
let _ = tx_events.send(InternalEvent::InternalLog(format!("UDP received but Metadata empty ({} known). Still discovering?", metas.len())));
last_warning_time = std::time::Instant::now();
}
@@ -497,24 +504,43 @@ fn udp_worker(shared_config: Arc<Mutex<ConnectionConfig>>, id_to_meta: Arc<Mutex
let data_slice = &buf[offset..offset + size as usize];
let mut base_ts_guard = BASE_TELEM_TS.lock().unwrap();
if let Some(base) = *base_ts_guard {
let diff = if ts_raw > base { ts_raw - base } else { base - ts_raw };
if diff > 100_000_000 {
*base_ts_guard = Some(ts_raw);
let _ = tx_events.send(InternalEvent::InternalLog("Clock reset detected. Syncing base.".to_string()));
}
}
if base_ts_guard.is_none() { *base_ts_guard = Some(ts_raw); }
let base = base_ts_guard.unwrap();
let ts_s = if ts_raw >= base {
(ts_raw - base) as f64 / 1000000.0
} else {
0.0 // Avoid huge jitter wrap-around
0.0
};
drop(base_ts_guard);
if let Some(meta) = metas.get(&id) {
let _ = tx_events.send(InternalEvent::TelemMatched(id));
let t = meta.sig_type.as_str();
let t = meta.sig_type.to_lowercase();
let val = match size {
1 => { if t.contains('u') { data_slice[0] as f64 } else { (data_slice[0] as i8) as f64 } },
2 => { let b = data_slice[0..2].try_into().unwrap(); if t.contains('u') { u16::from_le_bytes(b) as f64 } else { i16::from_le_bytes(b) as f64 } },
4 => { let b = data_slice[0..4].try_into().unwrap(); if t.contains("float") { f32::from_le_bytes(b) as f64 } else if t.contains('u') { u32::from_le_bytes(b) as f64 } else { i32::from_le_bytes(b) as f64 } },
8 => { let b = data_slice[0..8].try_into().unwrap(); if t.contains("float") { f64::from_le_bytes(b) } else if t.contains('u') { u64::from_le_bytes(b) as f64 } else { i64::from_le_bytes(b) as f64 } },
4 => {
let b = data_slice[0..4].try_into().unwrap();
if t.contains("float") || (t.contains("32") && (t.contains('f') || t.contains("real"))) { f32::from_le_bytes(b) as f64 }
else if t.contains('u') { u32::from_le_bytes(b) as f64 }
else { i32::from_le_bytes(b) as f64 }
},
8 => {
let b = data_slice[0..8].try_into().unwrap();
if t.contains("float") || t.contains("double") || (t.contains("64") && (t.contains('f') || t.contains("real"))) { f64::from_le_bytes(b) }
else if t.contains('u') { u64::from_le_bytes(b) as f64 }
else { i64::from_le_bytes(b) as f64 }
},
_ => 0.0,
};
for name in &meta.names {
@@ -702,6 +728,16 @@ impl eframe::App for MarteDebugApp {
}
});
ui.separator();
ui.heading("Telemetry Stats");
let mut ids: Vec<_> = self.telem_match_count.keys().cloned().collect();
ids.sort();
if ids.is_empty() { ui.label("No IDs matched yet."); }
for id in ids {
if let Some(count) = self.telem_match_count.get(&id) {
ui.label(format!("ID {}: {} samples", id, count));
}
}
ui.separator();
ui.heading("Forced Signals");
for (path, val) in &self.forced_signals { ui.horizontal(|ui| { ui.label(format!("{}: {}", path, val)); if ui.button("").clicked() { let _ = self.tx_cmd.send(format!("UNFORCE {}", path)); } }); }
});