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