2020#include <libswiftnav/constants.h>
2121#include <libswiftnav/bits.h>
2222#include <libswiftnav/nav_msg.h>
23+ #include <libswiftnav/l2c_capability.h>
2324
2425void nav_msg_init (nav_msg_t * n )
2526{
@@ -222,16 +223,13 @@ static u8 nav_parity(u32 *word)
222223bool subframe_ready (nav_msg_t * n ) {
223224 return (n -> subframe_start_index != 0 );
224225}
225-
226- s8 process_subframe (nav_msg_t * n , ephemeris_t * e ) {
226+ s8 process_subframe (nav_msg_t * n , gnss_signal_t sid ,
227+ gps_l1ca_decoded_data_t * data )
228+ {
227229 // Check parity and parse out the ephemeris from the most recently received subframe
228230
229- if (!e ) {
230- log_error ("process_subframe: CALLED WITH e = NULL!" );
231- n -> subframe_start_index = 0 ; // Mark the subframe as processed
232- n -> next_subframe_id = 1 ; // Make sure we start again next time
233- return -1 ;
234- }
231+ assert (data != NULL );
232+ memset (data , 0 , sizeof (gps_l1ca_decoded_data_t ));
235233
236234 // First things first - check the parity, and invert bits if necessary.
237235 // process the data, skipping the first word, TLM, and starting with HOW
@@ -242,40 +240,40 @@ s8 process_subframe(nav_msg_t *n, ephemeris_t *e) {
242240 BIT_POLARITY_INVERTED ;
243241 if ((prev_bit_polarity != BIT_POLARITY_UNKNOWN )
244242 && (prev_bit_polarity != n -> bit_polarity )) {
245- log_warn_sid (e -> sid , "Nav phase flip - half cycle slip detected, "
243+ log_warn_sid (sid , "Nav phase flip - half cycle slip detected, "
246244 "but not corrected" );
247245 /* TODO: declare phase ambiguity to IAR */
248246 }
249247
250248 /* Complain if buffer overrun */
251249 if (n -> overrun ) {
252- log_error_sid (e -> sid , "nav_msg subframe buffer overrun!" );
250+ log_error_sid (sid , "nav_msg subframe buffer overrun!" );
253251 n -> overrun = false;
254252 }
255253
256254 /* Extract word 2, and the last two parity bits of word 1 */
257255 u32 sf_word2 = extract_word (n , 28 , 32 , 0 );
258256 if (nav_parity (& sf_word2 )) {
259- log_info_sid (e -> sid , "subframe parity mismatch (word 2)" );
257+ log_info_sid (sid , "subframe parity mismatch (word 2)" );
260258 n -> subframe_start_index = 0 ; // Mark the subframe as processed
261259 n -> next_subframe_id = 1 ; // Make sure we start again next time
262260 return -2 ;
263261 }
264262
265263 n -> alert = sf_word2 >> 12 & 0x01 ; // Alert flag, bit 18
266264 if (n -> alert ) {
267- log_warn_sid (e -> sid , "alert flag set! Ignoring satellite." );
265+ log_warn_sid (sid , "alert flag set! Ignoring satellite." );
268266 }
269267
270268 u8 sf_id = sf_word2 >> 8 & 0x07 ; // Which of 5 possible subframes is it? bits 20-22
271269
272- if (sf_id <= 3 && sf_id == n -> next_subframe_id ) { // Is it the one that we want next?
270+ if (sf_id <= 4 && sf_id == n -> next_subframe_id ) { // Is it the one that we want next?
273271
274272 for (int w = 0 ; w < 8 ; w ++ ) { // For words 3..10
275273 n -> frame_words [sf_id - 1 ][w ] = extract_word (n , 30 * (w + 2 ) - 2 , 32 , 0 ); // Get the bits
276274 // MSBs are D29* and D30*. LSBs are D1...D30
277275 if (nav_parity (& n -> frame_words [sf_id - 1 ][w ])) { // Check parity and invert bits if D30*
278- log_info_sid (e -> sid , "subframe parity mismatch (word %d)" , w + 3 );
276+ log_info_sid (sid , "subframe parity mismatch (word %d)" , w + 3 );
279277 n -> next_subframe_id = 1 ; // Make sure we start again next time
280278 n -> subframe_start_index = 0 ; // Mark the subframe as processed
281279 return -3 ;
@@ -285,14 +283,30 @@ s8 process_subframe(nav_msg_t *n, ephemeris_t *e) {
285283 n -> next_subframe_id ++ ;
286284
287285 if (sf_id == 3 ) {
288- // Got all of subframes 1 to 3
289- n -> next_subframe_id = 1 ; // Make sure we start again next time
290286
291287 // Now let's actually decode the ephemeris...
292- decode_ephemeris (n -> frame_words , e );
288+ data -> ephemeris .sid = sid ;
289+ decode_ephemeris (n -> frame_words , & data -> ephemeris );
290+ data -> ephemeris_upd_flag = true;
293291
294292 return 1 ;
293+ }
294+
295+ if (4 == sf_id ) { /* parse Subframe 4 */
296+ /* get words 3-8 from 25th page (SV config
297+ * bits) */
298+
299+ /* check Word 3 bits 2..7 (63..69) for Page ID, see IS-200H, pg. 84
300+ * Page 25 has ID 63, see IS-200H, pg. 109-110 */
301+ if ((n -> frame_words [3 ][3 - 3 ] >> (30 - 8 ) & 0x3f ) == 63 ) {
302+ decode_l2c_capability (n -> frame_words [3 ], & (data -> gps_l2c_sv_capability ));
303+ data -> gps_l2c_sv_capability_upd_flag = true;
304+ }
305+
306+ /* Got all of subframes 1 to 4 */
307+ n -> next_subframe_id = 1 ; /* Make sure we start again next time */
295308
309+ return 1 ;
296310 }
297311 } else { // didn't get the subframe that we want next
298312 n -> next_subframe_id = 1 ; // Make sure we start again next time
0 commit comments