source: ntrip/trunk/BNC/src/PPP_SSR_I/pppClient.cpp@ 10498

Last change on this file since 10498 was 9481, checked in by stuerze, 3 years ago

minor changes

  • Property svn:keywords set to Author Date Id Rev URL;svn:eol-style=native
  • Property svn:mime-type set to text/plain
File size: 14.4 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
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.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: t_pppClient
30 *
31 * Purpose: Precise Point Positioning
32 *
33 * Author: L. Mervart
34 *
35 * Created: 21-Nov-2009
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <newmatio.h>
42#include <iomanip>
43#include <sstream>
44
45#include "pppClient.h"
46#include "pppUtils.h"
47#include "bncephuser.h"
48#include "bncutils.h"
49
50using namespace BNC_PPP;
51using namespace std;
52
53// Constructor
54////////////////////////////////////////////////////////////////////////////
55t_pppClient::t_pppClient(const t_pppOptions* opt) {
56 _opt = new t_pppOptions(*opt);
57 _filter = new t_pppFilter(this);
58 _epoData = new t_epoData();
59 _log = new ostringstream();
60 _ephUser = new bncEphUser(false);
61 _pppUtils = new t_pppUtils();
62 _newEph = 0;
63}
64
65// Destructor
66////////////////////////////////////////////////////////////////////////////
67t_pppClient::~t_pppClient() {
68 delete _filter;
69 delete _epoData;
70 delete _opt;
71 delete _ephUser;
72 delete _log;
73 delete _pppUtils;
74 if (_newEph)
75 delete _newEph;
76}
77
78//
79////////////////////////////////////////////////////////////////////////////
80void t_pppClient::processEpoch(const vector<t_satObs*>& satObs, t_output* output) {
81
82 // Convert and store observations
83 // ------------------------------
84 _epoData->clear();
85 for (unsigned ii = 0; ii < satObs.size(); ii++) {
86 const t_satObs* obs = satObs[ii];
87 t_prn prn = obs->_prn;
88 if (prn.system() == 'E') {prn.setFlags(1);} // force I/NAV usage
89 t_satData* satData = new t_satData();
90
91 if (_epoData->tt.undef()) {
92 _epoData->tt = obs->_time;
93 }
94
95 satData->tt = obs->_time;
96 satData->prn = QString(prn.toInternalString().c_str());
97 satData->slipFlag = false;
98 satData->P1 = 0.0;
99 satData->P2 = 0.0;
100 satData->P5 = 0.0;
101 satData->P6 = 0.0;
102 satData->P7 = 0.0;
103 satData->L1 = 0.0;
104 satData->L2 = 0.0;
105 satData->L5 = 0.0;
106 satData->L6 = 0.0;
107 satData->L7 = 0.0;
108 for (unsigned ifrq = 0; ifrq < obs->_obs.size(); ifrq++) {
109 t_frqObs* frqObs = obs->_obs[ifrq];
110 double cb = 0.0;
111 const t_satCodeBias* satCB = _pppUtils->satCodeBias(prn);
112 if (satCB && satCB->_bias.size()) {
113 for (unsigned ii = 0; ii < satCB->_bias.size(); ii++) {
114
115 const t_frqCodeBias& bias = satCB->_bias[ii];
116 if (frqObs && frqObs->_rnxType2ch == bias._rnxType2ch) {
117 cb = bias._value;
118 }
119 // FIXME: use C/Q bias for X observations
120 // qDebug() << satData->prn << frqObs->_rnxType2ch.c_str();
121 }
122 }
123 if (frqObs->_rnxType2ch[0] == '1') {
124 if (frqObs->_codeValid) satData->P1 = frqObs->_code + cb;
125 if (frqObs->_phaseValid) satData->L1 = frqObs->_phase;
126 if (frqObs->_slip) satData->slipFlag = true;
127 }
128 else if (frqObs->_rnxType2ch[0] == '2') {
129 if (frqObs->_codeValid) satData->P2 = frqObs->_code + cb;
130 if (frqObs->_phaseValid) satData->L2 = frqObs->_phase;
131 if (frqObs->_slip) satData->slipFlag = true;
132 }
133 else if (frqObs->_rnxType2ch[0] == '5') {
134 if (frqObs->_codeValid) satData->P5 = frqObs->_code + cb;
135 if (frqObs->_phaseValid) satData->L5 = frqObs->_phase;
136 if (frqObs->_slip) satData->slipFlag = true;
137 }
138 else if (frqObs->_rnxType2ch[0] == '6') {
139 if (frqObs->_codeValid) satData->P6 = frqObs->_code + cb;
140 if (frqObs->_phaseValid) satData->L6 = frqObs->_phase;
141 if (frqObs->_slip) satData->slipFlag = true;
142 }
143 else if (frqObs->_rnxType2ch[0] == '7') {
144 if (frqObs->_codeValid) satData->P7 = frqObs->_code + cb;
145 if (frqObs->_phaseValid) satData->L7 = frqObs->_phase;
146 if (frqObs->_slip) satData->slipFlag = true;
147 }
148 }
149 putNewObs(satData);
150 }
151
152 // Data Pre-Processing
153 // -------------------
154 QMutableMapIterator<QString, t_satData*> it(_epoData->satData);
155 while (it.hasNext()) {
156 it.next();
157 QString prn = it.key();
158 t_satData* satData = it.value();
159
160 if (cmpToT(satData) != success) {
161 delete satData;
162 it.remove();
163 continue;
164 }
165
166 }
167
168 // Filter Solution
169 // ---------------
170 if (_filter->update(_epoData) == success) {
171 output->_error = false;
172 output->_epoTime = _filter->time();
173 output->_xyzRover[0] = _filter->x();
174 output->_xyzRover[1] = _filter->y();
175 output->_xyzRover[2] = _filter->z();
176 copy(&_filter->Q().data()[0], &_filter->Q().data()[6], output->_covMatrix);
177 output->_neu[0] = _filter->neu()[0];
178 output->_neu[1] = _filter->neu()[1];
179 output->_neu[2] = _filter->neu()[2];
180 output->_numSat = _filter->numSat();
181 output->_hDop = _filter->HDOP();
182 output->_trp0 = _filter->trp0();
183 output->_trp = _filter->trp();
184 output->_trpStdev = _filter->trpStdev();
185 }
186 else {
187 output->_error = true;
188 }
189
190 output->_log = _log->str();
191 delete _log; _log = new ostringstream();
192}
193
194//
195////////////////////////////////////////////////////////////////////////////
196void t_pppClient::putNewObs(t_satData* satData) {
197
198 // Set Observations GPS
199 // --------------------
200 if (satData->system() == 'G') {
201 if (satData->P1 != 0.0 && satData->P2 != 0.0 &&
202 satData->L1 != 0.0 && satData->L2 != 0.0 ) {
203 t_frequency::type fType1 = t_lc::toFreq(satData->system(), t_lc::l1);
204 t_frequency::type fType2 = t_lc::toFreq(satData->system(), t_lc::l2);
205 double f1 = t_CST::freq(fType1, 0);
206 double f2 = t_CST::freq(fType2, 0);
207 double a1 = f1 * f1 / (f1 * f1 - f2 * f2);
208 double a2 = - f2 * f2 / (f1 * f1 - f2 * f2);
209 satData->L1 = satData->L1 * t_CST::c / f1;
210 satData->L2 = satData->L2 * t_CST::c / f2;
211 satData->P3 = a1 * satData->P1 + a2 * satData->P2;
212 satData->L3 = a1 * satData->L1 + a2 * satData->L2;
213 satData->lambda3 = a1 * t_CST::c / f1 + a2 * t_CST::c / f2;
214 satData->lkA = a1;
215 satData->lkB = a2;
216 _epoData->satData[satData->prn] = satData;
217 }
218 else {
219 delete satData;
220 }
221 }
222
223 // Set Observations Glonass
224 // ------------------------
225 else if (satData->system() == 'R' && _opt->useSystem('R')) {
226 if (satData->P1 != 0.0 && satData->P2 != 0.0 &&
227 satData->L1 != 0.0 && satData->L2 != 0.0 ) {
228
229 int channel = 0;
230 if (satData->system() == 'R') {
231 const t_eph* eph = _ephUser->ephLast(satData->prn);
232 if (eph) {
233 channel = eph->slotNum();
234 }
235 else {
236 delete satData;
237 return;
238 }
239 }
240
241 t_frequency::type fType1 = t_lc::toFreq(satData->system(), t_lc::l1);
242 t_frequency::type fType2 = t_lc::toFreq(satData->system(), t_lc::l2);
243 double f1 = t_CST::freq(fType1, channel);
244 double f2 = t_CST::freq(fType2, channel);
245 double a1 = f1 * f1 / (f1 * f1 - f2 * f2);
246 double a2 = - f2 * f2 / (f1 * f1 - f2 * f2);
247 satData->L1 = satData->L1 * t_CST::c / f1;
248 satData->L2 = satData->L2 * t_CST::c / f2;
249 satData->P3 = a1 * satData->P1 + a2 * satData->P2;
250 satData->L3 = a1 * satData->L1 + a2 * satData->L2;
251 satData->lambda3 = a1 * t_CST::c / f1 + a2 * t_CST::c / f2;
252 satData->lkA = a1;
253 satData->lkB = a2;
254 _epoData->satData[satData->prn] = satData;
255 }
256 else {
257 delete satData;
258 }
259 }
260
261 // Set Observations Galileo
262 // ------------------------
263 else if (satData->system() == 'E' && _opt->useSystem('E')) {
264 if (satData->P1 != 0.0 && satData->P5 != 0.0 &&
265 satData->L1 != 0.0 && satData->L5 != 0.0 ) {
266 double f1 = t_CST::freq(t_frequency::E1, 0);
267 double f5 = t_CST::freq(t_frequency::E5, 0);
268 double a1 = f1 * f1 / (f1 * f1 - f5 * f5);
269 double a5 = - f5 * f5 / (f1 * f1 - f5 * f5);
270 satData->L1 = satData->L1 * t_CST::c / f1;
271 satData->L5 = satData->L5 * t_CST::c / f5;
272 satData->P3 = a1 * satData->P1 + a5 * satData->P5;
273 satData->L3 = a1 * satData->L1 + a5 * satData->L5;
274 satData->lambda3 = a1 * t_CST::c / f1 + a5 * t_CST::c / f5;
275 satData->lkA = a1;
276 satData->lkB = a5;
277 _epoData->satData[satData->prn] = satData;
278 }
279 else {
280 delete satData;
281 }
282 }
283
284 // Set Observations BDS
285 // ---------------------
286 else if (satData->system() == 'C' && _opt->useSystem('C')) {
287 if (satData->P2 != 0.0 && satData->P6 != 0.0 &&
288 satData->L2 != 0.0 && satData->L6 != 0.0 ) {
289 double f2 = t_CST::freq(t_frequency::C2, 0);
290 double f6 = t_CST::freq(t_frequency::C6, 0);
291 double a2 = f2 * f2 / (f2 * f2 - f6 * f6);
292 double a6 = - f6 * f6 / (f2 * f2 - f6 * f6);
293 satData->L2 = satData->L2 * t_CST::c / f2;
294 satData->L6 = satData->L6 * t_CST::c / f6;
295 satData->P3 = a2 * satData->P2 + a6 * satData->P6;
296 satData->L3 = a2 * satData->L2 + a6 * satData->L6;
297 satData->lambda3 = a2 * t_CST::c / f2 + a6 * t_CST::c / f6;
298 satData->lkA = a2;
299 satData->lkB = a6;
300 _epoData->satData[satData->prn] = satData;
301 }
302 else {
303 delete satData;
304 }
305 }
306 else {
307 delete satData;
308 }
309}
310
311//
312////////////////////////////////////////////////////////////////////////////
313void t_pppClient::putOrbCorrections(const std::vector<t_orbCorr*>& corr) {
314 for (unsigned ii = 0; ii < corr.size(); ii++) {
315 QString prn = QString(corr[ii]->_prn.toInternalString().c_str());
316 t_eph* eLast = _ephUser->ephLast(prn);
317 t_eph* ePrev = _ephUser->ephPrev(prn);
318 if (eLast && eLast->IOD() == corr[ii]->_iod) {
319 eLast->setOrbCorr(corr[ii]);
320 }
321 else if (ePrev && ePrev->IOD() == corr[ii]->_iod) {
322 ePrev->setOrbCorr(corr[ii]);
323 }
324 }
325}
326
327//
328////////////////////////////////////////////////////////////////////////////
329void t_pppClient::putClkCorrections(const std::vector<t_clkCorr*>& corr) {
330 for (unsigned ii = 0; ii < corr.size(); ii++) {
331 QString prn = QString(corr[ii]->_prn.toInternalString().c_str());
332 t_eph* eLast = _ephUser->ephLast(prn);
333 t_eph* ePrev = _ephUser->ephPrev(prn);
334 if (eLast && eLast->IOD() == corr[ii]->_iod) {
335 eLast->setClkCorr(corr[ii]);
336 }
337 else if (ePrev && ePrev->IOD() == corr[ii]->_iod) {
338 ePrev->setClkCorr(corr[ii]);
339 }
340 }
341}
342
343//
344//////////////////////////////////////////////////////////////////////////////
345void t_pppClient::putCodeBiases(const std::vector<t_satCodeBias*>& satCodeBias) {
346 for (unsigned ii = 0; ii < satCodeBias.size(); ii++) {
347 _pppUtils->putCodeBias(new t_satCodeBias(*satCodeBias[ii]));
348 }
349}
350
351//
352//////////////////////////////////////////////////////////////////////////////
353void t_pppClient::putPhaseBiases(const std::vector<t_satPhaseBias*>& /*satPhaseBias*/) {
354}
355
356//
357//////////////////////////////////////////////////////////////////////////////
358void t_pppClient::putTec(const t_vTec* /*vTec*/) {
359}
360
361//
362//////////////////////////////////////////////////////////////////////////////
363void t_pppClient::putEphemeris(const t_eph* eph) {
364 if (_newEph)
365 delete _newEph;
366 _newEph = 0;
367 const t_ephGPS* ephGPS = dynamic_cast<const t_ephGPS*>(eph);
368 const t_ephGlo* ephGlo = dynamic_cast<const t_ephGlo*>(eph);
369 const t_ephGal* ephGal = dynamic_cast<const t_ephGal*>(eph);
370 const t_ephBDS* ephBDS = dynamic_cast<const t_ephBDS*>(eph);
371 if (ephGPS) {
372 _newEph = new t_ephGPS(*ephGPS);
373 }
374 else if (ephGlo) {
375 _newEph = new t_ephGlo(*ephGlo);
376 }
377 else if (ephGal) {
378 _newEph = new t_ephGal(*ephGal);
379 }
380 else if (ephBDS) {
381 _newEph = new t_ephBDS(*ephBDS);
382 }
383
384 if (_newEph) {
385 _ephUser->putNewEph(_newEph, _opt->_realTime);
386 }
387}
388
389// Satellite Position
390////////////////////////////////////////////////////////////////////////////
391t_irc t_pppClient::getSatPos(const bncTime& tt, const QString& prn,
392 ColumnVector& xc, ColumnVector& vv) {
393
394 t_eph* eLast = _ephUser->ephLast(prn);
395 t_eph* ePrev = _ephUser->ephPrev(prn);
396 if (eLast && eLast->getCrd(tt, xc, vv, _opt->useOrbClkCorr()) == success) {
397 return success;
398 }
399 else if (ePrev && ePrev->getCrd(tt, xc, vv, _opt->useOrbClkCorr()) == success) {
400 return success;
401 }
402 return failure;
403}
404
405// Correct Time of Transmission
406////////////////////////////////////////////////////////////////////////////
407t_irc t_pppClient::cmpToT(t_satData* satData) {
408
409 double prange = satData->P3;
410 if (prange == 0.0) {
411 return failure;
412 }
413
414 double clkSat = 0.0;
415 for (int ii = 1; ii <= 10; ii++) {
416
417 bncTime ToT = satData->tt - prange / t_CST::c - clkSat;
418
419 ColumnVector xc(6);
420 ColumnVector vv(3);
421 if (getSatPos(ToT, satData->prn, xc, vv) != success) {
422 return failure;
423 }
424
425 double clkSatOld = clkSat;
426 clkSat = xc(4);
427
428 if ( fabs(clkSat-clkSatOld) * t_CST::c < 1.e-4 ) {
429 satData->xx = xc.Rows(1,3);
430 satData->vv = vv;
431 satData->clk = clkSat * t_CST::c;
432 return success;
433 }
434 }
435
436 return failure;
437}
438
439//
440////////////////////////////////////////////////////////////////////////////
441void t_pppClient::reset() {
442
443 // to delete all parameters
444 delete _filter;
445 _filter = new t_pppFilter(this);
446
447 // to delete old orbit and clock corrections
448 delete _ephUser;
449 _ephUser = new bncEphUser(false);
450
451 // to delete old code biases
452 delete _pppUtils;
453 _pppUtils = new t_pppUtils();
454
455}
Note: See TracBrowser for help on using the repository browser.