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

Last change on this file since 7029 was 7029, checked in by stuerze, 9 years ago

code bias usage is added for PPP SSR_I mode

  • Property svn:keywords set to Author Date Id Rev URL;svn:eol-style=native
  • Property svn:mime-type set to text/plain
File size: 13.3 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 "bncephuser.h"
47#include "bncutils.h"
48
49using namespace BNC_PPP;
50using namespace std;
51
52// Constructor
53////////////////////////////////////////////////////////////////////////////
54t_pppClient::t_pppClient(const t_pppOptions* opt) {
55
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
62 for (unsigned ii = 0; ii <= t_prn::MAXPRN; ii++) {
63 _satCodeBiases[ii] = 0;
64 }
65
66}
67
68// Destructor
69////////////////////////////////////////////////////////////////////////////
70t_pppClient::~t_pppClient() {
71
72 for (unsigned ii = 0; ii <= t_prn::MAXPRN; ii++) {
73 delete _satCodeBiases[ii];
74 }
75
76 delete _filter;
77 delete _epoData;
78 delete _opt;
79 delete _ephUser;
80 delete _log;
81}
82
83//
84////////////////////////////////////////////////////////////////////////////
85void t_pppClient::processEpoch(const vector<t_satObs*>& satObs, t_output* output) {
86
87 // Convert and store observations
88 // ------------------------------
89 _epoData->clear();
90 for (unsigned ii = 0; ii < satObs.size(); ii++) {
91 const t_satObs* obs = satObs[ii];
92 t_prn prn = obs->_prn;
93 t_satData* satData = new t_satData();
94
95 if (_epoData->tt.undef()) {
96 _epoData->tt = obs->_time;
97 }
98
99 satData->tt = obs->_time;
100 satData->prn = QString(prn.toInternalString().c_str());
101 satData->slipFlag = false;
102 satData->P1 = 0.0;
103 satData->P2 = 0.0;
104 satData->P5 = 0.0;
105 satData->P7 = 0.0;
106 satData->L1 = 0.0;
107 satData->L2 = 0.0;
108 satData->L5 = 0.0;
109 satData->L7 = 0.0;
110 for (unsigned ifrq = 0; ifrq < obs->_obs.size(); ifrq++) {
111 t_frqObs* frqObs = obs->_obs[ifrq];
112 double cb = 0.0;
113 const t_satCodeBias* satCB = satCodeBias(prn);
114 if (satCB && satCB->_bias.size()) {
115 for (unsigned ii = 0; ii < satCB->_bias.size(); ii++) {
116 const t_frqCodeBias& bias = satCB->_bias[ii];
117 if (frqObs && frqObs->_rnxType2ch == bias._rnxType2ch) {
118 cb = bias._value;
119 }
120 }
121 }
122 if (frqObs->_rnxType2ch[0] == '1') {
123 if (frqObs->_codeValid) satData->P1 = frqObs->_code + cb;
124 if (frqObs->_phaseValid) satData->L1 = frqObs->_phase;
125 if (frqObs->_slip) satData->slipFlag = true;
126 }
127 else if (frqObs->_rnxType2ch[0] == '2') {
128 if (frqObs->_codeValid) satData->P2 = frqObs->_code + cb;
129 if (frqObs->_phaseValid) satData->L2 = frqObs->_phase;
130 if (frqObs->_slip) satData->slipFlag = true;
131 }
132 else if (frqObs->_rnxType2ch[0] == '5') {
133 if (frqObs->_codeValid) satData->P5 = frqObs->_code + cb;
134 if (frqObs->_phaseValid) satData->L5 = frqObs->_phase;
135 if (frqObs->_slip) satData->slipFlag = true;
136 }
137 else if (frqObs->_rnxType2ch[0] == '7') {
138 if (frqObs->_codeValid) satData->P7 = frqObs->_code + cb;
139 if (frqObs->_phaseValid) satData->L7 = frqObs->_phase;
140 if (frqObs->_slip) satData->slipFlag = true;
141 }
142 }
143 putNewObs(satData);
144 }
145
146 // Data Pre-Processing
147 // -------------------
148 QMutableMapIterator<QString, t_satData*> it(_epoData->satData);
149 while (it.hasNext()) {
150 it.next();
151 QString prn = it.key();
152 t_satData* satData = it.value();
153
154 if (cmpToT(satData) != success) {
155 delete satData;
156 it.remove();
157 continue;
158 }
159 }
160
161 // Filter Solution
162 // ---------------
163 if (_filter->update(_epoData) == success) {
164 output->_error = false;
165 output->_epoTime = _filter->time();
166 output->_xyzRover[0] = _filter->x();
167 output->_xyzRover[1] = _filter->y();
168 output->_xyzRover[2] = _filter->z();
169 copy(&_filter->Q().data()[0], &_filter->Q().data()[6], output->_covMatrix);
170 output->_neu[0] = _filter->neu()[0];
171 output->_neu[1] = _filter->neu()[1];
172 output->_neu[2] = _filter->neu()[2];
173 output->_numSat = _filter->numSat();
174 output->_pDop = _filter->PDOP();
175 output->_trp0 = _filter->trp0();
176 output->_trp = _filter->trp();
177 }
178 else {
179 output->_error = true;
180 }
181
182 output->_log = _log->str();
183 delete _log; _log = new ostringstream();
184}
185
186//
187////////////////////////////////////////////////////////////////////////////
188void t_pppClient::putNewObs(t_satData* satData) {
189
190 // Set Observations GPS
191 // --------------------
192 if (satData->system() == 'G') {
193 if (satData->P1 != 0.0 && satData->P2 != 0.0 &&
194 satData->L1 != 0.0 && satData->L2 != 0.0 ) {
195 t_frequency::type fType1 = t_lc::toFreq(satData->system(), t_lc::l1);
196 t_frequency::type fType2 = t_lc::toFreq(satData->system(), t_lc::l2);
197 double f1 = t_CST::freq(fType1, 0);
198 double f2 = t_CST::freq(fType2, 0);
199 double a1 = f1 * f1 / (f1 * f1 - f2 * f2);
200 double a2 = - f2 * f2 / (f1 * f1 - f2 * f2);
201 satData->L1 = satData->L1 * t_CST::c / f1;
202 satData->L2 = satData->L2 * t_CST::c / f2;
203 satData->P3 = a1 * satData->P1 + a2 * satData->P2;
204 satData->L3 = a1 * satData->L1 + a2 * satData->L2;
205 satData->lambda3 = a1 * t_CST::c / f1 + a2 * t_CST::c / f2;
206 satData->lkA = a1;
207 satData->lkB = a2;
208 _epoData->satData[satData->prn] = satData;
209 }
210 else {
211 delete satData;
212 }
213 }
214
215 // Set Observations Glonass
216 // ------------------------
217 else if (satData->system() == 'R' && _opt->useSystem('R')) {
218 if (satData->P1 != 0.0 && satData->P2 != 0.0 &&
219 satData->L1 != 0.0 && satData->L2 != 0.0 ) {
220
221 int channel = 0;
222 if (satData->system() == 'R') {
223 const t_eph* eph = _ephUser->ephLast(satData->prn);
224 if (eph) {
225 channel = eph->slotNum();
226 }
227 else {
228 delete satData;
229 return;
230 }
231 }
232
233 t_frequency::type fType1 = t_lc::toFreq(satData->system(), t_lc::l1);
234 t_frequency::type fType2 = t_lc::toFreq(satData->system(), t_lc::l2);
235 double f1 = t_CST::freq(fType1, channel);
236 double f2 = t_CST::freq(fType2, channel);
237 double a1 = f1 * f1 / (f1 * f1 - f2 * f2);
238 double a2 = - f2 * f2 / (f1 * f1 - f2 * f2);
239 satData->L1 = satData->L1 * t_CST::c / f1;
240 satData->L2 = satData->L2 * t_CST::c / f2;
241 satData->P3 = a1 * satData->P1 + a2 * satData->P2;
242 satData->L3 = a1 * satData->L1 + a2 * satData->L2;
243 satData->lambda3 = a1 * t_CST::c / f1 + a2 * t_CST::c / f2;
244 satData->lkA = a1;
245 satData->lkB = a2;
246 _epoData->satData[satData->prn] = satData;
247 }
248 else {
249 delete satData;
250 }
251 }
252
253 // Set Observations Galileo
254 // ------------------------
255 else if (satData->system() == 'E' && _opt->useSystem('E')) {
256 if (satData->P1 != 0.0 && satData->P5 != 0.0 &&
257 satData->L1 != 0.0 && satData->L5 != 0.0 ) {
258 double f1 = t_CST::freq(t_frequency::E1, 0);
259 double f5 = t_CST::freq(t_frequency::E5, 0);
260 double a1 = f1 * f1 / (f1 * f1 - f5 * f5);
261 double a5 = - f5 * f5 / (f1 * f1 - f5 * f5);
262 satData->L1 = satData->L1 * t_CST::c / f1;
263 satData->L5 = satData->L5 * t_CST::c / f5;
264 satData->P3 = a1 * satData->P1 + a5 * satData->P5;
265 satData->L3 = a1 * satData->L1 + a5 * satData->L5;
266 satData->lambda3 = a1 * t_CST::c / f1 + a5 * t_CST::c / f5;
267 satData->lkA = a1;
268 satData->lkB = a5;
269 _epoData->satData[satData->prn] = satData;
270 }
271 else {
272 delete satData;
273 }
274 }
275
276 // Set Observations BDS
277 // ---------------------
278 else if (satData->system() == 'C' && _opt->useSystem('C')) {
279 if (satData->P2 != 0.0 && satData->P7 != 0.0 &&
280 satData->L2 != 0.0 && satData->L7 != 0.0 ) {
281 double f2 = t_CST::freq(t_frequency::C2, 0);
282 double f7 = t_CST::freq(t_frequency::C7, 0);
283 double a2 = f2 * f2 / (f2 * f2 - f7 * f7);
284 double a7 = - f7 * f7 / (f2 * f2 - f7 * f7);
285 satData->L2 = satData->L2 * t_CST::c / f2;
286 satData->L7 = satData->L7 * t_CST::c / f7;
287 satData->P3 = a2 * satData->P2 + a7 * satData->P7;
288 satData->L3 = a2 * satData->L2 + a7 * satData->L7;
289 satData->lambda3 = a2 * t_CST::c / f2 + a7 * t_CST::c / f7;
290 satData->lkA = a2;
291 satData->lkB = a7;
292 _epoData->satData[satData->prn] = satData;
293 }
294 else {
295 delete satData;
296 }
297 }
298}
299
300//
301////////////////////////////////////////////////////////////////////////////
302void t_pppClient::putOrbCorrections(const std::vector<t_orbCorr*>& corr) {
303 for (unsigned ii = 0; ii < corr.size(); ii++) {
304 QString prn = QString(corr[ii]->_prn.toInternalString().c_str());
305 t_eph* eLast = _ephUser->ephLast(prn);
306 t_eph* ePrev = _ephUser->ephPrev(prn);
307 if (eLast && eLast->IOD() == corr[ii]->_iod) {
308 eLast->setOrbCorr(corr[ii]);
309 }
310 else if (ePrev && ePrev->IOD() == corr[ii]->_iod) {
311 ePrev->setOrbCorr(corr[ii]);
312 }
313 }
314}
315
316//
317////////////////////////////////////////////////////////////////////////////
318void t_pppClient::putClkCorrections(const std::vector<t_clkCorr*>& corr) {
319 for (unsigned ii = 0; ii < corr.size(); ii++) {
320 QString prn = QString(corr[ii]->_prn.toInternalString().c_str());
321 t_eph* eLast = _ephUser->ephLast(prn);
322 t_eph* ePrev = _ephUser->ephPrev(prn);
323 if (eLast && eLast->IOD() == corr[ii]->_iod) {
324 eLast->setClkCorr(corr[ii]);
325 }
326 else if (ePrev && ePrev->IOD() == corr[ii]->_iod) {
327 ePrev->setClkCorr(corr[ii]);
328 }
329 }
330}
331
332//
333//////////////////////////////////////////////////////////////////////////////
334void t_pppClient::putCodeBiases(const std::vector<t_satCodeBias*>& satCodeBias) {
335 for (unsigned ii = 0; ii < satCodeBias.size(); ii++) {
336 putCodeBias(new t_satCodeBias(*satCodeBias[ii]));
337 }
338}
339
340//
341//////////////////////////////////////////////////////////////////////////////
342void t_pppClient::putEphemeris(const t_eph* eph) {
343 const t_ephGPS* ephGPS = dynamic_cast<const t_ephGPS*>(eph);
344 const t_ephGlo* ephGlo = dynamic_cast<const t_ephGlo*>(eph);
345 const t_ephGal* ephGal = dynamic_cast<const t_ephGal*>(eph);
346 const t_ephBDS* ephBDS = dynamic_cast<const t_ephBDS*>(eph);
347 if (ephGPS) {
348 _ephUser->putNewEph(new t_ephGPS(*ephGPS), true);
349 }
350 else if (ephGlo) {
351 _ephUser->putNewEph(new t_ephGlo(*ephGlo), true);
352 }
353 else if (ephGal) {
354 _ephUser->putNewEph(new t_ephGal(*ephGal), true);
355 }
356 else if (ephBDS) {
357 _ephUser->putNewEph(new t_ephBDS(*ephBDS), true);
358 }
359}
360
361// Satellite Position
362////////////////////////////////////////////////////////////////////////////
363t_irc t_pppClient::getSatPos(const bncTime& tt, const QString& prn,
364 ColumnVector& xc, ColumnVector& vv) {
365
366 t_eph* eLast = _ephUser->ephLast(prn);
367 t_eph* ePrev = _ephUser->ephPrev(prn);
368 if (eLast && eLast->getCrd(tt, xc, vv, _opt->useOrbClkCorr()) == success) {
369 return success;
370 }
371 else if (ePrev && ePrev->getCrd(tt, xc, vv, _opt->useOrbClkCorr()) == success) {
372 return success;
373 }
374 return failure;
375}
376
377// Correct Time of Transmission
378////////////////////////////////////////////////////////////////////////////
379t_irc t_pppClient::cmpToT(t_satData* satData) {
380
381 double prange = satData->P3;
382 if (prange == 0.0) {
383 return failure;
384 }
385
386 double clkSat = 0.0;
387 for (int ii = 1; ii <= 10; ii++) {
388
389 bncTime ToT = satData->tt - prange / t_CST::c - clkSat;
390
391 ColumnVector xc(4);
392 ColumnVector vv(3);
393 if (getSatPos(ToT, satData->prn, xc, vv) != success) {
394 return failure;
395 }
396
397 double clkSatOld = clkSat;
398 clkSat = xc(4);
399
400 if ( fabs(clkSat-clkSatOld) * t_CST::c < 1.e-4 ) {
401 satData->xx = xc.Rows(1,3);
402 satData->vv = vv;
403 satData->clk = clkSat * t_CST::c;
404 return success;
405 }
406 }
407
408 return failure;
409}
410
411void t_pppClient::putCodeBias(t_satCodeBias* satCodeBias) {
412 int iPrn = satCodeBias->_prn.toInt();
413 delete _satCodeBiases[iPrn];
414 _satCodeBiases[iPrn] = satCodeBias;
415}
Note: See TracBrowser for help on using the repository browser.