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