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.ntrip;
18  
19  import org.hipparchus.util.FastMath;
20  import org.junit.Assert;
21  import org.junit.Test;
22  import org.orekit.errors.OrekitException;
23  import org.orekit.errors.OrekitMessages;
24  
25  public class DataStreamRecordTest {
26  
27      private static String BAD_FIELD  = "bad field";
28      private static String CLK24      = "STR;CLK24;BRDC_CoM_ITRF;RTCM 3.1;1060(5);0;GPS;MISC;DEU;49.87;8.62;0;1;RETINA;none;B;N;1400;IGS Combination";
29      private static String RTCM3EPH01 = "STR;RTCM3EPH01;Assisted-GNSS;RTCM 3.3;1019,1020,1042,1043,1044,1045,1046;0;GPS+GLO+GAL+BDS+QZS+SBAS;MISC;DEU;48.09;11.28;0;1;RETICLE;none;N;N;13600;gnss.gsoc.dlr.de:2101/BCEP0_DEU1(1)";
30      private static String SSRA01BKG1 = "STR;SSRA01BKG1;IGS-SSR APC;RTCM 3.1;4076_021(60),4076_022(5),4076_025(60),4076_041(60),4076_042(5);0;GPS+GLO;MISC;DEU;50.09;8.66;0;1;RTNet;none;B;N;1000;BKG IGS-SSR";
31  
32      @Test
33      public void testSSRA01BKG1() {
34          final DataStreamRecord str = new DataStreamRecord(SSRA01BKG1);
35          Assert.assertEquals(RecordType.STR,                        str.getRecordType());
36          Assert.assertEquals("SSRA01BKG1",                          str.getMountPoint());
37          Assert.assertEquals("IGS-SSR APC",                         str.getSourceIdentifier());
38          Assert.assertEquals(DataFormat.RTCM_3,                     str.getFormat());
39          Assert.assertEquals(5,                                     str.getFormatDetails().size());
40          Assert.assertEquals("4076_021",                            str.getFormatDetails().get(0).getId());
41          Assert.assertEquals(60,                                    str.getFormatDetails().get(0).getRate());
42          Assert.assertEquals("4076_022",                            str.getFormatDetails().get(1).getId());
43          Assert.assertEquals(5,                                     str.getFormatDetails().get(1).getRate());
44          Assert.assertEquals("4076_025",                            str.getFormatDetails().get(2).getId());
45          Assert.assertEquals(60,                                    str.getFormatDetails().get(2).getRate());
46          Assert.assertEquals("4076_041",                            str.getFormatDetails().get(3).getId());
47          Assert.assertEquals(60,                                    str.getFormatDetails().get(3).getRate());
48          Assert.assertEquals("4076_042",                            str.getFormatDetails().get(4).getId());
49          Assert.assertEquals(5,                                     str.getFormatDetails().get(4).getRate());
50          Assert.assertEquals(CarrierPhase.NO,                       str.getCarrierPhase());
51          Assert.assertEquals(2,                                     str.getNavigationSystems().size());
52          Assert.assertEquals(NavigationSystem.GPS,                  str.getNavigationSystems().get(0));
53          Assert.assertEquals("GPS",                                 str.getNavigationSystems().get(0).toString());
54          Assert.assertEquals(NavigationSystem.GLO,                  str.getNavigationSystems().get(1));
55          Assert.assertEquals("Glonass",                             str.getNavigationSystems().get(1).toString());
56          Assert.assertEquals("MISC",                                str.getNetwork());
57          Assert.assertEquals("DEU",                                 str.getCountry());
58          Assert.assertEquals(50.09,                                 FastMath.toDegrees(str.getLatitude()),  1.0e-10);
59          Assert.assertEquals(8.66,                                  FastMath.toDegrees(str.getLongitude()), 1.0e-10);
60          Assert.assertEquals(false,                                 str.isNMEARequired());
61          Assert.assertEquals(true,                                  str.isNetworked());
62          Assert.assertEquals("RTNet",                               str.getGenerator());
63          Assert.assertEquals("none",                                str.getCompressionEncryption());
64          Assert.assertEquals(Authentication.BASIC,                  str.getAuthentication());
65          Assert.assertEquals(false,                                 str.areFeesRequired());
66          Assert.assertEquals(1000,                                  str.getBitRate());
67          Assert.assertEquals("BKG IGS-SSR",                         str.getMisc());
68      }
69  
70      @Test
71      public void testCLK24() {
72          final DataStreamRecord str = new DataStreamRecord(CLK24);
73          Assert.assertEquals(RecordType.STR,       str.getRecordType());
74          Assert.assertEquals("CLK24",              str.getMountPoint());
75          Assert.assertEquals("BRDC_CoM_ITRF",      str.getSourceIdentifier());
76          Assert.assertEquals(DataFormat.RTCM_3,    str.getFormat());
77          Assert.assertEquals(1,                    str.getFormatDetails().size());
78          Assert.assertEquals("1060",               str.getFormatDetails().get(0).getId());
79          Assert.assertEquals(5,                    str.getFormatDetails().get(0).getRate());
80          Assert.assertEquals(CarrierPhase.NO,      str.getCarrierPhase());
81          Assert.assertEquals(1,                    str.getNavigationSystems().size());
82          Assert.assertEquals(NavigationSystem.GPS, str.getNavigationSystems().get(0));
83          Assert.assertEquals("MISC",               str.getNetwork());
84          Assert.assertEquals("DEU",                str.getCountry());
85          Assert.assertEquals(49.87,                FastMath.toDegrees(str.getLatitude()),  1.0e-15);
86          Assert.assertEquals( 8.62,                FastMath.toDegrees(str.getLongitude()), 1.0e-15);
87          Assert.assertEquals(false,                str.isNMEARequired());
88          Assert.assertEquals(true,                 str.isNetworked());
89          Assert.assertEquals("RETINA",             str.getGenerator());
90          Assert.assertEquals("none",               str.getCompressionEncryption());
91          Assert.assertEquals(Authentication.BASIC, str.getAuthentication());
92          Assert.assertEquals(false,                str.areFeesRequired());
93          Assert.assertEquals(1400,                 str.getBitRate());
94          Assert.assertEquals("IGS Combination",    str.getMisc());
95      }
96  
97      @Test
98      public void testRTCM3EPH01() {
99          final DataStreamRecord str = new DataStreamRecord(RTCM3EPH01);
100         Assert.assertEquals(RecordType.STR,                        str.getRecordType());
101         Assert.assertEquals("RTCM3EPH01",                          str.getMountPoint());
102         Assert.assertEquals("Assisted-GNSS",                       str.getSourceIdentifier());
103         Assert.assertEquals(DataFormat.RTCM_3,                     str.getFormat());
104         Assert.assertEquals(7,                                     str.getFormatDetails().size());
105         Assert.assertEquals("1019",                                str.getFormatDetails().get(0).getId());
106         Assert.assertEquals(-1,                                    str.getFormatDetails().get(0).getRate());
107         Assert.assertEquals("1020",                                str.getFormatDetails().get(1).getId());
108         Assert.assertEquals(-1,                                    str.getFormatDetails().get(1).getRate());
109         Assert.assertEquals("1042",                                str.getFormatDetails().get(2).getId());
110         Assert.assertEquals(-1,                                    str.getFormatDetails().get(2).getRate());
111         Assert.assertEquals("1043",                                str.getFormatDetails().get(3).getId());
112         Assert.assertEquals(-1,                                    str.getFormatDetails().get(3).getRate());
113         Assert.assertEquals("1044",                                str.getFormatDetails().get(4).getId());
114         Assert.assertEquals(-1,                                    str.getFormatDetails().get(4).getRate());
115         Assert.assertEquals("1045",                                str.getFormatDetails().get(5).getId());
116         Assert.assertEquals(-1,                                    str.getFormatDetails().get(5).getRate());
117         Assert.assertEquals("1046",                                str.getFormatDetails().get(6).getId());
118         Assert.assertEquals(-1,                                    str.getFormatDetails().get(6).getRate());
119         Assert.assertEquals(CarrierPhase.NO,                       str.getCarrierPhase());
120         Assert.assertEquals(6,                                     str.getNavigationSystems().size());
121         Assert.assertEquals(NavigationSystem.GPS,                  str.getNavigationSystems().get(0));
122         Assert.assertEquals("GPS",                                 str.getNavigationSystems().get(0).toString());
123         Assert.assertEquals(NavigationSystem.GLO,                  str.getNavigationSystems().get(1));
124         Assert.assertEquals("Glonass",                             str.getNavigationSystems().get(1).toString());
125         Assert.assertEquals(NavigationSystem.GAL,                  str.getNavigationSystems().get(2));
126         Assert.assertEquals("Galileo",                             str.getNavigationSystems().get(2).toString());
127         Assert.assertEquals(NavigationSystem.BDS,                  str.getNavigationSystems().get(3));
128         Assert.assertEquals("Beidou",                              str.getNavigationSystems().get(3).toString());
129         Assert.assertEquals(NavigationSystem.QZS,                  str.getNavigationSystems().get(4));
130         Assert.assertEquals("QZNSS",                               str.getNavigationSystems().get(4).toString());
131         Assert.assertEquals(NavigationSystem.SBAS,                 str.getNavigationSystems().get(5));
132         Assert.assertEquals("SBAS",                                str.getNavigationSystems().get(5).toString());
133         Assert.assertEquals("MISC",                                str.getNetwork());
134         Assert.assertEquals("DEU",                                 str.getCountry());
135         Assert.assertEquals(48.09,                                 FastMath.toDegrees(str.getLatitude()),  1.0e-15);
136         Assert.assertEquals(11.28,                                 FastMath.toDegrees(str.getLongitude()), 1.0e-15);
137         Assert.assertEquals(false,                                 str.isNMEARequired());
138         Assert.assertEquals(true,                                  str.isNetworked());
139         Assert.assertEquals("RETICLE",                             str.getGenerator());
140         Assert.assertEquals("none",                                str.getCompressionEncryption());
141         Assert.assertEquals(Authentication.NONE,                   str.getAuthentication());
142         Assert.assertEquals(false,                                 str.areFeesRequired());
143         Assert.assertEquals(13600,                                 str.getBitRate());
144         Assert.assertEquals("gnss.gsoc.dlr.de:2101/BCEP0_DEU1(1)", str.getMisc());
145     }
146 
147     @Test
148     public void testDigestAuthentication() {
149         final DataStreamRecord str = new DataStreamRecord(CLK24.replace(";B;", ";D;"));
150         Assert.assertEquals(Authentication.DIGEST, str.getAuthentication());
151     }
152 
153     @Test
154     public void testSingleBase() {
155         final DataStreamRecord str = new DataStreamRecord(CLK24.replace(";0;1;RETINA;", ";0;0;RETINA;"));
156         Assert.assertFalse(str.isNetworked());
157     }
158 
159     @Test
160     public void testRequiresNMEA() {
161         final DataStreamRecord str = new DataStreamRecord(CLK24.replace(";0;1;RETINA;", ";1;1;RETINA;"));
162         Assert.assertTrue(str.isNMEARequired());
163     }
164 
165     @Test
166     public void testRequiresFees() {
167         final DataStreamRecord str = new DataStreamRecord(CLK24.replace(";B;N;", ";B;Y;"));
168         Assert.assertTrue(str.areFeesRequired());
169     }
170 
171     @Test
172     public void testUnknownDataFormat() {
173         try {
174             new DataStreamRecord(CLK24.replace(";RTCM 3.1;", ";" + BAD_FIELD + ";"));
175             Assert.fail("an exception should habe been thrown");
176         } catch (OrekitException me) {
177             Assert.assertEquals(OrekitMessages.UNKNOWN_DATA_FORMAT, me.getSpecifier());
178             Assert.assertEquals(BAD_FIELD, (String) me.getParts()[0]);
179         }
180     }
181 
182     @Test
183     public void testUnknownAuthenticationMethod() {
184         try {
185             new DataStreamRecord(CLK24.replace(";B;", ";" + BAD_FIELD + ";"));
186             Assert.fail("an exception should habe been thrown");
187         } catch (OrekitException me) {
188             Assert.assertEquals(OrekitMessages.UNKNOWN_AUTHENTICATION_METHOD, me.getSpecifier());
189             Assert.assertEquals(BAD_FIELD, (String) me.getParts()[0]);
190         }
191     }
192 
193     @Test
194     public void testUnknownCarrierPhaseNotParsable() {
195         try {
196             new DataStreamRecord(CLK24.replace(";0;GPS", ";" + BAD_FIELD + ";GPS"));
197             Assert.fail("an exception should habe been thrown");
198         } catch (OrekitException me) {
199             Assert.assertEquals(OrekitMessages.UNKNOWN_CARRIER_PHASE_CODE, me.getSpecifier());
200             Assert.assertEquals(BAD_FIELD, (String) me.getParts()[0]);
201         }
202     }
203 
204     @Test
205     public void testUnknownCarrierPhaseWrongNumber() {
206         try {
207             new DataStreamRecord(CLK24.replace(";0;GPS", ";17;GPS"));
208             Assert.fail("an exception should habe been thrown");
209         } catch (OrekitException me) {
210             Assert.assertEquals(OrekitMessages.UNKNOWN_CARRIER_PHASE_CODE, me.getSpecifier());
211             Assert.assertEquals("17", (String) me.getParts()[0]);
212         }
213     }
214 
215     @Test
216     public void testUnknownNavigationSystem() {
217         try {
218             new DataStreamRecord(CLK24.replace(";GPS;", ";GPS+" + BAD_FIELD + "+GLO;"));
219             Assert.fail("an exception should habe been thrown");
220         } catch (OrekitException me) {
221             Assert.assertEquals(OrekitMessages.UNKNOWN_NAVIGATION_SYSTEM, me.getSpecifier());
222             Assert.assertEquals(BAD_FIELD, (String) me.getParts()[0]);
223         }
224     }
225 
226 }