SubFrame4E.java

  1. /* Copyright 2002-2024 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. import org.hipparchus.util.MathUtils;

  19. /**
  20.  * Container for sub-frames 4, page 25.
  21.  * <p>
  22.  * Table 20-1, sheet 9 and table 40-1, sheet 9 in
  23.  * <a href="https://navcen.uscg.gov/sites/default/files/pdf/gps/IS-GPS-200N.pdf">NAVSTAR
  24.  * GPS Space Segment/Navigation User Segment Interface</a>, IS-GPS-200N, 22 Aug 2022
  25.  * </p>
  26.  * @author Luc Maisonobe
  27.  * @since 12.0
  28.  */
  29. public class SubFrame4E extends SubFrame45 {

  30.     /** Number of Anti-spoofing entries. */
  31.     public static final int NB_AS = 32;

  32.     /** Number of SV health entries. */
  33.     public static final int NB_SVH = 8;

  34.     /** Size of Anti-spoofing. */
  35.     private static final int AS_SIZE = 4;

  36.     /** Size of SV Health. */
  37.     private static final int SVH_SIZE = 6;

  38.     /** Index of first AS field. */
  39.     private static final int FIRST_AS = 9;

  40.     /** Index of reserved field in word 8. */
  41.     private static final int RESERVED_8 = FIRST_AS + NB_AS;

  42.     /** Index of reserved field in word 10. */
  43.     private static final int RESERVED_10 = RESERVED_8 + 1 + NB_AS + NB_SVH;

  44.     /** Simple constructor.
  45.      * @param words raw words
  46.      */
  47.     SubFrame4E(final int[] words) {

  48.         // create raw container
  49.         super(words, RESERVED_10 + 1);

  50.         // populate container
  51.         int field = FIRST_AS - 1;
  52.         int word  = 3;
  53.         int shift = 22;

  54.         // anti-spoofing
  55.         for (int i = 0; i < NB_AS; ++i) {
  56.             if (shift >= AS_SIZE + PARITY_SIZE) {
  57.                 // current word contains a complete AS
  58.                 shift -= AS_SIZE;
  59.                 setField(++field, word, shift, AS_SIZE, words);
  60.             } else {
  61.                 // current word is exhausted
  62.                 shift = WORD_SIZE - AS_SIZE;
  63.                 setField(++field, ++word, shift, AS_SIZE, words);
  64.             }
  65.         }

  66.         // 2 bits for system use
  67.         shift -= 2;
  68.         setField(RESERVED_8, word, shift, 2, words);

  69.         // SV health
  70.         for (int i = 0; i < NB_SVH; ++i) {
  71.             if (shift >= SVH_SIZE + PARITY_SIZE) {
  72.                 // current word contains a complete SVH
  73.                 shift -= SVH_SIZE;
  74.                 setField(++field, word, shift, SVH_SIZE, words);
  75.             } else {
  76.                 // current word is exhausted
  77.                 shift = WORD_SIZE - SVH_SIZE;
  78.                 setField(++field, ++word, shift, SVH_SIZE, words);
  79.             }
  80.         }

  81.         setField(RESERVED_10, 10,  8, 4, words);

  82.     }

  83.     /** Get the anti-spoofing for a satellite.
  84.      * @param index in the sub-frame (from 1 to 32, beware it is not the satellite number,
  85.      * it is also related to {@link #getDataId()})
  86.      * @return anti-spoofing
  87.      */
  88.     public int getAntiSpoofing(final int index) {
  89.         MathUtils.checkRangeInclusive(index, 1, NB_AS);
  90.         return getField(FIRST_AS + index - 1);
  91.     }

  92.     /** Get the reserved field in word 8.
  93.      * @return reserved field in word 8
  94.      */
  95.     public int getReserved8() {
  96.         return getField(RESERVED_8);
  97.     }

  98.     /** Get the Sv health for a satellite.
  99.      * @param index in the sub-frame (from 1 to 7 or 1 to 8 depending on
  100.      * {@link #getDataId()}, beware it is not the satellite number,
  101.      * it is also related to {@link #getDataId()}), an
  102.      * @return anti-spoofing
  103.      */
  104.     public int getSvHealth(final int index) {
  105.         MathUtils.checkRangeInclusive(index, 1, NB_SVH);
  106.         return getField(RESERVED_8 + index);
  107.     }

  108.     /** Get the reserved field in word 10.
  109.      * @return reserved field in word 10
  110.      */
  111.     public int getReserved10() {
  112.         return getField(RESERVED_10);
  113.     }

  114. }