[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"
|
---|
| 46 | #include "bncconst.h"
|
---|
[511] | 47 | #include "bncapp.h"
|
---|
[1535] | 48 | #include "bncutils.h"
|
---|
| 49 | #include "bncsettings.h"
|
---|
[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 |
|
---|
[1535] | 66 | bncSettings settings;
|
---|
[1580] | 67 | _checkMountPoint = settings.value("miscMount").toString();
|
---|
[1022] | 68 | _staID = staID;
|
---|
| 69 |
|
---|
| 70 | // Ensure, that the Decoder uses the "old" convention for the data structure for Rinex2. Perlt
|
---|
[689] | 71 | _Parser.rinex3 = 0;
|
---|
| 72 |
|
---|
[505] | 73 | memset(&_Parser, 0, sizeof(_Parser));
|
---|
[880] | 74 |
|
---|
[1153] | 75 | double secGPS;
|
---|
| 76 | currentGPSWeeks(_Parser.GPSWeek, secGPS);
|
---|
| 77 | _Parser.GPSTOW = int(secGPS);
|
---|
| 78 |
|
---|
[939] | 79 | connect(this, SIGNAL(newGPSEph(gpsephemeris*)),
|
---|
| 80 | (bncApp*) qApp, SLOT(slotNewGPSEph(gpsephemeris*)));
|
---|
| 81 | connect(this, SIGNAL(newGlonassEph(glonassephemeris*)),
|
---|
| 82 | (bncApp*) qApp, SLOT(slotNewGlonassEph(glonassephemeris*)));
|
---|
| 83 |
|
---|
[880] | 84 | // Sub-Decoder for Clock and Orbit Corrections
|
---|
| 85 | // -------------------------------------------
|
---|
[970] | 86 | _coDecoder = new RTCM3coDecoder(staID);
|
---|
[1021] | 87 |
|
---|
| 88 | // Mode can be either observations or corrections
|
---|
| 89 | // ----------------------------------------------
|
---|
| 90 | _mode = unknown;
|
---|
[296] | 91 | }
|
---|
| 92 |
|
---|
| 93 | // Destructor
|
---|
| 94 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 95 | RTCM3Decoder::~RTCM3Decoder() {
|
---|
[880] | 96 | delete _coDecoder;
|
---|
[296] | 97 | }
|
---|
| 98 |
|
---|
| 99 | //
|
---|
| 100 | ////////////////////////////////////////////////////////////////////////////
|
---|
[1218] | 101 | t_irc RTCM3Decoder::Decode(char* buffer, int bufLen, vector<string>& errmsg) {
|
---|
[508] | 102 |
|
---|
[1218] | 103 | errmsg.clear();
|
---|
| 104 |
|
---|
[913] | 105 | bool decoded = false;
|
---|
| 106 |
|
---|
[880] | 107 | // Try to decode Clock and Orbit Corrections
|
---|
| 108 | // -----------------------------------------
|
---|
[1021] | 109 | if (_mode == unknown || _mode == corrections) {
|
---|
[1218] | 110 | if ( _coDecoder->Decode(buffer, bufLen, errmsg) == success ) {
|
---|
[1021] | 111 | decoded = true;
|
---|
| 112 | if (_mode == unknown) {
|
---|
| 113 | _mode = corrections;
|
---|
| 114 | }
|
---|
| 115 | }
|
---|
[913] | 116 | }
|
---|
[880] | 117 |
|
---|
| 118 | // Remaining part decodes the Observations
|
---|
| 119 | // ---------------------------------------
|
---|
[1033] | 120 | if (_mode == unknown || _mode == observations || _checkMountPoint == _staID || _checkMountPoint == "ALL") {
|
---|
[1127] | 121 |
|
---|
[1021] | 122 | for (int ii = 0; ii < bufLen; ii++) {
|
---|
| 123 | _Parser.Message[_Parser.MessageSize++] = buffer[ii];
|
---|
[1127] | 124 |
|
---|
[1021] | 125 | if (_Parser.MessageSize >= _Parser.NeedBytes) {
|
---|
[1185] | 126 |
|
---|
[1239] | 127 | while(int rr = RTCM3Parser(&_Parser)) {
|
---|
[1130] | 128 |
|
---|
[1239] | 129 | // RTCMv3 message types
|
---|
| 130 | // --------------------
|
---|
| 131 | _typeList.push_back(_Parser.blocktype);
|
---|
[1185] | 132 |
|
---|
[1239] | 133 | // RTCMv3 antenna descriptor
|
---|
| 134 | // -------------------------
|
---|
| 135 | if(rr == 1007 || rr == 1008 || rr == 1033)
|
---|
| 136 | {
|
---|
| 137 | _antType.push_back(_Parser.antenna); /* correct ? */
|
---|
| 138 | }
|
---|
[1185] | 139 |
|
---|
[1239] | 140 | // RTCMv3 antenna XYZ
|
---|
| 141 | // ------------------
|
---|
| 142 | else if(rr == 1005)
|
---|
| 143 | {
|
---|
[1268] | 144 | _antList.push_back(t_antInfo());
|
---|
| 145 | _antList.back().type = t_antInfo::ARP;
|
---|
| 146 | _antList.back().xx = _Parser.antX * 1e-4;
|
---|
| 147 | _antList.back().yy = _Parser.antY * 1e-4;
|
---|
| 148 | _antList.back().zz = _Parser.antZ * 1e-4;
|
---|
| 149 | _antList.back().message = rr;
|
---|
[1239] | 150 | }
|
---|
[1033] | 151 |
|
---|
[1239] | 152 | // RTCMv3 antenna XYZ-H
|
---|
| 153 | // --------------------
|
---|
| 154 | else if(rr == 1006)
|
---|
| 155 | {
|
---|
[1268] | 156 | _antList.push_back(t_antInfo());
|
---|
| 157 | _antList.back().type = t_antInfo::ARP;
|
---|
| 158 | _antList.back().xx = _Parser.antX * 1e-4;
|
---|
| 159 | _antList.back().yy = _Parser.antY * 1e-4;
|
---|
| 160 | _antList.back().zz = _Parser.antZ * 1e-4;
|
---|
| 161 | _antList.back().height = _Parser.antH * 1e-4;
|
---|
| 162 | _antList.back().height_f = true;
|
---|
| 163 | _antList.back().message = rr;
|
---|
[1239] | 164 | }
|
---|
| 165 |
|
---|
[1021] | 166 | // GNSS Observations
|
---|
| 167 | // -----------------
|
---|
[1239] | 168 | else if (rr == 1 || rr == 2) {
|
---|
[1127] | 169 | decoded = true;
|
---|
[1021] | 170 |
|
---|
| 171 | if (!_Parser.init) {
|
---|
| 172 | HandleHeader(&_Parser);
|
---|
| 173 | _Parser.init = 1;
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | if (rr == 2) {
|
---|
[1299] | 177 | emit(newMessage( (_staID + ": No valid RINEX! All values are modulo 299792.458!").toAscii(), true));
|
---|
[1021] | 178 | }
|
---|
| 179 |
|
---|
| 180 | for (int ii = 0; ii < _Parser.Data.numsats; ii++) {
|
---|
| 181 | p_obs obs = new t_obs();
|
---|
| 182 | _obsList.push_back(obs);
|
---|
| 183 | if (_Parser.Data.satellites[ii] <= PRN_GPS_END) {
|
---|
| 184 | obs->_o.satSys = 'G';
|
---|
| 185 | obs->_o.satNum = _Parser.Data.satellites[ii];
|
---|
[366] | 186 | }
|
---|
[1021] | 187 | else if (_Parser.Data.satellites[ii] <= PRN_GLONASS_END) {
|
---|
| 188 | obs->_o.satSys = 'R';
|
---|
| 189 | obs->_o.satNum = _Parser.Data.satellites[ii] - PRN_GLONASS_START + 1;
|
---|
| 190 | }
|
---|
[511] | 191 | else {
|
---|
[1021] | 192 | obs->_o.satSys = 'S';
|
---|
| 193 | obs->_o.satNum = _Parser.Data.satellites[ii] - PRN_WAAS_START + 20;
|
---|
| 194 | }
|
---|
| 195 | obs->_o.GPSWeek = _Parser.Data.week;
|
---|
| 196 | obs->_o.GPSWeeks = _Parser.Data.timeofweek / 1000.0;
|
---|
| 197 |
|
---|
| 198 | for (int jj = 0; jj < _Parser.numdatatypesGPS; jj++) {
|
---|
| 199 | int v = 0;
|
---|
| 200 | // sepearated declaration and initalization of df and pos. Perlt
|
---|
| 201 | int df;
|
---|
| 202 | int pos;
|
---|
| 203 | df = _Parser.dataflag[jj];
|
---|
| 204 | pos = _Parser.datapos[jj];
|
---|
[511] | 205 | if ( (_Parser.Data.dataflags[ii] & df)
|
---|
| 206 | && !isnan(_Parser.Data.measdata[ii][pos])
|
---|
| 207 | && !isinf(_Parser.Data.measdata[ii][pos])) {
|
---|
[1021] | 208 | v = 1;
|
---|
[511] | 209 | }
|
---|
[1021] | 210 | else {
|
---|
| 211 | df = _Parser.dataflagGPS[jj];
|
---|
| 212 | pos = _Parser.dataposGPS[jj];
|
---|
| 213 | if ( (_Parser.Data.dataflags[ii] & df)
|
---|
| 214 | && !isnan(_Parser.Data.measdata[ii][pos])
|
---|
| 215 | && !isinf(_Parser.Data.measdata[ii][pos])) {
|
---|
[1126] | 216 | v = 1;
|
---|
[1021] | 217 | }
|
---|
[627] | 218 | }
|
---|
[1021] | 219 | if (!v) {
|
---|
| 220 | continue;
|
---|
[627] | 221 | }
|
---|
[1021] | 222 | else
|
---|
| 223 | {
|
---|
[1126] | 224 | int isat = (_Parser.Data.satellites[ii] < 120
|
---|
| 225 | ? _Parser.Data.satellites[ii]
|
---|
| 226 | : _Parser.Data.satellites[ii] - 80);
|
---|
| 227 |
|
---|
[1021] | 228 | // variables df and pos are used consequently. Perlt
|
---|
| 229 | if (df & GNSSDF_C1DATA) {
|
---|
| 230 | obs->_o.C1 = _Parser.Data.measdata[ii][pos];
|
---|
| 231 | }
|
---|
| 232 | else if (df & GNSSDF_C2DATA) {
|
---|
| 233 | obs->_o.C2 = _Parser.Data.measdata[ii][pos];
|
---|
| 234 | }
|
---|
| 235 | else if (df & GNSSDF_P1DATA) {
|
---|
| 236 | obs->_o.P1 = _Parser.Data.measdata[ii][pos];
|
---|
| 237 | }
|
---|
| 238 | else if (df & GNSSDF_P2DATA) {
|
---|
| 239 | obs->_o.P2 = _Parser.Data.measdata[ii][pos];
|
---|
| 240 | }
|
---|
| 241 | else if (df & (GNSSDF_L1CDATA|GNSSDF_L1PDATA)) {
|
---|
[1044] | 242 | obs->_o.L1 = _Parser.Data.measdata[ii][pos];
|
---|
| 243 | obs->_o.SNR1 = _Parser.Data.snrL1[ii];
|
---|
[1126] | 244 | obs->_o.lock_timei_L1 = _Parser.lastlockl1[isat];
|
---|
[1021] | 245 | }
|
---|
| 246 | else if (df & (GNSSDF_L2CDATA|GNSSDF_L2PDATA)) {
|
---|
[1044] | 247 | obs->_o.L2 = _Parser.Data.measdata[ii][pos];
|
---|
| 248 | obs->_o.SNR2 = _Parser.Data.snrL2[ii];
|
---|
[1126] | 249 | obs->_o.lock_timei_L2 = _Parser.lastlockl2[isat];
|
---|
[1021] | 250 | }
|
---|
| 251 | else if (df & (GNSSDF_S1CDATA|GNSSDF_S1PDATA)) {
|
---|
| 252 | obs->_o.S1 = _Parser.Data.measdata[ii][pos];
|
---|
| 253 | }
|
---|
| 254 | else if (df & (GNSSDF_S2CDATA|GNSSDF_S2PDATA)) {
|
---|
| 255 | obs->_o.S2 = _Parser.Data.measdata[ii][pos];
|
---|
| 256 | }
|
---|
[627] | 257 | }
|
---|
[511] | 258 | }
|
---|
[366] | 259 | }
|
---|
[296] | 260 | }
|
---|
[1021] | 261 |
|
---|
| 262 | // GPS Ephemeris
|
---|
| 263 | // -------------
|
---|
| 264 | else if (rr == 1019) {
|
---|
| 265 | decoded = true;
|
---|
| 266 | gpsephemeris* ep = new gpsephemeris(_Parser.ephemerisGPS);
|
---|
| 267 | emit newGPSEph(ep);
|
---|
| 268 | }
|
---|
| 269 |
|
---|
| 270 | // GLONASS Ephemeris
|
---|
| 271 | // -----------------
|
---|
| 272 | else if (rr == 1020) {
|
---|
| 273 | decoded = true;
|
---|
| 274 | glonassephemeris* ep = new glonassephemeris(_Parser.ephemerisGLONASS);
|
---|
| 275 | emit newGlonassEph(ep);
|
---|
| 276 | }
|
---|
[296] | 277 | }
|
---|
| 278 | }
|
---|
| 279 | }
|
---|
[1021] | 280 | if (_mode == unknown && decoded) {
|
---|
| 281 | _mode = observations;
|
---|
| 282 | }
|
---|
[296] | 283 | }
|
---|
[1021] | 284 |
|
---|
| 285 | if (decoded) {
|
---|
| 286 | return success;
|
---|
[658] | 287 | }
|
---|
| 288 | else {
|
---|
[1021] | 289 | return failure;
|
---|
[658] | 290 | }
|
---|
[296] | 291 | }
|
---|