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.MathUtils;
20
21 /**
22 * Container for sub-frames 4, page 25.
23 * <p>
24 * Table 20-1, sheet 9 and table 40-1, sheet 9 in
25 * <a href="https://navcen.uscg.gov/sites/default/files/pdf/gps/IS-GPS-200N.pdf">NAVSTAR
26 * GPS Space Segment/Navigation User Segment Interface</a>, IS-GPS-200N, 22 Aug 2022
27 * </p>
28 * @author Luc Maisonobe
29 * @since 12.0
30 */
31 public class SubFrame4E extends SubFrame45 {
32
33 /** Number of Anti-spoofing entries. */
34 public static final int NB_AS = 32;
35
36 /** Number of SV health entries. */
37 public static final int NB_SVH = 8;
38
39 /** Size of Anti-spoofing. */
40 private static final int AS_SIZE = 4;
41
42 /** Size of SV Health. */
43 private static final int SVH_SIZE = 6;
44
45 /** Index of first AS field. */
46 private static final int FIRST_AS = 9;
47
48 /** Index of reserved field in word 8. */
49 private static final int RESERVED_8 = FIRST_AS + NB_AS;
50
51 /** Index of reserved field in word 10. */
52 private static final int RESERVED_10 = RESERVED_8 + 1 + NB_AS + NB_SVH;
53
54 /** Simple constructor.
55 * @param words raw words
56 */
57 SubFrame4E(final int[] words) {
58
59 // create raw container
60 super(words, RESERVED_10 + 1);
61
62 // populate container
63 int field = FIRST_AS - 1;
64 int word = 3;
65 int shift = 22;
66
67 // anti-spoofing
68 for (int i = 0; i < NB_AS; ++i) {
69 if (shift >= AS_SIZE + PARITY_SIZE) {
70 // current word contains a complete AS
71 shift -= AS_SIZE;
72 setField(++field, word, shift, AS_SIZE, words);
73 } else {
74 // current word is exhausted
75 shift = WORD_SIZE - AS_SIZE;
76 setField(++field, ++word, shift, AS_SIZE, words);
77 }
78 }
79
80 // 2 bits for system use
81 shift -= 2;
82 setField(RESERVED_8, word, shift, 2, words);
83
84 // SV health
85 for (int i = 0; i < NB_SVH; ++i) {
86 if (shift >= SVH_SIZE + PARITY_SIZE) {
87 // current word contains a complete SVH
88 shift -= SVH_SIZE;
89 setField(++field, word, shift, SVH_SIZE, words);
90 } else {
91 // current word is exhausted
92 shift = WORD_SIZE - SVH_SIZE;
93 setField(++field, ++word, shift, SVH_SIZE, words);
94 }
95 }
96
97 setField(RESERVED_10, 10, 8, 4, words);
98
99 }
100
101 /** Get the anti-spoofing for a satellite.
102 * @param index in the sub-frame (from 1 to 32, beware it is not the satellite number,
103 * it is also related to {@link #getDataId()})
104 * @return anti-spoofing
105 */
106 public int getAntiSpoofing(final int index) {
107 MathUtils.checkRangeInclusive(index, 1, NB_AS);
108 return getField(FIRST_AS + index - 1);
109 }
110
111 /** Get the reserved field in word 8.
112 * @return reserved field in word 8
113 */
114 public int getReserved8() {
115 return getField(RESERVED_8);
116 }
117
118 /** Get the Sv health for a satellite.
119 * @param index in the sub-frame (from 1 to 7 or 1 to 8 depending on
120 * {@link #getDataId()}, beware it is not the satellite number,
121 * it is also related to {@link #getDataId()}), an
122 * @return anti-spoofing
123 */
124 public int getSvHealth(final int index) {
125 MathUtils.checkRangeInclusive(index, 1, NB_SVH);
126 return getField(RESERVED_8 + index);
127 }
128
129 /** Get the reserved field in word 10.
130 * @return reserved field in word 10
131 */
132 public int getReserved10() {
133 return getField(RESERVED_10);
134 }
135
136 }