Skip to content

Commit f5ed59c

Browse files
authored
Merge pull request #22 from rtk-rs/release
release v1.3
2 parents 832226d + 4e12745 commit f5ed59c

File tree

8 files changed

+304
-46
lines changed

8 files changed

+304
-46
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ thiserror = "2"
4141
itertools = "0.14"
4242
anise = { version = "0.6", optional = true }
4343
gnss-rs = { version = "2.4.0", features = ["serde"] }
44-
gnss-qc-traits = { version = "0.2.0", optional = true }
44+
gnss-qc-traits = { version = "0.3.1", optional = true }
4545
hifitime = { version = "4.1", features = ["serde", "std"] }
4646

4747
flate2 = { version = "1", optional = true, default-features = false, features = ["zlib"] }

src/entry.rs

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,17 +174,19 @@ impl SP3Entry {
174174
let mut formatted = format!(
175175
"P{}{}{}{}",
176176
sv,
177-
CoordsFormatter::new(self.position_km.0),
178-
CoordsFormatter::new(self.position_km.1),
179-
CoordsFormatter::new(self.position_km.2),
177+
CoordsFormatter::coordinates(self.position_km.0),
178+
CoordsFormatter::coordinates(self.position_km.1),
179+
CoordsFormatter::coordinates(self.position_km.2),
180180
);
181181

182182
if let Some(value) = self.clock_us {
183-
formatted.push_str(&format!("{}", CoordsFormatter::new(value)));
183+
formatted.push_str(&format!("{}", CoordsFormatter::coordinates(value)));
184184
} else {
185-
formatted.push_str(" ");
185+
formatted.push_str(" ");
186186
}
187187

188+
formatted.push_str(" "); // deviations not handled yet
189+
188190
if self.clock_event {
189191
formatted.push('E');
190192
} else {
@@ -214,13 +216,13 @@ impl SP3Entry {
214216
formatted.push_str(&format!(
215217
"\nV{}{}{}{}",
216218
sv,
217-
CoordsFormatter::new(vel_x_km),
218-
CoordsFormatter::new(vel_y_km),
219-
CoordsFormatter::new(vel_z_km),
219+
CoordsFormatter::coordinates(vel_x_km),
220+
CoordsFormatter::coordinates(vel_y_km),
221+
CoordsFormatter::coordinates(vel_z_km),
220222
));
221223

222224
if let Some(drift_ns) = self.clock_drift_ns {
223-
formatted.push_str(&format!("{}", CoordsFormatter::new(drift_ns)));
225+
formatted.push_str(&format!("{}", CoordsFormatter::coordinates(drift_ns)));
224226
}
225227
}
226228

@@ -553,6 +555,7 @@ VG01 -22859.768469 -8524.538983 -15063.229095\n",
553555
"PG01 15402.861499 21607.418873 -992.500669
554556
VG01 -22859.768469 -8524.538983 -15063.229095 -3.292980\n",
555557
);
558+
556559
let mut buf = BufWriter::new(Utf8Buffer::new(1024));
557560

558561
data.format(g01, &mut buf).unwrap_or_else(|e| {
@@ -565,4 +568,34 @@ VG01 -22859.768469 -8524.538983 -15063.229095 -3.292980\n",
565568
assert_eq!(formatted, expected);
566569
}
567570
}
571+
572+
#[test]
573+
fn sp3_d_predicted_entry_formatting() {
574+
let g01 = SV::from_str("G01").unwrap();
575+
576+
let entry = SP3Entry {
577+
position_km: (-22335.782004, -14656.280389, -1218.238499),
578+
velocity_km_s: None,
579+
predicted_clock: true,
580+
predicted_orbit: true,
581+
maneuver: true,
582+
clock_event: true,
583+
clock_us: Some(-176.397152),
584+
clock_drift_ns: None,
585+
};
586+
587+
let mut buf = BufWriter::new(Utf8Buffer::new(1024));
588+
589+
entry.format(g01, &mut buf).unwrap_or_else(|e| {
590+
panic!("SP3/data formatting issue: {}", e);
591+
});
592+
593+
let formatted = buf.into_inner().unwrap();
594+
let formatted = formatted.to_ascii_utf8();
595+
596+
assert_eq!(
597+
formatted,
598+
"PG01 -22335.782004 -14656.280389 -1218.238499 -176.397152 EP MP\n"
599+
);
600+
}
568601
}

src/formatting.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,35 @@ pub(crate) struct CoordsFormatter {
2121
}
2222

2323
impl CoordsFormatter {
24-
pub fn new(value: f64) -> Self {
24+
pub fn coordinates(value: f64) -> Self {
2525
Self {
2626
value,
2727
width: 13,
2828
precision: 6,
2929
}
3030
}
31+
32+
pub fn fractional_mjd(value: f64) -> Self {
33+
Self {
34+
value,
35+
width: 15,
36+
precision: 13,
37+
}
38+
}
3139
}
3240

3341
impl std::fmt::Display for CoordsFormatter {
3442
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
3543
let value = self.value;
36-
let sign_str = if value.is_sign_positive() { " " } else { "" };
44+
let sign_str = if self.precision == 13 {
45+
""
46+
} else {
47+
if value.is_sign_positive() {
48+
" "
49+
} else {
50+
""
51+
}
52+
};
3753

3854
let formatted = if value.is_sign_positive() {
3955
format!(
@@ -83,7 +99,7 @@ impl SP3 {
8399
// ss,
84100
// nanos / 10
85101
// )?;
86-
writeln!(writer, "* {}", formatter,)?;
102+
writeln!(writer, "* {}", formatter)?;
87103

88104
for key in self
89105
.data

src/header/line2.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! header line #2 helpers
22
use std::io::{BufWriter, Write};
33

4-
use crate::{prelude::Duration, FormattingError, ParsingError};
4+
use crate::{formatting::CoordsFormatter, prelude::Duration, FormattingError, ParsingError};
55

66
pub(crate) fn is_header_line2(content: &str) -> bool {
77
content.starts_with("##")
@@ -81,14 +81,14 @@ impl Line2 {
8181

8282
write!(
8383
w,
84-
"##{:5} {:6}.{:08} {:5}.{:08} {:05} {:0.13}",
84+
"##{:5} {:6}.{:08} {:5}.{:08} {:05} {}",
8585
self.week,
8686
week_seconds,
8787
week_nanos / 10,
8888
dt_seconds,
8989
dt_nanos / 10,
9090
self.mjd_fract.0,
91-
self.mjd_fract.1,
91+
CoordsFormatter::fractional_mjd(self.mjd_fract.1),
9292
)?;
9393

9494
Ok(())

src/parsing.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ impl SP3 {
151151
if pc_count == 0 {
152152
header.constellation = Constellation::from_str(line[3..5].trim())?;
153153
timescale = TimeScale::from_str(line[9..12].trim())?;
154-
155154
header.timescale = timescale;
156155
}
157156

src/position.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,25 @@ mod test {
186186
assert_eq!(entry.orbit_prediction, orbit_prediction);
187187
}
188188
}
189+
190+
#[test]
191+
fn sp3_d_predicted_position() {
192+
let g01 = SV::from_str("G01").unwrap();
193+
194+
let content =
195+
"PG01 -22335.782004 -14656.280389 -1218.238499 -176.397152 10 9 11 102 EP MP";
196+
197+
let position = PositionEntry::from_str(content).unwrap_or_else(|e| {
198+
panic!("Failed to parse predicted state \"{}\": {}", content, e);
199+
});
200+
201+
assert_eq!(position.sv, g01);
202+
assert_eq!(position.x_km, -22335.782004);
203+
assert_eq!(position.y_km, -14656.280389);
204+
assert_eq!(position.z_km, -1218.238499);
205+
assert!(position.clock_event);
206+
assert!(position.clock_prediction);
207+
assert!(position.maneuver);
208+
assert!(position.orbit_prediction);
209+
}
189210
}

0 commit comments

Comments
 (0)