rinex/navigation/
frame.rs1use crate::{
2 navigation::{EarthOrientation, Ephemeris, IonosphereModel, TimeOffset},
3 prelude::ParsingError,
4};
5
6#[cfg(doc)]
7use crate::prelude::TimeScale;
8
9#[cfg(feature = "serde")]
10use serde::{Deserialize, Serialize};
11
12#[derive(Default, Debug, Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
14#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
15pub enum NavFrameType {
16 #[default]
18 Ephemeris,
19
20 SystemTimeOffset,
22
23 EarthOrientation,
25
26 IonosphereModel,
28}
29
30impl std::fmt::Display for NavFrameType {
31 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
32 match self {
33 Self::Ephemeris => f.write_str("EPH"),
34 Self::SystemTimeOffset => f.write_str("STO"),
35 Self::EarthOrientation => f.write_str("EOP"),
36 Self::IonosphereModel => f.write_str("ION"),
37 }
38 }
39}
40
41impl std::str::FromStr for NavFrameType {
42 type Err = ParsingError;
43 fn from_str(s: &str) -> Result<Self, Self::Err> {
44 let c = s.to_uppercase();
45 let c = c.trim();
46 match c {
47 "EPH" => Ok(Self::Ephemeris),
48 "STO" => Ok(Self::SystemTimeOffset),
49 "EOP" => Ok(Self::EarthOrientation),
50 "ION" => Ok(Self::IonosphereModel),
51 _ => Err(ParsingError::NavFrameClass),
52 }
53 }
54}
55
56#[derive(Debug, Clone, PartialEq)]
59#[cfg_attr(feature = "serde", derive(Serialize))]
60pub enum NavFrame {
61 EPH(Ephemeris),
65
66 EOP(EarthOrientation),
69
70 ION(IonosphereModel),
75
76 STO(TimeOffset),
81}
82
83impl NavFrame {
84 pub fn as_ephemeris(&self) -> Option<&Ephemeris> {
86 match self {
87 Self::EPH(eph) => Some(eph),
88 _ => None,
89 }
90 }
91
92 pub fn as_mut_ephemeris(&mut self) -> Option<&mut Ephemeris> {
94 match self {
95 Self::EPH(eph) => Some(eph),
96 _ => None,
97 }
98 }
99
100 pub fn as_system_time(&self) -> Option<&TimeOffset> {
102 match self {
103 Self::STO(fr) => Some(fr),
104 _ => None,
105 }
106 }
107
108 pub fn as_mut_system_time(&mut self) -> Option<&mut TimeOffset> {
110 match self {
111 Self::STO(fr) => Some(fr),
112 _ => None,
113 }
114 }
115
116 pub fn as_ionosphere_model(&self) -> Option<&IonosphereModel> {
118 match self {
119 Self::ION(fr) => Some(fr),
120 _ => None,
121 }
122 }
123
124 pub fn as_mut_ionosphere_model(&mut self) -> Option<&mut IonosphereModel> {
126 match self {
127 Self::ION(fr) => Some(fr),
128 _ => None,
129 }
130 }
131
132 pub fn as_earth_orientation(&self) -> Option<&EarthOrientation> {
134 match self {
135 Self::EOP(fr) => Some(fr),
136 _ => None,
137 }
138 }
139
140 pub fn as_mut_earth_orientation(&mut self) -> Option<&mut EarthOrientation> {
142 match self {
143 Self::EOP(fr) => Some(fr),
144 _ => None,
145 }
146 }
147}