feat(terrain,ci): add lost-model GPS, GPX trace, inclinometer, throttle expo/crawl, relay ping, log rotation & release CI

This commit is contained in:
bleackstorm committed 2026-11-26 12:15:20 +01:00
1 parent c83f90570f
commit 9f0c64f873
20 files changed
+926 -78

No files matched your search

+91
View File
@@ -154,6 +154,78 @@ impl SrtWriterState {
}
}
/// Écrivain de trace GPS `.gpx` 1.1 compagnon du fichier DVR (throttlé ~1 Hz, supprimé si 0 point GPS).
struct GpxWriterState {
writer: Option<BufWriter<File>>,
path: PathBuf,
points: u32,
last_emit: Option<Instant>,
}
impl GpxWriterState {
fn open_for_video(video_path: &Path) -> Self {
let gpx_path = video_path.with_extension("gpx");
let mut writer = File::create(&gpx_path).ok().map(BufWriter::new);
if let Some(ref mut w) = writer {
let name = video_path
.file_stem()
.and_then(|s| s.to_str())
.unwrap_or("steamframe_fpv");
let _ = writeln!(
w,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\
<gpx version=\"1.1\" creator=\"steamframe-fpv\" xmlns=\"http://www.topografix.com/GPX/1/1\">\n\
<trk>\n\
<name>{}</name>\n\
<trkseg>",
name
);
}
Self {
writer,
path: gpx_path,
points: 0,
last_emit: None,
}
}
fn push_point(&mut self, lat_deg: f64, lon_deg: f64, alt_m: f32) {
if !lat_deg.is_finite() || !lon_deg.is_finite() || (lat_deg.abs() < 1e-4 && lon_deg.abs() < 1e-4) {
return;
}
if let Some(last) = self.last_emit {
if last.elapsed() < Duration::from_millis(950) {
return;
}
}
self.last_emit = Some(Instant::now());
if let Some(ref mut w) = self.writer {
let iso_utc = chrono::Utc::now().format("%Y-%m-%dT%H:%M:%SZ");
let ele = if alt_m.is_finite() { alt_m } else { 0.0 };
if writeln!(
w,
" <trkpt lat=\"{:.7}\" lon=\"{:.7}\"><ele>{:.1}</ele><time>{}</time></trkpt>",
lat_deg, lon_deg, ele, iso_utc
)
.is_ok()
{
self.points = self.points.saturating_add(1);
}
}
}
fn finish(&mut self) {
if let Some(ref mut w) = self.writer {
let _ = writeln!(w, " </trkseg>\n </trk>\n</gpx>");
let _ = w.flush();
}
self.writer = None;
if self.points == 0 {
let _ = fs::remove_file(&self.path);
}
}
}
/// Détecte si un paquet bitstream H.264 ou H.265 contient une image clé (IDR / SPS / IRAP / VPS).
pub fn detect_keyframe(bytes: &[u8], codec: &str, gst_is_delta: bool) -> bool {
if !gst_is_delta {
@@ -424,6 +496,7 @@ pub struct DvrRecorder {
frames_recorded: Arc<AtomicU64>,
is_recording: Arc<AtomicBool>,
srt_writer: Mutex<SrtWriterState>,
gpx_writer: Mutex<GpxWriterState>,
}
impl DvrRecorder {
@@ -557,6 +630,7 @@ impl DvrRecorder {
.map_err(|e| anyhow!("Impossible de démarrer le pipeline DVR : {}", e))?;
let srt_writer = Mutex::new(SrtWriterState::open_for_video(&file_path));
let gpx_writer = Mutex::new(GpxWriterState::open_for_video(&file_path));
Ok(Arc::new(Self {
pipeline,
@@ -568,6 +642,7 @@ impl DvrRecorder {
frames_recorded: Arc::new(AtomicU64::new(0)),
is_recording: Arc::new(AtomicBool::new(true)),
srt_writer,
gpx_writer,
}))
}
@@ -628,6 +703,14 @@ impl DvrRecorder {
self.srt_writer.lock().push_caption(elapsed_ms, caption);
}
/// Enregistre un point GPS dans la trace `.gpx` compagnon (throttlé ~1 Hz).
pub fn push_gps_point(&self, lat_deg: f64, lon_deg: f64, alt_m: f32) {
if !self.is_recording.load(Ordering::Acquire) {
return;
}
self.gpx_writer.lock().push_point(lat_deg, lon_deg, alt_m);
}
/// Sonde le bus GStreamer (non-bloquant) et rafraîchit la taille réelle du fichier sur disque.
fn poll_health_and_size(&self) {
if let Some(bus) = self.pipeline.bus() {
@@ -708,6 +791,7 @@ impl DvrRecorder {
let end_ms = self.start_time.elapsed().as_millis() as u64;
self.srt_writer.lock().finish(end_ms);
self.gpx_writer.lock().finish();
let _ = self.appsrc.end_of_stream();
@@ -810,6 +894,7 @@ mod tests {
let dvr = DvrRecorder::start_composited_osd(&dir, DvrContainer::Mkv, 320, 240)
.expect("start dvr failed");
dvr.push_telemetry_caption("BAT 15.2V (3.80V/c) | LQ 99% | G2 | 24 km/h");
dvr.push_gps_point(48.856614, 2.3522219, 35.4);
let fake_rgba = vec![0u8; 320 * 240 * 4];
for _ in 0..10 {
dvr.push_slice(&fake_rgba);
@@ -817,12 +902,18 @@ mod tests {
}
let path = dvr.file_path().to_path_buf();
let srt_path = path.with_extension("srt");
let gpx_path = path.with_extension("gpx");
dvr.stop();
assert!(path.exists());
assert!(srt_path.exists());
assert!(gpx_path.exists());
let srt_content = fs::read_to_string(&srt_path).expect("read srt");
assert!(srt_content.contains("BAT 15.2V"));
assert!(srt_content.contains("-->"));
let gpx_content = fs::read_to_string(&gpx_path).expect("read gpx");
assert!(gpx_content.contains("<gpx"));
assert!(gpx_content.contains("48.8566140"));
assert!(gpx_content.contains("</gpx>"));
let meta = fs::metadata(&path).expect("file metadata");
assert!(meta.len() > 0);
let _ = fs::remove_dir_all(&dir);