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