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

Last change on this file since 10617 was 10617, checked in by stuerze, 3 days ago

small bugfix in range check for SSR orbit and clock corrections

File size: 30.6 KB
RevLine 
[866]1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
8// http://www.fsv.cvut.cz
9//
10// Email: euref-ip@bkg.bund.de
11//
12// This program is free software; you can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation, version 2.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: RTCM3coDecoder
30 *
31 * Purpose: RTCM3 Clock Orbit Decoder
32 *
33 * Author: L. Mervart
34 *
35 * Created: 05-May-2008
36 *
[6215]37 * Changes:
[866]38 *
39 * -----------------------------------------------------------------------*/
40
[868]41#include <stdio.h>
[920]42#include <math.h>
[868]43
[866]44#include "RTCM3coDecoder.h"
[918]45#include "bncutils.h"
[934]46#include "bncrinex.h"
[5070]47#include "bnccore.h"
[1535]48#include "bncsettings.h"
[4428]49#include "bnctime.h"
[866]50
51using namespace std;
52
53// Constructor
54////////////////////////////////////////////////////////////////////////////
[9048]55RTCM3coDecoder::RTCM3coDecoder(const QString& staID) {
[934]56
[970]57 _staID = staID;
58
[934]59 // File Output
60 // -----------
[1535]61 bncSettings settings;
[934]62 QString path = settings.value("corrPath").toString();
63 if (!path.isEmpty()) {
64 expandEnvVar(path);
65 if ( path.length() > 0 && path[path.length()-1] != QDir::separator() ) {
66 path += QDir::separator();
67 }
[970]68 _fileNameSkl = path + staID;
[934]69 }
[6141]70 _out = 0;
[934]71
[6215]72 connect(this, SIGNAL(newOrbCorrections(QList<t_orbCorr>)),
[6141]73 BNC_CORE, SLOT(slotNewOrbCorrections(QList<t_orbCorr>)));
[1828]74
[6215]75 connect(this, SIGNAL(newClkCorrections(QList<t_clkCorr>)),
[6141]76 BNC_CORE, SLOT(slotNewClkCorrections(QList<t_clkCorr>)));
77
[6486]78 connect(this, SIGNAL(newCodeBiases(QList<t_satCodeBias>)),
79 BNC_CORE, SLOT(slotNewCodeBiases(QList<t_satCodeBias>)));
80
81 connect(this, SIGNAL(newPhaseBiases(QList<t_satPhaseBias>)),
82 BNC_CORE, SLOT(slotNewPhaseBiases(QList<t_satPhaseBias>)));
83
84 connect(this, SIGNAL(newTec(t_vTec)),
85 BNC_CORE, SLOT(slotNewTec(t_vTec)));
86
[6215]87 connect(this, SIGNAL(providerIDChanged(QString)),
[5577]88 BNC_CORE, SIGNAL(providerIDChanged(QString)));
89
[6215]90 connect(this, SIGNAL(newMessage(QByteArray,bool)),
[5068]91 BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
[4428]92
[6467]93 reset();
[5576]94
95 _providerID[0] = -1;
96 _providerID[1] = -1;
97 _providerID[2] = -1;
[9025]98
99 _ssrCorr = 0;
[10534]100
[866]101}
102
103// Destructor
104////////////////////////////////////////////////////////////////////////////
105RTCM3coDecoder::~RTCM3coDecoder() {
[935]106 delete _out;
[9025]107 delete _ssrCorr;
[7641]108 _IODs.clear();
109 _orbCorrections.clear();
110 _clkCorrections.clear();
111 _lastClkCorrections.clear();
112 _codeBiases.clear();
113 _phaseBiases.clear();
114 _vTecMap.clear();
[866]115}
116
[7641]117//
[6467]118////////////////////////////////////////////////////////////////////////////
119void RTCM3coDecoder::reset() {
120 memset(&_clkOrb, 0, sizeof(_clkOrb));
121 memset(&_codeBias, 0, sizeof(_codeBias));
122 memset(&_phaseBias, 0, sizeof(_phaseBias));
123 memset(&_vTEC, 0, sizeof(_vTEC));
124}
125
[934]126// Reopen Output File
[6215]127////////////////////////////////////////////////////////////////////////
[6141]128void RTCM3coDecoder::reopen() {
[934]129
[6141]130 if (!_fileNameSkl.isEmpty()) {
[934]131
[1535]132 bncSettings settings;
[934]133
[1154]134 QDateTime datTim = currentDateAndTimeGPS();
[934]135
136 QString hlpStr = bncRinex::nextEpochStr(datTim,
[9771]137 settings.value("corrIntr").toString(), 3);
[934]138
[9941]139 QString cntStr = (_fileNameSkl.contains("ION")) ? "_ION.ssr" : "_MC.ssr";
140
[9771]141 QString fileNameHlp = _fileNameSkl +
142 "_S_" + // stream
143 QString("%1").arg(datTim.date().year()) +
144 QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0')) +
[9941]145 hlpStr + // HM_period
146 cntStr; // mixed ION or CLK
[934]147
[6141]148 if (_fileName == fileNameHlp) {
[934]149 return;
150 }
151 else {
[6141]152 _fileName = fileNameHlp;
[934]153 }
154
[6141]155 delete _out;
[1727]156 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
[8204]157 _out = new ofstream( _fileName.toLatin1().data(), ios_base::out | ios_base::app );
[1727]158 }
159 else {
[8204]160 _out = new ofstream( _fileName.toLatin1().data() );
[1727]161 }
[934]162 }
163}
164
[6215]165//
[866]166////////////////////////////////////////////////////////////////////////////
[1227]167t_irc RTCM3coDecoder::Decode(char* buffer, int bufLen, vector<string>& errmsg) {
[868]168
[1218]169 errmsg.clear();
170
[1227]171 _buffer.append(QByteArray(buffer,bufLen));
[868]172
[1023]173 t_irc retCode = failure;
174
[1832]175 while(_buffer.size()) {
176
[9025]177 struct SsrCorr::ClockOrbit clkOrbSav;
178 struct SsrCorr::CodeBias codeBiasSav;
179 struct SsrCorr::PhaseBias phaseBiasSav;
180 struct SsrCorr::VTEC vTECSav;
[10534]181 memcpy(&clkOrbSav, &_clkOrb, sizeof(clkOrbSav)); // save state
182 memcpy(&codeBiasSav, &_codeBias, sizeof(codeBiasSav));
183 memcpy(&phaseBiasSav, &_phaseBias, sizeof(phaseBiasSav));
184 memcpy(&vTECSav, &_vTEC, sizeof(vTECSav));
[6454]185
[879]186 int bytesused = 0;
[9306]187
[9025]188 GCOB_RETURN irc = _ssrCorr->GetSSR(&_clkOrb, &_codeBias, &_vTEC, &_phaseBias,
[9306]189 _buffer.data(), _buffer.size(), &bytesused);
[1829]190
[1833]191 if (irc <= -30) { // not enough data - restore state and exit loop
[6454]192 memcpy(&_clkOrb, &clkOrbSav, sizeof(clkOrbSav));
193 memcpy(&_codeBias, &codeBiasSav, sizeof(codeBiasSav));
194 memcpy(&_phaseBias, &phaseBiasSav, sizeof(phaseBiasSav));
195 memcpy(&_vTEC, &vTECSav, sizeof(vTECSav));
[1833]196 break;
[869]197 }
[1832]198
[1833]199 else if (irc < 0) { // error - skip 1 byte and retry
[6467]200 reset();
[1842]201 _buffer = _buffer.mid(bytesused ? bytesused : 1);
[1833]202 }
203
204 else { // OK or MESSAGEFOLLOWS
[1828]205 _buffer = _buffer.mid(bytesused);
206
[6467]207 if (irc == GCOBR_OK || irc == GCOBR_MESSAGEFOLLOWS ) {
[6556]208 setEpochTime(); // sets _lastTime
[7641]209
210 if (_lastTime.valid()) {
[6467]211 reopen();
212 checkProviderID();
213 sendResults();
214 retCode = success;
[919]215 }
[6467]216 else {
[10527]217 emit newMessage("RTCM3coDecoder: _lastTime invalid: " + _staID.toLatin1(), true);
[6467]218 retCode = failure;
[1829]219 }
[6467]220 reset();
[869]221 }
[1829]222 }
[1833]223 }
[1832]224
[1829]225 return retCode;
[866]226}
[934]227
[6215]228//
[934]229////////////////////////////////////////////////////////////////////////////
[6141]230void RTCM3coDecoder::sendResults() {
[934]231
[6455]232 // Orbit and clock corrections of all satellites
233 // ---------------------------------------------
[6854]234 for (unsigned ii = 0; ii < CLOCKORBIT_NUMGPS
235 + CLOCKORBIT_NUMGLONASS
236 + CLOCKORBIT_NUMGALILEO
237 + CLOCKORBIT_NUMQZSS
238 + CLOCKORBIT_NUMSBAS
239 + _clkOrb.NumberOfSat[CLOCKORBIT_SATBDS];
240 ii++) {
[10572]241 if (corrIsOutOfRange(_clkOrb.Sat[ii])) {
242 continue;
243 }
[10599]244 char sys = ' ';
245 int num = _clkOrb.Sat[ii].ID;
246 int flag = 0; // to force NAV type usage according SSR standard
[6454]247 if (ii < _clkOrb.NumberOfSat[CLOCKORBIT_SATGPS]) {
[10599]248 sys = 'G';
249 flag = t_eph::LNAV;
[3022]250 }
[6854]251 else if (ii >= CLOCKORBIT_OFFSETGLONASS &&
[6855]252 ii < CLOCKORBIT_OFFSETGLONASS + _clkOrb.NumberOfSat[CLOCKORBIT_SATGLONASS]) {
[10599]253 sys = 'R';
254 flag = t_eph::FDMA_M;
[3022]255 }
[6854]256 else if (ii >= CLOCKORBIT_OFFSETGALILEO &&
[6855]257 ii < CLOCKORBIT_OFFSETGALILEO + _clkOrb.NumberOfSat[CLOCKORBIT_SATGALILEO]) {
[10599]258 sys = 'E';
259 flag = t_eph::INAV;
[6854]260 }
261 else if (ii >= CLOCKORBIT_OFFSETQZSS &&
[6855]262 ii < CLOCKORBIT_OFFSETQZSS + _clkOrb.NumberOfSat[CLOCKORBIT_SATQZSS]) {
[10599]263 sys = 'J';
264 flag = t_eph::LNAV;
[6854]265 }
266 else if (ii >= CLOCKORBIT_OFFSETSBAS &&
[6855]267 ii < CLOCKORBIT_OFFSETSBAS + _clkOrb.NumberOfSat[CLOCKORBIT_SATSBAS]) {
[10599]268 sys = 'S';
269 flag = t_eph::SBASL1;
[6854]270 }
271 else if (ii >= CLOCKORBIT_OFFSETBDS &&
[6855]272 ii < CLOCKORBIT_OFFSETBDS + _clkOrb.NumberOfSat[CLOCKORBIT_SATBDS]) {
[10599]273 sys = 'C';
274 if (num < 6) {// GEO
275 flag = t_eph::D2;
276 }
277 else if (num > 58 && num < 63) { // GEO
278 flag = t_eph::D2;
279 }
280 else {
281 flag = t_eph::D1;
282 }
[6854]283 }
[6141]284 else {
285 continue;
286 }
[9025]287
[6141]288 // Orbit correction
289 // ----------------
[9025]290 if ( _clkOrb.messageType == _ssrCorr->COTYPE_GPSCOMBINED ||
291 _clkOrb.messageType == _ssrCorr->COTYPE_GLONASSCOMBINED ||
292 _clkOrb.messageType == _ssrCorr->COTYPE_GALILEOCOMBINED ||
293 _clkOrb.messageType == _ssrCorr->COTYPE_QZSSCOMBINED ||
294 _clkOrb.messageType == _ssrCorr->COTYPE_SBASCOMBINED ||
295 _clkOrb.messageType == _ssrCorr->COTYPE_BDSCOMBINED ||
296 _clkOrb.messageType == _ssrCorr->COTYPE_GPSORBIT ||
297 _clkOrb.messageType == _ssrCorr->COTYPE_GLONASSORBIT ||
298 _clkOrb.messageType == _ssrCorr->COTYPE_GALILEOORBIT ||
299 _clkOrb.messageType == _ssrCorr->COTYPE_QZSSORBIT ||
300 _clkOrb.messageType == _ssrCorr->COTYPE_SBASORBIT ||
301 _clkOrb.messageType == _ssrCorr->COTYPE_BDSORBIT ) {
[3022]302
[6141]303 t_orbCorr orbCorr;
[10599]304 orbCorr._prn.set(sys, num, flag);
[6564]305 orbCorr._staID = _staID.toStdString();
[6556]306 orbCorr._iod = _clkOrb.Sat[ii].IOD;
307 orbCorr._time = _lastTime;
308 orbCorr._updateInt = _clkOrb.UpdateInterval;
[10599]309 orbCorr._system = sys;
[6556]310 orbCorr._xr[0] = _clkOrb.Sat[ii].Orbit.DeltaRadial;
311 orbCorr._xr[1] = _clkOrb.Sat[ii].Orbit.DeltaAlongTrack;
312 orbCorr._xr[2] = _clkOrb.Sat[ii].Orbit.DeltaCrossTrack;
313 orbCorr._dotXr[0] = _clkOrb.Sat[ii].Orbit.DotDeltaRadial;
314 orbCorr._dotXr[1] = _clkOrb.Sat[ii].Orbit.DotDeltaAlongTrack;
315 orbCorr._dotXr[2] = _clkOrb.Sat[ii].Orbit.DotDeltaCrossTrack;
[3022]316
[7652]317 _orbCorrections[_lastTime].append(orbCorr);
[3022]318
[6471]319 _IODs[orbCorr._prn] = _clkOrb.Sat[ii].IOD;
[6141]320 }
[3022]321
[6455]322 // Clock Corrections
323 // -----------------
[9025]324 if ( _clkOrb.messageType == _ssrCorr->COTYPE_GPSCOMBINED ||
325 _clkOrb.messageType == _ssrCorr->COTYPE_GLONASSCOMBINED ||
326 _clkOrb.messageType == _ssrCorr->COTYPE_GALILEOCOMBINED ||
327 _clkOrb.messageType == _ssrCorr->COTYPE_QZSSCOMBINED ||
328 _clkOrb.messageType == _ssrCorr->COTYPE_SBASCOMBINED ||
329 _clkOrb.messageType == _ssrCorr->COTYPE_BDSCOMBINED ||
330 _clkOrb.messageType == _ssrCorr->COTYPE_GPSCLOCK ||
331 _clkOrb.messageType == _ssrCorr->COTYPE_GLONASSCLOCK ||
332 _clkOrb.messageType == _ssrCorr->COTYPE_GALILEOCLOCK ||
333 _clkOrb.messageType == _ssrCorr->COTYPE_QZSSCLOCK ||
334 _clkOrb.messageType == _ssrCorr->COTYPE_SBASCLOCK ||
335 _clkOrb.messageType == _ssrCorr->COTYPE_BDSCLOCK) {
[3022]336
[6141]337 t_clkCorr clkCorr;
[10599]338 clkCorr._prn.set(sys, _clkOrb.Sat[ii].ID, flag);
[6564]339 clkCorr._staID = _staID.toStdString();
[6141]340 clkCorr._time = _lastTime;
[6556]341 clkCorr._updateInt = _clkOrb.UpdateInterval;
[7014]342 clkCorr._dClk = _clkOrb.Sat[ii].Clock.DeltaA0 / t_CST::c;
343 clkCorr._dotDClk = _clkOrb.Sat[ii].Clock.DeltaA1 / t_CST::c;
344 clkCorr._dotDotDClk = _clkOrb.Sat[ii].Clock.DeltaA2 / t_CST::c;
[3022]345
[6471]346 _lastClkCorrections[clkCorr._prn] = clkCorr;
347
348 if (_IODs.contains(clkCorr._prn)) {
349 clkCorr._iod = _IODs[clkCorr._prn];
[7652]350 _clkCorrections[_lastTime].append(clkCorr);
[3022]351 }
352 }
[6141]353
354 // High-Resolution Clocks
355 // ----------------------
[9025]356 if ( _clkOrb.messageType == _ssrCorr->COTYPE_GPSHR ||
357 _clkOrb.messageType == _ssrCorr->COTYPE_GLONASSHR ||
358 _clkOrb.messageType == _ssrCorr->COTYPE_GALILEOHR ||
359 _clkOrb.messageType == _ssrCorr->COTYPE_QZSSHR ||
360 _clkOrb.messageType == _ssrCorr->COTYPE_SBASHR ||
361 _clkOrb.messageType == _ssrCorr->COTYPE_BDSHR) {
[10599]362 t_prn prn(sys, _clkOrb.Sat[ii].ID, flag);
[6471]363 if (_lastClkCorrections.contains(prn)) {
364 t_clkCorr clkCorr;
[6556]365 clkCorr = _lastClkCorrections[prn];
366 clkCorr._time = _lastTime;
367 clkCorr._updateInt = _clkOrb.UpdateInterval;
368 clkCorr._dClk += _clkOrb.Sat[ii].hrclock / t_CST::c;
[6471]369 if (_IODs.contains(clkCorr._prn)) {
370 clkCorr._iod = _IODs[clkCorr._prn];
[10536]371 _clkCorrections[_lastTime].append(clkCorr);
[6471]372 }
373 }
[6141]374 }
[3022]375 }
376
[6455]377 // Code Biases
378 // -----------
[6854]379 for (unsigned ii = 0; ii < CLOCKORBIT_NUMGPS
380 + CLOCKORBIT_NUMGLONASS
381 + CLOCKORBIT_NUMGALILEO
382 + CLOCKORBIT_NUMQZSS
383 + CLOCKORBIT_NUMSBAS
384 + _codeBias.NumberOfSat[CLOCKORBIT_SATBDS];
385 ii++) {
[10599]386 char sys = ' ';
387 int num = _codeBias.Sat[ii].ID;
388 int flag = 0;
[6454]389 if (ii < _codeBias.NumberOfSat[CLOCKORBIT_SATGPS]) {
[10599]390 sys = 'G';
391 flag = t_eph::LNAV;
[3022]392 }
[6854]393 else if (ii >= CLOCKORBIT_OFFSETGLONASS &&
[6855]394 ii < CLOCKORBIT_OFFSETGLONASS + _codeBias.NumberOfSat[CLOCKORBIT_SATGLONASS]) {
[10599]395 sys = 'R';
396 flag = t_eph::FDMA_M;
[3022]397 }
[6854]398 else if (ii >= CLOCKORBIT_OFFSETGALILEO &&
[6855]399 ii < CLOCKORBIT_OFFSETGALILEO + _codeBias.NumberOfSat[CLOCKORBIT_SATGALILEO]) {
[10599]400 sys = 'E';
401 flag = t_eph::INAV;
[6854]402 }
403 else if (ii >= CLOCKORBIT_OFFSETQZSS &&
[6855]404 ii < CLOCKORBIT_OFFSETQZSS + _codeBias.NumberOfSat[CLOCKORBIT_SATQZSS]) {
[10599]405 sys = 'J';
406 flag = t_eph::LNAV;
[6854]407 }
408 else if (ii >= CLOCKORBIT_OFFSETSBAS &&
[6855]409 ii < CLOCKORBIT_OFFSETSBAS + _codeBias.NumberOfSat[CLOCKORBIT_SATSBAS]) {
[10599]410 sys = 'S';
411 flag = t_eph::SBASL1;
[6854]412 }
413 else if (ii >= CLOCKORBIT_OFFSETBDS &&
[6855]414 ii < CLOCKORBIT_OFFSETBDS + _codeBias.NumberOfSat[CLOCKORBIT_SATBDS]) {
[10599]415 sys = 'C';
416 if (num < 6) {// GEO
417 flag = t_eph::D2;
418 }
419 else if (num > 58 && num < 63) { // GEO
420 flag = t_eph::D2;
421 }
422 else {
423 flag = t_eph::D1;
424 }
[6854]425 }
[6141]426 else {
427 continue;
428 }
[6463]429 t_satCodeBias satCodeBias;
[10599]430 satCodeBias._prn.set(sys, num, flag);
[6564]431 satCodeBias._staID = _staID.toStdString();
[6556]432 satCodeBias._time = _lastTime;
433 satCodeBias._updateInt = _codeBias.UpdateInterval;
[6454]434 for (unsigned jj = 0; jj < _codeBias.Sat[ii].NumberOfCodeBiases; jj++) {
[9025]435 const SsrCorr::CodeBias::BiasSat::CodeBiasEntry& biasEntry = _codeBias.Sat[ii].Biases[jj];
[6472]436 t_frqCodeBias frqCodeBias;
[10599]437 frqCodeBias._rnxType2ch.assign(_ssrCorr->codeTypeToRnxType(sys, biasEntry.Type));
[6472]438 frqCodeBias._value = biasEntry.Bias;
[6474]439 if (!frqCodeBias._rnxType2ch.empty()) {
440 satCodeBias._bias.push_back(frqCodeBias);
441 }
[6141]442 }
[7652]443 _codeBiases[_lastTime].append(satCodeBias);
[3022]444 }
445
[6487]446 // Phase Biases
447 // -----------
[6854]448 for (unsigned ii = 0; ii < CLOCKORBIT_NUMGPS
449 + CLOCKORBIT_NUMGLONASS
450 + CLOCKORBIT_NUMGALILEO
451 + CLOCKORBIT_NUMQZSS
452 + CLOCKORBIT_NUMSBAS
453 + _phaseBias.NumberOfSat[CLOCKORBIT_SATBDS];
454 ii++) {
[10599]455 char sys = ' ';
456 int num = _phaseBias.Sat[ii].ID;
457 int flag = 0;
[6487]458 if (ii < _phaseBias.NumberOfSat[CLOCKORBIT_SATGPS]) {
[10599]459 sys = 'G';
460 flag = t_eph::LNAV;
[6487]461 }
[6854]462 else if (ii >= CLOCKORBIT_OFFSETGLONASS &&
[6855]463 ii < CLOCKORBIT_OFFSETGLONASS + _phaseBias.NumberOfSat[CLOCKORBIT_SATGLONASS]) {
[10599]464 sys = 'R';
465 flag = t_eph::FDMA_M;
[6487]466 }
[6854]467 else if (ii >= CLOCKORBIT_OFFSETGALILEO &&
[6855]468 ii < CLOCKORBIT_OFFSETGALILEO + _phaseBias.NumberOfSat[CLOCKORBIT_SATGALILEO]) {
[10599]469 sys = 'E';
470 flag = t_eph::INAV;
[6854]471 }
472 else if (ii >= CLOCKORBIT_OFFSETQZSS &&
[6855]473 ii < CLOCKORBIT_OFFSETQZSS + _phaseBias.NumberOfSat[CLOCKORBIT_SATQZSS]) {
[10599]474 sys = 'J';
475 flag = t_eph::LNAV;
[6854]476 }
477 else if (ii >= CLOCKORBIT_OFFSETSBAS &&
[6855]478 ii < CLOCKORBIT_OFFSETSBAS + _phaseBias.NumberOfSat[CLOCKORBIT_SATSBAS]) {
[10599]479 sys = 'S';
480 flag = t_eph::SBASL1;
[6854]481 }
482 else if (ii >= CLOCKORBIT_OFFSETBDS &&
[6855]483 ii < CLOCKORBIT_OFFSETBDS + _phaseBias.NumberOfSat[CLOCKORBIT_SATBDS]) {
[10599]484 sys = 'C';
485 if (num < 6) {// GEO
486 flag = t_eph::D2;
487 }
488 else if (num > 58 && num < 63) { // GEO
489 flag = t_eph::D2;
490 }
491 else {
492 flag = t_eph::D1;
493 }
[6854]494 }
[6487]495 else {
496 continue;
497 }
498 t_satPhaseBias satPhaseBias;
[10599]499 satPhaseBias._prn.set(sys, num, flag);
[6564]500 satPhaseBias._staID = _staID.toStdString();
[6488]501 satPhaseBias._time = _lastTime;
[6556]502 satPhaseBias._updateInt = _phaseBias.UpdateInterval;
[6857]503 satPhaseBias._dispBiasConstistInd = _phaseBias.DispersiveBiasConsistencyIndicator;
504 satPhaseBias._MWConsistInd = _phaseBias.MWConsistencyIndicator;
[8617]505 satPhaseBias._yaw = _phaseBias.Sat[ii].YawAngle;
506 satPhaseBias._yawRate = _phaseBias.Sat[ii].YawRate;
[6487]507 for (unsigned jj = 0; jj < _phaseBias.Sat[ii].NumberOfPhaseBiases; jj++) {
[9025]508 const SsrCorr::PhaseBias::PhaseBiasSat::PhaseBiasEntry& biasEntry = _phaseBias.Sat[ii].Biases[jj];
[6487]509 t_frqPhaseBias frqPhaseBias;
[10599]510 frqPhaseBias._rnxType2ch.assign(_ssrCorr->codeTypeToRnxType(sys, biasEntry.Type));
[6488]511 frqPhaseBias._value = biasEntry.Bias;
512 frqPhaseBias._fixIndicator = biasEntry.SignalIntegerIndicator;
513 frqPhaseBias._fixWideLaneIndicator = biasEntry.SignalsWideLaneIntegerIndicator;
514 frqPhaseBias._jumpCounter = biasEntry.SignalDiscontinuityCounter;
[6487]515 if (!frqPhaseBias._rnxType2ch.empty()) {
516 satPhaseBias._bias.push_back(frqPhaseBias);
517 }
518 }
[7652]519 _phaseBiases[_lastTime].append(satPhaseBias);
[6487]520 }
521
[6490]522 // Ionospheric Model
523 // -----------------
524 if (_vTEC.NumLayers > 0) {
[6497]525 _vTecMap[_lastTime]._time = _lastTime;
[6556]526 _vTecMap[_lastTime]._updateInt = _vTEC.UpdateInterval;
[6564]527 _vTecMap[_lastTime]._staID = _staID.toStdString();
[6491]528 for (unsigned ii = 0; ii < _vTEC.NumLayers; ii++) {
[9025]529 const SsrCorr::VTEC::IonoLayers& ionoLayer = _vTEC.Layers[ii];
[6491]530 t_vTecLayer layer;
531 layer._height = ionoLayer.Height;
[6878]532 layer._C.ReSize(ionoLayer.Degree+1, ionoLayer.Order+1);
533 layer._S.ReSize(ionoLayer.Degree+1, ionoLayer.Order+1);
534 for (unsigned iDeg = 0; iDeg <= ionoLayer.Degree; iDeg++) {
535 for (unsigned iOrd = 0; iOrd <= ionoLayer.Order; iOrd++) {
[6491]536 layer._C[iDeg][iOrd] = ionoLayer.Cosinus[iDeg][iOrd];
537 layer._S[iDeg][iOrd] = ionoLayer.Sinus[iDeg][iOrd];
538 }
539 }
[6497]540 _vTecMap[_lastTime]._layers.push_back(layer);
[6491]541 }
[6490]542 }
543
[6455]544 // Dump all older epochs
545 // ---------------------
546 QMutableMapIterator<bncTime, QList<t_orbCorr> > itOrb(_orbCorrections);
547 while (itOrb.hasNext()) {
548 itOrb.next();
549 if (itOrb.key() < _lastTime) {
550 emit newOrbCorrections(itOrb.value());
[6456]551 t_orbCorr::writeEpoch(_out, itOrb.value());
[6455]552 itOrb.remove();
[7641]553 }
[6141]554 }
[6455]555 QMutableMapIterator<bncTime, QList<t_clkCorr> > itClk(_clkCorrections);
556 while (itClk.hasNext()) {
557 itClk.next();
558 if (itClk.key() < _lastTime) {
559 emit newClkCorrections(itClk.value());
[6456]560 t_clkCorr::writeEpoch(_out, itClk.value());
[6455]561 itClk.remove();
[7641]562 }
[6141]563 }
[6474]564 QMutableMapIterator<bncTime, QList<t_satCodeBias> > itCB(_codeBiases);
565 while (itCB.hasNext()) {
566 itCB.next();
567 if (itCB.key() < _lastTime) {
568 emit newCodeBiases(itCB.value());
[6475]569 t_satCodeBias::writeEpoch(_out, itCB.value());
[6474]570 itCB.remove();
[7641]571 }
[6474]572 }
[6487]573 QMutableMapIterator<bncTime, QList<t_satPhaseBias> > itPB(_phaseBiases);
574 while (itPB.hasNext()) {
575 itPB.next();
576 if (itPB.key() < _lastTime) {
577 emit newPhaseBiases(itPB.value());
578 t_satPhaseBias::writeEpoch(_out, itPB.value());
579 itPB.remove();
[7641]580 }
[6487]581 }
[6490]582 QMutableMapIterator<bncTime, t_vTec> itTec(_vTecMap);
583 while (itTec.hasNext()) {
584 itTec.next();
585 if (itTec.key() < _lastTime) {
586 emit newTec(itTec.value());
587 t_vTec::write(_out, itTec.value());
588 itTec.remove();
[7641]589 }
[6490]590 }
[3022]591}
[5576]592
[6215]593//
[5576]594////////////////////////////////////////////////////////////////////////////
595void RTCM3coDecoder::checkProviderID() {
596
[10553]597 if (_clkOrb.SSRProviderID == 0 && _clkOrb.SSRSolutionID == 0 && _clkOrb.SSRIOD == 0) {
598 return;
599 }
600
[5576]601 int newProviderID[3];
[6454]602 newProviderID[0] = _clkOrb.SSRProviderID;
603 newProviderID[1] = _clkOrb.SSRSolutionID;
604 newProviderID[2] = _clkOrb.SSRIOD;
[10534]605 QString newProviderIDStr = QString(" [SSR Provider ID: %1 SSR Solution ID: %2 SSR IOD: %3]: ")
606 .arg(newProviderID[0]).arg(newProviderID[1]).arg(newProviderID[2]);
[5576]607
608 bool alreadySet = false;
609 bool different = false;
610
611 for (unsigned ii = 0; ii < 3; ii++) {
612 if (_providerID[ii] != -1) {
613 alreadySet = true;
614 }
615 if (_providerID[ii] != newProviderID[ii]) {
616 different = true;
617 }
618 _providerID[ii] = newProviderID[ii];
619 }
[6215]620
[5576]621 if (alreadySet && different) {
[10534]622 emit newMessage("RTCM3coDecoder: Provider Changed " + newProviderIDStr.toLatin1() + _staID.toLatin1(), true);
[5577]623 emit providerIDChanged(_staID);
[5576]624 }
625}
[6467]626
[10572]627// Check corrections
628////////////////////////////////////////////////////////////////////////////
629bool RTCM3coDecoder::corrIsOutOfRange(const SsrCorr::ClockOrbit::SatData& coSat) {
630
[10617]631 QString ssrParStr;
632 QString ssrParValue;
633 bool corrIsOutOfRange = false;
[10572]634
[10617]635 switch (_type) {
636 // ======== //
637 // IGS SSR //
638 // ======== //
639 case IGSssr:
640 if (coSat.Clock.DeltaA0 < -209.7151 ||
641 coSat.Clock.DeltaA0 > +209.7151) {
642 ssrParStr = "Clock::DeltaA0";
643 ssrParValue = QString::number(coSat.Clock.DeltaA0, 'f', 4);
644 corrIsOutOfRange = true;
645 }
646 if (coSat.Clock.DeltaA1 < -1.048575 ||
647 coSat.Clock.DeltaA1 > +1.048575) {
648 ssrParStr = "Clock::DeltaA1";
649 ssrParValue = QString::number(coSat.Clock.DeltaA1, 'f', 6);
650 corrIsOutOfRange = true;
651 }
652 if (coSat.Clock.DeltaA2 < -1.3421772 ||
653 coSat.Clock.DeltaA2 > +1.3421772) {
654 ssrParStr = "Clock::DeltaA2";
655 ssrParValue = QString::number(coSat.Clock.DeltaA2, 'f', 7);
656 corrIsOutOfRange = true;
657 }
[10572]658
[10617]659 if (coSat.Orbit.DeltaRadial < -209.7151 ||
660 coSat.Orbit.DeltaRadial > +209.7151) {
661 ssrParStr = "Orbit::DeltaRadial";
662 ssrParValue = QString::number(coSat.Orbit.DeltaRadial, 'f', 4);
663 corrIsOutOfRange = true;
664 }
665
666 if (coSat.Orbit.DeltaAlongTrack < -209.7148 ||
667 coSat.Orbit.DeltaAlongTrack > +209.7148) {
668 ssrParStr = "Orbit::DeltaAlongTrack";
669 ssrParValue = QString::number(coSat.Orbit.DeltaAlongTrack, 'f', 4);
670 corrIsOutOfRange = true;
671 }
672 if (coSat.Orbit.DeltaCrossTrack < -209.7148 ||
673 coSat.Orbit.DeltaCrossTrack > +209.7148) {
674 ssrParStr = "Orbit::DeltaCrossTrack";
675 ssrParValue = QString::number(coSat.Orbit.DeltaCrossTrack, 'f', 4);
676 corrIsOutOfRange = true;
677 }
678
679 if (coSat.Orbit.DotDeltaRadial < -1.048575 ||
680 coSat.Orbit.DotDeltaRadial > +1.048575) {
681 ssrParStr = "Orbit::DotDeltaRadial";
682 ssrParValue = QString::number(coSat.Orbit.DotDeltaRadial, 'f', 6);
683 corrIsOutOfRange = true;
684 }
685 if (coSat.Orbit.DotDeltaAlongTrack < -1.048572 ||
686 coSat.Orbit.DotDeltaAlongTrack > +1.048572) {
687 ssrParStr = "Orbit::DotDeltaAlongTrack";
688 ssrParValue = QString::number(coSat.Orbit.DotDeltaAlongTrack, 'f', 6);
689 corrIsOutOfRange = true;
690 }
691 if (coSat.Orbit.DotDeltaCrossTrack < -1.048572 ||
692 coSat.Orbit.DotDeltaCrossTrack > +1.048572) {
693 ssrParStr = "Orbit::DotDeltaCrossTrack";
694 ssrParValue = QString::number(coSat.Orbit.DotDeltaCrossTrack, 'f', 6);
695 corrIsOutOfRange = true;
696 }
697 break;
698 //==========//
699 // RTCM SSR //
700 // =========//
701 case RTCMssr:
702 if (coSat.Clock.DeltaA0 < -209.7151 ||
703 coSat.Clock.DeltaA0 > +209.7151) {
704 ssrParStr = "Clock::DeltaA0";
705 ssrParValue = QString::number(coSat.Clock.DeltaA0, 'f', 4);
706 corrIsOutOfRange = true;
707 }
708 if (coSat.Clock.DeltaA1 < -1.048575 ||
709 coSat.Clock.DeltaA1 > +1.048575) {
710 ssrParStr = "Clock::DeltaA1";
711 ssrParValue = QString::number(coSat.Clock.DeltaA1, 'f', 6);
712 corrIsOutOfRange = true;
713 }
714 if (coSat.Clock.DeltaA2 < -1.34217726 ||
715 coSat.Clock.DeltaA2 > +1.34217726) {
716 ssrParStr = "Clock::DeltaA2";
717 ssrParValue = QString::number(coSat.Clock.DeltaA2, 'f', 8);
718 corrIsOutOfRange = true;
719 }
720
721 if (coSat.Orbit.DeltaRadial < -209.7151 ||
722 coSat.Orbit.DeltaRadial > +209.7151) {
723 ssrParStr = "Orbit::DeltaRadial";
724 ssrParValue = QString::number(coSat.Orbit.DeltaRadial, 'f', 4);
725 corrIsOutOfRange = true;
726 }
727
728 if (coSat.Orbit.DeltaAlongTrack < -209.7148 ||
729 coSat.Orbit.DeltaAlongTrack > +209.7148) {
730 ssrParStr = "Orbit::DeltaAlongTrack";
731 ssrParValue = QString::number(coSat.Orbit.DeltaAlongTrack, 'f', 4);
732 corrIsOutOfRange = true;
733 }
734 if (coSat.Orbit.DeltaCrossTrack < -209.7148 ||
735 coSat.Orbit.DeltaCrossTrack > +209.7148) {
736 ssrParStr = "Orbit::DeltaCrossTrack";
737 ssrParValue = QString::number(coSat.Orbit.DeltaCrossTrack, 'f', 4);
738 corrIsOutOfRange = true;
739 }
740
741 if (coSat.Orbit.DotDeltaRadial < -1.048575 ||
742 coSat.Orbit.DotDeltaRadial > +1.048575) {
743 ssrParStr = "Orbit::DotDeltaRadial";
744 ssrParValue = QString::number(coSat.Orbit.DotDeltaRadial, 'f', 6);
745 corrIsOutOfRange = true;
746 }
747 if (coSat.Orbit.DotDeltaAlongTrack < -1.048572 ||
748 coSat.Orbit.DotDeltaAlongTrack > +1.048572) {
749 ssrParStr = "Orbit::DotDeltaAlongTrack";
750 ssrParValue = QString::number(coSat.Orbit.DotDeltaAlongTrack, 'f', 6);
751 corrIsOutOfRange = true;
752 }
753 if (coSat.Orbit.DotDeltaCrossTrack < -1.048572 ||
754 coSat.Orbit.DotDeltaCrossTrack > +1.048572) {
755 ssrParStr = "Orbit::DotDeltaCrossTrack";
756 ssrParValue = QString::number(coSat.Orbit.DotDeltaCrossTrack, 'f', 6);
757 corrIsOutOfRange = true;
758 }
759 break;
760 }
761
762 if (corrIsOutOfRange) {
763 emit newMessage("RTCM3coDecoder: Correction " + ssrParStr.toLatin1()
764 + " (" + ssrParValue.toLatin1() + ") "
765 + "is out of range " + _staID.toLatin1(), true);
766 }
767
768 return corrIsOutOfRange;
[10572]769}
770
[6467]771//
772////////////////////////////////////////////////////////////////////////////
[6556]773void RTCM3coDecoder::setEpochTime() {
[6467]774
775 _lastTime.reset();
776
[6854]777 double epoSecGPS = -1.0;
778 double epoSecGlo = -1.0;
779 double epoSecGal = -1.0;
780 double epoSecQzss = -1.0;
781 double epoSecSbas = -1.0;
782 double epoSecBds = -1.0;
[6467]783 if (_clkOrb.NumberOfSat[CLOCKORBIT_SATGPS] > 0) {
[6553]784 epoSecGPS = _clkOrb.EpochTime[CLOCKORBIT_SATGPS]; // 0 .. 604799 s
[6467]785 }
786 else if (_codeBias.NumberOfSat[CLOCKORBIT_SATGPS] > 0) {
[7641]787 epoSecGPS = _codeBias.EpochTime[CLOCKORBIT_SATGPS]; // 0 .. 604799 s
[6467]788 }
[6470]789 else if (_phaseBias.NumberOfSat[CLOCKORBIT_SATGPS] > 0) {
[7641]790 epoSecGPS = _phaseBias.EpochTime[CLOCKORBIT_SATGPS]; // 0 .. 604799 s
[6470]791 }
792 else if (_vTEC.NumLayers > 0) {
[7641]793 epoSecGPS = _vTEC.EpochTime; // 0 .. 604799 s
[6470]794 }
[6467]795 else if (_clkOrb.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) {
[6470]796 epoSecGlo = _clkOrb.EpochTime[CLOCKORBIT_SATGLONASS]; // 0 .. 86399 s
[6467]797 }
798 else if (_codeBias.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) {
[6470]799 epoSecGlo = _codeBias.EpochTime[CLOCKORBIT_SATGLONASS]; // 0 .. 86399 s
[6467]800 }
[6470]801 else if (_phaseBias.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) {
802 epoSecGlo = _phaseBias.EpochTime[CLOCKORBIT_SATGLONASS]; // 0 .. 86399 s
803 }
[6854]804 else if (_clkOrb.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0) {
805 epoSecGal = _clkOrb.EpochTime[CLOCKORBIT_SATGALILEO];
806 }
807 else if (_codeBias.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0) {
808 epoSecGal = _codeBias.EpochTime[CLOCKORBIT_SATGALILEO];
809 }
810 else if (_phaseBias.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0) {
811 epoSecGal = _phaseBias.EpochTime[CLOCKORBIT_SATGALILEO];
812 }
813 else if (_clkOrb.NumberOfSat[CLOCKORBIT_SATQZSS] > 0) {
814 epoSecQzss = _clkOrb.EpochTime[CLOCKORBIT_SATQZSS];
815 }
816 else if (_codeBias.NumberOfSat[CLOCKORBIT_SATQZSS] > 0) {
817 epoSecQzss = _codeBias.EpochTime[CLOCKORBIT_SATQZSS];
818 }
819 else if (_phaseBias.NumberOfSat[CLOCKORBIT_SATQZSS] > 0) {
820 epoSecQzss = _phaseBias.EpochTime[CLOCKORBIT_SATQZSS];
821 }
822 else if (_clkOrb.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) {
823 epoSecSbas = _clkOrb.EpochTime[CLOCKORBIT_SATSBAS];
824 }
825 else if (_codeBias.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) {
826 epoSecSbas = _codeBias.EpochTime[CLOCKORBIT_SATSBAS];
827 }
828 else if (_phaseBias.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) {
829 epoSecSbas = _phaseBias.EpochTime[CLOCKORBIT_SATSBAS];
830 }
831 else if (_clkOrb.NumberOfSat[CLOCKORBIT_SATBDS] > 0) {
832 epoSecBds = _clkOrb.EpochTime[CLOCKORBIT_SATBDS];
833 }
834 else if (_codeBias.NumberOfSat[CLOCKORBIT_SATBDS] > 0) {
835 epoSecBds = _codeBias.EpochTime[CLOCKORBIT_SATBDS];
836 }
837 else if (_phaseBias.NumberOfSat[CLOCKORBIT_SATBDS] > 0) {
838 epoSecBds = _phaseBias.EpochTime[CLOCKORBIT_SATBDS];
839 }
[6467]840
841 // Retrieve current time
842 // ---------------------
843 int currentWeek = 0;
844 double currentSec = 0.0;
845 currentGPSWeeks(currentWeek, currentSec);
846 bncTime currentTime(currentWeek, currentSec);
847
848 // Set _lastTime close to currentTime
849 // ----------------------------------
850 if (epoSecGPS != -1) {
851 _lastTime.set(currentWeek, epoSecGPS);
852 }
853 else if (epoSecGlo != -1) {
[10534]854 QDate date = dateAndTimeFromGPSweek(currentTime.gpsw(), currentTime.gpssec()).date();
855 if (_type == IGSssr) {
[10569]856 if (epoSecGPS != epoSecGlo) {// should be not done in case of an IGS-SSR encoding error => line has to be deleted
[10534]857 epoSecGlo = epoSecGlo + gnumleap(date.year(), date.month(), date.day());
858 }
859 }
[9050]860 if (_type == RTCMssr) {
[9025]861 epoSecGlo = epoSecGlo - 3 * 3600 + gnumleap(date.year(), date.month(), date.day());
862 }
[6467]863 _lastTime.set(currentWeek, epoSecGlo);
[6468]864 }
[6854]865 else if (epoSecGal != -1) {
866 _lastTime.set(currentWeek, epoSecGal);
867 }
868 else if (epoSecQzss != -1) {
869 _lastTime.set(currentWeek, epoSecQzss);
870 }
871 else if (epoSecSbas != -1) {
872 _lastTime.set(currentWeek, epoSecSbas);
873 }
874 else if (epoSecBds != -1) {
[10534]875 if (_type == IGSssr) {
876 if (epoSecGPS != -1 && epoSecGPS != epoSecBds) {// should be not done in case of an IGS-SSR encoding error => line has to be deleted
877 epoSecBds += 14.0;
878 if (epoSecBds > 604800.0) {
879 epoSecBds -= 7.0*24.0*60.0*60.0;
880 }
881 }
882 }// line has to be deleted
[9050]883 if (_type == RTCMssr) {
[9025]884 epoSecBds += 14.0;
885 if (epoSecBds > 604800.0) {
886 epoSecBds -= 7.0*24.0*60.0*60.0;
887 }
[7711]888 }
[6854]889 _lastTime.set(currentWeek, epoSecBds);
890 }
[6468]891
892 if (_lastTime.valid()) {
[6469]893 double maxDiff = 12 * 3600.0;
894 while (_lastTime < currentTime - maxDiff) {
895 _lastTime = _lastTime + maxDiff;
[6467]896 }
[6469]897 while (_lastTime > currentTime + maxDiff) {
898 _lastTime = _lastTime - maxDiff;
[6467]899 }
900 }
901}
Note: See TracBrowser for help on using the repository browser.