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

Last change on this file since 7241 was 7241, checked in by stuerze, 9 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: 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 "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 }
173 else {
174 output->_error = true;
175 }
176
177 output->_log = _log->str();
178 delete _log; _log = new ostringstream();
179}
180
181//
182////////////////////////////////////////////////////////////////////////////
183void t_pppClient::putNewObs(t_satData* satData) {
184
185 // Set Observations GPS
186 // --------------------
187 if (satData->system() == 'G') {
188 if (satData->P1 != 0.0 && satData->P2 != 0.0 &&
189 satData->L1 != 0.0 && satData->L2 != 0.0 ) {
190 t_frequency::type fType1 = t_lc::toFreq(satData->system(), t_lc::l1);
191 t_frequency::type fType2 = t_lc::toFreq(satData->system(), t_lc::l2);
192 double f1 = t_CST::freq(fType1, 0);
193 double f2 = t_CST::freq(fType2, 0);
194 double a1 = f1 * f1 / (f1 * f1 - f2 * f2);
195 double a2 = - f2 * f2 / (f1 * f1 - f2 * f2);
196 satData->L1 = satData->L1 * t_CST::c / f1;
197 satData->L2 = satData->L2 * t_CST::c / f2;
198 satData->P3 = a1 * satData->P1 + a2 * satData->P2;
199 satData->L3 = a1 * satData->L1 + a2 * satData->L2;
200 satData->lambda3 = a1 * t_CST::c / f1 + a2 * t_CST::c / f2;
201 satData->lkA = a1;
202 satData->lkB = a2;
203 _epoData->satData[satData->prn] = satData;
204 }
205 else {
206 delete satData;
207 }
208 }
209
210 // Set Observations Glonass
211 // ------------------------
212 else if (satData->system() == 'R' && _opt->useSystem('R')) {
213 if (satData->P1 != 0.0 && satData->P2 != 0.0 &&
214 satData->L1 != 0.0 && satData->L2 != 0.0 ) {
215
216 int channel = 0;
217 if (satData->system() == 'R') {
218 const t_eph* eph = _ephUser->ephLast(satData->prn);
219 if (eph) {
220 channel = eph->slotNum();
221 }
222 else {
223 delete satData;
224 return;
225 }
226 }
227
228 t_frequency::type fType1 = t_lc::toFreq(satData->system(), t_lc::l1);
229 t_frequency::type fType2 = t_lc::toFreq(satData->system(), t_lc::l2);
230 double f1 = t_CST::freq(fType1, channel);
231 double f2 = t_CST::freq(fType2, channel);
232 double a1 = f1 * f1 / (f1 * f1 - f2 * f2);
233 double a2 = - f2 * f2 / (f1 * f1 - f2 * f2);
234 satData->L1 = satData->L1 * t_CST::c / f1;
235 satData->L2 = satData->L2 * t_CST::c / f2;
236 satData->P3 = a1 * satData->P1 + a2 * satData->P2;
237 satData->L3 = a1 * satData->L1 + a2 * satData->L2;
238 satData->lambda3 = a1 * t_CST::c / f1 + a2 * t_CST::c / f2;
239 satData->lkA = a1;
240 satData->lkB = a2;
241 _epoData->satData[satData->prn] = satData;
242 }
243 else {
244 delete satData;
245 }
246 }
247
248 // Set Observations Galileo
249 // ------------------------
250 else if (satData->system() == 'E' && _opt->useSystem('E')) {
251 if (satData->P1 != 0.0 && satData->P5 != 0.0 &&
252 satData->L1 != 0.0 && satData->L5 != 0.0 ) {
253 double f1 = t_CST::freq(t_frequency::E1, 0);
254 double f5 = t_CST::freq(t_frequency::E5, 0);
255 double a1 = f1 * f1 / (f1 * f1 - f5 * f5);
256 double a5 = - f5 * f5 / (f1 * f1 - f5 * f5);
257 satData->L1 = satData->L1 * t_CST::c / f1;
258 satData->L5 = satData->L5 * t_CST::c / f5;
259 satData->P3 = a1 * satData->P1 + a5 * satData->P5;
260 satData->L3 = a1 * satData->L1 + a5 * satData->L5;
261 satData->lambda3 = a1 * t_CST::c / f1 + a5 * t_CST::c / f5;
262 satData->lkA = a1;
263 satData->lkB = a5;
264 _epoData->satData[satData->prn] = satData;
265 }
266 else {
267 delete satData;
268 }
269 }
270
271 // Set Observations BDS
272 // ---------------------
273 else if (satData->system() == 'C' && _opt->useSystem('C')) {
274 if (satData->P2 != 0.0 && satData->P7 != 0.0 &&
275 satData->L2 != 0.0 && satData->L7 != 0.0 ) {
276 double f2 = t_CST::freq(t_frequency::C2, 0);
277 double f7 = t_CST::freq(t_frequency::C7, 0);
278 double a2 = f2 * f2 / (f2 * f2 - f7 * f7);
279 double a7 = - f7 * f7 / (f2 * f2 - f7 * f7);
280 satData->L2 = satData->L2 * t_CST::c / f2;
281 satData->L7 = satData->L7 * t_CST::c / f7;
282 satData->P3 = a2 * satData->P2 + a7 * satData->P7;
283 satData->L3 = a2 * satData->L2 + a7 * satData->L7;
284 satData->lambda3 = a2 * t_CST::c / f2 + a7 * t_CST::c / f7;
285 satData->lkA = a2;
286 satData->lkB = a7;
287 _epoData->satData[satData->prn] = satData;
288 }
289 else {
290 delete satData;
291 }
292 }
293}
294
295//
296////////////////////////////////////////////////////////////////////////////
297void t_pppClient::putOrbCorrections(const std::vector<t_orbCorr*>& corr) {
298 for (unsigned ii = 0; ii < corr.size(); ii++) {
299 QString prn = QString(corr[ii]->_prn.toInternalString().c_str());
300 t_eph* eLast = _ephUser->ephLast(prn);
301 t_eph* ePrev = _ephUser->ephPrev(prn);
302 if (eLast && eLast->IOD() == corr[ii]->_iod) {
303 eLast->setOrbCorr(corr[ii]);
304 }
305 else if (ePrev && ePrev->IOD() == corr[ii]->_iod) {
306 ePrev->setOrbCorr(corr[ii]);
307 }
308 }
309}
310
311//
312////////////////////////////////////////////////////////////////////////////
313void t_pppClient::putClkCorrections(const std::vector<t_clkCorr*>& 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->setClkCorr(corr[ii]);
320 }
321 else if (ePrev && ePrev->IOD() == corr[ii]->_iod) {
322 ePrev->setClkCorr(corr[ii]);
323 }
324 }
325}
326
327//
328//////////////////////////////////////////////////////////////////////////////
329void t_pppClient::putCodeBiases(const std::vector<t_satCodeBias*>& satCodeBias) {
330 for (unsigned ii = 0; ii < satCodeBias.size(); ii++) {
331 _pppUtils->putCodeBias(new t_satCodeBias(*satCodeBias[ii]));
332 }
333}
334
335//
336//////////////////////////////////////////////////////////////////////////////
337void t_pppClient::putTec(const t_vTec* /*vTec*/) {
338}
339
340//
341//////////////////////////////////////////////////////////////////////////////
342void t_pppClient::putEphemeris(const t_eph* eph) {
343 bool check = _opt->_realTime;
344 const t_ephGPS* ephGPS = dynamic_cast<const t_ephGPS*>(eph);
345 const t_ephGlo* ephGlo = dynamic_cast<const t_ephGlo*>(eph);
346 const t_ephGal* ephGal = dynamic_cast<const t_ephGal*>(eph);
347 const t_ephBDS* ephBDS = dynamic_cast<const t_ephBDS*>(eph);
348 if (ephGPS) {
349 _ephUser->putNewEph(new t_ephGPS(*ephGPS), check);
350 }
351 else if (ephGlo) {
352 _ephUser->putNewEph(new t_ephGlo(*ephGlo), check);
353 }
354 else if (ephGal) {
355 _ephUser->putNewEph(new t_ephGal(*ephGal), check);
356 }
357 else if (ephBDS) {
358 _ephUser->putNewEph(new t_ephBDS(*ephBDS), check);
359 }
360}
361
362// Satellite Position
363////////////////////////////////////////////////////////////////////////////
364t_irc t_pppClient::getSatPos(const bncTime& tt, const QString& prn,
365 ColumnVector& xc, ColumnVector& vv) {
366
367 t_eph* eLast = _ephUser->ephLast(prn);
368 t_eph* ePrev = _ephUser->ephPrev(prn);
369 if (eLast && eLast->getCrd(tt, xc, vv, _opt->useOrbClkCorr()) == success) {
370 return success;
371 }
372 else if (ePrev && ePrev->getCrd(tt, xc, vv, _opt->useOrbClkCorr()) == success) {
373 return success;
374 }
375 return failure;
376}
377
378// Correct Time of Transmission
379////////////////////////////////////////////////////////////////////////////
380t_irc t_pppClient::cmpToT(t_satData* satData) {
381
382 double prange = satData->P3;
383 if (prange == 0.0) {
384 return failure;
385 }
386
387 double clkSat = 0.0;
388 for (int ii = 1; ii <= 10; ii++) {
389
390 bncTime ToT = satData->tt - prange / t_CST::c - clkSat;
391
392 ColumnVector xc(4);
393 ColumnVector vv(3);
394 if (getSatPos(ToT, satData->prn, xc, vv) != success) {
395 return failure;
396 }
397
398 double clkSatOld = clkSat;
399 clkSat = xc(4);
400
401 if ( fabs(clkSat-clkSatOld) * t_CST::c < 1.e-4 ) {
402 satData->xx = xc.Rows(1,3);
403 satData->vv = vv;
404 satData->clk = clkSat * t_CST::c;
405 return success;
406 }
407 }
408
409 return failure;
410}
Note: See TracBrowser for help on using the repository browser.