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

Last change on this file since 8843 was 8843, checked in by stuerze, 4 years ago

Harmonization of RTCM3 Signal ID Mapping and RTCM SSR Signal and Tracking Mode Identifiers

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