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

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

ephemeris checks + debugging output added

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