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
+56
-30
@@ -47,10 +47,13 @@ impl Default for LogBuffer {
|
||||
enum FileLogCmd {
|
||||
Line { text: String, flush: bool },
|
||||
Flush,
|
||||
FlushSync(mpsc::SyncSender<()>),
|
||||
}
|
||||
|
||||
static GLOBAL_LOG_TX: std::sync::OnceLock<SyncSender<FileLogCmd>> = std::sync::OnceLock::new();
|
||||
|
||||
/// Logger centralisé capturant tous les événements et erreurs pour l'interface graphique
|
||||
/// et les enregistrant sur un thread I/O dédié sans jamais bloquer les boucles temps réel.
|
||||
/// et les enregistrant sur un thread I/O dédié (stderr + fichier) sans jamais bloquer les boucles temps réel.
|
||||
pub struct GuiLogger {
|
||||
buffer: Arc<Mutex<LogBuffer>>,
|
||||
file_tx: Option<SyncSender<FileLogCmd>>,
|
||||
@@ -60,34 +63,53 @@ impl GuiLogger {
|
||||
pub fn init(log_file_path: &str) -> Arc<Mutex<LogBuffer>> {
|
||||
let buffer = Arc::new(Mutex::new(LogBuffer::default()));
|
||||
|
||||
let file_tx = OpenOptions::new()
|
||||
let file_opt = OpenOptions::new()
|
||||
.create(true)
|
||||
.append(true)
|
||||
.open(log_file_path)
|
||||
.ok()
|
||||
.and_then(|file| {
|
||||
let (tx, rx) = mpsc::sync_channel::<FileLogCmd>(512);
|
||||
thread::Builder::new()
|
||||
.name("fpv-log-writer".into())
|
||||
.spawn(move || {
|
||||
let mut writer = BufWriter::new(file);
|
||||
while let Ok(cmd) = rx.recv() {
|
||||
match cmd {
|
||||
FileLogCmd::Line { text, flush } => {
|
||||
let _ = writer.write_all(text.as_bytes());
|
||||
if flush {
|
||||
let _ = writer.flush();
|
||||
}
|
||||
}
|
||||
FileLogCmd::Flush => {
|
||||
let _ = writer.flush();
|
||||
.ok();
|
||||
|
||||
let (tx, rx) = mpsc::sync_channel::<FileLogCmd>(512);
|
||||
let file_tx = thread::Builder::new()
|
||||
.name("fpv-log-writer".into())
|
||||
.spawn(move || {
|
||||
let mut writer = file_opt.map(BufWriter::new);
|
||||
let mut stderr = std::io::stderr();
|
||||
while let Ok(cmd) = rx.recv() {
|
||||
match cmd {
|
||||
FileLogCmd::Line { text, flush } => {
|
||||
let _ = stderr.write_all(text.as_bytes());
|
||||
if let Some(ref mut w) = writer {
|
||||
let _ = w.write_all(text.as_bytes());
|
||||
if flush {
|
||||
let _ = w.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
let _ = writer.flush();
|
||||
})
|
||||
.ok()
|
||||
.map(|_| tx)
|
||||
FileLogCmd::Flush => {
|
||||
let _ = stderr.flush();
|
||||
if let Some(ref mut w) = writer {
|
||||
let _ = w.flush();
|
||||
}
|
||||
}
|
||||
FileLogCmd::FlushSync(ack) => {
|
||||
let _ = stderr.flush();
|
||||
if let Some(ref mut w) = writer {
|
||||
let _ = w.flush();
|
||||
}
|
||||
let _ = ack.send(());
|
||||
}
|
||||
}
|
||||
}
|
||||
let _ = stderr.flush();
|
||||
if let Some(ref mut w) = writer {
|
||||
let _ = w.flush();
|
||||
}
|
||||
})
|
||||
.ok()
|
||||
.map(|_| {
|
||||
let _ = GLOBAL_LOG_TX.set(tx.clone());
|
||||
tx
|
||||
});
|
||||
|
||||
let logger = Box::new(Self {
|
||||
@@ -101,6 +123,16 @@ impl GuiLogger {
|
||||
|
||||
buffer
|
||||
}
|
||||
|
||||
/// Attend la vidange complète du fichier journal et de `stderr` avant la fin du processus.
|
||||
pub fn flush_blocking() {
|
||||
if let Some(tx) = GLOBAL_LOG_TX.get() {
|
||||
let (ack_tx, ack_rx) = mpsc::sync_channel::<()>(1);
|
||||
if tx.send(FileLogCmd::FlushSync(ack_tx)).is_ok() {
|
||||
let _ = ack_rx.recv_timeout(std::time::Duration::from_millis(500));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Log for GuiLogger {
|
||||
@@ -131,13 +163,7 @@ impl Log for GuiLogger {
|
||||
message: format!("{}", record.args()),
|
||||
};
|
||||
|
||||
// Affichage console standard
|
||||
eprintln!(
|
||||
"[{}] [{:<5}] ({}) {}",
|
||||
entry.timestamp, entry.level, entry.target, entry.message
|
||||
);
|
||||
|
||||
// Envoi non-bloquant vers le thread d'écriture disque (jamais d'I/O sur thread temps réel)
|
||||
// Envoi non-bloquant vers le thread I/O dédié (stderr + fichier, jamais de syscall bloquant ici)
|
||||
if let Some(ref tx) = self.file_tx {
|
||||
let line = format!(
|
||||
"[{}] [{:<5}] ({}) {}\n",
|
||||
|
||||
Reference in new issue
Block a user