Skip to content

Commit a8b0444

Browse files
authored
NAV (ephemeris): SV flag exploitation (#333)
Signed-off-by: Guillaume W. Bres <[email protected]>
1 parent 908375e commit a8b0444

File tree

5 files changed

+82
-22
lines changed

5 files changed

+82
-22
lines changed

db/NAV/orbits.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@
503503
"uraiNed0": "f64",
504504
"uraiNed1": "f64",
505505
"uraiEd": "f64",
506-
"svHealth": "f64",
506+
"health": "flag",
507507
"tgd": "f64",
508508
"uraiNed2": "f64",
509509
"iscL1Ca": "f64",
@@ -542,7 +542,7 @@
542542
"uraiNed0": "f64",
543543
"uraiNed1": "f64",
544544
"uraiEd": "f64",
545-
"svHealth": "f64",
545+
"health": "flag",
546546
"tgd": "f64",
547547
"uraiNed2": "f64",
548548
"iscL1Ca": "f64",
@@ -584,7 +584,7 @@
584584
"week": "u32",
585585
"spare2": "f64",
586586
"accuracy": "f64",
587-
"satH1": "flag",
587+
"health": "flag",
588588
"tgd1b1b3": "f64",
589589
"tgd2b2b3": "f64",
590590
"t_tm": "f64",
@@ -621,7 +621,7 @@
621621
"week": "u32",
622622
"spare2": "f64",
623623
"accuracy": "f64",
624-
"satH1": "flag",
624+
"health": "flag",
625625
"tgdb1b3": "f64",
626626
"tgdb2b3": "f64",
627627
"t_tm": "f64",
@@ -656,7 +656,7 @@
656656
"week": "u32",
657657
"spare2": "f64",
658658
"accuracy": "f64",
659-
"satH1": "flag",
659+
"health": "flag",
660660
"tgdb1b3": "f64",
661661
"tgdb2b3": "f64",
662662
"t_tm": "f64",

src/navigation/ephemeris/mod.rs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ pub mod flags;
77

88
use orbits::OrbitItem;
99

10+
use flags::{
11+
bds::{BdsHealth, BdsSatH1},
12+
gal::GalHealth,
13+
geo::GeoHealth,
14+
glonass::{GlonassHealth, GlonassHealth2},
15+
gps::GpsQzssl1cHealth,
16+
};
17+
1018
#[cfg(feature = "log")]
1119
use log::error;
1220

@@ -76,6 +84,62 @@ impl Ephemeris {
7684
Some(Duration::from_seconds(tgd_s))
7785
}
7886

87+
/// Returns true if this [Ephemeris] declares attached SV as suitable for navigation.
88+
pub fn sv_healthy(&self) -> bool {
89+
let health = self.orbits.get("health");
90+
91+
if health.is_none() {
92+
return false;
93+
}
94+
95+
let health = health.unwrap();
96+
97+
if let Some(flag) = health.as_gps_qzss_l1l2l5_health_flag() {
98+
flag.healthy()
99+
} else if let Some(flag) = health.as_gps_qzss_l1c_health_flag() {
100+
!flag.intersects(GpsQzssl1cHealth::UNHEALTHY)
101+
} else if let Some(flag) = health.as_glonass_health_flag() {
102+
// TODO: Status mask .. ?
103+
if let Some(flag2) = self
104+
.orbits
105+
.get("health2")
106+
.and_then(|item| Some(item.as_glonass_health2_flag().unwrap()))
107+
{
108+
!flag.intersects(GlonassHealth::UNHEALTHY)
109+
&& flag2.intersects(GlonassHealth2::HEALTHY_ALMANAC)
110+
} else {
111+
!flag.intersects(GlonassHealth::UNHEALTHY)
112+
}
113+
} else if let Some(flag) = health.as_geo_health_flag() {
114+
// TODO !
115+
false
116+
} else if let Some(flag) = health.as_bds_sat_h1_flag() {
117+
!flag.intersects(BdsSatH1::UNHEALTHY)
118+
} else if let Some(flag) = health.as_bds_health_flag() {
119+
flag == BdsHealth::Healthy
120+
} else {
121+
false
122+
}
123+
}
124+
125+
/// Returns true if this [Ephemeris] declares this satellite as in testing mode. declared healthy (suitable
126+
pub fn sv_in_testing(&self) -> bool {
127+
let health = self.orbits.get("health");
128+
129+
if health.is_none() {
130+
return false;
131+
}
132+
133+
let health = health.unwrap();
134+
135+
// only exists for modern BDS at the moment
136+
if let Some(flag) = health.as_bds_health_flag() {
137+
flag == BdsHealth::UnhealthyTesting
138+
} else {
139+
false
140+
}
141+
}
142+
79143
/// Returns glonass frequency channel, in case this is a Glonass [Ephemeris] message,
80144
/// with described channel.
81145
pub fn glonass_freq_channel(&self) -> Option<i8> {

src/navigation/ephemeris/orbits.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,21 @@ impl OrbitItem {
208208

209209
Ok(OrbitItem::GlonassHealth(flags))
210210
},
211+
(
212+
NavMessageType::LNAV | NavMessageType::D1 | NavMessageType::D2,
213+
Constellation::BeiDou,
214+
) => {
215+
// BDS H1 flag
216+
let flags = BdsSatH1::from_bits(unsigned)
217+
.ok_or(ParsingError::NavFlagsMapping)?;
218+
219+
Ok(OrbitItem::BdsSatH1(flags))
220+
},
211221
(
212222
NavMessageType::CNV1 | NavMessageType::CNV2 | NavMessageType::CNV3,
213223
Constellation::BeiDou,
214224
) => {
225+
// Modern BDS flag
215226
let flags = BdsHealth::from(unsigned);
216227

217228
Ok(OrbitItem::BdsHealth(flags))
@@ -231,21 +242,6 @@ impl OrbitItem {
231242
_ => Err(ParsingError::NavHealthFlagDefinition),
232243
}
233244
},
234-
"satH1" => {
235-
// BDS H1 flag
236-
match (msgtype, constellation) {
237-
(
238-
NavMessageType::LNAV | NavMessageType::D1 | NavMessageType::D2,
239-
Constellation::BeiDou,
240-
) => {
241-
let flags = BdsSatH1::from_bits(unsigned)
242-
.ok_or(ParsingError::NavFlagsMapping)?;
243-
244-
Ok(OrbitItem::BdsSatH1(flags))
245-
},
246-
_ => Err(ParsingError::NavHealthFlagDefinition),
247-
}
248-
},
249245
"source" => {
250246
// complex signal source indication
251247
match (msgtype, constellation) {

src/navigation/ephemeris/parsing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ mod test {
393393
ephemeris.get_orbit_f64("accuracy"),
394394
Some(0.200000000000e+01)
395395
);
396-
assert!(ephemeris.get_orbit_f64("satH1").is_some());
396+
assert!(ephemeris.get_orbit_f64("health").is_some());
397397

398398
assert_eq!(
399399
ephemeris.get_orbit_f64("tgd1b1b3"),

src/navigation/parsing/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ mod test {
290290
//SPARE
291291
} else if k.eq("accuracy") {
292292
assert_eq!(v.as_f64(), 0.200000000000e+01);
293-
} else if k.eq("satH1") {
293+
} else if k.eq("health") {
294294
assert_eq!(v.as_f64(), 0.000000000000e+00);
295295
} else if k.eq("tgd1b1b3") {
296296
assert_eq!(v.as_f64(), -0.599999994133e-09);

0 commit comments

Comments
 (0)