new merge conflict addressed, to_datetime unused code removed, some refactoring to appease tests

This commit is contained in:
Carlos Guerra
2026-04-16 21:24:53 +02:00
committed by Will Greenberg
parent fee082cde4
commit ba78c7bd01
5 changed files with 43 additions and 61 deletions

View File

@@ -164,21 +164,18 @@ impl DiagTask {
// For fixed-mode sessions, write the configured coordinates to the sidecar
// immediately so the per-session GPS is stored durably and isn't affected
// by future config changes or GPS API calls.
if self.gps_mode == GpsMode::Fixed {
if let Some((lat, lon)) = self.gps_fixed_coords {
if let Some((entry_idx, _)) = qmdl_store.get_current_entry() {
if let Ok(mut gps_file) = qmdl_store.open_entry_gps_for_append(entry_idx).await
{
let record = GpsRecord {
unix_ts: 0,
lat,
lon,
};
if let Ok(json) = serde_json::to_string(&record) {
let _ = gps_file.write_all(format!("{json}\n").as_bytes()).await;
}
}
}
if self.gps_mode == GpsMode::Fixed
&& let Some((lat, lon)) = self.gps_fixed_coords
&& let Some((entry_idx, _)) = qmdl_store.get_current_entry()
&& let Ok(mut gps_file) = qmdl_store.open_entry_gps_for_append(entry_idx).await
{
let record = GpsRecord {
unix_ts: 0,
lat,
lon,
};
if let Ok(json) = serde_json::to_string(&record) {
let _ = gps_file.write_all(format!("{json}\n").as_bytes()).await;
}
}
self.stop_current_recording().await;

View File

@@ -1,7 +1,7 @@
use axum::Json;
use axum::extract::State;
use axum::http::StatusCode;
use chrono::{DateTime, FixedOffset, Utc};
use chrono::Utc;
use log::error;
use serde::{Deserialize, Deserializer, Serialize};
use std::sync::Arc;
@@ -40,14 +40,6 @@ pub struct GpsData {
pub timestamp: i64,
}
impl GpsData {
pub fn to_datetime(&self) -> DateTime<FixedOffset> {
DateTime::from_timestamp(self.timestamp, 0)
.unwrap_or_default()
.fixed_offset()
}
}
#[derive(Serialize, Deserialize)]
pub struct GpsRecord {
pub unix_ts: i64,
@@ -55,14 +47,6 @@ pub struct GpsRecord {
pub lon: f64,
}
impl GpsRecord {
pub fn to_datetime(&self) -> DateTime<FixedOffset> {
DateTime::from_timestamp(self.unix_ts, 0)
.unwrap_or_default()
.fixed_offset()
}
}
/// Reads all GPS records from a sidecar NDJSON file, skipping malformed lines.
pub async fn load_gps_records(file: tokio::fs::File) -> Vec<GpsRecord> {
let reader = BufReader::new(file);
@@ -91,21 +75,21 @@ pub async fn post_gps(
drop(gps);
let qmdl_store = state.qmdl_store_lock.read().await;
if let Some((entry_idx, _)) = qmdl_store.get_current_entry() {
if let Ok(mut file) = qmdl_store.open_entry_gps_for_append(entry_idx).await {
let record = GpsRecord {
unix_ts: Utc::now().timestamp(),
lat: gps_data.latitude,
lon: gps_data.longitude,
};
match serde_json::to_string(&record) {
Ok(json) => {
if let Err(e) = file.write_all(format!("{json}\n").as_bytes()).await {
error!("failed to write GPS record to sidecar: {e}");
}
if let Some((entry_idx, _)) = qmdl_store.get_current_entry()
&& let Ok(mut file) = qmdl_store.open_entry_gps_for_append(entry_idx).await
{
let record = GpsRecord {
unix_ts: Utc::now().timestamp(),
lat: gps_data.latitude,
lon: gps_data.longitude,
};
match serde_json::to_string(&record) {
Ok(json) => {
if let Err(e) = file.write_all(format!("{json}\n").as_bytes()).await {
error!("failed to write GPS record to sidecar: {e}");
}
Err(e) => error!("failed to serialize GPS record: {e}"),
}
Err(e) => error!("failed to serialize GPS record: {e}"),
}
}

View File

@@ -96,17 +96,17 @@ pub(crate) async fn load_gps_records_for_entry(
// not the current config, so old fixed-mode sessions still get coordinates even
// if the mode has since been changed. Use the configured fixed coords directly
// rather than gps_state, which can be overwritten by API calls or be None.
if entry_gps_mode == Some(GpsMode::Fixed) {
if let (Some(lat), Some(lon)) = (
if entry_gps_mode == Some(GpsMode::Fixed)
&& let (Some(lat), Some(lon)) = (
state.config.gps_fixed_latitude,
state.config.gps_fixed_longitude,
) {
return vec![GpsRecord {
unix_ts: 0,
lat,
lon,
}];
}
)
{
return vec![GpsRecord {
unix_ts: 0,
lat,
lon,
}];
}
vec![]
}

View File

@@ -551,7 +551,7 @@ mod tests {
async fn test_creating_updating_and_closing_entries() {
let dir = make_temp_dir();
let mut store = RecordingStore::create(dir.path()).await.unwrap();
let _ = store.new_entry(0).await.unwrap();
let _ = store.new_entry(GpsMode::Disabled).await.unwrap();
let entry_index = store.current_entry.unwrap();
assert_eq!(
RecordingStore::read_manifest(dir.path()).await.unwrap(),
@@ -588,7 +588,7 @@ mod tests {
async fn test_create_on_existing_store() {
let dir = make_temp_dir();
let mut store = RecordingStore::create(dir.path()).await.unwrap();
let _ = store.new_entry(0).await.unwrap();
let _ = store.new_entry(GpsMode::Disabled).await.unwrap();
let entry_index = store.current_entry.unwrap();
store
.update_entry_qmdl_size(entry_index, 1000)
@@ -602,9 +602,9 @@ mod tests {
async fn test_repeated_new_entries() {
let dir = make_temp_dir();
let mut store = RecordingStore::create(dir.path()).await.unwrap();
let _ = store.new_entry(0).await.unwrap();
let _ = store.new_entry(GpsMode::Disabled).await.unwrap();
let entry_index = store.current_entry.unwrap();
let _ = store.new_entry(0).await.unwrap();
let _ = store.new_entry(GpsMode::Disabled).await.unwrap();
let new_entry_index = store.current_entry.unwrap();
assert_ne!(entry_index, new_entry_index);
assert_eq!(store.manifest.entries.len(), 2);
@@ -614,7 +614,7 @@ mod tests {
async fn test_delete_all_entries() {
let dir = make_temp_dir();
let mut store = RecordingStore::create(dir.path()).await.unwrap();
let _ = store.new_entry(0).await.unwrap();
let _ = store.new_entry(GpsMode::Disabled).await.unwrap();
assert!(store.current_entry.is_some());
store.delete_all_entries().await.unwrap();

View File

@@ -25,8 +25,8 @@ use crate::analysis::{AnalysisCtrlMessage, AnalysisStatus};
use crate::config::Config;
use crate::diag::DiagDeviceCtrlMessage;
use crate::display::DisplayState;
use crate::notifications::DEFAULT_NOTIFICATION_TIMEOUT;
use crate::gps::GpsData;
use crate::notifications::DEFAULT_NOTIFICATION_TIMEOUT;
use crate::pcap::{generate_pcap_data, load_gps_records_for_entry};
use crate::qmdl_store::RecordingStore;
@@ -509,6 +509,7 @@ pub async fn debug_set_display_state(
#[cfg(test)]
mod tests {
use super::*;
use crate::config::GpsMode;
use async_zip::base::read::mem::ZipFileReader;
use axum::extract::{Path, State};
use tempfile::TempDir;
@@ -528,7 +529,7 @@ mod tests {
) -> String {
let entry_name = {
let mut store = store_lock.write().await;
let (mut qmdl_file, _analysis_file) = store.new_entry(0).await.unwrap();
let (mut qmdl_file, _analysis_file) = store.new_entry(GpsMode::Disabled).await.unwrap();
if !test_data.is_empty() {
use tokio::io::AsyncWriteExt;