source: ntrip/trunk/BNC/src/RTCM3/RTCM3coDecoder.cpp@ 11074

Last change on this file since 11074 was 11074, checked in by stuerze, 33 hours ago

update test suite and further findings

File size: 55.2 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
8// http://www.fsv.cvut.cz
9//
10// Email: euref-ip@bkg.bund.de
11//
12// This program is free software; you can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation, version 2.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: RTCM3coDecoder
30 *
31 * Purpose: RTCM3 Clock Orbit Decoder
32 *
33 * Author: L. Mervart
34 *
35 * Created: 05-May-2008
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <stdio.h>
42#include <math.h>
43#include <climits>
44
45#include "RTCM3coDecoder.h"
46#include "bncutils.h"
47#include "bncrinex.h"
48#include "bnccore.h"
49#include "bncsettings.h"
50#include "bnctime.h"
51
52using namespace std;
53
54// Constructor
55////////////////////////////////////////////////////////////////////////////
56RTCM3coDecoder::RTCM3coDecoder(const QString& staID) {
57
58 _staID = staID;
59
60 // File Output
61 // -----------
62 bncSettings settings;
63 QString path = settings.value("corrPath").toString();
64 if (!path.isEmpty()) {
65 expandEnvVar(path);
66 if ( path.length() > 0 && path[path.length()-1] != QDir::separator() ) {
67 path += QDir::separator();
68 }
69 _fileNameSkl = path + staID;
70 }
71 _out = 0;
72
73 Qt::ConnectionType conType = BNC_CORE->decoderConnectionType();
74 connect(this, SIGNAL(newOrbCorrections(QList<t_orbCorr>)),
75 BNC_CORE, SLOT(slotNewOrbCorrections(QList<t_orbCorr>)), conType);
76
77 connect(this, SIGNAL(newClkCorrections(QList<t_clkCorr>)),
78 BNC_CORE, SLOT(slotNewClkCorrections(QList<t_clkCorr>)), conType);
79
80 connect(this, SIGNAL(newCodeBiases(QList<t_satCodeBias>)),
81 BNC_CORE, SLOT(slotNewCodeBiases(QList<t_satCodeBias>)), conType);
82
83 connect(this, SIGNAL(newPhaseBiases(QList<t_satPhaseBias>)),
84 BNC_CORE, SLOT(slotNewPhaseBiases(QList<t_satPhaseBias>)), conType);
85
86 connect(this, SIGNAL(newTec(t_vTec)),
87 BNC_CORE, SLOT(slotNewTec(t_vTec)), conType);
88
89 connect(this, SIGNAL(newMetaData(t_metaData)),
90 BNC_CORE, SLOT(slotNewMetaData(t_metaData)), conType);
91
92 connect(this, SIGNAL(newSatAntennas(QList<t_satAntenna>)),
93 BNC_CORE, SLOT(slotNewSatAntennas(QList<t_satAntenna>)), conType);
94
95 connect(this, SIGNAL(providerIDChanged(QString)),
96 BNC_CORE, SIGNAL(providerIDChanged(QString)), conType);
97
98 connect(this, SIGNAL(newMessage(QByteArray,bool)),
99 BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
100
101 reset();
102
103 _providerID[0] = -1;
104 _providerID[1] = -1;
105 _providerID[2] = -1;
106
107 for (unsigned s = 0; s < CLOCKORBIT_SATNUM; s++) {
108 _antennaReceived[s] = false;
109 _antennaIODKnown[s] = false;
110 _antennaIODProvider[s] = 0;
111 _antennaIODCur[s] = 0;
112 _antennaIODPrev[s] = 0;
113 }
114 for (unsigned i = 0; i < CLOCKORBIT_COUNTSAT; i++) {
115 _antennaSentProviderID[i] = 0;
116 _antennaSentIOD[i] = 0; // meaningless while _antennaSentTime[i] is invalid ("never sent")
117 }
118
119 _stateSnapshot = new t_stateSnapshot;
120 _ssrCorr = 0;
121
122}
123
124// Destructor
125////////////////////////////////////////////////////////////////////////////
126RTCM3coDecoder::~RTCM3coDecoder() {
127 delete _out;
128 delete _ssrCorr;
129 delete _stateSnapshot;
130 _IODs.clear();
131 _orbCorrections.clear();
132 _clkCorrections.clear();
133 _lastClkCorrections.clear();
134 _codeBiases.clear();
135 _phaseBiases.clear();
136 _vTecMap.clear();
137 _metaDataMap.clear();
138 _satAntennas.clear();
139}
140
141//
142////////////////////////////////////////////////////////////////////////////
143void RTCM3coDecoder::reset(bool resetPhaseBias) {
144 memset(&_clkOrb, 0, sizeof(_clkOrb));
145 memset(&_codeBias, 0, sizeof(_codeBias));
146 if (resetPhaseBias) {
147 memset(&_phaseBias, 0, sizeof(_phaseBias));
148 for (unsigned s = 0; s < CLOCKORBIT_SATNUM; s++) {
149 _phaseBiasSentEpoch[s] = UINT_MAX; // "never sent"
150 }
151 }
152 memset(&_vTEC, 0, sizeof(_vTEC));
153}
154
155// Reopen Output File
156////////////////////////////////////////////////////////////////////////
157void RTCM3coDecoder::reopen() {
158
159 if (!_fileNameSkl.isEmpty()) {
160
161 bncSettings settings;
162
163 QDateTime datTim = currentDateAndTimeGPS();
164
165 QString hlpStr = bncRinex::nextEpochStr(datTim,
166 settings.value("corrIntr").toString(), 3);
167
168 QString cntStr = (_fileNameSkl.contains("ION")) ? "_ION.ssr" : "_MC.ssr";
169
170 QString fileNameHlp = _fileNameSkl +
171 "_S_" + // stream
172 QString("%1").arg(datTim.date().year()) +
173 QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
174 hlpStr + // HM_period
175 cntStr; // mixed ION or CLK
176
177 if (_fileName == fileNameHlp) {
178 return;
179 }
180 else {
181 _fileName = fileNameHlp;
182 }
183
184 delete _out;
185 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
186 _out = new ofstream( _fileName.toLatin1().data(), ios_base::out | ios_base::app );
187 }
188 else {
189 _out = new ofstream( _fileName.toLatin1().data() );
190 }
191 }
192}
193
194//
195////////////////////////////////////////////////////////////////////////////
196t_irc RTCM3coDecoder::Decode(char* buffer, int bufLen, vector<string>& errmsg) {
197
198 errmsg.clear();
199
200 _buffer.append(QByteArray(buffer,bufLen));
201
202 t_irc retCode = failure;
203
204 while(_buffer.size()) {
205
206 // save state
207 memcpy(&_stateSnapshot->clkOrb, &_clkOrb, sizeof(_clkOrb));
208 memcpy(&_stateSnapshot->codeBias, &_codeBias, sizeof(_codeBias));
209 memcpy(&_stateSnapshot->phaseBias, &_phaseBias, sizeof(_phaseBias));
210 memcpy(&_stateSnapshot->vTEC, &_vTEC, sizeof(_vTEC));
211 memcpy(&_stateSnapshot->metaData, &_metaData, sizeof(_metaData));
212 memcpy(&_stateSnapshot->antenna, &_antenna, sizeof(_antenna));
213
214 // _antenna persists across messages, so its content alone can't tell
215 // whether a Satellite Antenna message arrived in this frame (an unchanged
216 // retransmission looks identical). Clear messageType[] as a marker: the
217 // COBOFS_SATANT decoder sets it (always non-zero) for each system it
218 // decodes. Restored with the snapshot if the frame turns out incomplete.
219 for (unsigned s = 0; s < CLOCKORBIT_SATNUM; s++) {
220 _antenna.messageType[s] = 0;
221 }
222
223 int bytesused = 0;
224
225 // message type of the frame at the start of the buffer (RTCM number,
226 // IGS-SSR 4076: 4076000 + subtype)
227 int msgType = -1;
228 if (_buffer.size() >= 6 && (unsigned char)_buffer[0] == 0xD3) {
229 const unsigned char* bb = reinterpret_cast<const unsigned char*>(_buffer.constData());
230 msgType = (bb[3] << 4) | (bb[4] >> 4);
231 if (msgType == 4076) {
232 msgType = 4076000 + (((bb[4] & 0x01) << 7) | (bb[5] >> 1));
233 }
234 }
235
236 GCOB_RETURN irc = _ssrCorr->GetSSR(&_clkOrb, &_codeBias, &_vTEC, &_phaseBias, &_metaData, &_antenna,
237 _buffer.data(), _buffer.size(), &bytesused);
238
239 if (irc <= -30) { // not enough data - restore state and exit loop
240 memcpy(&_clkOrb, &_stateSnapshot->clkOrb, sizeof(_clkOrb));
241 memcpy(&_codeBias, &_stateSnapshot->codeBias, sizeof(_codeBias));
242 memcpy(&_phaseBias, &_stateSnapshot->phaseBias, sizeof(_phaseBias));
243 memcpy(&_vTEC, &_stateSnapshot->vTEC, sizeof(_vTEC));
244 memcpy(&_metaData, &_stateSnapshot->metaData, sizeof(_metaData));
245 memcpy(&_antenna, &_stateSnapshot->antenna, sizeof(_antenna));
246 break;
247 }
248
249 else if (irc < 0) { // error - skip this message (or 1 byte if the
250 // frame itself couldn't be recognized) and retry
251 if (irc != GCOBR_UNKNOWNTYPE) {
252 // A recognized-but-unimplemented message (e.g. Tropospheric or
253 // Regional Ionospheric Correction) leaves _clkOrb/_codeBias/
254 // _phaseBias/_vTEC untouched, and bytesused is already reliably set
255 // from its CRC-validated frame length, so there is nothing to
256 // discard. Every other error code may have left inconsistent
257 // partial state (e.g. mid-satellite-loop) or an unreliable frame
258 // boundary, so reset defensively there. Without this, streams with
259 // frequent unimplemented messages (e.g. dense grid-based Regional
260 // Ionospheric traffic) would wipe unrelated, still-valid orbit/
261 // clock/bias/phase-bias state every time one is skipped.
262 reset();
263 }
264 _buffer = _buffer.mid(bytesused ? bytesused : 1);
265 }
266
267 else { // OK or MESSAGEFOLLOWS
268 _buffer = _buffer.mid(bytesused);
269
270 if (irc == GCOBR_OK || irc == GCOBR_MESSAGEFOLLOWS ) {
271 // Latch the reception until sendResults() consumes it - it may not
272 // run for this frame if _lastTime is still invalid.
273 for (unsigned s = 0; s < CLOCKORBIT_SATNUM; s++) {
274 if (_antenna.messageType[s] != 0) {
275 _antennaReceived[s] = true;
276 checkAntennaIOD(s);
277 }
278 }
279 setEpochTime(); // sets _lastTime
280
281 if (_lastTime.valid()) {
282 reopen();
283 checkProviderID();
284 sendResults();
285 // Pass on the epoch as soon as it is complete, not only when the
286 // next epoch arrives (one update interval later): complete when
287 // all message types of the previous epoch have arrived with
288 // Multiple Message Indicator 0. Consumers (PPP, combination) must
289 // not see an epoch partly, e.g. new clocks with old orbits.
290 if (irc == GCOBR_OK) {
291 checkEpochComplete(msgType);
292 }
293 retCode = success;
294 }
295 else {
296 emit newMessage("RTCM3coDecoder: _lastTime invalid: " + _staID.toLatin1(), true);
297 retCode = failure;
298 }
299 // Keep _phaseBias intact: an Extended Phase Bias message (COBOFS_PBEXT)
300 // arriving later needs to correlate against the satellite/signal list
301 // just published by this Phase Bias message. clock_orbit_rtcm_new.cpp's
302 // COBOFS_PBIAS handling resets pb->NumberOfSat[s] itself before decoding
303 // a fresh message, so this doesn't cause stale data to accumulate.
304 reset(false);
305 }
306 }
307 }
308
309 return retCode;
310}
311
312//
313////////////////////////////////////////////////////////////////////////////
314void RTCM3coDecoder::sendResults() {
315
316 // Orbit and clock corrections of all satellites
317 // ---------------------------------------------
318 for (unsigned ii = 0; ii < CLOCKORBIT_NUMGPS
319 + CLOCKORBIT_NUMGLONASS
320 + CLOCKORBIT_NUMGALILEO
321 + CLOCKORBIT_NUMQZSS
322 + CLOCKORBIT_NUMSBAS
323 + _clkOrb.NumberOfSat[CLOCKORBIT_SATBDS];
324 ii++) {
325 if (corrIsOutOfRange(_clkOrb.Sat[ii])) {
326 continue;
327 }
328 char sys = ' ';
329 int num = _clkOrb.Sat[ii].ID;
330 int flag = 0; // to force NAV type usage according SSR standard
331 if (ii < _clkOrb.NumberOfSat[CLOCKORBIT_SATGPS]) {
332 sys = 'G';
333 flag = t_eph::LNAV;
334 }
335 else if (ii >= CLOCKORBIT_OFFSETGLONASS &&
336 ii < CLOCKORBIT_OFFSETGLONASS + _clkOrb.NumberOfSat[CLOCKORBIT_SATGLONASS]) {
337 sys = 'R';
338 flag = t_eph::FDMA_M;
339 }
340 else if (ii >= CLOCKORBIT_OFFSETGALILEO &&
341 ii < CLOCKORBIT_OFFSETGALILEO + _clkOrb.NumberOfSat[CLOCKORBIT_SATGALILEO]) {
342 sys = 'E';
343 flag = t_eph::INAV;
344 }
345 else if (ii >= CLOCKORBIT_OFFSETQZSS &&
346 ii < CLOCKORBIT_OFFSETQZSS + _clkOrb.NumberOfSat[CLOCKORBIT_SATQZSS]) {
347 sys = 'J';
348 flag = t_eph::LNAV;
349 }
350 else if (ii >= CLOCKORBIT_OFFSETSBAS &&
351 ii < CLOCKORBIT_OFFSETSBAS + _clkOrb.NumberOfSat[CLOCKORBIT_SATSBAS]) {
352 sys = 'S';
353 flag = t_eph::SBASL1;
354 }
355 else if (ii >= CLOCKORBIT_OFFSETBDS &&
356 ii < CLOCKORBIT_OFFSETBDS + _clkOrb.NumberOfSat[CLOCKORBIT_SATBDS]) {
357 sys = 'C';
358 if (num < 6) {// GEO
359 flag = t_eph::D2;
360 }
361 else if (num > 58 && num < 63) { // GEO
362 flag = t_eph::D2;
363 }
364 else {
365 flag = t_eph::D1;
366 }
367 }
368 else {
369 continue;
370 }
371
372 // Orbit correction
373 // ----------------
374 if ( _clkOrb.messageType == _ssrCorr->COTYPE_GPSCOMBINED ||
375 _clkOrb.messageType == _ssrCorr->COTYPE_GLONASSCOMBINED ||
376 _clkOrb.messageType == _ssrCorr->COTYPE_GALILEOCOMBINED ||
377 _clkOrb.messageType == _ssrCorr->COTYPE_QZSSCOMBINED ||
378 _clkOrb.messageType == _ssrCorr->COTYPE_SBASCOMBINED ||
379 _clkOrb.messageType == _ssrCorr->COTYPE_BDSCOMBINED ||
380 _clkOrb.messageType == _ssrCorr->COTYPE_GPSORBIT ||
381 _clkOrb.messageType == _ssrCorr->COTYPE_GLONASSORBIT ||
382 _clkOrb.messageType == _ssrCorr->COTYPE_GALILEOORBIT ||
383 _clkOrb.messageType == _ssrCorr->COTYPE_QZSSORBIT ||
384 _clkOrb.messageType == _ssrCorr->COTYPE_SBASORBIT ||
385 _clkOrb.messageType == _ssrCorr->COTYPE_BDSORBIT ) {
386
387 t_orbCorr orbCorr;
388 orbCorr._prn.set(sys, num, flag);
389 checkPrnRange(orbCorr._prn);
390 orbCorr._staID = _staID.toStdString();
391 orbCorr._iod = _clkOrb.Sat[ii].IOD;
392 orbCorr._time = _lastTime;
393 orbCorr._updateInt = _clkOrb.UpdateInterval;
394 orbCorr._system = sys;
395 orbCorr._xr[0] = _clkOrb.Sat[ii].Orbit.DeltaRadial;
396 orbCorr._xr[1] = _clkOrb.Sat[ii].Orbit.DeltaAlongTrack;
397 orbCorr._xr[2] = _clkOrb.Sat[ii].Orbit.DeltaCrossTrack;
398 orbCorr._dotXr[0] = _clkOrb.Sat[ii].Orbit.DotDeltaRadial;
399 orbCorr._dotXr[1] = _clkOrb.Sat[ii].Orbit.DotDeltaAlongTrack;
400 orbCorr._dotXr[2] = _clkOrb.Sat[ii].Orbit.DotDeltaCrossTrack;
401 orbCorr._ssrFormat = (_type == RTCMssr) ? ssrRtcmOld :
402 (_type == RTCMnewssr) ? ssrRtcmNew : ssrUnknown;
403
404 _orbCorrections[_lastTime].append(orbCorr);
405
406 _IODs[orbCorr._prn] = _clkOrb.Sat[ii].IOD;
407 }
408
409 // Clock Corrections
410 // -----------------
411 if ( _clkOrb.messageType == _ssrCorr->COTYPE_GPSCOMBINED ||
412 _clkOrb.messageType == _ssrCorr->COTYPE_GLONASSCOMBINED ||
413 _clkOrb.messageType == _ssrCorr->COTYPE_GALILEOCOMBINED ||
414 _clkOrb.messageType == _ssrCorr->COTYPE_QZSSCOMBINED ||
415 _clkOrb.messageType == _ssrCorr->COTYPE_SBASCOMBINED ||
416 _clkOrb.messageType == _ssrCorr->COTYPE_BDSCOMBINED ||
417 _clkOrb.messageType == _ssrCorr->COTYPE_GPSCLOCK ||
418 _clkOrb.messageType == _ssrCorr->COTYPE_GLONASSCLOCK ||
419 _clkOrb.messageType == _ssrCorr->COTYPE_GALILEOCLOCK ||
420 _clkOrb.messageType == _ssrCorr->COTYPE_QZSSCLOCK ||
421 _clkOrb.messageType == _ssrCorr->COTYPE_SBASCLOCK ||
422 _clkOrb.messageType == _ssrCorr->COTYPE_BDSCLOCK) {
423
424 t_clkCorr clkCorr;
425 clkCorr._prn.set(sys, _clkOrb.Sat[ii].ID, flag);
426 checkPrnRange(clkCorr._prn);
427 clkCorr._staID = _staID.toStdString();
428 clkCorr._time = _lastTime;
429 clkCorr._updateInt = _clkOrb.UpdateInterval;
430 clkCorr._dClk = _clkOrb.Sat[ii].Clock.DeltaA0 / t_CST::c;
431 clkCorr._dotDClk = _clkOrb.Sat[ii].Clock.DeltaA1 / t_CST::c;
432 clkCorr._dotDotDClk = _clkOrb.Sat[ii].Clock.DeltaA2 / t_CST::c;
433
434 _lastClkCorrections[clkCorr._prn] = clkCorr;
435
436 if (_IODs.contains(clkCorr._prn)) {
437 clkCorr._iod = _IODs[clkCorr._prn];
438 _clkCorrections[_lastTime].append(clkCorr);
439 }
440 }
441
442 // High-Resolution Clocks
443 // ----------------------
444 if ( _clkOrb.messageType == _ssrCorr->COTYPE_GPSHR ||
445 _clkOrb.messageType == _ssrCorr->COTYPE_GLONASSHR ||
446 _clkOrb.messageType == _ssrCorr->COTYPE_GALILEOHR ||
447 _clkOrb.messageType == _ssrCorr->COTYPE_QZSSHR ||
448 _clkOrb.messageType == _ssrCorr->COTYPE_SBASHR ||
449 _clkOrb.messageType == _ssrCorr->COTYPE_BDSHR) {
450 t_prn prn(sys, _clkOrb.Sat[ii].ID, flag);
451 if (_lastClkCorrections.contains(prn)) {
452 t_clkCorr clkCorr;
453 clkCorr = _lastClkCorrections[prn];
454 clkCorr._time = _lastTime;
455 clkCorr._updateInt = _clkOrb.UpdateInterval;
456 clkCorr._dClk += _clkOrb.Sat[ii].hrclock / t_CST::c;
457 if (_IODs.contains(clkCorr._prn)) {
458 clkCorr._iod = _IODs[clkCorr._prn];
459 _clkCorrections[_lastTime].append(clkCorr);
460 }
461 }
462 }
463 }
464
465 // Code Biases
466 // -----------
467 for (unsigned ii = 0; ii < CLOCKORBIT_NUMGPS
468 + CLOCKORBIT_NUMGLONASS
469 + CLOCKORBIT_NUMGALILEO
470 + CLOCKORBIT_NUMQZSS
471 + CLOCKORBIT_NUMSBAS
472 + _codeBias.NumberOfSat[CLOCKORBIT_SATBDS];
473 ii++) {
474 char sys = ' ';
475 int num = _codeBias.Sat[ii].ID;
476 int flag = 0;
477 if (ii < _codeBias.NumberOfSat[CLOCKORBIT_SATGPS]) {
478 sys = 'G';
479 flag = t_eph::LNAV;
480 }
481 else if (ii >= CLOCKORBIT_OFFSETGLONASS &&
482 ii < CLOCKORBIT_OFFSETGLONASS + _codeBias.NumberOfSat[CLOCKORBIT_SATGLONASS]) {
483 sys = 'R';
484 flag = t_eph::FDMA_M;
485 }
486 else if (ii >= CLOCKORBIT_OFFSETGALILEO &&
487 ii < CLOCKORBIT_OFFSETGALILEO + _codeBias.NumberOfSat[CLOCKORBIT_SATGALILEO]) {
488 sys = 'E';
489 flag = t_eph::INAV;
490 }
491 else if (ii >= CLOCKORBIT_OFFSETQZSS &&
492 ii < CLOCKORBIT_OFFSETQZSS + _codeBias.NumberOfSat[CLOCKORBIT_SATQZSS]) {
493 sys = 'J';
494 flag = t_eph::LNAV;
495 }
496 else if (ii >= CLOCKORBIT_OFFSETSBAS &&
497 ii < CLOCKORBIT_OFFSETSBAS + _codeBias.NumberOfSat[CLOCKORBIT_SATSBAS]) {
498 sys = 'S';
499 flag = t_eph::SBASL1;
500 }
501 else if (ii >= CLOCKORBIT_OFFSETBDS &&
502 ii < CLOCKORBIT_OFFSETBDS + _codeBias.NumberOfSat[CLOCKORBIT_SATBDS]) {
503 sys = 'C';
504 if (num < 6) {// GEO
505 flag = t_eph::D2;
506 }
507 else if (num > 58 && num < 63) { // GEO
508 flag = t_eph::D2;
509 }
510 else {
511 flag = t_eph::D1;
512 }
513 }
514 else {
515 continue;
516 }
517 t_satCodeBias satCodeBias;
518 satCodeBias._prn.set(sys, num, flag);
519 checkPrnRange(satCodeBias._prn);
520 satCodeBias._staID = _staID.toStdString();
521 satCodeBias._time = _lastTime;
522 satCodeBias._updateInt = _codeBias.UpdateInterval;
523 satCodeBias._ssrIOD = _codeBias.SSRIOD;
524 satCodeBias._ssrProviderID = _codeBias.SSRProviderID;
525 for (unsigned jj = 0; jj < _codeBias.Sat[ii].NumberOfCodeBiases; jj++) {
526 const SsrCorr::CodeBias::BiasSat::CodeBiasEntry& biasEntry = _codeBias.Sat[ii].Biases[jj];
527 t_frqCodeBias frqCodeBias;
528 frqCodeBias._rnxType2ch.assign(_ssrCorr->codeTypeToRnxType(sys, biasEntry.Type));
529 frqCodeBias._value = biasEntry.Bias;
530 if (!frqCodeBias._rnxType2ch.empty()) {
531 satCodeBias._bias.push_back(frqCodeBias);
532 }
533 }
534 _codeBiases[_lastTime].append(satCodeBias);
535 }
536
537 // Phase Biases
538 // -----------
539 // _phaseBias is no longer wiped between messages (kept alive so a later
540 // Extended Phase Bias message can correlate against it - see
541 // COBOFS_PBEXT), so without this guard the block below would re-append
542 // the same system's satellites into the output on every other message
543 // decoded in between two actual phase-bias messages. Only emit a
544 // system's satellites once per epoch, tracked per system by comparing
545 // against the epoch we last actually sent for it.
546 bool phaseBiasFresh[CLOCKORBIT_SATNUM];
547 for (unsigned s = 0; s < CLOCKORBIT_SATNUM; s++) {
548 phaseBiasFresh[s] = _phaseBias.NumberOfSat[s] > 0 &&
549 _phaseBias.EpochTime[s] != _phaseBiasSentEpoch[s];
550 if (phaseBiasFresh[s]) {
551 _phaseBiasSentEpoch[s] = _phaseBias.EpochTime[s];
552 }
553 }
554 for (unsigned ii = 0; ii < CLOCKORBIT_NUMGPS
555 + CLOCKORBIT_NUMGLONASS
556 + CLOCKORBIT_NUMGALILEO
557 + CLOCKORBIT_NUMQZSS
558 + CLOCKORBIT_NUMSBAS
559 + _phaseBias.NumberOfSat[CLOCKORBIT_SATBDS];
560 ii++) {
561 char sys = ' ';
562 int num = _phaseBias.Sat[ii].ID;
563 int flag = 0;
564 if (ii < _phaseBias.NumberOfSat[CLOCKORBIT_SATGPS]) {
565 if (!phaseBiasFresh[CLOCKORBIT_SATGPS]) continue;
566 sys = 'G';
567 flag = t_eph::LNAV;
568 }
569 else if (ii >= CLOCKORBIT_OFFSETGLONASS &&
570 ii < CLOCKORBIT_OFFSETGLONASS + _phaseBias.NumberOfSat[CLOCKORBIT_SATGLONASS]) {
571 if (!phaseBiasFresh[CLOCKORBIT_SATGLONASS]) continue;
572 sys = 'R';
573 flag = t_eph::FDMA_M;
574 }
575 else if (ii >= CLOCKORBIT_OFFSETGALILEO &&
576 ii < CLOCKORBIT_OFFSETGALILEO + _phaseBias.NumberOfSat[CLOCKORBIT_SATGALILEO]) {
577 if (!phaseBiasFresh[CLOCKORBIT_SATGALILEO]) continue;
578 sys = 'E';
579 flag = t_eph::INAV;
580 }
581 else if (ii >= CLOCKORBIT_OFFSETQZSS &&
582 ii < CLOCKORBIT_OFFSETQZSS + _phaseBias.NumberOfSat[CLOCKORBIT_SATQZSS]) {
583 if (!phaseBiasFresh[CLOCKORBIT_SATQZSS]) continue;
584 sys = 'J';
585 flag = t_eph::LNAV;
586 }
587 else if (ii >= CLOCKORBIT_OFFSETSBAS &&
588 ii < CLOCKORBIT_OFFSETSBAS + _phaseBias.NumberOfSat[CLOCKORBIT_SATSBAS]) {
589 if (!phaseBiasFresh[CLOCKORBIT_SATSBAS]) continue;
590 sys = 'S';
591 flag = t_eph::SBASL1;
592 }
593 else if (ii >= CLOCKORBIT_OFFSETBDS &&
594 ii < CLOCKORBIT_OFFSETBDS + _phaseBias.NumberOfSat[CLOCKORBIT_SATBDS]) {
595 if (!phaseBiasFresh[CLOCKORBIT_SATBDS]) continue;
596 sys = 'C';
597 if (num < 6) {// GEO
598 flag = t_eph::D2;
599 }
600 else if (num > 58 && num < 63) { // GEO
601 flag = t_eph::D2;
602 }
603 else {
604 flag = t_eph::D1;
605 }
606 }
607 else {
608 continue;
609 }
610 t_satPhaseBias satPhaseBias;
611 satPhaseBias._prn.set(sys, num, flag);
612 checkPrnRange(satPhaseBias._prn);
613 satPhaseBias._staID = _staID.toStdString();
614 satPhaseBias._time = _lastTime;
615 satPhaseBias._updateInt = _phaseBias.UpdateInterval;
616 satPhaseBias._ssrIOD = _phaseBias.SSRIOD;
617 satPhaseBias._ssrProviderID = _phaseBias.SSRProviderID;
618 satPhaseBias._ssrFormat = (_type == RTCMssr) ? ssrRtcmOld :
619 (_type == RTCMnewssr) ? ssrRtcmNew : ssrUnknown;
620 if (satPhaseBias._ssrFormat == e_ssrFormat::ssrRtcmNew) {
621 satPhaseBias._satYawInfoInd = _phaseBias.SatelliteYawInformationIndicator;
622 satPhaseBias._extPBPhaseInd = _phaseBias.ExtendedPhaseBiasPropertyID;
623 }
624 else {
625 satPhaseBias._dispBiasConsistInd = _phaseBias.DispersiveBiasConsistencyIndicator;
626 satPhaseBias._MelbWuebConsistInd = _phaseBias.MWConsistencyIndicator;
627 }
628 satPhaseBias._yaw = _phaseBias.Sat[ii].YawAngle;
629 satPhaseBias._yawRate = _phaseBias.Sat[ii].YawRate;
630 for (unsigned jj = 0; jj < _phaseBias.Sat[ii].NumberOfPhaseBiases; jj++) {
631 const SsrCorr::PhaseBias::PhaseBiasSat::PhaseBiasEntry& biasEntry = _phaseBias.Sat[ii].Biases[jj];
632 t_frqPhaseBias frqPhaseBias;
633 frqPhaseBias._rnxType2ch.assign(_ssrCorr->codeTypeToRnxType(sys, biasEntry.Type));
634 frqPhaseBias._value = biasEntry.Bias;
635 frqPhaseBias._fixIndicator = biasEntry.IntegerIndicator;
636 if (satPhaseBias._ssrFormat == e_ssrFormat::ssrRtcmNew) {
637 if (satPhaseBias._extPBPhaseInd) {
638 frqPhaseBias._fixWideLaneIndicator = biasEntry.WidelaneGroupIndicator;
639 }
640 }
641 else {
642 frqPhaseBias._fixWideLaneIndicator = biasEntry.WidelaneGroupIndicator;
643 }
644 frqPhaseBias._jumpCounter = biasEntry.DiscontinuityCounter;
645 if (!frqPhaseBias._rnxType2ch.empty()) {
646 satPhaseBias._bias.push_back(frqPhaseBias);
647 }
648 }
649 _phaseBiases[_lastTime].append(satPhaseBias);
650 }
651
652 // Ionospheric Model
653 // -----------------
654 if (_vTEC.NumLayers > 0) {
655 _vTecMap[_lastTime]._time = _lastTime;
656 _vTecMap[_lastTime]._updateInt = _vTEC.UpdateInterval;
657 _vTecMap[_lastTime]._staID = _staID.toStdString();
658 for (unsigned ii = 0; ii < _vTEC.NumLayers; ii++) {
659 const SsrCorr::VTEC::IonoLayers& ionoLayer = _vTEC.Layers[ii];
660 t_vTecLayer layer;
661 layer._height = ionoLayer.Height;
662 layer._C.ReSize(ionoLayer.Degree+1, ionoLayer.Order+1);
663 layer._S.ReSize(ionoLayer.Degree+1, ionoLayer.Order+1);
664 for (unsigned iDeg = 0; iDeg <= ionoLayer.Degree; iDeg++) {
665 for (unsigned iOrd = 0; iOrd <= ionoLayer.Order; iOrd++) {
666 layer._C[iDeg][iOrd] = ionoLayer.Cosinus[iDeg][iOrd];
667 layer._S[iDeg][iOrd] = ionoLayer.Sinus[iDeg][iOrd];
668 }
669 }
670 _vTecMap[_lastTime]._layers.push_back(layer);
671 }
672 }
673
674 // Metadata (model correction information)
675 // ----------------------------------------
676 if (_metaData.NumEntries > 0) {
677 // Metadata carries no epoch field of its own (it is keyed here by
678 // _lastTime, inherited from whichever other message last set it), so a
679 // fresh, complete message must replace rather than accumulate onto
680 // whatever a previous message at the same _lastTime already stored.
681 _metaDataMap[_lastTime] = t_metaData();
682 _metaDataMap[_lastTime]._time = _lastTime;
683 _metaDataMap[_lastTime]._staID = _staID.toStdString();
684 _metaDataMap[_lastTime]._ssrIOD = _metaData.SSRIOD;
685 _metaDataMap[_lastTime]._providerID = _metaData.SSRProviderID;
686 _metaDataMap[_lastTime]._solutionID = _metaData.SSRSolutionID;
687 for (unsigned ii = 0; ii < _metaData.NumEntries; ii++) {
688 const SsrCorr::MetaData::ModelPart& part = _metaData.Entries[ii];
689 t_metaDataEntry entry;
690 entry._typeIndicator = part.TypeIndicator;
691 entry._applicationIndicator = part.ApplicationIndicator;
692 entry._nonDefaultIndicator = part.nonDefaultIndicator;
693 entry._nonDefaultIdentifier = part.nonDefaultIdentifier;
694 entry._dataIODIndicator = part.DataIODIndicator;
695 entry._dataIOD = part.DataIOD;
696 _metaDataMap[_lastTime]._entries.push_back(entry);
697 }
698 }
699
700 // Satellite Antenna corrections
701 // ------------------------------
702 // _antenna, like _metaData, carries no epoch field of its own and is never
703 // wiped by reset(), so each system's data persists across unrelated
704 // messages. Only a system for which an Antenna message was actually
705 // received (_antennaReceived, latched in Decode()) is considered, so
706 // persisted data is never re-stamped with a newer time.
707 //
708 // The SatelliteAntennaIOD is unique only per SSR Provider ID (DF414) and
709 // only within 64 days, and a client that has not received the stream for
710 // 64 days must discard cached antenna data (enforced downstream against
711 // t_satAntenna::_time, see ssrSatAntennaTrusted() in pppSatObs.cpp). So an
712 // unchanged (provider ID, IOD) retransmission is suppressed only if it was
713 // last emitted less than ANT_REFRESH_SEC ago. Re-emitting it after that
714 // keeps _time close to the last reception - not the first - so continuously
715 // received data never ages out. It also means a reception after a long
716 // gap is always emitted, even when the provider has legitimately reused
717 // the IOD for different content, and each .ssr file contains the antenna
718 // data at least once per refresh interval.
719 //
720 // This is tracked per satellite, not per system: providers may split a
721 // system's satellites across several messages with rotating satellite
722 // masks (DF394), all carrying the same IOD - a per-system check would
723 // emit only whichever subset happened to arrive first.
724 {
725 const double ANT_REFRESH_SEC = 3600.0;
726 struct SysInfo { unsigned sysIdx; char sysChar; unsigned numSat; unsigned offset; };
727 const SysInfo sysInfos[] = {
728 { CLOCKORBIT_SATGPS, 'G', CLOCKORBIT_NUMGPS, CLOCKORBIT_OFFSETGPS },
729 { CLOCKORBIT_SATGLONASS, 'R', CLOCKORBIT_NUMGLONASS, CLOCKORBIT_OFFSETGLONASS },
730 { CLOCKORBIT_SATGALILEO, 'E', CLOCKORBIT_NUMGALILEO, CLOCKORBIT_OFFSETGALILEO },
731 { CLOCKORBIT_SATQZSS, 'J', CLOCKORBIT_NUMQZSS, CLOCKORBIT_OFFSETQZSS },
732 { CLOCKORBIT_SATBDS, 'C', CLOCKORBIT_NUMBDS, CLOCKORBIT_OFFSETBDS },
733 };
734 for (const SysInfo& si : sysInfos) {
735 unsigned s = si.sysIdx;
736 if (!_antennaReceived[s]) {
737 continue; // no Antenna message received for this system since the last check
738 }
739 _antennaReceived[s] = false;
740 if (_antenna.SatelliteMask[s] == 0) {
741 continue; // no satellites in this system's antenna data
742 }
743 for (unsigned k = 0; k < si.numSat; k++) {
744 if (!((_antenna.SatelliteMask[s] >> (63 - k)) & 1ULL)) {
745 continue;
746 }
747 unsigned i = si.offset + k;
748 if (_antennaSentTime[i].valid() &&
749 _antenna.SSRProviderID[s] == _antennaSentProviderID[i] &&
750 _antenna.SatelliteAntennaIOD[s] == _antennaSentIOD[i] &&
751 _lastTime - _antennaSentTime[i] < ANT_REFRESH_SEC) {
752 continue; // unchanged retransmission, emitted recently
753 }
754 _antennaSentProviderID[i] = _antenna.SSRProviderID[s];
755 _antennaSentIOD[i] = _antenna.SatelliteAntennaIOD[s];
756 _antennaSentTime[i] = _lastTime;
757 int num = k + 1; // PRN within this system, DF394 MSB-first convention
758 int flag = 0;
759 switch (si.sysChar) {
760 case 'G': flag = t_eph::LNAV; break;
761 case 'R': flag = t_eph::FDMA_M; break;
762 case 'E': flag = t_eph::INAV; break;
763 case 'J': flag = t_eph::LNAV; break;
764 case 'C': flag = (num < 6 || (num > 58 && num < 63)) ? t_eph::D2 : t_eph::D1; break;
765 }
766
767 t_satAntenna satAntenna;
768 satAntenna._prn.set(si.sysChar, num, flag);
769 satAntenna._staID = _staID.toStdString();
770 satAntenna._time = _lastTime;
771 satAntenna._ssrProviderID = _antenna.SSRProviderID[s];
772 satAntenna._satelliteAntennaIOD = _antenna.SatelliteAntennaIOD[s];
773 satAntenna._phaseCenterInfoInd = _antenna.PhaseCenterInformationIndicator[s];
774 satAntenna._groupDelayInfoInd = _antenna.GroupDelayInformationIndicator[s];
775 satAntenna._nadirAngleDependentCorrInd = _antenna.NadirAngleDependentCorrectionIndicator[s];
776 satAntenna._maximumOffNadirAngle = _antenna.maximumOffNadirAngle[s];
777 satAntenna._nadirAngleRangeExtension = _antenna.NadirAngleDependentCorrectionRangeExtension[s];
778
779 const SsrCorr::Antenna::SatellitePart& satPart = _antenna.Sat[i];
780 for (unsigned f = 0; f < ANT_MAXFREQUENCIES; f++) {
781 if (!((satPart.GnssFrequencyMask >> (ANT_MAXFREQUENCIES - 1 - f)) & 1U)) {
782 continue;
783 }
784 t_frqAntenna frqAntenna;
785 frqAntenna._frqType = _ssrCorr->antFreqIndexToStr(si.sysChar, f);
786 if (frqAntenna._frqType.empty()) {
787 continue; // reserved/unmapped DF+018 bit position
788 }
789 frqAntenna._nadirCorrectionIndicator = satPart.Freq[f].NadirCorrectionIndicator;
790 frqAntenna._nadirCorrection = satPart.Freq[f].NadirCorrection;
791 if (satAntenna._nadirAngleDependentCorrInd) {
792 unsigned count = satAntenna._maximumOffNadirAngle + 1;
793 for (unsigned deg = 0; deg < count && deg < ANT_MAXNADIRDEGREES; deg++) {
794 frqAntenna._nadirAngleCorrection.push_back(satPart.Freq[f].NadirAngleCorrection[deg]);
795 }
796 }
797 satAntenna._freq.push_back(frqAntenna);
798 }
799 _satAntennas[_lastTime].append(satAntenna);
800 }
801 }
802 }
803
804 // Dump all older epochs
805 // ---------------------
806 dumpEpochs(false);
807}
808
809// Pass the current epoch on as soon as it is complete: every message type
810// due at this epoch has arrived with Multiple Message Indicator 0. A type is
811// due if its interval (learned from its previous epochs) has passed since
812// its last epoch; types missing for more than three intervals are no longer
813// expected. Until the intervals are known, and if a due type is missing,
814// the epoch is passed on when the next epoch arrives. Types arriving after
815// the epoch was passed on are passed on as soon as they are complete.
816////////////////////////////////////////////////////////////////////////////
817void RTCM3coDecoder::checkEpochComplete(int msgType) {
818 const bncTime& epoch = _lastTime;
819 if (_typeLast.contains(msgType)) {
820 if (!(_typeLast[msgType] < epoch)) {
821 if (epoch == _flushedEpoch) {
822 dumpEpochs(true); // repeated type of an epoch already passed on
823 }
824 return;
825 }
826 _typeInt[msgType] = epoch - _typeLast[msgType];
827 }
828 _typeLast[msgType] = epoch;
829
830 if (epoch == _flushedEpoch) {
831 dumpEpochs(true);
832 return;
833 }
834 bool complete = !_typeInt.isEmpty();
835 QMapIterator<int, double> it(_typeInt);
836 while (it.hasNext()) {
837 it.next();
838 double sinceLast = epoch - _typeLast[it.key()];
839 if (sinceLast > 0.0 && sinceLast >= it.value() - 0.1 && sinceLast <= 3.0 * it.value()) {
840 complete = false;
841 break;
842 }
843 }
844 if (complete) {
845 dumpEpochs(true);
846 _flushedEpoch = epoch;
847 }
848}
849
850// Emit and write the collected corrections of all epochs older than
851// _lastTime (all epochs if all is set, e.g. at the end of a replay)
852////////////////////////////////////////////////////////////////////////////
853void RTCM3coDecoder::dumpEpochs(bool all) {
854 QMutableMapIterator<bncTime, QList<t_orbCorr> > itOrb(_orbCorrections);
855 while (itOrb.hasNext()) {
856 itOrb.next();
857 if (all || itOrb.key() < _lastTime) {
858 emit newOrbCorrections(itOrb.value());
859 t_orbCorr::writeEpoch(_out, itOrb.value());
860 itOrb.remove();
861 }
862 }
863 QMutableMapIterator<bncTime, QList<t_clkCorr> > itClk(_clkCorrections);
864 while (itClk.hasNext()) {
865 itClk.next();
866 if (all || itClk.key() < _lastTime) {
867 emit newClkCorrections(itClk.value());
868 t_clkCorr::writeEpoch(_out, itClk.value());
869 itClk.remove();
870 }
871 }
872 QMutableMapIterator<bncTime, QList<t_satCodeBias> > itCB(_codeBiases);
873 while (itCB.hasNext()) {
874 itCB.next();
875 if (all || itCB.key() < _lastTime) {
876 emit newCodeBiases(itCB.value());
877 t_satCodeBias::writeEpoch(_out, itCB.value());
878 itCB.remove();
879 }
880 }
881 QMutableMapIterator<bncTime, QList<t_satPhaseBias> > itPB(_phaseBiases);
882 while (itPB.hasNext()) {
883 itPB.next();
884 if (all || itPB.key() < _lastTime) {
885 emit newPhaseBiases(itPB.value());
886 t_satPhaseBias::writeEpoch(_out, itPB.value());
887 itPB.remove();
888 }
889 }
890 QMutableMapIterator<bncTime, t_vTec> itTec(_vTecMap);
891 while (itTec.hasNext()) {
892 itTec.next();
893 if (all || itTec.key() < _lastTime) {
894 emit newTec(itTec.value());
895 t_vTec::write(_out, itTec.value());
896 itTec.remove();
897 }
898 }
899 QMutableMapIterator<bncTime, t_metaData> itMD(_metaDataMap);
900 while (itMD.hasNext()) {
901 itMD.next();
902 if (all || itMD.key() < _lastTime) {
903 emit newMetaData(itMD.value());
904 t_metaData::write(_out, itMD.value());
905 itMD.remove();
906 }
907 }
908 QMutableMapIterator<bncTime, QList<t_satAntenna> > itAnt(_satAntennas);
909 while (itAnt.hasNext()) {
910 itAnt.next();
911 if (all || itAnt.key() < _lastTime) {
912 emit newSatAntennas(itAnt.value());
913 t_satAntenna::writeEpoch(_out, itAnt.value());
914 itAnt.remove();
915 }
916 }
917 if (all && _out) {
918 _out->flush();
919 }
920}
921
922//
923////////////////////////////////////////////////////////////////////////////
924void RTCM3coDecoder::checkProviderID() {
925
926 if (_clkOrb.SSRProviderID == 0 && _clkOrb.SSRSolutionID == 0 && _clkOrb.SSRIOD == 0) {
927 return;
928 }
929
930 int newProviderID[3];
931 newProviderID[0] = _clkOrb.SSRProviderID;
932 newProviderID[1] = _clkOrb.SSRSolutionID;
933 newProviderID[2] = _clkOrb.SSRIOD;
934 QString newProviderIDStr = QString(" [SSR Provider ID: %1 SSR Solution ID: %2 SSR IOD: %3]: ")
935 .arg(newProviderID[0]).arg(newProviderID[1]).arg(newProviderID[2]);
936
937 bool alreadySet = false;
938 bool different = false;
939
940 for (unsigned ii = 0; ii < 3; ii++) {
941 if (_providerID[ii] != -1) {
942 alreadySet = true;
943 }
944 if (_providerID[ii] != newProviderID[ii]) {
945 different = true;
946 }
947 _providerID[ii] = newProviderID[ii];
948 }
949
950 if (alreadySet && different) {
951 emit newMessage("RTCM3coDecoder: SSR Provider or Service changed " + newProviderIDStr.toLatin1() + _staID.toLatin1(), true);
952 emit providerIDChanged(_staID);
953 }
954}
955
956// Check corrections
957////////////////////////////////////////////////////////////////////////////
958bool RTCM3coDecoder::corrIsOutOfRange(const SsrCorr::ClockOrbit::SatData& coSat) {
959
960 QString ssrParStr;
961 QString ssrParValue;
962 bool corrIsOutOfRange = false;
963
964 switch (_type) {
965 // ======== //
966 // IGS SSR //
967 // ======== //
968 case IGSssr:
969 if (coSat.Clock.DeltaA0 < -209.7151 ||
970 coSat.Clock.DeltaA0 > +209.7151) {
971 ssrParStr = "Clock::DeltaA0";
972 ssrParValue = QString::number(coSat.Clock.DeltaA0, 'f', 4);
973 corrIsOutOfRange = true;
974 }
975 if (coSat.Clock.DeltaA1 < -1.048575 ||
976 coSat.Clock.DeltaA1 > +1.048575) {
977 ssrParStr = "Clock::DeltaA1";
978 ssrParValue = QString::number(coSat.Clock.DeltaA1, 'f', 6);
979 corrIsOutOfRange = true;
980 }
981 if (coSat.Clock.DeltaA2 < -1.3421772 ||
982 coSat.Clock.DeltaA2 > +1.3421772) {
983 ssrParStr = "Clock::DeltaA2";
984 ssrParValue = QString::number(coSat.Clock.DeltaA2, 'f', 7);
985 corrIsOutOfRange = true;
986 }
987
988 if (coSat.Orbit.DeltaRadial < -209.7151 ||
989 coSat.Orbit.DeltaRadial > +209.7151) {
990 ssrParStr = "Orbit::DeltaRadial";
991 ssrParValue = QString::number(coSat.Orbit.DeltaRadial, 'f', 4);
992 corrIsOutOfRange = true;
993 }
994
995 if (coSat.Orbit.DeltaAlongTrack < -209.7148 ||
996 coSat.Orbit.DeltaAlongTrack > +209.7148) {
997 ssrParStr = "Orbit::DeltaAlongTrack";
998 ssrParValue = QString::number(coSat.Orbit.DeltaAlongTrack, 'f', 4);
999 corrIsOutOfRange = true;
1000 }
1001 if (coSat.Orbit.DeltaCrossTrack < -209.7148 ||
1002 coSat.Orbit.DeltaCrossTrack > +209.7148) {
1003 ssrParStr = "Orbit::DeltaCrossTrack";
1004 ssrParValue = QString::number(coSat.Orbit.DeltaCrossTrack, 'f', 4);
1005 corrIsOutOfRange = true;
1006 }
1007
1008 if (coSat.Orbit.DotDeltaRadial < -1.048575 ||
1009 coSat.Orbit.DotDeltaRadial > +1.048575) {
1010 ssrParStr = "Orbit::DotDeltaRadial";
1011 ssrParValue = QString::number(coSat.Orbit.DotDeltaRadial, 'f', 6);
1012 corrIsOutOfRange = true;
1013 }
1014 if (coSat.Orbit.DotDeltaAlongTrack < -1.048572 ||
1015 coSat.Orbit.DotDeltaAlongTrack > +1.048572) {
1016 ssrParStr = "Orbit::DotDeltaAlongTrack";
1017 ssrParValue = QString::number(coSat.Orbit.DotDeltaAlongTrack, 'f', 6);
1018 corrIsOutOfRange = true;
1019 }
1020 if (coSat.Orbit.DotDeltaCrossTrack < -1.048572 ||
1021 coSat.Orbit.DotDeltaCrossTrack > +1.048572) {
1022 ssrParStr = "Orbit::DotDeltaCrossTrack";
1023 ssrParValue = QString::number(coSat.Orbit.DotDeltaCrossTrack, 'f', 6);
1024 corrIsOutOfRange = true;
1025 }
1026 break;
1027 //==========//
1028 // RTCM SSR //
1029 // =========//
1030 case RTCMssr:
1031 case RTCMnewssr:
1032 if (coSat.Clock.DeltaA0 < -209.7151 ||
1033 coSat.Clock.DeltaA0 > +209.7151) {
1034 ssrParStr = "Clock::DeltaA0";
1035 ssrParValue = QString::number(coSat.Clock.DeltaA0, 'f', 4);
1036 corrIsOutOfRange = true;
1037 }
1038 if (coSat.Clock.DeltaA1 < -1.048575 ||
1039 coSat.Clock.DeltaA1 > +1.048575) {
1040 ssrParStr = "Clock::DeltaA1";
1041 ssrParValue = QString::number(coSat.Clock.DeltaA1, 'f', 6);
1042 corrIsOutOfRange = true;
1043 }
1044 if (coSat.Clock.DeltaA2 < -1.34217726 ||
1045 coSat.Clock.DeltaA2 > +1.34217726) {
1046 ssrParStr = "Clock::DeltaA2";
1047 ssrParValue = QString::number(coSat.Clock.DeltaA2, 'f', 8);
1048 corrIsOutOfRange = true;
1049 }
1050
1051 if (coSat.Orbit.DeltaRadial < -209.7151 ||
1052 coSat.Orbit.DeltaRadial > +209.7151) {
1053 ssrParStr = "Orbit::DeltaRadial";
1054 ssrParValue = QString::number(coSat.Orbit.DeltaRadial, 'f', 4);
1055 corrIsOutOfRange = true;
1056 }
1057
1058 if (coSat.Orbit.DeltaAlongTrack < -209.7148 ||
1059 coSat.Orbit.DeltaAlongTrack > +209.7148) {
1060 ssrParStr = "Orbit::DeltaAlongTrack";
1061 ssrParValue = QString::number(coSat.Orbit.DeltaAlongTrack, 'f', 4);
1062 corrIsOutOfRange = true;
1063 }
1064 if (coSat.Orbit.DeltaCrossTrack < -209.7148 ||
1065 coSat.Orbit.DeltaCrossTrack > +209.7148) {
1066 ssrParStr = "Orbit::DeltaCrossTrack";
1067 ssrParValue = QString::number(coSat.Orbit.DeltaCrossTrack, 'f', 4);
1068 corrIsOutOfRange = true;
1069 }
1070
1071 if (coSat.Orbit.DotDeltaRadial < -1.048575 ||
1072 coSat.Orbit.DotDeltaRadial > +1.048575) {
1073 ssrParStr = "Orbit::DotDeltaRadial";
1074 ssrParValue = QString::number(coSat.Orbit.DotDeltaRadial, 'f', 6);
1075 corrIsOutOfRange = true;
1076 }
1077 if (coSat.Orbit.DotDeltaAlongTrack < -1.048572 ||
1078 coSat.Orbit.DotDeltaAlongTrack > +1.048572) {
1079 ssrParStr = "Orbit::DotDeltaAlongTrack";
1080 ssrParValue = QString::number(coSat.Orbit.DotDeltaAlongTrack, 'f', 6);
1081 corrIsOutOfRange = true;
1082 }
1083 if (coSat.Orbit.DotDeltaCrossTrack < -1.048572 ||
1084 coSat.Orbit.DotDeltaCrossTrack > +1.048572) {
1085 ssrParStr = "Orbit::DotDeltaCrossTrack";
1086 ssrParValue = QString::number(coSat.Orbit.DotDeltaCrossTrack, 'f', 6);
1087 corrIsOutOfRange = true;
1088 }
1089 break;
1090 }
1091
1092 if (corrIsOutOfRange) {
1093 emit newMessage("RTCM3coDecoder: Correction " + ssrParStr.toLatin1()
1094 + " (" + ssrParValue.toLatin1() + ") "
1095 + "is out of range " + _staID.toLatin1(), true);
1096 }
1097
1098 return corrIsOutOfRange;
1099}
1100
1101//
1102////////////////////////////////////////////////////////////////////////////
1103void RTCM3coDecoder::setEpochTime() {
1104
1105 // _phaseBias is no longer wiped between messages (kept alive so a later
1106 // Extended Phase Bias message can correlate against it), so
1107 // NumberOfSat[s] > 0 alone no longer means "phase bias was just decoded
1108 // this cycle" - it can be stale from many messages ago. Gate each
1109 // phase-bias fallback below on the same per-system freshness tracking
1110 // sendResults() uses (_phaseBiasSentEpoch), so a stale leftover value
1111 // never gets picked as this cycle's epoch.
1112 bncTime prevTime = _lastTime;
1113 _lastTime.reset();
1114
1115 double epoSecGPS = -1.0;
1116 double epoSecGlo = -1.0;
1117 double epoSecGal = -1.0;
1118 double epoSecQzss = -1.0;
1119 double epoSecSbas = -1.0;
1120 double epoSecBds = -1.0;
1121 if (_clkOrb.NumberOfSat[CLOCKORBIT_SATGPS] > 0) {
1122 epoSecGPS = _clkOrb.EpochTime[CLOCKORBIT_SATGPS]; // 0 .. 604799 s
1123 }
1124 else if (_codeBias.NumberOfSat[CLOCKORBIT_SATGPS] > 0) {
1125 epoSecGPS = _codeBias.EpochTime[CLOCKORBIT_SATGPS]; // 0 .. 604799 s
1126 }
1127 else if (_phaseBias.NumberOfSat[CLOCKORBIT_SATGPS] > 0 &&
1128 _phaseBias.EpochTime[CLOCKORBIT_SATGPS] != _phaseBiasSentEpoch[CLOCKORBIT_SATGPS]) {
1129 epoSecGPS = _phaseBias.EpochTime[CLOCKORBIT_SATGPS]; // 0 .. 604799 s
1130 }
1131 else if (_vTEC.NumLayers > 0) {
1132 epoSecGPS = _vTEC.EpochTime; // 0 .. 604799 s
1133 }
1134 else if (_clkOrb.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) {
1135 epoSecGlo = _clkOrb.EpochTime[CLOCKORBIT_SATGLONASS]; // 0 .. 86399 s
1136 }
1137 else if (_codeBias.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) {
1138 epoSecGlo = _codeBias.EpochTime[CLOCKORBIT_SATGLONASS]; // 0 .. 86399 s
1139 }
1140 else if (_phaseBias.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0 &&
1141 _phaseBias.EpochTime[CLOCKORBIT_SATGLONASS] != _phaseBiasSentEpoch[CLOCKORBIT_SATGLONASS]) {
1142 epoSecGlo = _phaseBias.EpochTime[CLOCKORBIT_SATGLONASS]; // 0 .. 86399 s
1143 }
1144 else if (_clkOrb.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0) {
1145 epoSecGal = _clkOrb.EpochTime[CLOCKORBIT_SATGALILEO];
1146 }
1147 else if (_codeBias.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0) {
1148 epoSecGal = _codeBias.EpochTime[CLOCKORBIT_SATGALILEO];
1149 }
1150 else if (_phaseBias.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0 &&
1151 _phaseBias.EpochTime[CLOCKORBIT_SATGALILEO] != _phaseBiasSentEpoch[CLOCKORBIT_SATGALILEO]) {
1152 epoSecGal = _phaseBias.EpochTime[CLOCKORBIT_SATGALILEO];
1153 }
1154 else if (_clkOrb.NumberOfSat[CLOCKORBIT_SATQZSS] > 0) {
1155 epoSecQzss = _clkOrb.EpochTime[CLOCKORBIT_SATQZSS];
1156 }
1157 else if (_codeBias.NumberOfSat[CLOCKORBIT_SATQZSS] > 0) {
1158 epoSecQzss = _codeBias.EpochTime[CLOCKORBIT_SATQZSS];
1159 }
1160 else if (_phaseBias.NumberOfSat[CLOCKORBIT_SATQZSS] > 0 &&
1161 _phaseBias.EpochTime[CLOCKORBIT_SATQZSS] != _phaseBiasSentEpoch[CLOCKORBIT_SATQZSS]) {
1162 epoSecQzss = _phaseBias.EpochTime[CLOCKORBIT_SATQZSS];
1163 }
1164 else if (_clkOrb.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) {
1165 epoSecSbas = _clkOrb.EpochTime[CLOCKORBIT_SATSBAS];
1166 }
1167 else if (_codeBias.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) {
1168 epoSecSbas = _codeBias.EpochTime[CLOCKORBIT_SATSBAS];
1169 }
1170 else if (_phaseBias.NumberOfSat[CLOCKORBIT_SATSBAS] > 0 &&
1171 _phaseBias.EpochTime[CLOCKORBIT_SATSBAS] != _phaseBiasSentEpoch[CLOCKORBIT_SATSBAS]) {
1172 epoSecSbas = _phaseBias.EpochTime[CLOCKORBIT_SATSBAS];
1173 }
1174 else if (_clkOrb.NumberOfSat[CLOCKORBIT_SATBDS] > 0) {
1175 epoSecBds = _clkOrb.EpochTime[CLOCKORBIT_SATBDS];
1176 }
1177 else if (_codeBias.NumberOfSat[CLOCKORBIT_SATBDS] > 0) {
1178 epoSecBds = _codeBias.EpochTime[CLOCKORBIT_SATBDS];
1179 }
1180 else if (_phaseBias.NumberOfSat[CLOCKORBIT_SATBDS] > 0 &&
1181 _phaseBias.EpochTime[CLOCKORBIT_SATBDS] != _phaseBiasSentEpoch[CLOCKORBIT_SATBDS]) {
1182 epoSecBds = _phaseBias.EpochTime[CLOCKORBIT_SATBDS];
1183 }
1184
1185 // Retrieve current time
1186 // ---------------------
1187 int currentWeek = 0;
1188 double currentSec = 0.0;
1189 currentGPSWeeks(currentWeek, currentSec);
1190 bncTime currentTime(currentWeek, currentSec);
1191
1192 // Set _lastTime close to currentTime
1193 // ----------------------------------
1194 if (_type == IGSssr) {
1195 if (epoSecGPS != -1) _igsRefEpoSec = epoSecGPS;
1196 else if (epoSecGal != -1) _igsRefEpoSec = epoSecGal;
1197 else if (epoSecQzss != -1) _igsRefEpoSec = epoSecQzss;
1198 else if (epoSecSbas != -1) _igsRefEpoSec = epoSecSbas;
1199 }
1200
1201 char epoSys = 0; // system the epoch of this message is taken from
1202 if (epoSecGPS != -1) {
1203 epoSys = 'G';
1204 _lastTime.set(currentWeek, epoSecGPS);
1205 }
1206 else if (epoSecGlo != -1) {
1207 epoSys = 'R';
1208 QDate date = dateAndTimeFromGPSweek(currentTime.gpsw(), currentTime.gpssec()).date();
1209 double leap = gnumleap(date.year(), date.month(), date.day());
1210 // IGS-SSR: the SSR Epoch Time (IDF003, 20 bit) is given in one continuous
1211 // time scale for all GNSS, i.e. GPS seconds of week also for GLONASS
1212 // (IGS SSR v1.00) - no conversion. Old encoders wrote UTC instead, as
1213 // seconds of day (e.g. BNC before 2026-09-30) or as seconds of week:
1214 // recognised by comparison with the GPS/Galileo epoch of the same stream
1215 // and converted, with a warning, during a transition period. The value
1216 // in GPS time is taken modulo one day around the stream's GPS epoch,
1217 // which covers both variants.
1218 if (_type == IGSssr && _igsRefEpoSec >= 0.0 &&
1219 igsLegacyEpoch(epoSecGlo, fmod(_igsRefEpoSec - leap + 7 * 86400.0, 86400.0), 86400.0)) {
1220 // seconds of day: outdated convention; seconds of week: erroneous
1221 bool secOfWeek = (epoSecGlo >= 86400.0);
1222 double dd = fmod(epoSecGlo + leap - _igsRefEpoSec, 86400.0);
1223 if (dd > 43200.0) dd -= 86400.0;
1224 else if (dd < -43200.0) dd += 86400.0;
1225 epoSecGlo = _igsRefEpoSec + dd;
1226 bncTime& warned = _legacyEpochWarned['R'];
1227 if (!warned.valid() || currentTime - warned >= 3600.0) {
1228 warned = currentTime;
1229 if (secOfWeek) {
1230 emit newMessage(_staID.toLatin1() + ": IGS-SSR GLONASS epoch time erroneously encoded "
1231 "(UTC seconds of week instead of GPS seconds of week, IGS SSR v1.00 IDF003) "
1232 "detected and converted - the SSR encoder should be corrected", true);
1233 }
1234 else {
1235 emit newMessage(_staID.toLatin1() + ": IGS-SSR GLONASS epoch time in outdated convention "
1236 "(UTC seconds of day instead of GPS seconds of week, IGS SSR v1.00 IDF003) "
1237 "detected and converted - the SSR encoder should be updated", true);
1238 }
1239 }
1240 }
1241 if (_type == RTCMssr || _type == RTCMnewssr) {
1242 // Same GLONASS epoch wire convention (UTC+3h) as RTCMssr
1243 epoSecGlo = epoSecGlo - 3 * 3600 + leap;
1244 }
1245 _lastTime.set(currentWeek, epoSecGlo);
1246 }
1247 else if (epoSecGal != -1) {
1248 epoSys = 'E';
1249 _lastTime.set(currentWeek, epoSecGal);
1250 }
1251 else if (epoSecQzss != -1) {
1252 epoSys = 'J';
1253 _lastTime.set(currentWeek, epoSecQzss);
1254 }
1255 else if (epoSecSbas != -1) {
1256 epoSys = 'S';
1257 _lastTime.set(currentWeek, epoSecSbas);
1258 }
1259 else if (epoSecBds != -1) {
1260 epoSys = 'C';
1261 // RTCM-SSR: BDT; IGS-SSR: GPS time scale for all GNSS (IDF003). Old
1262 // IGS-SSR encoders wrote BDT: recognised and converted as for GLONASS.
1263 bool bdt = (_type != IGSssr);
1264 if (_type == IGSssr && _igsRefEpoSec >= 0.0 &&
1265 igsLegacyEpoch(epoSecBds, fmod(_igsRefEpoSec - 14.0 + 604800.0, 604800.0), 604800.0)) {
1266 bdt = true;
1267 bncTime& warned = _legacyEpochWarned['C'];
1268 if (!warned.valid() || currentTime - warned >= 3600.0) {
1269 warned = currentTime;
1270 emit newMessage(_staID.toLatin1() + ": IGS-SSR BDS epoch time in outdated convention "
1271 "(BDT instead of GPS seconds of week, IGS SSR v1.00 IDF003) "
1272 "detected and converted - the SSR encoder should be updated", true);
1273 }
1274 }
1275 if (bdt) {
1276 epoSecBds += 14.0;
1277 if (epoSecBds > 604800.0) {
1278 epoSecBds -= 7.0*24.0*60.0*60.0;
1279 }
1280 }
1281 _lastTime.set(currentWeek, epoSecBds);
1282 }
1283 // Some message types (e.g. Metadata) carry no epoch field of their own,
1284 // and none of the above found anything fresh to use either - fall back
1285 // to the last known valid time rather than leaving _lastTime invalid
1286 // (which would silently drop the message's output entirely).
1287 else if (prevTime.valid()) {
1288 _lastTime = prevTime;
1289 }
1290
1291 if (_lastTime.valid()) {
1292 double maxDiff = 12 * 3600.0;
1293 while (_lastTime < currentTime - maxDiff) {
1294 _lastTime = _lastTime + maxDiff;
1295 }
1296 while (_lastTime > currentTime + maxDiff) {
1297 _lastTime = _lastTime - maxDiff;
1298 }
1299 }
1300
1301 // Plausibility: the orbit/clock epochs of all systems of a stream,
1302 // converted to GPS time, refer to the same update cycles as its GPS epochs. A difference
1303 // of more than MAX_DIFF to the latest GPS epoch (itself not older than
1304 // MAX_DIFF) indicates an erroneous encoding not covered above; the epoch
1305 // is used as it is and reported at most once per hour and system.
1306 // Only orbit/clock messages are checked: code and phase biases may be
1307 // sent with the (older) epoch of their last update (e.g. Galileo HAS).
1308 const double MAX_DIFF = 120.0;
1309 bool clkOrbMsg = false;
1310 for (unsigned s = 0; s < CLOCKORBIT_SATNUM; s++) {
1311 if (_clkOrb.NumberOfSat[s] > 0) {
1312 clkOrbMsg = true;
1313 }
1314 }
1315 if (!clkOrbMsg) {
1316 return;
1317 }
1318 if (_lastTime.valid() && epoSys == 'G') {
1319 _lastGpsEpoch = _lastTime;
1320 }
1321 else if (_lastTime.valid() && epoSys != 0 && _lastGpsEpoch.valid() &&
1322 fabs(currentTime - _lastGpsEpoch) <= MAX_DIFF &&
1323 fabs(_lastTime - _lastGpsEpoch) > MAX_DIFF) {
1324 bncTime& warned = _epochDiffWarned[QChar(epoSys)];
1325 if (!warned.valid() || currentTime - warned >= 3600.0) {
1326 warned = currentTime;
1327 emit newMessage(QString("%1: %2 SSR epoch time %3 %4 differs by %5 s from the GPS SSR epoch time "
1328 "of the stream - erroneously encoded?")
1329 .arg(_staID).arg(epoSys)
1330 .arg(QString::fromStdString(_lastTime.datestr()))
1331 .arg(QString::fromStdString(_lastTime.timestr(0)))
1332 .arg(_lastTime - _lastGpsEpoch, 0, 'f', 0).toLatin1(), true);
1333 }
1334 }
1335}
1336
1337// IGS-SSR: true if value (seconds, periodic with period) matches the epoch
1338// expected in the outdated convention (legacyRef) better than the GPS time
1339// reference of the stream, within the spread of epochs of one update cycle
1340////////////////////////////////////////////////////////////////////////////
1341bool RTCM3coDecoder::igsLegacyEpoch(double value, double legacyRef, double period) const {
1342 auto dist = [period](double a, double b) {
1343 double d = fmod(fabs(a - b), period);
1344 return std::min(d, period - d);
1345 };
1346 double dSpec = dist(value, fmod(_igsRefEpoSec, period));
1347 double dLegacy = dist(value, legacyRef);
1348 return dLegacy < dSpec && dLegacy <= 30.0;
1349}
1350
1351// Satellite numbers on the wire can exceed BNC's supported range (e.g. 6-bit
1352// IDs up to 63, while t_prn supports G01-G32). They are passed on unchanged,
1353// but t_prn::toInt() maps them to the unused index 0, so they are not usable
1354// for per-satellite processing - report that once per satellite.
1355////////////////////////////////////////////////////////////////////////////
1356void RTCM3coDecoder::checkPrnRange(const t_prn& prn) {
1357 if (prn.toInt() != 0) {
1358 return;
1359 }
1360 QString prnStr = QString::fromStdString(prn.toString());
1361 if (!_prnOutOfRangeLogged.contains(prnStr)) {
1362 _prnOutOfRangeLogged.insert(prnStr);
1363 emit newMessage(QString("%1: satellite %2 outside the range supported by BNC - not usable for processing")
1364 .arg(_staID).arg(prnStr).toLatin1(), true);
1365 }
1366}
1367
1368// All Satellite Antenna messages of one GNSS must use the same Satellite
1369// Antenna IOD (a satellite set may be split over several messages). During
1370// a legitimate IOD change old and new IOD are both seen for a while, until
1371// every message has been sent with the new one - but the IOD never returns
1372// to a replaced value within 64 days (uniqueness per SSR Provider ID), so a
1373// switch back to the replaced IOD within that period reveals messages of the
1374// same GNSS using different IODs. Reported once per GNSS and IOD pair; the
1375// data itself is not changed (PPP checks each satellite's IOD individually).
1376////////////////////////////////////////////////////////////////////////////
1377void RTCM3coDecoder::checkAntennaIOD(unsigned s) {
1378 const double MAX_AGE_SEC = 64.0 * 86400.0;
1379 unsigned int iod = _antenna.SatelliteAntennaIOD[s];
1380 unsigned int provider = _antenna.SSRProviderID[s];
1381
1382 int currentWeek = 0;
1383 double currentSec = 0.0;
1384 currentGPSWeeks(currentWeek, currentSec);
1385 bncTime currentTime(currentWeek, currentSec);
1386
1387 if (!_antennaIODKnown[s] || provider != _antennaIODProvider[s]) {
1388 _antennaIODKnown[s] = true;
1389 _antennaIODProvider[s] = provider;
1390 _antennaIODCur[s] = iod;
1391 _antennaIODPrevTime[s].reset(); // no replaced IOD yet
1392 return;
1393 }
1394 if (iod == _antennaIODCur[s]) {
1395 return;
1396 }
1397 if (_antennaIODPrevTime[s].valid() && iod == _antennaIODPrev[s] &&
1398 currentTime - _antennaIODPrevTime[s] < MAX_AGE_SEC) {
1399 const char sysChars[CLOCKORBIT_SATNUM] = {'G', 'R', 'E', 'J', 'S', 'C'};
1400 char sys = (s < CLOCKORBIT_SATNUM) ? sysChars[s] : '?';
1401 QString key = QString("%1_%2_%3").arg(sys).arg(_antennaIODCur[s]).arg(iod);
1402 if (!_antennaIODLogged.contains(key)) {
1403 _antennaIODLogged.insert(key);
1404 emit newMessage(QString("%1: GNSS %2 Satellite Antenna IOD switches back %3 -> %4"
1405 " - messages of one GNSS must use the same IOD")
1406 .arg(_staID).arg(sys).arg(_antennaIODCur[s]).arg(iod).toLatin1(), true);
1407 }
1408 }
1409 _antennaIODPrev[s] = _antennaIODCur[s];
1410 _antennaIODPrevTime[s] = currentTime;
1411 _antennaIODCur[s] = iod;
1412}
Note: See TracBrowser for help on using the repository browser.