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

Last change on this file since 9286 was 9286, checked in by stuerze, 10 months ago

minor changes

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