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.Rtcm1058;
26  import org.orekit.gnss.metric.messages.rtcm.correction.RtcmClockCorrectionData;
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 Rtcm1058Test {
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 = "010000100010" +                      // Message number: 1058
43                           "01111110011000111111" +              // GPS Epoch Time 1s
44                           "0101" +                              // SSR Update Interval
45                           "0" +                                 // Multiple Message Indicator
46                           "0111" +                              // IOD SSR
47                           "0000111101101111" +                  // SSR Provider ID
48                           "0001" +                              // SSR Solution ID
49                           "000001" +                            // No. of Satellites
50                           "000001" +                            // Satellite ID
51                           "0011101011111101111111" +            // Delta Clock C0
52                           "001110101111110111111" +             // Delta Clock C1
53                           "0011101011111101111111000110000000"; // Delta Clock C2
54  
55          message = new ByteArrayEncodedMessage(byteArrayFromBinary(m));
56          message.start();
57  
58          messages = new ArrayList<>();
59          messages.add(1058);
60  
61      }
62  
63      @Test
64      public void testPerfectValue() {
65          final Rtcm1058 rtcm1058 = (Rtcm1058) new RtcmMessagesParser(messages, DataContext.getDefault().getTimeScales()).
66                                    parse(message, false);
67  
68          // Verify size
69          Assertions.assertEquals(1,                            rtcm1058.getData().size());
70  
71          // Verify header
72          Assertions.assertEquals(1058,                         rtcm1058.getTypeCode());
73          Assertions.assertEquals(517695.0,                     rtcm1058.getHeader().getEpochTime1s(), eps);
74          Assertions.assertEquals(30.0,                         rtcm1058.getHeader().getSsrUpdateInterval().getUpdateInterval(), eps);
75          Assertions.assertEquals(0,                            rtcm1058.getHeader().getMultipleMessageIndicator());
76          Assertions.assertEquals(7,                            rtcm1058.getHeader().getIodSsr());
77          Assertions.assertEquals(3951,                         rtcm1058.getHeader().getSsrProviderId());
78          Assertions.assertEquals(1,                            rtcm1058.getHeader().getSsrSolutionId());
79          Assertions.assertEquals(1,                            rtcm1058.getHeader().getNumberOfSatellites());
80  
81          // Verify data for satellite G01
82          final RtcmClockCorrectionData g01 = rtcm1058.getDataMap().get("G01").get(0);
83          Assertions.assertEquals(1,                            g01.getSatelliteID());
84          Assertions.assertEquals(96.6527,                      g01.getClockCorrection().getDeltaClockC0(),            eps);
85          Assertions.assertEquals(0.483263,                     g01.getClockCorrection().getDeltaClockC1(),            eps);
86          Assertions.assertEquals(0.61857734,                   g01.getClockCorrection().getDeltaClockC2(),            eps);
87      }
88  
89      private byte[] byteArrayFromBinary(String radix2Value) {
90          final byte[] array = new byte[radix2Value.length() / 8];
91          for (int i = 0; i < array.length; ++i) {
92              for (int j = 0; j < 8; ++j) {
93                  if (radix2Value.charAt(8 * i + j) != '0') {
94                      array[i] |= 0x1 << (7 - j);
95                  }
96              }
97          }
98          return array;
99      }
100 
101 }