@@ -377,7 +377,7 @@ impl Ephemeris {
377
377
Ok ( doppler)
378
378
}
379
379
380
- pub fn get_sid ( & self ) -> std :: result :: Result < GnssSignal , InvalidGnssSignal > {
380
+ pub fn get_sid ( & self ) -> Result < GnssSignal , InvalidGnssSignal > {
381
381
GnssSignal :: from_gnss_signal_t ( self . 0 . sid )
382
382
}
383
383
@@ -405,6 +405,137 @@ impl Ephemeris {
405
405
}
406
406
}
407
407
408
+ #[ cfg( feature = "sbp-conversions" ) ]
409
+ mod sbp_error {
410
+ use crate :: { signal:: InvalidGnssSignal , time:: InvalidGpsTime } ;
411
+ use std:: error:: Error ;
412
+ use std:: fmt;
413
+
414
+ #[ derive( Debug , Copy , Clone , PartialOrd , PartialEq ) ]
415
+ pub enum EphemerisDecodeError {
416
+ InvalidTime ( InvalidGpsTime ) ,
417
+ InvalidSignal ( InvalidGnssSignal ) ,
418
+ }
419
+
420
+ impl fmt:: Display for EphemerisDecodeError {
421
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
422
+ match self {
423
+ EphemerisDecodeError :: InvalidTime ( time_err) => time_err. fmt ( f) ,
424
+ EphemerisDecodeError :: InvalidSignal ( sig_err) => sig_err. fmt ( f) ,
425
+ }
426
+ }
427
+ }
428
+
429
+ impl Error for EphemerisDecodeError { }
430
+
431
+ impl From < InvalidGpsTime > for EphemerisDecodeError {
432
+ fn from ( other : InvalidGpsTime ) -> EphemerisDecodeError {
433
+ EphemerisDecodeError :: InvalidTime ( other)
434
+ }
435
+ }
436
+
437
+ impl From < InvalidGnssSignal > for EphemerisDecodeError {
438
+ fn from ( other : InvalidGnssSignal ) -> EphemerisDecodeError {
439
+ EphemerisDecodeError :: InvalidSignal ( other)
440
+ }
441
+ }
442
+ }
443
+
444
+ #[ cfg( feature = "sbp-conversions" ) ]
445
+ pub use sbp_error:: EphemerisDecodeError ;
446
+
447
+ #[ cfg( feature = "sbp-conversions" ) ]
448
+ impl std:: convert:: TryFrom < sbp:: messages:: observation:: MsgEphemerisGPS > for Ephemeris {
449
+ type Error = EphemerisDecodeError ;
450
+
451
+ fn try_from (
452
+ eph : sbp:: messages:: observation:: MsgEphemerisGPS ,
453
+ ) -> Result < Ephemeris , EphemerisDecodeError > {
454
+ use std:: convert:: TryInto ;
455
+
456
+ Ok ( Ephemeris :: new (
457
+ eph. common . sid . try_into ( ) ?,
458
+ eph. common . toe . try_into ( ) ?,
459
+ eph. common . ura ,
460
+ eph. common . fit_interval ,
461
+ eph. common . valid ,
462
+ eph. common . health_bits ,
463
+ 0 ,
464
+ EphemerisTerms :: new_kepler (
465
+ Constellation :: Gps ,
466
+ [ eph. tgd , 0. ] ,
467
+ eph. c_rc as f64 ,
468
+ eph. c_rs as f64 ,
469
+ eph. c_uc as f64 ,
470
+ eph. c_us as f64 ,
471
+ eph. c_ic as f64 ,
472
+ eph. c_is as f64 ,
473
+ eph. dn ,
474
+ eph. m0 ,
475
+ eph. ecc ,
476
+ eph. sqrta ,
477
+ eph. omega0 ,
478
+ eph. omegadot ,
479
+ eph. w ,
480
+ eph. inc ,
481
+ eph. inc_dot ,
482
+ eph. af0 as f64 ,
483
+ eph. af1 as f64 ,
484
+ eph. af2 as f64 ,
485
+ eph. toc . try_into ( ) ?,
486
+ eph. iodc ,
487
+ eph. iode as u16 ,
488
+ ) ,
489
+ ) )
490
+ }
491
+ }
492
+
493
+ #[ cfg( feature = "sbp-conversions" ) ]
494
+ impl std:: convert:: TryFrom < sbp:: messages:: observation:: MsgEphemerisGal > for Ephemeris {
495
+ type Error = EphemerisDecodeError ;
496
+
497
+ fn try_from (
498
+ eph : sbp:: messages:: observation:: MsgEphemerisGal ,
499
+ ) -> Result < Ephemeris , EphemerisDecodeError > {
500
+ use std:: convert:: TryInto ;
501
+
502
+ Ok ( Ephemeris :: new (
503
+ eph. common . sid . try_into ( ) ?,
504
+ eph. common . toe . try_into ( ) ?,
505
+ eph. common . ura ,
506
+ eph. common . fit_interval ,
507
+ eph. common . valid ,
508
+ eph. common . health_bits ,
509
+ eph. source ,
510
+ EphemerisTerms :: new_kepler (
511
+ Constellation :: Gal ,
512
+ [ eph. bgd_e1e5a , eph. bgd_e1e5b ] ,
513
+ eph. c_rc as f64 ,
514
+ eph. c_rs as f64 ,
515
+ eph. c_uc as f64 ,
516
+ eph. c_us as f64 ,
517
+ eph. c_ic as f64 ,
518
+ eph. c_is as f64 ,
519
+ eph. dn ,
520
+ eph. m0 ,
521
+ eph. ecc ,
522
+ eph. sqrta ,
523
+ eph. omega0 ,
524
+ eph. omegadot ,
525
+ eph. w ,
526
+ eph. inc ,
527
+ eph. inc_dot ,
528
+ eph. af0 as f64 ,
529
+ eph. af1 as f64 ,
530
+ eph. af2 as f64 ,
531
+ eph. toc . try_into ( ) ?,
532
+ eph. iodc ,
533
+ eph. iode as u16 ,
534
+ ) ,
535
+ ) )
536
+ }
537
+ }
538
+
408
539
impl PartialEq for Ephemeris {
409
540
fn eq ( & self , other : & Self ) -> bool {
410
541
unsafe { c_bindings:: ephemeris_equal ( & self . 0 , & other. 0 ) }
0 commit comments