Skip to content

Commit 3a959ca

Browse files
authored
Clean up enum representations (#32)
1 parent a76777f commit 3a959ca

File tree

3 files changed

+177
-96
lines changed

3 files changed

+177
-96
lines changed

src/ephemeris.rs

+10-11
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,16 @@ type Result<T> = std::result::Result<T, InvalidEphemeris>;
3636

3737
/// Various statuses that an ephemeris can be in
3838
#[derive(Copy, Clone, Debug)]
39-
#[cfg_attr(windows, repr(i32))]
40-
#[cfg_attr(not(windows), repr(u32))]
4139
pub enum Status {
42-
Null = c_bindings::ephemeris_status_t_EPH_NULL,
43-
Invalid = c_bindings::ephemeris_status_t_EPH_INVALID,
44-
WnEqualsZero = c_bindings::ephemeris_status_t_EPH_WN_EQ_0,
45-
FitIntervalEqualsZero = c_bindings::ephemeris_status_t_EPH_FIT_INTERVAL_EQ_0,
46-
Unhealthy = c_bindings::ephemeris_status_t_EPH_UNHEALTHY,
47-
TooOld = c_bindings::ephemeris_status_t_EPH_TOO_OLD,
48-
InvalidSid = c_bindings::ephemeris_status_t_EPH_INVALID_SID,
49-
InvalidIod = c_bindings::ephemeris_status_t_EPH_INVALID_IOD,
50-
Valid = c_bindings::ephemeris_status_t_EPH_VALID,
40+
Null,
41+
Invalid,
42+
WnEqualsZero,
43+
FitIntervalEqualsZero,
44+
Unhealthy,
45+
TooOld,
46+
InvalidSid,
47+
InvalidIod,
48+
Valid,
5149
}
5250

5351
impl Status {
@@ -66,6 +64,7 @@ impl Status {
6664
}
6765

6866
/// Orbital terms of an ephemeris
67+
#[derive(Clone)]
6968
pub enum EphemerisTerms {
7069
/// GPS, BDS, GAL, and QZSS all broadcast their terms as keplarian elements
7170
Kepler(c_bindings::ephemeris_kepler_t),

src/signal.rs

+147-77
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,19 @@ use std::str::Utf8Error;
1111

1212
/// GNSS satellite constellations
1313
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
14-
#[repr(i32)]
1514
pub enum Constellation {
1615
/// GPS
17-
Gps = c_bindings::constellation_e_CONSTELLATION_GPS,
16+
Gps,
1817
/// SBAS - Space based augmentation systems
19-
Sbas = c_bindings::constellation_e_CONSTELLATION_SBAS,
18+
Sbas,
2019
/// GLONASS
21-
Glo = c_bindings::constellation_e_CONSTELLATION_GLO,
20+
Glo,
2221
/// Beidou
23-
Bds = c_bindings::constellation_e_CONSTELLATION_BDS,
22+
Bds,
2423
/// QZSS
25-
Qzs = c_bindings::constellation_e_CONSTELLATION_QZS,
24+
Qzs,
2625
/// Galileo
27-
Gal = c_bindings::constellation_e_CONSTELLATION_GAL,
26+
Gal,
2827
}
2928

3029
impl Constellation {
@@ -43,7 +42,14 @@ impl Constellation {
4342
}
4443

4544
pub(crate) fn to_constellation_t(&self) -> c_bindings::constellation_t {
46-
*self as c_bindings::constellation_t
45+
match *self {
46+
Constellation::Gps => c_bindings::constellation_e_CONSTELLATION_GPS,
47+
Constellation::Sbas => c_bindings::constellation_e_CONSTELLATION_SBAS,
48+
Constellation::Glo => c_bindings::constellation_e_CONSTELLATION_GLO,
49+
Constellation::Bds => c_bindings::constellation_e_CONSTELLATION_BDS,
50+
Constellation::Qzs => c_bindings::constellation_e_CONSTELLATION_QZS,
51+
Constellation::Gal => c_bindings::constellation_e_CONSTELLATION_GAL,
52+
}
4753
}
4854

4955
/// Gets the specified maximum number of active satellites for the constellation
@@ -63,104 +69,103 @@ impl Constellation {
6369

6470
/// Code identifiers
6571
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq)]
66-
#[repr(i32)]
6772
pub enum Code {
6873
/// GPS L1CA: BPSK(1)
69-
GpsL1ca = c_bindings::code_e_CODE_GPS_L1CA,
74+
GpsL1ca,
7075
/// GPS L2C: 2 x BPSK(0.5)
71-
GpsL2cm = c_bindings::code_e_CODE_GPS_L2CM,
76+
GpsL2cm,
7277
/// SBAS L1: BPSK(1)
73-
SbasL1ca = c_bindings::code_e_CODE_SBAS_L1CA,
78+
SbasL1ca,
7479
/// GLONASS L1OF: FDMA BPSK(0.5)
75-
GloL1of = c_bindings::code_e_CODE_GLO_L1OF,
80+
GloL1of,
7681
/// GLONASS L2OF: FDMA BPSK(0.5)
77-
GloL2of = c_bindings::code_e_CODE_GLO_L2OF,
82+
GloL2of,
7883
/// GPS L1P(Y): encrypted BPSK(10)
79-
GpsL1p = c_bindings::code_e_CODE_GPS_L1P,
84+
GpsL1p,
8085
/// GPS L2P(Y): encrypted BPSK(10)
81-
GpsL2p = c_bindings::code_e_CODE_GPS_L2P,
82-
GpsL2cl = c_bindings::code_e_CODE_GPS_L2CL,
83-
GpsL2cx = c_bindings::code_e_CODE_GPS_L2CX,
86+
GpsL2p,
87+
GpsL2cl,
88+
GpsL2cx,
8489
/// GPS L5: QPSK(10) at 1150*f0
85-
GpsL5i = c_bindings::code_e_CODE_GPS_L5I,
86-
GpsL5q = c_bindings::code_e_CODE_GPS_L5Q,
87-
GpsL5x = c_bindings::code_e_CODE_GPS_L5X,
90+
GpsL5i,
91+
GpsL5q,
92+
GpsL5x,
8893
/// BDS2 B1I: BPSK(2) at 1526*f0
89-
Bds2B1 = c_bindings::code_e_CODE_BDS2_B1,
94+
Bds2B1,
9095
/// BDS2 B2I: BPSK(2) at 1180*f0
91-
Bds2B2 = c_bindings::code_e_CODE_BDS2_B2,
96+
Bds2B2,
9297
/// Galileo E1: CASM CBOC(1,1) at 1540*f0
93-
GalE1b = c_bindings::code_e_CODE_GAL_E1B,
94-
GalE1c = c_bindings::code_e_CODE_GAL_E1C,
95-
GalE1x = c_bindings::code_e_CODE_GAL_E1X,
98+
GalE1b,
99+
GalE1c,
100+
GalE1x,
96101
/// Galileo E6: CASM BPSK(5) at 1250*f0
97-
GalE6b = c_bindings::code_e_CODE_GAL_E6B,
98-
GalE6c = c_bindings::code_e_CODE_GAL_E6C,
99-
GalE6x = c_bindings::code_e_CODE_GAL_E6X,
102+
GalE6b,
103+
GalE6c,
104+
GalE6x,
100105
/// Galileo E5b: QPSK(10) at 1180*f0
101-
GalE7i = c_bindings::code_e_CODE_GAL_E7I,
102-
GalE7q = c_bindings::code_e_CODE_GAL_E7Q,
103-
GalE7x = c_bindings::code_e_CODE_GAL_E7X,
106+
GalE7i,
107+
GalE7q,
108+
GalE7x,
104109
/// Galileo E5AltBOC(15,10) at 1165*f0
105-
GalE8i = c_bindings::code_e_CODE_GAL_E8I,
106-
GalE8q = c_bindings::code_e_CODE_GAL_E8Q,
107-
GalE8x = c_bindings::code_e_CODE_GAL_E8X,
110+
GalE8i,
111+
GalE8q,
112+
GalE8x,
108113
/// Galileo E5a: QPSK(10) at 1150*f0
109-
GalE5i = c_bindings::code_e_CODE_GAL_E5I,
110-
GalE5q = c_bindings::code_e_CODE_GAL_E5Q,
111-
GalE5x = c_bindings::code_e_CODE_GAL_E5X,
114+
GalE5i,
115+
GalE5q,
116+
GalE5x,
112117
/// GLONASS L1P: encrypted
113-
GloL1p = c_bindings::code_e_CODE_GLO_L1P,
118+
GloL1p,
114119
/// GLONASS L2P: encrypted
115-
GloL2p = c_bindings::code_e_CODE_GLO_L2P,
120+
GloL2p,
116121
/// QZSS L1CA: BPSK(1) at 1540*f0
117-
QzsL1ca = c_bindings::code_e_CODE_QZS_L1CA,
122+
QzsL1ca,
118123
/// QZSS L1C: TM-BOC at 1540*f0
119-
QzsL1ci = c_bindings::code_e_CODE_QZS_L1CI,
120-
QzsL1cq = c_bindings::code_e_CODE_QZS_L1CQ,
121-
QzsL1cx = c_bindings::code_e_CODE_QZS_L1CX,
124+
QzsL1ci,
125+
QzsL1cq,
126+
QzsL1cx,
122127
/// QZSS L2C: 2 x BPSK(0.5) at 1200*f0
123-
QzsL2cm = c_bindings::code_e_CODE_QZS_L2CM,
124-
QzsL2cl = c_bindings::code_e_CODE_QZS_L2CL,
125-
QzsL2cx = c_bindings::code_e_CODE_QZS_L2CX,
128+
QzsL2cm,
129+
QzsL2cl,
130+
QzsL2cx,
126131
/// QZSS L5: QPSK(10) at 1150*f0
127-
QzsL5i = c_bindings::code_e_CODE_QZS_L5I,
128-
QzsL5q = c_bindings::code_e_CODE_QZS_L5Q,
129-
QzsL5x = c_bindings::code_e_CODE_QZS_L5X,
132+
QzsL5i,
133+
QzsL5q,
134+
QzsL5x,
130135
/// SBAS L5: ? at 1150*f0
131-
SbasL5i = c_bindings::code_e_CODE_SBAS_L5I,
132-
SbasL5q = c_bindings::code_e_CODE_SBAS_L5Q,
133-
SbasL5x = c_bindings::code_e_CODE_SBAS_L5X,
136+
SbasL5i,
137+
SbasL5q,
138+
SbasL5x,
134139
/// BDS3 B1C: TM-BOC at 1540*f0
135-
Bds3B1ci = c_bindings::code_e_CODE_BDS3_B1CI,
136-
Bds3B1cq = c_bindings::code_e_CODE_BDS3_B1CQ,
137-
Bds3B1cx = c_bindings::code_e_CODE_BDS3_B1CX,
140+
Bds3B1ci,
141+
Bds3B1cq,
142+
Bds3B1cx,
138143
/// BDS3 B2a: QPSK(10) at 1150*f0
139-
Bds3B5i = c_bindings::code_e_CODE_BDS3_B5I,
140-
Bds3B5q = c_bindings::code_e_CODE_BDS3_B5Q,
141-
Bds3B5x = c_bindings::code_e_CODE_BDS3_B5X,
144+
Bds3B5i,
145+
Bds3B5q,
146+
Bds3B5x,
142147
/// BDS3 B2b: QPSK(10) at 1180*f0
143-
Bds3B7i = c_bindings::code_e_CODE_BDS3_B7I,
144-
Bds3B7q = c_bindings::code_e_CODE_BDS3_B7Q,
145-
Bds3B7x = c_bindings::code_e_CODE_BDS3_B7X,
148+
Bds3B7i,
149+
Bds3B7q,
150+
Bds3B7x,
146151
/// BDS3 B3I: QPSK(10) at 1240*f0
147-
Bds3B3i = c_bindings::code_e_CODE_BDS3_B3I,
148-
Bds3B3q = c_bindings::code_e_CODE_BDS3_B3Q,
149-
Bds3B3x = c_bindings::code_e_CODE_BDS3_B3X,
152+
Bds3B3i,
153+
Bds3B3q,
154+
Bds3B3x,
150155
/// GPS L1C: TM-BOC at 1540*f0
151-
GpsL1ci = c_bindings::code_e_CODE_GPS_L1CI,
152-
GpsL1cq = c_bindings::code_e_CODE_GPS_L1CQ,
153-
GpsL1cx = c_bindings::code_e_CODE_GPS_L1CX,
156+
GpsL1ci,
157+
GpsL1cq,
158+
GpsL1cx,
154159
/// Auxiliary GPS antenna signals
155-
AuxGps = c_bindings::code_e_CODE_AUX_GPS,
160+
AuxGps,
156161
/// Auxiliary SBAS antenna signals
157-
AuxSbas = c_bindings::code_e_CODE_AUX_SBAS,
162+
AuxSbas,
158163
/// Auxiliary GAL antenna signals
159-
AuxGal = c_bindings::code_e_CODE_AUX_GAL,
164+
AuxGal,
160165
/// Auxiliary QZSS antenna signals
161-
AuxQzs = c_bindings::code_e_CODE_AUX_QZS,
166+
AuxQzs,
162167
/// Auxiliary BDS antenna signals
163-
AuxBds = c_bindings::code_e_CODE_AUX_BDS,
168+
AuxBds,
164169
}
165170

166171
impl Code {
@@ -234,6 +239,75 @@ impl Code {
234239
}
235240
}
236241

242+
pub(crate) fn to_code_t(&self) -> c_bindings::code_t {
243+
match *self {
244+
Code::GpsL1ca => c_bindings::code_e_CODE_GPS_L1CA,
245+
Code::GpsL2cm => c_bindings::code_e_CODE_GPS_L2CM,
246+
Code::SbasL1ca => c_bindings::code_e_CODE_SBAS_L1CA,
247+
Code::GloL1of => c_bindings::code_e_CODE_GLO_L1OF,
248+
Code::GloL2of => c_bindings::code_e_CODE_GLO_L2OF,
249+
Code::GpsL1p => c_bindings::code_e_CODE_GPS_L1P,
250+
Code::GpsL2p => c_bindings::code_e_CODE_GPS_L2P,
251+
Code::GpsL2cl => c_bindings::code_e_CODE_GPS_L2CL,
252+
Code::GpsL2cx => c_bindings::code_e_CODE_GPS_L2CX,
253+
Code::GpsL5i => c_bindings::code_e_CODE_GPS_L5I,
254+
Code::GpsL5q => c_bindings::code_e_CODE_GPS_L5Q,
255+
Code::GpsL5x => c_bindings::code_e_CODE_GPS_L5X,
256+
Code::Bds2B1 => c_bindings::code_e_CODE_BDS2_B1,
257+
Code::Bds2B2 => c_bindings::code_e_CODE_BDS2_B2,
258+
Code::GalE1b => c_bindings::code_e_CODE_GAL_E1B,
259+
Code::GalE1c => c_bindings::code_e_CODE_GAL_E1C,
260+
Code::GalE1x => c_bindings::code_e_CODE_GAL_E1X,
261+
Code::GalE6b => c_bindings::code_e_CODE_GAL_E6B,
262+
Code::GalE6c => c_bindings::code_e_CODE_GAL_E6C,
263+
Code::GalE6x => c_bindings::code_e_CODE_GAL_E6X,
264+
Code::GalE7i => c_bindings::code_e_CODE_GAL_E7I,
265+
Code::GalE7q => c_bindings::code_e_CODE_GAL_E7Q,
266+
Code::GalE7x => c_bindings::code_e_CODE_GAL_E7X,
267+
Code::GalE8i => c_bindings::code_e_CODE_GAL_E8I,
268+
Code::GalE8q => c_bindings::code_e_CODE_GAL_E8Q,
269+
Code::GalE8x => c_bindings::code_e_CODE_GAL_E8X,
270+
Code::GalE5i => c_bindings::code_e_CODE_GAL_E5I,
271+
Code::GalE5q => c_bindings::code_e_CODE_GAL_E5Q,
272+
Code::GalE5x => c_bindings::code_e_CODE_GAL_E5X,
273+
Code::GloL1p => c_bindings::code_e_CODE_GLO_L1P,
274+
Code::GloL2p => c_bindings::code_e_CODE_GLO_L2P,
275+
Code::QzsL1ca => c_bindings::code_e_CODE_QZS_L1CA,
276+
Code::QzsL1ci => c_bindings::code_e_CODE_QZS_L1CI,
277+
Code::QzsL1cq => c_bindings::code_e_CODE_QZS_L1CQ,
278+
Code::QzsL1cx => c_bindings::code_e_CODE_QZS_L1CX,
279+
Code::QzsL2cm => c_bindings::code_e_CODE_QZS_L2CM,
280+
Code::QzsL2cl => c_bindings::code_e_CODE_QZS_L2CL,
281+
Code::QzsL2cx => c_bindings::code_e_CODE_QZS_L2CX,
282+
Code::QzsL5i => c_bindings::code_e_CODE_QZS_L5I,
283+
Code::QzsL5q => c_bindings::code_e_CODE_QZS_L5Q,
284+
Code::QzsL5x => c_bindings::code_e_CODE_QZS_L5X,
285+
Code::SbasL5i => c_bindings::code_e_CODE_SBAS_L5I,
286+
Code::SbasL5q => c_bindings::code_e_CODE_SBAS_L5Q,
287+
Code::SbasL5x => c_bindings::code_e_CODE_SBAS_L5X,
288+
Code::Bds3B1ci => c_bindings::code_e_CODE_BDS3_B1CI,
289+
Code::Bds3B1cq => c_bindings::code_e_CODE_BDS3_B1CQ,
290+
Code::Bds3B1cx => c_bindings::code_e_CODE_BDS3_B1CX,
291+
Code::Bds3B5i => c_bindings::code_e_CODE_BDS3_B5I,
292+
Code::Bds3B5q => c_bindings::code_e_CODE_BDS3_B5Q,
293+
Code::Bds3B5x => c_bindings::code_e_CODE_BDS3_B5X,
294+
Code::Bds3B7i => c_bindings::code_e_CODE_BDS3_B7I,
295+
Code::Bds3B7q => c_bindings::code_e_CODE_BDS3_B7Q,
296+
Code::Bds3B7x => c_bindings::code_e_CODE_BDS3_B7X,
297+
Code::Bds3B3i => c_bindings::code_e_CODE_BDS3_B3I,
298+
Code::Bds3B3q => c_bindings::code_e_CODE_BDS3_B3Q,
299+
Code::Bds3B3x => c_bindings::code_e_CODE_BDS3_B3X,
300+
Code::GpsL1ci => c_bindings::code_e_CODE_GPS_L1CI,
301+
Code::GpsL1cq => c_bindings::code_e_CODE_GPS_L1CQ,
302+
Code::GpsL1cx => c_bindings::code_e_CODE_GPS_L1CX,
303+
Code::AuxGps => c_bindings::code_e_CODE_AUX_GPS,
304+
Code::AuxSbas => c_bindings::code_e_CODE_AUX_SBAS,
305+
Code::AuxGal => c_bindings::code_e_CODE_AUX_GAL,
306+
Code::AuxQzs => c_bindings::code_e_CODE_AUX_QZS,
307+
Code::AuxBds => c_bindings::code_e_CODE_AUX_BDS,
308+
}
309+
}
310+
237311
/// Attempts to make a `Code` from a string
238312
pub fn from_str(s: &ffi::CStr) -> Option<Code> {
239313
Self::from_code_t(unsafe { c_bindings::code_string_to_enum(s.as_ptr()) })
@@ -252,10 +326,6 @@ impl Code {
252326
.unwrap()
253327
}
254328

255-
pub(crate) fn to_code_t(&self) -> c_bindings::code_t {
256-
*self as c_bindings::code_t
257-
}
258-
259329
/// Get the number of signals for a code
260330
pub fn sig_count(&self) -> u16 {
261331
unsafe { c_bindings::code_to_sig_count(self.to_code_t()) }

src/solver.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,26 @@ impl Dops {
170170

171171
/// Different strategies of how to choose which measurements to use in a solution
172172
#[derive(Copy, Clone, Debug)]
173-
#[repr(u32)]
174173
pub enum ProcessingStrategy {
175-
GpsOnly = c_bindings::processing_strategy_t_GPS_ONLY,
176-
AllConstellations = c_bindings::processing_strategy_t_ALL_CONSTELLATIONS,
177-
GpsL1caWhenPossible = c_bindings::processing_strategy_t_GPS_L1CA_WHEN_POSSIBLE,
178-
L1Only = c_bindings::processing_strategy_t_L1_ONLY,
174+
GpsOnly,
175+
AllConstellations,
176+
GpsL1caWhenPossible,
177+
L1Only,
178+
}
179+
180+
impl ProcessingStrategy {
181+
pub(crate) fn to_processing_strategy_t(&self) -> c_bindings::processing_strategy_t {
182+
match *self {
183+
ProcessingStrategy::GpsOnly => c_bindings::processing_strategy_t_GPS_ONLY,
184+
ProcessingStrategy::AllConstellations => {
185+
c_bindings::processing_strategy_t_ALL_CONSTELLATIONS
186+
}
187+
ProcessingStrategy::GpsL1caWhenPossible => {
188+
c_bindings::processing_strategy_t_GPS_L1CA_WHEN_POSSIBLE
189+
}
190+
ProcessingStrategy::L1Only => c_bindings::processing_strategy_t_L1_ONLY,
191+
}
192+
}
179193
}
180194

181195
/// Holds the settings to customize how the GNSS solution is calculated
@@ -299,7 +313,6 @@ impl Default for SidSet {
299313

300314
/// Causes of a failed PVT solution
301315
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
302-
#[repr(usize)]
303316
pub enum PvtError {
304317
/// The PDOP of the solution was unacceptably high
305318
HighPdop = 0,
@@ -350,7 +363,6 @@ impl std::error::Error for PvtError {}
350363

351364
/// Indicates action taken while successfully calculating a solution
352365
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
353-
#[repr(usize)]
354366
pub enum PvtStatus {
355367
/// Solution OK and RAIM check passed
356368
RaimPassed,
@@ -392,7 +404,7 @@ pub fn calc_pvt(
392404
tor.c_ptr(),
393405
settings.disable_raim,
394406
settings.disable_velocity,
395-
settings.strategy as u32,
407+
settings.strategy.to_processing_strategy_t(),
396408
&mut solution.0,
397409
&mut dops.0,
398410
&mut sidset.0,

0 commit comments

Comments
 (0)