Skip to content

Commit

Permalink
Split parsing of normal observations and events into dedicated functions
Browse files Browse the repository at this point in the history
We don't yet actually *do* anything with events, but we can at least
return an Error to prevent the rest of the system from trying to
treat them as normal observations.

Signed-off-by: Jason Gerecke <killertofu@gmail.com>
  • Loading branch information
jigpu committed Mar 31, 2024
1 parent 5f4b451 commit 6556aaf
Showing 1 changed file with 62 additions and 5 deletions.
67 changes: 62 additions & 5 deletions rinex/src/observation/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,6 @@ pub(crate) fn parse_epoch(
let (n_sat, rem) = rem.split_at(3);
let n_sat = n_sat.trim().parse::<u16>()?;

// previously identified observables (that we expect)
let obs = header.obs.as_ref().unwrap();
let observables = &obs.codes;

// grab possible clock offset
let offs: Option<&str> = match header.version.major < 2 {
true => {
Expand Down Expand Up @@ -247,6 +243,34 @@ pub(crate) fn parse_epoch(
false => None, // empty field
};

match flag {
EpochFlag::Ok | EpochFlag::PowerFailure | EpochFlag::CycleSlip => {
parse_normal(header, epoch, flag, n_sat, clock_offset, rem, lines)
},
_ => parse_event(header, epoch, flag, n_sat, clock_offset, rem, lines),
}
}

fn parse_normal(
header: &Header,
epoch: Epoch,
flag: EpochFlag,
n_sat: u16,
clock_offset: Option<f64>,
rem: &str,
mut lines: std::str::Lines<'_>,
) -> Result<
(
(Epoch, EpochFlag),
Option<f64>,
BTreeMap<SV, HashMap<Observable, ObservationData>>,
),
Error,
> {
// previously identified observables (that we expect)
let obs = header.obs.as_ref().unwrap();
let observables = &obs.codes;

let data = match header.version.major {
2 => {
// grab system descriptions
Expand All @@ -270,6 +294,29 @@ pub(crate) fn parse_epoch(
Ok(((epoch, flag), clock_offset, data))
}

fn parse_event(
header: &Header,
epoch: Epoch,
flag: EpochFlag,
n_records: u16,
clock_offset: Option<f64>,
rem: &str,
mut lines: std::str::Lines<'_>,
) -> Result<
(
(Epoch, EpochFlag),
Option<f64>,
BTreeMap<SV, HashMap<Observable, ObservationData>>,
),
Error,
> {
// TODO: Verify that the number of lines of data
// to read matches the number of records expected

// TODO: Actually process event data
Err(Error::MissingData)
}

/*
* Parses a V2 epoch from given lines iteratoor
* Vehicle description is contained in the epoch descriptor
Expand Down Expand Up @@ -1761,7 +1808,17 @@ mod test {
let clock_offset: Option<f64> = None;

let e = parse_epoch(&header, epoch_str, ts);
assert!(e.is_ok());

match expected_flag {
EpochFlag::Ok | EpochFlag::PowerFailure | EpochFlag::CycleSlip => {
assert!(e.is_ok())
},
_ => {
// TODO: Update alongside parse_event
assert!(e.is_err());
return;
},
}
let ((e, flag), _, _) = e.unwrap();
assert_eq!(flag, expected_flag);
if ver.major < 3 {
Expand Down

0 comments on commit 6556aaf

Please sign in to comment.