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 org.hipparchus.util.FastMath;
20  import org.junit.jupiter.api.Assertions;
21  import org.junit.jupiter.api.BeforeEach;
22  import org.junit.jupiter.api.Test;
23  import org.orekit.Utils;
24  import org.orekit.data.DataContext;
25  import org.orekit.gnss.SatelliteSystem;
26  import org.orekit.gnss.metric.messages.rtcm.ephemeris.Rtcm1042;
27  import org.orekit.gnss.metric.messages.rtcm.ephemeris.Rtcm1042Data;
28  import org.orekit.gnss.metric.parser.ByteArrayEncodedMessage;
29  import org.orekit.gnss.metric.parser.EncodedMessage;
30  import org.orekit.gnss.metric.parser.RtcmMessagesParser;
31  import org.orekit.propagation.analytical.gnss.GNSSPropagator;
32  import org.orekit.propagation.analytical.gnss.GNSSPropagatorBuilder;
33  import org.orekit.propagation.analytical.gnss.data.BeidouLegacyNavigationMessage;
34  import org.orekit.time.GNSSDate;
35  
36  import java.util.ArrayList;
37  
38  public class Rtcm1042Test {
39  
40      private final double eps = 1.0e-15;
41  
42      @BeforeEach
43      public void setUp() {
44          Utils.setDataRoot("gnss");
45      }
46  
47      @Test
48      public void testParseMessage() {
49  
50          final String m = "010000010010" +                     // Message number: 1042
51                          "001100" +                           // Satellite ID
52                          "1111111011101" +                    // Week Number
53                          "0001" +                             // SV Accuracy
54                          "01011101111101" +                   // IDOT
55                          "10100" +                            // AODE
56                          "00001111011011111" +                // toc
57                          "01111111000" +                      // af2
58                          "0000101011111101110010" +           // af1
59                          "010010101111110111111111" +         // af0
60                          "10100" +                            // AODC
61                          "000000000000000000" +               // Crs
62                          "0111111011001111" +                 // DELTA n
63                          "00000110110011111011100110011011" + // M0
64                          "000000000000000000" +               // Cuc
65                          "00010011111101111000111000011001" + // ecc
66                          "000000000000000000" +               // Cus
67                          "10100001000011000111111111111111" + // A^(1/2)
68                          "10001000111000111" +                // toe
69                          "000000000000000000" +               // Cic
70                          "00011100011100000111111000111111" + // OMEGA0
71                          "000000000000000000" +               // Cis
72                          "00101000001111100011110011110000" + // i0
73                          "000000000000000000" +               // Crc
74                          "00001100001111100011110011110000" + // Argument of perigee
75                          "111111111011111111110100" +         // OMEGADOT
76                          "0001001111" +                       // tGD1
77                          "0111001111" +                       // tGD2
78                          "0" +                                // SV Health
79                          "0";                                 // Reserved
80  
81          final EncodedMessage message = new ByteArrayEncodedMessage(byteArrayFromBinary(m));
82          message.start();
83  
84          ArrayList<Integer> messages = new ArrayList<>();
85          messages.add(1042);
86  
87          final Rtcm1042                rtcm1042      = (Rtcm1042) new RtcmMessagesParser(messages, DataContext.getDefault().getTimeScales()).
88                                                        parse(message, false);
89          final Rtcm1042Data            ephemerisData = rtcm1042.getEphemerisData();
90          final BeidouLegacyNavigationMessage beidouMessage = ephemerisData.getBeidouNavigationMessage();
91  
92          // Verify propagator initialization
93          final GNSSPropagator propagator = new GNSSPropagatorBuilder(beidouMessage).build();
94          Assertions.assertNotNull(propagator);
95          Assertions.assertEquals(0.0, beidouMessage.getDate().
96                              durationFrom(new GNSSDate(beidouMessage.getWeek(), beidouMessage.getTime(), SatelliteSystem.BEIDOU).getDate()), eps);
97  
98          // Verify message number
99          Assertions.assertEquals(1042,                   rtcm1042.getTypeCode());
100         Assertions.assertEquals(1,                      rtcm1042.getData().size());
101 
102         // Verify navigation message
103         Assertions.assertEquals(12,                     beidouMessage.getPRN());
104         Assertions.assertEquals(8157,                   beidouMessage.getWeek());
105         Assertions.assertEquals(2.1475894557210572E-9,  beidouMessage.getIDot(),               eps);
106         Assertions.assertEquals(20,                     beidouMessage.getAODE(),               eps);
107         Assertions.assertEquals(1.3769368E-17,          beidouMessage.getAf2(),                eps);
108         Assertions.assertEquals(1.5994495E-10,          beidouMessage.getAf1(),                eps);
109         Assertions.assertEquals(5.721448687836528E-4,   beidouMessage.getAf0(),                eps);
110         Assertions.assertEquals(20,                     beidouMessage.getAODC());
111         Assertions.assertEquals(0.0,                    beidouMessage.getCrs(),                eps);
112         Assertions.assertEquals(1.458633710547623E-4,   beidouMessage.getMeanMotion0(),        eps);
113         Assertions.assertEquals(1.4587496546628753E-4,  beidouMessage.getMeanMotion0() + beidouMessage.getDeltaN0(),        eps);
114         Assertions.assertEquals(0.1671775426328288,     beidouMessage.getM0(),                 eps);
115         Assertions.assertEquals(0.0,                    beidouMessage.getCuc(),                eps);
116         Assertions.assertEquals(0.03899807028938085,    beidouMessage.getE(),                  eps);
117         Assertions.assertEquals(0.0,                    beidouMessage.getCus(),                eps);
118         Assertions.assertEquals(5153.562498092651,      FastMath.sqrt(beidouMessage.getSma()), eps);
119         Assertions.assertEquals(560696.0,               beidouMessage.getTime(),               eps);
120         Assertions.assertEquals(0.0,                    beidouMessage.getCic(),                eps);
121         Assertions.assertEquals(0.0,                    beidouMessage.getCis(),                eps);
122         Assertions.assertEquals(0.987714701321906,      beidouMessage.getI0(),                 eps);
123         Assertions.assertEquals(0.0,                    beidouMessage.getCrc(),                eps);
124         Assertions.assertEquals(0.30049130834913723,    beidouMessage.getPa(),                 eps);
125         Assertions.assertEquals(-5.855958209879004E-9,  beidouMessage.getOmegaDot(),           eps);
126         Assertions.assertEquals(0.6980085385373721,     beidouMessage.getOmega0(),             eps);
127         Assertions.assertEquals(7.9E-9,                 beidouMessage.getTGD1(),               eps);
128         Assertions.assertEquals(4.63E-8,                beidouMessage.getTGD2(),               eps);
129 
130         // Verify other data
131         Assertions.assertEquals(12,                     ephemerisData.getSatelliteID());
132         Assertions.assertEquals(0.0,                    ephemerisData.getSvHealth(),        eps);
133         Assertions.assertEquals(63224,                  ephemerisData.getBeidouToc(),       eps);
134         Assertions.assertEquals(ephemerisData.getAccuracyProvider().getAccuracy(), beidouMessage.getSvAccuracy(), eps);
135 
136     }
137 
138     @Test
139     public void testNullMessage() {
140 
141         final String m = "010000010010" +                     // Message number: 1042
142                         "001100" +                           // Satellite ID
143                         "1111111011101" +                    // Week Number
144                         "0001" +                             // SV Accuracy
145                         "01011101111101" +                   // IDOT
146                         "10100" +                            // AODE
147                         "00001111011011111" +                // toc
148                         "01111111000" +                      // af2
149                         "0000101011111101110010" +           // af1
150                         "010010101111110111111111" +         // af0
151                         "10100" +                            // AODC
152                         "000000000000000000" +               // Crs
153                         "0111111011001111" +                 // DELTA n
154                         "00000110110011111011100110011011" + // M0
155                         "000000000000000000" +               // Cuc
156                         "00010011111101111000111000011001" + // ecc
157                         "000000000000000000" +               // Cus
158                         "10100001000011000111111111111111" + // A^(1/2)
159                         "10001000111000111" +                // toe
160                         "000000000000000000" +               // Cic
161                         "00011100011100000111111000111111" + // OMEGA0
162                         "000000000000000000" +               // Cis
163                         "00101000001111100011110011110000" + // i0
164                         "000000000000000000" +               // Crc
165                         "00001100001111100011110011110000" + // Argument of perigee
166                         "111111111011111111110100" +         // OMEGADOT
167                         "0001001111" +                       // tGD1
168                         "0111001111" +                       // tGD2
169                         "0" +                                // SV Health
170                         "0";                                 // Reserved
171 
172        final EncodedMessage message = new ByteArrayEncodedMessage(byteArrayFromBinary(m));
173        message.start();
174 
175        ArrayList<Integer> messages = new ArrayList<>();
176        messages.add(9999999);
177 
178        final Rtcm1042 rtcm1042 = (Rtcm1042) new RtcmMessagesParser(messages, DataContext.getDefault().getTimeScales()).
179                                  parse(message, false);
180 
181        Assertions.assertNull(rtcm1042);
182     }
183 
184 
185     private byte[] byteArrayFromBinary(String radix2Value) {
186         final byte[] array = new byte[radix2Value.length() / 8];
187         for (int i = 0; i < array.length; ++i) {
188             for (int j = 0; j < 8; ++j) {
189                 if (radix2Value.charAt(8 * i + j) != '0') {
190                     array[i] |= 0x1 << (7 - j);
191                 }
192             }
193         }
194         return array;
195     }
196 
197 }