1   /* Copyright 2002-2025 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.RinexNavigationParser;
22  import org.orekit.files.rinex.navigation.parsers.ParseInfo;
23  import org.orekit.files.rinex.utils.ParsingUtils;
24  import org.orekit.propagation.analytical.gnss.data.SBASNavigationMessage;
25  import org.orekit.time.TimeScale;
26  import org.orekit.utils.units.Unit;
27  
28  /** Parser for SBAS.
29   * @author Bryan Cazabonne
30   * @author Luc Maisonobe
31   * @since 14.0
32   */
33  public class SbasParser extends AbstractEphemerisParser<SBASNavigationMessage> {
34  
35      /** Simple constructor.
36       * @param parseInfo container for parsing data
37       * @param message container for navigation message
38       */
39      public SbasParser(final ParseInfo parseInfo, final SBASNavigationMessage message) {
40          super(parseInfo, message);
41      }
42  
43      /** {@inheritDoc} */
44      @Override
45      public void parseLine00() {
46  
47          final ParseInfo parseInfo = getParseInfo();
48          final SBASNavigationMessage message = getMessage();
49  
50          // parse PRN
51          message.setPRN(ParsingUtils.parseInt(parseInfo.getLine(), 1, 2));
52  
53          // Time scale (UTC for Rinex 3.01 and GPS for other RINEX versions)
54          final int version100 = (int) FastMath.rint(parseInfo.getHeader().getFormatVersion() * 100);
55          final TimeScale timeScale = (version100 == 301) ?
56                                      parseInfo.getTimeScales().getUTC() :
57                                      parseInfo.getTimeScales().getGPS();
58  
59          message.setEpochToc(parseInfo.parseDate(timeScale));
60          message.setAGf0(parseInfo.parseDouble2(Unit.SECOND));
61          message.setAGf1(parseInfo.parseDouble3(RinexNavigationParser.S_PER_S));
62          message.setTime(parseInfo.parseDouble4(Unit.SECOND));
63  
64          // Set the ephemeris epoch (same as time of clock epoch)
65          message.setDate(message.getEpochToc());
66  
67      }
68  
69      /** {@inheritDoc} */
70      @Override
71      public void parseLine01() {
72          super.parseLine01();
73          getMessage().setHealth(getParseInfo().parseDouble4(Unit.NONE));
74      }
75  
76      /** {@inheritDoc} */
77      @Override
78      public void parseLine02() {
79          super.parseLine02();
80          getMessage().setURA(getParseInfo().parseDouble4(Unit.NONE));
81      }
82  
83      /** {@inheritDoc} */
84      @Override
85      public void parseLine03() {
86          super.parseLine03();
87          final ParseInfo parseInfo = getParseInfo();
88          final SBASNavigationMessage message = getMessage();
89          message.setIODN(parseInfo.parseDouble4(Unit.NONE));
90          parseInfo.closePendingRecord();
91      }
92  
93      /** {@inheritDoc} */
94      @Override
95      public void closeRecord(final RinexNavigation file) {
96          file.addSBASNavigationMessage(getMessage());
97      }
98  
99  }