Skip to content

Commit d5a024b

Browse files
authored
Add functions for applying iono and tropo corrections (#40)
1 parent e9abd05 commit d5a024b

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

build.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ fn main() {
3737
"{}/include/swiftnav/single_epoch_solver.h",
3838
dst.display()
3939
))
40+
.header(format!(
41+
"{}/include/swiftnav/correct_iono_tropo.h",
42+
dst.display()
43+
))
4044
// Tell cargo to invalidate the built crate whenever any of the
4145
// included header files changed.
4246
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
@@ -107,6 +111,8 @@ fn main() {
107111
.whitelist_function("sid_set_contains")
108112
.whitelist_function("calc_PVT")
109113
.whitelist_var("pvt_err_msg")
114+
.whitelist_function("correct_iono")
115+
.whitelist_function("correct_tropo")
110116
// Finish the builder and generate the bindings.
111117
.generate()
112118
// Unwrap the Result and panic on failure.

src/coords.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ impl ECEF {
242242
&mut self.0
243243
}
244244

245+
pub fn as_single_ptr(&self) -> *const f64 {
246+
&self.0[0]
247+
}
248+
245249
pub fn as_array_ref(&self) -> &[f64; 3] {
246250
&self.0
247251
}

src/ionosphere.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,17 @@
99
//! * IS-GPS-200H, Section 20.3.3.5.2.5 and Figure 20-4
1010
1111
use crate::{c_bindings, time::GpsTime};
12+
use crate::{coords::ECEF, navmeas::NavigationMeasurement};
1213

1314
/// Represents an ionosphere model
1415
#[derive(Debug, Clone, PartialOrd, PartialEq)]
1516
pub struct Ionosphere(c_bindings::ionosphere_t);
1617

1718
impl Ionosphere {
19+
fn as_ptr(&self) -> *const c_bindings::ionosphere_t {
20+
&self.0
21+
}
22+
1823
/// Construct an ionosphere model from already decoded parameters
1924
pub fn new(
2025
toa: GpsTime,
@@ -84,6 +89,19 @@ impl Ionosphere {
8489
pub fn calc_delay(&self, t: &GpsTime, lat_u: f64, lon_u: f64, a: f64, e: f64) -> f64 {
8590
unsafe { c_bindings::calc_ionosphere(t.c_ptr(), lat_u, lon_u, a, e, &self.0) }
8691
}
92+
93+
/// Apply ionosphere corrections to a set of measurements
94+
pub fn correct_measurements(&self, pos: ECEF, measurements: &mut [NavigationMeasurement]) {
95+
assert!(measurements.len() <= std::u8::MAX as usize);
96+
unsafe {
97+
c_bindings::correct_iono(
98+
pos.as_single_ptr(),
99+
self.as_ptr(),
100+
measurements.len() as u8,
101+
measurements.as_mut_ptr() as *mut c_bindings::navigation_measurement_t,
102+
);
103+
}
104+
}
87105
}
88106

89107
#[cfg(test)]

src/troposphere.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//! References:
88
//! * UNB Neutral Atmosphere Models: Development and Performance. R Leandro,
99
//! M Santos, and R B Langley
10-
use crate::{c_bindings, time::GpsTime};
10+
use crate::{c_bindings, coords::ECEF, navmeas::NavigationMeasurement, time::GpsTime};
1111

1212
/// Calculate tropospheric delay using UNM3m model.
1313
///
@@ -17,6 +17,18 @@ pub fn calc_delay(t: &GpsTime, lat: f64, h: f64, el: f64) -> f64 {
1717
unsafe { c_bindings::calc_troposphere(t.c_ptr(), lat, h, el) }
1818
}
1919

20+
/// Apply troposphere corrections to a set of measurements
21+
pub fn correct_measurements(pos: ECEF, measurements: &mut [NavigationMeasurement]) {
22+
assert!(measurements.len() <= std::u8::MAX as usize);
23+
unsafe {
24+
c_bindings::correct_tropo(
25+
pos.as_single_ptr(),
26+
measurements.len() as u8,
27+
measurements.as_mut_ptr() as *mut c_bindings::navigation_measurement_t,
28+
);
29+
}
30+
}
31+
2032
#[cfg(test)]
2133
mod tests {
2234
use crate::{

0 commit comments

Comments
 (0)