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.hipparchus.util.FastMath;
20  import org.orekit.files.rinex.navigation.RinexNavigation;
21  import org.orekit.files.rinex.navigation.parsers.ParseInfo;
22  import org.orekit.propagation.analytical.gnss.data.NavICLegacyNavigationMessage;
23  import org.orekit.propagation.analytical.gnss.data.NavICLegacyNavigationMessageFactory;
24  import org.orekit.time.GNSSDate;
25  import org.orekit.utils.units.Unit;
26  
27  /** Parser for NavIC legacy.
28   * @author Bryan Cazabonne
29   * @author Luc Maisonobe
30   * @since 14.0
31   */
32  public class NavICLnavParser
33      extends LegacyNavigationParser<NavICLegacyNavigationMessage, NavICLegacyNavigationMessageFactory> {
34  
35      /** URA index to URA mapping (table 23 of NavIC ICD). */
36      // CHECKSTYLE: stop Indentation check
37      static final double[] NAVIC_URA = {
38             2.40,    3.40,    4.85,   6.85,
39             9.65,   13.65,   24.00,  48.00,
40            96.00,  192.00,  384.00, 768.00,
41          1536.00, 3072.00, 6144.00, Double.NaN
42      };
43      // CHECKSTYLE: resume Indentation check
44  
45      /** Simple constructor.
46       * @param parseInfo container for parsing data
47       * @param factory factory for navigation message
48       */
49      public NavICLnavParser(final ParseInfo parseInfo, final NavICLegacyNavigationMessageFactory factory) {
50          super(parseInfo, factory);
51      }
52  
53      /** {@inheritDoc} */
54      @Override
55      public void parseLine00() {
56          final ParseInfo parseInfo = getParseInfo();
57          parseSvEpochSvClockLine(parseInfo.getTimeScales().getNavIC(), parseInfo, getFactory());
58      }
59  
60      /** {@inheritDoc} */
61      @Override
62      public void parseLine01() {
63          super.parseLine01();
64          // for NavIC legacy, Issue Of Data applies to both clock and ephemeris
65          final NavICLegacyNavigationMessageFactory factory = getFactory();
66          factory.setIodc(factory.getIode());
67      }
68  
69      /** {@inheritDoc} */
70      @Override
71      public void parseLine06() {
72          super.parseLine06();
73  
74          // for NavIC legacy, the User Range Accurary is provided as an index in a table
75          // the base class implementation just parsed it as a double, we need to fix it
76          final NavICLegacyNavigationMessageFactory factory = getFactory();
77          final int index = (int) FastMath.rint(factory.getSvAccuracy());
78          factory.setSvAccuracy(NAVIC_URA[FastMath.min(index, NAVIC_URA.length - 1)]);
79  
80      }
81  
82      /** {@inheritDoc} */
83      @Override
84      public void parseLine07() {
85          final ParseInfo parseInfo = getParseInfo();
86          final NavICLegacyNavigationMessageFactory factory = getFactory();
87          factory.setTransmissionTime(new GNSSDate(factory.getTimeOfEphemeris().getWeekNumber(),
88                                                   parseInfo.parseDouble1(Unit.SECOND),
89                                                   factory.getSystem()));
90          // there is no fit interval in NavIC L message
91          parseInfo.closePendingRecord();
92      }
93  
94      /** {@inheritDoc} */
95      @Override
96      public void closeRecord(final RinexNavigation file) {
97          file.addNavICLegacyNavigationMessage(getMessage());
98      }
99  
100 }