1 //==============================================================================
2 //
3 //  This file is part of GPSTk, the GPS Toolkit.
4 //
5 //  The GPSTk is free software; you can redistribute it and/or modify
6 //  it under the terms of the GNU Lesser General Public License as published
7 //  by the Free Software Foundation; either version 3.0 of the License, or
8 //  any later version.
9 //
10 //  The GPSTk is distributed in the hope that it will be useful,
11 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //  GNU Lesser General Public License for more details.
14 //
15 //  You should have received a copy of the GNU Lesser General Public
16 //  License along with GPSTk; if not, write to the Free Software Foundation,
17 //  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 //  This software was developed by Applied Research Laboratories at the
20 //  University of Texas at Austin.
21 //  Copyright 2004-2020, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 //  This software was developed by Applied Research Laboratories at the
28 //  University of Texas at Austin, under contract to an agency or agencies
29 //  within the U.S. Department of Defense. The U.S. Government retains all
30 //  rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 //  Pursuant to DoD Directive 523024
33 //
34 //  DISTRIBUTION STATEMENT A: This software has been approved for public
35 //                            release, distribution is unlimited.
36 //
37 //==============================================================================
38 
39 #include "EngAlmanac.hpp"
40 #include "TestUtil.hpp"
41 #include <iostream>
42 
43 #include "AlmanacDataGenerator.hpp"
44 #include "BinUtils.hpp"
45 
46 class EngAlmanac_T
47 {
48 public:
49       //Reads in AlmanacData object to form comparison data types
EngAlmanac_T(AlmanacData iAData,AlmanacSubframes iASubframes)50    EngAlmanac_T(AlmanacData iAData, AlmanacSubframes iASubframes)
51    {
52       eps = 1E-6; //Low precision, data is extracted from binary subframes, some have only 16 bit precision
53       aData = iAData;
54       aSubframes = iASubframes;
55    }
56 
~EngAlmanac_T()57    ~EngAlmanac_T() {} // Default Desructor
58 
59    gpstk::EngAlmanac alm;
60 
addSubframeTest(void)61    int addSubframeTest(void)
62    {
63       gpstk::TestUtil testFramework("EngAlmanac", "addSubframe", __FILE__, __LINE__);
64 
65 
66          //Subframe and week number mod 1024
67       testMesg = "Adding subframe 5 page 1 failed";
68       testFramework.assert(alm.addSubframe(aSubframes.totalSf[0], 819), testMesg,
69                            __LINE__);
70       testMesg = "Adding subframe 5 page 2 failed";
71       testFramework.assert(alm.addSubframe(aSubframes.totalSf[1], 819), testMesg,
72                            __LINE__);
73       testMesg = "Adding subframe 5 page 3 failed";
74       testFramework.assert(alm.addSubframe(aSubframes.totalSf[2], 819), testMesg,
75                            __LINE__);
76       testMesg = "Adding subframe 5 page 4 failed";
77       testFramework.assert(alm.addSubframe(aSubframes.totalSf[3], 819), testMesg,
78                            __LINE__);
79       testMesg = "Adding subframe 5 page 5 failed";
80       testFramework.assert(alm.addSubframe(aSubframes.totalSf[4], 819), testMesg,
81                            __LINE__);
82       testMesg = "Adding subframe 5 page 6 failed";
83       testFramework.assert(alm.addSubframe(aSubframes.totalSf[5], 819), testMesg,
84                            __LINE__);
85       testMesg = "Adding subframe 5 page 7 failed";
86       testFramework.assert(alm.addSubframe(aSubframes.totalSf[6], 819), testMesg,
87                            __LINE__);
88       testMesg = "Adding subframe 5 page 8 failed";
89       testFramework.assert(alm.addSubframe(aSubframes.totalSf[7], 819), testMesg,
90                            __LINE__);
91          //skip this test, no valid almanac data for PRN 8
92          // testMesg = "Adding subframe 5 page 9 failed";
93          // testFramework.assert(alm.addSubframe(aSubframes.totalSf[31], 819), testMesg, __LINE__);
94       testMesg = "Adding subframe 5 page 10 failed";
95       testFramework.assert(alm.addSubframe(aSubframes.totalSf[8], 819), testMesg,
96                            __LINE__);
97       testMesg = "Adding subframe 5 page 11 failed";
98       testFramework.assert(alm.addSubframe(aSubframes.totalSf[9], 819), testMesg,
99                            __LINE__);
100       testMesg = "Adding subframe 5 page 12 failed";
101       testFramework.assert(alm.addSubframe(aSubframes.totalSf[10], 819), testMesg,
102                            __LINE__);
103       testMesg = "Adding subframe 5 page 13 failed";
104       testFramework.assert(alm.addSubframe(aSubframes.totalSf[11], 819), testMesg,
105                            __LINE__);
106       testMesg = "Adding subframe 5 page 14 failed";
107       testFramework.assert(alm.addSubframe(aSubframes.totalSf[12], 819), testMesg,
108                            __LINE__);
109       testMesg = "Adding subframe 5 page 15 failed";
110       testFramework.assert(alm.addSubframe(aSubframes.totalSf[13], 819), testMesg,
111                            __LINE__);
112       testMesg = "Adding subframe 5 page 16 failed";
113       testFramework.assert(alm.addSubframe(aSubframes.totalSf[14], 819), testMesg,
114                            __LINE__);
115       testMesg = "Adding subframe 5 page 17 failed";
116       testFramework.assert(alm.addSubframe(aSubframes.totalSf[15], 819), testMesg,
117                            __LINE__);
118       testMesg = "Adding subframe 5 page 18 failed";
119       testFramework.assert(alm.addSubframe(aSubframes.totalSf[16], 819), testMesg,
120                            __LINE__);
121       testMesg = "Adding subframe 5 page 19 failed";
122       testFramework.assert(alm.addSubframe(aSubframes.totalSf[17], 819), testMesg,
123                            __LINE__);
124       testMesg = "Adding subframe 5 page 20 failed";
125       testFramework.assert(alm.addSubframe(aSubframes.totalSf[18], 819), testMesg,
126                            __LINE__);
127       testMesg = "Adding subframe 5 page 21 failed";
128       testFramework.assert(alm.addSubframe(aSubframes.totalSf[19], 819), testMesg,
129                            __LINE__);
130       testMesg = "Adding subframe 5 page 22 failed";
131       testFramework.assert(alm.addSubframe(aSubframes.totalSf[20], 819), testMesg,
132                            __LINE__);
133       testMesg = "Adding subframe 5 page 23 failed";
134       testFramework.assert(alm.addSubframe(aSubframes.totalSf[21], 819), testMesg,
135                            __LINE__);
136       testMesg = "Adding subframe 5 page 24 failed";
137       testFramework.assert(alm.addSubframe(aSubframes.totalSf[22], 819), testMesg,
138                            __LINE__);
139 
140       testMesg = "Adding subframe 4 page 2 failed";
141       testFramework.assert(alm.addSubframe(aSubframes.totalSf[23], 819), testMesg,
142                            __LINE__);
143       testMesg = "Adding subframe 4 page 3 failed";
144       testFramework.assert(alm.addSubframe(aSubframes.totalSf[24], 819), testMesg,
145                            __LINE__);
146       testMesg = "Adding subframe 4 page 4 failed";
147       testFramework.assert(alm.addSubframe(aSubframes.totalSf[25], 819), testMesg,
148                            __LINE__);
149       testMesg = "Adding subframe 4 page 5 failed";
150       testFramework.assert(alm.addSubframe(aSubframes.totalSf[26], 819), testMesg,
151                            __LINE__);
152       testMesg = "Adding subframe 4 page 7 failed";
153       testFramework.assert(alm.addSubframe(aSubframes.totalSf[27], 819), testMesg,
154                            __LINE__);
155       testMesg = "Adding subframe 4 page 8 failed";
156       testFramework.assert(alm.addSubframe(aSubframes.totalSf[28], 819), testMesg,
157                            __LINE__);
158       testMesg = "Adding subframe 4 page 9 failed";
159       testFramework.assert(alm.addSubframe(aSubframes.totalSf[29], 819), testMesg,
160                            __LINE__);
161       testMesg = "Adding subframe 4 page 10 failed";
162       testFramework.assert(alm.addSubframe(aSubframes.totalSf[30], 819), testMesg,
163                            __LINE__);
164 
165 //subframe 5 page 25
166          /*
167            copy the tlm and how from above for subframe 5
168            dataID = 2 (from the IS-GPS-200)
169            svID = 51 for this page
170            toa = 319488 * 2**-12
171            WNa = 819 % 256 = 51
172            all sv healths are good except 8, set it to 111111 (or leave it blank, don't think it matters)
173 
174            word 3:
175            dID svID (51)         319488*2**-12 = 78      Wn = 51
176            10    110011          01001110                        00110011 = 10 1100 1101 0011 1000 1100 1100 0000
177            2CD38CC0
178 
179            word 5:
180            00 0000               0000 00                 00 0000                 1111 11                 00 0000
181 
182            word 10 is reserved, doesn't matter what set to
183 
184          */
185       const long subframe551[10] = {0x22c000e4, 0x00000598, 0x2CD38CC0, 0x00000000, 0x00000FC0,
186                                     0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x11111110
187       };
188       testMesg = "Adding subframe 5 page 25 failed";
189       testFramework.assert(alm.addSubframe(subframe551, 819), testMesg, __LINE__);
190 
191 //subframe 4 page 25
192          /*
193            copy the tlm and the how from above for subframe 4
194            dataID = 2 (from the IS-GPS-200)
195            svID = 63 for this page
196 
197            Assume reserved bits are 1, and all satellites have Anti spoofing on and are in block II//IIA/IIR
198            therefore all the sv configs need to be set to 1001
199 
200            word 3
201            dID   svID            4 svconfigs
202            10            1111 11         10 0110 0110 0110 01 = 0x2F666640
203 
204            word 4,5,6,7
205            6 sv configs
206            10 0110 0110 0110 0110 0110 01 = 0x26666640
207 
208            word 8
209            4 sv configs                  2 reserved      1 sv health
210            10 0110 0110 0110 01  11                      0000 00         =       0x26667000
211 
212            word 9
213            5 sv healths, all 0 = 0x00000000
214 
215            word 10
216            3 sv healths                  4 reserved      2 parity
217            00 0000 0000 0000 0000        1111            00                      = 0x00000F00
218 
219          */
220       const long subframe447[10] = {0x22c000e4, 0x0000042c, 0x2FE66640, 0x26666640, 0x26666640,
221                                     0x26666640, 0x26666640, 0x26667000, 0x00000000, 0x00000F00
222       };
223       testMesg = "Adding subframe 4 page 25 failed";
224       testFramework.assert(alm.addSubframe(subframe447, 819), testMesg, __LINE__);
225 
226 // subframe4 page 18
227          /*
228            copy tlm and how from other subframe4 pages
229            data id = 2
230            sv id = 56
231 
232               //deadbeefdeadc0de
233               alpha0 = (222 - 256) * 2**-30 = -3.166496753692627e-08 //Twos compliment
234               alpha1 = (173 - 256) * 2**-27 / pi = -1.968422573302286e-07
235               alpha2 = (190 - 256) * 2**-24 / pi**2 = -3.985880685087617e-07
236               alpha3 = (239 - 256) * 2**-24 / pi**3 = -3.26798013069863e-08
237               beta0 = (222 - 256) * 2**11 = -69632 //Twos compliment
238               beta1 = (173 - 256) * 2**14 / pi = -432860.7015445238
239               beta2 = (192 - 256) * 2**16 / pi**2 = -424971.8458357919
240               beta3 = (222 - 256) * 2**16 / pi**3 = -71863.64306088151
241 
242                  //cabobobs
243                  A0 = (3400577205 - 4294967296) * 2**-30 = -0.8329656822606921
244                     //baddab
245                     A1 = (12246443 - 16777216) * 2**-50 = -4.0241348031599955e-09
246                     dtLS = 13 = 0x0d
247                     tot = 110 * 2**12 = 450560 = 0x6e
248                     WNt = 90 = 0x5a
249                     WNLSF = 254 = 0xFE
250                     DN (right justified) = 5 =>0x05
251                     dtLSF = (153 - 256) = -103 = 0x99
252 
253 
254                     word 3
255                     dataID       svID    alpha0          alpha1          parity
256                     10           111000  11011110        10101101    000000              = 0x2e37ab40
257 
258                     word 4
259                     alpha2               alpha3          beta0           parity
260                     10111110     11101111        11011110        000000                  = 0x2fbbf780
261 
262                     word 5
263                     beta1                beta2           beta3           parity
264                     10101101     11000000        11011110        000000                  = 0x2b703780
265 
266                     word 6
267                     A0                                                                   parity
268                     11001010101100001011000010110101    000000                   = 0x2eb76ac0
269 
270                     word 7
271                     A1 (24 msb)                                                  parity
272                     110010101011000010110000(10110101)   000000                  = 0x32ac2c00
273 
274                     word 8
275                     A0 (8 lsb)   tot             WNt             parity
276                     10110101     01101110        01011010        000000                  = 0x2d5b9680
277 
278                     word 9
279                     dtLS                 WNLSF           DN                      parity
280                     00001101     11111110        00000101        000000                  = 0x037f8140
281 
282                     word 10
283                     dtLSF                14b reserved    2b              parity
284                     10011001     11111111111111  00              000000                  = 0x267fff00
285          */
286       const long subframe456[10] = {0x22c000e4, 0x0000042c, 0x2e37ab40, 0x2fbbf780, 0x2b703780,
287                                     0x2eb76ac0, 0x32ac2c00, 0x2d5b9680, 0x037f8140, 0x267fff00
288       };
289       testMesg = "Adding subframe 4 page 18 failed";
290       testFramework.assert(alm.addSubframe(subframe456, 819), testMesg, __LINE__);
291 
292 
293       return testFramework.countFails();
294    }
295 
getTest(void)296    int getTest(void)
297    {
298       int x, failCount;
299       gpstk::TestUtil testFramework("EngAlmanac", "getTest", __FILE__, __LINE__);
300 
301          //GPSTK documentation should really say what units these return as
302          // For loop which tests all the data values for the almanac. Commented out, too many tests
303          /*
304            for(int i=0; i<31; i++)
305            {
306            if ( i >= 7) x = i + 2; //switch to allow for skipped prn 8
307            else x = i + 1;
308            testMesg = "getEcc returned the wrong value";
309            testFramework.assert(std::abs(alm.getEcc(gpstk::SatID(x, gpstk::SatelliteSystem::GPS)) - aData.ecc[i])*1E2 < eps, testMesg, __LINE__);
310            testMesg = "getIOffset returned the wrong value";
311            testFramework.assert(std::abs(alm.getIOffset(gpstk::SatID(x, gpstk::SatelliteSystem::GPS)) - (aData.oi[i] - .3*M_PI)) < eps, testMesg, __LINE__);
312            testMesg = "getOmegadot returned the wrong value";
313            testFramework.assert(std::abs(alm.getOmegadot(gpstk::SatID(x, gpstk::SatelliteSystem::GPS)) - aData.rora[i])*1E8 < eps, testMesg, __LINE__);
314            testMesg = "get6bitHealth returned the wrong value";
315            testFramework.assert(alm.get6bitHealth(gpstk::SatID(x, gpstk::SatelliteSystem::GPS)) == 0 , testMesg, __LINE__);
316            testMesg = "getSVHealth returned the wrong value";
317            testFramework.assert(alm.getSVHealth(gpstk::SatID(x, gpstk::SatelliteSystem::GPS)) == 0, testMesg, __LINE__);
318            testMesg = "getSVConfig returned the wrong value";
319            testFramework.assert(alm.getSVConfig(gpstk::SatID(x, gpstk::SatelliteSystem::GPS)) == 9, testMesg, __LINE__); //9 is 1001
320            testMesg = "getAhalf returned the wrong value";
321            testFramework.assert(std::abs(alm.getAhalf(gpstk::SatID(x, gpstk::SatelliteSystem::GPS)) - aData.sqrta[i])*1E-4 < eps, testMesg, __LINE__);
322            testMesg = "getA returned the wrong value";
323            testFramework.assert(std::abs(alm.getA(gpstk::SatID(x, gpstk::SatelliteSystem::GPS)) - pow(aData.sqrta[i],2))*1E-8 < eps, testMesg, __LINE__);
324            testMesg = "getOmega0 returned the wrong value";
325            testFramework.assert(std::abs(alm.getOmega0(gpstk::SatID(x, gpstk::SatelliteSystem::GPS)) - aData.raaw[i])*1E-1 < eps, testMesg, __LINE__);
326            testMesg = "getW returned the wrong value";
327            testFramework.assert(std::abs(alm.getW(gpstk::SatID(x, gpstk::SatelliteSystem::GPS)) - aData.aop[i]) < eps, testMesg, __LINE__);
328            testMesg = "getM0 returned the wrong value";
329            testFramework.assert(std::abs(alm.getM0(gpstk::SatID(x, gpstk::SatelliteSystem::GPS)) - aData.ma[i])*1E-1 < eps, testMesg, __LINE__);
330            testMesg = "getAf0 returned the wrong value";
331            testFramework.assert(std::abs(alm.getAf0(gpstk::SatID(x, gpstk::SatelliteSystem::GPS)) - aData.af0[i])*1E5 < eps, testMesg, __LINE__);
332            testMesg = "getAf1 returned the wrong value";
333            testFramework.assert(std::abs(alm.getAf1(gpstk::SatID(x, gpstk::SatelliteSystem::GPS)) - aData.af1[i]) < eps, testMesg, __LINE__);
334            }
335          */
336 
337          //getEcc test
338       failCount = 0;
339       for (int i=0; i<31; i++)
340       {
341          if ( i >= 7) x = i + 2;
342          else x = i + 1;
343          if (!(std::abs(alm.getEcc(gpstk::SatID(x,
344                                                 gpstk::SatelliteSystem::GPS)) - aData.ecc[i])*1E2 < eps))
345             failCount++;
346       }
347       testMesg = "getEcc returned the wrong value";
348       testFramework.assert(failCount == 0, testMesg, __LINE__);
349 
350          //getIOffset test
351       failCount = 0;
352       for (int i=0; i<31; i++)
353       {
354          if ( i >= 7) x = i + 2;
355          else x = i + 1;
356          if (!(std::abs(alm.getIOffset(gpstk::SatID(x,
357                                                     gpstk::SatelliteSystem::GPS)) - (aData.oi[i] - .3*M_PI)) < eps))
358             failCount++;
359       }
360       testMesg = "getIOffset returned the wrong value";
361       testFramework.assert(failCount == 0, testMesg, __LINE__);
362 
363          //getOmegadot test
364       failCount = 0;
365       for (int i=0; i<31; i++)
366       {
367          if ( i >= 7) x = i + 2;
368          else x = i + 1;
369          if (!(std::abs(alm.getOmegadot(gpstk::SatID(x,
370                                                      gpstk::SatelliteSystem::GPS)) - aData.rora[i])*1E8 < eps))
371             failCount++;
372       }
373       testMesg = "getOmegadot returned the wrong value";
374       testFramework.assert(failCount == 0, testMesg, __LINE__);
375 
376          //get6bitHealth test
377       failCount = 0;
378       for (int i=0; i<31; i++)
379       {
380          if ( i >= 7) x = i + 2;
381          else x = i + 1;
382          if (!(alm.get6bitHealth(gpstk::SatID(x, gpstk::SatelliteSystem::GPS)) == 0))
383             failCount++;
384       }
385       testMesg = "get6bitHealth returned the wrong value";
386       testFramework.assert(failCount == 0, testMesg, __LINE__);
387 
388          //getSVHealth test
389       failCount = 0;
390       for (int i=0; i<31; i++)
391       {
392          if ( i >= 7) x = i + 2;
393          else x = i + 1;
394          if (!(alm.getSVHealth(gpstk::SatID(x, gpstk::SatelliteSystem::GPS)) == 0))
395             failCount++;
396       }
397       testMesg = "getSVHealth returned the wrong value";
398       testFramework.assert(failCount == 0, testMesg, __LINE__);
399 
400          //getSVConfig test
401       failCount = 0;
402       for (int i=0; i<31; i++)
403       {
404          if ( i >= 7) x = i + 2;
405          else x = i + 1;
406          if (!(alm.getSVConfig(gpstk::SatID(x, gpstk::SatelliteSystem::GPS)) == 9))
407             failCount++;
408       }
409       testMesg = "getSVConfig returned the wrong value";
410       testFramework.assert(failCount == 0, testMesg, __LINE__);
411 
412          //getAhalf test
413       failCount = 0;
414       for (int i=0; i<31; i++)
415       {
416          if ( i >= 7) x = i + 2;
417          else x = i + 1;
418          if (!(std::abs(alm.getAhalf(gpstk::SatID(x,
419                                                   gpstk::SatelliteSystem::GPS)) - aData.sqrta[i])*1E-4 < eps))
420             failCount++;
421       }
422       testMesg = "getAhalf returned the wrong value";
423       testFramework.assert(failCount == 0, testMesg, __LINE__);
424 
425          //getA test
426       failCount = 0;
427       for (int i=0; i<31; i++)
428       {
429          if ( i >= 7) x = i + 2;
430          else x = i + 1;
431          if (!(std::abs(alm.getA(gpstk::SatID(x,
432                                               gpstk::SatelliteSystem::GPS)) - pow(aData.sqrta[i],2))*1E-8 < eps))
433             failCount++;
434       }
435       testMesg = "getA returned the wrong value";
436       testFramework.assert(failCount == 0, testMesg, __LINE__);
437 
438          //getOmega0 test
439       failCount = 0;
440       for (int i=0; i<31; i++)
441       {
442          if ( i >= 7) x = i + 2;
443          else x = i + 1;
444          if (!(std::abs(alm.getOmega0(gpstk::SatID(x,
445                                                    gpstk::SatelliteSystem::GPS)) - aData.raaw[i])*1E-1 < eps))
446             failCount++;
447       }
448       testMesg = "getOmega0 returned the wrong value";
449       testFramework.assert(failCount == 0, testMesg, __LINE__);
450 
451          //getW test
452       failCount = 0;
453       for (int i=0; i<31; i++)
454       {
455          if ( i >= 7) x = i + 2;
456          else x = i + 1;
457          if (!(std::abs(alm.getW(gpstk::SatID(x,
458                                               gpstk::SatelliteSystem::GPS)) - aData.aop[i]) < eps))
459             failCount++;
460       }
461       testMesg = "getW returned the wrong value";
462       testFramework.assert(failCount == 0, testMesg, __LINE__);
463 
464          //getM0 test
465       failCount = 0;
466       for (int i=0; i<31; i++)
467       {
468          if ( i >= 7) x = i + 2;
469          else x = i + 1;
470          if (!(std::abs(alm.getM0(gpstk::SatID(x,
471                                                gpstk::SatelliteSystem::GPS)) - aData.ma[i])*1E-1 < eps))
472             failCount++;
473       }
474       testMesg = "getM0 returned the wrong value";
475       testFramework.assert(failCount == 0, testMesg, __LINE__);
476 
477          //getAf0 test
478       failCount = 0;
479       for (int i=0; i<31; i++)
480       {
481          if ( i >= 7) x = i + 2;
482          else x = i + 1;
483          if (!(std::abs(alm.getAf0(gpstk::SatID(x,
484                                                 gpstk::SatelliteSystem::GPS)) - aData.af0[i])*1E5 < eps))
485             failCount++;
486       }
487       testMesg = "getAf0 returned the wrong value";
488       testFramework.assert(failCount == 0, testMesg, __LINE__);
489 
490          //getAf1 test
491       failCount = 0;
492       for (int i=0; i<31; i++)
493       {
494          if ( i >= 7) x = i + 2;
495          else x = i + 1;
496          if (!(std::abs(alm.getAf1(gpstk::SatID(x,
497                                                 gpstk::SatelliteSystem::GPS)) - aData.af1[i]) < eps))
498             failCount++;
499       }
500       testMesg = "getAf1 returned the wrong value";
501       testFramework.assert(failCount == 0, testMesg, __LINE__);
502 
503       double a[4], b[4];
504       alm.getIon(a, b);
505 
506       testMesg = "getIon returned an incorrect value for Alpha0";
507       testFramework.assert(std::abs(a[0] + 3.166496753692627e-08) < eps, testMesg,
508                            __LINE__);
509       testMesg = "getIon returned an incorrect value for Alpha1";
510       testFramework.assert(std::abs(a[1] + 1.968422573302286e-07) < eps, testMesg,
511                            __LINE__);
512       testMesg = "getIon returned an incorrect value for Alpha2";
513       testFramework.assert(std::abs(a[2] + 3.985880685087617e-07) < eps, testMesg,
514                            __LINE__);
515       testMesg = "getIon returned an incorrect value for Alpha3";
516       testFramework.assert(std::abs(a[3] + 3.26798013069863e-08) < eps, testMesg,
517                            __LINE__);
518       testMesg = "getIon returned an incorrect value for Beta0";
519       testFramework.assert(std::abs(b[0] + 69632) < eps, testMesg, __LINE__);
520       testMesg = "getIon returned an incorrect value for Beta1";
521       testFramework.assert(std::abs(b[1] + 432860.7015445238) < eps, testMesg,
522                            __LINE__);
523       testMesg = "getIon returned an incorrect value for Beta2";
524       testFramework.assert(std::abs(b[2] + 424971.8458357919) < eps, testMesg,
525                            __LINE__);
526       testMesg = "getIon returned an incorrect value for Beta3";
527       testFramework.assert(std::abs(b[3] + 71863.64306088151) < eps, testMesg,
528                            __LINE__);
529 
530       double a0, a1, deltaTLS, deltaTLSF;
531       long tot;
532       int WNt, WNLSF, DN;
533       alm.getUTC(a0, a1, deltaTLS, tot, WNt, WNLSF, DN, deltaTLSF);
534 
535       testMesg = "getUTC returned an incorrect value for A0";
536       testFramework.assert(std::abs(a0 + 0.8329656822606921) < eps, testMesg,
537                            __LINE__);
538       testMesg = "getUTC returned an incorrect value for A1";
539       testFramework.assert(std::abs(a1 + 4.0241348031599955e-09) < eps, testMesg,
540                            __LINE__);
541       testMesg = "getUTC returned an incorrect value for deltaTLS";
542       testFramework.assert(std::abs(deltaTLS - 13) < eps, testMesg, __LINE__);
543       testMesg = "getUTC returned an incorrect value for deltaTLSF";
544       testFramework.assert(std::abs(deltaTLSF + 103) < eps, testMesg, __LINE__);
545       testMesg = "getUTC returned an incorrect value for Tot";
546       testFramework.assert( tot == 450560, testMesg, __LINE__);
547       testMesg = "getUTC returned an incorrect value for WNt";
548       testFramework.assert( WNt == int(851/256)*256 + 90, testMesg, __LINE__);
549 
550          // Below test FAILS! in the 8 bit week conversion. Passing
551          // unsigned value into week conversion can cause diff to be
552          // larger than LIMIT[type], resulting in incorrect value.
553          // See EngNav.cpp convertXbit.
554 
555          /** @todo JMK says: I looked at the subframe 4 pg 18 data on
556           * line 251 (look for subframe456) and broke out the bits by
557           * hand.  The WNlsf was 766, and that's what the code is
558           * returning.  I honestly have no idea what this expression
559           * here is supposed to be, but I'm keeping it in case someone
560           * else wants to have a go at it:
561           * int(851/256)*256 + 254
562           */
563       testMesg = "getUTC returned an incorrect value for WNLSF";
564       testFramework.assert( WNLSF == 766, testMesg, __LINE__);
565 
566       testMesg = "getUTC returned an incorrect value for DN";
567       testFramework.assert( DN == 5, testMesg, __LINE__);
568 
569       testMesg = "getAlmOrbElem returned an incorrect AlmOrbit object";
570       failCount = 0;
571       for (int i=0; i<30; i++)
572       {
573          x = i+1;
574          if (x > 7) x = i+2;
575          gpstk::AlmOrbit Compare(aData.id[i], aData.ecc[i], (aData.oi[i] - .3*M_PI),
576                                  aData.rora[i],
577                                  aData.sqrta[i], aData.raaw[i], aData.aop[i], aData.ma[i], aData.af0[i],
578                                  aData.af1[i],
579                                  aData.toa[i], 0/*?*/, aData.week[i], aData.health[i]);
580          gpstk::AlmOrbit orbitData;
581          orbitData = alm.getAlmOrbElem(gpstk::SatID(x, gpstk::SatelliteSystem::GPS));
582 
583 // No == operator for AlmOrbit, using AlmOrbit's get methods to compare
584 // Too many tests, using counter. Uncomment to find specific error
585             /*
586               testMesg = "PRN value in getAlmOrbElem is incorrect";
587               testFramework.assert(orbitData.getPRN() == Compare.getPRN(), testMesg, __LINE__);
588               testMesg = "ecc value in getAlmOrbElem is incorrect";
589               testFramework.assert(std::abs(orbitData.getecc() - Compare.getecc()) < eps, testMesg, __LINE__);
590               testMesg = "i_offset value in getAlmOrbElem is incorrect";
591               testFramework.assert(std::abs(orbitData.geti_offset() - Compare.geti_offset()) < eps, testMesg, __LINE__);
592               testMesg = "OMEGAdot value in getAlmOrbElem is incorrect";
593               testFramework.assert(std::abs(orbitData.getOMEGAdot() - Compare.getOMEGAdot()) < eps, testMesg, __LINE__);
594               testMesg = "Ahalf value in getAlmOrbElem is incorrect";
595               testFramework.assert(std::abs(orbitData.getAhalf() - Compare.getAhalf()) < eps, testMesg, __LINE__);
596               testMesg = "OMEGA0 value in getAlmOrbElem is incorrect";
597               testFramework.assert(std::abs(orbitData.getOMEGA0() - Compare.getOMEGA0()) < eps, testMesg, __LINE__);
598               testMesg = "w value in getAlmOrbElem is incorrect";
599               testFramework.assert(std::abs(orbitData.getw() - Compare.getw()) < eps, testMesg, __LINE__);
600               testMesg = "M0 value in getAlmOrbElem is incorrect";
601               testFramework.assert(std::abs(orbitData.getM0() - Compare.getM0()) < eps, testMesg, __LINE__);
602               testMesg = "AF0 value in getAlmOrbElem is incorrect";
603               testFramework.assert(std::abs(orbitData.getAF0() - Compare.getAF0()) < eps, testMesg, __LINE__);
604               testMesg = "AF1 value in getAlmOrbElem is incorrect";
605               testFramework.assert(std::abs(orbitData.getAF1() - Compare.getAF1()) < eps, testMesg, __LINE__);
606               testMesg = "ToaSOW value in getAlmOrbElem is incorrect";
607               testFramework.assert(orbitData.getToaSOW() == Compare.getToaSOW(), testMesg, __LINE__);
608               testMesg = "xmit_time value in getAlmOrbElem is incorrect";
609               testFramework.assert(orbitData.getxmit_time() == Compare.getxmit_time(), testMesg, __LINE__);
610               testMesg = "ToaWeek value in getAlmOrbElem is incorrect";
611               testFramework.assert(orbitData.getToaWeek() == Compare.getToaWeek(), testMesg, __LINE__);
612             */
613 
614          if (!(orbitData.getPRN() == Compare.getPRN())) failCount++;
615          if (!(std::abs(orbitData.getecc() - Compare.getecc()) < eps)) failCount++;
616          if (!(std::abs(orbitData.geti_offset() - Compare.geti_offset()) < eps))
617             failCount++;
618          if (!(std::abs(orbitData.getOMEGAdot() - Compare.getOMEGAdot()) < eps))
619             failCount++;
620          if (!(std::abs(orbitData.getAhalf() - Compare.getAhalf()) < eps)) failCount++;
621          if (!(std::abs(orbitData.getOMEGA0() - Compare.getOMEGA0()) < eps))
622             failCount++;
623          if (!(std::abs(orbitData.getw() - Compare.getw()) < eps)) failCount++;
624          if (!(std::abs(orbitData.getM0() - Compare.getM0()) < eps)) failCount++;
625          if (!(std::abs(orbitData.getAF0() - Compare.getAF0()) < eps)) failCount++;
626          if (!(std::abs(orbitData.getAF1() - Compare.getAF1()) < eps)) failCount++;
627          if (!(orbitData.getToaSOW() == Compare.getToaSOW())) failCount++;
628          if (!(orbitData.getxmit_time() == Compare.getxmit_time())) failCount++;
629          if (!(orbitData.getToaWeek() == Compare.getToaWeek())) failCount++;
630       }
631       testFramework.assert(failCount == 0, testMesg, __LINE__);
632 
633       return testFramework.countFails();
634 
635    }
636 
637 private:
638    double eps;
639    std::string testMesg;
640    AlmanacData aData; //data where the almanac info is stored
641    AlmanacSubframes aSubframes; //data where subframes are stored
642 
643 };
644 
645 
main()646 int main() //Main function to initialize and run all tests above
647 {
648    std::string pathData = gpstk::getPathData();
649    std::string almanacLocation = pathData + "/test_input_gps_almanac.txt";
650    std::ifstream iAlmanac(
651       almanacLocation.c_str()); // Reads in almanac data from file
652    AlmanacData iAData(iAlmanac); // Parses file into data objects
653    AlmanacSubframes iASubframes(
654       iAData); // Takes data objects and generates the subframes needed
655 
656    EngAlmanac_T testClass(iAData, iASubframes);
657    int check, errorCounter = 0;
658 
659    check = testClass.addSubframeTest(); // Tests adding the subframes to a class member of EngAlmanac
660    errorCounter += check;
661 
662    check = testClass.getTest(); // Tests the get methods and if subframes stored the correct data
663    errorCounter += check;
664 
665    std::cout << "Total Failures for " << __FILE__ << ": " << errorCounter <<
666              std::endl;
667 
668    return errorCounter; //Return the total number of errors
669 }
670