source: ntrip/trunk/BNC/src/PPP/pppClient.cpp@ 10002

Last change on this file since 10002 was 10002, checked in by stuerze, 14 months 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: 25.5 KB
Line 
1/* -------------------------------------------------------------------------
2 * BKG NTRIP Client
3 * -------------------------------------------------------------------------
4 *
5 * Class: t_pppClient
6 *
7 * Purpose: PPP Client processing starts here
8 *
9 * Author: L. Mervart
10 *
11 * Created: 29-Jul-2014
12 *
13 * Changes:
14 *
15 * -----------------------------------------------------------------------*/
16
17#include <QThreadStorage>
18
19#include <iostream>
20#include <iomanip>
21#include <cmath>
22#include <string.h>
23#include <stdexcept>
24
25#include "pppClient.h"
26#include "pppEphPool.h"
27#include "pppObsPool.h"
28#include "bncconst.h"
29#include "bncutils.h"
30#include "pppStation.h"
31#include "bncantex.h"
32#include "pppFilter.h"
33
34using namespace BNC_PPP;
35using namespace std;
36
37// Global variable holding thread-specific pointers
38//////////////////////////////////////////////////////////////////////////////
39QThreadStorage<t_pppClient*> CLIENTS;
40
41// Static function returning thread-specific pointer
42//////////////////////////////////////////////////////////////////////////////
43t_pppClient* t_pppClient::instance() {
44 return CLIENTS.localData();
45}
46
47// Constructor
48//////////////////////////////////////////////////////////////////////////////
49t_pppClient::t_pppClient(const t_pppOptions* opt) {
50 _output = 0;
51 _opt = new t_pppOptions(*opt);
52 _log = new ostringstream();
53 _ephPool = new t_pppEphPool();
54 _obsPool = new t_pppObsPool();
55 _staRover = new t_pppStation();
56 _filter = new t_pppFilter(_obsPool);
57 _tides = new t_tides();
58 _antex = 0;
59 if (!_opt->_antexFileName.empty()) {
60 _antex = new bncAntex(_opt->_antexFileName.c_str());
61 }
62 if (!_opt->_blqFileName.empty()) {
63 if (_tides->readBlqFile(_opt->_blqFileName.c_str()) == success) {
64 //_tides->printAllBlqSets();
65 }
66 }
67
68 if (_opt->_refSatRequired) {
69 for (unsigned iSys = 0; iSys < _opt->systems().size(); iSys++) {
70 char sys = _opt->systems()[iSys];
71 _refSatMap[sys] = new t_pppRefSat();
72 }
73 }
74
75 _offGG = 0.0;
76 CLIENTS.setLocalData(this); // CLIENTS takes ownership over "this"
77}
78
79// Destructor
80//////////////////////////////////////////////////////////////////////////////
81t_pppClient::~t_pppClient() {
82 delete _log;
83 delete _opt;
84 delete _filter;
85 delete _ephPool;
86 delete _obsPool;
87 delete _staRover;
88 if (_antex) {
89 delete _antex;
90 }
91 delete _tides;
92 clearObs();
93 QMapIterator<char, t_pppRefSat*> it(_refSatMap);
94 while (it.hasNext()) {
95 it.next();
96 delete it.value();
97 }
98 _refSatMap.clear();
99}
100
101//
102//////////////////////////////////////////////////////////////////////////////
103void t_pppClient::putEphemeris(const t_eph* eph) {
104 const t_ephGPS* ephGPS = dynamic_cast<const t_ephGPS*>(eph);
105 const t_ephGlo* ephGlo = dynamic_cast<const t_ephGlo*>(eph);
106 const t_ephGal* ephGal = dynamic_cast<const t_ephGal*>(eph);
107 const t_ephBDS* ephBDS = dynamic_cast<const t_ephBDS*>(eph);
108 if (ephGPS) {
109 _ephPool->putEphemeris(new t_ephGPS(*ephGPS));
110 }
111 else if (ephGlo) {
112 _ephPool->putEphemeris(new t_ephGlo(*ephGlo));
113 }
114 else if (ephGal) {
115 _ephPool->putEphemeris(new t_ephGal(*ephGal));
116 }
117 else if (ephBDS) {
118 _ephPool->putEphemeris(new t_ephBDS(*ephBDS));
119 }
120}
121
122//
123//////////////////////////////////////////////////////////////////////////////
124void t_pppClient::putTec(const t_vTec* vTec) {
125 _obsPool->putTec(new t_vTec(*vTec));
126}
127
128//
129//////////////////////////////////////////////////////////////////////////////
130void t_pppClient::putOrbCorrections(const vector<t_orbCorr*>& corr) {
131 for (unsigned ii = 0; ii < corr.size(); ii++) {
132 _ephPool->putOrbCorrection(new t_orbCorr(*corr[ii]));
133 }
134}
135
136//
137//////////////////////////////////////////////////////////////////////////////
138void t_pppClient::putClkCorrections(const vector<t_clkCorr*>& corr) {
139 for (unsigned ii = 0; ii < corr.size(); ii++) {
140 _ephPool->putClkCorrection(new t_clkCorr(*corr[ii]));
141 }
142}
143
144//
145//////////////////////////////////////////////////////////////////////////////
146void t_pppClient::putCodeBiases(const vector<t_satCodeBias*>& biases) {
147 for (unsigned ii = 0; ii < biases.size(); ii++) {
148 _obsPool->putCodeBias(new t_satCodeBias(*biases[ii]));
149 }
150}
151
152//
153//////////////////////////////////////////////////////////////////////////////
154void t_pppClient::putPhaseBiases(const vector<t_satPhaseBias*>& biases) {
155 for (unsigned ii = 0; ii < biases.size(); ii++) {
156 _obsPool->putPhaseBias(new t_satPhaseBias(*biases[ii]));
157 }
158}
159
160//
161//////////////////////////////////////////////////////////////////////////////
162t_irc t_pppClient::prepareObs(const vector<t_satObs*>& satObs,
163 vector<t_pppSatObs*>& obsVector, bncTime& epoTime) {
164
165 // Default
166 // -------
167 epoTime.reset();
168 clearObs();
169
170 // Create vector of valid observations
171 // -----------------------------------
172 for (unsigned ii = 0; ii < satObs.size(); ii++) {
173 char sys = satObs[ii]->_prn.system();
174 if (_opt->useSystem(sys)) {
175 t_pppSatObs* pppSatObs = new t_pppSatObs(*satObs[ii]);
176 if (pppSatObs->isValid()) {
177 obsVector.push_back(pppSatObs);
178 }
179 else {
180 delete pppSatObs;
181 }
182 }
183 }
184
185 // Check whether data are synchronized, compute epoTime
186 // ----------------------------------------------------
187 const double MAXSYNC = 0.05; // synchronization limit
188 double meanDt = 0.0;
189 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
190 const t_pppSatObs* satObs = obsVector.at(ii);
191 if (epoTime.undef()) {
192 epoTime = satObs->time();
193 }
194 else {
195 double dt = satObs->time() - epoTime;
196 if (fabs(dt) > MAXSYNC) {
197 LOG << "t_pppClient::prepareObs asynchronous observations" << endl;
198 return failure;
199 }
200 meanDt += dt;
201 }
202 }
203
204 if (obsVector.size() > 0) {
205 epoTime += meanDt / obsVector.size();
206 }
207
208 return success;
209}
210
211//
212//////////////////////////////////////////////////////////////////////////////
213bool t_pppClient::preparePseudoObs(std::vector<t_pppSatObs*>& obsVector) {
214
215 bool pseudoObsIono = false;
216
217 if (_opt->_pseudoObsIono) {
218 vector<t_pppSatObs*>::iterator it = obsVector.begin();
219 while (it != obsVector.end()) {
220 t_pppSatObs* satObs = *it;
221 char sys = satObs->prn().system();
222 t_pppRefSat* refSat = _refSatMap[sys];
223 double stecRef = refSat->stecValue();
224 if (stecRef && !satObs->isReference()) {
225 pseudoObsIono = true;
226 satObs->setPseudoObsIono(t_frequency::G1, stecRef);
227 }
228 it++;
229 }
230 }
231
232/*
233 vector<t_pppSatObs*>::iterator it = obsVector.begin();
234 while (it != obsVector.end()) {
235 t_pppSatObs* satObs = *it;
236 satObs->printObsMinusComputed();
237 it++;
238 }
239*/
240 return pseudoObsIono;
241}
242
243//
244//////////////////////////////////////////////////////////////////////////////
245void t_pppClient::useObsWithCodeBiasesOnly(std::vector<t_pppSatObs*>& obsVector) {
246
247 vector<t_pppSatObs*>::iterator it = obsVector.begin();
248 while (it != obsVector.end()) {
249 t_pppSatObs* pppSatObs = *it;
250 char sys = pppSatObs->prn().system();
251 bool codeBiasesAvailable = false;
252 t_frequency::type fType1 = t_lc::toFreq(sys,t_lc::c1);
253 t_frequency::type fType2 = t_lc::toFreq(sys,t_lc::c2);
254 if (pppSatObs->getCodeBias(fType1) &&
255 pppSatObs->getCodeBias(fType2)) {
256 codeBiasesAvailable = true;
257 }
258 if (codeBiasesAvailable) {
259 ++it;
260 }
261 else {
262 it = obsVector.erase(it);
263 delete pppSatObs;
264 }
265 }
266
267}
268
269
270// Compute the Bancroft position, check for blunders
271//////////////////////////////////////////////////////////////////////////////
272t_irc t_pppClient::cmpBancroft(const bncTime& epoTime,
273 vector<t_pppSatObs*>& obsVector,
274 ColumnVector& xyzc, bool print) {
275
276 t_lc::type tLC = t_lc::dummy;
277
278 while (true) {
279 Matrix BB(obsVector.size(), 4);
280 int iObs = -1;
281 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
282 const t_pppSatObs* satObs = obsVector.at(ii);
283 if (tLC == t_lc::dummy) {
284 if (satObs->isValid(t_lc::cIF)) {
285 tLC = t_lc::cIF;
286 }
287 else if (satObs->isValid(t_lc::c1)) {
288 tLC = t_lc::c1;
289 }
290 else if (satObs->isValid(t_lc::c2)) {
291 tLC = t_lc::c2;
292 }
293 }
294 if ( satObs->isValid(tLC) &&
295 (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
296 ++iObs;
297 BB[iObs][0] = satObs->xc()[0];
298 BB[iObs][1] = satObs->xc()[1];
299 BB[iObs][2] = satObs->xc()[2];
300 BB[iObs][3] = satObs->obsValue(tLC) - satObs->cmpValueForBanc(tLC);
301 }
302 }
303 if (iObs + 1 < _opt->_minObs) {
304 LOG << "t_pppClient::cmpBancroft not enough observations: " << iObs + 1 << endl;
305 return failure;
306 }
307 BB = BB.Rows(1,iObs+1);
308 if (bancroft(BB, xyzc) != success) {
309 return failure;
310 }
311
312 xyzc[3] /= t_CST::c;
313
314 // Check Blunders
315 // --------------
316 const double BLUNDER = 100.0;
317 double maxRes = 0.0;
318 unsigned maxResIndex = 0;
319 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
320 const t_pppSatObs* satObs = obsVector.at(ii);
321 if (satObs->isValid() &&
322 (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
323 ColumnVector rr = satObs->xc().Rows(1,3) - xyzc.Rows(1,3);
324 double res = rr.NormFrobenius() - satObs->obsValue(tLC)
325 - (satObs->xc()[3] - xyzc[3]) * t_CST::c;
326 if (fabs(res) > maxRes) {
327 maxRes = fabs(res);
328 maxResIndex = ii;
329 }
330 }
331 }
332 if (maxRes < BLUNDER) {
333 if (print && _numEpoProcessing == 1) {
334 LOG.setf(ios::fixed);
335 LOG << "\nPPP of Epoch ";
336 if (!_epoTimeRover.undef()) LOG << string(_epoTimeRover);
337 LOG << "\n---------------------------------------------------------------\n";
338 LOG << string(epoTime) << " BANCROFT:" << ' '
339 << setw(14) << setprecision(3) << xyzc[0] << ' '
340 << setw(14) << setprecision(3) << xyzc[1] << ' '
341 << setw(14) << setprecision(3) << xyzc[2] << ' '
342 << setw(14) << setprecision(3) << xyzc[3] * t_CST::c << endl << endl;
343 }
344 break;
345 }
346 else {
347 t_pppSatObs* satObs = obsVector.at(maxResIndex);
348 LOG << "t_pppClient::cmpBancroft outlier " << satObs->prn().toString()
349 << " " << maxRes << endl;
350 delete satObs;
351 obsVector.erase(obsVector.begin() + maxResIndex);
352 }
353 }
354
355 return success;
356}
357// Compute A Priori GPS-Glonass Offset
358//////////////////////////////////////////////////////////////////////////////
359double t_pppClient::cmpOffGG(vector<t_pppSatObs*>& obsVector) {
360
361 t_lc::type tLC = t_lc::dummy;
362 double offGG = 0.0;
363
364 if (OPT->useSystem('R')) {
365
366 while (obsVector.size() > 0) {
367 offGG = 0.0;
368 double maxRes = 0.0;
369 int maxResIndex = -1;
370 t_prn maxResPrn;
371 unsigned nObs = 0;
372 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
373 t_pppSatObs* satObs = obsVector.at(ii);
374 if (satObs->prn().system() == 'R') {
375 if (tLC == t_lc::dummy) {
376 tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
377 }
378 if (satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= OPT->_minEle)) {
379 double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
380 ++nObs;
381 offGG += ll;
382 if (fabs(ll) > fabs(maxRes)) {
383 maxRes = ll;
384 maxResIndex = ii;
385 maxResPrn = satObs->prn();
386 }
387 }
388 }
389 }
390
391 if (nObs > 0) {
392 offGG = offGG / nObs;
393 }
394 else {
395 offGG = 0.0;
396 }
397
398 if (fabs(maxRes) > 1000.0) {
399 LOG << "t_pppClient::cmpOffGG outlier " << maxResPrn.toString() << " " << maxRes << endl;
400 obsVector.erase(obsVector.begin() + maxResIndex);
401 }
402 else {
403 break;
404 }
405 }
406 }
407
408 return offGG;
409}
410
411//
412//////////////////////////////////////////////////////////////////////////////
413void t_pppClient::initOutput(t_output* output) {
414 _output = output;
415 _output->_numSat = 0;
416 _output->_hDop = 0.0;
417 _output->_error = false;
418}
419
420//
421//////////////////////////////////////////////////////////////////////////////
422void t_pppClient::clearObs() {
423 for (unsigned ii = 0; ii < _obsRover.size(); ii++) {
424 delete _obsRover.at(ii);
425 }
426 _obsRover.clear();
427}
428
429//
430//////////////////////////////////////////////////////////////////////////////
431void t_pppClient::finish(t_irc irc, int ind) {
432#ifdef BNC_DEBUG_PPP
433 LOG << "t_pppClient::finish(" << ind << "): " << irc << endl;
434#endif
435
436 clearObs();
437
438 _output->_epoTime = _epoTimeRover;
439
440 if (irc == success) {
441 _output->_xyzRover[0] = _staRover->xyzApr()[0] + _filter->x()[0];
442 _output->_xyzRover[1] = _staRover->xyzApr()[1] + _filter->x()[1];
443 _output->_xyzRover[2] = _staRover->xyzApr()[2] + _filter->x()[2];
444
445 xyz2neu(_staRover->ellApr().data(), _filter->x().data(), _output->_neu);
446
447 copy(&_filter->Q().data()[0], &_filter->Q().data()[6], _output->_covMatrix);
448
449 _output->_trp0 = t_tropo::delay_saast(_staRover->xyzApr(), M_PI/2.0);
450 _output->_trp = _filter->trp();
451 _output->_trpStdev = _filter->trpStdev();
452
453 _output->_numSat = _filter->numSat();
454 _output->_hDop = _filter->HDOP();
455 _output->_error = false;
456 }
457 else {
458 _output->_error = true;
459 if (OPT->_obsModelType == OPT->DCMcodeBias ||
460 OPT->_obsModelType == OPT->DCMphaseBias) {
461 if (ind == 1 || ind > 7) {
462 reset();
463 }
464 }
465 }
466 _output->_log = _log->str();
467 delete _log; _log = new ostringstream();
468
469 return;
470}
471
472//
473//////////////////////////////////////////////////////////////////////////////
474t_irc t_pppClient::cmpModel(t_pppStation* station, const ColumnVector& xyzc,
475 vector<t_pppSatObs*>& obsVector) {
476 bncTime time;
477 time = _epoTimeRover;
478 station->setName(_opt->_roverName);
479 station->setAntName(_opt->_antNameRover);
480 station->setEpochTime(time);
481 if (_opt->xyzAprRoverSet()) {
482 station->setXyzApr(_opt->_xyzAprRover);
483 }
484 else {
485 station->setXyzApr(xyzc.Rows(1,3));
486 }
487 station->setNeuEcc(_opt->_neuEccRover);
488
489 // Receiver Clock
490 // --------------
491 station->setDClk(xyzc[3]);
492
493 // Tides
494 // -----
495 station->setTideDsplEarth(_tides->earth(time, station->xyzApr()));
496 station->setTideDsplOcean(_tides->ocean(time, station->xyzApr(), station->name()));
497
498 // Observation model
499 // -----------------
500 vector<t_pppSatObs*>::iterator it = obsVector.begin();
501 while (it != obsVector.end()) {
502 t_pppSatObs* satObs = *it;
503 t_irc modelSetup;
504 if (satObs->isValid()) {
505 modelSetup = satObs->cmpModel(station);
506 }
507 if (satObs->isValid() &&
508 satObs->eleSat() >= _opt->_minEle &&
509 modelSetup == success) {
510 ++it;
511 }
512 else {
513 delete satObs;
514 it = obsVector.erase(it);
515 }
516 }
517
518 return success;
519}
520
521//
522//////////////////////////////////////////////////////////////////////////////
523void t_pppClient::processEpoch(const vector<t_satObs*>& satObs, t_output* output) {
524
525 try {
526 initOutput(output);
527 bool epochReProcessing = false;
528 _numEpoProcessing = 0;
529 _historicalRefSats.clear();
530
531 do {
532 _numEpoProcessing++;
533#ifdef BNC_DEBUG_PPP
534 LOG << "_numEpoProcessing " << _numEpoProcessing << endl;
535#endif
536 if (_obsPool->refSatChanged()) {
537 if(_filter->datumTransformation(_refSatMap) != success) {
538 LOG << "t_pppFilter::datumTransformation() != success" << endl;
539 return finish(failure,1);
540 }
541 else {
542 LOG << "t_pppFilter::datumTransformation() == success" << endl;
543 _filter->rememberState(1);
544 }
545 }
546 // Prepare Observations of the Rover
547 // ---------------------------------
548 if (prepareObs(satObs, _obsRover, _epoTimeRover) != success) {
549 return finish(failure,2);
550 }
551
552 for (int iter = 1; iter <= 2; iter++) {
553 ColumnVector xyzc(4); xyzc = 0.0;
554 bool print = (iter == 2);
555 if (cmpBancroft(_epoTimeRover, _obsRover, xyzc, print) != success) {
556 return finish(failure,3);
557 }
558
559 if (cmpModel(_staRover, xyzc, _obsRover) != success) {
560 return finish(failure,4);
561 }
562 }
563
564 if (_opt->_refSatRequired) {
565 if (handleRefSatellites(_obsRover) != success) {
566 return finish(failure,6);
567 }
568 if (_obsPool->refSatChanged()) {
569 LOG << "t_pppFilter: refSatChanged()" << endl;
570 epochReProcessing = true;
571 continue;
572 }
573 }
574
575 // use observations only if satellite code biases are available
576 // ------------------------------------------------------------
577 if (!_opt->_corrMount.empty() &&
578 (OPT->_obsModelType == OPT->DCMcodeBias ||
579 OPT->_obsModelType == OPT->DCMphaseBias)) {
580 useObsWithCodeBiasesOnly(_obsRover);
581 }
582
583 if (int(_obsRover.size()) < _opt->_minObs) {
584 LOG << "t_pppClient::processEpoch not enough observations" << endl;
585 return finish(failure,5);
586 }
587
588 _offGG = cmpOffGG(_obsRover);
589
590 // Prepare Pseudo Observations of the Rover
591 // ----------------------------------------
592 _pseudoObsIono = preparePseudoObs(_obsRover);
593
594 // Store last epoch of data
595 // ------------------------
596 _obsPool->putEpoch(_epoTimeRover, _obsRover, _pseudoObsIono, _refSatMap);
597
598 // Process Epoch in Filter
599 // -----------------------
600 if (_filter->processEpoch() != success) {
601 LOG << "filter->processEpoch() != success" << endl;
602 return finish(failure,7);
603 }
604
605 // Epoch re-processing required?
606 // -----------------------------
607 if (_obsPool->refSatChangeRequired() && //SLIP
608 _opt->_obsModelType != t_pppOptions::UncombPPP) {
609 LOG << "pppClient: _obsPool->refSatChangeRequired() " << endl;
610 epochReProcessing = true;
611 _obsPool->deleteLastEpoch();
612 _filter->restoreState(0);
613 setHistoricalRefSats();
614 }
615 else {
616 epochReProcessing = false;
617 if (OPT->_obsModelType == OPT->DCMcodeBias ||
618 OPT->_obsModelType == OPT->DCMphaseBias) {
619 _filter->rememberState(0);
620 }
621 }
622 } while (epochReProcessing);
623
624 }
625 catch (Exception& exc) {
626 LOG << exc.what() << endl;
627 return finish(failure,8);
628 }
629 catch (t_except msg) {
630 LOG << msg.what() << endl;
631 return finish(failure,9);
632 }
633 catch (const char* msg) {
634 LOG << msg << endl;
635 return finish(failure,10);
636 }
637 catch (...) {
638 LOG << "unknown exception" << endl;
639 return finish(failure,11);
640 }
641 return finish(success,12);
642}
643
644//
645////////////////////////////////////////////////////////////////////////////
646double lorentz(const ColumnVector& aa, const ColumnVector& bb) {
647 return aa[0]*bb[0] + aa[1]*bb[1] + aa[2]*bb[2] - aa[3]*bb[3];
648}
649
650//
651////////////////////////////////////////////////////////////////////////////
652t_irc t_pppClient::bancroft(const Matrix& BBpass, ColumnVector& pos) {
653
654 if (pos.Nrows() != 4) {
655 pos.ReSize(4);
656 }
657 pos = 0.0;
658
659 for (int iter = 1; iter <= 2; iter++) {
660 Matrix BB = BBpass;
661 int mm = BB.Nrows();
662 for (int ii = 1; ii <= mm; ii++) {
663 double xx = BB(ii,1);
664 double yy = BB(ii,2);
665 double traveltime = 0.072;
666 if (iter > 1) {
667 double zz = BB(ii,3);
668 double rho = sqrt( (xx-pos(1)) * (xx-pos(1)) +
669 (yy-pos(2)) * (yy-pos(2)) +
670 (zz-pos(3)) * (zz-pos(3)) );
671 traveltime = rho / t_CST::c;
672 }
673 double angle = traveltime * t_CST::omega;
674 double cosa = cos(angle);
675 double sina = sin(angle);
676 BB(ii,1) = cosa * xx + sina * yy;
677 BB(ii,2) = -sina * xx + cosa * yy;
678 }
679
680 Matrix BBB;
681 if (mm > 4) {
682 SymmetricMatrix hlp; hlp << BB.t() * BB;
683 BBB = hlp.i() * BB.t();
684 }
685 else {
686 BBB = BB.i();
687 }
688 ColumnVector ee(mm); ee = 1.0;
689 ColumnVector alpha(mm); alpha = 0.0;
690 for (int ii = 1; ii <= mm; ii++) {
691 alpha(ii) = lorentz(BB.Row(ii).t(),BB.Row(ii).t())/2.0;
692 }
693 ColumnVector BBBe = BBB * ee;
694 ColumnVector BBBalpha = BBB * alpha;
695 double aa = lorentz(BBBe, BBBe);
696 double bb = lorentz(BBBe, BBBalpha)-1;
697 double cc = lorentz(BBBalpha, BBBalpha);
698 double root = sqrt(bb*bb-aa*cc);
699
700 Matrix hlpPos(4,2);
701 hlpPos.Column(1) = (-bb-root)/aa * BBBe + BBBalpha;
702 hlpPos.Column(2) = (-bb+root)/aa * BBBe + BBBalpha;
703
704 ColumnVector omc(2);
705 for (int pp = 1; pp <= 2; pp++) {
706 hlpPos(4,pp) = -hlpPos(4,pp);
707 omc(pp) = BB(1,4) -
708 sqrt( (BB(1,1)-hlpPos(1,pp)) * (BB(1,1)-hlpPos(1,pp)) +
709 (BB(1,2)-hlpPos(2,pp)) * (BB(1,2)-hlpPos(2,pp)) +
710 (BB(1,3)-hlpPos(3,pp)) * (BB(1,3)-hlpPos(3,pp)) ) -
711 hlpPos(4,pp);
712 }
713 if ( fabs(omc(1)) > fabs(omc(2)) ) {
714 pos = hlpPos.Column(2);
715 }
716 else {
717 pos = hlpPos.Column(1);
718 }
719 }
720 if (pos.size() != 4 ||
721 std::isnan(pos(1)) ||
722 std::isnan(pos(2)) ||
723 std::isnan(pos(3)) ||
724 std::isnan(pos(4))) {
725 return failure;
726 }
727
728 return success;
729}
730
731//
732//////////////////////////////////////////////////////////////////////////////
733void t_pppClient::setRefSatellites(std::vector<t_pppSatObs*>& obsVector) {
734 // reference satellite definition per system
735 for (unsigned iSys = 0; iSys < _opt->systems().size(); iSys++) {
736 t_irc refSatReDefinition = success;
737 char sys = _opt->systems()[iSys];
738 bool refSatDefined = false;
739 t_pppRefSat* refSat = _refSatMap[sys];
740 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
741 t_pppSatObs* satObs = obsVector.at(ii);
742 if (satObs->eleSat() < _opt->_minEle) {
743 continue;
744 }
745 // reference satellite is unchanged
746 // ================================
747 if ( !_obsPool->refSatChangeRequired(sys) && refSat->prn() == satObs->prn()) {
748 refSatDefined = true;
749 obsVector[ii]->setAsReference();
750 }
751 // reference satellite has changed
752 // ===============================
753 else if ( _obsPool->refSatChangeRequired(sys) && refSat->prn() != satObs->prn()) {
754 if (satObs->prn().system() == sys) {
755 if (!_historicalRefSats[sys].contains(satObs->prn())) {
756 refSatDefined = true;
757 obsVector[ii]->setAsReference();
758 refSat->setPrn(satObs->prn());
759 }
760 else if ( _historicalRefSats[sys].contains(satObs->prn())) {
761 refSatReDefinition = failure;
762 }
763 }
764 }
765 if (refSatDefined) {
766 if (OPT->_pseudoObsIono) {
767 refSat->setStecValue(satObs->getIonoCodeDelay(t_frequency::G1));
768 }
769 break;
770 }
771 }
772
773 // all available satellites were already tried to use
774 if ((!refSatDefined) && (refSatReDefinition == failure)) {
775 refSat->setPrn(t_prn(sys, 99));
776 _obsPool->setRefSatChangeRequired(sys, false);
777 return;
778 }
779
780 // reference satellite has to be initialized
781 // =========================================
782 if (!refSatDefined) {
783 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
784 t_pppSatObs* satObs = obsVector.at(ii);
785 if (satObs->eleSat() < _opt->_minEle) {
786 continue;
787 }
788 if (satObs->prn().system() == sys &&
789 !_historicalRefSats[sys].contains(satObs->prn())) {
790 obsVector[ii]->setAsReference();
791 refSat->setPrn(satObs->prn());
792 if (OPT->_pseudoObsIono) {
793 refSat->setStecValue(satObs->getIonoCodeDelay(t_frequency::G1));
794 }
795 refSatDefined = true;
796 break;
797 }
798 }
799 }
800
801 // no observations for that system
802 // ===============================
803 if (!refSatDefined) {
804 refSat->setPrn(t_prn());
805 }
806 _obsPool->setRefSatChangeRequired(sys, false); // done or impossible
807 }
808
809 return;
810}
811
812//
813//////////////////////////////////////////////////////////////////////////////
814t_irc t_pppClient::handleRefSatellites(std::vector<t_pppSatObs*>& obsVector) {
815
816 // set refSats in current epoch
817 // ============================
818 setRefSatellites(obsVector); // current epoch
819 LOG.setf(ios::fixed);
820 t_pppObsPool::t_epoch* epoch = _obsPool->lastEpoch();
821 const QMap<char, t_pppRefSat*>& refSatMapLastEpoch = epoch->refSatMap();
822
823 QMapIterator<char, t_pppRefSat*> it(_refSatMap);
824 while (it.hasNext()) {
825 it.next();
826 char sys = it.key();
827 t_prn prn = it.value()->prn();
828 t_prn refSatLastEpochPrn = t_prn();
829 if (epoch) {
830 refSatLastEpochPrn = refSatMapLastEpoch[sys]->prn();
831 }
832 if (prn.number() == 0) { // no obs for that system available
833 continue;
834 }
835 else if (prn.number() == 99) { // refSat re-definition not possible
836 LOG << " => refSat re-definition impossible: " << sys << endl;
837 return failure;
838 }
839 QString str;
840 if (prn == refSatLastEpochPrn || refSatLastEpochPrn == t_prn() ) {
841 _obsPool->setRefSatChanged(sys, false);
842 str = " SET ";
843 }
844 else {
845 _obsPool->setRefSatChanged(sys, true);
846 str = " RESET ";
847 }
848 LOG << string(_epoTimeRover) << str.toStdString() << " REFSAT " << sys << ": " << prn.toString() << endl;
849 }
850 return success;
851}
852
853void t_pppClient::setHistoricalRefSats() {
854 QMapIterator<char, t_pppRefSat*> it(_refSatMap);
855 while (it.hasNext()) {
856 it.next();
857 t_prn prn = it.value()->prn();
858 char sys = prn.system();
859 if (_obsPool->refSatChangeRequired(sys)) {
860 _historicalRefSats[sys].append(prn);
861 }
862 }
863}
864
865//
866//////////////////////////////////////////////////////////////////////////////
867void t_pppClient::reset() {LOG << "t_pppClient::reset()" << endl;
868
869 // to delete old orbit and clock corrections
870 delete _ephPool;
871 _ephPool = new t_pppEphPool();
872
873 // to delete old code biases
874 delete _obsPool;
875 _obsPool = new t_pppObsPool();
876
877 // to delete all parameters
878 delete _filter;
879 _filter = new t_pppFilter(_obsPool);
880
881}
Note: See TracBrowser for help on using the repository browser.