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

Last change on this file since 9585 was 9585, checked in by stuerze, 2 years ago

update regarding PPP

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