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.Rtcm1057;
26  import org.orekit.gnss.metric.messages.rtcm.correction.RtcmOrbitCorrectionData;
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 Rtcm1057Test {
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 = "010000100001" +                      // Message number: 1057
43                           "01111110011000111111" +              // GPS 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                           "10000100" +                          // IODE
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                           "01001010111111011110000000";         // Dot Delta Cross-Track
59  
60          message = new ByteArrayEncodedMessage(byteArrayFromBinary(m));
61          message.start();
62  
63          messages = new ArrayList<>();
64          messages.add(1057);
65  
66      }
67  
68      @Test
69      public void testPerfectValue() {
70          final Rtcm1057 rtcm1057 = (Rtcm1057) new RtcmMessagesParser(messages, DataContext.getDefault().getTimeScales()).
71                                    parse(message, false);
72  
73          // Verify size
74          Assertions.assertEquals(1,                            rtcm1057.getData().size());
75  
76          // Verify header
77          Assertions.assertEquals(1057,                         rtcm1057.getTypeCode());
78          Assertions.assertEquals(517695.0,                     rtcm1057.getHeader().getEpochTime1s(), eps);
79          Assertions.assertEquals(30.0,                         rtcm1057.getHeader().getSsrUpdateInterval().getUpdateInterval(), eps);
80          Assertions.assertEquals(0,                            rtcm1057.getHeader().getMultipleMessageIndicator());
81          Assertions.assertEquals(7,                            rtcm1057.getHeader().getIodSsr());
82          Assertions.assertEquals(3951,                         rtcm1057.getHeader().getSsrProviderId());
83          Assertions.assertEquals(1,                            rtcm1057.getHeader().getSsrSolutionId());
84          Assertions.assertEquals(1,                            rtcm1057.getHeader().getNumberOfSatellites());
85  
86          // Verify data for satellite G01
87          final RtcmOrbitCorrectionData g01 = rtcm1057.getDataMap().get("G01").get(0);
88          Assertions.assertEquals(1,                            g01.getSatelliteID());
89          Assertions.assertEquals(132,                          g01.getGnssIod());
90          Assertions.assertEquals(18.0095,                      g01.getOrbitCorrection().getDeltaOrbitRadial(),        eps);
91          Assertions.assertEquals(122.8668,                     g01.getOrbitCorrection().getDeltaOrbitAlongTrack(),    eps);
92          Assertions.assertEquals(122.8668,                     g01.getOrbitCorrection().getDeltaOrbitCrossTrack(),    eps);
93          Assertions.assertEquals(0.090047,                     g01.getOrbitCorrection().getDotOrbitDeltaRadial(),     eps);
94          Assertions.assertEquals(0.614332,                     g01.getOrbitCorrection().getDotOrbitDeltaAlongTrack(), eps);
95          Assertions.assertEquals(0.614332,                     g01.getOrbitCorrection().getDotOrbitDeltaCrossTrack(), eps);
96      }
97  
98      private byte[] byteArrayFromBinary(String radix2Value) {
99          final byte[] array = new byte[radix2Value.length() / 8];
100         for (int i = 0; i < array.length; ++i) {
101             for (int j = 0; j < 8; ++j) {
102                 if (radix2Value.charAt(8 * i + j) != '0') {
103                     array[i] |= 0x1 << (7 - j);
104                 }
105             }
106         }
107         return array;
108     }
109 
110 }