1   /* Copyright 2002-2025 CS GROUP
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.metric.messages.rtcm;
18  
19  import java.util.ArrayList;
20  
21  import org.junit.jupiter.api.Assertions;
22  import org.junit.jupiter.api.BeforeEach;
23  import org.junit.jupiter.api.Test;
24  import org.orekit.data.DataContext;
25  import org.orekit.gnss.metric.messages.rtcm.correction.Rtcm1243;
26  import org.orekit.gnss.metric.messages.rtcm.correction.RtcmCombinedCorrectionData;
27  import org.orekit.gnss.metric.parser.ByteArrayEncodedMessage;
28  import org.orekit.gnss.metric.parser.EncodedMessage;
29  import org.orekit.gnss.metric.parser.RtcmMessagesParser;
30  
31  public class Rtcm1243Test {
32  
33      private double eps = 1.0e-13;
34  
35      private EncodedMessage message;
36  
37      private ArrayList<Integer> messages;
38  
39      @BeforeEach
40      public void setUp() {
41  
42          final String m = "010011011011" +                       // Message Number: 1243
43                           "00001111110011000111" +               // Galileo Epoch Time 1s
44                           "0101" +                               // SSR Update Interval
45                           "0" +                                  // Multiple Message Indicator
46                           "0" +                                  // Satellite Reference Datum
47                           "0111" +                               // IOD SSR
48                           "0000111101101111" +                   // SSR Provider ID
49                           "0001" +                               // SSR Solution ID
50                           "000001" +                             // No. of Satellites
51                           "000001" +                             // Satellite ID
52                           "0010000100" +                         // Galileo IOD
53                           "0000101011111101111111" +             // Delta Radial
54                           "01001010111111011111" +               // Delta Along-Track
55                           "01001010111111011111" +               // Delta Cross-Track
56                           "000010101111110111111" +              // Dot Delta Radial
57                           "0100101011111101111" +                // Dot Delta Along-Track
58                           "0100101011111101111" +                // Dot Delta Cross-Track
59                           "0011101011111101111111" +             // Delta Clock C0
60                           "001110101111110111111" +              // Delta Clock C1
61                           "0011101011111101111111000110000000";  // Delta Clock C2
62  
63          message = new ByteArrayEncodedMessage(byteArrayFromBinary(m));
64          message.start();
65  
66          messages = new ArrayList<>();
67          messages.add(1243);
68  
69      }
70  
71      @Test
72      public void testPerfectValue() {
73          final Rtcm1243 rtcm1243 = (Rtcm1243) new RtcmMessagesParser(messages, DataContext.getDefault().getTimeScales()).
74                                    parse(message, false);
75  
76          // Verify size
77          Assertions.assertEquals(1,                            rtcm1243.getData().size());
78  
79          // Verify header
80          Assertions.assertEquals(1243,                         rtcm1243.getTypeCode());
81          Assertions.assertEquals(64711.0,                      rtcm1243.getHeader().getEpochTime1s(), eps);
82          Assertions.assertEquals(30.0,                         rtcm1243.getHeader().getSsrUpdateInterval().getUpdateInterval(), eps);
83          Assertions.assertEquals(0,                            rtcm1243.getHeader().getMultipleMessageIndicator());
84          Assertions.assertEquals(7,                            rtcm1243.getHeader().getIodSsr());
85          Assertions.assertEquals(3951,                         rtcm1243.getHeader().getSsrProviderId());
86          Assertions.assertEquals(1,                            rtcm1243.getHeader().getSsrSolutionId());
87          Assertions.assertEquals(1,                            rtcm1243.getHeader().getNumberOfSatellites());
88  
89          // Verify data for satellite E01
90          final RtcmCombinedCorrectionData e01 = rtcm1243.getDataMap().get("E01").get(0);
91          Assertions.assertEquals(1,                            e01.getSatelliteID());
92          Assertions.assertEquals(132,                          e01.getGnssIod());
93          Assertions.assertEquals(18.0095,                      e01.getOrbitCorrection().getDeltaOrbitRadial(),        eps);
94          Assertions.assertEquals(122.8668,                     e01.getOrbitCorrection().getDeltaOrbitAlongTrack(),    eps);
95          Assertions.assertEquals(122.8668,                     e01.getOrbitCorrection().getDeltaOrbitCrossTrack(),    eps);
96          Assertions.assertEquals(0.090047,                     e01.getOrbitCorrection().getDotOrbitDeltaRadial(),     eps);
97          Assertions.assertEquals(0.614332,                     e01.getOrbitCorrection().getDotOrbitDeltaAlongTrack(), eps);
98          Assertions.assertEquals(0.614332,                     e01.getOrbitCorrection().getDotOrbitDeltaCrossTrack(), eps);
99          Assertions.assertEquals(96.6527,                      e01.getClockCorrection().getDeltaClockC0(),            eps);
100         Assertions.assertEquals(0.483263,                     e01.getClockCorrection().getDeltaClockC1(),            eps);
101         Assertions.assertEquals(0.61857734,                   e01.getClockCorrection().getDeltaClockC2(),            eps);
102     }
103 
104     private byte[] byteArrayFromBinary(String radix2Value) {
105         final byte[] array = new byte[radix2Value.length() / 8];
106         for (int i = 0; i < array.length; ++i) {
107             for (int j = 0; j < 8; ++j) {
108                 if (radix2Value.charAt(8 * i + j) != '0') {
109                     array[i] |= 0x1 << (7 - j);
110                 }
111             }
112         }
113         return array;
114     }
115 
116 }