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

Last change on this file since 7572 was 7572, checked in by stuerze, 8 years ago

mionor additions regarding tropo sinex output

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