source: ntrip/branches/BNC_2.12/src/RTCM3/RTCM3Decoder.cpp@ 9209

Last change on this file since 9209 was 9209, checked in by stuerze, 11 months ago

small re-organization of debug output

File size: 60.4 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
8// http://www.fsv.cvut.cz
9//
10// Email: euref-ip@bkg.bund.de
11//
12// This program is free software; you can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation, version 2.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: RTCM3Decoder
30 *
31 * Purpose: RTCM3 Decoder
32 *
33 * Author: L. Mervart
34 *
35 * Created: 24-Aug-2006
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iostream>
42#include <iomanip>
43#include <sstream>
44#include <math.h>
45#include <string.h>
46
47#include "bits.h"
48#include "gnss.h"
49#include "RTCM3Decoder.h"
50#include "rtcm_utils.h"
51#include "bncconst.h"
52#include "bnccore.h"
53#include "bncutils.h"
54#include "bncsettings.h"
55
56using namespace std;
57
58// Error Handling
59////////////////////////////////////////////////////////////////////////////
60void RTCM3Error(const char*, ...) {
61}
62
63// Constructor
64////////////////////////////////////////////////////////////////////////////
65RTCM3Decoder::RTCM3Decoder(const QString& staID, bncRawFile* rawFile) :
66 GPSDecoder() {
67
68 _staID = staID;
69 _rawFile = rawFile;
70
71 connect(this, SIGNAL(newGPSEph(t_ephGPS)), BNC_CORE,
72 SLOT(slotNewGPSEph(t_ephGPS)));
73 connect(this, SIGNAL(newGlonassEph(t_ephGlo)), BNC_CORE,
74 SLOT(slotNewGlonassEph(t_ephGlo)));
75 connect(this, SIGNAL(newGalileoEph(t_ephGal)), BNC_CORE,
76 SLOT(slotNewGalileoEph(t_ephGal)));
77 connect(this, SIGNAL(newSBASEph(t_ephSBAS)), BNC_CORE,
78 SLOT(slotNewSBASEph(t_ephSBAS)));
79 connect(this, SIGNAL(newBDSEph(t_ephBDS)), BNC_CORE,
80 SLOT(slotNewBDSEph(t_ephBDS)));
81
82 _MessageSize = _SkipBytes = _BlockSize = _NeedBytes = 0;
83}
84
85// Destructor
86////////////////////////////////////////////////////////////////////////////
87RTCM3Decoder::~RTCM3Decoder() {
88 QMapIterator<QByteArray, RTCM3coDecoder*> it(_coDecoders);
89 while (it.hasNext())
90 {
91 it.next();
92 delete it.value();
93 }
94}
95
96//
97////////////////////////////////////////////////////////////////////////////
98bool RTCM3Decoder::DecodeRTCM3GPS(unsigned char* data, int size) {
99 bool decoded = false;
100 bncTime CurrentObsTime;
101 int i, numsats, syncf, type;
102 uint64_t numbits = 0, bitfield = 0;
103
104 data += 3; /* header */
105 size -= 6; /* header + crc */
106
107 GETBITS(type, 12)
108 SKIPBITS(12)
109 /* id */
110 GETBITS(i, 30)
111
112 CurrentObsTime.set(i);
113 if (_CurrentTime.valid() && CurrentObsTime != _CurrentTime) {
114 decoded = true;
115 _obsList.append(_CurrentObsList);
116 _CurrentObsList.clear();
117 }
118
119 _CurrentTime = CurrentObsTime;
120
121 GETBITS(syncf, 1)
122 /* sync */
123 GETBITS(numsats, 5)
124 SKIPBITS(4)
125 /* smind, smint */
126
127 while (numsats--) {
128 int sv, code, l1range, amb = 0;
129 t_satObs CurrentObs;
130 CurrentObs._time = CurrentObsTime;
131
132 GETBITS(sv, 6)
133 if (sv < 40)
134 CurrentObs._prn.set('G', sv);
135 else
136 CurrentObs._prn.set('S', sv - 20);
137
138 t_frqObs *frqObs = new t_frqObs;
139 /* L1 */
140 GETBITS(code, 1);
141 (code) ?
142 frqObs->_rnxType2ch.assign("1W") : frqObs->_rnxType2ch.assign("1C");
143 GETBITS(l1range, 24);
144 GETBITSSIGN(i, 20);
145 if ((i & ((1 << 20) - 1)) != 0x80000) {
146 frqObs->_code = l1range * 0.02;
147 frqObs->_phase = (l1range * 0.02 + i * 0.0005) / GPS_WAVELENGTH_L1;
148 frqObs->_codeValid = frqObs->_phaseValid = true;
149 }
150 GETBITS(frqObs->_lockTimeIndicator, 7);
151 frqObs->_lockTime = lti2sec(type, frqObs->_lockTimeIndicator);
152 frqObs->_lockTimeValid = (frqObs->_lockTime >= 0.0 && frqObs->_phaseValid);
153 if (type == 1002 || type == 1004) {
154 GETBITS(amb, 8);
155 if (amb) {
156 frqObs->_code += amb * 299792.458;
157 frqObs->_phase += (amb * 299792.458) / GPS_WAVELENGTH_L1;
158 }
159 GETBITS(i, 8);
160 if (i) {
161 frqObs->_snr = i * 0.25;
162 frqObs->_snrValid = true;
163 }
164 }
165 CurrentObs._obs.push_back(frqObs);
166 if (type == 1003 || type == 1004) {
167 frqObs = new t_frqObs;
168 /* L2 */
169 GETBITS(code, 2);
170 switch (code) {
171 case 3:
172 frqObs->_rnxType2ch.assign("2W"); /* or "2Y"? */
173 break;
174 case 2:
175 frqObs->_rnxType2ch.assign("2W");
176 break;
177 case 1:
178 frqObs->_rnxType2ch.assign("2P");
179 break;
180 case 0:
181 frqObs->_rnxType2ch.assign("2X"); /* or "2S" or "2L"? */
182 break;
183 }
184 GETBITSSIGN(i, 14);
185 if ((i & ((1 << 14) - 1)) != 0x2000) {
186 frqObs->_code = l1range * 0.02 + i * 0.02 + amb * 299792.458;
187 frqObs->_codeValid = true;
188 }
189 GETBITSSIGN(i, 20);
190 if ((i & ((1 << 20) - 1)) != 0x80000) {
191 frqObs->_phase = (l1range * 0.02 + i * 0.0005 + amb * 299792.458)
192 / GPS_WAVELENGTH_L2;
193 frqObs->_phaseValid = true;
194 }
195 GETBITS(frqObs->_lockTimeIndicator, 7);
196 frqObs->_lockTime = lti2sec(type, frqObs->_lockTimeIndicator);
197 frqObs->_lockTimeValid = (frqObs->_lockTime >= 0.0 && frqObs->_phaseValid);
198 if (type == 1004) {
199 GETBITS(i, 8);
200 if (i) {
201 frqObs->_snr = i * 0.25;
202 frqObs->_snrValid = true;
203 }
204 }
205 CurrentObs._obs.push_back(frqObs);
206 }
207 _CurrentObsList.push_back(CurrentObs);
208 }
209
210 if (!syncf) {
211 decoded = true;
212 _obsList.append(_CurrentObsList);
213 _CurrentTime.reset();
214 _CurrentObsList.clear();
215 }
216 return decoded;
217}
218
219#define RTCM3_MSM_NUMSIG 32
220#define RTCM3_MSM_NUMSAT 64
221#define RTCM3_MSM_NUMCELLS 96 /* arbitrary limit */
222
223/**
224 * Frequency numbers of GLONASS with an offset of 100 to detect unset values.
225 * Gets filled by ephemeris and data blocks and shared between different streams.
226 */
227static int GLOFreq[RTCM3_MSM_NUMSAT];
228
229/*
230 * Storage structure to store frequency and RINEX ID assignment for MSM
231 * message */
232struct CodeData {
233 double wl;
234 const char *code; /* currently unused */
235};
236
237/** MSM signal types for GPS and SBAS */
238static struct CodeData gps[RTCM3_MSM_NUMSIG] = {
239 {0.0, 0},
240 {GPS_WAVELENGTH_L1, "1C"},
241 {GPS_WAVELENGTH_L1, "1P"},
242 {GPS_WAVELENGTH_L1, "1W"},
243 {0.0, 0},
244 {0.0, 0},
245 {0.0, 0},
246 {GPS_WAVELENGTH_L2, "2C"},
247 {GPS_WAVELENGTH_L2, "2P"},
248 {GPS_WAVELENGTH_L2, "2W"},
249 {0.0, 0},
250 {0.0, 0},
251 {0.0, 0},
252 {0.0, 0},
253 {GPS_WAVELENGTH_L2, "2S"},
254 {GPS_WAVELENGTH_L2, "2L"},
255 {GPS_WAVELENGTH_L2, "2X"},
256 {0.0, 0},
257 {0.0, 0},
258 {0.0, 0},
259 {0.0, 0},
260 {GPS_WAVELENGTH_L5, "5I"},
261 {GPS_WAVELENGTH_L5, "5Q"},
262 {GPS_WAVELENGTH_L5, "5X"},
263 {0.0, 0},
264 {0.0, 0},
265 {0.0, 0},
266 {0.0, 0},
267 {0.0, 0},
268 {GPS_WAVELENGTH_L1, "1S"},
269 {GPS_WAVELENGTH_L1, "1L"},
270 {GPS_WAVELENGTH_L1, "1X"}
271 };
272
273/**
274 * MSM signal types for GLONASS
275 *
276 * NOTE: Uses 0.0, 1.0 for wavelength as sat index dependence is done later!
277 */
278static struct CodeData glo[RTCM3_MSM_NUMSIG] = {
279 {0.0, 0},
280 {0.0, "1C"},
281 {0.0, "1P"},
282 {0.0, 0},
283 {0.0, 0},
284 {0.0, 0},
285 {0.0, 0},
286 {1.0, "2C"},
287 {1.0, "2P"},
288 {GLO_WAVELENGTH_L1a, "4A"},
289 {GLO_WAVELENGTH_L1a, "4B"},
290 {GLO_WAVELENGTH_L1a, "4X"},
291 {GLO_WAVELENGTH_L2a, "6A"},
292 {GLO_WAVELENGTH_L2a, "6B"},
293 {GLO_WAVELENGTH_L2a, "6X"},
294 {GLO_WAVELENGTH_L3, "3I"},
295 {GLO_WAVELENGTH_L3, "3Q"},
296 {GLO_WAVELENGTH_L3, "3X"},
297 {0.0, 0},
298 {0.0, 0},
299 {0.0, 0},
300 {0.0, 0},
301 {0.0, 0},
302 {0.0, 0},
303 {0.0, 0},
304 {0.0, 0},
305 {0.0, 0},
306 {0.0, 0},
307 {0.0, 0},
308 {0.0, 0},
309 {0.0, 0},
310 {0.0, 0}
311 };
312
313/** MSM signal types for Galileo */
314static struct CodeData gal[RTCM3_MSM_NUMSIG] = {
315 {0.0, 0},
316 {GAL_WAVELENGTH_E1, "1C"},
317 {GAL_WAVELENGTH_E1, "1A"},
318 {GAL_WAVELENGTH_E1, "1B"},
319 {GAL_WAVELENGTH_E1, "1X"},
320 {GAL_WAVELENGTH_E1, "1Z"},
321 {0.0, 0},
322 {GAL_WAVELENGTH_E6, "6C"},
323 {GAL_WAVELENGTH_E6, "6A"},
324 {GAL_WAVELENGTH_E6, "6B"},
325 {GAL_WAVELENGTH_E6, "6X"},
326 {GAL_WAVELENGTH_E6, "6Z"},
327 {0.0, 0},
328 {GAL_WAVELENGTH_E5B, "7I"},
329 {GAL_WAVELENGTH_E5B, "7Q"},
330 {GAL_WAVELENGTH_E5B, "7X"},
331 {0.0, 0},
332 {GAL_WAVELENGTH_E5AB,"8I"},
333 {GAL_WAVELENGTH_E5AB,"8Q"},
334 {GAL_WAVELENGTH_E5AB,"8X"},
335 {0.0, 0},
336 {GAL_WAVELENGTH_E5A, "5I"},
337 {GAL_WAVELENGTH_E5A, "5Q"},
338 {GAL_WAVELENGTH_E5A, "5X"},
339 {0.0, 0},
340 {0.0, 0},
341 {0.0, 0},
342 {0.0, 0},
343 {0.0, 0},
344 {0.0, 0},
345 {0.0, 0},
346 {0.0, 0}
347 };
348
349/** MSM signal types for QZSS */
350static struct CodeData qzss[RTCM3_MSM_NUMSIG] = {
351 {0.0, 0},
352 {GPS_WAVELENGTH_L1, "1C"},
353 {0.0, 0},
354 {0.0, 0},
355 {0.0, 0},
356 {0.0, 0},
357 {0.0, 0},
358 {0.0, 0},
359 {QZSS_WAVELENGTH_L6, "6S"},
360 {QZSS_WAVELENGTH_L6, "6L"},
361 {QZSS_WAVELENGTH_L6, "6X"},
362 {0.0, 0},
363 {0.0, 0},
364 {0.0, 0},
365 {GPS_WAVELENGTH_L2, "2S"},
366 {GPS_WAVELENGTH_L2, "2L"},
367 {GPS_WAVELENGTH_L2, "2X"},
368 {0.0, 0},
369 {0.0, 0},
370 {0.0, 0},
371 {0.0, 0},
372 {GPS_WAVELENGTH_L5, "5I"},
373 {GPS_WAVELENGTH_L5, "5Q"},
374 {GPS_WAVELENGTH_L5, "5X"},
375 {0.0, 0},
376 {0.0, 0},
377 {0.0, 0},
378 {0.0, 0},
379 {0.0, 0},
380 {GPS_WAVELENGTH_L1, "1S"},
381 {GPS_WAVELENGTH_L1, "1L"},
382 {GPS_WAVELENGTH_L1, "1X"}
383 };
384
385/** MSM signal types for Beidou/BDS */
386static struct CodeData bds[RTCM3_MSM_NUMSIG] = {
387 {0.0, 0},
388 {BDS_WAVELENGTH_B1, "2I"},
389 {BDS_WAVELENGTH_B1, "2Q"},
390 {BDS_WAVELENGTH_B1, "2X"},
391 {0.0, 0},
392 {0.0, 0},
393 {0.0, 0},
394 {BDS_WAVELENGTH_B3, "6I"},
395 {BDS_WAVELENGTH_B3, "6Q"},
396 {BDS_WAVELENGTH_B3, "6X"},
397 {0.0, 0},
398 {0.0, 0},
399 {0.0, 0},
400 {BDS_WAVELENGTH_B2, "7I"},
401 {BDS_WAVELENGTH_B2, "7Q"},
402 {BDS_WAVELENGTH_B2, "7X"},
403 {0.0, 0},
404 {0.0, 0},
405 {0.0, 0},
406 {0.0, 0},
407 {0.0, 0},
408 {BDS_WAVELENGTH_B2a, "5D"},
409 {BDS_WAVELENGTH_B2a, "5P"},
410 {BDS_WAVELENGTH_B2a, "5X"},
411 {BDS_WAVELENGTH_B2b, "7D"},
412 {0.0, 0},
413 {0.0, 0},
414 {0.0, 0},
415 {0.0, 0},
416 {BDS_WAVELENGTH_B1C, "1D"},
417 {BDS_WAVELENGTH_B1C, "1P"},
418 {BDS_WAVELENGTH_B1C, "1X"}
419 };
420
421/** MSM signal types for IRNSS */
422static struct CodeData irn[RTCM3_MSM_NUMSIG] = {
423 {0.0, 0},
424 {0.0, 0},
425 {0.0, 0},
426 {0.0, 0},
427 {0.0, 0},
428 {0.0, 0},
429 {0.0, 0},
430 {IRNSS_WAVELENGTH_S, "9A"},
431 {0.0, 0},
432 {0.0, 0},
433 {0.0, 0},
434 {0.0, 0},
435 {0.0, 0},
436 {0.0, 0},
437 {0.0, 0},
438 {0.0, 0},
439 {0.0, 0},
440 {0.0, 0},
441 {0.0, 0},
442 {0.0, 0},
443 {0.0, 0},
444 {IRNSS_WAVELENGTH_L5, "5A"},
445 {0.0, 0},
446 {0.0, 0},
447 {0.0, 0},
448 {0.0, 0},
449 {0.0, 0},
450 {0.0, 0},
451 {0.0, 0},
452 {0.0, 0},
453 {0.0, 0},
454 {0.0, 0}
455 };
456
457#define UINT64(c) c ## ULL
458
459//
460////////////////////////////////////////////////////////////////////////////
461bool RTCM3Decoder::DecodeRTCM3MSM(unsigned char* data, int size) {
462 bool decoded = false;
463 int type, syncf, i;
464 uint64_t numbits = 0, bitfield = 0;
465
466 data += 3; /* header */
467 size -= 6; /* header + crc */
468
469 GETBITS(type, 12)
470 SKIPBITS(12)
471 /* id */
472 char sys;
473 if (type >= 1131)
474 sys = 'I';
475 else if (type >= 1121)
476 sys = 'C';
477 else if (type >= 1111)
478 sys = 'J';
479 else if (type >= 1101)
480 sys = 'S';
481 else if (type >= 1091)
482 sys = 'E';
483 else if (type >= 1081)
484 sys = 'R';
485 else if (type >= 1071)
486 sys = 'G';
487
488 bncTime CurrentObsTime;
489 if (sys == 'C') /* BDS */ {
490 GETBITS(i, 30)
491 CurrentObsTime.setBDS(i);
492 }
493 else if (sys == 'R') /* GLONASS */ {
494 SKIPBITS(3)
495 GETBITS(i, 27)
496 /* tk */
497 CurrentObsTime.setTk(i);
498 }
499 else /* GPS style date */ {
500 GETBITS(i, 30)
501 CurrentObsTime.set(i);
502 }
503 if (_CurrentTime.valid() && CurrentObsTime != _CurrentTime) {
504 decoded = true;
505 _obsList.append(_CurrentObsList);
506 _CurrentObsList.clear();
507 }
508 _CurrentTime = CurrentObsTime;
509
510 GETBITS(syncf, 1)
511 /**
512 * Ignore unknown types except for sync flag
513 *
514 * We actually support types 1-3 in following code, but as they are missing
515 * the full cycles and can't be used later we skip interpretation here already.
516 */
517 if (type <= 1137 && (type % 10) >= 4 && (type % 10) <= 7) {
518 int sigmask, numsat = 0, numsig = 0;
519 uint64_t satmask, cellmask, ui;
520 // satellite data
521 double rrmod[RTCM3_MSM_NUMSAT]; // GNSS sat rough ranges modulo 1 millisecond
522 int rrint[RTCM3_MSM_NUMSAT]; // number of integer msecs in GNSS sat rough ranges
523 int rdop[RTCM3_MSM_NUMSAT]; // GNSS sat rough phase range rates
524 int extsat[RTCM3_MSM_NUMSAT];// extended sat info
525 // signal data
526 int ll[RTCM3_MSM_NUMCELLS]; // lock time indicator
527 /*int hc[RTCM3_MSM_NUMCELLS];*/ // half cycle ambiguity indicator
528 double cnr[RTCM3_MSM_NUMCELLS]; // signal cnr
529 double cp[RTCM3_MSM_NUMCELLS]; // fine phase range data
530 double psr[RTCM3_MSM_NUMCELLS]; // fine psr
531 double dop[RTCM3_MSM_NUMCELLS]; // fine phase range rates
532
533 SKIPBITS(3 + 7 + 2 + 2 + 1 + 3)
534 GETBITS64(satmask, RTCM3_MSM_NUMSAT)
535
536 /* http://gurmeetsingh.wordpress.com/2008/08/05/fast-bit-counting-routines/ */
537 for (ui = satmask; ui; ui &= (ui - 1) /* remove rightmost bit */)
538 ++numsat;
539 GETBITS(sigmask, RTCM3_MSM_NUMSIG)
540 for (i = sigmask; i; i &= (i - 1) /* remove rightmost bit */)
541 ++numsig;
542 for (i = 0; i < RTCM3_MSM_NUMSAT; ++i)
543 extsat[i] = 15;
544
545 i = numsat * numsig;
546 GETBITS64(cellmask, (unsigned )i)
547 // satellite data
548 switch (type % 10) {
549 case 1:
550 case 2:
551 case 3:
552 /* partial data, already skipped above, but implemented for future expansion ! */
553 for (int j = numsat; j--;)
554 GETFLOAT(rrmod[j], 10, 1.0 / 1024.0)
555 break;
556 case 4:
557 case 6:
558 for (int j = numsat; j--;)
559 GETBITS(rrint[j], 8)
560 for (int j = numsat; j--;)
561 GETFLOAT(rrmod[j], 10, 1.0 / 1024.0)
562 break;
563 case 5:
564 case 7:
565 for (int j = numsat; j--;)
566 GETBITS(rrint[j], 8)
567 for (int j = numsat; j--;)
568 GETBITS(extsat[j], 4)
569 for (int j = numsat; j--;)
570 GETFLOAT(rrmod[j], 10, 1.0 / 1024.0)
571 for (int j = numsat; j--;)
572 GETBITSSIGN(rdop[j], 14)
573 break;
574 }
575 // signal data
576 int numcells = numsat * numsig;
577 /** Drop anything which exceeds our cell limit. Increase limit definition
578 * when that happens. */
579 if (numcells <= RTCM3_MSM_NUMCELLS) {
580 switch (type % 10) {
581 case 1:
582 for (int count = numcells; count--;)
583 if (cellmask & (UINT64(1) << count))
584 GETFLOATSIGN(psr[count], 15, 1.0 / (1 << 24))
585 break;
586 case 2:
587 for (int count = numcells; count--;)
588 if (cellmask & (UINT64(1) << count))
589 GETFLOATSIGN(cp[count], 22, 1.0 / (1 << 29))
590 for (int count = numcells; count--;)
591 if (cellmask & (UINT64(1) << count))
592 GETBITS(ll[count], 4)
593 for (int count = numcells; count--;)
594 if (cellmask & (UINT64(1) << count))
595 SKIPBITS(1)/*GETBITS(hc[count], 1)*/
596 break;
597 case 3:
598 for (int count = numcells; count--;)
599 if (cellmask & (UINT64(1) << count))
600 GETFLOATSIGN(psr[count], 15, 1.0 / (1 << 24))
601 for (int count = numcells; count--;)
602 if (cellmask & (UINT64(1) << count))
603 GETFLOATSIGN(cp[count], 22, 1.0 / (1 << 29))
604 for (int count = numcells; count--;)
605 if (cellmask & (UINT64(1) << count))
606 GETBITS(ll[count], 4)
607 for (int count = numcells; count--;)
608 if (cellmask & (UINT64(1) << count))
609 SKIPBITS(1)/*GETBITS(hc[count], 1)*/
610 break;
611 case 4:
612 for (int count = numcells; count--;)
613 if (cellmask & (UINT64(1) << count))
614 GETFLOATSIGN(psr[count], 15, 1.0 / (1 << 24))
615 for (int count = numcells; count--;)
616 if (cellmask & (UINT64(1) << count))
617 GETFLOATSIGN(cp[count], 22, 1.0 / (1 << 29))
618 for (int count = numcells; count--;)
619 if (cellmask & (UINT64(1) << count))
620 GETBITS(ll[count], 4)
621 for (int count = numcells; count--;)
622 if (cellmask & (UINT64(1) << count))
623 SKIPBITS(1)/*GETBITS(hc[count], 1)*/
624 for (int count = numcells; count--;)
625 if (cellmask & (UINT64(1) << count))
626 GETBITS(cnr[count], 6)
627 break;
628 case 5:
629 for (int count = numcells; count--;)
630 if (cellmask & (UINT64(1) << count))
631 GETFLOATSIGN(psr[count], 15, 1.0 / (1 << 24))
632 for (int count = numcells; count--;)
633 if (cellmask & (UINT64(1) << count))
634 GETFLOATSIGN(cp[count], 22, 1.0 / (1 << 29))
635 for (int count = numcells; count--;)
636 if (cellmask & (UINT64(1) << count))
637 GETBITS(ll[count], 4)
638 for (int count = numcells; count--;)
639 if (cellmask & (UINT64(1) << count))
640 SKIPBITS(1)/*GETBITS(hc[count], 1)*/
641 for (int count = numcells; count--;)
642 if (cellmask & (UINT64(1) << count))
643 GETFLOAT(cnr[count], 6, 1.0)
644 for (int count = numcells; count--;)
645 if (cellmask & (UINT64(1) << count))
646 GETFLOATSIGN(dop[count], 15, 0.0001)
647 break;
648 case 6:
649 for (int count = numcells; count--;)
650 if (cellmask & (UINT64(1) << count))
651 GETFLOATSIGN(psr[count], 20, 1.0 / (1 << 29))
652 for (int count = numcells; count--;)
653 if (cellmask & (UINT64(1) << count))
654 GETFLOATSIGN(cp[count], 24, 1.0 / (1U << 31))
655 for (int count = numcells; count--;)
656 if (cellmask & (UINT64(1) << count))
657 GETBITS(ll[count], 10)
658 for (int count = numcells; count--;)
659 if (cellmask & (UINT64(1) << count))
660 SKIPBITS(1)/*GETBITS(hc[count], 1)*/
661 for (int count = numcells; count--;)
662 if (cellmask & (UINT64(1) << count))
663 GETFLOAT(cnr[count], 10, 1.0 / (1 << 4))
664 break;
665 case 7:
666 for (int count = numcells; count--;)
667 if (cellmask & (UINT64(1) << count))
668 GETFLOATSIGN(psr[count], 20, 1.0 / (1 << 29))
669 for (int count = numcells; count--;)
670 if (cellmask & (UINT64(1) << count))
671 GETFLOATSIGN(cp[count], 24, 1.0 / (1U << 31))
672 for (int count = numcells; count--;)
673 if (cellmask & (UINT64(1) << count))
674 GETBITS(ll[count], 10)
675 for (int count = numcells; count--;)
676 if (cellmask & (UINT64(1) << count))
677 SKIPBITS(1)/*GETBITS(hc[count], 1)*/
678 for (int count = numcells; count--;)
679 if (cellmask & (UINT64(1) << count))
680 GETFLOAT(cnr[count], 10, 1.0 / (1 << 4))
681 for (int count = numcells; count--;)
682 if (cellmask & (UINT64(1) << count))
683 GETFLOATSIGN(dop[count], 15, 0.0001)
684 break;
685 }
686 i = RTCM3_MSM_NUMSAT;
687 int j = -1;
688 t_satObs CurrentObs;
689 for (int count = numcells; count--;) {
690 while (j >= 0 && !(sigmask & (1 << --j)))
691 ;
692 if (j < 0) {
693 while (!(satmask & (UINT64(1) << (--i))))
694 /* next satellite */
695 ;
696 if (CurrentObs._obs.size() > 0)
697 _CurrentObsList.push_back(CurrentObs);
698 CurrentObs.clear();
699 CurrentObs._time = CurrentObsTime;
700 if (sys == 'S')
701 CurrentObs._prn.set(sys, 20 - 1 + RTCM3_MSM_NUMSAT - i);
702 else
703 CurrentObs._prn.set(sys, RTCM3_MSM_NUMSAT - i);
704 j = RTCM3_MSM_NUMSIG;
705 while (!(sigmask & (1 << --j)))
706 ;
707 --numsat;
708 }
709 if (cellmask & (UINT64(1) << count)) {
710 struct CodeData cd = {0.0, 0};
711 switch (sys) {
712 case 'J':
713 cd = qzss[RTCM3_MSM_NUMSIG - j - 1];
714 break;
715 case 'C':
716 cd = bds[RTCM3_MSM_NUMSIG - j - 1];
717 break;
718 case 'G':
719 case 'S':
720 cd = gps[RTCM3_MSM_NUMSIG - j - 1];
721 break;
722 case 'R':
723 cd = glo[RTCM3_MSM_NUMSIG - j - 1];
724 {
725 int k = GLOFreq[RTCM3_MSM_NUMSAT - i - 1];
726 if (extsat[numsat] < 14) { // channel number is available as extended info for MSM5/7
727 k = GLOFreq[RTCM3_MSM_NUMSAT - i - 1] = 100 + extsat[numsat] - 7;
728 }
729 if (k) {
730 if (cd.wl == 0.0) {
731 cd.wl = GLO_WAVELENGTH_L1(k - 100);
732 }
733 else if (cd.wl == 1.0) {
734 cd.wl = GLO_WAVELENGTH_L2(k - 100);
735 }
736 }
737 else if (!k && cd.wl <= 1) {
738 cd.code = 0;
739 }
740 }
741 break;
742 case 'E':
743 cd = gal[RTCM3_MSM_NUMSIG - j - 1];
744 break;
745 case 'I':
746 cd = irn[RTCM3_MSM_NUMSIG - j - 1];
747 break;
748 }
749 if (cd.code) {
750 t_frqObs *frqObs = new t_frqObs;
751 frqObs->_rnxType2ch.assign(cd.code);
752
753 switch (type % 10) {
754 case 1:
755 if (psr[count] > -1.0 / (1 << 10)) {
756 frqObs->_code = psr[count] * LIGHTSPEED / 1000.0
757 + (rrmod[numsat]) * LIGHTSPEED / 1000.0;
758 frqObs->_codeValid = true;
759 }
760 break;
761 case 2:
762 if (cp[count] > -1.0 / (1 << 8)) {
763 frqObs->_phase = cp[count] * LIGHTSPEED / 1000.0 / cd.wl
764 + (rrmod[numsat]) * LIGHTSPEED / 1000.0 / cd.wl;
765 frqObs->_phaseValid = true;
766 frqObs->_lockTime = lti2sec(type,ll[count]);
767 frqObs->_lockTimeValid = (frqObs->_lockTime >= 0.0);
768 frqObs->_lockTimeIndicator = ll[count];
769 }
770 break;
771 case 3:
772 if (psr[count] > -1.0 / (1 << 10)) {
773 frqObs->_code = psr[count] * LIGHTSPEED / 1000.0
774 + (rrmod[numsat]) * LIGHTSPEED / 1000.0;
775 frqObs->_codeValid = true;
776 }
777 if (cp[count] > -1.0 / (1 << 8)) {
778 frqObs->_phase = cp[count] * LIGHTSPEED / 1000.0 / cd.wl
779 + rrmod[numsat] * LIGHTSPEED / 1000.0 / cd.wl;
780 frqObs->_phaseValid = true;
781 frqObs->_lockTime = lti2sec(type,ll[count]);
782 frqObs->_lockTimeValid = (frqObs->_lockTime >= 0.0);
783 frqObs->_lockTimeIndicator = ll[count];
784 }
785 break;
786 case 4:
787 if (psr[count] > -1.0 / (1 << 10)) {
788 frqObs->_code = psr[count] * LIGHTSPEED / 1000.0
789 + (rrmod[numsat] + rrint[numsat]) * LIGHTSPEED / 1000.0;
790 frqObs->_codeValid = true;
791 }
792 if (cp[count] > -1.0 / (1 << 8)) {
793 frqObs->_phase = cp[count] * LIGHTSPEED / 1000.0 / cd.wl
794 + (rrmod[numsat] + rrint[numsat]) * LIGHTSPEED / 1000.0 / cd.wl;
795 frqObs->_phaseValid = true;
796 frqObs->_lockTime = lti2sec(type,ll[count]);
797 frqObs->_lockTimeValid = (frqObs->_lockTime >= 0.0);
798 frqObs->_lockTimeIndicator = ll[count];
799 }
800 frqObs->_snr = cnr[count];
801 frqObs->_snrValid = true;
802 break;
803 case 5:
804 if (psr[count] > -1.0 / (1 << 10)) {
805 frqObs->_code = psr[count] * LIGHTSPEED / 1000.0
806 + (rrmod[numsat] + rrint[numsat]) * LIGHTSPEED / 1000.0;
807 frqObs->_codeValid = true;
808 }
809 if (cp[count] > -1.0 / (1 << 8)) {
810 frqObs->_phase = cp[count] * LIGHTSPEED / 1000.0 / cd.wl
811 + (rrmod[numsat] + rrint[numsat]) * LIGHTSPEED / 1000.0 / cd.wl;
812 frqObs->_phaseValid = true;
813 frqObs->_lockTime = lti2sec(type,ll[count]);
814 frqObs->_lockTimeValid = (frqObs->_lockTime >= 0.0);
815 frqObs->_lockTimeIndicator = ll[count];
816 }
817 frqObs->_snr = cnr[count];
818 frqObs->_snrValid = true;
819 if (dop[count] > -1.6384) {
820 frqObs->_doppler = -(dop[count] + rdop[numsat]) / cd.wl;
821 frqObs->_dopplerValid = true;
822 }
823 break;
824 case 6:
825 if (psr[count] > -1.0 / (1 << 10)) {
826 frqObs->_code = psr[count] * LIGHTSPEED / 1000.0
827 + (rrmod[numsat] + rrint[numsat]) * LIGHTSPEED / 1000.0;
828 frqObs->_codeValid = true;
829 }
830 if (cp[count] > -1.0 / (1 << 8)) {
831 frqObs->_phase = cp[count] * LIGHTSPEED / 1000.0 / cd.wl
832 + (rrmod[numsat] + rrint[numsat]) * LIGHTSPEED / 1000.0 / cd.wl;
833 frqObs->_phaseValid = true;
834 frqObs->_lockTime = lti2sec(type,ll[count]);
835 frqObs->_lockTimeValid = (frqObs->_lockTime >= 0.0);
836 frqObs->_lockTimeIndicator = ll[count];
837 }
838
839 frqObs->_snr = cnr[count];
840 frqObs->_snrValid = true;
841 break;
842 case 7:
843 if (psr[count] > -1.0 / (1 << 10)) {
844 frqObs->_code = psr[count] * LIGHTSPEED / 1000.0
845 + (rrmod[numsat] + rrint[numsat]) * LIGHTSPEED / 1000.0;
846 frqObs->_codeValid = true;
847 }
848 if (cp[count] > -1.0 / (1 << 8)) {
849 frqObs->_phase = cp[count] * LIGHTSPEED / 1000.0 / cd.wl
850 + (rrmod[numsat] + rrint[numsat]) * LIGHTSPEED / 1000.0 / cd.wl;
851 frqObs->_phaseValid = true;
852 frqObs->_lockTime = lti2sec(type,ll[count]);
853 frqObs->_lockTimeValid = (frqObs->_lockTime >= 0.0);
854 frqObs->_lockTimeIndicator = ll[count];
855 }
856
857 frqObs->_snr = cnr[count];
858 frqObs->_snrValid = true;
859
860 if (dop[count] > -1.6384) {
861 frqObs->_doppler = -(dop[count] + rdop[numsat]) / cd.wl;
862 frqObs->_dopplerValid = true;
863 }
864 break;
865 }
866 CurrentObs._obs.push_back(frqObs);
867 }
868 }
869 }
870 if (CurrentObs._obs.size() > 0) {
871 _CurrentObsList.push_back(CurrentObs);
872 }
873 }
874 }
875 else if ((type % 10) < 4) {
876 emit(newMessage(QString("%1: Block %2 contain partial data! Ignored!")
877 .arg(_staID).arg(type).toAscii(), true));
878 }
879 if (!syncf) {
880 decoded = true;
881 _obsList.append(_CurrentObsList);
882 _CurrentTime.reset();
883 _CurrentObsList.clear();
884 }
885 return decoded;
886}
887
888//
889////////////////////////////////////////////////////////////////////////////
890bool RTCM3Decoder::DecodeRTCM3GLONASS(unsigned char* data, int size) {
891 bool decoded = false;
892 bncTime CurrentObsTime;
893 int i, numsats, syncf, type;
894 uint64_t numbits = 0, bitfield = 0;
895
896 data += 3; /* header */
897 size -= 6; /* header + crc */
898
899 GETBITS(type, 12)
900 SKIPBITS(12)
901 /* id */
902 GETBITS(i, 27)
903 /* tk */
904
905 CurrentObsTime.setTk(i);
906 if (_CurrentTime.valid() && CurrentObsTime != _CurrentTime) {
907 decoded = true;
908 _obsList.append(_CurrentObsList);
909 _CurrentObsList.clear();
910 }
911 _CurrentTime = CurrentObsTime;
912
913 GETBITS(syncf, 1)
914 /* sync */
915 GETBITS(numsats, 5)
916 SKIPBITS(4)
917 /* smind, smint */
918
919 while (numsats--) {
920 int sv, code, l1range, amb = 0, freq;
921 t_satObs CurrentObs;
922 CurrentObs._time = CurrentObsTime;
923
924 GETBITS(sv, 6)
925 CurrentObs._prn.set('R', sv);
926 GETBITS(code, 1)
927 GETBITS(freq, 5)
928 GLOFreq[sv - 1] = 100 + freq - 7; /* store frequency for other users (MSM) */
929
930 t_frqObs *frqObs = new t_frqObs;
931 /* L1 */
932 (code) ?
933 frqObs->_rnxType2ch.assign("1P") : frqObs->_rnxType2ch.assign("1C");
934 GETBITS(l1range, 25);
935 GETBITSSIGN(i, 20);
936 if ((i & ((1 << 20) - 1)) != 0x80000) {
937 frqObs->_code = l1range * 0.02;
938 frqObs->_phase = (l1range * 0.02 + i * 0.0005) / GLO_WAVELENGTH_L1(freq - 7);
939 frqObs->_codeValid = frqObs->_phaseValid = true;
940 }
941 GETBITS(frqObs->_lockTimeIndicator, 7);
942 frqObs->_lockTime = lti2sec(type, frqObs->_lockTimeIndicator);
943 frqObs->_lockTimeValid = (frqObs->_lockTime >= 0.0 && frqObs->_phaseValid);
944 if (type == 1010 || type == 1012) {
945 GETBITS(amb, 7);
946 if (amb) {
947 frqObs->_code += amb * 599584.916;
948 frqObs->_phase += (amb * 599584.916) / GLO_WAVELENGTH_L1(freq - 7);
949 }
950 GETBITS(i, 8);
951 if (i) {
952 frqObs->_snr = i * 0.25;
953 frqObs->_snrValid = true;
954 }
955 }
956 CurrentObs._obs.push_back(frqObs);
957 if (type == 1011 || type == 1012) {
958 frqObs = new t_frqObs;
959 /* L2 */
960 GETBITS(code, 2);
961 switch (code) {
962 case 3:
963 frqObs->_rnxType2ch.assign("2P");
964 break;
965 case 2:
966 frqObs->_rnxType2ch.assign("2P");
967 break;
968 case 1:
969 frqObs->_rnxType2ch.assign("2P");
970 break;
971 case 0:
972 frqObs->_rnxType2ch.assign("2C");
973 break;
974 }
975 GETBITSSIGN(i, 14);
976 if ((i & ((1 << 14) - 1)) != 0x2000) {
977 frqObs->_code = l1range * 0.02 + i * 0.02 + amb * 599584.916;
978 frqObs->_codeValid = true;
979 }
980 GETBITSSIGN(i, 20);
981 if ((i & ((1 << 20) - 1)) != 0x80000) {
982 frqObs->_phase = (l1range * 0.02 + i * 0.0005 + amb * 599584.916)
983 / GLO_WAVELENGTH_L2(freq - 7);
984 frqObs->_phaseValid = true;
985 }
986 GETBITS(frqObs->_lockTimeIndicator, 7);
987 frqObs->_lockTime = lti2sec(type, frqObs->_lockTimeIndicator);
988 frqObs->_lockTimeValid = (frqObs->_lockTime >= 0.0 && frqObs->_phaseValid);
989 if (type == 1012) {
990 GETBITS(i, 8);
991 if (i) {
992 frqObs->_snr = i * 0.25;
993 frqObs->_snrValid = true;
994 }
995 }
996 CurrentObs._obs.push_back(frqObs);
997 }
998 _CurrentObsList.push_back(CurrentObs);
999 }
1000 if (!syncf) {
1001 decoded = true;
1002 _obsList.append(_CurrentObsList);
1003 _CurrentTime.reset();
1004 _CurrentObsList.clear();
1005 }
1006 return decoded;
1007}
1008
1009//
1010////////////////////////////////////////////////////////////////////////////
1011bool RTCM3Decoder::DecodeGPSEphemeris(unsigned char* data, int size) {
1012 bool decoded = false;
1013
1014 if (size == 67) {
1015 t_ephGPS eph;
1016 int i, week;
1017 uint64_t numbits = 0, bitfield = 0;
1018 int fitIntervalFalg = 0;
1019
1020 data += 3; /* header */
1021 size -= 6; /* header + crc */
1022 SKIPBITS(12)
1023
1024 eph._receptDateTime = currentDateAndTimeGPS();
1025
1026 GETBITS(i, 6)
1027 eph._prn.set('G', i);
1028 GETBITS(week, 10)
1029 GETBITS(i, 4)
1030 eph._ura = accuracyFromIndex(i, eph.type());
1031 GETBITS(eph._L2Codes, 2)
1032 GETFLOATSIGN(eph._IDOT, 14, R2R_PI/(double)(1<<30)/(double)(1<<13))
1033 GETBITS(eph._IODE, 8)
1034 GETBITS(i, 16)
1035 i <<= 4;
1036 eph._TOC.set(i * 1000);
1037 GETFLOATSIGN(eph._clock_driftrate, 8, 1.0 / (double )(1 << 30) / (double )(1 << 25))
1038 GETFLOATSIGN(eph._clock_drift, 16, 1.0 / (double )(1 << 30) / (double )(1 << 13))
1039 GETFLOATSIGN(eph._clock_bias, 22, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1040 GETBITS(eph._IODC, 10)
1041 GETFLOATSIGN(eph._Crs, 16, 1.0 / (double )(1 << 5))
1042 GETFLOATSIGN(eph._Delta_n, 16, R2R_PI/(double)(1<<30)/(double)(1<<13))
1043 GETFLOATSIGN(eph._M0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1044 GETFLOATSIGN(eph._Cuc, 16, 1.0 / (double )(1 << 29))
1045 GETFLOAT(eph._e, 32, 1.0 / (double )(1 << 30) / (double )(1 << 3))
1046 GETFLOATSIGN(eph._Cus, 16, 1.0 / (double )(1 << 29))
1047 GETFLOAT(eph._sqrt_A, 32, 1.0 / (double )(1 << 19))
1048 if (eph._sqrt_A < 1000.0) {
1049#ifdef BNC_DEBUG_BCEP
1050 emit(newMessage(QString("%1: Block %2 (%3) SQRT_A %4 m!")
1051 .arg(_staID).arg(1020,4).arg(eph._prn.toString().c_str())
1052 .arg(eph._sqrt_A,10,'F',3).toAscii(), true));
1053#endif
1054 return false;
1055 }
1056 GETBITS(i, 16)
1057 i <<= 4;
1058 eph._TOEsec = i;
1059 bncTime t;
1060 t.set(i * 1000);
1061 eph._TOEweek = t.gpsw();
1062 int numOfRollOvers = int(floor(t.gpsw()/1024.0));
1063 week += (numOfRollOvers * 1024);
1064 /* week from HOW, differs from TOC, TOE week, we use adapted value instead */
1065 if (eph._TOEweek > week + 1 || eph._TOEweek < week - 1) /* invalid week */
1066 return false;
1067 GETFLOATSIGN(eph._Cic, 16, 1.0 / (double )(1 << 29))
1068 GETFLOATSIGN(eph._OMEGA0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1069 GETFLOATSIGN(eph._Cis, 16, 1.0 / (double )(1 << 29))
1070 GETFLOATSIGN(eph._i0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1071 GETFLOATSIGN(eph._Crc, 16, 1.0 / (double )(1 << 5))
1072 GETFLOATSIGN(eph._omega, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1073 GETFLOATSIGN(eph._OMEGADOT, 24, R2R_PI/(double)(1<<30)/(double)(1<<13))
1074 GETFLOATSIGN(eph._TGD, 8, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1075 GETBITS(eph._health, 6)
1076 GETBITS(eph._L2PFlag, 1)
1077 GETBITS(fitIntervalFalg, 1)
1078 eph._fitInterval = fitIntervalFromFlag(fitIntervalFalg, eph._IODC, eph.type());
1079 eph._TOT = 0.9999e9;
1080
1081 emit newGPSEph(eph);
1082 decoded = true;
1083 }
1084 return decoded;
1085}
1086
1087//
1088////////////////////////////////////////////////////////////////////////////
1089bool RTCM3Decoder::DecodeGLONASSEphemeris(unsigned char* data, int size) {
1090 bool decoded = false;
1091
1092 if (size == 51) {
1093 t_ephGlo eph;
1094 int sv, i, tk;
1095 uint64_t numbits = 0, bitfield = 0;
1096
1097 data += 3; /* header */
1098 size -= 6; /* header + crc */
1099 SKIPBITS(12)
1100
1101 eph._receptDateTime = currentDateAndTimeGPS();
1102
1103 GETBITS(sv, 6)
1104 eph._prn.set('R', sv);
1105
1106 GETBITS(i, 5)
1107 eph._frequency_number = i - 7;
1108 GETBITS(eph._almanac_health, 1) /* almanac healthy */
1109 GETBITS(eph._almanac_health_availablility_indicator, 1) /* almanac health ok */
1110 if (eph._almanac_health_availablility_indicator == 0.0) {
1111#ifdef BNC_DEBUG_BCEP
1112 emit(newMessage(QString("%1: Block %2 (%3): ALM = %4: missing data!")
1113 .arg(_staID).arg(1019,4).arg(eph._prn.toString().c_str())
1114 .arg(eph._almanac_health_availablility_indicator).toAscii(), true));
1115#endif
1116 return false;
1117 }
1118 GETBITS(eph._P1, 2) /* P1 */
1119 GETBITS(i, 5)
1120 tk = i * 60 * 60;
1121 GETBITS(i, 6)
1122 tk += i * 60;
1123 GETBITS(i, 1)
1124 tk += i * 30;
1125 eph._tki = tk - 3*60*60;
1126 if(eph._tki < 0.0) {
1127 eph._tki += 86400.0;
1128 }
1129 GETBITS(eph._health, 1) /* MSB of Bn*/
1130 GETBITS(eph._P2, 1) /* P2 */
1131 GETBITS(i, 7)
1132 eph._TOC.setTk(i * 15 * 60 * 1000); /* tb */
1133
1134 GETFLOATSIGNM(eph._x_velocity, 24, 1.0 / (double )(1 << 20))
1135 GETFLOATSIGNM(eph._x_pos, 27, 1.0 / (double )(1 << 11))
1136 GETFLOATSIGNM(eph._x_acceleration, 5, 1.0 / (double )(1 << 30))
1137 GETFLOATSIGNM(eph._y_velocity, 24, 1.0 / (double )(1 << 20))
1138 GETFLOATSIGNM(eph._y_pos, 27, 1.0 / (double )(1 << 11))
1139 GETFLOATSIGNM(eph._y_acceleration, 5, 1.0 / (double )(1 << 30))
1140 GETFLOATSIGNM(eph._z_velocity, 24, 1.0 / (double )(1 << 20))
1141 GETFLOATSIGNM(eph._z_pos, 27, 1.0 / (double )(1 << 11))
1142 GETFLOATSIGNM(eph._z_acceleration, 5, 1.0 / (double )(1 << 30))
1143 GETBITS(eph._P3, 1) /* P3 */
1144 GETFLOATSIGNM(eph._gamma, 11, 1.0 / (double )(1 << 30) / (double )(1 << 10))
1145 GETBITS(eph._M_P, 2) /* GLONASS-M P, */
1146 GETBITS(eph._M_l3, 1) /*GLONASS-M ln (third string) */
1147 GETFLOATSIGNM(eph._tau, 22, 1.0 / (double )(1 << 30)) /* GLONASS tau n(tb) */
1148 GETFLOATSIGNM(eph._M_delta_tau, 5, 1.0 / (double )(1 << 30)) /* GLONASS-M delta tau n(tb) */
1149 GETBITS(eph._E, 5)
1150 GETBITS(eph._M_P4, 1) /* GLONASS-M P4 */
1151 GETBITS(eph._M_FT, 4) /* GLONASS-M Ft */
1152 GETBITS(eph._M_NT, 11) /* GLONASS-M Nt */
1153 if (eph._M_NT == 0.0) {
1154#ifdef BNC_DEBUG_BCEP
1155 emit(newMessage(QString("%1: Block %2 (%3): NT = %4: missing data!")
1156 .arg(_staID).arg(1019,4).arg(eph._prn.toString().c_str()).arg(eph._M_NT,4).toAscii(), true));
1157#endif
1158 return false;
1159 }
1160 GETBITS(eph._M_M, 2) /* GLONASS-M M */
1161 GETBITS(eph._additional_data_availability, 1) /* GLONASS-M The Availability of Additional Data */
1162 if (eph._additional_data_availability == 0.0) {
1163#ifdef BNC_DEBUG_BCEP
1164 emit(newMessage(QString("%1: Block %2 (%3): ADD = %4: missing data!")
1165 .arg(_staID).arg(1019,4).arg(eph._prn.toString().c_str())
1166 .arg(eph._additional_data_availability).toAscii(), true));
1167#endif
1168 return false;
1169 }
1170 GETBITS(eph._NA, 11) /* GLONASS-M Na */
1171 GETFLOATSIGNM(eph._tauC, 32, 1.0/(double)(1<<30)/(double)(1<<1)) /* GLONASS tau c */
1172 GETBITS(eph._M_N4, 5) /* GLONASS-M N4 */
1173 GETFLOATSIGNM(eph._M_tau_GPS, 22, 1.0/(double)(1<<30)) /* GLONASS-M tau GPS */
1174 GETBITS(eph._M_l5, 1) /* GLONASS-M ln (fifth string) */
1175
1176 unsigned year, month, day;
1177 eph._TOC.civil_date(year, month, day);
1178 eph._gps_utc = gnumleap(year, month, day);
1179 eph._tt = eph._TOC;
1180
1181 eph._xv(1) = eph._x_pos * 1.e3;
1182 eph._xv(2) = eph._y_pos * 1.e3;
1183 eph._xv(3) = eph._z_pos * 1.e3;
1184 if (eph._xv.Rows(1,3).NormFrobenius() < 1.0) {
1185#ifdef BNC_DEBUG_BCEP
1186 emit(newMessage(QString("%1: Block %2 (%3): zero position!")
1187 .arg(_staID).arg(1019,4).arg(eph._prn.toString().c_str()).toAscii(), true));
1188#endif
1189 return false;
1190 }
1191 eph._xv(4) = eph._x_velocity * 1.e3;
1192 eph._xv(5) = eph._y_velocity * 1.e3;
1193 eph._xv(6) = eph._z_velocity * 1.e3;
1194 if (eph._xv.Rows(4,6).NormFrobenius() < 1.0) {
1195#ifdef BNC_DEBUG_BCEP
1196 emit(newMessage(QString("%1: Block %2 (%3): zero velocity!")
1197 .arg(_staID).arg(1019,4).arg(eph._prn.toString().c_str()).toAscii(), true));
1198#endif
1199 return false;
1200 }
1201 GLOFreq[sv - 1] = 100 + eph._frequency_number ; /* store frequency for other users (MSM) */
1202 _gloFrq = QString("%1 %2").arg(eph._prn.toString().c_str()).arg(eph._frequency_number, 2, 'f', 0);
1203
1204 emit newGlonassEph(eph);
1205 decoded = true;
1206 }
1207 return decoded;
1208}
1209
1210//
1211////////////////////////////////////////////////////////////////////////////
1212bool RTCM3Decoder::DecodeQZSSEphemeris(unsigned char* data, int size) {
1213 bool decoded = false;
1214
1215 if (size == 67) {
1216 t_ephGPS eph;
1217 int i, week;
1218 uint64_t numbits = 0, bitfield = 0;
1219 int fitIntervalFalg = 0;
1220
1221 data += 3; /* header */
1222 size -= 6; /* header + crc */
1223 SKIPBITS(12)
1224
1225 eph._receptDateTime = currentDateAndTimeGPS();
1226
1227 GETBITS(i, 4)
1228 eph._prn.set('J', i);
1229
1230 GETBITS(i, 16)
1231 i <<= 4;
1232 eph._TOC.set(i * 1000);
1233
1234 GETFLOATSIGN(eph._clock_driftrate, 8, 1.0 / (double )(1 << 30) / (double )(1 << 25))
1235 GETFLOATSIGN(eph._clock_drift, 16, 1.0 / (double )(1 << 30) / (double )(1 << 13))
1236 GETFLOATSIGN(eph._clock_bias, 22, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1237 GETBITS(eph._IODE, 8)
1238 GETFLOATSIGN(eph._Crs, 16, 1.0 / (double )(1 << 5))
1239 GETFLOATSIGN(eph._Delta_n, 16, R2R_PI/(double)(1<<30)/(double)(1<<13))
1240 GETFLOATSIGN(eph._M0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1241 GETFLOATSIGN(eph._Cuc, 16, 1.0 / (double )(1 << 29))
1242 GETFLOAT(eph._e, 32, 1.0 / (double )(1 << 30) / (double )(1 << 3))
1243 GETFLOATSIGN(eph._Cus, 16, 1.0 / (double )(1 << 29))
1244 GETFLOAT(eph._sqrt_A, 32, 1.0 / (double )(1 << 19))
1245 if (eph._sqrt_A < 1000.0) {
1246#ifdef BNC_DEBUG_BCEP
1247 emit(newMessage(QString("%1: Block %2 (%3) SQRT_A %4 m!")
1248 .arg(_staID).arg(1044,4).arg(eph._prn.toString().c_str())
1249 .arg(eph._sqrt_A,10,'F',3).toAscii(), true));
1250#endif
1251 return false;
1252 }
1253 GETBITS(i, 16)
1254 i <<= 4;
1255 eph._TOEsec = i;
1256 bncTime t;
1257 t.set(i*1000);
1258 eph._TOEweek = t.gpsw();
1259 GETFLOATSIGN(eph._Cic, 16, 1.0 / (double )(1 << 29))
1260 GETFLOATSIGN(eph._OMEGA0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1261 GETFLOATSIGN(eph._Cis, 16, 1.0 / (double )(1 << 29))
1262 GETFLOATSIGN(eph._i0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1263 GETFLOATSIGN(eph._Crc, 16, 1.0 / (double )(1 << 5))
1264 GETFLOATSIGN(eph._omega, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1265 GETFLOATSIGN(eph._OMEGADOT, 24, R2R_PI/(double)(1<<30)/(double)(1<<13))
1266 GETFLOATSIGN(eph._IDOT, 14, R2R_PI/(double)(1<<30)/(double)(1<<13))
1267 GETBITS(eph._L2Codes, 2)
1268 GETBITS(week, 10)
1269 int numOfRollOvers = int(floor(t.gpsw()/1024.0));
1270 week += (numOfRollOvers * 1024);
1271 /* week from HOW, differs from TOC, TOE week, we use adapted value instead */
1272 if (eph._TOEweek > week + 1 || eph._TOEweek < week - 1) /* invalid week */
1273 return false;
1274
1275 GETBITS(i, 4)
1276 if (i <= 6)
1277 eph._ura = ceil(10.0 * pow(2.0, 1.0 + i / 2.0)) / 10.0;
1278 else
1279 eph._ura = ceil(10.0 * pow(2.0, i / 2.0)) / 10.0;
1280 GETBITS(eph._health, 6)
1281 GETFLOATSIGN(eph._TGD, 8, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1282 GETBITS(eph._IODC, 10)
1283 GETBITS(fitIntervalFalg, 1)
1284 eph._fitInterval = fitIntervalFromFlag(fitIntervalFalg, eph._IODC, eph.type());
1285 eph._TOT = 0.9999e9;
1286
1287 emit newGPSEph(eph);
1288 decoded = true;
1289 }
1290 return decoded;
1291}
1292
1293//
1294////////////////////////////////////////////////////////////////////////////
1295bool RTCM3Decoder::DecodeIRNSSEphemeris(unsigned char* data, int size) {
1296 bool decoded = false;
1297
1298 if (size == 67) {
1299 t_ephGPS eph;
1300 int i, week, L5Flag, SFlag;
1301 uint64_t numbits = 0, bitfield = 0;
1302
1303 data += 3; /* header */
1304 size -= 6; /* header + crc */
1305 SKIPBITS(12)
1306
1307 eph._receptDateTime = currentDateAndTimeGPS();
1308
1309 GETBITS(i, 6)
1310 eph._prn.set('I', i);
1311 GETBITS(week, 10)
1312 GETFLOATSIGN(eph._clock_bias, 22, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1313 GETFLOATSIGN(eph._clock_drift, 16, 1.0 / (double )(1 << 30) / (double )(1 << 13))
1314 GETFLOATSIGN(eph._clock_driftrate, 8, 1.0 / (double )(1 << 30) / (double )(1 << 25))
1315 GETBITS(i, 4)
1316 eph._ura = accuracyFromIndex(i, eph.type());
1317 GETBITS(i, 16)
1318 i <<= 4;
1319 eph._TOC.set(i * 1000);
1320 GETFLOATSIGN(eph._TGD, 8, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1321 GETFLOATSIGN(eph._Delta_n, 22, R2R_PI/(double)(1<<30)/(double)(1 << 11))
1322 // IODCE
1323 GETBITS(eph._IODE, 8)
1324 eph._IODC = eph._IODE;
1325 SKIPBITS(10)
1326 GETBITS(L5Flag, 1)
1327 GETBITS(SFlag, 1)
1328 if (L5Flag == 0 && SFlag == 0) {
1329 eph._health = 0.0;
1330 }
1331 else if (L5Flag == 0 && SFlag == 1) {
1332 eph._health = 1.0;
1333 }
1334 else if (L5Flag == 1 && SFlag == 0) {
1335 eph._health = 2.0;
1336 }
1337 else if (L5Flag == 1 && SFlag == 1) {
1338 eph._health = 3.0;
1339 }
1340 GETFLOATSIGN(eph._Cuc, 15, 1.0 / (double )(1 << 28))
1341 GETFLOATSIGN(eph._Cus, 15, 1.0 / (double )(1 << 28))
1342 GETFLOATSIGN(eph._Cic, 15, 1.0 / (double )(1 << 28))
1343 GETFLOATSIGN(eph._Cis, 15, 1.0 / (double )(1 << 28))
1344 GETFLOATSIGN(eph._Crc, 15, 1.0 / (double )(1 << 4))
1345 GETFLOATSIGN(eph._Crs, 15, 1.0 / (double )(1 << 4))
1346 GETFLOATSIGN(eph._IDOT, 14, R2R_PI/(double)(1<<30)/(double)(1<<13))
1347 GETFLOATSIGN(eph._M0, 32, R2R_PI/(double)(1<<30)/(double)(1<< 1))
1348 GETBITS(i, 16)
1349 i <<= 4;
1350 eph._TOEsec = i;
1351 bncTime t;
1352 t.set(i * 1000);
1353 eph._TOEweek = t.gpsw();
1354 int numOfRollOvers = int(floor(t.gpsw()/1024.0));
1355 week += (numOfRollOvers * 1024);
1356 /* week from HOW, differs from TOC, TOE week, we use adapted value instead */
1357 if (eph._TOEweek > week + 1 || eph._TOEweek < week - 1) /* invalid week */
1358 return false;
1359 GETFLOAT(eph._e, 32, 1.0 / (double )(1 << 30) / (double )(1 << 3))
1360 GETFLOAT(eph._sqrt_A, 32, 1.0 / (double )(1 << 19))
1361 if (eph._sqrt_A < 1000.0) {
1362#ifdef BNC_DEBUG_BCEP
1363 emit(newMessage(QString("%1: Block %2 (%3) SQRT_A %4 m!")
1364 .arg(_staID).arg(1041,4).arg(eph._prn.toString().c_str())
1365 .arg(eph._sqrt_A,10,'F',3).toAscii(), true));
1366#endif
1367 return false;
1368 }
1369 GETFLOATSIGN(eph._OMEGA0, 32, R2R_PI/(double)(1<<30)/(double)(1<< 1))
1370 GETFLOATSIGN(eph._omega, 32, R2R_PI/(double)(1<<30)/(double)(1<< 1))
1371 GETFLOATSIGN(eph._OMEGADOT, 22, R2R_PI/(double)(1<<30)/(double)(1<<11))
1372 GETFLOATSIGN(eph._i0, 32, R2R_PI/(double)(1<<30)/(double)(1<< 1))
1373 SKIPBITS(2)
1374 SKIPBITS(2)
1375 eph._TOT = 0.9999e9;
1376
1377 emit newGPSEph(eph);
1378 decoded = true;
1379 }
1380 return decoded;
1381}
1382
1383//
1384////////////////////////////////////////////////////////////////////////////
1385bool RTCM3Decoder::DecodeSBASEphemeris(unsigned char* data, int size) {
1386 bool decoded = false;
1387
1388 if (size == 35) {
1389 t_ephSBAS eph;
1390 int i;
1391 uint64_t numbits = 0, bitfield = 0;
1392
1393 data += 3; /* header */
1394 size -= 6; /* header + crc */
1395 SKIPBITS(12)
1396
1397 eph._receptDateTime = currentDateAndTimeGPS();
1398
1399 GETBITS(i, 6)
1400 eph._prn.set('S', 20 + i);
1401 GETBITS(eph._IODN, 8)
1402 GETBITS(i, 13)
1403 i <<= 4;
1404 eph._TOC.setTOD(i * 1000);
1405 GETBITS(i, 4)
1406 eph._ura = accuracyFromIndex(i, eph.type());
1407 GETFLOATSIGN(eph._x_pos, 30, 0.08)
1408 GETFLOATSIGN(eph._y_pos, 30, 0.08)
1409 GETFLOATSIGN(eph._z_pos, 25, 0.4)
1410 ColumnVector pos(3);
1411 pos(1) = eph._x_pos; pos(2) = eph._y_pos; pos(3) = eph._z_pos;
1412 if (pos.NormFrobenius() < 1.0) {
1413#ifdef BNC_DEBUG_BCEP
1414 emit(newMessage(QString("%1: Block %2 (%3): zero position!")
1415 .arg(_staID).arg(1043,4).arg(eph._prn.toString().c_str()).toAscii(), true));
1416#endif
1417 return false;
1418 }
1419 GETFLOATSIGN(eph._x_velocity, 17, 0.000625)
1420 GETFLOATSIGN(eph._y_velocity, 17, 0.000625)
1421 GETFLOATSIGN(eph._z_velocity, 18, 0.004)
1422 GETFLOATSIGN(eph._x_acceleration, 10, 0.0000125)
1423 GETFLOATSIGN(eph._y_acceleration, 10, 0.0000125)
1424 GETFLOATSIGN(eph._z_acceleration, 10, 0.0000625)
1425 GETFLOATSIGN(eph._agf0, 12, 1.0 / (1 << 30) / (1 << 1))
1426 GETFLOATSIGN(eph._agf1, 8, 1.0 / (1 << 30) / (1 << 10))
1427
1428 eph._TOT = 0.9999E9;
1429 eph._health = 0;
1430
1431 emit newSBASEph(eph);
1432 decoded = true;
1433 }
1434 return decoded;
1435}
1436
1437//
1438////////////////////////////////////////////////////////////////////////////
1439bool RTCM3Decoder::DecodeGalileoEphemeris(unsigned char* data, int size) {
1440 bool decoded = false;
1441 uint64_t numbits = 0, bitfield = 0;
1442 int i;
1443
1444 data += 3; /* header */
1445 size -= 6; /* header + crc */
1446 GETBITS(i, 12)
1447
1448 if ((i == 1046 && size == 61) || (i == 1045 && size == 60)) {
1449 t_ephGal eph;
1450
1451 eph._receptDateTime = currentDateAndTimeGPS();
1452
1453 eph._inav = (i == 1046);
1454 eph._fnav = (i == 1045);
1455 GETBITS(i, 6)
1456 eph._prn.set('E', i, eph._inav ? 1 : 0);
1457
1458 GETBITS(eph._TOEweek, 12) //FIXME: roll-over after week 4095!!
1459 GETBITS(eph._IODnav, 10)
1460 GETBITS(i, 8)
1461 eph._SISA = accuracyFromIndex(i, eph.type());
1462 GETFLOATSIGN(eph._IDOT, 14, R2R_PI/(double)(1<<30)/(double)(1<<13))
1463 GETBITSFACTOR(i, 14, 60)
1464 eph._TOC.set(1024 + eph._TOEweek, i);
1465 GETFLOATSIGN(eph._clock_driftrate, 6, 1.0 / (double )(1 << 30) / (double )(1 << 29))
1466 GETFLOATSIGN(eph._clock_drift, 21, 1.0 / (double )(1 << 30) / (double )(1 << 16))
1467 GETFLOATSIGN(eph._clock_bias, 31, 1.0 / (double )(1 << 30) / (double )(1 << 4))
1468 GETFLOATSIGN(eph._Crs, 16, 1.0 / (double )(1 << 5))
1469 GETFLOATSIGN(eph._Delta_n, 16, R2R_PI/(double)(1<<30)/(double)(1<<13))
1470 GETFLOATSIGN(eph._M0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1471 GETFLOATSIGN(eph._Cuc, 16, 1.0 / (double )(1 << 29))
1472 GETFLOAT(eph._e, 32, 1.0 / (double )(1 << 30) / (double )(1 << 3))
1473 GETFLOATSIGN(eph._Cus, 16, 1.0 / (double )(1 << 29))
1474 GETFLOAT(eph._sqrt_A, 32, 1.0 / (double )(1 << 19))
1475 GETBITSFACTOR(eph._TOEsec, 14, 60)
1476 /* FIXME: overwrite value, copied from old code */
1477 eph._TOEsec = eph._TOC.gpssec();
1478 GETFLOATSIGN(eph._Cic, 16, 1.0 / (double )(1 << 29))
1479 GETFLOATSIGN(eph._OMEGA0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1480 GETFLOATSIGN(eph._Cis, 16, 1.0 / (double )(1 << 29))
1481 GETFLOATSIGN(eph._i0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1482 GETFLOATSIGN(eph._Crc, 16, 1.0 / (double )(1 << 5))
1483 GETFLOATSIGN(eph._omega, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1484 GETFLOATSIGN(eph._OMEGADOT, 24, R2R_PI/(double)(1<<30)/(double)(1<<13))
1485 GETFLOATSIGN(eph._BGD_1_5A, 10, 1.0 / (double )(1 << 30) / (double )(1 << 2))
1486 if (eph._inav) {
1487 /* set unused F/NAV values */
1488 eph._E5aHS = 0.0;
1489 eph._e5aDataInValid = false;
1490
1491 GETFLOATSIGN(eph._BGD_1_5B, 10, 1.0 / (double )(1 << 30) / (double )(1 << 2))
1492 GETBITS(eph._E5bHS, 2)
1493 GETBITS(eph._e5bDataInValid, 1)
1494 GETBITS(eph._E1_bHS, 2)
1495 GETBITS(eph._e1DataInValid, 1)
1496 if (eph._E5bHS != eph._E1_bHS) {
1497#ifdef BNC_DEBUG_BCEP
1498 emit(newMessage(QString("%1: Block %2 (%3) SHS E5b %4 E1B %5: inconsistent health!")
1499 .arg(_staID).arg(1046,4).arg(eph._prn.toString().c_str())
1500 .arg(eph._E5bHS).arg(eph._E1_bHS).toAscii(), true));
1501#endif
1502 return false;
1503 }
1504 if ((eph._BGD_1_5A == 0.0 && fabs(eph._BGD_1_5B) > 1e-9) ||
1505 (eph._BGD_1_5B == 0.0 && fabs(eph._BGD_1_5A) > 1e-9)) {
1506#ifdef BNC_DEBUG_BCEP
1507 emit(newMessage(QString("%1: Block %2 (%3) BGD_15a = %4 BGD_15b = %5: inconsistent BGD!")
1508 .arg(_staID).arg(1046,4).arg(eph._prn.toString().c_str())
1509 .arg(eph._BGD_1_5A,10,'E',3).arg(eph._BGD_1_5B,10,'E',3).toAscii(), true));
1510#endif
1511 return false;
1512 }
1513 }
1514 else {
1515 /* set unused I/NAV values */
1516 eph._BGD_1_5B = 0.0;
1517 eph._E5bHS = 0.0;
1518 eph._E1_bHS = 0.0;
1519 eph._e1DataInValid = false;
1520 eph._e5bDataInValid = false;
1521
1522 GETBITS(eph._E5aHS, 2)
1523 GETBITS(eph._e5aDataInValid, 1)
1524 }
1525 eph._TOT = 0.9999e9;
1526
1527 if (eph._sqrt_A < 1000.0) {
1528#ifdef BNC_DEBUG_BCEP
1529 emit(newMessage(QString("%1: Block %2 (%3) SQRT_A %4 m!")
1530 .arg(_staID).arg(eph._inav? 1046 : 1045,4).arg(eph._prn.toString().c_str())
1531 .arg(eph._sqrt_A,10,'F',3).toLatin1(), true));
1532#endif
1533 return false;
1534 }
1535
1536 emit newGalileoEph(eph);
1537 decoded = true;
1538 }
1539 return decoded;
1540}
1541
1542//
1543////////////////////////////////////////////////////////////////////////////
1544bool RTCM3Decoder::DecodeBDSEphemeris(unsigned char* data, int size) {
1545 bool decoded = false;
1546
1547 if (size == 70) {
1548 t_ephBDS eph;
1549 int i;
1550 uint64_t numbits = 0, bitfield = 0;
1551
1552 data += 3; /* header */
1553 size -= 6; /* header + crc */
1554 SKIPBITS(12)
1555
1556 eph._receptDateTime = currentDateAndTimeGPS();
1557
1558 GETBITS(i, 6)
1559 eph._prn.set('C', i);
1560
1561 SKIPBITS(13)
1562 /* week */
1563 GETBITS(i, 4)
1564 eph._URA = accuracyFromIndex(i, eph.type());
1565 GETFLOATSIGN(eph._IDOT, 14, R2R_PI/(double)(1<<30)/(double)(1<<13))
1566 GETBITS(eph._AODE, 5)
1567 GETBITS(i, 17)
1568 i <<= 3;
1569 eph._TOC.setBDS(i * 1000);
1570 GETFLOATSIGN(eph._clock_driftrate, 11, 1.0 / (double )(1 << 30) / (double )(1 << 30) / (double )(1 << 6))
1571 GETFLOATSIGN(eph._clock_drift, 22, 1.0 / (double )(1 << 30) / (double )(1 << 20))
1572 GETFLOATSIGN(eph._clock_bias, 24, 1.0 / (double )(1 << 30) / (double )(1 << 3))
1573 GETBITS(eph._AODC, 5)
1574 GETFLOATSIGN(eph._Crs, 18, 1.0 / (double )(1 << 6))
1575 GETFLOATSIGN(eph._Delta_n, 16, R2R_PI/(double)(1<<30)/(double)(1<<13))
1576 GETFLOATSIGN(eph._M0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1577 GETFLOATSIGN(eph._Cuc, 18, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1578 GETFLOAT(eph._e, 32, 1.0 / (double )(1 << 30) / (double )(1 << 3))
1579 GETFLOATSIGN(eph._Cus, 18, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1580 GETFLOAT(eph._sqrt_A, 32, 1.0 / (double )(1 << 19))
1581 if (eph._sqrt_A < 1000.0) {
1582#ifdef BNC_DEBUG_BCEP
1583 emit(newMessage(QString("%1: Block %2 (%3) SQRT_A %4 m!")
1584 .arg(_staID).arg(1042,4).arg(eph._prn.toString().c_str())
1585 .arg(eph._sqrt_A,10,'F',3).toAscii(), true));
1586#endif
1587 return false;
1588 }
1589 GETBITS(i, 17)
1590 i <<= 3;
1591 eph._TOEsec = i;
1592 eph._TOE.setBDS(i * 1000);
1593 GETFLOATSIGN(eph._Cic, 18, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1594 GETFLOATSIGN(eph._OMEGA0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1595 GETFLOATSIGN(eph._Cis, 18, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1596 GETFLOATSIGN(eph._i0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1597 GETFLOATSIGN(eph._Crc, 18, 1.0 / (double )(1 << 6))
1598 GETFLOATSIGN(eph._omega, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1599 GETFLOATSIGN(eph._OMEGADOT, 24, R2R_PI/(double)(1<<30)/(double)(1<<13))
1600 GETFLOATSIGN(eph._TGD1, 10, 0.0000000001)
1601 GETFLOATSIGN(eph._TGD2, 10, 0.0000000001)
1602 GETBITS(eph._SatH1, 1)
1603
1604 eph._TOT = 0.9999E9;
1605 emit newBDSEph(eph);
1606 decoded = true;
1607 }
1608 return decoded;
1609}
1610
1611//
1612////////////////////////////////////////////////////////////////////////////
1613bool RTCM3Decoder::DecodeAntennaReceiver(unsigned char* data, int size) {
1614 char *antenna, anttype[256];
1615 char *dummy;
1616 char *receiver, rectype[256];
1617
1618 int type;
1619
1620 int dnum = -1;
1621 int antnum = -1;
1622 int recnum = -1;
1623 uint64_t numbits = 0, bitfield = 0;
1624
1625 data += 3; /* header*/
1626 size -= 6; /* header + crc */
1627
1628 GETBITS(type, 12)
1629 SKIPBITS(12)
1630 GETSTRING(antnum, antenna)
1631 if (antnum > -1 && antnum < 265) {
1632 memcpy(anttype, antenna, antnum);
1633 anttype[antnum] = 0;
1634 if (!_antType.contains(anttype)) {
1635 _antType.push_back(anttype);
1636 }
1637 }
1638 if (type == 1033) {
1639 SKIPBITS(8)
1640 GETSTRING(dnum, dummy)
1641 GETSTRING(recnum, receiver)
1642 if (recnum > -1 && recnum < 265) {
1643 memcpy(rectype, receiver, recnum);
1644 rectype[recnum] = 0;
1645 if (!_recType.contains(rectype)) {
1646 _recType.push_back(rectype);
1647 }
1648 }
1649 }
1650 return true;
1651}
1652
1653//
1654////////////////////////////////////////////////////////////////////////////
1655bool RTCM3Decoder::DecodeAntennaPosition(unsigned char* data, int size) {
1656 int type;
1657 uint64_t numbits = 0, bitfield = 0;
1658 double x, y, z;
1659
1660 data += 3; /* header */
1661 size -= 6; /* header + crc */
1662
1663 GETBITS(type, 12)
1664 _antList.push_back(t_antInfo());
1665 _antList.back().type = t_antInfo::ARP;
1666 SKIPBITS(22)
1667 GETBITSSIGN(x, 38)
1668 _antList.back().xx = x * 1e-4;
1669 SKIPBITS(2)
1670 GETBITSSIGN(y, 38)
1671 _antList.back().yy = y * 1e-4;
1672 SKIPBITS(2)
1673 GETBITSSIGN(z, 38)
1674 _antList.back().zz = z * 1e-4;
1675 if (type == 1006)
1676 {
1677 double h;
1678 GETBITS(h, 16)
1679 _antList.back().height = h * 1e-4;
1680 _antList.back().height_f = true;
1681 }
1682 _antList.back().message = type;
1683
1684 return true;
1685}
1686
1687//
1688////////////////////////////////////////////////////////////////////////////
1689t_irc RTCM3Decoder::Decode(char* buffer, int bufLen, vector<string>& errmsg) {
1690 bool decoded = false;
1691
1692 errmsg.clear();
1693
1694 while (bufLen && _MessageSize < sizeof(_Message)) {
1695 int l = sizeof(_Message) - _MessageSize;
1696 if (l > bufLen)
1697 l = bufLen;
1698 memcpy(_Message + _MessageSize, buffer, l);
1699 _MessageSize += l;
1700 bufLen -= l;
1701 buffer += l;
1702 int id;
1703 while ((id = GetMessage())) {
1704 /* reset station ID for file loading as it can change */
1705 if (_rawFile)
1706 _staID = _rawFile->staID();
1707 /* store the id into the list of loaded blocks */
1708 _typeList.push_back(id);
1709
1710 /* SSR I+II data handled in another function, already pass the
1711 * extracted data block. That does no harm, as it anyway skip everything
1712 * else. */
1713 if ((id >= 1057 && id <= 1068) ||
1714 (id >= 1240 && id <= 1270) ||
1715 (id == 4076)) {
1716 if (!_coDecoders.contains(_staID.toLatin1())) {
1717 _coDecoders[_staID.toLatin1()] = new RTCM3coDecoder(_staID);
1718 }
1719 RTCM3coDecoder* coDecoder = _coDecoders[_staID.toLatin1()];
1720 if (id == 4076) {
1721 coDecoder->setSsrFormatType(RTCM3coDecoder::IGSssr);
1722 }
1723 else {
1724 coDecoder->setSsrFormatType(RTCM3coDecoder::RTCMssr);
1725 }
1726 if (coDecoder->Decode(reinterpret_cast<char *>(_Message), _BlockSize,
1727 errmsg) == success) {
1728 decoded = true;
1729 }
1730 }
1731 else if (id >= 1070 && id <= 1229) { /* MSM */
1732 if (DecodeRTCM3MSM(_Message, _BlockSize))
1733 decoded = true;
1734 }
1735 else {
1736 switch (id) {
1737 case 1001:
1738 case 1003:
1739 emit(newMessage(QString("%1: Block %2 contain partial data! Ignored!")
1740 .arg(_staID).arg(id).toAscii(), true));
1741 break; /* no use decoding partial data ATM, remove break when data can be used */
1742 case 1002:
1743 case 1004:
1744 if (DecodeRTCM3GPS(_Message, _BlockSize))
1745 decoded = true;
1746 break;
1747 case 1009:
1748 case 1011:
1749 emit(newMessage(QString("%1: Block %2 contain partial data! Ignored!")
1750 .arg(_staID).arg(id).toAscii(), true));
1751 break; /* no use decoding partial data ATM, remove break when data can be used */
1752 case 1010:
1753 case 1012:
1754 if (DecodeRTCM3GLONASS(_Message, _BlockSize))
1755 decoded = true;
1756 break;
1757 case 1019:
1758 if (DecodeGPSEphemeris(_Message, _BlockSize))
1759 decoded = true;
1760 break;
1761 case 1020:
1762 if (DecodeGLONASSEphemeris(_Message, _BlockSize))
1763 decoded = true;
1764 break;
1765 case 1043:
1766 if (DecodeSBASEphemeris(_Message, _BlockSize))
1767 decoded = true;
1768 break;
1769 case 1044:
1770 if (DecodeQZSSEphemeris(_Message, _BlockSize))
1771 decoded = true;
1772 break;
1773 case 1041:
1774 if (DecodeIRNSSEphemeris(_Message, _BlockSize))
1775 decoded = true;
1776 break;
1777 case 1045:
1778 case 1046:
1779 if (_staID.contains("AIRA") || _staID.contains("STK2") ||
1780 _staID.contains("CCJ2") || _staID.contains("SYOG")) {
1781 emit(newMessage(QString("%1: Block temporary %2 from JAXA RTKLIB encoded stations!")
1782 .arg(_staID).arg(id).toAscii(), true));
1783 break;
1784 }
1785 if (DecodeGalileoEphemeris(_Message, _BlockSize))
1786 decoded = true;
1787 break;
1788 case 1042:
1789 if (DecodeBDSEphemeris(_Message, _BlockSize))
1790 decoded = true;
1791 break;
1792 case 1007:
1793 case 1008:
1794 case 1033:
1795 DecodeAntennaReceiver(_Message, _BlockSize);
1796 break;
1797 case 1005:
1798 case 1006:
1799 DecodeAntennaPosition(_Message, _BlockSize);
1800 break;
1801 }
1802 }
1803 }
1804 }
1805 return decoded ? success : failure;
1806}
1807;
1808
1809//
1810////////////////////////////////////////////////////////////////////////////
1811uint32_t RTCM3Decoder::CRC24(long size, const unsigned char *buf) {
1812 uint32_t crc = 0;
1813 int ii;
1814 while (size--) {
1815 crc ^= (*buf++) << (16);
1816 for (ii = 0; ii < 8; ii++) {
1817 crc <<= 1;
1818 if (crc & 0x1000000)
1819 crc ^= 0x01864cfb;
1820 }
1821 }
1822 return crc;
1823}
1824
1825//
1826////////////////////////////////////////////////////////////////////////////
1827int RTCM3Decoder::GetMessage(void) {
1828 unsigned char *m, *e;
1829 int i;
1830
1831 m = _Message + _SkipBytes;
1832 e = _Message + _MessageSize;
1833 _NeedBytes = _SkipBytes = 0;
1834 while (e - m >= 3) {
1835 if (m[0] == 0xD3) {
1836 _BlockSize = ((m[1] & 3) << 8) | m[2];
1837 if (e - m >= static_cast<int>(_BlockSize + 6)) {
1838 if (static_cast<uint32_t>((m[3 + _BlockSize] << 16)
1839 | (m[3 + _BlockSize + 1] << 8)
1840 | (m[3 + _BlockSize + 2])) == CRC24(_BlockSize + 3, m)) {
1841 _BlockSize += 6;
1842 _SkipBytes = _BlockSize;
1843 break;
1844 }
1845 else
1846 ++m;
1847 }
1848 else {
1849 _NeedBytes = _BlockSize;
1850 break;
1851 }
1852 }
1853 else
1854 ++m;
1855 }
1856 if (e - m < 3)
1857 _NeedBytes = 3;
1858
1859 /* copy buffer to front */
1860 i = m - _Message;
1861 if (i && m < e)
1862 memmove(_Message, m, static_cast<size_t>(_MessageSize - i));
1863 _MessageSize -= i;
1864
1865 return !_NeedBytes ? ((_Message[3] << 4) | (_Message[4] >> 4)) : 0;
1866}
1867
1868// Time of Corrections
1869//////////////////////////////////////////////////////////////////////////////
1870int RTCM3Decoder::corrGPSEpochTime() const {
1871 return
1872 _coDecoders.size() > 0 ?
1873 _coDecoders.begin().value()->corrGPSEpochTime() : -1;
1874}
Note: See TracBrowser for help on using the repository browser.