From e9d3fc969d540607df9b9c01dd8a116f5b7804c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Est=C3=A9vez?= Date: Fri, 5 Jan 2024 11:27:03 +0100 Subject: [PATCH] osnma-longan-nano-client: add data sanitization code from galmon-osnma This adds some Galmon data sanitization code that was present in galmon-osnma but not present in osnma-longan-nano-client. --- galmon-osnma/src/main.rs | 2 +- osnma-longan-nano-client/src/main.rs | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/galmon-osnma/src/main.rs b/galmon-osnma/src/main.rs index ac6be6f..17ba577 100644 --- a/galmon-osnma/src/main.rs +++ b/galmon-osnma/src/main.rs @@ -66,7 +66,7 @@ fn main() -> std::io::Result<()> { let gst = Gst::new(wn, tow); if let Some(current) = current_subframe { if current > gst.gst_subframe() { - // Avoid processing INAV word that are in a previous subframe + // Avoid processing INAV words that are in a previous subframe log::warn!( "dropping INAV word from previous subframe (current subframe {:?}, \ this INAV word {:?} SVN {} band {})", diff --git a/osnma-longan-nano-client/src/main.rs b/osnma-longan-nano-client/src/main.rs index 1612ed8..4c41b57 100644 --- a/osnma-longan-nano-client/src/main.rs +++ b/osnma-longan-nano-client/src/main.rs @@ -78,6 +78,8 @@ fn main() -> Result<(), Box> { let port = &args[1]; let mut serial = Serial::new(port)?; let mut read_galmon = ReadTransport::new(std::io::stdin()); + let mut current_subframe = None; + let mut last_tow_mod_30 = 0; loop { let packet = read_galmon.read_packet()?; @@ -92,10 +94,29 @@ fn main() -> Result<(), Box> { { // This is needed because sometimes we can see a TOW of 604801 let secs_in_week = 604800; - let tow = inav.gnss_tow % secs_in_week; + let mut tow = inav.gnss_tow % secs_in_week; let wn = Wn::try_from(inav.gnss_wn).unwrap() + Wn::try_from(inav.gnss_tow / secs_in_week).unwrap(); + + // Fix bug in Galmon data: + // + // Often, the E1B word 16 starting at TOW = 29 mod 30 will have the + // TOW of the previous word 16 in the subframe, which starts at TOW + // = 15 mod 30. We detect this condition by looking at the last tow + // mod 30 that we saw and fixing if needed. + if tow % 30 == 15 && last_tow_mod_30 >= 19 { + tow += 29 - 15; // wn rollover is not possible by this addition + } + last_tow_mod_30 = tow % 30; + let gst = Gst::new(wn, tow); + if let Some(current) = current_subframe { + if current > gst.gst_subframe() { + // Avoid processing INAV words that are in a previous subframe + continue; + } + } + current_subframe = Some(gst.gst_subframe()); let svn = usize::try_from(inav.gnss_sv).unwrap(); let band = match sigid { 1 => InavBand::E1B,