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

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

some modification to allow encoding and decoding of SSR corrections in RTCM-SSR and IGS-SSR formats

File size: 23.4 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://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 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <stdio.h>
42#include <math.h>
43
44#include "RTCM3coDecoder.h"
45#include "bncutils.h"
46#include "bncrinex.h"
47#include "bnccore.h"
48#include "bncsettings.h"
49#include "bnctime.h"
50
51using namespace std;
52
53// Constructor
54////////////////////////////////////////////////////////////////////////////
55RTCM3coDecoder::RTCM3coDecoder(const QString& staID, const e_type type) {
56
57 _staID = staID;
58
59 // File Output
60 // -----------
61 bncSettings settings;
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 }
68 _fileNameSkl = path + staID;
69 }
70 _out = 0;
71
72 connect(this, SIGNAL(newOrbCorrections(QList<t_orbCorr>)),
73 BNC_CORE, SLOT(slotNewOrbCorrections(QList<t_orbCorr>)));
74
75 connect(this, SIGNAL(newClkCorrections(QList<t_clkCorr>)),
76 BNC_CORE, SLOT(slotNewClkCorrections(QList<t_clkCorr>)));
77
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
87 connect(this, SIGNAL(providerIDChanged(QString)),
88 BNC_CORE, SIGNAL(providerIDChanged(QString)));
89
90 connect(this, SIGNAL(newMessage(QByteArray,bool)),
91 BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
92
93 reset();
94
95 _providerID[0] = -1;
96 _providerID[1] = -1;
97 _providerID[2] = -1;
98
99 _type = type;
100 _ssrCorr = 0;
101}
102
103// Destructor
104////////////////////////////////////////////////////////////////////////////
105RTCM3coDecoder::~RTCM3coDecoder() {
106 delete _out;
107 delete _ssrCorr;
108 _IODs.clear();
109 _orbCorrections.clear();
110 _clkCorrections.clear();
111 _lastClkCorrections.clear();
112 _codeBiases.clear();
113 _phaseBiases.clear();
114 _vTecMap.clear();
115}
116
117//
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
126// Reopen Output File
127////////////////////////////////////////////////////////////////////////
128void RTCM3coDecoder::reopen() {
129
130 if (!_fileNameSkl.isEmpty()) {
131
132 bncSettings settings;
133
134 QDateTime datTim = currentDateAndTimeGPS();
135
136 QString hlpStr = bncRinex::nextEpochStr(datTim,
137 settings.value("corrIntr").toString(), false);
138
139 QString fileNameHlp = _fileNameSkl
140 + QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0'))
141 + hlpStr + datTim.toString(".yyC");
142
143 if (_fileName == fileNameHlp) {
144 return;
145 }
146 else {
147 _fileName = fileNameHlp;
148 }
149
150 delete _out;
151 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
152 _out = new ofstream( _fileName.toLatin1().data(), ios_base::out | ios_base::app );
153 }
154 else {
155 _out = new ofstream( _fileName.toLatin1().data() );
156 }
157 }
158}
159
160//
161////////////////////////////////////////////////////////////////////////////
162t_irc RTCM3coDecoder::Decode(char* buffer, int bufLen, vector<string>& errmsg) {
163
164 errmsg.clear();
165
166 _buffer.append(QByteArray(buffer,bufLen));
167
168 t_irc retCode = failure;
169
170 while(_buffer.size()) {
171
172 struct SsrCorr::ClockOrbit clkOrbSav;
173 struct SsrCorr::CodeBias codeBiasSav;
174 struct SsrCorr::PhaseBias phaseBiasSav;
175 struct SsrCorr::VTEC vTECSav;
176 memcpy(&clkOrbSav, &_clkOrb, sizeof(clkOrbSav)); // save state
177 memcpy(&codeBiasSav, &_codeBias, sizeof(codeBiasSav));
178 memcpy(&phaseBiasSav, &_phaseBias, sizeof(phaseBiasSav));
179 memcpy(&vTECSav, &_vTEC, sizeof(vTECSav));
180
181 int bytesused = 0;
182 if (_type == e_type::RTCMssr) {
183 _ssrCorr = new SsrCorrRtcm();
184 }
185 else {
186 _ssrCorr = new SsrCorrIgs();
187 }
188 GCOB_RETURN irc = _ssrCorr->GetSSR(&_clkOrb, &_codeBias, &_vTEC, &_phaseBias,
189 _buffer.data(), _buffer.size(), &bytesused);
190
191 if (irc <= -30) { // not enough data - restore state and exit loop
192 memcpy(&_clkOrb, &clkOrbSav, sizeof(clkOrbSav));
193 memcpy(&_codeBias, &codeBiasSav, sizeof(codeBiasSav));
194 memcpy(&_phaseBias, &phaseBiasSav, sizeof(phaseBiasSav));
195 memcpy(&_vTEC, &vTECSav, sizeof(vTECSav));
196 break;
197 }
198
199 else if (irc < 0) { // error - skip 1 byte and retry
200 reset();
201 _buffer = _buffer.mid(bytesused ? bytesused : 1);
202 }
203
204 else { // OK or MESSAGEFOLLOWS
205 _buffer = _buffer.mid(bytesused);
206
207 if (irc == GCOBR_OK || irc == GCOBR_MESSAGEFOLLOWS ) {
208
209 setEpochTime(); // sets _lastTime
210
211 if (_lastTime.valid()) {
212 reopen();
213 checkProviderID();
214 sendResults();
215 retCode = success;
216 }
217 else {
218 retCode = failure;
219 }
220
221 reset();
222 }
223 }
224 }
225
226 return retCode;
227}
228
229//
230////////////////////////////////////////////////////////////////////////////
231void RTCM3coDecoder::sendResults() {
232
233 // Orbit and clock corrections of all satellites
234 // ---------------------------------------------
235 for (unsigned ii = 0; ii < CLOCKORBIT_NUMGPS
236 + CLOCKORBIT_NUMGLONASS
237 + CLOCKORBIT_NUMGALILEO
238 + CLOCKORBIT_NUMQZSS
239 + CLOCKORBIT_NUMSBAS
240 + _clkOrb.NumberOfSat[CLOCKORBIT_SATBDS];
241 ii++) {
242 char sysCh = ' ';
243 int flag = 0;
244 if (ii < _clkOrb.NumberOfSat[CLOCKORBIT_SATGPS]) {
245 sysCh = 'G';
246 }
247 else if (ii >= CLOCKORBIT_OFFSETGLONASS &&
248 ii < CLOCKORBIT_OFFSETGLONASS + _clkOrb.NumberOfSat[CLOCKORBIT_SATGLONASS]) {
249 sysCh = 'R';
250 }
251 else if (ii >= CLOCKORBIT_OFFSETGALILEO &&
252 ii < CLOCKORBIT_OFFSETGALILEO + _clkOrb.NumberOfSat[CLOCKORBIT_SATGALILEO]) {
253 sysCh = 'E';
254 flag = 1; // I/NAV clock has been chosen as reference clock for Galileo SSR corrections
255 }
256 else if (ii >= CLOCKORBIT_OFFSETQZSS &&
257 ii < CLOCKORBIT_OFFSETQZSS + _clkOrb.NumberOfSat[CLOCKORBIT_SATQZSS]) {
258 sysCh = 'J';
259 }
260 else if (ii >= CLOCKORBIT_OFFSETSBAS &&
261 ii < CLOCKORBIT_OFFSETSBAS + _clkOrb.NumberOfSat[CLOCKORBIT_SATSBAS]) {
262 sysCh = 'S';
263 }
264 else if (ii >= CLOCKORBIT_OFFSETBDS &&
265 ii < CLOCKORBIT_OFFSETBDS + _clkOrb.NumberOfSat[CLOCKORBIT_SATBDS]) {
266 sysCh = 'C';
267 }
268 else {
269 continue;
270 }
271
272 // Orbit correction
273 // ----------------
274 if ( _clkOrb.messageType == _ssrCorr->COTYPE_GPSCOMBINED ||
275 _clkOrb.messageType == _ssrCorr->COTYPE_GLONASSCOMBINED ||
276 _clkOrb.messageType == _ssrCorr->COTYPE_GALILEOCOMBINED ||
277 _clkOrb.messageType == _ssrCorr->COTYPE_QZSSCOMBINED ||
278 _clkOrb.messageType == _ssrCorr->COTYPE_SBASCOMBINED ||
279 _clkOrb.messageType == _ssrCorr->COTYPE_BDSCOMBINED ||
280 _clkOrb.messageType == _ssrCorr->COTYPE_GPSORBIT ||
281 _clkOrb.messageType == _ssrCorr->COTYPE_GLONASSORBIT ||
282 _clkOrb.messageType == _ssrCorr->COTYPE_GALILEOORBIT ||
283 _clkOrb.messageType == _ssrCorr->COTYPE_QZSSORBIT ||
284 _clkOrb.messageType == _ssrCorr->COTYPE_SBASORBIT ||
285 _clkOrb.messageType == _ssrCorr->COTYPE_BDSORBIT ) {
286
287 t_orbCorr orbCorr;
288 orbCorr._prn.set(sysCh, _clkOrb.Sat[ii].ID, flag);
289 orbCorr._staID = _staID.toStdString();
290 orbCorr._iod = _clkOrb.Sat[ii].IOD;
291 orbCorr._time = _lastTime;
292 orbCorr._updateInt = _clkOrb.UpdateInterval;
293 orbCorr._system = sysCh;
294 orbCorr._xr[0] = _clkOrb.Sat[ii].Orbit.DeltaRadial;
295 orbCorr._xr[1] = _clkOrb.Sat[ii].Orbit.DeltaAlongTrack;
296 orbCorr._xr[2] = _clkOrb.Sat[ii].Orbit.DeltaCrossTrack;
297 orbCorr._dotXr[0] = _clkOrb.Sat[ii].Orbit.DotDeltaRadial;
298 orbCorr._dotXr[1] = _clkOrb.Sat[ii].Orbit.DotDeltaAlongTrack;
299 orbCorr._dotXr[2] = _clkOrb.Sat[ii].Orbit.DotDeltaCrossTrack;
300
301 _orbCorrections[_lastTime].append(orbCorr);
302
303 _IODs[orbCorr._prn] = _clkOrb.Sat[ii].IOD;
304 }
305
306 // Clock Corrections
307 // -----------------
308 if ( _clkOrb.messageType == _ssrCorr->COTYPE_GPSCOMBINED ||
309 _clkOrb.messageType == _ssrCorr->COTYPE_GLONASSCOMBINED ||
310 _clkOrb.messageType == _ssrCorr->COTYPE_GALILEOCOMBINED ||
311 _clkOrb.messageType == _ssrCorr->COTYPE_QZSSCOMBINED ||
312 _clkOrb.messageType == _ssrCorr->COTYPE_SBASCOMBINED ||
313 _clkOrb.messageType == _ssrCorr->COTYPE_BDSCOMBINED ||
314 _clkOrb.messageType == _ssrCorr->COTYPE_GPSCLOCK ||
315 _clkOrb.messageType == _ssrCorr->COTYPE_GLONASSCLOCK ||
316 _clkOrb.messageType == _ssrCorr->COTYPE_GALILEOCLOCK ||
317 _clkOrb.messageType == _ssrCorr->COTYPE_QZSSCLOCK ||
318 _clkOrb.messageType == _ssrCorr->COTYPE_SBASCLOCK ||
319 _clkOrb.messageType == _ssrCorr->COTYPE_BDSCLOCK) {
320
321 t_clkCorr clkCorr;
322 clkCorr._prn.set(sysCh, _clkOrb.Sat[ii].ID, flag);
323 clkCorr._staID = _staID.toStdString();
324 clkCorr._time = _lastTime;
325 clkCorr._updateInt = _clkOrb.UpdateInterval;
326 clkCorr._dClk = _clkOrb.Sat[ii].Clock.DeltaA0 / t_CST::c;
327 clkCorr._dotDClk = _clkOrb.Sat[ii].Clock.DeltaA1 / t_CST::c;
328 clkCorr._dotDotDClk = _clkOrb.Sat[ii].Clock.DeltaA2 / t_CST::c;
329
330 _lastClkCorrections[clkCorr._prn] = clkCorr;
331
332 if (_IODs.contains(clkCorr._prn)) {
333 clkCorr._iod = _IODs[clkCorr._prn];
334 _clkCorrections[_lastTime].append(clkCorr);
335 }
336 }
337
338 // High-Resolution Clocks
339 // ----------------------
340 if ( _clkOrb.messageType == _ssrCorr->COTYPE_GPSHR ||
341 _clkOrb.messageType == _ssrCorr->COTYPE_GLONASSHR ||
342 _clkOrb.messageType == _ssrCorr->COTYPE_GALILEOHR ||
343 _clkOrb.messageType == _ssrCorr->COTYPE_QZSSHR ||
344 _clkOrb.messageType == _ssrCorr->COTYPE_SBASHR ||
345 _clkOrb.messageType == _ssrCorr->COTYPE_BDSHR) {
346 t_prn prn(sysCh, _clkOrb.Sat[ii].ID, flag);
347 if (_lastClkCorrections.contains(prn)) {
348 t_clkCorr clkCorr;
349 clkCorr = _lastClkCorrections[prn];
350 clkCorr._time = _lastTime;
351 clkCorr._updateInt = _clkOrb.UpdateInterval;
352 clkCorr._dClk += _clkOrb.Sat[ii].hrclock / t_CST::c;
353 if (_IODs.contains(clkCorr._prn)) {
354 clkCorr._iod = _IODs[clkCorr._prn];
355 _clkCorrections[_lastTime].push_back(clkCorr);
356 }
357 }
358 }
359 }
360
361 // Code Biases
362 // -----------
363 for (unsigned ii = 0; ii < CLOCKORBIT_NUMGPS
364 + CLOCKORBIT_NUMGLONASS
365 + CLOCKORBIT_NUMGALILEO
366 + CLOCKORBIT_NUMQZSS
367 + CLOCKORBIT_NUMSBAS
368 + _codeBias.NumberOfSat[CLOCKORBIT_SATBDS];
369 ii++) {
370 char sysCh = ' ';
371 if (ii < _codeBias.NumberOfSat[CLOCKORBIT_SATGPS]) {
372 sysCh = 'G';
373 }
374 else if (ii >= CLOCKORBIT_OFFSETGLONASS &&
375 ii < CLOCKORBIT_OFFSETGLONASS + _codeBias.NumberOfSat[CLOCKORBIT_SATGLONASS]) {
376 sysCh = 'R';
377 }
378 else if (ii >= CLOCKORBIT_OFFSETGALILEO &&
379 ii < CLOCKORBIT_OFFSETGALILEO + _codeBias.NumberOfSat[CLOCKORBIT_SATGALILEO]) {
380 sysCh = 'E';
381 }
382 else if (ii >= CLOCKORBIT_OFFSETQZSS &&
383 ii < CLOCKORBIT_OFFSETQZSS + _codeBias.NumberOfSat[CLOCKORBIT_SATQZSS]) {
384 sysCh = 'J';
385 }
386 else if (ii >= CLOCKORBIT_OFFSETSBAS &&
387 ii < CLOCKORBIT_OFFSETSBAS + _codeBias.NumberOfSat[CLOCKORBIT_SATSBAS]) {
388 sysCh = 'S';
389 }
390 else if (ii >= CLOCKORBIT_OFFSETBDS &&
391 ii < CLOCKORBIT_OFFSETBDS + _codeBias.NumberOfSat[CLOCKORBIT_SATBDS]) {
392 sysCh = 'C';
393 }
394 else {
395 continue;
396 }
397 t_satCodeBias satCodeBias;
398 satCodeBias._prn.set(sysCh, _codeBias.Sat[ii].ID);
399 satCodeBias._staID = _staID.toStdString();
400 satCodeBias._time = _lastTime;
401 satCodeBias._updateInt = _codeBias.UpdateInterval;
402 for (unsigned jj = 0; jj < _codeBias.Sat[ii].NumberOfCodeBiases; jj++) {
403 const SsrCorr::CodeBias::BiasSat::CodeBiasEntry& biasEntry = _codeBias.Sat[ii].Biases[jj];
404 t_frqCodeBias frqCodeBias;
405 frqCodeBias._rnxType2ch.assign(_ssrCorr->codeTypeToRnxType(sysCh, biasEntry.Type));
406 frqCodeBias._value = biasEntry.Bias;
407 if (!frqCodeBias._rnxType2ch.empty()) {
408 satCodeBias._bias.push_back(frqCodeBias);
409 }
410 }
411 _codeBiases[_lastTime].append(satCodeBias);
412 }
413
414 // Phase Biases
415 // -----------
416 for (unsigned ii = 0; ii < CLOCKORBIT_NUMGPS
417 + CLOCKORBIT_NUMGLONASS
418 + CLOCKORBIT_NUMGALILEO
419 + CLOCKORBIT_NUMQZSS
420 + CLOCKORBIT_NUMSBAS
421 + _phaseBias.NumberOfSat[CLOCKORBIT_SATBDS];
422 ii++) {
423 char sysCh = ' ';
424 if (ii < _phaseBias.NumberOfSat[CLOCKORBIT_SATGPS]) {
425 sysCh = 'G';
426 }
427 else if (ii >= CLOCKORBIT_OFFSETGLONASS &&
428 ii < CLOCKORBIT_OFFSETGLONASS + _phaseBias.NumberOfSat[CLOCKORBIT_SATGLONASS]) {
429 sysCh = 'R';
430 }
431 else if (ii >= CLOCKORBIT_OFFSETGALILEO &&
432 ii < CLOCKORBIT_OFFSETGALILEO + _phaseBias.NumberOfSat[CLOCKORBIT_SATGALILEO]) {
433 sysCh = 'E';
434 }
435 else if (ii >= CLOCKORBIT_OFFSETQZSS &&
436 ii < CLOCKORBIT_OFFSETQZSS + _phaseBias.NumberOfSat[CLOCKORBIT_SATQZSS]) {
437 sysCh = 'J';
438 }
439 else if (ii >= CLOCKORBIT_OFFSETSBAS &&
440 ii < CLOCKORBIT_OFFSETSBAS + _phaseBias.NumberOfSat[CLOCKORBIT_SATSBAS]) {
441 sysCh = 'S';
442 }
443 else if (ii >= CLOCKORBIT_OFFSETBDS &&
444 ii < CLOCKORBIT_OFFSETBDS + _phaseBias.NumberOfSat[CLOCKORBIT_SATBDS]) {
445 sysCh = 'C';
446 }
447 else {
448 continue;
449 }
450 t_satPhaseBias satPhaseBias;
451 satPhaseBias._prn.set(sysCh, _phaseBias.Sat[ii].ID);
452 satPhaseBias._staID = _staID.toStdString();
453 satPhaseBias._time = _lastTime;
454 satPhaseBias._updateInt = _phaseBias.UpdateInterval;
455 satPhaseBias._dispBiasConstistInd = _phaseBias.DispersiveBiasConsistencyIndicator;
456 satPhaseBias._MWConsistInd = _phaseBias.MWConsistencyIndicator;
457 satPhaseBias._yaw = _phaseBias.Sat[ii].YawAngle;
458 satPhaseBias._yawRate = _phaseBias.Sat[ii].YawRate;
459 for (unsigned jj = 0; jj < _phaseBias.Sat[ii].NumberOfPhaseBiases; jj++) {
460 const SsrCorr::PhaseBias::PhaseBiasSat::PhaseBiasEntry& biasEntry = _phaseBias.Sat[ii].Biases[jj];
461 t_frqPhaseBias frqPhaseBias;
462 frqPhaseBias._rnxType2ch.assign(_ssrCorr->codeTypeToRnxType(sysCh, biasEntry.Type));
463 frqPhaseBias._value = biasEntry.Bias;
464 frqPhaseBias._fixIndicator = biasEntry.SignalIntegerIndicator;
465 frqPhaseBias._fixWideLaneIndicator = biasEntry.SignalsWideLaneIntegerIndicator;
466 frqPhaseBias._jumpCounter = biasEntry.SignalDiscontinuityCounter;
467 if (!frqPhaseBias._rnxType2ch.empty()) {
468 satPhaseBias._bias.push_back(frqPhaseBias);
469 }
470 }
471 _phaseBiases[_lastTime].append(satPhaseBias);
472 }
473
474 // Ionospheric Model
475 // -----------------
476 if (_vTEC.NumLayers > 0) {
477 _vTecMap[_lastTime]._time = _lastTime;
478 _vTecMap[_lastTime]._updateInt = _vTEC.UpdateInterval;
479 _vTecMap[_lastTime]._staID = _staID.toStdString();
480 for (unsigned ii = 0; ii < _vTEC.NumLayers; ii++) {
481 const SsrCorr::VTEC::IonoLayers& ionoLayer = _vTEC.Layers[ii];
482 t_vTecLayer layer;
483 layer._height = ionoLayer.Height;
484 layer._C.ReSize(ionoLayer.Degree+1, ionoLayer.Order+1);
485 layer._S.ReSize(ionoLayer.Degree+1, ionoLayer.Order+1);
486 for (unsigned iDeg = 0; iDeg <= ionoLayer.Degree; iDeg++) {
487 for (unsigned iOrd = 0; iOrd <= ionoLayer.Order; iOrd++) {
488 layer._C[iDeg][iOrd] = ionoLayer.Cosinus[iDeg][iOrd];
489 layer._S[iDeg][iOrd] = ionoLayer.Sinus[iDeg][iOrd];
490 }
491 }
492 _vTecMap[_lastTime]._layers.push_back(layer);
493 }
494 }
495
496 // Dump all older epochs
497 // ---------------------
498 QMutableMapIterator<bncTime, QList<t_orbCorr> > itOrb(_orbCorrections);
499 while (itOrb.hasNext()) {
500 itOrb.next();
501 if (itOrb.key() < _lastTime) {
502 emit newOrbCorrections(itOrb.value());
503 t_orbCorr::writeEpoch(_out, itOrb.value());
504 itOrb.remove();
505 }
506 }
507 QMutableMapIterator<bncTime, QList<t_clkCorr> > itClk(_clkCorrections);
508 while (itClk.hasNext()) {
509 itClk.next();
510 if (itClk.key() < _lastTime) {
511 emit newClkCorrections(itClk.value());
512 t_clkCorr::writeEpoch(_out, itClk.value());
513 itClk.remove();
514 }
515 }
516 QMutableMapIterator<bncTime, QList<t_satCodeBias> > itCB(_codeBiases);
517 while (itCB.hasNext()) {
518 itCB.next();
519 if (itCB.key() < _lastTime) {
520 emit newCodeBiases(itCB.value());
521 t_satCodeBias::writeEpoch(_out, itCB.value());
522 itCB.remove();
523 }
524 }
525 QMutableMapIterator<bncTime, QList<t_satPhaseBias> > itPB(_phaseBiases);
526 while (itPB.hasNext()) {
527 itPB.next();
528 if (itPB.key() < _lastTime) {
529 emit newPhaseBiases(itPB.value());
530 t_satPhaseBias::writeEpoch(_out, itPB.value());
531 itPB.remove();
532 }
533 }
534 QMutableMapIterator<bncTime, t_vTec> itTec(_vTecMap);
535 while (itTec.hasNext()) {
536 itTec.next();
537 if (itTec.key() < _lastTime) {
538 emit newTec(itTec.value());
539 t_vTec::write(_out, itTec.value());
540 itTec.remove();
541 }
542 }
543}
544
545//
546////////////////////////////////////////////////////////////////////////////
547void RTCM3coDecoder::checkProviderID() {
548
549 if (_clkOrb.SSRProviderID == 0 && _clkOrb.SSRSolutionID == 0 && _clkOrb.SSRIOD == 0) {
550 return;
551 }
552
553 int newProviderID[3];
554 newProviderID[0] = _clkOrb.SSRProviderID;
555 newProviderID[1] = _clkOrb.SSRSolutionID;
556 newProviderID[2] = _clkOrb.SSRIOD;
557
558 bool alreadySet = false;
559 bool different = false;
560
561 for (unsigned ii = 0; ii < 3; ii++) {
562 if (_providerID[ii] != -1) {
563 alreadySet = true;
564 }
565 if (_providerID[ii] != newProviderID[ii]) {
566 different = true;
567 }
568 _providerID[ii] = newProviderID[ii];
569 }
570
571 if (alreadySet && different) {
572 emit newMessage("RTCM3coDecoder: Provider Changed: " + _staID.toLatin1(), true);
573 emit providerIDChanged(_staID);
574 }
575}
576
577//
578////////////////////////////////////////////////////////////////////////////
579void RTCM3coDecoder::setEpochTime() {
580
581 _lastTime.reset();
582
583 double epoSecGPS = -1.0;
584 double epoSecGlo = -1.0;
585 double epoSecGal = -1.0;
586 double epoSecQzss = -1.0;
587 double epoSecSbas = -1.0;
588 double epoSecBds = -1.0;
589 if (_clkOrb.NumberOfSat[CLOCKORBIT_SATGPS] > 0) {
590 epoSecGPS = _clkOrb.EpochTime[CLOCKORBIT_SATGPS]; // 0 .. 604799 s
591 }
592 else if (_codeBias.NumberOfSat[CLOCKORBIT_SATGPS] > 0) {
593 epoSecGPS = _codeBias.EpochTime[CLOCKORBIT_SATGPS]; // 0 .. 604799 s
594 }
595 else if (_phaseBias.NumberOfSat[CLOCKORBIT_SATGPS] > 0) {
596 epoSecGPS = _phaseBias.EpochTime[CLOCKORBIT_SATGPS]; // 0 .. 604799 s
597 }
598 else if (_vTEC.NumLayers > 0) {
599 epoSecGPS = _vTEC.EpochTime; // 0 .. 604799 s
600 }
601 else if (_clkOrb.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) {
602 epoSecGlo = _clkOrb.EpochTime[CLOCKORBIT_SATGLONASS]; // 0 .. 86399 s
603 }
604 else if (_codeBias.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) {
605 epoSecGlo = _codeBias.EpochTime[CLOCKORBIT_SATGLONASS]; // 0 .. 86399 s
606 }
607 else if (_phaseBias.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) {
608 epoSecGlo = _phaseBias.EpochTime[CLOCKORBIT_SATGLONASS]; // 0 .. 86399 s
609 }
610 else if (_clkOrb.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0) {
611 epoSecGal = _clkOrb.EpochTime[CLOCKORBIT_SATGALILEO];
612 }
613 else if (_codeBias.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0) {
614 epoSecGal = _codeBias.EpochTime[CLOCKORBIT_SATGALILEO];
615 }
616 else if (_phaseBias.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0) {
617 epoSecGal = _phaseBias.EpochTime[CLOCKORBIT_SATGALILEO];
618 }
619 else if (_clkOrb.NumberOfSat[CLOCKORBIT_SATQZSS] > 0) {
620 epoSecQzss = _clkOrb.EpochTime[CLOCKORBIT_SATQZSS];
621 }
622 else if (_codeBias.NumberOfSat[CLOCKORBIT_SATQZSS] > 0) {
623 epoSecQzss = _codeBias.EpochTime[CLOCKORBIT_SATQZSS];
624 }
625 else if (_phaseBias.NumberOfSat[CLOCKORBIT_SATQZSS] > 0) {
626 epoSecQzss = _phaseBias.EpochTime[CLOCKORBIT_SATQZSS];
627 }
628 else if (_clkOrb.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) {
629 epoSecSbas = _clkOrb.EpochTime[CLOCKORBIT_SATSBAS];
630 }
631 else if (_codeBias.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) {
632 epoSecSbas = _codeBias.EpochTime[CLOCKORBIT_SATSBAS];
633 }
634 else if (_phaseBias.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) {
635 epoSecSbas = _phaseBias.EpochTime[CLOCKORBIT_SATSBAS];
636 }
637 else if (_clkOrb.NumberOfSat[CLOCKORBIT_SATBDS] > 0) {
638 epoSecBds = _clkOrb.EpochTime[CLOCKORBIT_SATBDS];
639 }
640 else if (_codeBias.NumberOfSat[CLOCKORBIT_SATBDS] > 0) {
641 epoSecBds = _codeBias.EpochTime[CLOCKORBIT_SATBDS];
642 }
643 else if (_phaseBias.NumberOfSat[CLOCKORBIT_SATBDS] > 0) {
644 epoSecBds = _phaseBias.EpochTime[CLOCKORBIT_SATBDS];
645 }
646
647 // Retrieve current time
648 // ---------------------
649 int currentWeek = 0;
650 double currentSec = 0.0;
651 currentGPSWeeks(currentWeek, currentSec);
652 bncTime currentTime(currentWeek, currentSec);
653
654 // Set _lastTime close to currentTime
655 // ----------------------------------
656 if (epoSecGPS != -1) {
657 _lastTime.set(currentWeek, epoSecGPS);
658 }
659 else if (epoSecGlo != -1) {
660 if (_type == e_type::RTCMssr) {
661 QDate date = dateAndTimeFromGPSweek(currentTime.gpsw(), currentTime.gpssec()).date();
662 epoSecGlo = epoSecGlo - 3 * 3600 + gnumleap(date.year(), date.month(), date.day());
663 }
664 _lastTime.set(currentWeek, epoSecGlo);
665 }
666 else if (epoSecGal != -1) {
667 _lastTime.set(currentWeek, epoSecGal);
668 }
669 else if (epoSecQzss != -1) {
670 _lastTime.set(currentWeek, epoSecQzss);
671 }
672 else if (epoSecSbas != -1) {
673 _lastTime.set(currentWeek, epoSecSbas);
674 }
675 else if (epoSecBds != -1) {
676 if (_type == e_type::RTCMssr) {
677 epoSecBds += 14.0;
678 if (epoSecBds > 604800.0) {
679 epoSecBds -= 7.0*24.0*60.0*60.0;
680 }
681 }
682 _lastTime.set(currentWeek, epoSecBds);
683 }
684
685 if (_lastTime.valid()) {
686 double maxDiff = 12 * 3600.0;
687 while (_lastTime < currentTime - maxDiff) {
688 _lastTime = _lastTime + maxDiff;
689 }
690 while (_lastTime > currentTime + maxDiff) {
691 _lastTime = _lastTime - maxDiff;
692 }
693 }
694}
Note: See TracBrowser for help on using the repository browser.