[297] | 1 | // Part of BNC, a utility for retrieving decoding and
|
---|
[464] | 2 | // converting GNSS data streams from NTRIP broadcasters.
|
---|
[297] | 3 | //
|
---|
[464] | 4 | // Copyright (C) 2007
|
---|
[297] | 5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
---|
| 6 | // http://www.bkg.bund.de
|
---|
[464] | 7 | // Czech Technical University Prague, Department of Geodesy
|
---|
[297] | 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.
|
---|
[296] | 24 |
|
---|
| 25 | /* -------------------------------------------------------------------------
|
---|
| 26 | * BKG NTRIP Client
|
---|
| 27 | * -------------------------------------------------------------------------
|
---|
| 28 | *
|
---|
| 29 | * Class: RTCM3Decoder
|
---|
| 30 | *
|
---|
| 31 | * Purpose: RTCM3 Decoder
|
---|
| 32 | *
|
---|
| 33 | * Author: L. Mervart
|
---|
| 34 | *
|
---|
| 35 | * Created: 24-Aug-2006
|
---|
| 36 | *
|
---|
| 37 | * Changes:
|
---|
| 38 | *
|
---|
| 39 | * -----------------------------------------------------------------------*/
|
---|
| 40 |
|
---|
| 41 | #include <iostream>
|
---|
[1807] | 42 | #include <iomanip>
|
---|
| 43 | #include <sstream>
|
---|
[296] | 44 | #include <math.h>
|
---|
[585] | 45 | #include <string.h>
|
---|
[296] | 46 |
|
---|
| 47 | #include "RTCM3Decoder.h"
|
---|
[1807] | 48 | #include "../RTCM/rtcm_utils.h"
|
---|
[296] | 49 | #include "bncconst.h"
|
---|
[5070] | 50 | #include "bnccore.h"
|
---|
[1535] | 51 | #include "bncutils.h"
|
---|
| 52 | #include "bncsettings.h"
|
---|
[296] | 53 |
|
---|
| 54 | using namespace std;
|
---|
| 55 |
|
---|
| 56 | #ifndef isinf
|
---|
| 57 | # define isinf(x) 0
|
---|
| 58 | #endif
|
---|
| 59 |
|
---|
[320] | 60 | // Error Handling
|
---|
| 61 | ////////////////////////////////////////////////////////////////////////////
|
---|
[504] | 62 | void RTCM3Error(const char*, ...) {
|
---|
[505] | 63 | }
|
---|
[320] | 64 |
|
---|
[296] | 65 | // Constructor
|
---|
| 66 | ////////////////////////////////////////////////////////////////////////////
|
---|
[2527] | 67 | RTCM3Decoder::RTCM3Decoder(const QString& staID, bncRawFile* rawFile) :
|
---|
[2387] | 68 | GPSDecoder() {
|
---|
[505] | 69 |
|
---|
[2527] | 70 | _staID = staID;
|
---|
| 71 | _rawFile = rawFile;
|
---|
[2387] | 72 |
|
---|
[1535] | 73 | bncSettings settings;
|
---|
[1580] | 74 | _checkMountPoint = settings.value("miscMount").toString();
|
---|
[1022] | 75 |
|
---|
[939] | 76 | connect(this, SIGNAL(newGPSEph(gpsephemeris*)),
|
---|
[5068] | 77 | BNC_CORE, SLOT(slotNewGPSEph(gpsephemeris*)));
|
---|
[5206] | 78 | connect(this, SIGNAL(newGlonassEph(glonassephemeris*, const QString&)),
|
---|
| 79 | BNC_CORE, SLOT(slotNewGlonassEph(glonassephemeris*, const QString&)));
|
---|
[2770] | 80 | connect(this, SIGNAL(newGalileoEph(galileoephemeris*)),
|
---|
[5068] | 81 | BNC_CORE, SLOT(slotNewGalileoEph(galileoephemeris*)));
|
---|
[939] | 82 |
|
---|
[1021] | 83 | // Mode can be either observations or corrections
|
---|
| 84 | // ----------------------------------------------
|
---|
| 85 | _mode = unknown;
|
---|
[1807] | 86 |
|
---|
| 87 | // Antenna position (used for decoding of message 1003)
|
---|
| 88 | // ----------------------------------------------------
|
---|
| 89 | _antXYZ[0] = _antXYZ[1] = _antXYZ[2] = 0;
|
---|
| 90 |
|
---|
[296] | 91 | }
|
---|
| 92 |
|
---|
| 93 | // Destructor
|
---|
| 94 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 95 | RTCM3Decoder::~RTCM3Decoder() {
|
---|
[3001] | 96 | QMapIterator<QByteArray, RTCM3coDecoder*> it(_coDecoders);
|
---|
| 97 | while (it.hasNext()) {
|
---|
[3008] | 98 | it.next();
|
---|
| 99 | delete it.value();
|
---|
[3001] | 100 | }
|
---|
[296] | 101 | }
|
---|
| 102 |
|
---|
| 103 | //
|
---|
| 104 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1218] | 105 | t_irc RTCM3Decoder::Decode(char* buffer, int bufLen, vector<string>& errmsg) {
|
---|
[508] | 106 |
|
---|
[1218] | 107 | errmsg.clear();
|
---|
| 108 |
|
---|
[913] | 109 | bool decoded = false;
|
---|
| 110 |
|
---|
[3001] | 111 | // If read from file, mode is always uknown
|
---|
| 112 | // ----------------------------------------
|
---|
| 113 | if (_rawFile) {
|
---|
| 114 | _mode = unknown;
|
---|
| 115 | _staID = _rawFile->staID();
|
---|
[2551] | 116 | }
|
---|
| 117 |
|
---|
[880] | 118 | // Try to decode Clock and Orbit Corrections
|
---|
| 119 | // -----------------------------------------
|
---|
[1021] | 120 | if (_mode == unknown || _mode == corrections) {
|
---|
[3002] | 121 |
|
---|
| 122 | // Find the corresponding coDecoder
|
---|
| 123 | // --------------------------------
|
---|
| 124 | if (!_coDecoders.contains(_staID.toAscii())) {
|
---|
| 125 | _coDecoders[_staID.toAscii()] = new RTCM3coDecoder(_staID);
|
---|
| 126 | }
|
---|
| 127 | RTCM3coDecoder* coDecoder = _coDecoders[_staID.toAscii()];
|
---|
| 128 |
|
---|
[3001] | 129 | if ( coDecoder->Decode(buffer, bufLen, errmsg) == success ) {
|
---|
[1021] | 130 | decoded = true;
|
---|
[3001] | 131 | if (!_rawFile && _mode == unknown) {
|
---|
| 132 | _mode = corrections;
|
---|
[1021] | 133 | }
|
---|
| 134 | }
|
---|
[913] | 135 | }
|
---|
[880] | 136 |
|
---|
[3001] | 137 | // Find the corresponding parser, initialize a new parser if necessary
|
---|
| 138 | // -------------------------------------------------------------------
|
---|
| 139 | bool newParser = !_parsers.contains(_staID.toAscii());
|
---|
| 140 | RTCM3ParserData& parser = _parsers[_staID.toAscii()];
|
---|
| 141 | if (newParser) {
|
---|
| 142 | memset(&parser, 0, sizeof(parser));
|
---|
| 143 | parser.rinex3 = 0;
|
---|
| 144 | double secGPS;
|
---|
| 145 | currentGPSWeeks(parser.GPSWeek, secGPS);
|
---|
| 146 | parser.GPSTOW = int(secGPS);
|
---|
[2527] | 147 | }
|
---|
| 148 |
|
---|
[880] | 149 | // Remaining part decodes the Observations
|
---|
| 150 | // ---------------------------------------
|
---|
[2676] | 151 | if (_mode == unknown || _mode == observations ||
|
---|
| 152 | _checkMountPoint == _staID || _checkMountPoint == "ALL") {
|
---|
[1127] | 153 |
|
---|
[2677] | 154 | for (int iByte = 0; iByte < bufLen; iByte++) {
|
---|
[1127] | 155 |
|
---|
[2677] | 156 | parser.Message[parser.MessageSize++] = buffer[iByte];
|
---|
| 157 |
|
---|
[2527] | 158 | if (parser.MessageSize >= parser.NeedBytes) {
|
---|
[1185] | 159 |
|
---|
[2676] | 160 | while (int rr = RTCM3Parser(&parser)) {
|
---|
[1130] | 161 |
|
---|
[1239] | 162 | // RTCMv3 message types
|
---|
| 163 | // --------------------
|
---|
[2527] | 164 | _typeList.push_back(parser.blocktype);
|
---|
[1185] | 165 |
|
---|
[1239] | 166 | // RTCMv3 antenna descriptor
|
---|
| 167 | // -------------------------
|
---|
[2676] | 168 | if (rr == 1007 || rr == 1008 || rr == 1033) {
|
---|
| 169 | _antType.push_back(parser.antenna);
|
---|
[1239] | 170 | }
|
---|
[1185] | 171 |
|
---|
[1239] | 172 | // RTCMv3 antenna XYZ
|
---|
| 173 | // ------------------
|
---|
[2676] | 174 | else if (rr == 1005) {
|
---|
| 175 | _antList.push_back(t_antInfo());
|
---|
| 176 | _antList.back().type = t_antInfo::ARP;
|
---|
| 177 | _antList.back().xx = parser.antX * 1e-4;
|
---|
| 178 | _antList.back().yy = parser.antY * 1e-4;
|
---|
| 179 | _antList.back().zz = parser.antZ * 1e-4;
|
---|
| 180 | _antList.back().message = rr;
|
---|
[1807] | 181 |
|
---|
[2676] | 182 | // Remember station position for 1003 message decoding
|
---|
| 183 | _antXYZ[0] = parser.antX * 1e-4;
|
---|
| 184 | _antXYZ[1] = parser.antY * 1e-4;
|
---|
| 185 | _antXYZ[2] = parser.antZ * 1e-4;
|
---|
[1239] | 186 | }
|
---|
[1033] | 187 |
|
---|
[1239] | 188 | // RTCMv3 antenna XYZ-H
|
---|
| 189 | // --------------------
|
---|
[2676] | 190 | else if(rr == 1006) {
|
---|
| 191 | _antList.push_back(t_antInfo());
|
---|
| 192 | _antList.back().type = t_antInfo::ARP;
|
---|
| 193 | _antList.back().xx = parser.antX * 1e-4;
|
---|
| 194 | _antList.back().yy = parser.antY * 1e-4;
|
---|
| 195 | _antList.back().zz = parser.antZ * 1e-4;
|
---|
| 196 | _antList.back().height = parser.antH * 1e-4;
|
---|
| 197 | _antList.back().height_f = true;
|
---|
| 198 | _antList.back().message = rr;
|
---|
[1807] | 199 |
|
---|
[2676] | 200 | // Remember station position for 1003 message decoding
|
---|
| 201 | _antXYZ[0] = parser.antX * 1e-4;
|
---|
| 202 | _antXYZ[1] = parser.antY * 1e-4;
|
---|
| 203 | _antXYZ[2] = parser.antZ * 1e-4;
|
---|
[1239] | 204 | }
|
---|
| 205 |
|
---|
[1021] | 206 | // GNSS Observations
|
---|
| 207 | // -----------------
|
---|
[1239] | 208 | else if (rr == 1 || rr == 2) {
|
---|
[1127] | 209 | decoded = true;
|
---|
[1021] | 210 |
|
---|
[2527] | 211 | if (!parser.init) {
|
---|
| 212 | HandleHeader(&parser);
|
---|
| 213 | parser.init = 1;
|
---|
[1021] | 214 | }
|
---|
| 215 |
|
---|
| 216 | if (rr == 2) {
|
---|
[2676] | 217 | emit(newMessage( (_staID +
|
---|
| 218 | ": No valid RINEX! All values are modulo 299792.458!").toAscii(),
|
---|
| 219 | true));
|
---|
[1021] | 220 | }
|
---|
[2683] | 221 |
|
---|
| 222 | gnssdata& gnssData = parser.Data;
|
---|
[1021] | 223 |
|
---|
[2683] | 224 | for (int iSat = 0; iSat < gnssData.numsats; iSat++) {
|
---|
[2677] | 225 |
|
---|
[6137] | 226 | t_satObs obs;
|
---|
[2711] | 227 | int satID = gnssData.satellites[iSat];
|
---|
[2674] | 228 |
|
---|
| 229 | // GPS
|
---|
| 230 | // ---
|
---|
| 231 | if (satID >= PRN_GPS_START && satID <= PRN_GPS_END) {
|
---|
[6137] | 232 | obs._prn.set('G', satID);
|
---|
[366] | 233 | }
|
---|
[2674] | 234 |
|
---|
| 235 | // Glonass
|
---|
| 236 | // -------
|
---|
| 237 | else if (satID >= PRN_GLONASS_START && satID <= PRN_GLONASS_END) {
|
---|
[6137] | 238 | obs._prn.set('R', satID - PRN_GLONASS_START + 1);
|
---|
[1021] | 239 | }
|
---|
[2674] | 240 |
|
---|
| 241 | // Galileo
|
---|
| 242 | // -------
|
---|
| 243 | else if (satID >= PRN_GALILEO_START && satID <= PRN_GALILEO_END) {
|
---|
[6137] | 244 | obs._prn.set('E', satID - PRN_GALILEO_START + 1);
|
---|
[2676] | 245 | }
|
---|
[2674] | 246 |
|
---|
[4368] | 247 | // SBAS
|
---|
[2674] | 248 | // ----
|
---|
[4368] | 249 | else if (satID >= PRN_SBAS_START && satID <= PRN_SBAS_END) {
|
---|
[6137] | 250 | obs._prn.set('S', satID - PRN_SBAS_START + 20);
|
---|
[1021] | 251 | }
|
---|
[2669] | 252 |
|
---|
[2674] | 253 | // Giove A and B
|
---|
| 254 | // -------------
|
---|
| 255 | else if (satID >= PRN_GIOVE_START && satID <= PRN_GIOVE_END) {
|
---|
[6137] | 256 | obs._prn.set('E', satID - PRN_GIOVE_START + PRN_GIOVE_OFFSET);
|
---|
[2676] | 257 | }
|
---|
[2674] | 258 |
|
---|
[4368] | 259 | // QZSS
|
---|
| 260 | // -------------
|
---|
| 261 | else if (satID >= PRN_QZSS_START && satID <= PRN_QZSS_END) {
|
---|
[6137] | 262 | obs._prn.set('J', satID - PRN_QZSS_START + 1);
|
---|
[4368] | 263 | }
|
---|
| 264 |
|
---|
| 265 | // COMPASS
|
---|
| 266 | // -------------
|
---|
| 267 | else if (satID >= PRN_COMPASS_START && satID <= PRN_COMPASS_END) {
|
---|
[6137] | 268 | obs._prn.set('C', satID - PRN_COMPASS_START + 1);
|
---|
[4368] | 269 | }
|
---|
| 270 |
|
---|
[2674] | 271 | // Unknown System
|
---|
| 272 | // --------------
|
---|
| 273 | else {
|
---|
[2669] | 274 | continue;
|
---|
| 275 | }
|
---|
| 276 |
|
---|
[6137] | 277 | obs._time.set(gnssData.week, gnssData.timeofweek / 1000.0);
|
---|
[1807] | 278 |
|
---|
[6137] | 279 | QString prn(obs._prn.toString().c_str());
|
---|
[2687] | 280 |
|
---|
[6137] | 281 | int obs_slip_cnt_L1 = 0;
|
---|
| 282 | int obs_slip_cnt_L2 = 0;
|
---|
| 283 | int obs_slip_cnt_L5 = 0;
|
---|
| 284 |
|
---|
[2687] | 285 | // Handle loss-of-lock flags
|
---|
| 286 | // -------------------------
|
---|
| 287 | const int maxSlipCnt = 100;
|
---|
| 288 | if (!_slip_cnt_L1.contains(prn)) {
|
---|
| 289 | _slip_cnt_L1[prn] = 0;
|
---|
| 290 | _slip_cnt_L2[prn] = 0;
|
---|
| 291 | _slip_cnt_L5[prn] = 0;
|
---|
| 292 | }
|
---|
| 293 | if (GNSSDF2_LOCKLOSSL1 & gnssData.dataflags2[iSat]) {
|
---|
| 294 | if (_slip_cnt_L1[prn] < maxSlipCnt) {
|
---|
| 295 | ++_slip_cnt_L1[prn];
|
---|
| 296 | }
|
---|
| 297 | else {
|
---|
| 298 | _slip_cnt_L1[prn] = 1;
|
---|
| 299 | }
|
---|
[6137] | 300 | obs_slip_cnt_L1 = _slip_cnt_L1[prn];
|
---|
[2687] | 301 | }
|
---|
| 302 | if (GNSSDF2_LOCKLOSSL2 & gnssData.dataflags2[iSat]) {
|
---|
| 303 | if (_slip_cnt_L2[prn] < maxSlipCnt) {
|
---|
| 304 | ++_slip_cnt_L2[prn];
|
---|
| 305 | }
|
---|
| 306 | else {
|
---|
| 307 | _slip_cnt_L2[prn] = 1;
|
---|
| 308 | }
|
---|
[6137] | 309 | obs_slip_cnt_L2 = _slip_cnt_L2[prn];
|
---|
[2687] | 310 | }
|
---|
| 311 | if (GNSSDF2_LOCKLOSSL5 & gnssData.dataflags2[iSat]) {
|
---|
| 312 | if (_slip_cnt_L5[prn] < maxSlipCnt) {
|
---|
| 313 | ++_slip_cnt_L5[prn];
|
---|
| 314 | }
|
---|
| 315 | else {
|
---|
| 316 | _slip_cnt_L5[prn] = 1;
|
---|
| 317 | }
|
---|
[6137] | 318 | obs_slip_cnt_L5 = _slip_cnt_L5[prn];
|
---|
[2687] | 319 | }
|
---|
| 320 |
|
---|
[2676] | 321 | // Loop over all data types
|
---|
| 322 | // ------------------------
|
---|
[2684] | 323 | for (int iEntry = 0; iEntry < GNSSENTRY_NUMBER; ++iEntry) {
|
---|
[6137] | 324 | if (gnssData.codetype[iSat][iEntry] == 0) {
|
---|
| 325 | continue;
|
---|
| 326 | }
|
---|
| 327 | string rnxType(gnssData.codetype[iSat][iEntry]);
|
---|
| 328 |
|
---|
| 329 | t_frqObs* frqObs = 0;
|
---|
| 330 | for (unsigned iFrq = 0; iFrq < obs._obs.size(); iFrq++) {
|
---|
| 331 | if (obs._obs[iFrq]->_rnxType2ch == rnxType) {
|
---|
| 332 | frqObs = obs._obs[iFrq];
|
---|
| 333 | break;
|
---|
| 334 | }
|
---|
| 335 | }
|
---|
| 336 | if (frqObs == 0) {
|
---|
| 337 | frqObs = new t_frqObs;
|
---|
| 338 | frqObs->_rnxType2ch = rnxType;
|
---|
| 339 | obs._obs.push_back(frqObs);
|
---|
| 340 | }
|
---|
| 341 |
|
---|
| 342 | switch(iEntry & 3) {
|
---|
| 343 | case GNSSENTRY_CODE:
|
---|
| 344 | frqObs->_codeValid = true;
|
---|
| 345 | frqObs->_code = gnssData.measdata[iSat][iEntry];
|
---|
| 346 | break;
|
---|
| 347 | case GNSSENTRY_PHASE:
|
---|
| 348 | frqObs->_phaseValid = true;
|
---|
| 349 | frqObs->_phase = gnssData.measdata[iSat][iEntry];
|
---|
| 350 | if (rnxType[0] == '1') {
|
---|
| 351 | frqObs->_slipCounter = obs_slip_cnt_L1;
|
---|
| 352 | }
|
---|
| 353 | else if (rnxType[0] == '2') {
|
---|
| 354 | frqObs->_slipCounter = obs_slip_cnt_L2;
|
---|
| 355 | }
|
---|
| 356 | else if (rnxType[0] == '5') {
|
---|
| 357 | frqObs->_slipCounter = obs_slip_cnt_L5;
|
---|
| 358 | }
|
---|
| 359 | break;
|
---|
| 360 | case GNSSENTRY_DOPPLER:
|
---|
| 361 | frqObs->_dopplerValid = true;
|
---|
| 362 | frqObs->_doppler = gnssData.measdata[iSat][iEntry];
|
---|
| 363 | break;
|
---|
| 364 | case GNSSENTRY_SNR:
|
---|
| 365 | frqObs->_snrValid = true;
|
---|
| 366 | frqObs->_snr = gnssData.measdata[iSat][iEntry];
|
---|
| 367 | break;
|
---|
| 368 | }
|
---|
[511] | 369 | }
|
---|
[2711] | 370 | _obsList.push_back(obs);
|
---|
[366] | 371 | }
|
---|
[296] | 372 | }
|
---|
[1021] | 373 |
|
---|
| 374 | // GPS Ephemeris
|
---|
| 375 | // -------------
|
---|
| 376 | else if (rr == 1019) {
|
---|
| 377 | decoded = true;
|
---|
[2676] | 378 | emit newGPSEph(new gpsephemeris(parser.ephemerisGPS));
|
---|
[1021] | 379 | }
|
---|
| 380 |
|
---|
| 381 | // GLONASS Ephemeris
|
---|
| 382 | // -----------------
|
---|
[5260] | 383 | else if (rr == 1020 && parser.ephemerisGLONASS.almanac_number >= 1
|
---|
| 384 | && parser.ephemerisGLONASS.almanac_number <= PRN_GLONASS_NUM) {
|
---|
[1021] | 385 | decoded = true;
|
---|
[5206] | 386 | emit newGlonassEph(new glonassephemeris(parser.ephemerisGLONASS), _staID);
|
---|
[1021] | 387 | }
|
---|
[2770] | 388 |
|
---|
| 389 | // Galileo Ephemeris
|
---|
| 390 | // -----------------
|
---|
[5545] | 391 | else if (rr == 1045 || rr == 1046) {
|
---|
[2770] | 392 | decoded = true;
|
---|
| 393 | emit newGalileoEph(new galileoephemeris(parser.ephemerisGALILEO));
|
---|
| 394 | }
|
---|
[296] | 395 | }
|
---|
| 396 | }
|
---|
| 397 | }
|
---|
[2527] | 398 | if (!_rawFile && _mode == unknown && decoded) {
|
---|
[2387] | 399 | _mode = observations;
|
---|
[1021] | 400 | }
|
---|
[296] | 401 | }
|
---|
[1021] | 402 |
|
---|
| 403 | if (decoded) {
|
---|
| 404 | return success;
|
---|
[658] | 405 | }
|
---|
| 406 | else {
|
---|
[1021] | 407 | return failure;
|
---|
[658] | 408 | }
|
---|
[296] | 409 | }
|
---|
[1807] | 410 |
|
---|
[3001] | 411 | // Time of Corrections
|
---|
| 412 | //////////////////////////////////////////////////////////////////////////////
|
---|
| 413 | int RTCM3Decoder::corrGPSEpochTime() const {
|
---|
| 414 | if (_mode == corrections && _coDecoders.size() > 0) {
|
---|
| 415 | return _coDecoders.begin().value()->corrGPSEpochTime();
|
---|
| 416 | }
|
---|
| 417 | else {
|
---|
| 418 | return -1;
|
---|
| 419 | }
|
---|
| 420 | }
|
---|