1   /* Copyright 2002-2026 CS GROUP
2    * Licensed to CS GROUP (CS) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * CS licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.orekit.files.rinex.navigation.parsers.ephemeris;
18  
19  import org.orekit.files.rinex.navigation.RinexNavigationParser;
20  import org.orekit.files.rinex.navigation.parsers.ParseInfo;
21  import org.orekit.files.rinex.navigation.parsers.RecordLineParser;
22  import org.orekit.propagation.analytical.gnss.data.AbstractNavigationMessage;
23  import org.orekit.propagation.analytical.gnss.data.AbstractNavigationMessageFactory;
24  import org.orekit.propagation.analytical.gnss.data.GNSSOrbitalElementsFactory;
25  import org.orekit.time.GNSSDate;
26  import org.orekit.utils.units.Unit;
27  
28  /** Parser for abstract navigation messages.
29   * @param <T> type of the navigation message
30   * @param <F> type of the navigation message factory
31   * @author Bryan Cazabonne
32   * @author Luc Maisonobe
33   * @since 14.0
34   */
35  public abstract class AbstractNavigationParser<T extends AbstractNavigationMessage<T>,
36                                                 F extends AbstractNavigationMessageFactory<T>>
37      extends RecordLineParser {
38  
39      /** Container for parsing data. */
40      private final ParseInfo parseInfo;
41  
42      /** Factory for navigation factory. */
43      private final F factory;
44  
45      /** Simple constructor.
46       * @param parseInfo container for parsing data
47       * @param factory factory for navigation message
48       */
49      protected AbstractNavigationParser(final ParseInfo parseInfo, final F factory) {
50          this.parseInfo = parseInfo;
51          this.factory   = factory;
52      }
53  
54      /** Get the factory.
55       * @return factory
56       */
57      protected F getFactory() {
58          return factory;
59      }
60  
61      /** Get the container for parsing data.
62       * @return container for parsing data
63       */
64      public ParseInfo getParseInfo() {
65          return parseInfo;
66      }
67  
68      /** Get the container for the navigation factory.
69       * @return container for the navigation message
70       */
71      public T getMessage() {
72          return factory.createFromDrivers();
73      }
74  
75      /** {@inheritDoc} */
76      @Override
77      public void parseLine00() {
78          if (parseInfo.getHeader().getFormatVersion() < 3.0) {
79              parseSvEpochSvClockLineRinex2(parseInfo.getLine(), parseInfo.getTimeScales().getGPS(), factory);
80          } else {
81              parseSvEpochSvClockLine(parseInfo.getTimeScales().getGPS(), parseInfo, factory);
82          }
83      }
84  
85      /** {@inheritDoc} */
86      @Override
87      public void parseLine01() {
88          factory.getCrsDriver().setValue(parseInfo.parseDouble2(Unit.METRE));
89          factory.getDeltaN0Driver().setValue(parseInfo.parseDouble3(RinexNavigationParser.RAD_PER_S));
90          factory.
91              getOrbitalParametersDrivers().
92              findByName(GNSSOrbitalElementsFactory.MEAN_ANOMALY).
93              setValue(parseInfo.parseDouble4(Unit.RADIAN));
94      }
95  
96      /** {@inheritDoc} */
97      @Override
98      public void parseLine02() {
99          factory.getCucDriver().setValue(parseInfo.parseDouble1(Unit.RADIAN));
100         factory.
101             getOrbitalParametersDrivers().
102             findByName(GNSSOrbitalElementsFactory.ECCENTRICITY).
103             setValue(parseInfo.parseDouble2(Unit.NONE));
104         factory.getCusDriver().setValue(parseInfo.parseDouble3(Unit.RADIAN));
105         final double sqrtA = parseInfo.parseDouble4(RinexNavigationParser.SQRT_M);
106         factory.
107             getOrbitalParametersDrivers().
108             findByName(GNSSOrbitalElementsFactory.SEMI_MAJOR_AXIS).
109             setValue(sqrtA * sqrtA);
110     }
111 
112     /** {@inheritDoc} */
113     @Override
114     public void parseLine03() {
115         factory.getTimeDriver().setValue(parseInfo.parseDouble1(Unit.SECOND));
116         factory.getCicDriver().setValue(parseInfo.parseDouble2(Unit.RADIAN));
117         factory.
118             getOrbitalParametersDrivers().
119             findByName(GNSSOrbitalElementsFactory.NODE_LONGITUDE).
120             setValue(parseInfo.parseDouble3(Unit.RADIAN));
121         factory.getCisDriver().setValue(parseInfo.parseDouble4(Unit.RADIAN));
122     }
123 
124     /** {@inheritDoc} */
125     @Override
126     public void parseLine04() {
127         factory.
128             getOrbitalParametersDrivers().
129             findByName(GNSSOrbitalElementsFactory.INCLINATION).
130             setValue(parseInfo.parseDouble1(Unit.RADIAN));
131         factory.getCrcDriver().setValue(parseInfo.parseDouble2(Unit.METRE));
132         factory.
133             getOrbitalParametersDrivers().
134             findByName(GNSSOrbitalElementsFactory.ARGUMENT_OF_PERIAPSIS).
135             setValue(parseInfo.parseDouble3(Unit.RADIAN));
136         factory.getOmegaDotDriver().setValue(parseInfo.parseDouble4(RinexNavigationParser.RAD_PER_S));
137     }
138 
139     /** {@inheritDoc} */
140     @Override
141     public void parseLine05() {
142         factory.getIDotDriver().setValue(parseInfo.parseDouble1(RinexNavigationParser.RAD_PER_S));
143         factory.setTimeOfEphemeris(new GNSSDate(parseInfo.parseInt3(), factory.getTimeDriver().getValue(),
144                                                 factory.getSystem()));
145     }
146 
147 }