@@ -7,6 +7,14 @@ pub mod flags;
7
7
8
8
use orbits:: OrbitItem ;
9
9
10
+ use flags:: {
11
+ bds:: { BdsHealth , BdsSatH1 } ,
12
+ gal:: GalHealth ,
13
+ geo:: GeoHealth ,
14
+ glonass:: { GlonassHealth , GlonassHealth2 } ,
15
+ gps:: GpsQzssl1cHealth ,
16
+ } ;
17
+
10
18
#[ cfg( feature = "log" ) ]
11
19
use log:: error;
12
20
@@ -76,6 +84,62 @@ impl Ephemeris {
76
84
Some ( Duration :: from_seconds ( tgd_s) )
77
85
}
78
86
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
+
79
143
/// Returns glonass frequency channel, in case this is a Glonass [Ephemeris] message,
80
144
/// with described channel.
81
145
pub fn glonass_freq_channel ( & self ) -> Option < i8 > {
0 commit comments