Skip to content

Commit

Permalink
osnma-longan-nano-client: add data sanitization code from galmon-osnma
Browse files Browse the repository at this point in the history
This adds some Galmon data sanitization code that was present in
galmon-osnma but not present in osnma-longan-nano-client.
  • Loading branch information
daniestevez committed Jan 5, 2024
1 parent 44d8b6f commit 04260a3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion galmon-osnma/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {})",
Expand Down
23 changes: 22 additions & 1 deletion osnma-longan-nano-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ fn main() -> Result<(), Box<dyn Error>> {
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()?;
Expand All @@ -92,10 +94,29 @@ fn main() -> Result<(), Box<dyn Error>> {
{
// 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,
Expand Down

0 comments on commit 04260a3

Please sign in to comment.