Skip to content

Commit d843a93

Browse files
authored
Update code to be more inline with the Rust API style (#65)
1 parent ef1b2da commit d843a93

File tree

5 files changed

+32
-34
lines changed

5 files changed

+32
-34
lines changed

src/coords.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl ECEF {
291291
/// First the vector between the points is converted into the local North, East,
292292
/// Down frame of the reference point. Then we can directly calculate the
293293
/// azimuth and elevation.
294-
pub fn get_azel_of(&self, point: &ECEF) -> AzimuthElevation {
294+
pub fn azel_of(&self, point: &ECEF) -> AzimuthElevation {
295295
let mut azel = AzimuthElevation::new(0.0, 0.0);
296296
unsafe {
297297
c_bindings::wgsecef2azel(point.as_ptr(), self.as_ptr(), &mut azel.az, &mut azel.el)

src/ephemeris.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ impl Ephemeris {
302302
/// Calculate satellite position, velocity and clock offset from ephemeris.
303303
pub fn calc_satellite_state(&self, t: GpsTime) -> Result<SatelliteState, InvalidEphemeris> {
304304
// First make sure the ephemeris is valid at `t`, and bail early if it isn't
305-
self.get_detailed_status(t).to_result()?;
305+
self.detailed_status(t).to_result()?;
306306

307307
let mut sat = SatelliteState {
308308
pos: ECEF::default(),
@@ -338,7 +338,7 @@ impl Ephemeris {
338338
pos: ECEF,
339339
) -> Result<AzimuthElevation, InvalidEphemeris> {
340340
// First make sure the ephemeris is valid at `t`, and bail early if it isn't
341-
self.get_detailed_status(t).to_result()?;
341+
self.detailed_status(t).to_result()?;
342342

343343
let mut sat = AzimuthElevation::default();
344344

@@ -367,7 +367,7 @@ impl Ephemeris {
367367
vel: ECEF,
368368
) -> Result<f64, InvalidEphemeris> {
369369
// First make sure the ephemeris is valid at `t`, and bail early if it isn't
370-
self.get_detailed_status(t).to_result()?;
370+
self.detailed_status(t).to_result()?;
371371

372372
let mut doppler = 0.0;
373373

@@ -386,17 +386,17 @@ impl Ephemeris {
386386
Ok(doppler)
387387
}
388388

389-
pub fn get_sid(&self) -> Result<GnssSignal, InvalidGnssSignal> {
389+
pub fn sid(&self) -> Result<GnssSignal, InvalidGnssSignal> {
390390
GnssSignal::from_gnss_signal_t(self.0.sid)
391391
}
392392

393393
/// Gets the status of an ephemeris - is the ephemeris invalid, unhealthy,
394394
/// or has some other condition which makes it unusable?
395-
pub fn get_status(&self) -> Status {
395+
pub fn status(&self) -> Status {
396396
Status::from_ephemeris_status_t(unsafe { c_bindings::get_ephemeris_status_t(&self.0) })
397397
}
398398

399-
pub fn get_detailed_status(&self, t: GpsTime) -> Status {
399+
pub fn detailed_status(&self, t: GpsTime) -> Status {
400400
Status::from_ephemeris_status_t(unsafe {
401401
c_bindings::ephemeris_valid_detailed(&self.0, t.c_ptr())
402402
})

src/navmeas.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl NavigationMeasurement {
4646
}
4747

4848
/// Gets the pseudorange measurement, if a valid one has been set
49-
pub fn get_pseudorange(&self) -> Option<f64> {
49+
pub fn pseudorange(&self) -> Option<f64> {
5050
if self.0.flags & NAV_MEAS_FLAG_CODE_VALID != 0 {
5151
Some(self.0.pseudorange)
5252
} else {
@@ -68,7 +68,7 @@ impl NavigationMeasurement {
6868
}
6969

7070
/// Gets the measured doppler measurement, if a valid one has been set
71-
pub fn get_measured_doppler(&self) -> Option<f64> {
71+
pub fn measured_doppler(&self) -> Option<f64> {
7272
if self.0.flags & NAV_MEAS_FLAG_MEAS_DOPPLER_VALID != 0 {
7373
Some(self.0.measured_doppler)
7474
} else {
@@ -101,7 +101,7 @@ impl NavigationMeasurement {
101101
}
102102

103103
/// Gets the signal CN0 measurement, if a valid one has been set
104-
pub fn get_cn0(&self) -> Option<f64> {
104+
pub fn cn0(&self) -> Option<f64> {
105105
if self.0.flags & NAV_MEAS_FLAG_CN0_VALID != 0 {
106106
Some(self.0.cn0)
107107
} else {
@@ -121,7 +121,7 @@ impl NavigationMeasurement {
121121
self.0.lock_time = value.as_secs_f64();
122122
}
123123

124-
pub fn get_lock_time(&self) -> Duration {
124+
pub fn lock_time(&self) -> Duration {
125125
Duration::from_secs_f64(self.0.lock_time)
126126
}
127127

@@ -130,7 +130,7 @@ impl NavigationMeasurement {
130130
self.0.sid = value.to_gnss_signal_t();
131131
}
132132

133-
pub fn get_sid(&self) -> GnssSignal {
133+
pub fn sid(&self) -> GnssSignal {
134134
GnssSignal::from_gnss_signal_t(self.0.sid).unwrap()
135135
}
136136

@@ -139,7 +139,7 @@ impl NavigationMeasurement {
139139
self.0.flags = flags;
140140
}
141141

142-
pub fn get_flags(&self) -> u16 {
142+
pub fn flags(&self) -> u16 {
143143
self.0.flags
144144
}
145145

src/signal.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,12 @@ impl Constellation {
5959
c_bindings::constellation_e_CONSTELLATION_BDS => Ok(Constellation::Bds),
6060
c_bindings::constellation_e_CONSTELLATION_QZS => Ok(Constellation::Qzs),
6161
c_bindings::constellation_e_CONSTELLATION_GAL => Ok(Constellation::Gal),
62-
c_bindings::constellation_e_CONSTELLATION_INVALID
63-
| c_bindings::constellation_e_CONSTELLATION_COUNT
64-
| _ => Err(InvalidConstellation(value)),
62+
_ => Err(InvalidConstellation(value)),
6563
}
6664
}
6765

68-
pub(crate) fn to_constellation_t(&self) -> c_bindings::constellation_t {
69-
match *self {
66+
pub(crate) fn to_constellation_t(self) -> c_bindings::constellation_t {
67+
match self {
7068
Constellation::Gps => c_bindings::constellation_e_CONSTELLATION_GPS,
7169
Constellation::Sbas => c_bindings::constellation_e_CONSTELLATION_SBAS,
7270
Constellation::Glo => c_bindings::constellation_e_CONSTELLATION_GLO,
@@ -278,14 +276,14 @@ impl Code {
278276
c_bindings::code_e_CODE_AUX_GAL => Ok(Code::AuxGal),
279277
c_bindings::code_e_CODE_AUX_QZS => Ok(Code::AuxQzs),
280278
c_bindings::code_e_CODE_AUX_BDS => Ok(Code::AuxBds),
281-
c_bindings::code_e_CODE_INVALID | c_bindings::code_e_CODE_COUNT | _ => {
279+
_ => {
282280
Err(InvalidCode(value))
283281
}
284282
}
285283
}
286284

287-
pub(crate) fn to_code_t(&self) -> c_bindings::code_t {
288-
match *self {
285+
pub(crate) fn to_code_t(self) -> c_bindings::code_t {
286+
match self {
289287
Code::GpsL1ca => c_bindings::code_e_CODE_GPS_L1CA,
290288
Code::GpsL2cm => c_bindings::code_e_CODE_GPS_L2CM,
291289
Code::SbasL1ca => c_bindings::code_e_CODE_SBAS_L1CA,
@@ -354,7 +352,7 @@ impl Code {
354352
}
355353

356354
/// Attempts to make a `Code` from a string
357-
pub fn from_str(s: &ffi::CStr) -> Result<Code, InvalidCode> {
355+
pub fn from_c_str(s: &ffi::CStr) -> Result<Code, InvalidCode> {
358356
Self::from_code_t(unsafe { c_bindings::code_string_to_enum(s.as_ptr()) })
359357
}
360358

@@ -468,15 +466,15 @@ impl GnssSignal {
468466
GnssSignal::new(sid.sat, Code::from_code_t(sid.code)?)
469467
}
470468

471-
pub(crate) fn to_gnss_signal_t(&self) -> c_bindings::gnss_signal_t {
469+
pub(crate) fn to_gnss_signal_t(self) -> c_bindings::gnss_signal_t {
472470
self.0
473471
}
474472

475-
pub fn get_sat(&self) -> u16 {
473+
pub fn sat(&self) -> u16 {
476474
self.0.sat
477475
}
478476

479-
pub fn get_code(&self) -> Code {
477+
pub fn code(&self) -> Code {
480478
Code::from_code_t(self.0.code).unwrap()
481479
}
482480

src/solver.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ pub enum ProcessingStrategy {
187187
}
188188

189189
impl ProcessingStrategy {
190-
pub(crate) fn to_processing_strategy_t(&self) -> c_bindings::processing_strategy_t {
191-
match *self {
190+
pub(crate) fn to_processing_strategy_t(self) -> c_bindings::processing_strategy_t {
191+
match self {
192192
ProcessingStrategy::GpsOnly => c_bindings::processing_strategy_t_GPS_ONLY,
193193
ProcessingStrategy::AllConstellations => {
194194
c_bindings::processing_strategy_t_ALL_CONSTELLATIONS
@@ -299,12 +299,12 @@ impl SidSet {
299299
}
300300

301301
/// Gets the number of satellites in the set
302-
pub fn get_sat_count(&self) -> u32 {
302+
pub fn sat_count(&self) -> u32 {
303303
unsafe { c_bindings::sid_set_get_sat_count(&self.0) }
304304
}
305305

306306
/// Gets the number of signals in the set
307-
pub fn get_sig_count(&self) -> u32 {
307+
pub fn sig_count(&self) -> u32 {
308308
unsafe { c_bindings::sid_set_get_sig_count(&self.0) }
309309
}
310310

@@ -761,9 +761,9 @@ mod tests {
761761
* geometry */
762762

763763
let mut nm1_broken = make_nm1();
764-
nm1_broken.set_pseudorange(nm1_broken.get_pseudorange().unwrap() + 5e8);
764+
nm1_broken.set_pseudorange(nm1_broken.pseudorange().unwrap() + 5e8);
765765
let mut nm2_broken = make_nm2();
766-
nm2_broken.set_pseudorange(nm2_broken.get_pseudorange().unwrap() - 2e7);
766+
nm2_broken.set_pseudorange(nm2_broken.pseudorange().unwrap() - 2e7);
767767

768768
let nms = [
769769
nm1_broken,
@@ -1002,9 +1002,9 @@ mod tests {
10021002

10031003
/* add a common bias of 120 m to the L2CM measurements */
10041004
let mut nm10_bias = make_nm10();
1005-
nm10_bias.set_pseudorange(nm10_bias.get_pseudorange().unwrap() + 120.);
1005+
nm10_bias.set_pseudorange(nm10_bias.pseudorange().unwrap() + 120.);
10061006
let mut nm11_bias = make_nm11();
1007-
nm11_bias.set_pseudorange(nm11_bias.get_pseudorange().unwrap() + 120.);
1007+
nm11_bias.set_pseudorange(nm11_bias.pseudorange().unwrap() + 120.);
10081008

10091009
/* healthy measurements, with bias on L2 */
10101010
let nms = [
@@ -1050,7 +1050,7 @@ mod tests {
10501050
);
10511051

10521052
/* add outlier to one of the L2 measurements */
1053-
nm11_bias.set_pseudorange(nm11_bias.get_pseudorange().unwrap() + 1000.);
1053+
nm11_bias.set_pseudorange(nm11_bias.pseudorange().unwrap() + 1000.);
10541054
let nms = [
10551055
make_nm2(),
10561056
make_nm3(),

0 commit comments

Comments
 (0)