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

Last change on this file since 9315 was 9315, checked in by stuerze, 3 years ago

message type typo corrected

File size: 62.3 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).toLatin1(), 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(1019,4).arg(eph._prn.toString().c_str())
1062 .arg(eph._sqrt_A,10,'F',3).toLatin1(), 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 /*
1122 if (eph._almanac_health_availablility_indicator == 0.0) {
1123#ifdef BNC_DEBUG_BCEP
1124 emit(newMessage(QString("%1: Block %2 (%3): ALM = %4: missing data!")
1125 .arg(_staID).arg(1020,4).arg(eph._prn.toString().c_str())
1126 .arg(eph._almanac_health_availablility_indicator).toLatin1(), true));
1127#endif
1128 return false;
1129 }*/
1130 GETBITS(eph._P1, 2) /* P1 */
1131 GETBITS(i, 5)
1132 tk = i * 60 * 60;
1133 GETBITS(i, 6)
1134 tk += i * 60;
1135 GETBITS(i, 1)
1136 tk += i * 30;
1137 eph._tki = tk - 3*60*60;
1138 if(eph._tki < 0.0) {
1139 eph._tki += 86400.0;
1140 }
1141 GETBITS(eph._health, 1) /* MSB of Bn*/
1142 GETBITS(eph._P2, 1) /* P2 */
1143 GETBITS(i, 7)
1144 eph._TOC.setTk(i * 15 * 60 * 1000); /* tb */
1145
1146 GETFLOATSIGNM(eph._x_velocity, 24, 1.0 / (double )(1 << 20))
1147 GETFLOATSIGNM(eph._x_pos, 27, 1.0 / (double )(1 << 11))
1148 GETFLOATSIGNM(eph._x_acceleration, 5, 1.0 / (double )(1 << 30))
1149 GETFLOATSIGNM(eph._y_velocity, 24, 1.0 / (double )(1 << 20))
1150 GETFLOATSIGNM(eph._y_pos, 27, 1.0 / (double )(1 << 11))
1151 GETFLOATSIGNM(eph._y_acceleration, 5, 1.0 / (double )(1 << 30))
1152 GETFLOATSIGNM(eph._z_velocity, 24, 1.0 / (double )(1 << 20))
1153 GETFLOATSIGNM(eph._z_pos, 27, 1.0 / (double )(1 << 11))
1154 GETFLOATSIGNM(eph._z_acceleration, 5, 1.0 / (double )(1 << 30))
1155 GETBITS(eph._P3, 1) /* P3 */
1156 GETFLOATSIGNM(eph._gamma, 11, 1.0 / (double )(1 << 30) / (double )(1 << 10))
1157 GETBITS(eph._M_P, 2) /* GLONASS-M P, */
1158 GETBITS(eph._M_l3, 1) /* GLONASS-M ln (third string) */
1159 GETFLOATSIGNM(eph._tau, 22, 1.0 / (double )(1 << 30)) /* GLONASS tau n(tb) */
1160 GETFLOATSIGNM(eph._M_delta_tau, 5, 1.0 / (double )(1 << 30)) /* GLONASS-M delta tau n(tb) */
1161 GETBITS(eph._E, 5)
1162 GETBITS(eph._M_P4, 1) /* GLONASS-M P4 */
1163 GETBITS(eph._M_FT, 4) /* GLONASS-M Ft */
1164 GETBITS(eph._M_NT, 11) /* GLONASS-M Nt */
1165 if (eph._M_NT == 0.0) {
1166#ifdef BNC_DEBUG_BCEP
1167 emit(newMessage(QString("%1: Block %2 (%3): NT = %4: missing data!")
1168 .arg(_staID).arg(1020,4).arg(eph._prn.toString().c_str()).arg(eph._M_NT,4).toLatin1(), true));
1169#endif
1170 return false;
1171 }
1172 GETBITS(eph._M_M, 2) /* GLONASS-M M */
1173 GETBITS(eph._additional_data_availability, 1) /* GLONASS-M The Availability of Additional Data */
1174 if (eph._additional_data_availability == 0.0) {
1175#ifdef BNC_DEBUG_BCEP
1176 emit(newMessage(QString("%1: Block %2 (%3): ADD = %4: missing data!")
1177 .arg(_staID).arg(1020,4).arg(eph._prn.toString().c_str())
1178 .arg(eph._additional_data_availability).toLatin1(), true));
1179#endif
1180 return false;
1181 }
1182 GETBITS(eph._NA, 11) /* GLONASS-M Na */
1183 GETFLOATSIGNM(eph._tauC, 32, 1.0/(double)(1<<30)/(double)(1<<1)) /* GLONASS tau c */
1184 GETBITS(eph._M_N4, 5) /* GLONASS-M N4 */
1185 GETFLOATSIGNM(eph._M_tau_GPS, 22, 1.0/(double)(1<<30)) /* GLONASS-M tau GPS */
1186 GETBITS(eph._M_l5, 1) /* GLONASS-M ln (fifth string) */
1187
1188 unsigned year, month, day;
1189 eph._TOC.civil_date(year, month, day);
1190 eph._gps_utc = gnumleap(year, month, day);
1191 eph._tt = eph._TOC;
1192
1193 eph._xv(1) = eph._x_pos * 1.e3;
1194 eph._xv(2) = eph._y_pos * 1.e3;
1195 eph._xv(3) = eph._z_pos * 1.e3;
1196 if (eph._xv.Rows(1,3).NormFrobenius() < 1.0) {
1197#ifdef BNC_DEBUG_BCEP
1198 emit(newMessage(QString("%1: Block %2 (%3): zero position!")
1199 .arg(_staID).arg(1020,4).arg(eph._prn.toString().c_str()).toLatin1(), true));
1200#endif
1201 return false;
1202 }
1203 eph._xv(4) = eph._x_velocity * 1.e3;
1204 eph._xv(5) = eph._y_velocity * 1.e3;
1205 eph._xv(6) = eph._z_velocity * 1.e3;
1206 if (eph._xv.Rows(4,6).NormFrobenius() < 1.0) {
1207#ifdef BNC_DEBUG_BCEP
1208 emit(newMessage(QString("%1: Block %2 (%3): zero velocity!")
1209 .arg(_staID).arg(1020,4).arg(eph._prn.toString().c_str()).toLatin1(), true));
1210#endif
1211 return false;
1212 }
1213 GLOFreq[sv - 1] = 100 + eph._frequency_number ; /* store frequency for other users (MSM) */
1214 _gloFrq = QString("%1 %2").arg(eph._prn.toString().c_str()).arg(eph._frequency_number, 2, 'f', 0);
1215
1216 emit newGlonassEph(eph);
1217 decoded = true;
1218 }
1219 return decoded;
1220}
1221
1222//
1223////////////////////////////////////////////////////////////////////////////
1224bool RTCM3Decoder::DecodeQZSSEphemeris(unsigned char* data, int size) {
1225 bool decoded = false;
1226
1227 if (size == 67) {
1228 t_ephGPS eph;
1229 int i, week;
1230 uint64_t numbits = 0, bitfield = 0;
1231 int fitIntervalFalg = 0;
1232
1233 data += 3; /* header */
1234 size -= 6; /* header + crc */
1235 SKIPBITS(12)
1236
1237 eph._receptDateTime = currentDateAndTimeGPS();
1238 eph._receptStaID = _staID;
1239
1240 GETBITS(i, 4)
1241 eph._prn.set('J', i);
1242
1243 GETBITS(i, 16)
1244 i <<= 4;
1245 eph._TOC.set(i * 1000);
1246
1247 GETFLOATSIGN(eph._clock_driftrate, 8, 1.0 / (double )(1 << 30) / (double )(1 << 25))
1248 GETFLOATSIGN(eph._clock_drift, 16, 1.0 / (double )(1 << 30) / (double )(1 << 13))
1249 GETFLOATSIGN(eph._clock_bias, 22, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1250 GETBITS(eph._IODE, 8)
1251 GETFLOATSIGN(eph._Crs, 16, 1.0 / (double )(1 << 5))
1252 GETFLOATSIGN(eph._Delta_n, 16, R2R_PI/(double)(1<<30)/(double)(1<<13))
1253 GETFLOATSIGN(eph._M0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1254 GETFLOATSIGN(eph._Cuc, 16, 1.0 / (double )(1 << 29))
1255 GETFLOAT(eph._e, 32, 1.0 / (double )(1 << 30) / (double )(1 << 3))
1256 GETFLOATSIGN(eph._Cus, 16, 1.0 / (double )(1 << 29))
1257 GETFLOAT(eph._sqrt_A, 32, 1.0 / (double )(1 << 19))
1258 if (eph._sqrt_A < 1000.0) {
1259#ifdef BNC_DEBUG_BCEP
1260 emit(newMessage(QString("%1: Block %2 (%3) SQRT_A %4 m!")
1261 .arg(_staID).arg(1044,4).arg(eph._prn.toString().c_str())
1262 .arg(eph._sqrt_A,10,'F',3).toLatin1(), true));
1263#endif
1264 return false;
1265 }
1266 GETBITS(i, 16)
1267 i <<= 4;
1268 eph._TOEsec = i;
1269 bncTime t;
1270 t.set(i*1000);
1271 eph._TOEweek = t.gpsw();
1272 GETFLOATSIGN(eph._Cic, 16, 1.0 / (double )(1 << 29))
1273 GETFLOATSIGN(eph._OMEGA0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1274 GETFLOATSIGN(eph._Cis, 16, 1.0 / (double )(1 << 29))
1275 GETFLOATSIGN(eph._i0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1276 GETFLOATSIGN(eph._Crc, 16, 1.0 / (double )(1 << 5))
1277 GETFLOATSIGN(eph._omega, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1278 GETFLOATSIGN(eph._OMEGADOT, 24, R2R_PI/(double)(1<<30)/(double)(1<<13))
1279 GETFLOATSIGN(eph._IDOT, 14, R2R_PI/(double)(1<<30)/(double)(1<<13))
1280 GETBITS(eph._L2Codes, 2)
1281 GETBITS(week, 10)
1282 int numOfRollOvers = int(floor(t.gpsw()/1024.0));
1283 week += (numOfRollOvers * 1024);
1284 /* week from HOW, differs from TOC, TOE week, we use adapted value instead */
1285 if (eph._TOEweek > week + 1 || eph._TOEweek < week - 1) /* invalid week */
1286 return false;
1287
1288 GETBITS(i, 4)
1289 if (i <= 6)
1290 eph._ura = ceil(10.0 * pow(2.0, 1.0 + i / 2.0)) / 10.0;
1291 else
1292 eph._ura = ceil(10.0 * pow(2.0, i / 2.0)) / 10.0;
1293 GETBITS(eph._health, 6)
1294 GETFLOATSIGN(eph._TGD, 8, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1295 GETBITS(eph._IODC, 10)
1296 GETBITS(fitIntervalFalg, 1)
1297 eph._fitInterval = fitIntervalFromFlag(fitIntervalFalg, eph._IODC, eph.type());
1298 eph._TOT = 0.9999e9;
1299
1300 emit newGPSEph(eph);
1301 decoded = true;
1302 }
1303 return decoded;
1304}
1305
1306//
1307////////////////////////////////////////////////////////////////////////////
1308bool RTCM3Decoder::DecodeIRNSSEphemeris(unsigned char* data, int size) {
1309 bool decoded = false;
1310
1311 if (size == 67) {
1312 t_ephGPS eph;
1313 int i, week, L5Flag, SFlag;
1314 uint64_t numbits = 0, bitfield = 0;
1315
1316 data += 3; /* header */
1317 size -= 6; /* header + crc */
1318 SKIPBITS(12)
1319
1320 eph._receptDateTime = currentDateAndTimeGPS();
1321 eph._receptStaID = _staID;
1322
1323 GETBITS(i, 6)
1324 eph._prn.set('I', i);
1325 GETBITS(week, 10)
1326 GETFLOATSIGN(eph._clock_bias, 22, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1327 GETFLOATSIGN(eph._clock_drift, 16, 1.0 / (double )(1 << 30) / (double )(1 << 13))
1328 GETFLOATSIGN(eph._clock_driftrate, 8, 1.0 / (double )(1 << 30) / (double )(1 << 25))
1329 GETBITS(i, 4)
1330 eph._ura = accuracyFromIndex(i, eph.type());
1331 GETBITS(i, 16)
1332 i <<= 4;
1333 eph._TOC.set(i * 1000);
1334 GETFLOATSIGN(eph._TGD, 8, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1335 GETFLOATSIGN(eph._Delta_n, 22, R2R_PI/(double)(1<<30)/(double)(1 << 11))
1336 // IODCE
1337 GETBITS(eph._IODE, 8)
1338 eph._IODC = eph._IODE;
1339 SKIPBITS(10)
1340 GETBITS(L5Flag, 1)
1341 GETBITS(SFlag, 1)
1342 if (L5Flag == 0 && SFlag == 0) {
1343 eph._health = 0.0;
1344 }
1345 else if (L5Flag == 0 && SFlag == 1) {
1346 eph._health = 1.0;
1347 }
1348 else if (L5Flag == 1 && SFlag == 0) {
1349 eph._health = 2.0;
1350 }
1351 else if (L5Flag == 1 && SFlag == 1) {
1352 eph._health = 3.0;
1353 }
1354 GETFLOATSIGN(eph._Cuc, 15, 1.0 / (double )(1 << 28))
1355 GETFLOATSIGN(eph._Cus, 15, 1.0 / (double )(1 << 28))
1356 GETFLOATSIGN(eph._Cic, 15, 1.0 / (double )(1 << 28))
1357 GETFLOATSIGN(eph._Cis, 15, 1.0 / (double )(1 << 28))
1358 GETFLOATSIGN(eph._Crc, 15, 1.0 / (double )(1 << 4))
1359 GETFLOATSIGN(eph._Crs, 15, 1.0 / (double )(1 << 4))
1360 GETFLOATSIGN(eph._IDOT, 14, R2R_PI/(double)(1<<30)/(double)(1<<13))
1361 GETFLOATSIGN(eph._M0, 32, R2R_PI/(double)(1<<30)/(double)(1<< 1))
1362 GETBITS(i, 16)
1363 i <<= 4;
1364 eph._TOEsec = i;
1365 bncTime t;
1366 t.set(i * 1000);
1367 eph._TOEweek = t.gpsw();
1368 int numOfRollOvers = int(floor(t.gpsw()/1024.0));
1369 week += (numOfRollOvers * 1024);
1370 /* week from HOW, differs from TOC, TOE week, we use adapted value instead */
1371 if (eph._TOEweek > week + 1 || eph._TOEweek < week - 1) /* invalid week */
1372 return false;
1373 GETFLOAT(eph._e, 32, 1.0 / (double )(1 << 30) / (double )(1 << 3))
1374 GETFLOAT(eph._sqrt_A, 32, 1.0 / (double )(1 << 19))
1375 if (eph._sqrt_A < 1000.0) {
1376#ifdef BNC_DEBUG_BCEP
1377 emit(newMessage(QString("%1: Block %2 (%3) SQRT_A %4 m!")
1378 .arg(_staID).arg(1041,4).arg(eph._prn.toString().c_str())
1379 .arg(eph._sqrt_A,10,'F',3).toLatin1(), true));
1380#endif
1381 return false;
1382 }
1383 GETFLOATSIGN(eph._OMEGA0, 32, R2R_PI/(double)(1<<30)/(double)(1<< 1))
1384 GETFLOATSIGN(eph._omega, 32, R2R_PI/(double)(1<<30)/(double)(1<< 1))
1385 GETFLOATSIGN(eph._OMEGADOT, 22, R2R_PI/(double)(1<<30)/(double)(1<<11))
1386 GETFLOATSIGN(eph._i0, 32, R2R_PI/(double)(1<<30)/(double)(1<< 1))
1387 SKIPBITS(2)
1388 SKIPBITS(2)
1389 eph._TOT = 0.9999e9;
1390
1391 emit newGPSEph(eph);
1392 decoded = true;
1393 }
1394 return decoded;
1395}
1396
1397//
1398////////////////////////////////////////////////////////////////////////////
1399bool RTCM3Decoder::DecodeSBASEphemeris(unsigned char* data, int size) {
1400 bool decoded = false;
1401
1402 if (size == 35) {
1403 t_ephSBAS eph;
1404 int i;
1405 uint64_t numbits = 0, bitfield = 0;
1406
1407 data += 3; /* header */
1408 size -= 6; /* header + crc */
1409 SKIPBITS(12)
1410
1411 eph._receptDateTime = currentDateAndTimeGPS();
1412 eph._receptStaID = _staID;
1413
1414 GETBITS(i, 6)
1415 eph._prn.set('S', 20 + i);
1416 GETBITS(eph._IODN, 8)
1417 GETBITS(i, 13)
1418 i <<= 4;
1419 eph._TOC.setTOD(i * 1000);
1420 GETBITS(i, 4)
1421 eph._ura = accuracyFromIndex(i, eph.type());
1422 GETFLOATSIGN(eph._x_pos, 30, 0.08)
1423 GETFLOATSIGN(eph._y_pos, 30, 0.08)
1424 GETFLOATSIGN(eph._z_pos, 25, 0.4)
1425 ColumnVector pos(3);
1426 pos(1) = eph._x_pos; pos(2) = eph._y_pos; pos(3) = eph._z_pos;
1427 if (pos.NormFrobenius() < 1.0) {
1428#ifdef BNC_DEBUG_BCEP
1429 emit(newMessage(QString("%1: Block %2 (%3): zero position!")
1430 .arg(_staID).arg(1043,4).arg(eph._prn.toString().c_str()).toLatin1(), true));
1431#endif
1432 return false;
1433 }
1434 GETFLOATSIGN(eph._x_velocity, 17, 0.000625)
1435 GETFLOATSIGN(eph._y_velocity, 17, 0.000625)
1436 GETFLOATSIGN(eph._z_velocity, 18, 0.004)
1437 GETFLOATSIGN(eph._x_acceleration, 10, 0.0000125)
1438 GETFLOATSIGN(eph._y_acceleration, 10, 0.0000125)
1439 GETFLOATSIGN(eph._z_acceleration, 10, 0.0000625)
1440 GETFLOATSIGN(eph._agf0, 12, 1.0 / (1 << 30) / (1 << 1))
1441 GETFLOATSIGN(eph._agf1, 8, 1.0 / (1 << 30) / (1 << 10))
1442
1443 eph._TOT = 0.9999E9;
1444 eph._health = 0;
1445
1446 emit newSBASEph(eph);
1447 decoded = true;
1448 }
1449 return decoded;
1450}
1451
1452//
1453////////////////////////////////////////////////////////////////////////////
1454bool RTCM3Decoder::DecodeGalileoEphemeris(unsigned char* data, int size) {
1455 bool decoded = false;
1456 uint64_t numbits = 0, bitfield = 0;
1457 int i;
1458
1459 data += 3; /* header */
1460 size -= 6; /* header + crc */
1461 GETBITS(i, 12)
1462
1463 if ((i == 1046 && size == 61) || (i == 1045 && size == 60)) {
1464 t_ephGal eph;
1465
1466 eph._receptDateTime = currentDateAndTimeGPS();
1467 eph._receptStaID = _staID;
1468
1469 eph._inav = (i == 1046);
1470 eph._fnav = (i == 1045);
1471 GETBITS(i, 6)
1472 eph._prn.set('E', i, eph._inav ? 1 : 0);
1473
1474 GETBITS(eph._TOEweek, 12) //FIXME: roll-over after week 4095!!
1475 GETBITS(eph._IODnav, 10)
1476 GETBITS(i, 8)
1477 eph._SISA = accuracyFromIndex(i, eph.type());
1478 GETFLOATSIGN(eph._IDOT, 14, R2R_PI/(double)(1<<30)/(double)(1<<13))
1479 GETBITSFACTOR(i, 14, 60)
1480 eph._TOC.set(1024 + eph._TOEweek, i);
1481 GETFLOATSIGN(eph._clock_driftrate, 6, 1.0 / (double )(1 << 30) / (double )(1 << 29))
1482 GETFLOATSIGN(eph._clock_drift, 21, 1.0 / (double )(1 << 30) / (double )(1 << 16))
1483 GETFLOATSIGN(eph._clock_bias, 31, 1.0 / (double )(1 << 30) / (double )(1 << 4))
1484 GETFLOATSIGN(eph._Crs, 16, 1.0 / (double )(1 << 5))
1485 GETFLOATSIGN(eph._Delta_n, 16, R2R_PI/(double)(1<<30)/(double)(1<<13))
1486 GETFLOATSIGN(eph._M0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1487 GETFLOATSIGN(eph._Cuc, 16, 1.0 / (double )(1 << 29))
1488 GETFLOAT(eph._e, 32, 1.0 / (double )(1 << 30) / (double )(1 << 3))
1489 GETFLOATSIGN(eph._Cus, 16, 1.0 / (double )(1 << 29))
1490 GETFLOAT(eph._sqrt_A, 32, 1.0 / (double )(1 << 19))
1491 GETBITSFACTOR(eph._TOEsec, 14, 60)
1492 /* FIXME: overwrite value, copied from old code */
1493 eph._TOEsec = eph._TOC.gpssec();
1494 GETFLOATSIGN(eph._Cic, 16, 1.0 / (double )(1 << 29))
1495 GETFLOATSIGN(eph._OMEGA0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1496 GETFLOATSIGN(eph._Cis, 16, 1.0 / (double )(1 << 29))
1497 GETFLOATSIGN(eph._i0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1498 GETFLOATSIGN(eph._Crc, 16, 1.0 / (double )(1 << 5))
1499 GETFLOATSIGN(eph._omega, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1500 GETFLOATSIGN(eph._OMEGADOT, 24, R2R_PI/(double)(1<<30)/(double)(1<<13))
1501 GETFLOATSIGN(eph._BGD_1_5A, 10, 1.0 / (double )(1 << 30) / (double )(1 << 2))
1502 if (eph._inav) {
1503 /* set unused F/NAV values */
1504 eph._E5aHS = 0.0;
1505 eph._e5aDataInValid = false;
1506
1507 GETFLOATSIGN(eph._BGD_1_5B, 10, 1.0 / (double )(1 << 30) / (double )(1 << 2))
1508 GETBITS(eph._E5bHS, 2)
1509 GETBITS(eph._e5bDataInValid, 1)
1510 GETBITS(eph._E1_bHS, 2)
1511 GETBITS(eph._e1DataInValid, 1)
1512 if (eph._E5bHS != eph._E1_bHS) {
1513#ifdef BNC_DEBUG_BCEP
1514 emit(newMessage(QString("%1: Block %2 (%3) SHS E5b %4 E1B %5: inconsistent health!")
1515 .arg(_staID).arg(1046,4).arg(eph._prn.toString().c_str())
1516 .arg(eph._E5bHS).arg(eph._E1_bHS).toLatin1(), true));
1517#endif
1518 return false;
1519 }
1520 if ((eph._BGD_1_5A == 0.0 && fabs(eph._BGD_1_5B) > 1e-9) ||
1521 (eph._BGD_1_5B == 0.0 && fabs(eph._BGD_1_5A) > 1e-9)) {
1522#ifdef BNC_DEBUG_BCEP
1523 emit(newMessage(QString("%1: Block %2 (%3) BGD_15a = %4 BGD_15b = %5: inconsistent BGD!")
1524 .arg(_staID).arg(1046,4).arg(eph._prn.toString().c_str())
1525 .arg(eph._BGD_1_5A,10,'E',3).arg(eph._BGD_1_5B,10,'E',3).toLatin1(), true));
1526#endif
1527 return false;
1528 }
1529 }
1530 else {
1531 /* set unused I/NAV values */
1532 eph._BGD_1_5B = 0.0;
1533 eph._E5bHS = 0.0;
1534 eph._E1_bHS = 0.0;
1535 eph._e1DataInValid = false;
1536 eph._e5bDataInValid = false;
1537
1538 GETBITS(eph._E5aHS, 2)
1539 GETBITS(eph._e5aDataInValid, 1)
1540 }
1541 eph._TOT = 0.9999e9;
1542
1543 if (eph._sqrt_A < 1000.0) {
1544#ifdef BNC_DEBUG_BCEP
1545 emit(newMessage(QString("%1: Block %2 (%3) SQRT_A %4 m!")
1546 .arg(_staID).arg(eph._inav? 1046 : 1045,4).arg(eph._prn.toString().c_str())
1547 .arg(eph._sqrt_A,10,'F',3).toLatin1(), true));
1548#endif
1549 return false;
1550 }
1551
1552 emit newGalileoEph(eph);
1553 decoded = true;
1554 }
1555 return decoded;
1556}
1557
1558//
1559////////////////////////////////////////////////////////////////////////////
1560bool RTCM3Decoder::DecodeBDSEphemeris(unsigned char* data, int size) {
1561 bool decoded = false;
1562
1563 if (size == 70) {
1564 t_ephBDS eph;
1565 int i;
1566 uint64_t numbits = 0, bitfield = 0;
1567
1568 data += 3; /* header */
1569 size -= 6; /* header + crc */
1570 SKIPBITS(12)
1571
1572 eph._receptDateTime = currentDateAndTimeGPS();
1573 eph._receptStaID = _staID;
1574
1575 GETBITS(i, 6)
1576 eph._prn.set('C', i);
1577
1578 SKIPBITS(13)
1579 /* week */
1580 GETBITS(i, 4)
1581 eph._URA = accuracyFromIndex(i, eph.type());
1582 GETFLOATSIGN(eph._IDOT, 14, R2R_PI/(double)(1<<30)/(double)(1<<13))
1583 GETBITS(eph._AODE, 5)
1584 GETBITS(i, 17)
1585 i <<= 3;
1586 eph._TOC.setBDS(i * 1000);
1587 GETFLOATSIGN(eph._clock_driftrate, 11, 1.0 / (double )(1 << 30) / (double )(1 << 30) / (double )(1 << 6))
1588 GETFLOATSIGN(eph._clock_drift, 22, 1.0 / (double )(1 << 30) / (double )(1 << 20))
1589 GETFLOATSIGN(eph._clock_bias, 24, 1.0 / (double )(1 << 30) / (double )(1 << 3))
1590 GETBITS(eph._AODC, 5)
1591 GETFLOATSIGN(eph._Crs, 18, 1.0 / (double )(1 << 6))
1592 GETFLOATSIGN(eph._Delta_n, 16, R2R_PI/(double)(1<<30)/(double)(1<<13))
1593 GETFLOATSIGN(eph._M0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1594 GETFLOATSIGN(eph._Cuc, 18, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1595 GETFLOAT(eph._e, 32, 1.0 / (double )(1 << 30) / (double )(1 << 3))
1596 GETFLOATSIGN(eph._Cus, 18, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1597 GETFLOAT(eph._sqrt_A, 32, 1.0 / (double )(1 << 19))
1598 if (eph._sqrt_A < 1000.0) {
1599#ifdef BNC_DEBUG_BCEP
1600 emit(newMessage(QString("%1: Block %2 (%3) SQRT_A %4 m!")
1601 .arg(_staID).arg(1042,4).arg(eph._prn.toString().c_str())
1602 .arg(eph._sqrt_A,10,'F',3).toLatin1(), true));
1603#endif
1604 return false;
1605 }
1606 GETBITS(i, 17)
1607 i <<= 3;
1608 eph._TOEsec = i;
1609 eph._TOE.setBDS(i * 1000);
1610 GETFLOATSIGN(eph._Cic, 18, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1611 GETFLOATSIGN(eph._OMEGA0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1612 GETFLOATSIGN(eph._Cis, 18, 1.0 / (double )(1 << 30) / (double )(1 << 1))
1613 GETFLOATSIGN(eph._i0, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1614 GETFLOATSIGN(eph._Crc, 18, 1.0 / (double )(1 << 6))
1615 GETFLOATSIGN(eph._omega, 32, R2R_PI/(double)(1<<30)/(double)(1<<1))
1616 GETFLOATSIGN(eph._OMEGADOT, 24, R2R_PI/(double)(1<<30)/(double)(1<<13))
1617 GETFLOATSIGN(eph._TGD1, 10, 0.0000000001)
1618 GETFLOATSIGN(eph._TGD2, 10, 0.0000000001)
1619 GETBITS(eph._SatH1, 1)
1620
1621 eph._TOT = 0.9999E9;
1622 emit newBDSEph(eph);
1623 decoded = true;
1624 }
1625 return decoded;
1626}
1627
1628//
1629////////////////////////////////////////////////////////////////////////////
1630bool RTCM3Decoder::DecodeAntennaReceiver(unsigned char* data, int size) {
1631 char *antenna;
1632 char *antserialnum;
1633 char *receiver;
1634 char *recfirmware;
1635 char *recserialnum;
1636 int type;
1637 int antsernum = -1;
1638 int antnum = -1;
1639 int recnum = -1;
1640 int recsernum = -1;
1641 int recfirnum = -1;
1642 uint64_t numbits = 0, bitfield = 0;
1643
1644 data += 3; /* header*/
1645 size -= 6; /* header + crc */
1646
1647 GETBITS(type, 12)
1648 SKIPBITS(12) /* reference station ID */
1649 GETSTRING(antnum, antenna)
1650 if ((antnum > -1 && antnum < 265) &&
1651 (_antType.empty() || strncmp(_antType.back().descriptor, antenna, recnum) != 0)) {
1652 _antType.push_back(t_antInfo());
1653 memcpy(_antType.back().descriptor, antenna, antnum);
1654 _antType.back().descriptor[antnum] = 0;
1655 }
1656 SKIPBITS(8) /* antenna setup ID */
1657 if (type == 1008 || type == 1033 ) {
1658 GETSTRING(antsernum, antserialnum)
1659 if ((antsernum > -1 && antsernum < 265)) {
1660 memcpy(_antType.back().serialnumber, antserialnum, antsernum);
1661 _antType.back().serialnumber[antsernum] = 0;
1662 }
1663 }
1664
1665 if (type == 1033) {
1666 GETSTRING(recnum, receiver)
1667 GETSTRING(recfirnum, recfirmware)
1668 GETSTRING(recsernum, recserialnum)
1669 if ((recnum > -1 && recnum < 265) &&
1670 (_recType.empty() || strncmp(_recType.back().descriptor, receiver, recnum) != 0)) {
1671 _recType.push_back(t_recInfo());
1672 memcpy(_recType.back().descriptor, receiver, recnum);
1673 _recType.back().descriptor[recnum] = 0;
1674 if (recfirnum > -1 && recfirnum < 265) {
1675 memcpy(_recType.back().firmware, recfirmware, recfirnum);
1676 _recType.back().firmware[recfirnum] = 0;
1677 }
1678 if (recsernum > -1 && recsernum < 265) {
1679 memcpy(_recType.back().serialnumber, recserialnum, recsernum);
1680 _recType.back().serialnumber[recsernum] = 0;
1681 }
1682 }
1683 }
1684 return true;
1685}
1686
1687//
1688////////////////////////////////////////////////////////////////////////////
1689bool RTCM3Decoder::DecodeAntennaPosition(unsigned char* data, int size) {
1690 int type;
1691 uint64_t numbits = 0, bitfield = 0;
1692 double x, y, z;
1693
1694 data += 3; /* header */
1695 size -= 6; /* header + crc */
1696
1697 GETBITS(type, 12)
1698 _antList.push_back(t_antRefPoint());
1699 _antList.back().type = t_antRefPoint::ARP;
1700 SKIPBITS(22)
1701 GETBITSSIGN(x, 38)
1702 _antList.back().xx = x * 1e-4;
1703 SKIPBITS(2)
1704 GETBITSSIGN(y, 38)
1705 _antList.back().yy = y * 1e-4;
1706 SKIPBITS(2)
1707 GETBITSSIGN(z, 38)
1708 _antList.back().zz = z * 1e-4;
1709 if (type == 1006)
1710 {
1711 double h;
1712 GETBITS(h, 16)
1713 _antList.back().height = h * 1e-4;
1714 _antList.back().height_f = true;
1715 }
1716 _antList.back().message = type;
1717
1718 return true;
1719}
1720
1721//
1722////////////////////////////////////////////////////////////////////////////
1723t_irc RTCM3Decoder::Decode(char* buffer, int bufLen, vector<string>& errmsg) {
1724 bool decoded = false;
1725
1726 errmsg.clear();
1727
1728 while (bufLen && _MessageSize < sizeof(_Message)) {
1729 int l = sizeof(_Message) - _MessageSize;
1730 if (l > bufLen)
1731 l = bufLen;
1732 memcpy(_Message + _MessageSize, buffer, l);
1733 _MessageSize += l;
1734 bufLen -= l;
1735 buffer += l;
1736 int id;
1737 while ((id = GetMessage())) {
1738 /* reset station ID for file loading as it can change */
1739 if (_rawFile)
1740 _staID = _rawFile->staID();
1741 /* store the id into the list of loaded blocks */
1742 _typeList.push_back(id);
1743
1744 /* SSR I+II data handled in another function, already pass the
1745 * extracted data block. That does no harm, as it anyway skip everything
1746 * else. */
1747 if ((id >= 1057 && id <= 1068) ||
1748 (id >= 1240 && id <= 1270) ||
1749 (id == 4076)) {
1750 if (!_coDecoders.contains(_staID.toLatin1())) {
1751 _coDecoders[_staID.toLatin1()] = new RTCM3coDecoder(_staID);
1752 if (id == 4076) {
1753 _coDecoders[_staID.toLatin1()]->initSsrFormatType(RTCM3coDecoder::IGSssr);
1754 }
1755 else {
1756 _coDecoders[_staID.toLatin1()]->initSsrFormatType(RTCM3coDecoder::RTCMssr);
1757 }
1758 }
1759 RTCM3coDecoder* coDecoder = _coDecoders[_staID.toLatin1()];
1760 if (coDecoder->Decode(reinterpret_cast<char *>(_Message), _BlockSize, errmsg) == success) {
1761 decoded = true;
1762 }
1763 }
1764 else if (id >= 1070 && id <= 1237) { /* MSM */
1765 if (DecodeRTCM3MSM(_Message, _BlockSize))
1766 decoded = true;
1767 }
1768 else {
1769 switch (id) {
1770 case 1001:
1771 case 1003:
1772 emit(newMessage(QString("%1: Block %2 contain partial data! Ignored!")
1773 .arg(_staID).arg(id).toLatin1(), true));
1774 break; /* no use decoding partial data ATM, remove break when data can be used */
1775 case 1002:
1776 case 1004:
1777 if (DecodeRTCM3GPS(_Message, _BlockSize))
1778 decoded = true;
1779 break;
1780 case 1009:
1781 case 1011:
1782 emit(newMessage(QString("%1: Block %2 contain partial data! Ignored!")
1783 .arg(_staID).arg(id).toLatin1(), true));
1784 break; /* no use decoding partial data ATM, remove break when data can be used */
1785 case 1010:
1786 case 1012:
1787 if (DecodeRTCM3GLONASS(_Message, _BlockSize))
1788 decoded = true;
1789 break;
1790 case 1019:
1791 if (DecodeGPSEphemeris(_Message, _BlockSize))
1792 decoded = true;
1793 break;
1794 case 1020:
1795 if (DecodeGLONASSEphemeris(_Message, _BlockSize))
1796 decoded = true;
1797 break;
1798 case 1043:
1799 if (DecodeSBASEphemeris(_Message, _BlockSize))
1800 decoded = true;
1801 break;
1802 case 1044:
1803 if (DecodeQZSSEphemeris(_Message, _BlockSize))
1804 decoded = true;
1805 break;
1806 case 1041:
1807 if (DecodeIRNSSEphemeris(_Message, _BlockSize))
1808 decoded = true;
1809 break;
1810 case 1045:
1811 case 1046:
1812 if (_staID.contains("AIRA") || _staID.contains("STK2") ||
1813 _staID.contains("CCJ2") || _staID.contains("SYOG")) {
1814 emit(newMessage(QString("%1: Block temporary %2 from JAXA RTKLIB encoded stations!")
1815 .arg(_staID).arg(id).toLatin1(), true));
1816 break;
1817 }
1818 if (DecodeGalileoEphemeris(_Message, _BlockSize))
1819 decoded = true;
1820 break;
1821 case 1042:
1822 if (DecodeBDSEphemeris(_Message, _BlockSize))
1823 decoded = true;
1824 break;
1825 case 1007:
1826 case 1008:
1827 case 1033:
1828 DecodeAntennaReceiver(_Message, _BlockSize);
1829 break;
1830 case 1005:
1831 case 1006:
1832 DecodeAntennaPosition(_Message, _BlockSize);
1833 break;
1834 }
1835 }
1836 }
1837 }
1838 return decoded ? success : failure;
1839}
1840;
1841
1842//
1843////////////////////////////////////////////////////////////////////////////
1844uint32_t RTCM3Decoder::CRC24(long size, const unsigned char *buf) {
1845 uint32_t crc = 0;
1846 int ii;
1847 while (size--) {
1848 crc ^= (*buf++) << (16);
1849 for (ii = 0; ii < 8; ii++) {
1850 crc <<= 1;
1851 if (crc & 0x1000000)
1852 crc ^= 0x01864cfb;
1853 }
1854 }
1855 return crc;
1856}
1857
1858//
1859////////////////////////////////////////////////////////////////////////////
1860int RTCM3Decoder::GetMessage(void) {
1861 unsigned char *m, *e;
1862 int i;
1863
1864 m = _Message + _SkipBytes;
1865 e = _Message + _MessageSize;
1866 _NeedBytes = _SkipBytes = 0;
1867 while (e - m >= 3) {
1868 if (m[0] == 0xD3) {
1869 _BlockSize = ((m[1] & 3) << 8) | m[2];
1870 if (e - m >= static_cast<int>(_BlockSize + 6)) {
1871 if (static_cast<uint32_t>((m[3 + _BlockSize] << 16)
1872 | (m[3 + _BlockSize + 1] << 8)
1873 | (m[3 + _BlockSize + 2])) == CRC24(_BlockSize + 3, m)) {
1874 _BlockSize += 6;
1875 _SkipBytes = _BlockSize;
1876 break;
1877 }
1878 else
1879 ++m;
1880 }
1881 else {
1882 _NeedBytes = _BlockSize;
1883 break;
1884 }
1885 }
1886 else
1887 ++m;
1888 }
1889 if (e - m < 3)
1890 _NeedBytes = 3;
1891
1892 /* copy buffer to front */
1893 i = m - _Message;
1894 if (i && m < e)
1895 memmove(_Message, m, static_cast<size_t>(_MessageSize - i));
1896 _MessageSize -= i;
1897
1898 return !_NeedBytes ? ((_Message[3] << 4) | (_Message[4] >> 4)) : 0;
1899}
1900
1901// Time of Corrections
1902//////////////////////////////////////////////////////////////////////////////
1903int RTCM3Decoder::corrGPSEpochTime() const {
1904 return
1905 _coDecoders.size() > 0 ?
1906 _coDecoders.begin().value()->corrGPSEpochTime() : -1;
1907}
Note: See TracBrowser for help on using the repository browser.