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

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