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