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

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

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

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