mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
feat(vrx): add live Radxa wfb_rx and SoC thermal telemetry ($VRX) to relay, OSD, and GPUI
This commit is contained in:
1 parent
56f37d1320
commit
dfa142c2d1
8 files changed
+358
-9
No files matched your search
@@ -38,8 +38,51 @@ pub trait FpvControlTarget: Send + Sync + 'static {
|
||||
}
|
||||
|
||||
const G29_TIMEOUT_MS: u64 = 1500;
|
||||
const VRX_TIMEOUT_MS: u64 = 3000;
|
||||
const TOAST_DURATION_MS: u64 = 1500;
|
||||
|
||||
/// Télémétrie temps réel de la liaison radio WFB-ng et du SoC Radxa Zero 3W (`$VRX,...`).
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct VrxLinkStats {
|
||||
pub temp_c: f32,
|
||||
pub rssi_a_dbm: i16,
|
||||
pub rssi_b_dbm: i16,
|
||||
pub fec_recovered: u32,
|
||||
pub fec_lost: u32,
|
||||
pub bitrate_kbps: u32,
|
||||
pub packets_received: u64,
|
||||
pub last_packet: Option<Instant>,
|
||||
}
|
||||
|
||||
impl Default for VrxLinkStats {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
temp_c: -1.0,
|
||||
rssi_a_dbm: -127,
|
||||
rssi_b_dbm: -127,
|
||||
fec_recovered: 0,
|
||||
fec_lost: 0,
|
||||
bitrate_kbps: 0,
|
||||
packets_received: 0,
|
||||
last_packet: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl VrxLinkStats {
|
||||
pub fn is_live(&self) -> bool {
|
||||
self.packets_received > 0
|
||||
&& self
|
||||
.last_packet
|
||||
.map(|t| t.elapsed() <= Duration::from_millis(VRX_TIMEOUT_MS))
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn is_overheating(&self) -> bool {
|
||||
self.temp_c >= 75.0
|
||||
}
|
||||
}
|
||||
|
||||
/// État temps réel reçu depuis le volant G29 (RP2350 -> ESP32-C3 -> UDP)
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct G29State {
|
||||
@@ -65,6 +108,7 @@ pub struct G29State {
|
||||
pub last_button_at: Option<Instant>,
|
||||
pub toast_text: String,
|
||||
pub toast_until: Option<Instant>,
|
||||
pub vrx: VrxLinkStats,
|
||||
}
|
||||
|
||||
impl Default for G29State {
|
||||
@@ -92,6 +136,7 @@ impl Default for G29State {
|
||||
last_button_at: None,
|
||||
toast_text: String::new(),
|
||||
toast_until: None,
|
||||
vrx: VrxLinkStats::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -349,9 +394,43 @@ impl G29BridgeReceiver {
|
||||
if let Some(telem) = telemetry {
|
||||
Self::parse_crsf_hex(hex, telem);
|
||||
}
|
||||
} else if let Some(rest) = line.strip_prefix("$VRX,") {
|
||||
Self::parse_vrx_stats(rest, state);
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_vrx_stats(fields: &str, state: &Arc<Mutex<G29State>>) {
|
||||
let mut parts = fields.split(',');
|
||||
let Some(temp_c) = parts.next().and_then(|s| s.trim().parse::<f32>().ok()) else {
|
||||
return;
|
||||
};
|
||||
let Some(rssi_a) = parts.next().and_then(|s| s.trim().parse::<i16>().ok()) else {
|
||||
return;
|
||||
};
|
||||
let Some(rssi_b) = parts.next().and_then(|s| s.trim().parse::<i16>().ok()) else {
|
||||
return;
|
||||
};
|
||||
let Some(fec_rec) = parts.next().and_then(|s| s.trim().parse::<u32>().ok()) else {
|
||||
return;
|
||||
};
|
||||
let Some(fec_lost) = parts.next().and_then(|s| s.trim().parse::<u32>().ok()) else {
|
||||
return;
|
||||
};
|
||||
let Some(kbps) = parts.next().and_then(|s| s.trim().parse::<u32>().ok()) else {
|
||||
return;
|
||||
};
|
||||
|
||||
let mut st = state.lock();
|
||||
st.vrx.temp_c = if temp_c.is_finite() { temp_c } else { -1.0 };
|
||||
st.vrx.rssi_a_dbm = rssi_a.clamp(-127, 0);
|
||||
st.vrx.rssi_b_dbm = rssi_b.clamp(-127, 0);
|
||||
st.vrx.fec_recovered = fec_rec;
|
||||
st.vrx.fec_lost = fec_lost;
|
||||
st.vrx.bitrate_kbps = kbps;
|
||||
st.vrx.packets_received = st.vrx.packets_received.saturating_add(1);
|
||||
st.vrx.last_packet = Some(Instant::now());
|
||||
}
|
||||
|
||||
fn parse_crsf_hex(hex: &str, telemetry: &Arc<Mutex<TelemetryState>>) {
|
||||
let bytes = hex.trim().as_bytes();
|
||||
if bytes.len() < 8 || !bytes.len().is_multiple_of(2) || bytes.len() > 128 {
|
||||
@@ -757,4 +836,21 @@ mod tests {
|
||||
assert!((0.0..250.0).contains(&rtt_ms));
|
||||
assert!(uart_ok);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_vrx_stats_line() {
|
||||
let state = Arc::new(Mutex::new(G29State::default()));
|
||||
G29BridgeReceiver::process_line("$VRX,76.4,-48,-53,4,1,6400", &state, None, None);
|
||||
let st = state.lock();
|
||||
assert!(!st.connected, "$VRX ne doit pas marquer le volant G29 connecté");
|
||||
assert!(st.vrx.is_live());
|
||||
assert!(st.vrx.is_overheating());
|
||||
assert!((st.vrx.temp_c - 76.4).abs() < 0.05);
|
||||
assert_eq!(st.vrx.rssi_a_dbm, -48);
|
||||
assert_eq!(st.vrx.rssi_b_dbm, -53);
|
||||
assert_eq!(st.vrx.fec_recovered, 4);
|
||||
assert_eq!(st.vrx.fec_lost, 1);
|
||||
assert_eq!(st.vrx.bitrate_kbps, 6400);
|
||||
assert_eq!(st.vrx.packets_received, 1);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user