mirror of
https://github.com/EFForg/rayhunter.git
synced 2026-06-05 04:31:53 -07:00
fixes requested, gps timestamp corrected, more error managing, more border conditions covered
This commit is contained in:
committed by
Will Greenberg
parent
5a4a3034be
commit
7bae34061d
+34
-3
@@ -1,8 +1,7 @@
|
|||||||
use axum::Json;
|
use axum::Json;
|
||||||
use axum::extract::State;
|
use axum::extract::State;
|
||||||
use axum::http::StatusCode;
|
use axum::http::StatusCode;
|
||||||
use chrono::Utc;
|
use log::{error, info, warn};
|
||||||
use log::{error, warn};
|
|
||||||
use serde::{Deserialize, Deserializer, Serialize};
|
use serde::{Deserialize, Deserializer, Serialize};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
|
use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
|
||||||
@@ -10,6 +9,34 @@ use tokio::io::{AsyncBufReadExt, AsyncWriteExt, BufReader};
|
|||||||
use crate::config::GpsMode;
|
use crate::config::GpsMode;
|
||||||
use crate::server::ServerState;
|
use crate::server::ServerState;
|
||||||
|
|
||||||
|
fn deserialize_latitude<'de, D>(deserializer: D) -> Result<f64, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
use serde::de;
|
||||||
|
let v = f64::deserialize(deserializer)?;
|
||||||
|
if !(-90.0..=90.0).contains(&v) {
|
||||||
|
return Err(de::Error::custom(format!(
|
||||||
|
"latitude {v} out of range [-90, 90]"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
Ok(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn deserialize_longitude<'de, D>(deserializer: D) -> Result<f64, D::Error>
|
||||||
|
where
|
||||||
|
D: Deserializer<'de>,
|
||||||
|
{
|
||||||
|
use serde::de;
|
||||||
|
let v = f64::deserialize(deserializer)?;
|
||||||
|
if !(-180.0..=180.0).contains(&v) {
|
||||||
|
return Err(de::Error::custom(format!(
|
||||||
|
"longitude {v} out of range [-180, 180]"
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
Ok(v)
|
||||||
|
}
|
||||||
|
|
||||||
fn deserialize_unix_ts<'de, D>(deserializer: D) -> Result<i64, D::Error>
|
fn deserialize_unix_ts<'de, D>(deserializer: D) -> Result<i64, D::Error>
|
||||||
where
|
where
|
||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
@@ -34,7 +61,9 @@ where
|
|||||||
|
|
||||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||||
pub struct GpsData {
|
pub struct GpsData {
|
||||||
|
#[serde(deserialize_with = "deserialize_latitude")]
|
||||||
pub latitude: f64,
|
pub latitude: f64,
|
||||||
|
#[serde(deserialize_with = "deserialize_longitude")]
|
||||||
pub longitude: f64,
|
pub longitude: f64,
|
||||||
#[serde(deserialize_with = "deserialize_unix_ts")]
|
#[serde(deserialize_with = "deserialize_unix_ts")]
|
||||||
pub timestamp: i64,
|
pub timestamp: i64,
|
||||||
@@ -88,7 +117,7 @@ pub async fn post_gps(
|
|||||||
match qmdl_store.open_entry_gps_for_append(entry_idx).await {
|
match qmdl_store.open_entry_gps_for_append(entry_idx).await {
|
||||||
Ok(Some(mut file)) => {
|
Ok(Some(mut file)) => {
|
||||||
let record = GpsRecord {
|
let record = GpsRecord {
|
||||||
unix_ts: Utc::now().timestamp(),
|
unix_ts: gps_data.timestamp,
|
||||||
lat: gps_data.latitude,
|
lat: gps_data.latitude,
|
||||||
lon: gps_data.longitude,
|
lon: gps_data.longitude,
|
||||||
};
|
};
|
||||||
@@ -117,6 +146,8 @@ pub async fn post_gps(
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
info!("GPS data received but no recording is active — position updated in memory only, not persisted to sidecar");
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(StatusCode::OK)
|
Ok(StatusCode::OK)
|
||||||
|
|||||||
+5
-2
@@ -43,7 +43,7 @@ use diag::{
|
|||||||
DiagDeviceCtrlMessage, delete_all_recordings, delete_recording, get_analysis_report,
|
DiagDeviceCtrlMessage, delete_all_recordings, delete_recording, get_analysis_report,
|
||||||
start_recording, stop_recording,
|
start_recording, stop_recording,
|
||||||
};
|
};
|
||||||
use log::{error, info};
|
use log::{error, info, warn};
|
||||||
use qmdl_store::RecordingStoreError;
|
use qmdl_store::RecordingStoreError;
|
||||||
use rayhunter::Device;
|
use rayhunter::Device;
|
||||||
use stats::get_log;
|
use stats::get_log;
|
||||||
@@ -315,7 +315,10 @@ async fn run_with_config(
|
|||||||
longitude: lon,
|
longitude: lon,
|
||||||
timestamp: 0,
|
timestamp: 0,
|
||||||
}),
|
}),
|
||||||
_ => None,
|
_ => {
|
||||||
|
warn!("gps_mode is Fixed but gps_fixed_latitude or gps_fixed_longitude is missing from config — no GPS coordinates will be recorded");
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ use tokio_util::io::ReaderStream;
|
|||||||
use tokio_util::sync::CancellationToken;
|
use tokio_util::sync::CancellationToken;
|
||||||
|
|
||||||
use crate::analysis::{AnalysisCtrlMessage, AnalysisStatus};
|
use crate::analysis::{AnalysisCtrlMessage, AnalysisStatus};
|
||||||
use crate::config::Config;
|
use crate::config::{Config, GpsMode};
|
||||||
use crate::diag::DiagDeviceCtrlMessage;
|
use crate::diag::DiagDeviceCtrlMessage;
|
||||||
use crate::display::DisplayState;
|
use crate::display::DisplayState;
|
||||||
use crate::gps::GpsData;
|
use crate::gps::GpsData;
|
||||||
@@ -162,8 +162,12 @@ pub async fn get_config(
|
|||||||
))]
|
))]
|
||||||
pub async fn set_config(
|
pub async fn set_config(
|
||||||
State(state): State<Arc<ServerState>>,
|
State(state): State<Arc<ServerState>>,
|
||||||
Json(config): Json<Config>,
|
Json(mut config): Json<Config>,
|
||||||
) -> Result<(StatusCode, String), (StatusCode, String)> {
|
) -> Result<(StatusCode, String), (StatusCode, String)> {
|
||||||
|
if config.gps_mode != GpsMode::Fixed {
|
||||||
|
config.gps_fixed_latitude = None;
|
||||||
|
config.gps_fixed_longitude = None;
|
||||||
|
}
|
||||||
let mut config_to_write = config.clone();
|
let mut config_to_write = config.clone();
|
||||||
config_to_write.wifi_ssid = None;
|
config_to_write.wifi_ssid = None;
|
||||||
config_to_write.wifi_password = None;
|
config_to_write.wifi_password = None;
|
||||||
@@ -509,7 +513,7 @@ pub async fn debug_set_display_state(
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::config::GpsMode;
|
use crate::config::GpsMode as _;
|
||||||
use async_zip::base::read::mem::ZipFileReader;
|
use async_zip::base::read::mem::ZipFileReader;
|
||||||
use axum::extract::{Path, State};
|
use axum::extract::{Path, State};
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|||||||
@@ -25,10 +25,6 @@
|
|||||||
let gps_data: GpsData | null = $state(null);
|
let gps_data: GpsData | null = $state(null);
|
||||||
let gps_mode: GpsMode = $state(GpsMode.Disabled);
|
let gps_mode: GpsMode = $state(GpsMode.Disabled);
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
get_config().then((c) => {
|
|
||||||
gps_mode = c.gps_mode;
|
|
||||||
});
|
|
||||||
|
|
||||||
const interval = setInterval(async () => {
|
const interval = setInterval(async () => {
|
||||||
try {
|
try {
|
||||||
// Don't update UI if browser tab isn't visible
|
// Don't update UI if browser tab isn't visible
|
||||||
@@ -46,6 +42,8 @@
|
|||||||
current_entry = new_manifest.current_entry;
|
current_entry = new_manifest.current_entry;
|
||||||
|
|
||||||
system_stats = await get_system_stats();
|
system_stats = await get_system_stats();
|
||||||
|
const config = await get_config();
|
||||||
|
gps_mode = config.gps_mode;
|
||||||
gps_data = await get_gps();
|
gps_data = await get_gps();
|
||||||
update_error = undefined;
|
update_error = undefined;
|
||||||
loaded = true;
|
loaded = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user