[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>
|
---|
| 42 | #include <math.h>
|
---|
[585] | 43 | #include <string.h>
|
---|
[296] | 44 |
|
---|
| 45 | #include "RTCM3Decoder.h"
|
---|
[880] | 46 | #include "RTCM3coDecoder.h"
|
---|
[296] | 47 | #include "bncconst.h"
|
---|
[511] | 48 | #include "bncapp.h"
|
---|
[1035] | 49 | #include "bncutils.h" /* Weber, for latencies */
|
---|
[296] | 50 |
|
---|
| 51 | using namespace std;
|
---|
| 52 |
|
---|
| 53 | #ifndef isinf
|
---|
| 54 | # define isinf(x) 0
|
---|
| 55 | #endif
|
---|
| 56 |
|
---|
[320] | 57 | // Error Handling
|
---|
| 58 | ////////////////////////////////////////////////////////////////////////////
|
---|
[504] | 59 | void RTCM3Error(const char*, ...) {
|
---|
[505] | 60 | }
|
---|
[320] | 61 |
|
---|
[296] | 62 | // Constructor
|
---|
| 63 | ////////////////////////////////////////////////////////////////////////////
|
---|
[970] | 64 | RTCM3Decoder::RTCM3Decoder(const QString& staID) : GPSDecoder() {
|
---|
[505] | 65 |
|
---|
[1033] | 66 | QSettings settings;
|
---|
| 67 | _checkMountPoint = settings.value("messTypes").toString();
|
---|
[1022] | 68 | _staID = staID;
|
---|
| 69 |
|
---|
[1095] | 70 | // Latency
|
---|
| 71 | _numLat = 0;
|
---|
| 72 | _minLat = 1000.;
|
---|
| 73 | _maxLat = -1000.;
|
---|
| 74 | _sumLat = 0.;
|
---|
| 75 | _sumLatQ = 0.;
|
---|
| 76 | _followSec = false;
|
---|
| 77 | _meanDiff = 0.;
|
---|
| 78 | _diffSecGPS= 0.;
|
---|
| 79 | _numGaps = 0;
|
---|
| 80 | _oldSecGPS = 0.;
|
---|
| 81 | _newSecGPS = 0.;
|
---|
| 82 | _curLat = 0.;
|
---|
| 83 | _perfIntr = 86400;
|
---|
| 84 | if ( settings.value("perfIntr").toString().isEmpty() ) { _perfIntr = 0; }
|
---|
| 85 | if ( settings.value("perfIntr").toString().indexOf("1 min") != -1 ) { _perfIntr = 60; }
|
---|
| 86 | if ( settings.value("perfIntr").toString().indexOf("5 min") != -1 ) { _perfIntr = 300; }
|
---|
| 87 | if ( settings.value("perfIntr").toString().indexOf("15 min") != -1 ) { _perfIntr = 900; }
|
---|
| 88 | if ( settings.value("perfIntr").toString().indexOf("1 hour") != -1 ) { _perfIntr = 3600; }
|
---|
| 89 | if ( settings.value("perfIntr").toString().indexOf("6 hours") != -1 ) { _perfIntr = 21600; }
|
---|
| 90 | if ( settings.value("perfIntr").toString().indexOf("1 day") != -1 ) { _perfIntr = 86400; }
|
---|
| 91 |
|
---|
[1022] | 92 | // Ensure, that the Decoder uses the "old" convention for the data structure for Rinex2. Perlt
|
---|
[689] | 93 | _Parser.rinex3 = 0;
|
---|
| 94 |
|
---|
[505] | 95 | memset(&_Parser, 0, sizeof(_Parser));
|
---|
[880] | 96 |
|
---|
[1153] | 97 | double secGPS;
|
---|
| 98 | currentGPSWeeks(_Parser.GPSWeek, secGPS);
|
---|
| 99 | _Parser.GPSTOW = int(secGPS);
|
---|
| 100 |
|
---|
[939] | 101 | connect(this, SIGNAL(newGPSEph(gpsephemeris*)),
|
---|
| 102 | (bncApp*) qApp, SLOT(slotNewGPSEph(gpsephemeris*)));
|
---|
| 103 | connect(this, SIGNAL(newGlonassEph(glonassephemeris*)),
|
---|
| 104 | (bncApp*) qApp, SLOT(slotNewGlonassEph(glonassephemeris*)));
|
---|
| 105 |
|
---|
[880] | 106 | // Sub-Decoder for Clock and Orbit Corrections
|
---|
| 107 | // -------------------------------------------
|
---|
[970] | 108 | _coDecoder = new RTCM3coDecoder(staID);
|
---|
[1021] | 109 |
|
---|
| 110 | // Mode can be either observations or corrections
|
---|
| 111 | // ----------------------------------------------
|
---|
| 112 | _mode = unknown;
|
---|
[296] | 113 | }
|
---|
| 114 |
|
---|
| 115 | // Destructor
|
---|
| 116 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 117 | RTCM3Decoder::~RTCM3Decoder() {
|
---|
[880] | 118 | delete _coDecoder;
|
---|
[296] | 119 | }
|
---|
| 120 |
|
---|
| 121 | //
|
---|
| 122 | ////////////////////////////////////////////////////////////////////////////
|
---|
[649] | 123 | t_irc RTCM3Decoder::Decode(char* buffer, int bufLen) {
|
---|
[508] | 124 |
|
---|
[913] | 125 | bool decoded = false;
|
---|
| 126 |
|
---|
[880] | 127 | // Try to decode Clock and Orbit Corrections
|
---|
| 128 | // -----------------------------------------
|
---|
[1021] | 129 | if (_mode == unknown || _mode == corrections) {
|
---|
| 130 | if ( _coDecoder->Decode(buffer, bufLen) == success ) {
|
---|
| 131 | decoded = true;
|
---|
[1035] | 132 |
|
---|
[1095] | 133 | // Latency
|
---|
[1035] | 134 | // -------
|
---|
[1095] | 135 | if (_perfIntr>0) {
|
---|
[1035] | 136 | if (0<_coDecoder->_epochList.size()) {
|
---|
| 137 | for (int ii=0;ii<_coDecoder->_epochList.size();ii++) {
|
---|
| 138 | int week;
|
---|
| 139 | double sec;
|
---|
[1095] | 140 | _newSecGPS = _coDecoder->_epochList[ii];
|
---|
[1153] | 141 | currentGPSWeeks(week, sec);
|
---|
[1095] | 142 | double dt = fabs(sec - _newSecGPS);
|
---|
[1035] | 143 | const double secPerWeek = 7.0 * 24.0 * 3600.0;
|
---|
| 144 | if (dt > 0.5 * secPerWeek) {
|
---|
[1095] | 145 | if (sec > _newSecGPS) {
|
---|
[1035] | 146 | sec -= secPerWeek;
|
---|
| 147 | } else {
|
---|
| 148 | sec += secPerWeek;
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
[1095] | 151 | if (_newSecGPS != _oldSecGPS) {
|
---|
| 152 | if (int(_newSecGPS) % _perfIntr < int(_oldSecGPS) % _perfIntr) {
|
---|
| 153 | if (_numLat>0) {
|
---|
| 154 | QString late;
|
---|
| 155 | if (_meanDiff>0.) {
|
---|
| 156 | late = QString(": Mean latency %1 sec, min %2, max %3, rms %4, %5 epochs, %6 gaps")
|
---|
| 157 | .arg(int(_sumLat/_numLat*100)/100.)
|
---|
| 158 | .arg(int(_minLat*100)/100.)
|
---|
| 159 | .arg(int(_maxLat*100)/100.)
|
---|
| 160 | .arg(int((sqrt((_sumLatQ - _sumLat * _sumLat / _numLat)/_numLat))*100)/100.)
|
---|
| 161 | .arg(_numLat)
|
---|
| 162 | .arg(_numGaps);
|
---|
| 163 | emit(newMessage(QString(_staID + late ).toAscii() ) );
|
---|
| 164 | } else {
|
---|
| 165 | late = QString(": Mean latency %1 sec, min %2, max %3, rms %4, %5 epochs")
|
---|
| 166 | .arg(int(_sumLat/_numLat*100)/100.)
|
---|
| 167 | .arg(int(_minLat*100)/100.)
|
---|
| 168 | .arg(int(_maxLat*100)/100.)
|
---|
| 169 | .arg(int((sqrt((_sumLatQ - _sumLat * _sumLat / _numLat)/_numLat))*100)/100.)
|
---|
| 170 | .arg(_numLat);
|
---|
| 171 | emit(newMessage(QString(_staID + late ).toAscii() ) );
|
---|
| 172 | }
|
---|
| 173 | }
|
---|
| 174 | _meanDiff = int(_diffSecGPS)/_numLat;
|
---|
| 175 | _diffSecGPS = 0.;
|
---|
| 176 | _numGaps = 0;
|
---|
| 177 | _sumLat = 0.;
|
---|
| 178 | _sumLatQ = 0.;
|
---|
| 179 | _numLat = 0;
|
---|
| 180 | _minLat = 1000.;
|
---|
| 181 | _maxLat = -1000.;
|
---|
| 182 | }
|
---|
| 183 | if (_followSec) {
|
---|
| 184 | _diffSecGPS += _newSecGPS - _oldSecGPS;
|
---|
| 185 | if (_meanDiff>0.) {
|
---|
| 186 | if (_newSecGPS - _oldSecGPS > 1.5 * _meanDiff) {
|
---|
| 187 | _numGaps += 1;
|
---|
| 188 | }
|
---|
| 189 | }
|
---|
| 190 | }
|
---|
| 191 | _curLat = sec - _newSecGPS;
|
---|
| 192 | _sumLat += _curLat;
|
---|
| 193 | _sumLatQ += _curLat * _curLat;
|
---|
| 194 | if (_curLat < _minLat) {_minLat = _curLat;}
|
---|
| 195 | if (_curLat >= _maxLat) {_maxLat = _curLat;}
|
---|
| 196 | _numLat += 1;
|
---|
| 197 | _oldSecGPS = _newSecGPS;
|
---|
| 198 | _followSec = true;
|
---|
[1035] | 199 | }
|
---|
| 200 | }
|
---|
| 201 | }
|
---|
| 202 | }
|
---|
| 203 | _coDecoder->_epochList.clear();
|
---|
| 204 |
|
---|
[1021] | 205 | if (_mode == unknown) {
|
---|
| 206 | _mode = corrections;
|
---|
| 207 | }
|
---|
| 208 | }
|
---|
[913] | 209 | }
|
---|
[880] | 210 |
|
---|
| 211 | // Remaining part decodes the Observations
|
---|
| 212 | // ---------------------------------------
|
---|
[1033] | 213 | if (_mode == unknown || _mode == observations || _checkMountPoint == _staID || _checkMountPoint == "ALL") {
|
---|
[1127] | 214 |
|
---|
[1021] | 215 | for (int ii = 0; ii < bufLen; ii++) {
|
---|
| 216 | _Parser.Message[_Parser.MessageSize++] = buffer[ii];
|
---|
[1127] | 217 |
|
---|
[1021] | 218 | if (_Parser.MessageSize >= _Parser.NeedBytes) {
|
---|
| 219 |
|
---|
[1030] | 220 | // RTCM message types
|
---|
| 221 | // ------------------
|
---|
[1127] | 222 | for (int kk = 0; kk < _Parser.typeSize; kk++) {
|
---|
| 223 | _typeList.push_back(_Parser.typeList[kk]);
|
---|
| 224 | }
|
---|
| 225 | _Parser.typeSize = 0;
|
---|
[1130] | 226 |
|
---|
| 227 | // Antenna XYZ-H
|
---|
| 228 | // -------------
|
---|
| 229 | for (int kk = 0; kk < _Parser.antSize; kk += 4) {
|
---|
| 230 | _antList.push_back(_Parser.antList[kk + 0]);
|
---|
| 231 | _antList.push_back(_Parser.antList[kk + 1]);
|
---|
| 232 | _antList.push_back(_Parser.antList[kk + 2]);
|
---|
| 233 | _antList.push_back(_Parser.antList[kk + 3]);
|
---|
| 234 | }
|
---|
| 235 | _Parser.antSize = 0;
|
---|
[1021] | 236 |
|
---|
[1033] | 237 | while(int rr = RTCM3Parser(&_Parser)) {
|
---|
| 238 |
|
---|
[1021] | 239 | // GNSS Observations
|
---|
| 240 | // -----------------
|
---|
| 241 | if (rr == 1 || rr == 2) {
|
---|
[1127] | 242 | decoded = true;
|
---|
[1021] | 243 |
|
---|
| 244 | if (!_Parser.init) {
|
---|
| 245 | HandleHeader(&_Parser);
|
---|
| 246 | _Parser.init = 1;
|
---|
| 247 | }
|
---|
| 248 |
|
---|
| 249 | if (rr == 2) {
|
---|
[1033] | 250 | emit(newMessage( (_staID + ": No valid RINEX! All values are modulo 299792.458!").toAscii() ));
|
---|
[1021] | 251 | }
|
---|
| 252 |
|
---|
| 253 | for (int ii = 0; ii < _Parser.Data.numsats; ii++) {
|
---|
| 254 | p_obs obs = new t_obs();
|
---|
| 255 | _obsList.push_back(obs);
|
---|
| 256 | if (_Parser.Data.satellites[ii] <= PRN_GPS_END) {
|
---|
| 257 | obs->_o.satSys = 'G';
|
---|
| 258 | obs->_o.satNum = _Parser.Data.satellites[ii];
|
---|
[366] | 259 | }
|
---|
[1021] | 260 | else if (_Parser.Data.satellites[ii] <= PRN_GLONASS_END) {
|
---|
| 261 | obs->_o.satSys = 'R';
|
---|
| 262 | obs->_o.satNum = _Parser.Data.satellites[ii] - PRN_GLONASS_START + 1;
|
---|
| 263 | }
|
---|
[511] | 264 | else {
|
---|
[1021] | 265 | obs->_o.satSys = 'S';
|
---|
| 266 | obs->_o.satNum = _Parser.Data.satellites[ii] - PRN_WAAS_START + 20;
|
---|
| 267 | }
|
---|
| 268 | obs->_o.GPSWeek = _Parser.Data.week;
|
---|
| 269 | obs->_o.GPSWeeks = _Parser.Data.timeofweek / 1000.0;
|
---|
| 270 |
|
---|
| 271 | for (int jj = 0; jj < _Parser.numdatatypesGPS; jj++) {
|
---|
| 272 | int v = 0;
|
---|
| 273 | // sepearated declaration and initalization of df and pos. Perlt
|
---|
| 274 | int df;
|
---|
| 275 | int pos;
|
---|
| 276 | df = _Parser.dataflag[jj];
|
---|
| 277 | pos = _Parser.datapos[jj];
|
---|
[511] | 278 | if ( (_Parser.Data.dataflags[ii] & df)
|
---|
| 279 | && !isnan(_Parser.Data.measdata[ii][pos])
|
---|
| 280 | && !isinf(_Parser.Data.measdata[ii][pos])) {
|
---|
[1021] | 281 | v = 1;
|
---|
[511] | 282 | }
|
---|
[1021] | 283 | else {
|
---|
| 284 | df = _Parser.dataflagGPS[jj];
|
---|
| 285 | pos = _Parser.dataposGPS[jj];
|
---|
| 286 | if ( (_Parser.Data.dataflags[ii] & df)
|
---|
| 287 | && !isnan(_Parser.Data.measdata[ii][pos])
|
---|
| 288 | && !isinf(_Parser.Data.measdata[ii][pos])) {
|
---|
[1126] | 289 | v = 1;
|
---|
[1021] | 290 | }
|
---|
[627] | 291 | }
|
---|
[1021] | 292 | if (!v) {
|
---|
| 293 | continue;
|
---|
[627] | 294 | }
|
---|
[1021] | 295 | else
|
---|
| 296 | {
|
---|
[1126] | 297 | int isat = (_Parser.Data.satellites[ii] < 120
|
---|
| 298 | ? _Parser.Data.satellites[ii]
|
---|
| 299 | : _Parser.Data.satellites[ii] - 80);
|
---|
| 300 |
|
---|
[1021] | 301 | // variables df and pos are used consequently. Perlt
|
---|
| 302 | if (df & GNSSDF_C1DATA) {
|
---|
| 303 | obs->_o.C1 = _Parser.Data.measdata[ii][pos];
|
---|
| 304 | }
|
---|
| 305 | else if (df & GNSSDF_C2DATA) {
|
---|
| 306 | obs->_o.C2 = _Parser.Data.measdata[ii][pos];
|
---|
| 307 | }
|
---|
| 308 | else if (df & GNSSDF_P1DATA) {
|
---|
| 309 | obs->_o.P1 = _Parser.Data.measdata[ii][pos];
|
---|
| 310 | }
|
---|
| 311 | else if (df & GNSSDF_P2DATA) {
|
---|
| 312 | obs->_o.P2 = _Parser.Data.measdata[ii][pos];
|
---|
| 313 | }
|
---|
| 314 | else if (df & (GNSSDF_L1CDATA|GNSSDF_L1PDATA)) {
|
---|
[1044] | 315 | obs->_o.L1 = _Parser.Data.measdata[ii][pos];
|
---|
| 316 | obs->_o.SNR1 = _Parser.Data.snrL1[ii];
|
---|
[1126] | 317 | obs->_o.lock_timei_L1 = _Parser.lastlockl1[isat];
|
---|
[1021] | 318 | }
|
---|
| 319 | else if (df & (GNSSDF_L2CDATA|GNSSDF_L2PDATA)) {
|
---|
[1044] | 320 | obs->_o.L2 = _Parser.Data.measdata[ii][pos];
|
---|
| 321 | obs->_o.SNR2 = _Parser.Data.snrL2[ii];
|
---|
[1126] | 322 | obs->_o.lock_timei_L2 = _Parser.lastlockl2[isat];
|
---|
[1021] | 323 | }
|
---|
| 324 | else if (df & (GNSSDF_S1CDATA|GNSSDF_S1PDATA)) {
|
---|
| 325 | obs->_o.S1 = _Parser.Data.measdata[ii][pos];
|
---|
| 326 | }
|
---|
| 327 | else if (df & (GNSSDF_S2CDATA|GNSSDF_S2PDATA)) {
|
---|
| 328 | obs->_o.S2 = _Parser.Data.measdata[ii][pos];
|
---|
| 329 | }
|
---|
[627] | 330 | }
|
---|
[511] | 331 | }
|
---|
[366] | 332 | }
|
---|
[296] | 333 | }
|
---|
[1021] | 334 |
|
---|
| 335 | // GPS Ephemeris
|
---|
| 336 | // -------------
|
---|
| 337 | else if (rr == 1019) {
|
---|
| 338 | decoded = true;
|
---|
| 339 | gpsephemeris* ep = new gpsephemeris(_Parser.ephemerisGPS);
|
---|
| 340 | emit newGPSEph(ep);
|
---|
| 341 | }
|
---|
| 342 |
|
---|
| 343 | // GLONASS Ephemeris
|
---|
| 344 | // -----------------
|
---|
| 345 | else if (rr == 1020) {
|
---|
| 346 | decoded = true;
|
---|
| 347 | glonassephemeris* ep = new glonassephemeris(_Parser.ephemerisGLONASS);
|
---|
| 348 | emit newGlonassEph(ep);
|
---|
| 349 | }
|
---|
[296] | 350 | }
|
---|
| 351 | }
|
---|
| 352 | }
|
---|
[1021] | 353 | if (_mode == unknown && decoded) {
|
---|
| 354 | _mode = observations;
|
---|
| 355 | }
|
---|
[296] | 356 | }
|
---|
[1021] | 357 |
|
---|
| 358 | if (decoded) {
|
---|
| 359 | return success;
|
---|
[658] | 360 | }
|
---|
| 361 | else {
|
---|
[1021] | 362 | return failure;
|
---|
[658] | 363 | }
|
---|
[296] | 364 | }
|
---|