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

Last change on this file since 11141 was 11141, checked in by stuerze, 4 weeks ago

roll-over handling for Galileo and BDS in RTCM3Decoder added

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