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 5, page 1-24.
24   * <p>
25   * Table 20-1, sheet 4 and table 40-1, sheet 4 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 SubFrameAlmanac extends SubFrame45 {
33  
34      /** Index of e field. */
35      private static final int E = 9;
36  
37      /** Index of TOA field. */
38      private static final int TOA = 10;
39  
40      /** Index of δi field. */
41      private static final int DELTA_I = 11;
42  
43      /** Index of dot(Ω) field. */
44      private static final int OMEGA_DOT = 12;
45  
46      /** Index of SV health field. */
47      private static final int SV_HEALTH = 13;
48  
49      /** Index of √a field. */
50      private static final int SQRT_A = 14;
51  
52      /** Index of Ω₀ field. */
53      private static final int UPPERCASE_OMEGA_0 = 15;
54  
55      /** Index of ω field. */
56      private static final int LOWERCASE_OMEGA = 16;
57  
58      /** Index of M₀ field. */
59      private static final int M0 = 17;
60  
61      /** Index of AF0 field. */
62      private static final int AF0 = 18;
63  
64      /** Index of AF1 field. */
65      private static final int AF1 = 19;
66  
67      /** Simple constructor.
68       * @param words raw words
69       */
70      SubFrameAlmanac(final int[] words) {
71  
72          // create raw container
73          super(words, AF1 + 1);
74  
75          // populate container
76          setField(E,                  3,  6, 16, words);
77          setField(TOA,                4, 22,  8, words);
78          setField(DELTA_I,            4,  6, 16, words);
79          setField(OMEGA_DOT,          5, 14, 16, words);
80          setField(SV_HEALTH,          5,  6,  8, words);
81          setField(SQRT_A,             6,  6, 24, words);
82          setField(UPPERCASE_OMEGA_0,  7,  6, 24, words);
83          setField(LOWERCASE_OMEGA,    8,  6, 24, words);
84          setField(M0,                 9,  6, 24, words);
85          setField(AF0,               10, 22,  8, 10,  8,  3, words);
86          setField(AF1,               10, 11, 11, words);
87  
88      }
89  
90      /** Get the PRN code phase of the SV.
91       * @return PRN code phase
92       */
93      public int getPRN() {
94          // sub-frames that contain almanacs use the SV-ID for the PRN
95          return getSvId();
96      }
97  
98      /** Get eccentricity.
99       * @return eccentricity
100      */
101     public double getE() {
102         return FastMath.scalb((double) getField(E), -21);
103     }
104 
105     /** Get Time Of Almanac.
106      * @return Time Of Almanac (seconds)
107      */
108     public int getToaA() {
109         return getField(TOA) << 12;
110     }
111 
112     /** Get Δi.
113      * @return Δi (rad)
114      */
115     public double getDeltai() {
116         return Units.SEMI_CIRCLE.toSI(FastMath.scalb((double) getField(DELTA_I), -19));
117     }
118 
119     /** Get dot(Ω).
120      * @return dot(Ω) (rad/s)
121      */
122     public double getOmegaDot() {
123         return Units.SEMI_CIRCLE.toSI(FastMath.scalb((double) getField(OMEGA_DOT), -38));
124     }
125 
126     /** Get SV health.
127      * @return SV health
128      */
129     public int getSvHealth() {
130         return getField(SV_HEALTH);
131     }
132 
133     /** Get √a.
134      * @return d√a (√m)
135      */
136     public double getSqrtA() {
137         return FastMath.scalb((double) getField(SQRT_A), -11);
138     }
139 
140     /** Get Ω₀.
141      * @return Ω₀ (rad)
142      */
143     public double getUppercaseOmega0() {
144         return Units.SEMI_CIRCLE.toSI(FastMath.scalb((double) getField(UPPERCASE_OMEGA_0), -23));
145     }
146 
147     /** Get ω.
148      * @return ω(rad)
149      */
150     public double getLowercaseOmega() {
151         return Units.SEMI_CIRCLE.toSI(FastMath.scalb((double) getField(LOWERCASE_OMEGA), -23));
152     }
153 
154     /** Get M₀.
155      * @return M₀ (rad)
156      */
157     public double getM0() {
158         return Units.SEMI_CIRCLE.toSI(FastMath.scalb((double) getField(M0), -23));
159     }
160 
161     /** Get af₀.
162      * @return af₀ (second)
163      */
164     public double getAF0() {
165         return FastMath.scalb((double) getField(AF0), -20);
166     }
167 
168     /** Get af₁.
169      * @return af₁ (second/second)
170      */
171     public double getAF1() {
172         return FastMath.scalb((double) getField(AF1), -38);
173     }
174 
175 }