source: ntrip/trunk/BNC/src/PPP_free/bncpppclient.cpp@ 6077

Last change on this file since 6077 was 6077, checked in by mervart, 8 years ago
File size: 10.7 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: bncPPPclient
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 "bncpppclient.h"
46#include "bnccore.h"
47#include "bncutils.h"
48#include "bncconst.h"
49#include "bncmodel.h"
50#include "pppOptions.h"
51#include "pppClient.h"
52
53using namespace BNC_PPP;
54using namespace std;
55
56// Constructor
57////////////////////////////////////////////////////////////////////////////
58bncPPPclient::bncPPPclient(QByteArray staID, const t_pppOptions* opt) : bncEphUser(false) {
59
60 _opt = opt;
61 _staID = staID;
62 _model = new bncModel(this);
63 _epoData = new t_epoData();
64}
65
66// Destructor
67////////////////////////////////////////////////////////////////////////////
68bncPPPclient::~bncPPPclient() {
69 _epoData->clear();
70
71 QMapIterator<QString, t_corr*> ic(_corr);
72 while (ic.hasNext()) {
73 ic.next();
74 delete ic.value();
75 }
76
77 QMapIterator<QString, t_bias*> ib(_bias);
78 while (ib.hasNext()) {
79 ib.next();
80 delete ib.value();
81 }
82
83 delete _model;
84}
85
86//
87////////////////////////////////////////////////////////////////////////////
88void bncPPPclient::processEpoch(const vector<t_satObs*>& satObs, t_output* output) {
89 QMutexLocker locker(&_mutex);
90
91 // Convert and store observations
92 // ------------------------------
93 _epoData->clear();
94 for (unsigned ii = 0; ii < satObs.size(); ii++) {
95 const t_satObs* obs = satObs[ii];
96 t_satData* satData = new t_satData();
97 satData->tt = obs->_time;
98 satData->prn = QString(obs->_prn.toString().c_str());
99 satData->slipFlag = false;
100 satData->P1 = 0.0;
101 satData->P2 = 0.0;
102 satData->P5 = 0.0;
103 satData->L1 = 0.0;
104 satData->L2 = 0.0;
105 satData->L5 = 0.0;
106 for (unsigned ifrq = 0; ifrq < obs->_obs.size(); ifrq++) {
107 t_frqObs* frqObs = obs->_obs[ifrq];
108 if (frqObs->_rnxType2ch[0] == '1') {
109 if (frqObs->_codeValid) satData->P1 = frqObs->_code;
110 if (frqObs->_phaseValid) satData->L1 = frqObs->_phase;
111 if (frqObs->_slip) satData->slipFlag = true;
112 }
113 else if (frqObs->_rnxType2ch[0] == '2') {
114 if (frqObs->_codeValid) satData->P2 = frqObs->_code;
115 if (frqObs->_phaseValid) satData->L2 = frqObs->_phase;
116 if (frqObs->_slip) satData->slipFlag = true;
117 }
118 else if (frqObs->_rnxType2ch[0] == '5') {
119 if (frqObs->_codeValid) satData->P5 = frqObs->_code;
120 if (frqObs->_phaseValid) satData->L5 = frqObs->_phase;
121 if (frqObs->_slip) satData->slipFlag = true;
122 }
123 }
124 putNewObs(satData);
125 }
126
127 // Data Pre-Processing
128 // -------------------
129 QMutableMapIterator<QString, t_satData*> it(_epoData->satData);
130 while (it.hasNext()) {
131 it.next();
132 QString prn = it.key();
133 t_satData* satData = it.value();
134
135 if (cmpToT(satData) != success) {
136 delete satData;
137 it.remove();
138 continue;
139 }
140 }
141
142 // Filter Solution
143 // ---------------
144 if (_model->update(_epoData) == success) {
145 output->_error = false;
146 output->_epoTime = _model->time();
147 output->_xyzRover[0] = _model->x();
148 output->_xyzRover[1] = _model->y();
149 output->_xyzRover[2] = _model->z();
150 output->_numSat = 0;
151 output->_pDop = 0.0;
152 }
153 else {
154 output->_error = true;
155 }
156
157 output->_log = LOG.str();
158}
159
160//
161////////////////////////////////////////////////////////////////////////////
162void bncPPPclient::putNewObs(t_satData* satData) {
163
164 // Set Observations GPS and Glonass
165 // --------------------------------
166 if (satData->system() == 'G' || satData->system() == 'R') {
167 if (satData->P1 != 0.0 && satData->P2 != 0.0 &&
168 satData->L1 != 0.0 && satData->L2 != 0.0 ) {
169
170 int channel = 0;
171 if (satData->system() == 'R') {
172// cerr << "not yet implemented" << endl;
173// exit(0);
174 }
175
176 t_frequency::type fType1 = t_lc::toFreq(satData->system(), t_lc::l1);
177 t_frequency::type fType2 = t_lc::toFreq(satData->system(), t_lc::l2);
178 double f1 = t_CST::freq(fType1, channel);
179 double f2 = t_CST::freq(fType2, channel);
180 double a1 = f1 * f1 / (f1 * f1 - f2 * f2);
181 double a2 = - f2 * f2 / (f1 * f1 - f2 * f2);
182 satData->P3 = a1 * satData->P1 + a2 * satData->P2;
183 satData->L3 = a1 * satData->L1 + a2 * satData->L2;
184 satData->lambda3 = a1 * t_CST::c / f1 + a2 * t_CST::c / f2;
185 _epoData->satData[satData->prn] = satData;
186 }
187 else {
188 delete satData;
189 }
190 }
191
192 // Set Observations Galileo
193 // ------------------------
194 else if (satData->system() == 'E') {
195 if (satData->P1 != 0.0 && satData->P5 != 0.0 &&
196 satData->L1 != 0.0 && satData->L5 != 0.0 ) {
197 double f1 = t_CST::freq(t_frequency::E1, 0);
198 double f5 = t_CST::freq(t_frequency::E5, 0);
199 double a1 = f1 * f1 / (f1 * f1 - f5 * f5);
200 double a5 = - f5 * f5 / (f1 * f1 - f5 * f5);
201 satData->P3 = a1 * satData->P1 + a5 * satData->P5;
202 satData->L3 = a1 * satData->L1 + a5 * satData->L5;
203 satData->lambda3 = a1 * t_CST::c / f1 + a5 * t_CST::c / f5;
204 _epoData->satData[satData->prn] = satData;
205 }
206 else {
207 delete satData;
208 }
209 }
210}
211
212//
213////////////////////////////////////////////////////////////////////////////
214void bncPPPclient::putNewCorrections(QList<QString> corrList) {
215 QMutexLocker locker(&_mutex);
216
217 // Check the Mountpoint (source of corrections)
218 // --------------------------------------------
219 if (!_opt->_corrMount.empty()) {
220 QMutableListIterator<QString> itm(corrList);
221 while (itm.hasNext()) {
222 QStringList hlp = itm.next().split(" ");
223 if (hlp.size() > 0) {
224 QString mountpoint = hlp[hlp.size()-1];
225 if (mountpoint != QString(_opt->_corrMount.c_str())) {
226 itm.remove();
227 }
228 }
229 }
230 }
231
232 if (corrList.size() == 0) {
233 return;
234 }
235
236 QListIterator<QString> it(corrList);
237 while (it.hasNext()) {
238 QString line = it.next();
239
240 QTextStream in(&line);
241 int messageType;
242 int updateInterval;
243 int GPSweek;
244 double GPSweeks;
245 QString prn;
246 in >> messageType >> updateInterval >> GPSweek >> GPSweeks >> prn;
247
248 if ( t_corr::relevantMessageType(messageType) ) {
249 t_corr* cc = 0;
250 if (_corr.contains(prn)) {
251 cc = _corr.value(prn);
252 }
253 else {
254 cc = new t_corr();
255 _corr[prn] = cc;
256 }
257 cc->readLine(line);
258 _corr_tt = cc->tClk;
259 }
260 else if ( messageType == BTYPE_GPS || messageType == BTYPE_GLONASS ) {
261 t_bias* bb = 0;
262 if (_bias.contains(prn)) {
263 bb = _bias.value(prn);
264 }
265 else {
266 bb = new t_bias();
267 _bias[prn] = bb;
268 }
269 bb->readLine(line);
270 }
271 }
272}
273
274// Satellite Position
275////////////////////////////////////////////////////////////////////////////
276t_irc bncPPPclient::getSatPos(const bncTime& tt, const QString& prn,
277 ColumnVector& xc, ColumnVector& vv) {
278
279 const double MAXAGE = 120.0;
280
281 if (_eph.contains(prn)) {
282
283 if (_opt->useOrbClkCorr() && prn[0] != 'E') {
284 if (_corr.contains(prn)) {
285 t_corr* cc = _corr.value(prn);
286 if (cc->ready() && tt - cc->tClk < MAXAGE) {
287 t_eph* eLast = _eph.value(prn)->last;
288 t_eph* ePrev = _eph.value(prn)->prev;
289 if (eLast && eLast->IOD() == cc->iod) {
290 eLast->position(tt.gpsw(), tt.gpssec(), xc.data(), vv.data());
291 return applyCorr(tt, cc, xc, vv);
292 }
293 else if (ePrev && ePrev->IOD() == cc->iod) {
294 ePrev->position(tt.gpsw(), tt.gpssec(), xc.data(), vv.data());
295 return applyCorr(tt, cc, xc, vv);
296 }
297 }
298 }
299 }
300
301 else {
302 t_eph* ee = _eph.value(prn)->last;
303 ee->position(tt.gpsw(), tt.gpssec(), xc.data(), vv.data());
304 return success;
305 }
306 }
307
308 return failure;
309}
310
311//
312////////////////////////////////////////////////////////////////////////////
313t_irc bncPPPclient::applyCorr(const bncTime& tt, const t_corr* cc,
314 ColumnVector& xc, ColumnVector& vv) {
315
316 double dtRao = tt - cc->tRao;
317
318 // Position
319 // --------
320 ColumnVector raoHlp = cc->rao + cc->dotRao * dtRao;
321
322 if (raoHlp.norm_Frobenius() > 20.0) {
323 return failure;
324 }
325
326 ColumnVector dx(3);
327 RSW_to_XYZ(xc.Rows(1,3), vv, raoHlp, dx);
328 xc[0] -= dx[0];
329 xc[1] -= dx[1];
330 xc[2] -= dx[2];
331
332 // Velocity
333 // --------
334 ColumnVector dotRaoHlp = cc->dotRao;
335
336 ColumnVector dv(3);
337 RSW_to_XYZ(xc.Rows(1,3), vv, dotRaoHlp, dv);
338 vv[0] -= dv[0];
339 vv[1] -= dv[1];
340 vv[2] -= dv[2];
341
342 // Clocks
343 // ------
344 double dtClk = tt - cc->tClk;
345
346 xc[3] += cc->dClk + cc->dotDClk * dtClk + cc->dotDotDClk * dtClk * dtClk
347 + cc->hrClk;
348
349 return success;
350}
351
352// Correct Time of Transmission
353////////////////////////////////////////////////////////////////////////////
354t_irc bncPPPclient::cmpToT(t_satData* satData) {
355
356 double prange = satData->P3;
357 if (prange == 0.0) {
358 return failure;
359 }
360
361 double clkSat = 0.0;
362 for (int ii = 1; ii <= 10; ii++) {
363
364 bncTime ToT = satData->tt - prange / t_CST::c - clkSat;
365
366 ColumnVector xc(4);
367 ColumnVector vv(3);
368 if (getSatPos(ToT, satData->prn, xc, vv) != success) {
369 return failure;
370 }
371
372 double clkSatOld = clkSat;
373 clkSat = xc(4);
374
375 if ( fabs(clkSat-clkSatOld) * t_CST::c < 1.e-4 ) {
376 satData->xx = xc.Rows(1,3);
377 satData->vv = vv;
378 satData->clk = clkSat * t_CST::c;
379 return success;
380 }
381 }
382
383 return failure;
384}
385
Note: See TracBrowser for help on using the repository browser.