SubFrame4C.java

  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. import org.hipparchus.util.MathUtils;

  19. /**
  20.  * Container for sub-frames 4, page 13.
  21.  * <p>
  22.  * Table 40-1, sheet 10 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 SubFrame4C extends SubFrame45 {

  30.     /** Number of Estimated Range Deviations. */
  31.     public static final int NB_ERD = 30;

  32.     /** Index of availability indicator field. */
  33.     private static final int AVAILABILITY_INDICATOR = 9;

  34.     /** Size of Estimated Range Deviations. */
  35.     private static final int ERD_SIZE = 6;

  36.     /** Simple constructor.
  37.      * @param words raw words
  38.      */
  39.     SubFrame4C(final int[] words) {

  40.         // create raw container
  41.         super(words, AVAILABILITY_INDICATOR + NB_ERD + 1);

  42.         // populate container
  43.         int field = AVAILABILITY_INDICATOR;
  44.         int word  = 3;
  45.         int shift = 20;
  46.         setField(field, word, shift, 2, words);
  47.         for (int i = 0; i < NB_ERD; ++i) {
  48.             if (shift >= ERD_SIZE + PARITY_SIZE) {
  49.                 // current word contains a complete ERD
  50.                 shift -= ERD_SIZE;
  51.                 setField(++field, word, shift, ERD_SIZE, words);
  52.             } else {
  53.                 // current word contains only the MSF of next ERD
  54.                 final int msbBits = shift - PARITY_SIZE;
  55.                 shift += WORD_SIZE - ERD_SIZE;
  56.                 setField(++field,
  57.                          word,     PARITY_SIZE,                      msbBits,
  58.                          word + 1, WORD_SIZE - (ERD_SIZE - msbBits), ERD_SIZE - msbBits, words);
  59.                 ++word;
  60.             }
  61.         }

  62.     }

  63.     /** Get an Estimated Range Deviation.
  64.      * @param index index of the ERD (between 1 and {@link #NB_ERD})
  65.      * @return Estimated Range Deviation
  66.      */
  67.     public int getERD(final int index) {
  68.         MathUtils.checkRangeInclusive(index, 1, NB_ERD);
  69.         return getField(AVAILABILITY_INDICATOR + index);
  70.     }

  71. }