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

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