Skip to content

Commit

Permalink
Fix compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jbangelo committed May 26, 2024
1 parent bf54558 commit c645e0a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 64 deletions.
7 changes: 1 addition & 6 deletions swiftnav-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ fn main() {
"{}/include/swiftnav/single_epoch_solver.h",
dst.display()
))
.header(format!(
"{}/include/swiftnav/correct_iono_tropo.h",
dst.display()
))
// Tell cargo to invalidate the built crate whenever any of the
// included header files changed.
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
Expand Down Expand Up @@ -164,14 +160,13 @@ fn main() {
.allowlist_var("NAV_MEAS_FLAG_CODE_VALID")
.allowlist_var("NAV_MEAS_FLAG_MEAS_DOPPLER_VALID")
.allowlist_var("NAV_MEAS_FLAG_CN0_VALID")
.allowlist_type("obs_mask_config_t")
.allowlist_function("sid_set_init")
.allowlist_function("sid_set_get_sat_count")
.allowlist_function("sid_set_get_sig_count")
.allowlist_function("sid_set_contains")
.allowlist_function("calc_PVT")
.allowlist_var("pvt_err_msg")
.allowlist_function("correct_iono")
.allowlist_function("correct_tropo")
.allowlist_type("geoid_model_t")
.allowlist_function("get_geoid_offset")
.allowlist_function("get_geoid_model")
Expand Down
19 changes: 1 addition & 18 deletions swiftnav/src/ionosphere.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//! # References
//! * IS-GPS-200H, Section 20.3.3.5.2.5 and Figure 20-4
use crate::{coords::ECEF, navmeas::NavigationMeasurement, time::GpsTime};
use crate::time::GpsTime;
use std::error::Error;
use std::fmt::{Display, Formatter};

Expand All @@ -37,10 +37,6 @@ impl Display for IonoDecodeFailure {
impl Error for IonoDecodeFailure {}

impl Ionosphere {
fn as_ptr(&self) -> *const swiftnav_sys::ionosphere_t {
&self.0
}

/// Construct an ionosphere model from already decoded parameters
#[allow(clippy::too_many_arguments)]
pub fn new(
Expand Down Expand Up @@ -110,19 +106,6 @@ impl Ionosphere {
pub fn calc_delay(&self, t: &GpsTime, lat_u: f64, lon_u: f64, a: f64, e: f64) -> f64 {
unsafe { swiftnav_sys::calc_ionosphere(t.c_ptr(), lat_u, lon_u, a, e, &self.0) }
}

/// Apply ionosphere corrections to a set of measurements
pub fn correct_measurements(&self, pos: ECEF, measurements: &mut [NavigationMeasurement]) {
assert!(measurements.len() <= std::u8::MAX as usize);
unsafe {
swiftnav_sys::correct_iono(
pos.as_single_ptr(),
self.as_ptr(),
measurements.len() as u8,
measurements.as_mut_ptr() as *mut swiftnav_sys::navigation_measurement_t,
);
}
}
}

#[cfg(test)]
Expand Down
8 changes: 4 additions & 4 deletions swiftnav/src/navmeas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ impl NavigationMeasurement {
///
/// Units of meters, time of flight multiplied by speed of light
pub fn set_pseudorange(&mut self, value: f64) {
self.0.pseudorange = value;
self.0.raw_pseudorange = value;
self.0.flags |= NAV_MEAS_FLAG_CODE_VALID;
}

/// Gets the pseudorange measurement, if a valid one has been set
pub fn pseudorange(&self) -> Option<f64> {
if self.0.flags & NAV_MEAS_FLAG_CODE_VALID != 0 {
Some(self.0.pseudorange)
Some(self.0.raw_pseudorange)
} else {
None
}
Expand All @@ -63,14 +63,14 @@ impl NavigationMeasurement {
///
/// Units of Hertz
pub fn set_measured_doppler(&mut self, value: f64) {
self.0.measured_doppler = value;
self.0.raw_measured_doppler = value;
self.0.flags |= NAV_MEAS_FLAG_MEAS_DOPPLER_VALID;
}

/// Gets the measured doppler measurement, if a valid one has been set
pub fn measured_doppler(&self) -> Option<f64> {
if self.0.flags & NAV_MEAS_FLAG_MEAS_DOPPLER_VALID != 0 {
Some(self.0.measured_doppler)
Some(self.0.raw_measured_doppler)
} else {
None
}
Expand Down
9 changes: 9 additions & 0 deletions swiftnav/src/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,14 @@ pub fn calc_pvt(
let mut dops = Dops::new();
let mut sidset = SidSet::new();

// TODO expose this via the PvtSettings
let obs_config = swiftnav_sys::obs_mask_config_t {
cn0_mask: swiftnav_sys::cn0_mask_t {
enable: false,
threshold_dbhz: 0.0,
},
};

let result = unsafe {
let meas_ptr =
measurements.as_ptr() as *const [swiftnav_sys::navigation_measurement_t; 0usize];
Expand All @@ -411,6 +419,7 @@ pub fn calc_pvt(
tor.c_ptr(),
settings.disable_raim,
settings.disable_velocity,
&obs_config,
settings.strategy.to_processing_strategy_t(),
&mut solution.0,
&mut dops.0,
Expand Down
46 changes: 10 additions & 36 deletions swiftnav/src/troposphere.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,18 @@
//! # References
//! * UNB Neutral Atmosphere Models: Development and Performance. R Leandro,
//! M Santos, and R B Langley
use crate::{coords::ECEF, navmeas::NavigationMeasurement, time::GpsTime};
/// Calculate tropospheric delay using UNM3m model.
///
/// Requires the time of the delay, the latitude (rad) and height (m) of the
/// receiver, and the elevation of the satellite (rad)
pub fn calc_delay(t: &GpsTime, lat: f64, h: f64, el: f64) -> f64 {
unsafe { swiftnav_sys::calc_troposphere(t.c_ptr(), lat, h, el) }
}

/// Apply troposphere corrections to a set of measurements
pub fn correct_measurements(pos: ECEF, measurements: &mut [NavigationMeasurement]) {
assert!(measurements.len() <= std::u8::MAX as usize);
unsafe {
swiftnav_sys::correct_tropo(
pos.as_single_ptr(),
measurements.len() as u8,
measurements.as_mut_ptr() as *mut swiftnav_sys::navigation_measurement_t,
);
}
pub fn calc_delay(doy: f64, lat: f64, h: f64, el: f64) -> f64 {
unsafe { swiftnav_sys::calc_troposphere(doy, lat, h, el) }
}

#[cfg(test)]
mod tests {
use crate::{
time::{GpsTime, DAY},
troposphere::calc_delay,
};
use crate::troposphere::calc_delay;

const D2R: f64 = std::f64::consts::PI / 180.0;

Expand All @@ -59,11 +43,7 @@ mod tests {
let el = 45.0 * D2R;
let d_true = 2.8567;

/* GPS week 1669 starts on 1.1.2012, so easier to generate given doy */
let t = GpsTime::new(1669, 0.).unwrap();
let t = t + DAY.mul_f64(doy);

let d_tropo = calc_delay(&t, lat, h, el);
let d_tropo = calc_delay(doy, lat, h, el);

assert!(
(d_tropo - d_true).abs() < D_TOL,
Expand All @@ -78,10 +58,7 @@ mod tests {
let el = 20. * D2R;
let d_true = 7.4942;

let t = GpsTime::new(1669, 0.).unwrap();
let t = t + DAY.mul_f64(doy);

let d_tropo = calc_delay(&t, lat, h, el);
let d_tropo = calc_delay(doy, lat, h, el);

assert!(
(d_tropo - d_true).abs() < D_TOL,
Expand All @@ -94,12 +71,9 @@ mod tests {
let h = 0.0;
let doy = 50.5;
let el = 10. * D2R;
let d_true = 12.9004;

let t = GpsTime::new(1669, 0.).unwrap();
let t = t + DAY.mul_f64(doy);
let d_true = 12.9007;

let d_tropo = calc_delay(&t, lat, h, el);
let d_tropo = calc_delay(doy, lat, h, el);

assert!(
(d_tropo - d_true).abs() < D_TOL,
Expand All @@ -111,7 +85,7 @@ mod tests {
/* altitude sanity tests */
let max_tropo_correction = 30.0;
let h = -5000.;
let d_tropo = calc_delay(&t, lat, h, el);
let d_tropo = calc_delay(doy, lat, h, el);

assert!(
d_tropo.abs() < max_tropo_correction,
Expand All @@ -121,7 +95,7 @@ mod tests {
);

let h = 12000.;
let d_tropo = calc_delay(&t, lat, h, el);
let d_tropo = calc_delay(doy, lat, h, el);

assert!(
d_tropo.abs() < max_tropo_correction,
Expand All @@ -136,7 +110,7 @@ mod tests {
let max_tropo_correction = 100.0;

for el in elevation_testcases.iter() {
let d_tropo = calc_delay(&t, lat, h, *el);
let d_tropo = calc_delay(doy, lat, h, *el);
assert!(
d_tropo.abs() < max_tropo_correction,
"Sanity test fail at satellite elevation {:.5}. : Correction was {:.5}",
Expand Down

0 comments on commit c645e0a

Please sign in to comment.