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

Last change on this file since 10605 was 10599, checked in by stuerze, 11 days ago

ADDED: consideration of NAV type in all applications

File size: 26.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://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) {
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 _ssrCorr = 0;
100
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(), 3);
138
139 QString cntStr = (_fileNameSkl.contains("ION")) ? "_ION.ssr" : "_MC.ssr";
140
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')) +
145 hlpStr + // HM_period
146 cntStr; // mixed ION or CLK
147
148 if (_fileName == fileNameHlp) {
149 return;
150 }
151 else {
152 _fileName = fileNameHlp;
153 }
154
155 delete _out;
156 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
157 _out = new ofstream( _fileName.toLatin1().data(), ios_base::out | ios_base::app );
158 }
159 else {
160 _out = new ofstream( _fileName.toLatin1().data() );
161 }
162 }
163}
164
165//
166////////////////////////////////////////////////////////////////////////////
167t_irc RTCM3coDecoder::Decode(char* buffer, int bufLen, vector<string>& errmsg) {
168
169 errmsg.clear();
170
171 _buffer.append(QByteArray(buffer,bufLen));
172
173 t_irc retCode = failure;
174
175 while(_buffer.size()) {
176
177 struct SsrCorr::ClockOrbit clkOrbSav;
178 struct SsrCorr::CodeBias codeBiasSav;
179 struct SsrCorr::PhaseBias phaseBiasSav;
180 struct SsrCorr::VTEC vTECSav;
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));
185
186 int bytesused = 0;
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 setEpochTime(); // sets _lastTime
209
210 if (_lastTime.valid()) {
211 reopen();
212 checkProviderID();
213 sendResults();
214 retCode = success;
215 }
216 else {
217 emit newMessage("RTCM3coDecoder: _lastTime invalid: " + _staID.toLatin1(), true);
218 retCode = failure;
219 }
220 reset();
221 }
222 }
223 }
224
225 return retCode;
226}
227
228//
229////////////////////////////////////////////////////////////////////////////
230void RTCM3coDecoder::sendResults() {
231
232 // Orbit and clock corrections of all satellites
233 // ---------------------------------------------
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++) {
241 if (corrIsOutOfRange(_clkOrb.Sat[ii])) {
242 emit newMessage("RTCM3coDecoder: Correction out of range " + _staID.toLatin1(), true);
243 continue;
244 }
245 char sys = ' ';
246 int num = _clkOrb.Sat[ii].ID;
247 int flag = 0; // to force NAV type usage according SSR standard
248 if (ii < _clkOrb.NumberOfSat[CLOCKORBIT_SATGPS]) {
249 sys = 'G';
250 flag = t_eph::LNAV;
251 }
252 else if (ii >= CLOCKORBIT_OFFSETGLONASS &&
253 ii < CLOCKORBIT_OFFSETGLONASS + _clkOrb.NumberOfSat[CLOCKORBIT_SATGLONASS]) {
254 sys = 'R';
255 flag = t_eph::FDMA_M;
256 }
257 else if (ii >= CLOCKORBIT_OFFSETGALILEO &&
258 ii < CLOCKORBIT_OFFSETGALILEO + _clkOrb.NumberOfSat[CLOCKORBIT_SATGALILEO]) {
259 sys = 'E';
260 flag = t_eph::INAV;
261 }
262 else if (ii >= CLOCKORBIT_OFFSETQZSS &&
263 ii < CLOCKORBIT_OFFSETQZSS + _clkOrb.NumberOfSat[CLOCKORBIT_SATQZSS]) {
264 sys = 'J';
265 flag = t_eph::LNAV;
266 }
267 else if (ii >= CLOCKORBIT_OFFSETSBAS &&
268 ii < CLOCKORBIT_OFFSETSBAS + _clkOrb.NumberOfSat[CLOCKORBIT_SATSBAS]) {
269 sys = 'S';
270 flag = t_eph::SBASL1;
271 }
272 else if (ii >= CLOCKORBIT_OFFSETBDS &&
273 ii < CLOCKORBIT_OFFSETBDS + _clkOrb.NumberOfSat[CLOCKORBIT_SATBDS]) {
274 sys = 'C';
275 if (num < 6) {// GEO
276 flag = t_eph::D2;
277 }
278 else if (num > 58 && num < 63) { // GEO
279 flag = t_eph::D2;
280 }
281 else {
282 flag = t_eph::D1;
283 }
284 }
285 else {
286 continue;
287 }
288
289 // Orbit correction
290 // ----------------
291 if ( _clkOrb.messageType == _ssrCorr->COTYPE_GPSCOMBINED ||
292 _clkOrb.messageType == _ssrCorr->COTYPE_GLONASSCOMBINED ||
293 _clkOrb.messageType == _ssrCorr->COTYPE_GALILEOCOMBINED ||
294 _clkOrb.messageType == _ssrCorr->COTYPE_QZSSCOMBINED ||
295 _clkOrb.messageType == _ssrCorr->COTYPE_SBASCOMBINED ||
296 _clkOrb.messageType == _ssrCorr->COTYPE_BDSCOMBINED ||
297 _clkOrb.messageType == _ssrCorr->COTYPE_GPSORBIT ||
298 _clkOrb.messageType == _ssrCorr->COTYPE_GLONASSORBIT ||
299 _clkOrb.messageType == _ssrCorr->COTYPE_GALILEOORBIT ||
300 _clkOrb.messageType == _ssrCorr->COTYPE_QZSSORBIT ||
301 _clkOrb.messageType == _ssrCorr->COTYPE_SBASORBIT ||
302 _clkOrb.messageType == _ssrCorr->COTYPE_BDSORBIT ) {
303
304 t_orbCorr orbCorr;
305 orbCorr._prn.set(sys, num, flag);
306 orbCorr._staID = _staID.toStdString();
307 orbCorr._iod = _clkOrb.Sat[ii].IOD;
308 orbCorr._time = _lastTime;
309 orbCorr._updateInt = _clkOrb.UpdateInterval;
310 orbCorr._system = sys;
311 orbCorr._xr[0] = _clkOrb.Sat[ii].Orbit.DeltaRadial;
312 orbCorr._xr[1] = _clkOrb.Sat[ii].Orbit.DeltaAlongTrack;
313 orbCorr._xr[2] = _clkOrb.Sat[ii].Orbit.DeltaCrossTrack;
314 orbCorr._dotXr[0] = _clkOrb.Sat[ii].Orbit.DotDeltaRadial;
315 orbCorr._dotXr[1] = _clkOrb.Sat[ii].Orbit.DotDeltaAlongTrack;
316 orbCorr._dotXr[2] = _clkOrb.Sat[ii].Orbit.DotDeltaCrossTrack;
317
318 _orbCorrections[_lastTime].append(orbCorr);
319
320 _IODs[orbCorr._prn] = _clkOrb.Sat[ii].IOD;
321 }
322
323 // Clock Corrections
324 // -----------------
325 if ( _clkOrb.messageType == _ssrCorr->COTYPE_GPSCOMBINED ||
326 _clkOrb.messageType == _ssrCorr->COTYPE_GLONASSCOMBINED ||
327 _clkOrb.messageType == _ssrCorr->COTYPE_GALILEOCOMBINED ||
328 _clkOrb.messageType == _ssrCorr->COTYPE_QZSSCOMBINED ||
329 _clkOrb.messageType == _ssrCorr->COTYPE_SBASCOMBINED ||
330 _clkOrb.messageType == _ssrCorr->COTYPE_BDSCOMBINED ||
331 _clkOrb.messageType == _ssrCorr->COTYPE_GPSCLOCK ||
332 _clkOrb.messageType == _ssrCorr->COTYPE_GLONASSCLOCK ||
333 _clkOrb.messageType == _ssrCorr->COTYPE_GALILEOCLOCK ||
334 _clkOrb.messageType == _ssrCorr->COTYPE_QZSSCLOCK ||
335 _clkOrb.messageType == _ssrCorr->COTYPE_SBASCLOCK ||
336 _clkOrb.messageType == _ssrCorr->COTYPE_BDSCLOCK) {
337
338 t_clkCorr clkCorr;
339 clkCorr._prn.set(sys, _clkOrb.Sat[ii].ID, flag);
340 clkCorr._staID = _staID.toStdString();
341 clkCorr._time = _lastTime;
342 clkCorr._updateInt = _clkOrb.UpdateInterval;
343 clkCorr._dClk = _clkOrb.Sat[ii].Clock.DeltaA0 / t_CST::c;
344 clkCorr._dotDClk = _clkOrb.Sat[ii].Clock.DeltaA1 / t_CST::c;
345 clkCorr._dotDotDClk = _clkOrb.Sat[ii].Clock.DeltaA2 / t_CST::c;
346
347 _lastClkCorrections[clkCorr._prn] = clkCorr;
348
349 if (_IODs.contains(clkCorr._prn)) {
350 clkCorr._iod = _IODs[clkCorr._prn];
351 _clkCorrections[_lastTime].append(clkCorr);
352 }
353 }
354
355 // High-Resolution Clocks
356 // ----------------------
357 if ( _clkOrb.messageType == _ssrCorr->COTYPE_GPSHR ||
358 _clkOrb.messageType == _ssrCorr->COTYPE_GLONASSHR ||
359 _clkOrb.messageType == _ssrCorr->COTYPE_GALILEOHR ||
360 _clkOrb.messageType == _ssrCorr->COTYPE_QZSSHR ||
361 _clkOrb.messageType == _ssrCorr->COTYPE_SBASHR ||
362 _clkOrb.messageType == _ssrCorr->COTYPE_BDSHR) {
363 t_prn prn(sys, _clkOrb.Sat[ii].ID, flag);
364 if (_lastClkCorrections.contains(prn)) {
365 t_clkCorr clkCorr;
366 clkCorr = _lastClkCorrections[prn];
367 clkCorr._time = _lastTime;
368 clkCorr._updateInt = _clkOrb.UpdateInterval;
369 clkCorr._dClk += _clkOrb.Sat[ii].hrclock / t_CST::c;
370 if (_IODs.contains(clkCorr._prn)) {
371 clkCorr._iod = _IODs[clkCorr._prn];
372 _clkCorrections[_lastTime].append(clkCorr);
373 }
374 }
375 }
376 }
377
378 // Code Biases
379 // -----------
380 for (unsigned ii = 0; ii < CLOCKORBIT_NUMGPS
381 + CLOCKORBIT_NUMGLONASS
382 + CLOCKORBIT_NUMGALILEO
383 + CLOCKORBIT_NUMQZSS
384 + CLOCKORBIT_NUMSBAS
385 + _codeBias.NumberOfSat[CLOCKORBIT_SATBDS];
386 ii++) {
387 char sys = ' ';
388 int num = _codeBias.Sat[ii].ID;
389 int flag = 0;
390 if (ii < _codeBias.NumberOfSat[CLOCKORBIT_SATGPS]) {
391 sys = 'G';
392 flag = t_eph::LNAV;
393 }
394 else if (ii >= CLOCKORBIT_OFFSETGLONASS &&
395 ii < CLOCKORBIT_OFFSETGLONASS + _codeBias.NumberOfSat[CLOCKORBIT_SATGLONASS]) {
396 sys = 'R';
397 flag = t_eph::FDMA_M;
398 }
399 else if (ii >= CLOCKORBIT_OFFSETGALILEO &&
400 ii < CLOCKORBIT_OFFSETGALILEO + _codeBias.NumberOfSat[CLOCKORBIT_SATGALILEO]) {
401 sys = 'E';
402 flag = t_eph::INAV;
403 }
404 else if (ii >= CLOCKORBIT_OFFSETQZSS &&
405 ii < CLOCKORBIT_OFFSETQZSS + _codeBias.NumberOfSat[CLOCKORBIT_SATQZSS]) {
406 sys = 'J';
407 flag = t_eph::LNAV;
408 }
409 else if (ii >= CLOCKORBIT_OFFSETSBAS &&
410 ii < CLOCKORBIT_OFFSETSBAS + _codeBias.NumberOfSat[CLOCKORBIT_SATSBAS]) {
411 sys = 'S';
412 flag = t_eph::SBASL1;
413 }
414 else if (ii >= CLOCKORBIT_OFFSETBDS &&
415 ii < CLOCKORBIT_OFFSETBDS + _codeBias.NumberOfSat[CLOCKORBIT_SATBDS]) {
416 sys = 'C';
417 if (num < 6) {// GEO
418 flag = t_eph::D2;
419 }
420 else if (num > 58 && num < 63) { // GEO
421 flag = t_eph::D2;
422 }
423 else {
424 flag = t_eph::D1;
425 }
426 }
427 else {
428 continue;
429 }
430 t_satCodeBias satCodeBias;
431 satCodeBias._prn.set(sys, num, flag);
432 satCodeBias._staID = _staID.toStdString();
433 satCodeBias._time = _lastTime;
434 satCodeBias._updateInt = _codeBias.UpdateInterval;
435 for (unsigned jj = 0; jj < _codeBias.Sat[ii].NumberOfCodeBiases; jj++) {
436 const SsrCorr::CodeBias::BiasSat::CodeBiasEntry& biasEntry = _codeBias.Sat[ii].Biases[jj];
437 t_frqCodeBias frqCodeBias;
438 frqCodeBias._rnxType2ch.assign(_ssrCorr->codeTypeToRnxType(sys, biasEntry.Type));
439 frqCodeBias._value = biasEntry.Bias;
440 if (!frqCodeBias._rnxType2ch.empty()) {
441 satCodeBias._bias.push_back(frqCodeBias);
442 }
443 }
444 _codeBiases[_lastTime].append(satCodeBias);
445 }
446
447 // Phase Biases
448 // -----------
449 for (unsigned ii = 0; ii < CLOCKORBIT_NUMGPS
450 + CLOCKORBIT_NUMGLONASS
451 + CLOCKORBIT_NUMGALILEO
452 + CLOCKORBIT_NUMQZSS
453 + CLOCKORBIT_NUMSBAS
454 + _phaseBias.NumberOfSat[CLOCKORBIT_SATBDS];
455 ii++) {
456 char sys = ' ';
457 int num = _phaseBias.Sat[ii].ID;
458 int flag = 0;
459 if (ii < _phaseBias.NumberOfSat[CLOCKORBIT_SATGPS]) {
460 sys = 'G';
461 flag = t_eph::LNAV;
462 }
463 else if (ii >= CLOCKORBIT_OFFSETGLONASS &&
464 ii < CLOCKORBIT_OFFSETGLONASS + _phaseBias.NumberOfSat[CLOCKORBIT_SATGLONASS]) {
465 sys = 'R';
466 flag = t_eph::FDMA_M;
467 }
468 else if (ii >= CLOCKORBIT_OFFSETGALILEO &&
469 ii < CLOCKORBIT_OFFSETGALILEO + _phaseBias.NumberOfSat[CLOCKORBIT_SATGALILEO]) {
470 sys = 'E';
471 flag = t_eph::INAV;
472 }
473 else if (ii >= CLOCKORBIT_OFFSETQZSS &&
474 ii < CLOCKORBIT_OFFSETQZSS + _phaseBias.NumberOfSat[CLOCKORBIT_SATQZSS]) {
475 sys = 'J';
476 flag = t_eph::LNAV;
477 }
478 else if (ii >= CLOCKORBIT_OFFSETSBAS &&
479 ii < CLOCKORBIT_OFFSETSBAS + _phaseBias.NumberOfSat[CLOCKORBIT_SATSBAS]) {
480 sys = 'S';
481 flag = t_eph::SBASL1;
482 }
483 else if (ii >= CLOCKORBIT_OFFSETBDS &&
484 ii < CLOCKORBIT_OFFSETBDS + _phaseBias.NumberOfSat[CLOCKORBIT_SATBDS]) {
485 sys = 'C';
486 if (num < 6) {// GEO
487 flag = t_eph::D2;
488 }
489 else if (num > 58 && num < 63) { // GEO
490 flag = t_eph::D2;
491 }
492 else {
493 flag = t_eph::D1;
494 }
495 }
496 else {
497 continue;
498 }
499 t_satPhaseBias satPhaseBias;
500 satPhaseBias._prn.set(sys, num, flag);
501 satPhaseBias._staID = _staID.toStdString();
502 satPhaseBias._time = _lastTime;
503 satPhaseBias._updateInt = _phaseBias.UpdateInterval;
504 satPhaseBias._dispBiasConstistInd = _phaseBias.DispersiveBiasConsistencyIndicator;
505 satPhaseBias._MWConsistInd = _phaseBias.MWConsistencyIndicator;
506 satPhaseBias._yaw = _phaseBias.Sat[ii].YawAngle;
507 satPhaseBias._yawRate = _phaseBias.Sat[ii].YawRate;
508 for (unsigned jj = 0; jj < _phaseBias.Sat[ii].NumberOfPhaseBiases; jj++) {
509 const SsrCorr::PhaseBias::PhaseBiasSat::PhaseBiasEntry& biasEntry = _phaseBias.Sat[ii].Biases[jj];
510 t_frqPhaseBias frqPhaseBias;
511 frqPhaseBias._rnxType2ch.assign(_ssrCorr->codeTypeToRnxType(sys, biasEntry.Type));
512 frqPhaseBias._value = biasEntry.Bias;
513 frqPhaseBias._fixIndicator = biasEntry.SignalIntegerIndicator;
514 frqPhaseBias._fixWideLaneIndicator = biasEntry.SignalsWideLaneIntegerIndicator;
515 frqPhaseBias._jumpCounter = biasEntry.SignalDiscontinuityCounter;
516 if (!frqPhaseBias._rnxType2ch.empty()) {
517 satPhaseBias._bias.push_back(frqPhaseBias);
518 }
519 }
520 _phaseBiases[_lastTime].append(satPhaseBias);
521 }
522
523 // Ionospheric Model
524 // -----------------
525 if (_vTEC.NumLayers > 0) {
526 _vTecMap[_lastTime]._time = _lastTime;
527 _vTecMap[_lastTime]._updateInt = _vTEC.UpdateInterval;
528 _vTecMap[_lastTime]._staID = _staID.toStdString();
529 for (unsigned ii = 0; ii < _vTEC.NumLayers; ii++) {
530 const SsrCorr::VTEC::IonoLayers& ionoLayer = _vTEC.Layers[ii];
531 t_vTecLayer layer;
532 layer._height = ionoLayer.Height;
533 layer._C.ReSize(ionoLayer.Degree+1, ionoLayer.Order+1);
534 layer._S.ReSize(ionoLayer.Degree+1, ionoLayer.Order+1);
535 for (unsigned iDeg = 0; iDeg <= ionoLayer.Degree; iDeg++) {
536 for (unsigned iOrd = 0; iOrd <= ionoLayer.Order; iOrd++) {
537 layer._C[iDeg][iOrd] = ionoLayer.Cosinus[iDeg][iOrd];
538 layer._S[iDeg][iOrd] = ionoLayer.Sinus[iDeg][iOrd];
539 }
540 }
541 _vTecMap[_lastTime]._layers.push_back(layer);
542 }
543 }
544
545 // Dump all older epochs
546 // ---------------------
547 QMutableMapIterator<bncTime, QList<t_orbCorr> > itOrb(_orbCorrections);
548 while (itOrb.hasNext()) {
549 itOrb.next();
550 if (itOrb.key() < _lastTime) {
551 emit newOrbCorrections(itOrb.value());
552 t_orbCorr::writeEpoch(_out, itOrb.value());
553 itOrb.remove();
554 }
555 }
556 QMutableMapIterator<bncTime, QList<t_clkCorr> > itClk(_clkCorrections);
557 while (itClk.hasNext()) {
558 itClk.next();
559 if (itClk.key() < _lastTime) {
560 emit newClkCorrections(itClk.value());
561 t_clkCorr::writeEpoch(_out, itClk.value());
562 itClk.remove();
563 }
564 }
565 QMutableMapIterator<bncTime, QList<t_satCodeBias> > itCB(_codeBiases);
566 while (itCB.hasNext()) {
567 itCB.next();
568 if (itCB.key() < _lastTime) {
569 emit newCodeBiases(itCB.value());
570 t_satCodeBias::writeEpoch(_out, itCB.value());
571 itCB.remove();
572 }
573 }
574 QMutableMapIterator<bncTime, QList<t_satPhaseBias> > itPB(_phaseBiases);
575 while (itPB.hasNext()) {
576 itPB.next();
577 if (itPB.key() < _lastTime) {
578 emit newPhaseBiases(itPB.value());
579 t_satPhaseBias::writeEpoch(_out, itPB.value());
580 itPB.remove();
581 }
582 }
583 QMutableMapIterator<bncTime, t_vTec> itTec(_vTecMap);
584 while (itTec.hasNext()) {
585 itTec.next();
586 if (itTec.key() < _lastTime) {
587 emit newTec(itTec.value());
588 t_vTec::write(_out, itTec.value());
589 itTec.remove();
590 }
591 }
592}
593
594//
595////////////////////////////////////////////////////////////////////////////
596void RTCM3coDecoder::checkProviderID() {
597
598 if (_clkOrb.SSRProviderID == 0 && _clkOrb.SSRSolutionID == 0 && _clkOrb.SSRIOD == 0) {
599 return;
600 }
601
602 int newProviderID[3];
603 newProviderID[0] = _clkOrb.SSRProviderID;
604 newProviderID[1] = _clkOrb.SSRSolutionID;
605 newProviderID[2] = _clkOrb.SSRIOD;
606 QString newProviderIDStr = QString(" [SSR Provider ID: %1 SSR Solution ID: %2 SSR IOD: %3]: ")
607 .arg(newProviderID[0]).arg(newProviderID[1]).arg(newProviderID[2]);
608
609 bool alreadySet = false;
610 bool different = false;
611
612 for (unsigned ii = 0; ii < 3; ii++) {
613 if (_providerID[ii] != -1) {
614 alreadySet = true;
615 }
616 if (_providerID[ii] != newProviderID[ii]) {
617 different = true;
618 }
619 _providerID[ii] = newProviderID[ii];
620 }
621
622 if (alreadySet && different) {
623 emit newMessage("RTCM3coDecoder: Provider Changed " + newProviderIDStr.toLatin1() + _staID.toLatin1(), true);
624 emit providerIDChanged(_staID);
625 }
626}
627
628// Check corrections
629////////////////////////////////////////////////////////////////////////////
630bool RTCM3coDecoder::corrIsOutOfRange(const SsrCorr::ClockOrbit::SatData& coSat) {
631
632 if (fabs(coSat.Clock.DeltaA0) > 209.7151) {return true;}
633 if (fabs(coSat.Clock.DeltaA1) > 1.048575) {return true;}
634 if (fabs(coSat.Clock.DeltaA2) > 1.34217726) {return true;}
635
636 if (fabs(coSat.Orbit.DeltaRadial) > 209.7151) {return true;}
637 if (fabs(coSat.Orbit.DeltaAlongTrack) > 209.7148) {return true;}
638 if (fabs(coSat.Orbit.DeltaCrossTrack) > 209.7148) {return true;}
639
640 if (fabs(coSat.Orbit.DotDeltaRadial) > 1.048575) {return true;}
641 if (fabs(coSat.Orbit.DotDeltaAlongTrack) > 1.048572) {return true;}
642 if (fabs(coSat.Orbit.DotDeltaCrossTrack) > 1.048572) {return true;}
643 return false;
644}
645
646//
647////////////////////////////////////////////////////////////////////////////
648void RTCM3coDecoder::setEpochTime() {
649
650 _lastTime.reset();
651
652 double epoSecGPS = -1.0;
653 double epoSecGlo = -1.0;
654 double epoSecGal = -1.0;
655 double epoSecQzss = -1.0;
656 double epoSecSbas = -1.0;
657 double epoSecBds = -1.0;
658 if (_clkOrb.NumberOfSat[CLOCKORBIT_SATGPS] > 0) {
659 epoSecGPS = _clkOrb.EpochTime[CLOCKORBIT_SATGPS]; // 0 .. 604799 s
660 }
661 else if (_codeBias.NumberOfSat[CLOCKORBIT_SATGPS] > 0) {
662 epoSecGPS = _codeBias.EpochTime[CLOCKORBIT_SATGPS]; // 0 .. 604799 s
663 }
664 else if (_phaseBias.NumberOfSat[CLOCKORBIT_SATGPS] > 0) {
665 epoSecGPS = _phaseBias.EpochTime[CLOCKORBIT_SATGPS]; // 0 .. 604799 s
666 }
667 else if (_vTEC.NumLayers > 0) {
668 epoSecGPS = _vTEC.EpochTime; // 0 .. 604799 s
669 }
670 else if (_clkOrb.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) {
671 epoSecGlo = _clkOrb.EpochTime[CLOCKORBIT_SATGLONASS]; // 0 .. 86399 s
672 }
673 else if (_codeBias.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) {
674 epoSecGlo = _codeBias.EpochTime[CLOCKORBIT_SATGLONASS]; // 0 .. 86399 s
675 }
676 else if (_phaseBias.NumberOfSat[CLOCKORBIT_SATGLONASS] > 0) {
677 epoSecGlo = _phaseBias.EpochTime[CLOCKORBIT_SATGLONASS]; // 0 .. 86399 s
678 }
679 else if (_clkOrb.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0) {
680 epoSecGal = _clkOrb.EpochTime[CLOCKORBIT_SATGALILEO];
681 }
682 else if (_codeBias.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0) {
683 epoSecGal = _codeBias.EpochTime[CLOCKORBIT_SATGALILEO];
684 }
685 else if (_phaseBias.NumberOfSat[CLOCKORBIT_SATGALILEO] > 0) {
686 epoSecGal = _phaseBias.EpochTime[CLOCKORBIT_SATGALILEO];
687 }
688 else if (_clkOrb.NumberOfSat[CLOCKORBIT_SATQZSS] > 0) {
689 epoSecQzss = _clkOrb.EpochTime[CLOCKORBIT_SATQZSS];
690 }
691 else if (_codeBias.NumberOfSat[CLOCKORBIT_SATQZSS] > 0) {
692 epoSecQzss = _codeBias.EpochTime[CLOCKORBIT_SATQZSS];
693 }
694 else if (_phaseBias.NumberOfSat[CLOCKORBIT_SATQZSS] > 0) {
695 epoSecQzss = _phaseBias.EpochTime[CLOCKORBIT_SATQZSS];
696 }
697 else if (_clkOrb.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) {
698 epoSecSbas = _clkOrb.EpochTime[CLOCKORBIT_SATSBAS];
699 }
700 else if (_codeBias.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) {
701 epoSecSbas = _codeBias.EpochTime[CLOCKORBIT_SATSBAS];
702 }
703 else if (_phaseBias.NumberOfSat[CLOCKORBIT_SATSBAS] > 0) {
704 epoSecSbas = _phaseBias.EpochTime[CLOCKORBIT_SATSBAS];
705 }
706 else if (_clkOrb.NumberOfSat[CLOCKORBIT_SATBDS] > 0) {
707 epoSecBds = _clkOrb.EpochTime[CLOCKORBIT_SATBDS];
708 }
709 else if (_codeBias.NumberOfSat[CLOCKORBIT_SATBDS] > 0) {
710 epoSecBds = _codeBias.EpochTime[CLOCKORBIT_SATBDS];
711 }
712 else if (_phaseBias.NumberOfSat[CLOCKORBIT_SATBDS] > 0) {
713 epoSecBds = _phaseBias.EpochTime[CLOCKORBIT_SATBDS];
714 }
715
716 // Retrieve current time
717 // ---------------------
718 int currentWeek = 0;
719 double currentSec = 0.0;
720 currentGPSWeeks(currentWeek, currentSec);
721 bncTime currentTime(currentWeek, currentSec);
722
723 // Set _lastTime close to currentTime
724 // ----------------------------------
725 if (epoSecGPS != -1) {
726 _lastTime.set(currentWeek, epoSecGPS);
727 }
728 else if (epoSecGlo != -1) {
729 QDate date = dateAndTimeFromGPSweek(currentTime.gpsw(), currentTime.gpssec()).date();
730 if (_type == IGSssr) {
731 if (epoSecGPS != epoSecGlo) {// should be not done in case of an IGS-SSR encoding error => line has to be deleted
732 epoSecGlo = epoSecGlo + gnumleap(date.year(), date.month(), date.day());
733 }
734 }
735 if (_type == RTCMssr) {
736 epoSecGlo = epoSecGlo - 3 * 3600 + gnumleap(date.year(), date.month(), date.day());
737 }
738 _lastTime.set(currentWeek, epoSecGlo);
739 }
740 else if (epoSecGal != -1) {
741 _lastTime.set(currentWeek, epoSecGal);
742 }
743 else if (epoSecQzss != -1) {
744 _lastTime.set(currentWeek, epoSecQzss);
745 }
746 else if (epoSecSbas != -1) {
747 _lastTime.set(currentWeek, epoSecSbas);
748 }
749 else if (epoSecBds != -1) {
750 if (_type == IGSssr) {
751 if (epoSecGPS != -1 && epoSecGPS != epoSecBds) {// should be not done in case of an IGS-SSR encoding error => line has to be deleted
752 epoSecBds += 14.0;
753 if (epoSecBds > 604800.0) {
754 epoSecBds -= 7.0*24.0*60.0*60.0;
755 }
756 }
757 }// line has to be deleted
758 if (_type == RTCMssr) {
759 epoSecBds += 14.0;
760 if (epoSecBds > 604800.0) {
761 epoSecBds -= 7.0*24.0*60.0*60.0;
762 }
763 }
764 _lastTime.set(currentWeek, epoSecBds);
765 }
766
767 if (_lastTime.valid()) {
768 double maxDiff = 12 * 3600.0;
769 while (_lastTime < currentTime - maxDiff) {
770 _lastTime = _lastTime + maxDiff;
771 }
772 while (_lastTime > currentTime + maxDiff) {
773 _lastTime = _lastTime - maxDiff;
774 }
775 }
776}
Note: See TracBrowser for help on using the repository browser.