@@ -395,6 +395,23 @@ void dgnss_update_ambiguity_state(ambiguity_state_t *s)
395395 }
396396}
397397
398+ /** Formats flag bits for sbp.
399+ * bit positions:
400+ * -`0`: fixed mode?
401+ * -`3`: RAIM available?
402+ * -`4`: RAIM repair used?
403+ *
404+ * \param ret return code from baseline()
405+ * \param fixed 1 for fixed, 0 for float
406+ * \return formatted flag value
407+ */
408+ u8 baseline_flag (s8 ret , bool fixed )
409+ {
410+ return (ret == 1 ) << 4 /* RAIM repair? */
411+ | (ret != 2 ) << 3 /* RAIM available? */
412+ | fixed ; /* Fixed mode? */
413+ }
414+
398415/** Finds the baseline using low latency sdiffs.
399416 * The low latency sdiffs are not guaranteed to match up with either the
400417 * amb_test's or the float sdiffs, and thus care must be taken to transform them
@@ -410,37 +427,43 @@ void dgnss_update_ambiguity_state(ambiguity_state_t *s)
410427 * \param b Output baseline.
411428 * \param disable_raim Flag to turn off raim checks/repair.
412429 * \param raim_threshold raim check threshold
413- * \return 1 if we are using an IAR resolved baseline.
414- * 2 if we are using a float baseline.
415- * -1 if we can't give a baseline.
430+ * \return positive value: SBP baseline msg flags
431+ * negative value: baseline error code
416432 */
417433s8 dgnss_baseline (u8 num_sdiffs , const sdiff_t * sdiffs ,
418434 const double ref_ecef [3 ], const ambiguity_state_t * s ,
419435 u8 * num_used , double b [3 ],
420436 bool disable_raim , double raim_threshold )
421437{
422- s8 ret = baseline (num_sdiffs , sdiffs , ref_ecef , & s -> fixed_ambs , num_used , b ,
438+ s8 ret ;
439+
440+ /* Try IAR resolved baseline */
441+ ret = baseline (num_sdiffs , sdiffs , ref_ecef , & s -> fixed_ambs , num_used , b ,
423442 disable_raim , raim_threshold );
424443 if (ret >= 0 ) {
425- if (ret == 1 ) /* TODO: Export this rather than just printing */
444+ if (ret == 1 )
426445 log_warn ("dgnss_baseline: Fixed baseline RAIM repair" );
427446 log_debug ("fixed solution" );
428447 DEBUG_EXIT ();
429- return 1 ;
448+ return baseline_flag ( ret , true) ;
430449 }
450+
431451 /* We weren't able to get an IAR resolved baseline, check if we can get a
432452 * float baseline. */
433- if (( ret = baseline (num_sdiffs , sdiffs , ref_ecef , & s -> float_ambs , num_used , b ,
434- disable_raim , raim_threshold ))
435- >= 0 ) {
436- if (ret == 1 ) /* TODO: Export this rather than just printing */
453+ ret = baseline (num_sdiffs , sdiffs , ref_ecef , & s -> float_ambs , num_used , b ,
454+ disable_raim , raim_threshold );
455+ if ( ret >= 0 ) {
456+ if (ret == 1 )
437457 log_warn ("dgnss_baseline: Float baseline RAIM repair" );
438458 log_debug ("float solution" );
439459 DEBUG_EXIT ();
440- return 2 ;
460+ return baseline_flag ( ret , false) ;
441461 }
442462 log_debug ("no baseline solution" );
443463 DEBUG_EXIT ();
464+
465+ /* Must be negative! */
466+ assert (ret < 0 );
444467 return ret ;
445468}
446469
0 commit comments