source: ntrip/trunk/BNC/src/RTCM3/RTCM3Decoder.cpp@ 10554

Last change on this file since 10554 was 10554, checked in by stuerze, 7 weeks ago

minor changes

File size: 74.6 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#include "bnctime.h"
56#include "crs.h"
57
58using namespace std;
59
60// Error Handling
61////////////////////////////////////////////////////////////////////////////
62void RTCM3Error(const char*, ...) {
63}
64
65// Constructor
66////////////////////////////////////////////////////////////////////////////
67RTCM3Decoder::RTCM3Decoder(const QString& staID, bncRawFile* rawFile) :
68 GPSDecoder() {
69
70 _staID = staID;
71 _rawFile = rawFile;
72
73 connect(this, SIGNAL(newGPSEph(t_ephGPS)), BNC_CORE,
74 SLOT(slotNewGPSEph(t_ephGPS)));
75 connect(this, SIGNAL(newGlonassEph(t_ephGlo)), BNC_CORE,
76 SLOT(slotNewGlonassEph(t_ephGlo)));
77 connect(this, SIGNAL(newGalileoEph(t_ephGal)), BNC_CORE,
78 SLOT(slotNewGalileoEph(t_ephGal)));
79 connect(this, SIGNAL(newSBASEph(t_ephSBAS)), BNC_CORE,
80 SLOT(slotNewSBASEph(t_ephSBAS)));
81 connect(this, SIGNAL(newBDSEph(t_ephBDS)), BNC_CORE,
82 SLOT(slotNewBDSEph(t_ephBDS)));
83
84 _MessageSize = _SkipBytes = _BlockSize = _NeedBytes = 0;
85}
86
87// Destructor
88////////////////////////////////////////////////////////////////////////////
89RTCM3Decoder::~RTCM3Decoder() {
90 QMapIterator<QByteArray, RTCM3coDecoder*> it(_coDecoders);
91 while (it.hasNext()) {
92 it.next();
93 delete it.value();
94 }
95 _coDecoders.clear();
96}
97
98//
99////////////////////////////////////////////////////////////////////////////
100bool RTCM3Decoder::DecodeRTCM3GPS(unsigned char* data, int size) {
101 bool decoded = false;
102 bncTime CurrentObsTime;
103 int i, numsats, syncf, type;
104 uint64_t numbits = 0, bitfield = 0;
105
106 data += 3; /* header */
107 size -= 6; /* header + crc */
108
109 GETBITS(type, 12)
110 SKIPBITS(12)
111 /* id */
112 GETBITS(i, 30)
113
114 CurrentObsTime.set(i);
115 if (_CurrentTime.valid() && CurrentObsTime != _CurrentTime) {
116 decoded = true;
117 _obsList.append(_CurrentObsList);
118 _CurrentObsList.clear();
119 }
120
121 _CurrentTime = CurrentObsTime;
122
123 GETBITS(syncf, 1)
124 /* sync */
125 GETBITS(numsats, 5)
126 SKIPBITS(4)
127 /* smind, smint */
128
129 while (numsats--) {
130 int sv, code, l1range, amb = 0;
131 t_satObs CurrentObs;
132 CurrentObs._time = CurrentObsTime;
133 CurrentObs._type = type;
134
135 GETBITS(sv, 6)
136 if (sv < 40)
137 CurrentObs._prn.set('G', sv);
138 else
139 CurrentObs._prn.set('S', sv - 20);
140
141 t_frqObs *frqObs = new t_frqObs;
142 /* L1 */
143 GETBITS(code, 1);
144 (code) ?
145 frqObs->_rnxType2ch.assign("1W") : frqObs->_rnxType2ch.assign("1C");
146 GETBITS(l1range, 24);
147 GETBITSSIGN(i, 20);
148 if ((i & ((1 << 20) - 1)) != 0x80000) {
149 frqObs->_code = l1range * 0.02;
150 frqObs->_phase = (l1range * 0.02 + i * 0.0005) / GPS_WAVELENGTH_L1;
151 frqObs->_codeValid = frqObs->_phaseValid = true;
152 }
153 GETBITS(frqObs->_lockTimeIndicator, 7);
154 frqObs->_lockTime = lti2sec(type, frqObs->_lockTimeIndicator);
155 frqObs->_lockTimeValid = (frqObs->_lockTime >= 0.0 && frqObs->_phaseValid);
156 if (type == 1002 || type == 1004) {
157 GETBITS(amb, 8);
158 if (amb) {
159 frqObs->_code += amb * 299792.458;
160 frqObs->_phase += (amb * 299792.458) / GPS_WAVELENGTH_L1;
161 }
162 GETBITS(i, 8);
163 if (i) {
164 frqObs->_snr = i * 0.25;
165 frqObs->_snrValid = true;
166 }
167 }
168 CurrentObs._obs.push_back(frqObs);
169 if (type == 1003 || type == 1004) {
170 frqObs = new t_frqObs;
171 /* L2 */
172 GETBITS(code, 2);
173 switch (code) {
174 case 3:
175 frqObs->_rnxType2ch.assign("2W"); /* or "2Y"? */
176 break;
177 case 2:
178 frqObs->_rnxType2ch.assign("2W");
179 break;
180 case 1:
181 frqObs->_rnxType2ch.assign("2P");
182 break;
183 case 0:
184 frqObs->_rnxType2ch.assign("2X"); /* or "2S" or "2L"? */
185 break;
186 }
187 GETBITSSIGN(i, 14);
188 if ((i & ((1 << 14) - 1)) != 0x2000) {
189 frqObs->_code = l1range * 0.02 + i * 0.02 + amb * 299792.458;
190 frqObs->_codeValid = true;
191 }
192 GETBITSSIGN(i, 20);
193 if ((i & ((1 << 20) - 1)) != 0x80000) {
194 frqObs->_phase = (l1range * 0.02 + i * 0.0005 + amb * 299792.458)
195 / GPS_WAVELENGTH_L2;
196 frqObs->_phaseValid = true;
197 }
198 GETBITS(frqObs->_lockTimeIndicator, 7);
199 frqObs->_lockTime = lti2sec(type, frqObs->_lockTimeIndicator);
200 frqObs->_lockTimeValid = (frqObs->_lockTime >= 0.0 && frqObs->_phaseValid);
201 if (type == 1004) {
202 GETBITS(i, 8);
203 if (i) {
204 frqObs->_snr = i * 0.25;
205 frqObs->_snrValid = true;
206 }
207 }
208 CurrentObs._obs.push_back(frqObs);
209 }
210 _CurrentObsList.push_back(CurrentObs);
211 }
212
213 if (!syncf) {
214 decoded = true;
215 _obsList.append(_CurrentObsList);
216 _CurrentTime.reset();
217 _CurrentObsList.clear();
218 }
219 return decoded;
220}
221
222#define RTCM3_MSM_NUMSIG 32
223#define RTCM3_MSM_NUMSAT 64
224#define RTCM3_MSM_NUMCELLS 96 /* arbitrary limit */
225
226/**
227 * Frequency numbers of GLONASS with an offset of 100 to detect unset values.
228 * Gets filled by ephemeris and data blocks and shared between different streams.
229 */
230static int GLOFreq[RTCM3_MSM_NUMSAT];
231
232/*
233 * Storage structure to store frequency and RINEX ID assignment for MSM
234 * message */
235struct CodeData {
236 double wl;
237 const char *code; /* currently unused */
238};
239
240/** MSM signal types for GPS and SBAS */
241static struct CodeData gps[RTCM3_MSM_NUMSIG] = {
242 {0.0, 0},
243 {GPS_WAVELENGTH_L1, "1C"},
244 {GPS_WAVELENGTH_L1, "1P"},
245 {GPS_WAVELENGTH_L1, "1W"},
246 {0.0, 0},
247 {0.0, 0},
248 {0.0, 0},
249 {GPS_WAVELENGTH_L2, "2C"},
250 {GPS_WAVELENGTH_L2, "2P"},
251 {GPS_WAVELENGTH_L2, "2W"},
252 {0.0, 0},
253 {0.0, 0},
254 {0.0, 0},
255 {0.0, 0},
256 {GPS_WAVELENGTH_L2, "2S"},
257 {GPS_WAVELENGTH_L2, "2L"},
258 {GPS_WAVELENGTH_L2, "2X"},
259 {0.0, 0},
260 {0.0, 0},
261 {0.0, 0},
262 {0.0, 0},
263 {GPS_WAVELENGTH_L5, "5I"},
264 {GPS_WAVELENGTH_L5, "5Q"},
265 {GPS_WAVELENGTH_L5, "5X"},
266 {0.0, 0},
267 {0.0, 0},
268 {0.0, 0},
269 {0.0, 0},
270 {0.0, 0},
271 {GPS_WAVELENGTH_L1, "1S"},
272 {GPS_WAVELENGTH_L1, "1L"},
273 {GPS_WAVELENGTH_L1, "1X"}
274 };
275
276/**
277 * MSM signal types for GLONASS
278 *
279 * NOTE: Uses 0.0, 1.0 for wavelength as sat index dependence is done later!
280 */
281static struct CodeData glo[RTCM3_MSM_NUMSIG] = {
282 {0.0, 0},
283 {0.0, "1C"},
284 {0.0, "1P"},
285 {0.0, 0},
286 {0.0, 0},
287 {0.0, 0},
288 {0.0, 0},
289 {1.0, "2C"},
290 {1.0, "2P"},
291 {GLO_WAVELENGTH_L1a, "4A"},
292 {GLO_WAVELENGTH_L1a, "4B"},
293 {GLO_WAVELENGTH_L1a, "4X"},
294 {GLO_WAVELENGTH_L2a, "6A"},
295 {GLO_WAVELENGTH_L2a, "6B"},
296 {GLO_WAVELENGTH_L2a, "6X"},
297 {GLO_WAVELENGTH_L3, "3I"},
298 {GLO_WAVELENGTH_L3, "3Q"},
299 {GLO_WAVELENGTH_L3, "3X"},
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 {0.0, 0},
312 {0.0, 0},
313 {0.0, 0}
314 };
315
316/** MSM signal types for Galileo */
317static struct CodeData gal[RTCM3_MSM_NUMSIG] = {
318 {0.0, 0},
319 {GAL_WAVELENGTH_E1, "1C"},
320 {GAL_WAVELENGTH_E1, "1A"},
321 {GAL_WAVELENGTH_E1, "1B"},
322 {GAL_WAVELENGTH_E1, "1X"},
323 {GAL_WAVELENGTH_E1, "1Z"},
324 {0.0, 0},
325 {GAL_WAVELENGTH_E6, "6C"},
326 {GAL_WAVELENGTH_E6, "6A"},
327 {GAL_WAVELENGTH_E6, "6B"},
328 {GAL_WAVELENGTH_E6, "6X"},
329 {GAL_WAVELENGTH_E6, "6Z"},
330 {0.0, 0},
331 {GAL_WAVELENGTH_E5B, "7I"},
332 {GAL_WAVELENGTH_E5B, "7Q"},
333 {GAL_WAVELENGTH_E5B, "7X"},
334 {0.0, 0},
335 {GAL_WAVELENGTH_E5AB,"8I"},
336 {GAL_WAVELENGTH_E5AB,"8Q"},
337 {GAL_WAVELENGTH_E5AB,"8X"},
338 {0.0, 0},
339 {GAL_WAVELENGTH_E5A, "5I"},
340 {GAL_WAVELENGTH_E5A, "5Q"},
341 {GAL_WAVELENGTH_E5A, "5X"},
342 {0.0, 0},
343 {0.0, 0},
344 {0.0, 0},
345 {0.0, 0},
346 {0.0, 0},
347 {0.0, 0},
348 {0.0, 0},
349 {0.0, 0}
350 };
351
352/** MSM signal types for QZSS */
353static struct CodeData qzss[RTCM3_MSM_NUMSIG] = {
354 {0.0, 0},
355 {GPS_WAVELENGTH_L1, "1C"},
356 {0.0, 0},
357 {0.0, 0},
358 {0.0, 0},
359 {0.0, 0},
360 {0.0, 0},
361 {0.0, 0},
362 {QZSS_WAVELENGTH_L6, "6S"},
363 {QZSS_WAVELENGTH_L6, "6L"},
364 {QZSS_WAVELENGTH_L6, "6X"},
365 {0.0, 0},
366 {0.0, 0},
367 {0.0, 0},
368 {GPS_WAVELENGTH_L2, "2S"},
369 {GPS_WAVELENGTH_L2, "2L"},
370 {GPS_WAVELENGTH_L2, "2X"},
371 {0.0, 0},
372 {0.0, 0},
373 {0.0, 0},
374 {0.0, 0},
375 {GPS_WAVELENGTH_L5, "5I"},
376 {GPS_WAVELENGTH_L5, "5Q"},
377 {GPS_WAVELENGTH_L5, "5X"},
378 {0.0, 0},
379 {0.0, 0},
380 {0.0, 0},
381 {0.0, 0},
382 {0.0, 0},
383 {GPS_WAVELENGTH_L1, "1S"},
384 {GPS_WAVELENGTH_L1, "1L"},
385 {GPS_WAVELENGTH_L1, "1X"}
386 };
387
388/** MSM signal types for Beidou/BDS */
389static struct CodeData bds[RTCM3_MSM_NUMSIG] = {
390 {0.0, 0},
391 {BDS_WAVELENGTH_B1, "2I"},
392 {BDS_WAVELENGTH_B1, "2Q"},
393 {BDS_WAVELENGTH_B1, "2X"},
394 {0.0, 0},
395 {0.0, 0},
396 {0.0, 0},
397 {BDS_WAVELENGTH_B3, "6I"},
398 {BDS_WAVELENGTH_B3, "6Q"},
399 {BDS_WAVELENGTH_B3, "6X"},
400 {0.0, 0},
401 {0.0, 0},
402 {0.0, 0},
403 {BDS_WAVELENGTH_B2, "7I"},
404 {BDS_WAVELENGTH_B2, "7Q"},
405 {BDS_WAVELENGTH_B2, "7X"},
406 {0.0, 0},
407 {0.0, 0},
408 {0.0, 0},
409 {0.0, 0},
410 {0.0, 0},
411 {BDS_WAVELENGTH_B2a, "5D"},
412 {BDS_WAVELENGTH_B2a, "5P"},
413 {BDS_WAVELENGTH_B2a, "5X"},
414 {BDS_WAVELENGTH_B2b, "7D"},
415 {0.0, 0},
416 {0.0, 0},
417 {0.0, 0},
418 {0.0, 0},
419 {BDS_WAVELENGTH_B1C, "1D"},
420 {BDS_WAVELENGTH_B1C, "1P"},
421 {BDS_WAVELENGTH_B1C, "1X"}
422 };
423
424/** MSM signal types for IRNSS */
425static struct CodeData irn[RTCM3_MSM_NUMSIG] = {
426 {0.0, 0},
427 {0.0, 0},
428 {0.0, 0},
429 {0.0, 0},
430 {0.0, 0},
431 {0.0, 0},
432 {0.0, 0},
433 {IRNSS_WAVELENGTH_S, "9A"},
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 {0.0, 0},
445 {0.0, 0},
446 {0.0, 0},
447 {IRNSS_WAVELENGTH_L5, "5A"},
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 {0.0, 0},
456 {0.0, 0},
457 {0.0, 0}
458 };
459
460#define UINT64(c) c ## ULL
461
462//
463////////////////////////////////////////////////////////////////////////////
464bool RTCM3Decoder::DecodeRTCM3MSM(unsigned char* data, int size) {
465 bool decoded = false;
466 int type, syncf, i;
467 uint64_t numbits = 0, bitfield = 0;
468
469 data += 3; /* header */
470 size -= 6; /* header + crc */
471
472 GETBITS(type, 12)
473 SKIPBITS(12)
474 /* id */
475 char sys;
476 if (type >= 1131 && type <= 1137) {
477 sys = 'I';
478 }
479 else if (type >= 1121 && type <= 1127) {
480 sys = 'C';
481 }
482 else if (type >= 1111 && type <= 1117) {
483 sys = 'J';
484 }
485 else if (type >= 1101 && type <= 1107) {
486 sys = 'S';
487 }
488 else if (type >= 1091 && type <= 1097) {
489 sys = 'E';
490 }
491 else if (type >= 1081 && type <= 1087) {
492 sys = 'R';
493 }
494 else if (type >= 1071 && type <= 1077) {
495 sys = 'G';
496 }
497 else {
498 return decoded; // false
499 }
500 bncTime CurrentObsTime;
501 if (sys == 'C') /* BDS */ {
502 GETBITS(i, 30)
503 CurrentObsTime.setBDS(i);
504 }
505 else if (sys == 'R') /* GLONASS */ {
506 SKIPBITS(3)
507 GETBITS(i, 27)
508 /* tk */
509 CurrentObsTime.setTk(i);
510 }
511 else /* GPS style date */ {
512 GETBITS(i, 30)
513 CurrentObsTime.set(i);
514 }
515 if (_CurrentTime.valid() && CurrentObsTime != _CurrentTime) {
516 decoded = true;
517 _obsList.append(_CurrentObsList);
518 _CurrentObsList.clear();
519 }
520 _CurrentTime = CurrentObsTime;
521
522 GETBITS(syncf, 1)
523 /**
524 * Ignore unknown types except for sync flag
525 *
526 * We actually support types 1-3 in following code, but as they are missing
527 * the full cycles and can't be used later we skip interpretation here already.
528 */
529 if (type <= 1137 && (type % 10) >= 4 && (type % 10) <= 7) {
530 int sigmask, numsat = 0, numsig = 0;
531 uint64_t satmask, cellmask, ui;
532 // satellite data
533 double rrmod[RTCM3_MSM_NUMSAT]; // GNSS sat rough ranges modulo 1 millisecond
534 int rrint[RTCM3_MSM_NUMSAT]; // number of integer msecs in GNSS sat rough ranges
535 int rdop[RTCM3_MSM_NUMSAT]; // GNSS sat rough phase range rates
536 int extsat[RTCM3_MSM_NUMSAT];// extended sat info
537 // signal data
538 int ll[RTCM3_MSM_NUMCELLS]; // lock time indicator
539 /*int hc[RTCM3_MSM_NUMCELLS];*/ // half cycle ambiguity indicator
540 double cnr[RTCM3_MSM_NUMCELLS]; // signal cnr
541 double cp[RTCM3_MSM_NUMCELLS]; // fine phase range data
542 double psr[RTCM3_MSM_NUMCELLS]; // fine psr
543 double dop[RTCM3_MSM_NUMCELLS]; // fine phase range rates
544
545 SKIPBITS(3 + 7 + 2 + 2 + 1 + 3)
546 GETBITS64(satmask, RTCM3_MSM_NUMSAT)
547
548 /* http://gurmeetsingh.wordpress.com/2008/08/05/fast-bit-counting-routines/ */
549 for (ui = satmask; ui; ui &= (ui - 1) /* remove rightmost bit */)
550 ++numsat;
551 GETBITS(sigmask, RTCM3_MSM_NUMSIG)
552 for (i = sigmask; i; i &= (i - 1) /* remove rightmost bit */)
553 ++numsig;
554 for (i = 0; i < RTCM3_MSM_NUMSAT; ++i)
555 extsat[i] = 15;
556
557 i = numsat * numsig;
558 GETBITS64(cellmask, (unsigned )i)
559 // satellite data
560 switch (type % 10) {
561 case 1:
562 case 2:
563 case 3:
564 /* partial data, already skipped above, but implemented for future expansion ! */
565 for (int j = numsat; j--;)
566 GETFLOAT(rrmod[j], 10, 1.0 / 1024.0)
567 break;
568 case 4:
569 case 6:
570 for (int j = numsat; j--;)
571 GETBITS(rrint[j], 8)
572 for (int j = numsat; j--;)
573 GETFLOAT(rrmod[j], 10, 1.0 / 1024.0)
574 break;
575 case 5:
576 case 7:
577 for (int j = numsat; j--;)
578 GETBITS(rrint[j], 8)
579 for (int j = numsat; j--;)
580 GETBITS(extsat[j], 4)
581 for (int j = numsat; j--;)
582 GETFLOAT(rrmod[j], 10, 1.0 / 1024.0)
583 for (int j = numsat; j--;)
584 GETBITSSIGN(rdop[j], 14)
585 break;
586 }
587 // signal data
588 int numcells = numsat * numsig;
589 /** Drop anything which exceeds our cell limit. Increase limit definition
590 * when that happens. */
591 if (numcells <= RTCM3_MSM_NUMCELLS) {
592 switch (type % 10) {
593 case 1:
594 for (int count = numcells; count--;)
595 if (cellmask & (UINT64(1) << count))
596 GETFLOATSIGN(psr[count], 15, 1.0 / (1 << 24))
597 break;
598 case 2:
599 for (int count = numcells; count--;)
600 if (cellmask & (UINT64(1) << count))
601 GETFLOATSIGN(cp[count], 22, 1.0 / (1 << 29))
602 for (int count = numcells; count--;)
603 if (cellmask & (UINT64(1) << count))
604 GETBITS(ll[count], 4)
605 for (int count = numcells; count--;)
606 if (cellmask & (UINT64(1) << count))
607 SKIPBITS(1)/*GETBITS(hc[count], 1)*/
608 break;
609 case 3:
610 for (int count = numcells; count--;)
611 if (cellmask & (UINT64(1) << count))
612 GETFLOATSIGN(psr[count], 15, 1.0 / (1 << 24))
613 for (int count = numcells; count--;)
614 if (cellmask & (UINT64(1) << count))
615 GETFLOATSIGN(cp[count], 22, 1.0 / (1 << 29))
616 for (int count = numcells; count--;)
617 if (cellmask & (UINT64(1) << count))
618 GETBITS(ll[count], 4)
619 for (int count = numcells; count--;)
620 if (cellmask & (UINT64(1) << count))
621 SKIPBITS(1)/*GETBITS(hc[count], 1)*/
622 break;
623 case 4:
624 for (int count = numcells; count--;)
625 if (cellmask & (UINT64(1) << count))
626 GETFLOATSIGN(psr[count], 15, 1.0 / (1 << 24))
627 for (int count = numcells; count--;)
628 if (cellmask & (UINT64(1) << count))
629 GETFLOATSIGN(cp[count], 22, 1.0 / (1 << 29))
630 for (int count = numcells; count--;)
631 if (cellmask & (UINT64(1) << count))
632 GETBITS(ll[count], 4)
633 for (int count = numcells; count--;)
634 if (cellmask & (UINT64(1) << count))
635 SKIPBITS(1)/*GETBITS(hc[count], 1)*/
636 for (int count = numcells; count--;)
637 if (cellmask & (UINT64(1) << count))
638 GETBITS(cnr[count], 6)
639 break;
640 case 5:
641 for (int count = numcells; count--;)
642 if (cellmask & (UINT64(1) << count))
643 GETFLOATSIGN(psr[count], 15, 1.0 / (1 << 24))
644 for (int count = numcells; count--;)
645 if (cellmask & (UINT64(1) << count))
646 GETFLOATSIGN(cp[count], 22, 1.0 / (1 << 29))
647 for (int count = numcells; count--;)
648 if (cellmask & (UINT64(1) << count))
649 GETBITS(ll[count], 4)
650 for (int count = numcells; count--;)
651 if (cellmask & (UINT64(1) << count))
652 SKIPBITS(1)/*GETBITS(hc[count], 1)*/
653 for (int count = numcells; count--;)
654 if (cellmask & (UINT64(1) << count))
655 GETFLOAT(cnr[count], 6, 1.0)
656 for (int count = numcells; count--;)
657 if (cellmask & (UINT64(1) << count))
658 GETFLOATSIGN(dop[count], 15, 0.0001)
659 break;
660 case 6:
661 for (int count = numcells; count--;)
662 if (cellmask & (UINT64(1) << count))
663 GETFLOATSIGN(psr[count], 20, 1.0 / (1 << 29))
664 for (int count = numcells; count--;)
665 if (cellmask & (UINT64(1) << count))
666 GETFLOATSIGN(cp[count], 24, 1.0 / (1U << 31))
667 for (int count = numcells; count--;)
668 if (cellmask & (UINT64(1) << count))
669 GETBITS(ll[count], 10)
670 for (int count = numcells; count--;)
671 if (cellmask & (UINT64(1) << count))
672 SKIPBITS(1)/*GETBITS(hc[count], 1)*/
673 for (int count = numcells; count--;)
674 if (cellmask & (UINT64(1) << count))
675 GETFLOAT(cnr[count], 10, 1.0 / (1 << 4))
676 break;
677 case 7:
678 for (int count = numcells; count--;)
679 if (cellmask & (UINT64(1) << count))
680 GETFLOATSIGN(psr[count], 20, 1.0 / (1 << 29))
681 for (int count = numcells; count--;)
682 if (cellmask & (UINT64(1) << count))
683 GETFLOATSIGN(cp[count], 24, 1.0 / (1U << 31))
684 for (int count = numcells; count--;)
685 if (cellmask & (UINT64(1) << count))
686 GETBITS(ll[count], 10)
687 for (int count = numcells; count--;)
688 if (cellmask & (UINT64(1) << count))
689 SKIPBITS(1)/*GETBITS(hc[count], 1)*/
690 for (int count = numcells; count--;)
691 if (cellmask & (UINT64(1) << count))
692 GETFLOAT(cnr[count], 10, 1.0 / (1 << 4))
693 for (int count = numcells; count--;)
694 if (cellmask & (UINT64(1) << count))
695 GETFLOATSIGN(dop[count], 15, 0.0001)
696 break;
697 }
698 i = RTCM3_MSM_NUMSAT;
699 int j = -1;
700 t_satObs CurrentObs;
701 for (int count = numcells; count--;) {
702 while (j >= 0 && !(sigmask & (1 << --j)))
703 ;
704 if (j < 0) {
705 while (!(satmask & (UINT64(1) << (--i))))
706 /* next satellite */
707 ;
708 if (CurrentObs._obs.size() > 0)
709 _CurrentObsList.push_back(CurrentObs);
710 CurrentObs.clear();
711 CurrentObs._time = CurrentObsTime;
712 CurrentObs._type = type;
713 if (sys == 'S')
714 CurrentObs._prn.set(sys, 20 - 1 + RTCM3_MSM_NUMSAT - i);
715 else
716 CurrentObs._prn.set(sys, RTCM3_MSM_NUMSAT - i);
717 j = RTCM3_MSM_NUMSIG;
718 while (!(sigmask & (1 << --j)))
719 ;
720 --numsat;
721 }
722 if (cellmask & (UINT64(1) << count)) {
723 struct CodeData cd = {0.0, 0};
724 switch (sys) {
725 case 'J':
726 cd = qzss[RTCM3_MSM_NUMSIG - j - 1];
727 break;
728 case 'C':
729 cd = bds[RTCM3_MSM_NUMSIG - j - 1];
730 break;
731 case 'G':
732 case 'S':
733 cd = gps[RTCM3_MSM_NUMSIG - j - 1];
734 break;
735 case 'R':
736 cd = glo[RTCM3_MSM_NUMSIG - j - 1];
737 {
738 int k = GLOFreq[RTCM3_MSM_NUMSAT - i - 1];
739 if (extsat[numsat] < 14) { // channel number is available as extended info for MSM5/7
740 k = GLOFreq[RTCM3_MSM_NUMSAT - i - 1] = 100 + extsat[numsat] - 7;
741 }
742 if (k) {
743 if (cd.wl == 0.0) {
744 cd.wl = GLO_WAVELENGTH_L1(k - 100);
745 }
746 else if (cd.wl == 1.0) {
747 cd.wl = GLO_WAVELENGTH_L2(k - 100);
748 }
749 }
750 else if (!k && cd.wl <= 1) {
751 cd.code = 0;
752 }
753 }
754 break;
755 case 'E':
756 cd = gal[RTCM3_MSM_NUMSIG - j - 1];
757 break;
758 case 'I':
759 cd = irn[RTCM3_MSM_NUMSIG - j - 1];
760 break;
761 }
762 if (cd.code) {
763 t_frqObs *frqObs = new t_frqObs;
764 frqObs->_rnxType2ch.assign(cd.code);
765
766 switch (type % 10) {
767 case 1:
768 if (psr[count] > -1.0 / (1 << 10)) {
769 frqObs->_code = psr[count] * LIGHTSPEED / 1000.0
770 + (rrmod[numsat]) * LIGHTSPEED / 1000.0;
771 frqObs->_codeValid = true;
772 }
773 break;
774 case 2:
775 if (cp[count] > -1.0 / (1 << 8)) {
776 frqObs->_phase = cp[count] * LIGHTSPEED / 1000.0 / cd.wl
777 + (rrmod[numsat]) * LIGHTSPEED / 1000.0 / cd.wl;
778 frqObs->_phaseValid = true;
779 frqObs->_lockTime = lti2sec(type,ll[count]);
780 frqObs->_lockTimeValid = (frqObs->_lockTime >= 0.0);
781 frqObs->_lockTimeIndicator = ll[count];
782 }
783 break;
784 case 3:
785 if (psr[count] > -1.0 / (1 << 10)) {
786 frqObs->_code = psr[count] * LIGHTSPEED / 1000.0
787 + (rrmod[numsat]) * LIGHTSPEED / 1000.0;
788 frqObs->_codeValid = true;
789 }
790 if (cp[count] > -1.0 / (1 << 8)) {
791 frqObs->_phase = cp[count] * LIGHTSPEED / 1000.0 / cd.wl
792 + rrmod[numsat] * LIGHTSPEED / 1000.0 / cd.wl;
793 frqObs->_phaseValid = true;
794 frqObs->_lockTime = lti2sec(type,ll[count]);
795 frqObs->_lockTimeValid = (frqObs->_lockTime >= 0.0);
796 frqObs->_lockTimeIndicator = ll[count];
797 }
798 break;
799 case 4:
800 if (psr[count] > -1.0 / (1 << 10)) {
801 frqObs->_code = psr[count] * LIGHTSPEED / 1000.0
802 + (rrmod[numsat] + rrint[numsat]) * LIGHTSPEED / 1000.0;
803 frqObs->_codeValid = true;
804 }
805 if (cp[count] > -1.0 / (1 << 8)) {
806 frqObs->_phase = cp[count] * LIGHTSPEED / 1000.0 / cd.wl
807 + (rrmod[numsat] + rrint[numsat]) * LIGHTSPEED / 1000.0 / cd.wl;
808 frqObs->_phaseValid = true;
809 frqObs->_lockTime = lti2sec(type,ll[count]);
810 frqObs->_lockTimeValid = (frqObs->_lockTime >= 0.0);
811 frqObs->_lockTimeIndicator = ll[count];
812 }
813 frqObs->_snr = cnr[count];
814 frqObs->_snrValid = true;
815 break;
816 case 5:
817 if (psr[count] > -1.0 / (1 << 10)) {
818 frqObs->_code = psr[count] * LIGHTSPEED / 1000.0
819 + (rrmod[numsat] + rrint[numsat]) * LIGHTSPEED / 1000.0;
820 frqObs->_codeValid = true;
821 }
822 if (cp[count] > -1.0 / (1 << 8)) {
823 frqObs->_phase = cp[count] * LIGHTSPEED / 1000.0 / cd.wl
824 + (rrmod[numsat] + rrint[numsat]) * LIGHTSPEED / 1000.0 / cd.wl;
825 frqObs->_phaseValid = true;
826 frqObs->_lockTime = lti2sec(type,ll[count]);
827 frqObs->_lockTimeValid = (frqObs->_lockTime >= 0.0);
828 frqObs->_lockTimeIndicator = ll[count];
829 }
830 frqObs->_snr = cnr[count];
831 frqObs->_snrValid = true;
832 if (dop[count] > -1.6384) {
833 frqObs->_doppler = -(dop[count] + rdop[numsat]) / cd.wl;
834 frqObs->_dopplerValid = true;
835 }
836 break;
837 case 6:
838 if (psr[count] > -1.0 / (1 << 10)) {
839 frqObs->_code = psr[count] * LIGHTSPEED / 1000.0
840 + (rrmod[numsat] + rrint[numsat]) * LIGHTSPEED / 1000.0;
841 frqObs->_codeValid = true;
842 }
843 if (cp[count] > -1.0 / (1 << 8)) {
844 frqObs->_phase = cp[count] * LIGHTSPEED / 1000.0 / cd.wl
845 + (rrmod[numsat] + rrint[numsat]) * LIGHTSPEED / 1000.0 / cd.wl;
846 frqObs->_phaseValid = true;
847 frqObs->_lockTime = lti2sec(type,ll[count]);
848 frqObs->_lockTimeValid = (frqObs->_lockTime >= 0.0);
849 frqObs->_lockTimeIndicator = ll[count];
850 }
851
852 frqObs->_snr = cnr[count];
853 frqObs->_snrValid = true;
854 break;
855 case 7:
856 if (psr[count] > -1.0 / (1 << 10)) {
857 frqObs->_code = psr[count] * LIGHTSPEED / 1000.0
858 + (rrmod[numsat] + rrint[numsat]) * LIGHTSPEED / 1000.0;
859 frqObs->_codeValid = true;
860 }
861 if (cp[count] > -1.0 / (1 << 8)) {
862 frqObs->_phase = cp[count] * LIGHTSPEED / 1000.0 / cd.wl
863 + (rrmod[numsat] + rrint[numsat]) * LIGHTSPEED / 1000.0 / cd.wl;
864 frqObs->_phaseValid = true;
865 frqObs->_lockTime = lti2sec(type,ll[count]);
866 frqObs->_lockTimeValid = (frqObs->_lockTime >= 0.0);
867 frqObs->_lockTimeIndicator = ll[count];
868 }
869
870 frqObs->_snr = cnr[count];
871 frqObs->_snrValid = true;
872
873 if (dop[count] > -1.6384) {
874 frqObs->_doppler = -(dop[count] + rdop[numsat]) / cd.wl;
875 frqObs->_dopplerValid = true;
876 }
877 break;
878 }
879 CurrentObs._obs.push_back(frqObs);
880 }
881 }
882 }
883 if (CurrentObs._obs.size() > 0) {
884 _CurrentObsList.push_back(CurrentObs);
885 }
886 }
887 }
888 else if ((type % 10) < 4) {
889#ifdef BNC_DEBUG_OBS
890 emit(newMessage(QString("%1: Block %2 contain partial data! Ignored!")
891 .arg(_staID).arg(type).toLatin1(), true));
892#endif
893 }
894 if (!syncf) {
895 decoded = true;
896 _obsList.append(_CurrentObsList);
897 _CurrentTime.reset();
898 _CurrentObsList.clear();
899 }
900 return decoded;
901}
902
903//
904////////////////////////////////////////////////////////////////////////////
905bool RTCM3Decoder::DecodeRTCM3GLONASS(unsigned char* data, int size) {
906 bool decoded = false;
907 bncTime CurrentObsTime;
908 int i, numsats, syncf, type;
909 uint64_t numbits = 0, bitfield = 0;
910
911 data += 3; /* header */
912 size -= 6; /* header + crc */
913
914 GETBITS(type, 12)
915 SKIPBITS(12)
916 /* id */
917 GETBITS(i, 27)
918 /* tk */
919
920 CurrentObsTime.setTk(i);
921 if (_CurrentTime.valid() && CurrentObsTime != _CurrentTime) {
922 decoded = true;
923 _obsList.append(_CurrentObsList);
924 _CurrentObsList.clear();
925 }
926 _CurrentTime = CurrentObsTime;
927
928 GETBITS(syncf, 1)
929 /* sync */
930 GETBITS(numsats, 5)
931 SKIPBITS(4)
932 /* smind, smint */
933
934 while (numsats--) {
935 int sv, code, l1range, amb = 0, freq;
936 t_satObs CurrentObs;
937 CurrentObs._time = CurrentObsTime;
938 CurrentObs._type = type;
939
940 GETBITS(sv, 6)
941 CurrentObs._prn.set('R', sv);
942 GETBITS(code, 1)
943 GETBITS(freq, 5)
944 GLOFreq[sv - 1] = 100 + freq - 7; /* store frequency for other users (MSM) */
945
946 t_frqObs *frqObs = new t_frqObs;
947 /* L1 */
948 (code) ?
949 frqObs->_rnxType2ch.assign("1P") : frqObs->_rnxType2ch.assign("1C");
950 GETBITS(l1range, 25);
951 GETBITSSIGN(i, 20);
952 if ((i & ((1 << 20) - 1)) != 0x80000) {
953 frqObs->_code = l1range * 0.02;
954 frqObs->_phase = (l1range * 0.02 + i * 0.0005) / GLO_WAVELENGTH_L1(freq - 7);
955 frqObs->_codeValid = frqObs->_phaseValid = true;
956 }
957 GETBITS(frqObs->_lockTimeIndicator, 7);
958 frqObs->_lockTime = lti2sec(type, frqObs->_lockTimeIndicator);
959 frqObs->_lockTimeValid = (frqObs->_lockTime >= 0.0 && frqObs->_phaseValid);
960 if (type == 1010 || type == 1012) {
961 GETBITS(amb, 7);
962 if (amb) {
963 frqObs->_code += amb * 599584.916;
964 frqObs->_phase += (amb * 599584.916) / GLO_WAVELENGTH_L1(freq - 7);
965 }
966 GETBITS(i, 8);
967 if (i) {
968 frqObs->_snr = i * 0.25;
969 frqObs->_snrValid = true;
970 }
971 }
972 CurrentObs._obs.push_back(frqObs);
973 if (type == 1011 || type == 1012) {
974 frqObs = new t_frqObs;
975 /* L2 */
976 GETBITS(code, 2);
977 switch (code) {
978 case 3:
979 frqObs->_rnxType2ch.assign("2P");
980 break;
981 case 2:
982 frqObs->_rnxType2ch.assign("2P");
983 break;
984 case 1:
985 frqObs->_rnxType2ch.assign("2P");
986 break;
987 case 0:
988 frqObs->_rnxType2ch.assign("2C");
989 break;
990 }
991 GETBITSSIGN(i, 14);
992 if ((i & ((1 << 14) - 1)) != 0x2000) {
993 frqObs->_code = l1range * 0.02 + i * 0.02 + amb * 599584.916;
994 frqObs->_codeValid = true;
995 }
996 GETBITSSIGN(i, 20);
997 if ((i & ((1 << 20) - 1)) != 0x80000) {
998 frqObs->_phase = (l1range * 0.02 + i * 0.0005 + amb * 599584.916)
999 / GLO_WAVELENGTH_L2(freq - 7);
1000 frqObs->_phaseValid = true;
1001 }
1002 GETBITS(frqObs->_lockTimeIndicator, 7);
1003 frqObs->_lockTime = lti2sec(type, frqObs->_lockTimeIndicator);
1004 frqObs->_lockTimeValid = (frqObs->_lockTime >= 0.0 && frqObs->_phaseValid);
1005 if (type == 1012) {
1006 GETBITS(i, 8);
1007 if (i) {
1008 frqObs->_snr = i * 0.25;
1009 frqObs->_snrValid = true;
1010 }
1011 }
1012 CurrentObs._obs.push_back(frqObs);
1013 }
1014 _CurrentObsList.push_back(CurrentObs);
1015 }
1016 if (!syncf) {
1017 decoded = true;
1018 _obsList.append(_CurrentObsList);
1019 _CurrentTime.reset();
1020 _CurrentObsList.clear();
1021 }
1022 return decoded;
1023}
1024
1025//
1026////////////////////////////////////////////////////////////////////////////
1027bool RTCM3Decoder::DecodeGPSEphemeris(unsigned char* data, int size) {
1028 bool decoded = false;
1029
1030 if (size == 67) {
1031 t_ephGPS eph;
1032 int i, week;
1033 uint64_t numbits = 0, bitfield = 0;
1034 int fitIntervalFalg = 0;
1035
1036 data += 3; /* header */
1037 size -= 6; /* header + crc */
1038 SKIPBITS(12)
1039
1040 eph._receptDateTime = currentDateAndTimeGPS();
1041 eph._receptStaID = _staID;
1042
1043 GETBITS(i, 6)
1044 if (i < 1 || i > 63 ) {
1045#ifdef BNC_DEBUG_BCE
1046 emit(newMessage(QString("%1: Block %2 (G) PRN# is out of range: %3!")
1047 .arg(_staID)
1048 .arg(1019,4)
1049 .arg(i).toLatin1(), true));
1050#endif
1051 return false;
1052 }
1053 eph._prn.set('G', i);
1054 GETBITS(week, 10)
1055 if (week < 0 || week > 1023) {
1056#ifdef BNC_DEBUG_BCE
1057 emit(newMessage(QString("%1: Block %2 (%3) WEEK # is out of range: %4!")
1058 .arg(_staID)
1059 .arg(1019,4)
1060 .arg(eph._prn.toString().c_str())
1061 .arg(week).toLatin1(), true));
1062#endif
1063 return false;
1064 }
1065 GETBITS(i, 4)
1066 eph._ura = accuracyFromIndex(i, eph.type());
1067 GETBITS(eph._L2Codes, 2)
1068 GETFLOATSIGN(eph._IDOT, 14, R2R_PI/(double)(1<<30)/(double)(1<<13))
1069 GETBITS(eph._IODE, 8)
1070 GETBITS(i, 16)
1071 i <<= 4;
1072 if (i < 0 || i > 604784) {
1073#ifdef BNC_DEBUG_BCE
1074 emit(newMessage(QString("%1: Block %2 (%3) TOC is out of range: %4!")
1075 .arg(_staID)
1076 .arg(1019,4)
1077 .arg(eph._prn.toString().c_str())
1078 .arg(i).toLatin1(), true));
1079#endif
1080 return false;
1081 }
1082 eph._TOC.set(i * 1000);
1083 GETFLOATSIGN(eph._clock_driftrate, 8, 1.0 / (double )(1 << 30) / (double )(1 << 25))
1084 GETFLOATSIGN(eph._clock_drift, 16, 1.0 / (double )(1 << 30) / (double )(1 << 13))
1085 GETFLOATSIGN(eph._clock_bias, 22, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1086 GETBITS(eph._IODC, 10)
1087 GETFLOATSIGN(eph._Crs, 16, 1.0 / (double )(1 << 5))
1088 GETFLOATSIGN(eph._Delta_n, 16, R2R_PI/(double)(1<<30)/(double)(1<<13))
1089 GETFLOATSIGN(eph._M0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1090 GETFLOATSIGN(eph._Cuc, 16, 1.0 / (double )(1 << 29))
1091 GETFLOAT(eph._e, 32, 1.0 / (double )(1 << 30) / (double )(1 << 3))
1092 GETFLOATSIGN(eph._Cus, 16, 1.0 / (double )(1 << 29))
1093 GETFLOAT(eph._sqrt_A, 32, 1.0 / (double )(1 << 19))
1094 if (eph._sqrt_A < 1000.0) {
1095#ifdef BNC_DEBUG_BCE
1096 emit(newMessage(QString("%1: Block %2 (%3) SQRT_A %4 m!")
1097 .arg(_staID).arg(1019,4).arg(eph._prn.toString().c_str())
1098 .arg(eph._sqrt_A,10,'F',3).toLatin1(), true));
1099#endif
1100 return false;
1101 }
1102 GETBITS(i, 16)
1103 i <<= 4;
1104 if (i < 0 || i > 604784) {
1105#ifdef BNC_DEBUG_BCE
1106 emit(newMessage(QString("%1: Block %2 (%3) TOE is out of range: %4!")
1107 .arg(_staID)
1108 .arg(1019,4)
1109 .arg(eph._prn.toString().c_str())
1110 .arg(i).toLatin1(), true));
1111#endif
1112 return false;
1113 }
1114 eph._TOEsec = i;
1115 bncTime t;
1116 t.set(i * 1000);
1117 eph._TOEweek = t.gpsw();
1118 int numOfRollOvers = int(floor(t.gpsw()/1024.0));
1119 week += (numOfRollOvers * 1024);
1120 /* week from HOW, differs from TOC, TOE week, we use adapted value instead */
1121 if (eph._TOEweek > week + 1 || eph._TOEweek < week - 1) /* invalid week */
1122 return false;
1123 GETFLOATSIGN(eph._Cic, 16, 1.0 / (double )(1 << 29))
1124 GETFLOATSIGN(eph._OMEGA0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1125 GETFLOATSIGN(eph._Cis, 16, 1.0 / (double )(1 << 29))
1126 GETFLOATSIGN(eph._i0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1127 GETFLOATSIGN(eph._Crc, 16, 1.0 / (double )(1 << 5))
1128 GETFLOATSIGN(eph._omega, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1129 GETFLOATSIGN(eph._OMEGADOT, 24, R2R_PI/(double)(1<<30)/(double)(1<<13))
1130 GETFLOATSIGN(eph._TGD, 8, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1131 GETBITS(eph._health, 6)
1132 GETBITS(eph._L2PFlag, 1)
1133 GETBITS(fitIntervalFalg, 1)
1134 eph._fitInterval = fitIntervalFromFlag(fitIntervalFalg, eph._IODC, eph.type());
1135 eph._TOT = 0.9999e9;
1136 eph._navType = t_eph::LNAV;
1137
1138 emit newGPSEph(eph);
1139 decoded = true;
1140 }
1141 return decoded;
1142}
1143
1144//
1145////////////////////////////////////////////////////////////////////////////
1146bool RTCM3Decoder::DecodeGLONASSEphemeris(unsigned char* data, int size) {
1147 bool decoded = false;
1148
1149 if (size == 51) {
1150 t_ephGlo eph;
1151 int sv, i, tk;
1152 uint64_t numbits = 0, bitfield = 0;
1153
1154 data += 3; /* header */
1155 size -= 6; /* header + crc */
1156 SKIPBITS(12)
1157
1158 eph._receptDateTime = currentDateAndTimeGPS();
1159 eph._receptStaID = _staID;
1160
1161 eph._flags_unknown = true;
1162
1163 GETBITS(sv, 6)
1164 if (sv < 1 || sv > 63) {
1165#ifdef BNC_DEBUG_BCE
1166 emit(newMessage(QString("%1: Block %2 (R): SLOT# is unknown (0) or out of range: %3!")
1167 .arg(_staID)
1168 .arg(1020,4)
1169 .arg(sv).toLatin1(), true));
1170#endif
1171 return false;
1172 }
1173 eph._prn.set('R', sv);
1174
1175 GETBITS(i, 5)
1176 if (i < 0 || i > 20) {
1177#ifdef BNC_DEBUG_BCE
1178 emit(newMessage(QString("%1: Block %2 (%3): FRQ CHN# is out of range: %4")
1179 .arg(_staID)
1180 .arg(1020,4)
1181 .arg(eph._prn.toString().c_str())
1182 .arg(i).toLatin1(), true));
1183#endif
1184 return false;
1185 }
1186 eph._frequency_number = i - 7;
1187 GETBITS(eph._almanac_health, 1) /* almanac healthy */
1188 GETBITS(eph._almanac_health_availablility_indicator, 1) /* almanac health ok */
1189 GETBITS(eph._P1, 2) /* P1 */
1190 GETBITS(i, 5)
1191 if (i < 0 || i > 23) {
1192#ifdef BNC_DEBUG_BCE
1193 emit(newMessage(QString("%1: Block %2 (%3): T_k (bits 11-7) is out of range: %4")
1194 .arg(_staID)
1195 .arg(1020,4)
1196 .arg(eph._prn.toString().c_str())
1197 .arg(i).toLatin1(), true));
1198#endif
1199 return false;
1200 }
1201 tk = i * 60 * 60;
1202 GETBITS(i, 6)
1203 if (i < 0 || i > 59) {
1204#ifdef BNC_DEBUG_BCE
1205 emit(newMessage(QString("%1: Block %2 (%3): T_k (bits 6-1) is out of range: %4")
1206 .arg(_staID)
1207 .arg(1020,4)
1208 .arg(eph._prn.toString().c_str())
1209 .arg(i).toLatin1(), true));
1210#endif
1211 return false;
1212 }
1213 tk += i * 60;
1214 GETBITS(i, 1)
1215 if (i < 0 || i > 1) {
1216#ifdef BNC_DEBUG_BCE
1217 emit(newMessage(QString("%1: Block %2 (%3): T_k (bit 0) is out of range: %4")
1218 .arg(_staID)
1219 .arg(1020,4)
1220 .arg(eph._prn.toString().c_str())
1221 .arg(i).toLatin1(), true));
1222#endif
1223 return false;
1224 }
1225 tk += i * 30;
1226 eph._tki = tk - 3*60*60;
1227 if(eph._tki < 0.0) {
1228 eph._tki += 86400.0;
1229 }
1230 GETBITS(eph._health, 1) /* MSB of Bn*/
1231 GETBITS(eph._P2, 1) /* P2 */
1232 GETBITS(i, 7)
1233 i *= 15;
1234 if (i < 15 || i > 1425) {
1235#ifdef BNC_DEBUG_BCE
1236 emit(newMessage(QString("%1: Block %2 (%3): T_b is out of range: %4")
1237 .arg(_staID)
1238 .arg(1020,4)
1239 .arg(eph._prn.toString().c_str())
1240 .arg(i).toLatin1(), true));
1241#endif
1242 return false;
1243 }
1244 eph._TOC.setTk(i * 60 * 1000); /* tb */
1245
1246 GETFLOATSIGNM(eph._x_velocity, 24, 1.0 / (double )(1 << 20))
1247 GETFLOATSIGNM(eph._x_pos, 27, 1.0 / (double )(1 << 11))
1248 GETFLOATSIGNM(eph._x_acceleration, 5, 1.0 / (double )(1 << 30))
1249 GETFLOATSIGNM(eph._y_velocity, 24, 1.0 / (double )(1 << 20))
1250 GETFLOATSIGNM(eph._y_pos, 27, 1.0 / (double )(1 << 11))
1251 GETFLOATSIGNM(eph._y_acceleration, 5, 1.0 / (double )(1 << 30))
1252 GETFLOATSIGNM(eph._z_velocity, 24, 1.0 / (double )(1 << 20))
1253 GETFLOATSIGNM(eph._z_pos, 27, 1.0 / (double )(1 << 11))
1254 GETFLOATSIGNM(eph._z_acceleration, 5, 1.0 / (double )(1 << 30))
1255 GETBITS(eph._P3, 1) /* P3 */
1256 GETFLOATSIGNM(eph._gamma, 11, 1.0 / (double )(1 << 30) / (double )(1 << 10))
1257 GETBITS(eph._M_P, 2) /* GLONASS-M P, */
1258 GETBITS(eph._M_l3, 1) /* GLONASS-M ln (third string) */
1259 GETFLOATSIGNM(eph._tau, 22, 1.0 / (double )(1 << 30)) /* GLONASS tau n(tb) */
1260 GETFLOATSIGNM(eph._M_delta_tau, 5, 1.0 / (double )(1 << 30)) /* GLONASS-M delta tau n(tb) */
1261 GETBITS(eph._E, 5)
1262 GETBITS(eph._M_P4, 1) /* GLONASS-M P4 */
1263 GETBITS(eph._M_FT, 4) /* GLONASS-M Ft */
1264 GETBITS(eph._M_NT, 11) /* GLONASS-M Nt */
1265 if (eph._M_NT == 0.0) {
1266#ifdef BNC_DEBUG_BCE
1267 emit(newMessage(QString("%1: Block %2 (%3): NT = %4: missing data!")
1268 .arg(_staID).arg(1020,4).arg(eph._prn.toString().c_str()).arg(eph._M_NT,4).toLatin1(), true));
1269#endif
1270 return false;
1271 }
1272 GETBITS(eph._M_M, 2) /* GLONASS-M M */
1273 GETBITS(eph._additional_data_availability, 1) /* GLONASS-M The Availability of Additional Data */
1274 if (eph._additional_data_availability == 0.0) {
1275#ifdef BNC_DEBUG_BCE
1276 emit(newMessage(QString("%1: Block %2 (%3): ADD = %4: missing data!")
1277 .arg(_staID).arg(1020,4).arg(eph._prn.toString().c_str())
1278 .arg(eph._additional_data_availability).toLatin1(), true));
1279#endif
1280 return false;
1281 }
1282 GETBITS(eph._NA, 11) /* GLONASS-M Na */
1283 GETFLOATSIGNM(eph._tauC, 32, 1.0/(double)(1<<30)/(double)(1<<1)) /* GLONASS tau c */
1284 GETBITS(eph._M_N4, 5) /* GLONASS-M N4 */
1285 GETFLOATSIGNM(eph._M_tau_GPS, 22, 1.0/(double)(1<<30)) /* GLONASS-M tau GPS */
1286 GETBITS(eph._M_l5, 1) /* GLONASS-M ln (fifth string) */
1287
1288 unsigned year, month, day;
1289 eph._TOC.civil_date(year, month, day);
1290 eph._gps_utc = gnumleap(year, month, day);
1291 eph._tt = eph._TOC;
1292
1293 eph._xv(1) = eph._x_pos * 1.e3;
1294 eph._xv(2) = eph._y_pos * 1.e3;
1295 eph._xv(3) = eph._z_pos * 1.e3;
1296 if (eph._xv.Rows(1,3).NormFrobenius() < 1.0) {
1297#ifdef BNC_DEBUG_BCE
1298 emit(newMessage(QString("%1: Block %2 (%3): zero position!")
1299 .arg(_staID).arg(1020,4).arg(eph._prn.toString().c_str()).toLatin1(), true));
1300#endif
1301 return false;
1302 }
1303 eph._xv(4) = eph._x_velocity * 1.e3;
1304 eph._xv(5) = eph._y_velocity * 1.e3;
1305 eph._xv(6) = eph._z_velocity * 1.e3;
1306 if (eph._xv.Rows(4,6).NormFrobenius() < 1.0) {
1307#ifdef BNC_DEBUG_BCE
1308 emit(newMessage(QString("%1: Block %2 (%3): zero velocity!")
1309 .arg(_staID).arg(1020,4).arg(eph._prn.toString().c_str()).toLatin1(), true));
1310#endif
1311 return false;
1312 }
1313 GLOFreq[sv - 1] = 100 + eph._frequency_number ; /* store frequency for other users (MSM) */
1314 _gloFrq = QString("%1 %2").arg(eph._prn.toString().c_str()).arg(eph._frequency_number, 2, 'f', 0);
1315
1316 eph._navType = t_eph::FDMA;
1317
1318 emit newGlonassEph(eph);
1319 decoded = true;
1320 }
1321 return decoded;
1322}
1323
1324//
1325////////////////////////////////////////////////////////////////////////////
1326bool RTCM3Decoder::DecodeQZSSEphemeris(unsigned char* data, int size) {
1327 bool decoded = false;
1328
1329 if (size == 67) {
1330 t_ephGPS eph;
1331 int i, week;
1332 uint64_t numbits = 0, bitfield = 0;
1333 int fitIntervalFalg = 0;
1334
1335 data += 3; /* header */
1336 size -= 6; /* header + crc */
1337 SKIPBITS(12)
1338
1339 eph._receptDateTime = currentDateAndTimeGPS();
1340 eph._receptStaID = _staID;
1341
1342 GETBITS(i, 4)
1343 if (i < 1 || i > 10 ) {
1344#ifdef BNC_DEBUG_BCE
1345 emit(newMessage(QString("%1: Block %2 (J) SAT ID is out of range: %3!")
1346 .arg(_staID)
1347 .arg(1044,4)
1348 .arg(i).toLatin1(), true));
1349#endif
1350 return false;
1351 }
1352 eph._prn.set('J', i);
1353
1354 GETBITS(i, 16)
1355 i <<= 4;
1356 if (i < 0 || i > 604784) {
1357#ifdef BNC_DEBUG_BCE
1358 emit(newMessage(QString("%1: Block %2 (%3) TOC is out of range: %4!")
1359 .arg(_staID)
1360 .arg(1044,4)
1361 .arg(eph._prn.toString().c_str())
1362 .arg(i).toLatin1(), true));
1363#endif
1364 return false;
1365 }
1366 eph._TOC.set(i * 1000);
1367
1368 GETFLOATSIGN(eph._clock_driftrate, 8, 1.0 / (double )(1 << 30) / (double )(1 << 25))
1369 GETFLOATSIGN(eph._clock_drift, 16, 1.0 / (double )(1 << 30) / (double )(1 << 13))
1370 GETFLOATSIGN(eph._clock_bias, 22, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1371 GETBITS(eph._IODE, 8)
1372 GETFLOATSIGN(eph._Crs, 16, 1.0 / (double )(1 << 5))
1373 GETFLOATSIGN(eph._Delta_n, 16, R2R_PI/(double)(1<<30)/(double)(1<<13))
1374 GETFLOATSIGN(eph._M0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1375 GETFLOATSIGN(eph._Cuc, 16, 1.0 / (double )(1 << 29))
1376 GETFLOAT(eph._e, 32, 1.0 / (double )(1 << 30) / (double )(1 << 3))
1377 GETFLOATSIGN(eph._Cus, 16, 1.0 / (double )(1 << 29))
1378 GETFLOAT(eph._sqrt_A, 32, 1.0 / (double )(1 << 19))
1379 if (eph._sqrt_A < 1000.0) {
1380#ifdef BNC_DEBUG_BCE
1381 emit(newMessage(QString("%1: Block %2 (%3) SQRT_A %4 m!")
1382 .arg(_staID).arg(1044,4).arg(eph._prn.toString().c_str())
1383 .arg(eph._sqrt_A,10,'F',3).toLatin1(), true));
1384#endif
1385 return false;
1386 }
1387 GETBITS(i, 16)
1388 i <<= 4;
1389 if (i < 0 || i > 604784) {
1390#ifdef BNC_DEBUG_BCE
1391 emit(newMessage(QString("%1: Block %2 (%3) TOE is out of range: %4!")
1392 .arg(_staID)
1393 .arg(1044,4)
1394 .arg(eph._prn.toString().c_str())
1395 .arg(i).toLatin1(), true));
1396#endif
1397 return false;
1398 }
1399 eph._TOEsec = i;
1400 bncTime t;
1401 t.set(i*1000);
1402 eph._TOEweek = t.gpsw();
1403 GETFLOATSIGN(eph._Cic, 16, 1.0 / (double )(1 << 29))
1404 GETFLOATSIGN(eph._OMEGA0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1405 GETFLOATSIGN(eph._Cis, 16, 1.0 / (double )(1 << 29))
1406 GETFLOATSIGN(eph._i0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1407 GETFLOATSIGN(eph._Crc, 16, 1.0 / (double )(1 << 5))
1408 GETFLOATSIGN(eph._omega, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1409 GETFLOATSIGN(eph._OMEGADOT, 24, R2R_PI/(double)(1<<30)/(double)(1<<13))
1410 GETFLOATSIGN(eph._IDOT, 14, R2R_PI/(double)(1<<30)/(double)(1<<13))
1411 GETBITS(eph._L2Codes, 2)
1412 GETBITS(week, 10)
1413 if (week < 0 || week > 1023) {
1414#ifdef BNC_DEBUG_BCE
1415 emit(newMessage(QString("%1: Block %2 (%3) WEEK # is out of range: %4!")
1416 .arg(_staID)
1417 .arg(1044,4)
1418 .arg(eph._prn.toString().c_str())
1419 .arg(week).toLatin1(), true));
1420#endif
1421 return false;
1422 }
1423 int numOfRollOvers = int(floor(t.gpsw()/1024.0));
1424 week += (numOfRollOvers * 1024);
1425 /* week from HOW, differs from TOC, TOE week, we use adapted value instead */
1426 if (eph._TOEweek > week + 1 || eph._TOEweek < week - 1) /* invalid week */
1427 return false;
1428
1429 GETBITS(i, 4)
1430 if (i <= 6)
1431 eph._ura = ceil(10.0 * pow(2.0, 1.0 + i / 2.0)) / 10.0;
1432 else
1433 eph._ura = ceil(10.0 * pow(2.0, i / 2.0)) / 10.0;
1434 GETBITS(eph._health, 6)
1435 GETFLOATSIGN(eph._TGD, 8, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1436 GETBITS(eph._IODC, 10)
1437 GETBITS(fitIntervalFalg, 1)
1438 eph._fitInterval = fitIntervalFromFlag(fitIntervalFalg, eph._IODC, eph.type());
1439 eph._TOT = 0.9999e9;
1440 eph._navType = t_eph::LNAV;
1441
1442 emit newGPSEph(eph);
1443 decoded = true;
1444 }
1445 return decoded;
1446}
1447
1448//
1449////////////////////////////////////////////////////////////////////////////
1450bool RTCM3Decoder::DecodeIRNSSEphemeris(unsigned char* data, int size) {
1451 bool decoded = false;
1452
1453 if (size == 67) {
1454 t_ephGPS eph;
1455 int i, week, L5Flag, SFlag;
1456 uint64_t numbits = 0, bitfield = 0;
1457
1458 data += 3; /* header */
1459 size -= 6; /* header + crc */
1460 SKIPBITS(12)
1461
1462 eph._receptDateTime = currentDateAndTimeGPS();
1463 eph._receptStaID = _staID;
1464
1465 GETBITS(i, 6)
1466 if (i < 1 || i > 63 ) {
1467#ifdef BNC_DEBUG_BCE
1468 emit(newMessage(QString("%1: Block %2 (I) PRN# is out of range: %3!")
1469 .arg(_staID)
1470 .arg(1041,4)
1471 .arg(i).toLatin1(), true));
1472#endif
1473 return false;
1474 }
1475 eph._prn.set('I', i);
1476 GETBITS(week, 10)
1477 if (week < 0 || week > 1023) {
1478#ifdef BNC_DEBUG_BCE
1479 emit(newMessage(QString("%1: Block %2 (%3) WEEK # is out of range: %4!")
1480 .arg(_staID)
1481 .arg(1041,4)
1482 .arg(eph._prn.toString().c_str())
1483 .arg(week).toLatin1(), true));
1484#endif
1485 return false;
1486 }
1487 GETFLOATSIGN(eph._clock_bias, 22, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1488 GETFLOATSIGN(eph._clock_drift, 16, 1.0 / (double )(1 << 30) / (double )(1 << 13))
1489 GETFLOATSIGN(eph._clock_driftrate, 8, 1.0 / (double )(1 << 30) / (double )(1 << 25))
1490 GETBITS(i, 4)
1491 eph._ura = accuracyFromIndex(i, eph.type());
1492 GETBITS(i, 16)
1493 i <<= 4;
1494 if (i < 0 || i > 1048560) {
1495#ifdef BNC_DEBUG_BCE
1496 emit(newMessage(QString("%1: Block %2 (%3) TOC is out of range: %4!")
1497 .arg(_staID)
1498 .arg(1041,4)
1499 .arg(eph._prn.toString().c_str())
1500 .arg(i).toLatin1(), true));
1501#endif
1502 return false;
1503 }
1504 eph._TOC.set(i * 1000);
1505 GETFLOATSIGN(eph._TGD, 8, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1506 GETFLOATSIGN(eph._Delta_n, 22, R2R_PI/(double)(1<<30)/(double)(1 << 11))
1507 // IODCE
1508 GETBITS(eph._IODE, 8)
1509 eph._IODC = eph._IODE;
1510 SKIPBITS(10)
1511 GETBITS(L5Flag, 1)
1512 GETBITS(SFlag, 1)
1513 if (L5Flag == 0 && SFlag == 0) {
1514 eph._health = 0.0;
1515 }
1516 else if (L5Flag == 0 && SFlag == 1) {
1517 eph._health = 1.0;
1518 }
1519 else if (L5Flag == 1 && SFlag == 0) {
1520 eph._health = 2.0;
1521 }
1522 else if (L5Flag == 1 && SFlag == 1) {
1523 eph._health = 3.0;
1524 }
1525 GETFLOATSIGN(eph._Cuc, 15, 1.0 / (double )(1 << 28))
1526 GETFLOATSIGN(eph._Cus, 15, 1.0 / (double )(1 << 28))
1527 GETFLOATSIGN(eph._Cic, 15, 1.0 / (double )(1 << 28))
1528 GETFLOATSIGN(eph._Cis, 15, 1.0 / (double )(1 << 28))
1529 GETFLOATSIGN(eph._Crc, 15, 1.0 / (double )(1 << 4))
1530 GETFLOATSIGN(eph._Crs, 15, 1.0 / (double )(1 << 4))
1531 GETFLOATSIGN(eph._IDOT, 14, R2R_PI/(double)(1<<30)/(double)(1<<13))
1532 SKIPBITS(2)
1533 GETFLOATSIGN(eph._M0, 32, R2R_PI/(double)(1<<30)/(double)(1<< 1))
1534 GETBITS(i, 16)
1535 i <<= 4;
1536 if (i < 0 || i > 1048560) {
1537#ifdef BNC_DEBUG_BCE
1538 emit(newMessage(QString("%1: Block %2 (%3) TOE is out of range: %4!")
1539 .arg(_staID)
1540 .arg(1041,4)
1541 .arg(eph._prn.toString().c_str())
1542 .arg(i).toLatin1(), true));
1543#endif
1544 return false;
1545 }
1546 eph._TOEsec = i;
1547 bncTime t;
1548 t.set(i * 1000);
1549 eph._TOEweek = t.gpsw();
1550 int numOfRollOvers = int(floor(t.gpsw()/1024.0));
1551 week += (numOfRollOvers * 1024);
1552 /* week from HOW, differs from TOC, TOE week, we use adapted value instead */
1553 if (eph._TOEweek > week + 1 || eph._TOEweek < week - 1) /* invalid week */
1554 return false;
1555 GETFLOAT(eph._e, 32, 1.0 / (double )(1 << 30) / (double )(1 << 3))
1556 GETFLOAT(eph._sqrt_A, 32, 1.0 / (double )(1 << 19))
1557 if (eph._sqrt_A < 1000.0) {
1558#ifdef BNC_DEBUG_BCE
1559 emit(newMessage(QString("%1: Block %2 (%3) SQRT_A %4 m!")
1560 .arg(_staID).arg(1041,4).arg(eph._prn.toString().c_str())
1561 .arg(eph._sqrt_A,10,'F',3).toLatin1(), true));
1562#endif
1563 return false;
1564 }
1565 GETFLOATSIGN(eph._OMEGA0, 32, R2R_PI/(double)(1<<30)/(double)(1<< 1))
1566 GETFLOATSIGN(eph._omega, 32, R2R_PI/(double)(1<<30)/(double)(1<< 1))
1567 GETFLOATSIGN(eph._OMEGADOT, 22, R2R_PI/(double)(1<<30)/(double)(1<<11))
1568 GETFLOATSIGN(eph._i0, 32, R2R_PI/(double)(1<<30)/(double)(1<< 1))
1569 SKIPBITS(2)
1570 eph._TOT = 0.9999e9;
1571 eph._navType = t_eph::LNAV;
1572
1573 emit newGPSEph(eph);
1574 decoded = true;
1575 }
1576 return decoded;
1577}
1578
1579//
1580////////////////////////////////////////////////////////////////////////////
1581bool RTCM3Decoder::DecodeSBASEphemeris(unsigned char* data, int size) {
1582 bool decoded = false;
1583
1584 if (size == 35) {
1585 t_ephSBAS eph;
1586 int i;
1587 uint64_t numbits = 0, bitfield = 0;
1588
1589 data += 3; /* header */
1590 size -= 6; /* header + crc */
1591 SKIPBITS(12)
1592
1593 eph._receptDateTime = currentDateAndTimeGPS();
1594 eph._receptStaID = _staID;
1595
1596 GETBITS(i, 6)
1597 if (i < 0 || i > 38 ) {
1598#ifdef BNC_DEBUG_BCE
1599 emit(newMessage(QString("%1: Block %2 (S) PRN# is out of range: %3!")
1600 .arg(_staID)
1601 .arg(1043,4)
1602 .arg(i).toLatin1(), true));
1603#endif
1604 return false;
1605 }
1606 eph._prn.set('S', 20 + i);
1607 GETBITS(eph._IODN, 8)
1608 GETBITS(i, 13)
1609 i <<= 4;
1610 if (i < 0 || i > 86384) {
1611#ifdef BNC_DEBUG_BCE
1612 emit(newMessage(QString("%1: Block %2 (%3) TOC is out of range: %4!")
1613 .arg(_staID)
1614 .arg(1043,4)
1615 .arg(eph._prn.toString().c_str())
1616 .arg(i).toLatin1(), true));
1617#endif
1618 return false;
1619 }
1620 eph._TOC.setTOD(i * 1000);
1621 GETBITS(i, 4)
1622 eph._ura = accuracyFromIndex(i, eph.type());
1623 GETFLOATSIGN(eph._x_pos, 30, 0.08)
1624 GETFLOATSIGN(eph._y_pos, 30, 0.08)
1625 GETFLOATSIGN(eph._z_pos, 25, 0.4)
1626 ColumnVector pos(3);
1627 pos(1) = eph._x_pos; pos(2) = eph._y_pos; pos(3) = eph._z_pos;
1628 if (pos.NormFrobenius() < 1.0) {
1629#ifdef BNC_DEBUG_BCE
1630 emit(newMessage(QString("%1: Block %2 (%3): zero position!")
1631 .arg(_staID).arg(1043,4).arg(eph._prn.toString().c_str()).toLatin1(), true));
1632#endif
1633 return false;
1634 }
1635 GETFLOATSIGN(eph._x_velocity, 17, 0.000625)
1636 GETFLOATSIGN(eph._y_velocity, 17, 0.000625)
1637 GETFLOATSIGN(eph._z_velocity, 18, 0.004)
1638 GETFLOATSIGN(eph._x_acceleration, 10, 0.0000125)
1639 GETFLOATSIGN(eph._y_acceleration, 10, 0.0000125)
1640 GETFLOATSIGN(eph._z_acceleration, 10, 0.0000625)
1641 GETFLOATSIGN(eph._agf0, 12, 1.0 / (1 << 30) / (1 << 1))
1642 GETFLOATSIGN(eph._agf1, 8, 1.0 / (1 << 30) / (1 << 10))
1643
1644 eph._TOT = 0.9999E9;
1645 eph._health = 0;
1646 eph._navType = t_eph::SBASL1;
1647
1648 emit newSBASEph(eph);
1649 decoded = true;
1650 }
1651 return decoded;
1652}
1653
1654//
1655////////////////////////////////////////////////////////////////////////////
1656bool RTCM3Decoder::DecodeGalileoEphemeris(unsigned char* data, int size) {
1657 bool decoded = false;
1658 uint64_t numbits = 0, bitfield = 0;
1659 int i, week, mnum;
1660
1661 data += 3; /* header */
1662 size -= 6; /* header + crc */
1663 GETBITS(i, 12)
1664
1665 if ((i == 1046 && size == 61) || (i == 1045 && size == 60)) {
1666 t_ephGal eph;
1667 eph._receptDateTime = currentDateAndTimeGPS();
1668 eph._receptStaID = _staID;
1669
1670 eph._inav = (i == 1046);
1671 eph._fnav = (i == 1045);
1672 mnum = i;
1673 GETBITS(i, 6)
1674 if (i < 1 || i > 36 ) { // max. constellation within I/NAV / F/NAV frames is 36
1675#ifdef BNC_DEBUG_BCE
1676 emit(newMessage(QString("%1: Block %2 (E) PRN# is out of range: %3!")
1677 .arg(_staID)
1678 .arg(mnum,4)
1679 .arg(i).toLatin1(), true));
1680#endif
1681 return false;
1682 }
1683 eph._prn.set('E', i, eph._inav ? 1 : 0);
1684
1685 GETBITS(week, 12) //FIXME: roll-over after week 4095!!
1686 if (week < 0 || week > 4095) {
1687#ifdef BNC_DEBUG_BCE
1688 emit(newMessage(QString("%1: Block %2 (%3) WEEK # is out of range: %4!")
1689 .arg(_staID)
1690 .arg(mnum,4)
1691 .arg(eph._prn.toString().c_str())
1692 .arg(week).toLatin1(), true));
1693#endif
1694 return false;
1695 }
1696 eph._TOEweek = week;
1697 GETBITS(eph._IODnav, 10)
1698 GETBITS(i, 8)
1699 eph._SISA = accuracyFromIndex(i, eph.type());
1700 GETFLOATSIGN(eph._IDOT, 14, R2R_PI/(double)(1<<30)/(double)(1<<13))
1701 GETBITSFACTOR(i, 14, 60)
1702 if (i < 0 || i > 604740) {
1703#ifdef BNC_DEBUG_BCE
1704 emit(newMessage(QString("%1: Block %2 (%3) TOC is out of range: %4!")
1705 .arg(_staID)
1706 .arg(mnum,4)
1707 .arg(eph._prn.toString().c_str())
1708 .arg(i).toLatin1(), true));
1709#endif
1710 return false;
1711 }
1712 eph._TOC.set(1024 + eph._TOEweek, i);// Period #2 = + 1 x 1024 (has to be determined)
1713 GETFLOATSIGN(eph._clock_driftrate, 6, 1.0 / (double )(1 << 30) / (double )(1 << 29))
1714 GETFLOATSIGN(eph._clock_drift, 21, 1.0 / (double )(1 << 30) / (double )(1 << 16))
1715 GETFLOATSIGN(eph._clock_bias, 31, 1.0 / (double )(1 << 30) / (double )(1 << 4))
1716 GETFLOATSIGN(eph._Crs, 16, 1.0 / (double )(1 << 5))
1717 GETFLOATSIGN(eph._Delta_n, 16, R2R_PI/(double)(1<<30)/(double)(1<<13))
1718 GETFLOATSIGN(eph._M0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1719 GETFLOATSIGN(eph._Cuc, 16, 1.0 / (double )(1 << 29))
1720 GETFLOAT(eph._e, 32, 1.0 / (double )(1 << 30) / (double )(1 << 3))
1721 GETFLOATSIGN(eph._Cus, 16, 1.0 / (double )(1 << 29))
1722 GETFLOAT(eph._sqrt_A, 32, 1.0 / (double )(1 << 19))
1723 GETBITSFACTOR(eph._TOEsec, 14, 60)
1724 if (i < 0 || i > 604740) {
1725#ifdef BNC_DEBUG_BCE
1726 emit(newMessage(QString("%1: Block %2 (%3) TOE is out of range: %4!")
1727 .arg(_staID)
1728 .arg(mnum,4)
1729 .arg(eph._prn.toString().c_str())
1730 .arg(i).toLatin1(), true));
1731#endif
1732 return false;
1733 }
1734 /* FIXME: overwrite value, copied from old code */
1735 eph._TOEsec = eph._TOC.gpssec();
1736 GETFLOATSIGN(eph._Cic, 16, 1.0 / (double )(1 << 29))
1737 GETFLOATSIGN(eph._OMEGA0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1738 GETFLOATSIGN(eph._Cis, 16, 1.0 / (double )(1 << 29))
1739 GETFLOATSIGN(eph._i0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1740 GETFLOATSIGN(eph._Crc, 16, 1.0 / (double )(1 << 5))
1741 GETFLOATSIGN(eph._omega, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1742 GETFLOATSIGN(eph._OMEGADOT, 24, R2R_PI/(double)(1<<30)/(double)(1<<13))
1743 GETFLOATSIGN(eph._BGD_1_5A, 10, 1.0 / (double )(1 << 30) / (double )(1 << 2))
1744 if (eph._inav) {
1745 /* set unused F/NAV values */
1746 eph._E5aHS = 0.0;
1747 eph._e5aDataInValid = false;
1748
1749 GETFLOATSIGN(eph._BGD_1_5B, 10, 1.0 / (double )(1 << 30) / (double )(1 << 2))
1750 GETBITS(eph._E5bHS, 2)
1751 GETBITS(eph._e5bDataInValid, 1)
1752 GETBITS(eph._E1_bHS, 2)
1753 GETBITS(eph._e1DataInValid, 1)
1754 if (eph._E5bHS != eph._E1_bHS) {
1755#ifdef BNC_DEBUG_BCE
1756 emit(newMessage(QString("%1: Block %2 (%3) SHS E5b %4 E1B %5: inconsistent health!")
1757 .arg(_staID).arg(1046,4).arg(eph._prn.toString().c_str())
1758 .arg(eph._E5bHS).arg(eph._E1_bHS).toLatin1(), true));
1759#endif
1760 return false;
1761 }
1762 if ((eph._BGD_1_5A == 0.0 && fabs(eph._BGD_1_5B) > 1e-9) ||
1763 (eph._BGD_1_5B == 0.0 && fabs(eph._BGD_1_5A) > 1e-9)) {
1764#ifdef BNC_DEBUG_BCE
1765 emit(newMessage(QString("%1: Block %2 (%3) BGD_15a = %4 BGD_15b = %5: inconsistent BGD!")
1766 .arg(_staID).arg(1046,4).arg(eph._prn.toString().c_str())
1767 .arg(eph._BGD_1_5A,10,'E',3).arg(eph._BGD_1_5B,10,'E',3).toLatin1(), true));
1768#endif
1769 return false;
1770 }
1771 eph._navType = t_eph::INAF;
1772 }
1773 else {
1774 /* set unused I/NAV values */
1775 eph._BGD_1_5B = 0.0;
1776 eph._E5bHS = 0.0;
1777 eph._E1_bHS = 0.0;
1778 eph._e1DataInValid = false;
1779 eph._e5bDataInValid = false;
1780
1781 GETBITS(eph._E5aHS, 2)
1782 GETBITS(eph._e5aDataInValid, 1)
1783 eph._navType = t_eph::FNAV;
1784 }
1785 eph._TOT = 0.9999e9;
1786
1787 if (eph._sqrt_A < 1000.0) {
1788#ifdef BNC_DEBUG_BCE
1789 emit(newMessage(QString("%1: Block %2 (%3) SQRT_A %4 m!")
1790 .arg(_staID).arg(eph._inav? 1046 : 1045,4).arg(eph._prn.toString().c_str())
1791 .arg(eph._sqrt_A,10,'F',3).toLatin1(), true));
1792#endif
1793 return false;
1794 }
1795
1796 emit newGalileoEph(eph);
1797 decoded = true;
1798 }
1799 return decoded;
1800}
1801
1802//
1803////////////////////////////////////////////////////////////////////////////
1804bool RTCM3Decoder::DecodeBDSEphemeris(unsigned char* data, int size) {
1805 bool decoded = false;
1806 const double iMaxGEO = 10.0 / 180.0 * M_PI;
1807
1808 if (size == 70) {
1809 t_ephBDS eph;
1810 int i, week;
1811 uint64_t numbits = 0, bitfield = 0;
1812
1813 data += 3; /* header */
1814 size -= 6; /* header + crc */
1815 SKIPBITS(12)
1816
1817 eph._receptDateTime = currentDateAndTimeGPS();
1818 eph._receptStaID = _staID;
1819
1820 GETBITS(i, 6)
1821 if (i < 1 || i > 63 ) {
1822#ifdef BNC_DEBUG_BCE
1823 emit(newMessage(QString("%1: Block %2 (C) PRN# is out of range: %3!")
1824 .arg(_staID)
1825 .arg(1042,4)
1826 .arg(i).toLatin1(), true));
1827#endif
1828 return false;
1829 }
1830 eph._prn.set('C', i);
1831
1832 GETBITS(week, 13)
1833 if (week < 0 || week > 8191) {
1834#ifdef BNC_DEBUG_BCE
1835 emit(newMessage(QString("%1: Block %2 (%3) WEEK # is out of range: %4!")
1836 .arg(_staID)
1837 .arg(1042,4)
1838 .arg(eph._prn.toString().c_str())
1839 .arg(week).toLatin1(), true));
1840#endif
1841 return false;
1842 }
1843 eph._BDTweek = week;
1844 GETBITS(i, 4)
1845 eph._URA = accuracyFromIndex(i, eph.type());
1846 GETFLOATSIGN(eph._IDOT, 14, R2R_PI/(double)(1<<30)/(double)(1<<13))
1847 GETBITS(eph._AODE, 5)
1848 GETBITS(i, 17)
1849 i <<= 3;
1850 if (i < 0 || i > 604792) {
1851#ifdef BNC_DEBUG_BCE
1852 emit(newMessage(QString("%1: Block %2 (%3) TOC is out of range: %4!")
1853 .arg(_staID)
1854 .arg(1042,4)
1855 .arg(eph._prn.toString().c_str())
1856 .arg(i).toLatin1(), true));
1857#endif
1858 return false;
1859 }
1860 eph._TOC.setBDS(eph._BDTweek, i);
1861 GETFLOATSIGN(eph._clock_driftrate, 11, 1.0 / (double )(1 << 30) / (double )(1 << 30) / (double )(1 << 6))
1862 GETFLOATSIGN(eph._clock_drift, 22, 1.0 / (double )(1 << 30) / (double )(1 << 20))
1863 GETFLOATSIGN(eph._clock_bias, 24, 1.0 / (double )(1 << 30) / (double )(1 << 3))
1864 GETBITS(eph._AODC, 5)
1865 GETFLOATSIGN(eph._Crs, 18, 1.0 / (double )(1 << 6))
1866 GETFLOATSIGN(eph._Delta_n, 16, R2R_PI/(double)(1<<30)/(double)(1<<13))
1867 GETFLOATSIGN(eph._M0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1868 GETFLOATSIGN(eph._Cuc, 18, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1869 GETFLOAT(eph._e, 32, 1.0 / (double )(1 << 30) / (double )(1 << 3))
1870 GETFLOATSIGN(eph._Cus, 18, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1871 GETFLOAT(eph._sqrt_A, 32, 1.0 / (double )(1 << 19))
1872 if (eph._sqrt_A < 1000.0) {
1873#ifdef BNC_DEBUG_BCE
1874 emit(newMessage(QString("%1: Block %2 (%3) SQRT_A %4 m!")
1875 .arg(_staID).arg(1042,4).arg(eph._prn.toString().c_str())
1876 .arg(eph._sqrt_A,10,'F',3).toLatin1(), true));
1877#endif
1878 return false;
1879 }
1880 GETBITS(i, 17)
1881 i <<= 3;
1882 if (i < 0 || i > 604792) {
1883#ifdef BNC_DEBUG_BCE
1884 emit(newMessage(QString("%1: Block %2 (%3) TOE is out of range: %4!")
1885 .arg(_staID)
1886 .arg(1042,4)
1887 .arg(eph._prn.toString().c_str())
1888 .arg(i).toLatin1(), true));
1889#endif
1890 return false;
1891 }
1892 eph._TOEsec = i;
1893 eph._TOE.setBDS(eph._BDTweek, i);
1894 GETFLOATSIGN(eph._Cic, 18, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1895 GETFLOATSIGN(eph._OMEGA0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1896 GETFLOATSIGN(eph._Cis, 18, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1897 GETFLOATSIGN(eph._i0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1898 GETFLOATSIGN(eph._Crc, 18, 1.0 / (double )(1 << 6))
1899 GETFLOATSIGN(eph._omega, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1900 GETFLOATSIGN(eph._OMEGADOT, 24, R2R_PI/(double)(1<<30)/(double)(1<<13))
1901 GETFLOATSIGN(eph._TGD1, 10, 0.0000000001)
1902 GETFLOATSIGN(eph._TGD2, 10, 0.0000000001)
1903 GETBITS(eph._SatH1, 1)
1904
1905 eph._TOT = 0.9999E9;
1906 if (eph._i0 > iMaxGEO) {
1907 eph._navType = t_eph::D1;
1908 }
1909 else {
1910 eph._navType = t_eph::D2;
1911 }
1912
1913 emit newBDSEph(eph);
1914 decoded = true;
1915 }
1916 return decoded;
1917}
1918
1919//
1920////////////////////////////////////////////////////////////////////////////
1921bool RTCM3Decoder::DecodeAntennaReceiver(unsigned char* data, int size) {
1922 char *antenna;
1923 char *antserialnum;
1924 char *receiver;
1925 char *recfirmware;
1926 char *recserialnum;
1927 int type;
1928 int antsernum = -1;
1929 int antnum = -1;
1930 int recnum = -1;
1931 int recsernum = -1;
1932 int recfirnum = -1;
1933 uint64_t numbits = 0, bitfield = 0;
1934
1935 data += 3; /* header*/
1936 size -= 6; /* header + crc */
1937
1938 GETBITS(type, 12)
1939 SKIPBITS(12) /* reference station ID */
1940 GETSTRING(antnum, antenna)
1941 if ((antnum > -1 && antnum < 265) &&
1942 (_antType.empty() || strncmp(_antType.back().descriptor, antenna, recnum) != 0)) {
1943 _antType.push_back(t_antInfo());
1944 memcpy(_antType.back().descriptor, antenna, antnum);
1945 _antType.back().descriptor[antnum] = 0;
1946 }
1947 SKIPBITS(8) /* antenna setup ID */
1948 if (type == 1008 || type == 1033 ) {
1949 GETSTRING(antsernum, antserialnum)
1950 if ((antsernum > -1 && antsernum < 265)) {
1951 memcpy(_antType.back().serialnumber, antserialnum, antsernum);
1952 _antType.back().serialnumber[antsernum] = 0;
1953 }
1954 }
1955
1956 if (type == 1033) {
1957 GETSTRING(recnum, receiver)
1958 GETSTRING(recfirnum, recfirmware)
1959 GETSTRING(recsernum, recserialnum)
1960 if ((recnum > -1 && recnum < 265) &&
1961 (_recType.empty() || strncmp(_recType.back().descriptor, receiver, recnum) != 0)) {
1962 _recType.push_back(t_recInfo());
1963 memcpy(_recType.back().descriptor, receiver, recnum);
1964 _recType.back().descriptor[recnum] = 0;
1965 if (recfirnum > -1 && recfirnum < 265) {
1966 memcpy(_recType.back().firmware, recfirmware, recfirnum);
1967 _recType.back().firmware[recfirnum] = 0;
1968 }
1969 if (recsernum > -1 && recsernum < 265) {
1970 memcpy(_recType.back().serialnumber, recserialnum, recsernum);
1971 _recType.back().serialnumber[recsernum] = 0;
1972 }
1973 }
1974 }
1975 return true;
1976}
1977
1978//
1979////////////////////////////////////////////////////////////////////////////
1980bool RTCM3Decoder::DecodeAntennaPosition(unsigned char* data, int size) {
1981 int type;
1982 uint64_t numbits = 0, bitfield = 0;
1983 double x, y, z;
1984
1985 data += 3; /* header */
1986 size -= 6; /* header + crc */
1987
1988 GETBITS(type, 12)
1989 _antList.push_back(t_antRefPoint());
1990 _antList.back().type = t_antRefPoint::ARP;
1991 SKIPBITS(22)
1992 GETBITSSIGN(x, 38)
1993 _antList.back().xx = x * 1e-4;
1994 SKIPBITS(2)
1995 GETBITSSIGN(y, 38)
1996 _antList.back().yy = y * 1e-4;
1997 SKIPBITS(2)
1998 GETBITSSIGN(z, 38)
1999 _antList.back().zz = z * 1e-4;
2000 if (type == 1006) {
2001 double h;
2002 GETBITS(h, 16)
2003 _antList.back().height = h * 1e-4;
2004 _antList.back().height_f = true;
2005 }
2006 _antList.back().message = type;
2007
2008 return true;
2009}
2010
2011//
2012////////////////////////////////////////////////////////////////////////////
2013bool RTCM3Decoder::DecodeServiceCRS(unsigned char* data, int size) {
2014 t_serviceCrs serviceCrs;
2015 int servicecrsnum = -1;
2016
2017 uint64_t numbits = 0, bitfield = 0;
2018
2019 data += 3; // header
2020 size -= 6; // header + crc
2021
2022 SKIPBITS(12) // Message Number
2023
2024 GETBITS(servicecrsnum, 5)
2025 if (servicecrsnum > -1 && servicecrsnum <= 31) {
2026 for(int i = 0; i < servicecrsnum; i++) {
2027 GETBITS(serviceCrs._name[i], 8);
2028 }
2029 serviceCrs._name[servicecrsnum] = 0;
2030 }
2031 if (_serviceCrs.empty() ||
2032 (strncmp(_serviceCrs.back()._name, serviceCrs._name, servicecrsnum) != 0)) {
2033 _serviceCrs.push_back(serviceCrs);
2034 GETFLOAT(_serviceCrs.back()._CE, 16, 1/100.0)
2035 _serviceCrs.back().setCoordinateEpochFromCE();
2036 //_serviceCrs.back().print();
2037 }
2038 return true;
2039
2040}
2041
2042//
2043////////////////////////////////////////////////////////////////////////////
2044bool RTCM3Decoder::DecodeRTCMCRS(unsigned char* data, int size) {
2045
2046 t_rtcmCrs rtcmCrs;
2047 int rtcmcrsnum = -1;
2048
2049 uint64_t numbits = 0, bitfield = 0;
2050
2051 data += 3; // header
2052 size -= 6; // header + crc
2053
2054 SKIPBITS(12) // Message Number
2055 GETBITS(rtcmcrsnum, 5)
2056 if (rtcmcrsnum > -1 && rtcmcrsnum <= 31) {
2057 for(int i = 0; i < rtcmcrsnum; i++) {
2058 GETBITS(rtcmCrs._name[i], 8);
2059 }
2060 rtcmCrs._name[rtcmcrsnum] = 0;
2061 }
2062 if (_rtcmCrs.empty() ||
2063 (strncmp(_rtcmCrs.back()._name, rtcmCrs._name, rtcmcrsnum) != 0)) {
2064 _rtcmCrs.push_back(rtcmCrs);
2065
2066 GETBITS(_rtcmCrs.back()._anchor, 1)
2067 GETBITS(_rtcmCrs.back()._plateNumber, 5)
2068
2069 int dblinksnum = 0;
2070 GETBITS(dblinksnum, 3)
2071 for (int i = 0; i < dblinksnum; i++) {
2072 int dblinknum = -1;
2073 char dblinkname[31];
2074 GETBITS(dblinknum, 5)
2075 if (dblinknum > -1 && dblinknum <= 31) {
2076 for(int i = 0; i < dblinknum; i++) {
2077 GETBITS(dblinkname[i], 8);
2078 }
2079 dblinkname[dblinknum] = 0;
2080 _rtcmCrs.back()._databaseLinks.append(QString("%1").arg(dblinkname));
2081 }
2082 }
2083 //_rtcmCrs.back().print();
2084 }
2085
2086 return true;
2087}
2088
2089
2090////////////////////////////////////////////////////////////////////////////
2091bool RTCM3Decoder::DecodeHelmertTrafoParameters(unsigned char* data, int size) {
2092
2093 t_helmertPar helmertPar;
2094 int sourcenum = -1;
2095 int targetnum = -1;
2096
2097 uint64_t numbits = 0, bitfield = 0;
2098 data += 3; // header
2099 size -= 6; // header + crc
2100
2101 SKIPBITS(12) // Message Number
2102 GETBITS(sourcenum, 5)
2103 if (sourcenum > -1 && sourcenum <= 31) {
2104 for(int i = 0; i < sourcenum; i++) {
2105 GETBITS(helmertPar._sourceName[i], 8);
2106 }
2107 helmertPar._sourceName[sourcenum] = 0;
2108 }
2109 GETBITS(targetnum, 5)
2110 if (targetnum > -1 && targetnum <= 31) {
2111 for(int i = 0; i < targetnum; i++) {
2112 GETBITS(helmertPar._targetName[i], 8);
2113 }
2114 helmertPar._targetName[targetnum] = 0;
2115 }
2116 GETBITS(helmertPar._sysIdentNum, 8)
2117 GETBITS(helmertPar._utilTrafoMessageIndicator, 10)
2118 GETBITS(helmertPar._mjd, 16)
2119 helmertPar._mjd += 44244;
2120
2121 // delete old parameter entries if available
2122 if (!_helmertPar.empty()) {
2123 QList<t_helmertPar>::iterator it = _helmertPar.begin();
2124 while (it != _helmertPar.end()) {
2125 (helmertPar == *it) ? it = _helmertPar.erase(it) : ++it;
2126 }
2127 }
2128 _helmertPar.push_back(helmertPar);
2129
2130 GETFLOATSIGN(_helmertPar.back()._dx, 23, 1/1000.0)
2131 GETFLOATSIGN(_helmertPar.back()._dy, 23, 1/1000.0)
2132 GETFLOATSIGN(_helmertPar.back()._dz, 23, 1/1000.0)
2133
2134 GETFLOATSIGN(_helmertPar.back()._ox, 32, 1/50000.0)
2135 GETFLOATSIGN(_helmertPar.back()._oy, 32, 1/50000.0)
2136 GETFLOATSIGN(_helmertPar.back()._oz, 32, 1/50000.0)
2137
2138 GETFLOATSIGN(_helmertPar.back()._sc, 25, 1/100000.0)
2139
2140 GETFLOATSIGN(_helmertPar.back()._dxr, 17, 1/50000.0)
2141 GETFLOATSIGN(_helmertPar.back()._dyr, 17, 1/50000.0)
2142 GETFLOATSIGN(_helmertPar.back()._dzr, 17, 1/50000.0)
2143
2144 GETFLOATSIGN(_helmertPar.back()._oxr, 17, 1/2500000.0)
2145 GETFLOATSIGN(_helmertPar.back()._oyr, 17, 1/2500000.0)
2146 GETFLOATSIGN(_helmertPar.back()._ozr, 17, 1/2500000.0)
2147
2148 GETFLOATSIGN(_helmertPar.back()._scr, 14, 1/5000000.0)
2149
2150 //_helmertPar.back().print();
2151
2152 return true;
2153}
2154
2155
2156//
2157////////////////////////////////////////////////////////////////////////////
2158t_irc RTCM3Decoder::Decode(char* buffer, int bufLen, vector<string>& errmsg) {
2159 bool decoded = false;
2160
2161 errmsg.clear();
2162
2163 while (bufLen && _MessageSize < sizeof(_Message)) {
2164 int l = sizeof(_Message) - _MessageSize;
2165 if (l > bufLen)
2166 l = bufLen;
2167 memcpy(_Message + _MessageSize, buffer, l);
2168 _MessageSize += l;
2169 bufLen -= l;
2170 buffer += l;
2171 int id;
2172 while ((id = GetMessage())) {
2173 /* reset station ID for file loading as it can change */
2174 if (_rawFile)
2175 _staID = _rawFile->staID();
2176 /* store the id into the list of loaded blocks */
2177 _typeList.push_back(id);
2178
2179 /* SSR I+II data handled in another function, already pass the
2180 * extracted data block. That does no harm, as it anyway skip everything
2181 * else. */
2182 if ((id >= 1057 && id <= 1068) ||
2183 (id >= 1240 && id <= 1270) ||
2184 (id == 4076)) {
2185 if (!_coDecoders.contains(_staID.toLatin1())) {
2186 _coDecoders[_staID.toLatin1()] = new RTCM3coDecoder(_staID);
2187 if (id == 4076) {
2188 _coDecoders[_staID.toLatin1()]->initSsrFormatType(RTCM3coDecoder::IGSssr);
2189 }
2190 else {
2191 _coDecoders[_staID.toLatin1()]->initSsrFormatType(RTCM3coDecoder::RTCMssr);
2192 }
2193 }
2194 RTCM3coDecoder* coDecoder = _coDecoders[_staID.toLatin1()];
2195 if (coDecoder->Decode(reinterpret_cast<char *>(_Message), _BlockSize, errmsg) == success) {
2196 decoded = true;
2197 }
2198 }
2199 else if (id >= 1070 && id <= 1237) { /* MSM */
2200 if (DecodeRTCM3MSM(_Message, _BlockSize))
2201 decoded = true;
2202 }
2203 else {
2204 switch (id) {
2205 case 1001:
2206 case 1003:
2207#ifdef BNC_DEBUG_OBS
2208 emit(newMessage(QString("%1: Block %2 contain partial data! Ignored!")
2209 .arg(_staID).arg(id).toLatin1(), true));
2210#endif
2211 break; /* no use decoding partial data ATM, remove break when data can be used */
2212 case 1002:
2213 case 1004:
2214 if (DecodeRTCM3GPS(_Message, _BlockSize))
2215 decoded = true;
2216 break;
2217 case 1009:
2218 case 1011:
2219#ifdef BNC_DEBUG_OBS
2220 emit(newMessage(QString("%1: Block %2 contain partial data! Ignored!")
2221 .arg(_staID).arg(id).toLatin1(), true));
2222#endif
2223 break; /* no use decoding partial data ATM, remove break when data can be used */
2224 case 1010:
2225 case 1012:
2226 if (DecodeRTCM3GLONASS(_Message, _BlockSize))
2227 decoded = true;
2228 break;
2229 case 1019:
2230 if (DecodeGPSEphemeris(_Message, _BlockSize))
2231 decoded = true;
2232 break;
2233 case 1020:
2234 if (DecodeGLONASSEphemeris(_Message, _BlockSize))
2235 decoded = true;
2236 break;
2237 case 1043:
2238 if (DecodeSBASEphemeris(_Message, _BlockSize))
2239 decoded = true;
2240 break;
2241 case 1044:
2242 if (DecodeQZSSEphemeris(_Message, _BlockSize))
2243 decoded = true;
2244 break;
2245 case 1041:
2246 if (DecodeIRNSSEphemeris(_Message, _BlockSize))
2247 decoded = true;
2248 break;
2249 case 1045:
2250 case 1046:
2251 if (DecodeGalileoEphemeris(_Message, _BlockSize))
2252 decoded = true;
2253 break;
2254 case 1042:
2255 if (DecodeBDSEphemeris(_Message, _BlockSize))
2256 decoded = true;
2257 break;
2258 case 1007:
2259 case 1008:
2260 case 1033:
2261 DecodeAntennaReceiver(_Message, _BlockSize);
2262 break;
2263 case 1005:
2264 case 1006:
2265 DecodeAntennaPosition(_Message, _BlockSize);
2266 break;
2267 case 1300:
2268 DecodeServiceCRS(_Message, _BlockSize);
2269 break;
2270 case 1301:
2271 DecodeHelmertTrafoParameters(_Message, _BlockSize);
2272 break;
2273 case 1302:
2274 case 35:
2275 DecodeRTCMCRS(_Message, _BlockSize);
2276 break;
2277 }
2278 }
2279 }
2280 }
2281 /*
2282 for (int ii = 0; ii < _helmertParList.size(); ii++) {
2283 _helmertParList[ii].print();
2284 }*/
2285 return decoded ? success : failure;
2286}
2287
2288//
2289////////////////////////////////////////////////////////////////////////////
2290uint32_t RTCM3Decoder::CRC24(long size, const unsigned char *buf) {
2291 uint32_t crc = 0;
2292 int ii;
2293 while (size--) {
2294 crc ^= (*buf++) << (16);
2295 for (ii = 0; ii < 8; ii++) {
2296 crc <<= 1;
2297 if (crc & 0x1000000)
2298 crc ^= 0x01864cfb;
2299 }
2300 }
2301 return crc;
2302}
2303
2304//
2305////////////////////////////////////////////////////////////////////////////
2306int RTCM3Decoder::GetMessage(void) {
2307 unsigned char *m, *e;
2308 int i;
2309
2310 m = _Message + _SkipBytes;
2311 e = _Message + _MessageSize;
2312 _NeedBytes = _SkipBytes = 0;
2313 while (e - m >= 3) {
2314 if (m[0] == 0xD3) {
2315 _BlockSize = ((m[1] & 3) << 8) | m[2];
2316 if (e - m >= static_cast<int>(_BlockSize + 6)) {
2317 if (static_cast<uint32_t>((m[3 + _BlockSize] << 16)
2318 | (m[3 + _BlockSize + 1] << 8)
2319 | (m[3 + _BlockSize + 2])) == CRC24(_BlockSize + 3, m)) {
2320 _BlockSize += 6;
2321 _SkipBytes = _BlockSize;
2322 break;
2323 }
2324 else
2325 ++m;
2326 }
2327 else {
2328 _NeedBytes = _BlockSize;
2329 break;
2330 }
2331 }
2332 else
2333 ++m;
2334 }
2335 if (e - m < 3)
2336 _NeedBytes = 3;
2337
2338 /* copy buffer to front */
2339 i = m - _Message;
2340 if (i && m < e)
2341 memmove(_Message, m, static_cast<size_t>(_MessageSize - i));
2342 _MessageSize -= i;
2343
2344 return !_NeedBytes ? ((_Message[3] << 4) | (_Message[4] >> 4)) : 0;
2345}
2346
2347// Time of Corrections
2348//////////////////////////////////////////////////////////////////////////////
2349int RTCM3Decoder::corrGPSEpochTime() const {
2350 return
2351 _coDecoders.size() > 0 ?
2352 _coDecoders.begin().value()->corrGPSEpochTime() : -1;
2353}
2354
2355
2356
2357
Note: See TracBrowser for help on using the repository browser.