source: ntrip/trunk/BNC/src/RTCM/RTCM2Decoder.cpp@ 10269

Last change on this file since 10269 was 9088, checked in by stuerze, 4 years ago

adjusted allocation of slip and LTI according to the respective RTCM version

File size: 12.3 KB
RevLine 
[297]1// Part of BNC, a utility for retrieving decoding and
[464]2// converting GNSS data streams from NTRIP broadcasters.
[242]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.
[242]24
[464]25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: RTCM2Decoder
30 *
31 * Purpose: RTCM2 Decoder
32 *
33 * Author: L. Mervart
34 *
35 * Created: 24-Aug-2006
36 *
[7528]37 * Changes:
[464]38 *
39 * -----------------------------------------------------------------------*/
40
[1044]41#include <math.h>
42#include <sstream>
43#include <iomanip>
[1218]44#include <set>
[1044]45
[242]46#include "../bncutils.h"
[1044]47#include "rtcm_utils.h"
[243]48#include "RTCM2Decoder.h"
[242]49
50using namespace std;
[1044]51using namespace rtcm2;
[242]52
[7528]53//
[242]54// Constructor
[7528]55//
[242]56
[6443]57RTCM2Decoder::RTCM2Decoder(const std::string& ID) : _ephUser(true) {
[1044]58 _ID = ID;
[242]59}
60
[7528]61//
[242]62// Destructor
[7528]63//
[242]64
65RTCM2Decoder::~RTCM2Decoder() {
66}
67
68//
[1044]69t_irc RTCM2Decoder::getStaCrd(double& xx, double& yy, double& zz) {
[6703]70 if (!_msg03.validMsg) {
[1044]71 return failure;
72 }
[6703]73
[1044]74 xx = _msg03.x + (_msg22.validMsg ? _msg22.dL1[0] : 0.0);
75 yy = _msg03.y + (_msg22.validMsg ? _msg22.dL1[1] : 0.0);
76 zz = _msg03.z + (_msg22.validMsg ? _msg22.dL1[2] : 0.0);
[242]77
[1044]78 return success;
79}
80
[1167]81//
[6703]82t_irc RTCM2Decoder::getStaCrd(double& xx, double& yy, double& zz, double& dx1,
83 double& dy1, double& dz1, double& dx2, double& dy2, double& dz2) {
[1167]84 xx = _msg03.x;
85 yy = _msg03.y;
86 zz = _msg03.z;
[1044]87
[1167]88 dx1 = (_msg22.validMsg ? _msg22.dL1[0] : 0.0);
89 dy1 = (_msg22.validMsg ? _msg22.dL1[1] : 0.0);
90 dz1 = (_msg22.validMsg ? _msg22.dL1[2] : 0.0);
91
92 dx2 = (_msg22.validMsg ? _msg22.dL2[0] : 0.0);
93 dy2 = (_msg22.validMsg ? _msg22.dL2[1] : 0.0);
94 dz2 = (_msg22.validMsg ? _msg22.dL2[2] : 0.0);
95
96 return success;
97}
98
[1044]99//
[1218]100t_irc RTCM2Decoder::Decode(char* buffer, int bufLen, vector<string>& errmsg) {
[242]101
[1218]102 errmsg.clear();
103
[242]104 _buffer.append(buffer, bufLen);
[6703]105 int refWeek;
[242]106 double refSecs;
107 currentGPSWeeks(refWeek, refSecs);
[702]108 bool decoded = false;
[242]109
[6703]110 while (true) {
[242]111 _PP.getPacket(_buffer);
112 if (!_PP.valid()) {
[702]113 if (decoded) {
114 return success;
115 } else {
116 return failure;
117 }
[242]118 }
[6703]119
[1268]120 // Store message number
121 _typeList.push_back(_PP.ID());
[242]122
[6703]123 if (_PP.ID() == 18 || _PP.ID() == 19) {
[242]124
125 _ObsBlock.extract(_PP);
126
127 if (_ObsBlock.valid()) {
[702]128 decoded = true;
[242]129
[6703]130 int epochWeek;
[242]131 double epochSecs;
132 _ObsBlock.resolveEpoch(refWeek, refSecs, epochWeek, epochSecs);
[6703]133
134 for (int iSat = 0; iSat < _ObsBlock.nSat; iSat++) {
[6137]135 t_satObs obs;
[341]136 if (_ObsBlock.PRN[iSat] > 100) {
[6137]137 obs._prn.set('R', _ObsBlock.PRN[iSat] % 100);
[6703]138 } else {
[6194]139 obs._prn.set('G', _ObsBlock.PRN[iSat]);
[6703]140 }
[6194]141 char sys = obs._prn.system();
[6137]142 obs._time.set(epochWeek, epochSecs);
[6703]143
[6137]144 t_frqObs* frqObs1C = new t_frqObs;
[6703]145 frqObs1C->_rnxType2ch = "1C";
[8025]146 frqObs1C->_codeValid = true;
[6703]147 frqObs1C->_code = _ObsBlock.rng_C1[iSat];
[6137]148 obs._obs.push_back(frqObs1C);
[2711]149
[6137]150 t_frqObs* frqObs1P = new t_frqObs;
[6703]151 frqObs1P->_rnxType2ch = (sys == 'G') ? "1W" : "1P";
[8025]152 frqObs1P->_codeValid = true;
[6703]153 frqObs1P->_code = _ObsBlock.rng_P1[iSat];
[8025]154 frqObs1P->_phaseValid = true;
[6703]155 frqObs1P->_phase = _ObsBlock.resolvedPhase_L1(iSat);
[9088]156 frqObs1P->_slipCounter = _ObsBlock.slip_L1[iSat];
[6137]157 obs._obs.push_back(frqObs1P);
158
159 t_frqObs* frqObs2P = new t_frqObs;
[6703]160 frqObs2P->_rnxType2ch = (sys == 'G') ? "2W" : "2P";
[8025]161 frqObs2P->_codeValid = true;
[6703]162 frqObs2P->_code = _ObsBlock.rng_P2[iSat];
[8025]163 frqObs2P->_phaseValid = true;
[6703]164 frqObs2P->_phase = _ObsBlock.resolvedPhase_L2(iSat);
[9088]165 frqObs2P->_slipCounter = _ObsBlock.slip_L2[iSat];
[6137]166 obs._obs.push_back(frqObs2P);
167
[2711]168 _obsList.push_back(obs);
[242]169 }
170 _ObsBlock.clear();
171 }
172 }
[8025]173
[6703]174 else if (_PP.ID() == 20 || _PP.ID() == 21) {
[1044]175 _msg2021.extract(_PP);
176
177 if (_msg2021.valid()) {
[1045]178 decoded = true;
[6703]179 translateCorr2Obs(errmsg);
180 }
[1044]181 }
182
[6703]183 else if (_PP.ID() == 3) {
[1044]184 _msg03.extract(_PP);
185 }
186
[6703]187 else if (_PP.ID() == 22) {
[1044]188 _msg22.extract(_PP);
189 }
[1268]190
[6703]191 else if (_PP.ID() == 23) {
[1269]192 _msg23.extract(_PP);
193 }
[1268]194
[6703]195 else if (_PP.ID() == 24) {
[1269]196 _msg24.extract(_PP);
197 }
[1268]198
[1269]199 // Output for RTCM scan
[6703]200 if (_PP.ID() == 3) {
201 if (_msg03.validMsg) {
[8234]202 _antList.push_back(t_antRefPoint());
[6703]203
[8234]204 this->getStaCrd(_antList.back().xx, _antList.back().yy, _antList.back().zz);
[6703]205
[8234]206 _antList.back().type = t_antRefPoint::APC;
[6703]207 _antList.back().message = _PP.ID();
[1269]208 }
[6703]209 } else if (_PP.ID() == 23) {
[8234]210 if (_msg23.validMsg) {
211 int antlen = strlen(_msg23.antType.c_str());
212 int serlen = strlen(_msg23.antSN.c_str());
213 if ((antlen) &&
214 (_antType.empty() || strncmp(_antType.back().descriptor, _msg23.antType.c_str(), antlen) != 0)) {
215 _antType.push_back(t_antInfo());
216 memcpy(_antType.back().descriptor, _msg23.antType.c_str(), antlen);
217 _antType.back().descriptor[antlen] = 0;
218 if (serlen) {
219 memcpy(_antType.back().serialnumber, _msg23.antSN.c_str(), serlen);
220 _antType.back().serialnumber[serlen] = 0;
221 }
222 }
[1269]223 }
[6703]224 } else if (_PP.ID() == 24) {
225 if (_msg24.validMsg) {
[8234]226 _antList.push_back(t_antRefPoint());
[3594]227
[6703]228 _antList.back().xx = _msg24.x;
229 _antList.back().yy = _msg24.y;
230 _antList.back().zz = _msg24.z;
231
232 _antList.back().height_f = true;
233 _antList.back().height = _msg24.h;
234
[8234]235 _antList.back().type = t_antRefPoint::ARP;
[6703]236 _antList.back().message = _PP.ID();
[1269]237 }
238 }
[242]239 }
[649]240 return success;
[242]241}
242
[1218]243void RTCM2Decoder::translateCorr2Obs(vector<string>& errmsg) {
[1044]244
[3580]245 QMutexLocker locker(&_mutex);
246
[6703]247 if (!_msg03.validMsg || !_msg2021.valid()) {
[1044]248 return;
249 }
250
251 double stax = _msg03.x + (_msg22.validMsg ? _msg22.dL1[0] : 0.0);
252 double stay = _msg03.y + (_msg22.validMsg ? _msg22.dL1[1] : 0.0);
253 double staz = _msg03.z + (_msg22.validMsg ? _msg22.dL1[2] : 0.0);
254
[6703]255 int refWeek;
[1044]256 double refSecs;
257 currentGPSWeeks(refWeek, refSecs);
258
259 // Resolve receiver time of measurement (see RTCM 2.3, page 4-42, Message 18, Note 1)
260 // ----------------------------------------------------------------------------------
[6703]261 double hoursec_est = _msg2021.hoursec(); // estimated time of measurement
262 double hoursec_rcv = rint(hoursec_est * 1e2) / 1e2; // receiver clock reading at hoursec_est
[1044]263 double rcv_clk_bias = (hoursec_est - hoursec_rcv) * c_light;
264
[6703]265 int GPSWeek;
[1044]266 double GPSWeeks;
[6703]267 resolveEpoch(hoursec_est, refWeek, refSecs, GPSWeek, GPSWeeks);
[1044]268
[6703]269 int GPSWeek_rcv;
[1044]270 double GPSWeeks_rcv;
[6703]271 resolveEpoch(hoursec_rcv, refWeek, refSecs, GPSWeek_rcv, GPSWeeks_rcv);
[1044]272
273 // Loop over all satellites
274 // ------------------------
275 for (RTCM2_2021::data_iterator icorr = _msg2021.data.begin();
[6703]276 icorr != _msg2021.data.end(); icorr++) {
[1044]277 const RTCM2_2021::HiResCorr* corr = icorr->second;
278
[1218]279 // beg test
[6703]280 if (corr->PRN >= 200) {
[1218]281 continue;
282 }
283 // end test
284
[3562]285 QString prn;
[6703]286 char sys;
[3562]287 if (corr->PRN < 200) {
[6194]288 sys = 'G';
[7043]289 prn = sys + QString("%1_0").arg(corr->PRN, 2, 10, QChar('0'));
[6703]290 } else {
[6194]291 sys = 'R';
[7043]292 prn = sys + QString("%1_0").arg(corr->PRN - 200, 2, 10, QChar('0'));
[3562]293 }
[1218]294
[1044]295 double L1 = 0;
296 double L2 = 0;
297 double P1 = 0;
298 double P2 = 0;
299 string obsT = "";
300
301 // new observation
[7528]302 t_satObs new_obs;
[1044]303
[6137]304 t_frqObs* frqObs1C = new t_frqObs;
[6703]305 frqObs1C->_rnxType2ch = "1C";
[7528]306 new_obs._obs.push_back(frqObs1C);
[6137]307
308 t_frqObs* frqObs1P = new t_frqObs;
[6703]309 frqObs1P->_rnxType2ch = (sys == 'G') ? "1W" : "1P";
[7528]310 new_obs._obs.push_back(frqObs1P);
[6137]311
312 t_frqObs* frqObs2P = new t_frqObs;
[6703]313 frqObs2P->_rnxType2ch = (sys == 'G') ? "2W" : "2P";
[7528]314 new_obs._obs.push_back(frqObs2P);
[6137]315
[1218]316 // missing IOD
317 vector<string> missingIOD;
[6703]318 vector<string> hasIOD;
[1044]319 for (unsigned ii = 0; ii < 4; ii++) {
[7169]320 unsigned int IODcorr = 0;
[6703]321 double corrVal = 0;
322 const t_eph* eph = 0;
323 double* obsVal = 0;
[1044]324
325 switch (ii) {
[6703]326 case 0: // --- L1 ---
327 IODcorr = corr->IODp1;
328 corrVal = corr->phase1 * LAMBDA_1;
329 obsVal = &L1;
330 obsT = "L1";
331 break;
332 case 1: // --- L2 ---
333 IODcorr = corr->IODp2;
334 corrVal = corr->phase2 * LAMBDA_2;
335 obsVal = &L2;
336 obsT = "L2";
337 break;
338 case 2: // --- P1 ---
339 IODcorr = corr->IODr1;
340 corrVal = corr->range1;
341 obsVal = &P1;
342 obsT = "P1";
343 break;
344 case 3: // --- P2 ---
345 IODcorr = corr->IODr2;
346 corrVal = corr->range2;
347 obsVal = &P2;
348 obsT = "P2";
349 break;
350 default:
351 continue;
[1044]352 }
353
[1299]354 // Select corresponding ephemerides
[6443]355 const t_eph* ephLast = _ephUser.ephLast(prn);
356 const t_eph* ephPrev = _ephUser.ephPrev(prn);
[6703]357 if (ephLast && ephLast->IOD() == IODcorr) {
[6443]358 eph = ephLast;
[6703]359 } else if (ephPrev && ephPrev->IOD() == IODcorr) {
[6443]360 eph = ephPrev;
[6442]361 }
[1218]362
[6703]363 if (eph) {
[1218]364 ostringstream msg;
365 msg << obsT << ':' << setw(3) << eph->IOD();
366 hasIOD.push_back(msg.str());
367
[6703]368 int GPSWeek_tot;
369 double GPSWeeks_tot;
370 double rho, xSat, ySat, zSat, clkSat;
371 cmpRho(eph, stax, stay, staz, GPSWeek, GPSWeeks, rho, GPSWeek_tot,
372 GPSWeeks_tot, xSat, ySat, zSat, clkSat);
[1218]373
[6703]374 *obsVal = rho - corrVal + rcv_clk_bias - clkSat;
[1044]375
[6703]376 if (*obsVal == 0)
377 *obsVal = ZEROVALUE;
[1044]378
[7528]379 if (corr->PRN < 200) {
380 new_obs._prn.set('G', corr->PRN);
381 } else {
382 new_obs._prn.set('R', corr->PRN - 200);
[6703]383 }
[7528]384 new_obs._time.set(GPSWeek_rcv, GPSWeeks_rcv);
[6703]385
386 // Store estimated measurements
387 // ----------------------------
388 switch (ii) {
389 case 0: // --- L1 ---
390 frqObs1P->_phaseValid = true;
391 frqObs1P->_phase = *obsVal / LAMBDA_1;
[7835]392 //frqObs1P->_slipCounter = corr->lock1;
393 frqObs1P->_slipCounter = -1; // because RTCM2 definition is vice versa to RTCM3
[6703]394 break;
395 case 1: // --- L2 ---
396 frqObs2P->_phaseValid = true;
397 frqObs2P->_phase = *obsVal / LAMBDA_2;
[7835]398 //frqObs2P->_slipCounter = corr->lock2;
399 frqObs2P->_slipCounter = -1; // because RTCM2 definition is vice versa to RTCM3
[6703]400 break;
401 case 2: // --- C1 / P1 ---
402 if (corr->Pind1) {
403 frqObs1P->_codeValid = true;
404 frqObs1P->_code = *obsVal;
405 } else {
406 frqObs1C->_codeValid = true;
407 frqObs1C->_code = *obsVal;
408 }
409 break;
410 case 3: // --- C2 / P2 ---
411 if (corr->Pind2) {
412 frqObs2P->_codeValid = true;
413 frqObs2P->_code = *obsVal;
414 }
415 break;
416 default:
417 continue;
418 }
419 } else if (IODcorr != 0) {
[1218]420 ostringstream msg;
421 msg << obsT << ':' << setw(3) << IODcorr;
422 missingIOD.push_back(msg.str());
423 }
[1044]424 } // loop over frequencies
[6703]425
[1218]426 // Error report
[6703]427 if (missingIOD.size()) {
[1218]428 ostringstream missingIODstr;
429
[6703]430 copy(missingIOD.begin(), missingIOD.end(),
431 ostream_iterator<string>(missingIODstr, " "));
[1218]432
[6703]433 errmsg.push_back(
[8204]434 "missing eph for " + string(prn.toLatin1().data()) + " , IODs "
[6703]435 + missingIODstr.str());
[1218]436 }
437
438 // Store new observation
[7528]439 if (new_obs._time.mjd() > 0) {
440 _obsList.push_back(new_obs);
[1044]441 }
442 }
443}
Note: See TracBrowser for help on using the repository browser.