mirror of
https://github.com/bleackstorm/SteamFrame-FPV-Control-Center.git
synced 2026-12-03 07:31:57 +01:00
fix(safety,openxr,dvr,config): harden RC/firmware failsafes, OpenXR lifecycle, DVR StreamCopy, relay & persistent config
This commit is contained in:
1 parent
8028680f07
commit
d82a65d9e6
24 files changed
+2246
-638
No files matched your search
+52
-16
@@ -174,17 +174,19 @@ impl G29BridgeReceiver {
|
||||
let worker = thread::Builder::new()
|
||||
.name("g29-udp-rx".into())
|
||||
.spawn(move || {
|
||||
let mut buf = [0u8; 512];
|
||||
let mut last_reject_log = Instant::now() - Duration::from_secs(10);
|
||||
let mut buf = [0u8; 2048];
|
||||
let mut last_reject_log: Option<Instant> = None;
|
||||
while !stop_clone.load(Ordering::Acquire) {
|
||||
if let Ok((len, src)) = socket.recv_from(&mut buf) {
|
||||
if !Self::is_peer_allowed(src.ip(), &allowed_peers) {
|
||||
if last_reject_log.elapsed() >= Duration::from_secs(5) {
|
||||
if last_reject_log
|
||||
.is_none_or(|t| t.elapsed() >= Duration::from_secs(5))
|
||||
{
|
||||
log::warn!(
|
||||
"[G29 Bridge] Paquet UDP rejeté depuis IP non autorisée : {}",
|
||||
src
|
||||
);
|
||||
last_reject_log = Instant::now();
|
||||
last_reject_log = Some(Instant::now());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -198,10 +200,18 @@ impl G29BridgeReceiver {
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
}
|
||||
// Vérifier le timeout G29 à chaque itération (même si des trames $CRSF continuent d'arriver)
|
||||
{
|
||||
let mut st = state_clone.lock();
|
||||
if st.connected && !st.is_live() {
|
||||
st.connected = false;
|
||||
st.armed = false;
|
||||
st.failsafe = true;
|
||||
st.gear = 0;
|
||||
st.throttle_pct = 0;
|
||||
st.brake_pct = 0;
|
||||
st.clutch_pct = 0;
|
||||
log::warn!("[G29 Bridge] Perte de liaison avec le volant G29.");
|
||||
}
|
||||
}
|
||||
@@ -220,10 +230,11 @@ impl G29BridgeReceiver {
|
||||
pub fn send_command(target_ip: &str, target_port: u16, cmd: &str) -> Result<()> {
|
||||
let socket = UdpSocket::bind("0.0.0.0:0")?;
|
||||
let target = format!("{}:{}", target_ip.trim(), target_port);
|
||||
let payload = if cmd.ends_with('\n') {
|
||||
cmd.to_string()
|
||||
let trimmed = cmd.trim();
|
||||
let payload = if trimmed.starts_with('$') && !trimmed.contains('*') {
|
||||
crate::nomad_elrs::NomadHeadTracker::append_nmea_crc8(trimmed)
|
||||
} else {
|
||||
format!("{}\n", cmd)
|
||||
format!("{}\n", trimmed)
|
||||
};
|
||||
socket.send_to(payload.as_bytes(), target)?;
|
||||
Ok(())
|
||||
@@ -237,6 +248,25 @@ impl G29BridgeReceiver {
|
||||
Arc::clone(&self.state)
|
||||
}
|
||||
|
||||
/// Vérifie et retire le suffixe CRC-8 `*XX` optionnel sur les trames `$G29` / `$G29_EVT`.
|
||||
/// Si `*` est présent, le CRC-8 DVB-S2 doit être valide (sinon la trame est rejetée).
|
||||
fn verify_optional_crc8(line: &str) -> Option<&str> {
|
||||
if let Some((body, crc_hex)) = line.rsplit_once('*') {
|
||||
if crc_hex.len() != 2 {
|
||||
return None;
|
||||
}
|
||||
let expected = u8::from_str_radix(crc_hex, 16).ok()?;
|
||||
let calc = crate::nomad_elrs::NomadHeadTracker::crc8_dvb_s2(body.as_bytes());
|
||||
if calc == expected {
|
||||
Some(body)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
} else {
|
||||
Some(line)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn process_line(
|
||||
raw_line: &str,
|
||||
state: &Arc<Mutex<G29State>>,
|
||||
@@ -244,10 +274,18 @@ impl G29BridgeReceiver {
|
||||
telemetry: Option<&Arc<Mutex<TelemetryState>>>,
|
||||
) {
|
||||
let line = raw_line.trim();
|
||||
if let Some(rest) = line.strip_prefix("$G29,") {
|
||||
Self::parse_status_fields(rest, state);
|
||||
} else if let Some(rest) = line.strip_prefix("$G29_EVT,") {
|
||||
Self::parse_button_event(rest, state, control);
|
||||
if line.starts_with("$G29,") {
|
||||
if let Some(verified) = Self::verify_optional_crc8(line) {
|
||||
if let Some(rest) = verified.strip_prefix("$G29,") {
|
||||
Self::parse_status_fields(rest, state);
|
||||
}
|
||||
}
|
||||
} else if line.starts_with("$G29_EVT,") {
|
||||
if let Some(verified) = Self::verify_optional_crc8(line) {
|
||||
if let Some(rest) = verified.strip_prefix("$G29_EVT,") {
|
||||
Self::parse_button_event(rest, state, control);
|
||||
}
|
||||
}
|
||||
} else if let Some(hex) = line.strip_prefix("$CRSF,") {
|
||||
if let Some(telem) = telemetry {
|
||||
Self::parse_crsf_hex(hex, telem);
|
||||
@@ -420,10 +458,8 @@ impl G29BridgeReceiver {
|
||||
None
|
||||
}
|
||||
G29ButtonEvent::Circle if menu_open => {
|
||||
if let Some(ctrl) = control {
|
||||
ctrl.close_vr_menu();
|
||||
}
|
||||
Some("MENU VR OFF".to_string())
|
||||
let closed = control.map(|ctrl| ctrl.close_vr_menu()).unwrap_or(true);
|
||||
Some(if closed { "MENU VR OFF" } else { "RETOUR MENU" }.to_string())
|
||||
}
|
||||
G29ButtonEvent::DpadUp if menu_open => {
|
||||
if let Some(ctrl) = control {
|
||||
|
||||
Reference in new issue
Block a user