1   /* Copyright 2022-2025 Thales Alenia Space
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.gnss.rflink.gps;
18  
19  import org.hipparchus.util.FastMath;
20  import org.orekit.gnss.metric.parser.Units;
21  
22  /**
23   * Container for sub-frames 2.
24   * <p>
25   * Table 20-1, sheet 2 and table 40-1, sheet 2 in
26   * <a href="https://navcen.uscg.gov/sites/default/files/pdf/gps/IS-GPS-200N.pdf">NAVSTAR
27   * GPS Space Segment/Navigation User Segment Interface</a>, IS-GPS-200N, 22 Aug 2022
28   * </p>
29   * @author Luc Maisonobe
30   * @since 12.0
31   */
32  public class SubFrame2 extends SubFrame {
33  
34      /** Index of IODE field. */
35      private static final int IODE = 7;
36  
37      /** Index of Crs field. */
38      private static final int CRS = 8;
39  
40      /** Index of Δn field. */
41      private static final int DELTA_N = 9;
42  
43      /** Index of MO field. */
44      private static final int M0 = 10;
45  
46      /** Index of Cuc field. */
47      private static final int CUC = 11;
48  
49      /** Index of e field. */
50      private static final int E = 12;
51  
52      /** Index of Cus field. */
53      private static final int CUS = 13;
54  
55      /** Index of √a field. */
56      private static final int SQRT_A = 14;
57  
58      /** Index of TOE field. */
59      private static final int TOE = 15;
60  
61      /** Index of it interval field. */
62      private static final int FIT_INTERVAL = 16;
63  
64      /** Index of AODO field. */
65      private static final int AODO = 17;
66  
67      /** Simple constructor.
68       * @param words raw words
69       */
70      SubFrame2(final int[] words) {
71  
72          // create raw container
73          super(words, AODO + 1);
74  
75          // populate container
76          setField(IODE,          3, 22,  8, words);
77          setField(CRS,           3,  6, 16, words);
78          setField(DELTA_N,       4, 14, 16, words);
79          setField(M0,            4,  6,  8, 5,  6, 24, words);
80          setField(CUC,           6, 14, 16, words);
81          setField(E,             6,  6,  8, 7,  6, 24, words);
82          setField(CUS,           8, 14, 16, words);
83          setField(SQRT_A,        8,  6,  8, 9,  6, 24, words);
84          setField(TOE,          10, 14, 16, words);
85          setField(FIT_INTERVAL, 10, 13,  1, words);
86          setField(AODO,         10,  8,  5, words);
87  
88      }
89  
90      /** Get Issue Of Data (ephemeris).
91       * @return Issue Of Data (ephemeris)
92       */
93      public int getIODE() {
94          return getField(IODE);
95      }
96  
97      /** Get Crs.
98       * @return crs (m)
99       */
100     public double getCrs() {
101         return FastMath.scalb((double) getField(CRS), -5);
102     }
103 
104     /** Get Δn.
105      * @return Δn (rad/s)
106      */
107     public double getDeltaN() {
108         return Units.SEMI_CIRCLE.toSI(FastMath.scalb((double) getField(DELTA_N), -43));
109     }
110 
111     /** Get M₀.
112      * @return M₀ (rad)
113      */
114     public double getM0() {
115         return Units.SEMI_CIRCLE.toSI(FastMath.scalb((double) getField(M0), -31));
116     }
117 
118     /** Get Cuc.
119      * @return Cuc (rad)
120      */
121     public double getCuc() {
122         return Units.SEMI_CIRCLE.toSI(FastMath.scalb((double) getField(CUC), -29));
123     }
124 
125     /** Get e.
126      * @return e
127      */
128     public double getE() {
129         return FastMath.scalb((double) getField(E), -33);
130     }
131 
132     /** Get Cus.
133      * @return Cus (rad)
134      */
135     public double getCus() {
136         return Units.SEMI_CIRCLE.toSI(FastMath.scalb((double) getField(CUS), -29));
137     }
138 
139     /** Get √a.
140      * @return d√a (√m)
141      */
142     public double getSqrtA() {
143         return FastMath.scalb((double) getField(SQRT_A), -19);
144     }
145 
146     /** Get Time Of Ephemeris.
147      * @return Time Of Ephemeris
148      */
149     public int getToe() {
150         return getField(TOE) << 4;
151     }
152 
153     /** Get fit interval.
154      * @return fit interval
155      */
156     public int getFitInterval() {
157         return getField(FIT_INTERVAL);
158     }
159 
160     /** Get Age Of data Offset.
161      * @return Age Of Data Offset (s)
162      */
163     public int getAODO() {
164         return getField(AODO) * 900;
165     }
166 
167 }