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

Last change on this file since 9594 was 9594, checked in by stuerze, 2 years 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: 24.0 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 _offGR = 0.0;
76 _offGE = 0.0;
77 _offGC = 0.0;
78 CLIENTS.setLocalData(this); // CLIENTS takes ownership over "this"
79}
80
81// Destructor
82//////////////////////////////////////////////////////////////////////////////
83t_pppClient::~t_pppClient() {
84 delete _log;
85 delete _opt;
86 delete _filter;
87 delete _ephPool;
88 delete _obsPool;
89 delete _staRover;
90 if (_antex) {
91 delete _antex;
92 }
93 delete _tides;
94 clearObs();
95 QMapIterator<char, t_pppRefSat*> it(_refSatMap);
96 while (it.hasNext()) {
97 it.next();
98 delete it.value();
99 }
100 _refSatMap.clear();
101}
102
103//
104//////////////////////////////////////////////////////////////////////////////
105void t_pppClient::putEphemeris(const t_eph* eph) {
106 const t_ephGPS* ephGPS = dynamic_cast<const t_ephGPS*>(eph);
107 const t_ephGlo* ephGlo = dynamic_cast<const t_ephGlo*>(eph);
108 const t_ephGal* ephGal = dynamic_cast<const t_ephGal*>(eph);
109 const t_ephBDS* ephBDS = dynamic_cast<const t_ephBDS*>(eph);
110 if (ephGPS) {
111 _ephPool->putEphemeris(new t_ephGPS(*ephGPS));
112 }
113 else if (ephGlo) {
114 _ephPool->putEphemeris(new t_ephGlo(*ephGlo));
115 }
116 else if (ephGal) {
117 _ephPool->putEphemeris(new t_ephGal(*ephGal));
118 }
119 else if (ephBDS) {
120 _ephPool->putEphemeris(new t_ephBDS(*ephBDS));
121 }
122}
123
124//
125//////////////////////////////////////////////////////////////////////////////
126void t_pppClient::putTec(const t_vTec* vTec) {
127 _obsPool->putTec(new t_vTec(*vTec));
128}
129
130//
131//////////////////////////////////////////////////////////////////////////////
132void t_pppClient::putOrbCorrections(const vector<t_orbCorr*>& corr) {
133 for (unsigned ii = 0; ii < corr.size(); ii++) {
134 _ephPool->putOrbCorrection(new t_orbCorr(*corr[ii]));
135 }
136}
137
138//
139//////////////////////////////////////////////////////////////////////////////
140void t_pppClient::putClkCorrections(const vector<t_clkCorr*>& corr) {
141 for (unsigned ii = 0; ii < corr.size(); ii++) {
142 _ephPool->putClkCorrection(new t_clkCorr(*corr[ii]));
143 }
144}
145
146//
147//////////////////////////////////////////////////////////////////////////////
148void t_pppClient::putCodeBiases(const vector<t_satCodeBias*>& biases) {
149 for (unsigned ii = 0; ii < biases.size(); ii++) {
150 _obsPool->putCodeBias(new t_satCodeBias(*biases[ii]));
151 }
152}
153
154//
155//////////////////////////////////////////////////////////////////////////////
156void t_pppClient::putPhaseBiases(const vector<t_satPhaseBias*>& biases) {
157 for (unsigned ii = 0; ii < biases.size(); ii++) {
158 _obsPool->putPhaseBias(new t_satPhaseBias(*biases[ii]));
159 }
160}
161
162//
163//////////////////////////////////////////////////////////////////////////////
164t_irc t_pppClient::prepareObs(const vector<t_satObs*>& satObs,
165 vector<t_pppSatObs*>& obsVector, bncTime& epoTime) {
166
167 // Default
168 // -------
169 epoTime.reset();
170 clearObs();
171
172 // Create vector of valid observations
173 // -----------------------------------
174 for (unsigned ii = 0; ii < satObs.size(); ii++) {
175 char sys = satObs[ii]->_prn.system();
176 if (_opt->useSystem(sys)) {
177 t_pppSatObs* pppSatObs = new t_pppSatObs(*satObs[ii]);
178 if (pppSatObs->isValid()) {
179 obsVector.push_back(pppSatObs);
180 }
181 else {
182 delete pppSatObs;
183 }
184 }
185 }
186
187 // Check whether data are synchronized, compute epoTime
188 // ----------------------------------------------------
189 const double MAXSYNC = 0.05; // synchronization limit
190 double meanDt = 0.0;
191 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
192 const t_pppSatObs* satObs = obsVector.at(ii);
193 if (epoTime.undef()) {
194 epoTime = satObs->time();
195 }
196 else {
197 double dt = satObs->time() - epoTime;
198 if (fabs(dt) > MAXSYNC) {
199 LOG << "t_pppClient::prepareObs asynchronous observations" << endl;
200 return failure;
201 }
202 meanDt += dt;
203 }
204 }
205
206 if (obsVector.size() > 0) {
207 epoTime += meanDt / obsVector.size();
208 }
209
210 return success;
211}
212
213//
214//////////////////////////////////////////////////////////////////////////////
215bool t_pppClient::preparePseudoObs(std::vector<t_pppSatObs*>& obsVector) {
216
217 bool pseudoObsIono = false;
218
219 if (_opt->_pseudoObsIono) {
220 vector<t_pppSatObs*>::iterator it = obsVector.begin();
221 while (it != obsVector.end()) {
222 t_pppSatObs* satObs = *it;
223 char sys = satObs->prn().system();
224 t_pppRefSat* refSat = _refSatMap[sys];
225 double stecRef = refSat->stecValue();
226 if (stecRef && !satObs->isReference()) {
227 pseudoObsIono = true;
228 satObs->setPseudoObsIono(t_frequency::G1, stecRef);
229 }
230 it++;
231 }
232 }
233
234/*
235 vector<t_pppSatObs*>::iterator it = obsVector.begin();
236 while (it != obsVector.end()) {
237 t_pppSatObs* satObs = *it;
238 satObs->printObsMinusComputed();
239 it++;
240 }
241*/
242 return pseudoObsIono;
243}
244
245//
246//////////////////////////////////////////////////////////////////////////////
247void t_pppClient::useObsWithCodeBiasesOnly(std::vector<t_pppSatObs*>& obsVector) {
248
249 vector<t_pppSatObs*>::iterator it = obsVector.begin();
250 while (it != obsVector.end()) {
251 t_pppSatObs* pppSatObs = *it;
252 char sys = pppSatObs->prn().system();
253 bool codeBiasesAvailable = false;
254 t_frequency::type fType1 = t_lc::toFreq(sys,t_lc::c1);
255 t_frequency::type fType2 = t_lc::toFreq(sys,t_lc::c2);
256 if (pppSatObs->getCodeBias(fType1) &&
257 pppSatObs->getCodeBias(fType2)) {
258 codeBiasesAvailable = true;
259 }
260 if (codeBiasesAvailable) {
261 ++it;
262 }
263 else {
264 it = obsVector.erase(it);
265 delete pppSatObs;
266 }
267 }
268
269}
270
271
272// Compute the Bancroft position, check for blunders
273//////////////////////////////////////////////////////////////////////////////
274t_irc t_pppClient::cmpBancroft(const bncTime& epoTime,
275 vector<t_pppSatObs*>& obsVector,
276 ColumnVector& xyzc, bool print) {
277
278 t_lc::type tLC = t_lc::dummy;
279
280 while (true) {
281 Matrix BB(obsVector.size(), 4);
282 int iObs = -1;
283 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
284 const t_pppSatObs* satObs = obsVector.at(ii);
285 if (tLC == t_lc::dummy) {
286 if (satObs->isValid(t_lc::cIF)) {
287 tLC = t_lc::cIF;
288 }
289 else if (satObs->isValid(t_lc::c1)) {
290 tLC = t_lc::c1;
291 }
292 else if (satObs->isValid(t_lc::c2)) {
293 tLC = t_lc::c2;
294 }
295 }
296 if ( satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
297 ++iObs;
298 BB[iObs][0] = satObs->xc()[0];
299 BB[iObs][1] = satObs->xc()[1];
300 BB[iObs][2] = satObs->xc()[2];
301 BB[iObs][3] = satObs->obsValue(tLC) - satObs->cmpValueForBanc(tLC);
302 }
303 }
304 if (iObs + 1 < _opt->_minObs) {
305 LOG << "t_pppClient::cmpBancroft not enough observations: " << iObs + 1 << endl;
306 return failure;
307 }
308 BB = BB.Rows(1,iObs+1);
309 bancroft(BB, xyzc);
310
311 xyzc[3] /= t_CST::c;
312
313 // Check Blunders
314 // --------------
315 const double BLUNDER = 100.0;
316 double maxRes = 0.0;
317 unsigned maxResIndex = 0;
318 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
319 const t_pppSatObs* satObs = obsVector.at(ii);
320 if (satObs->isValid() &&
321 satObs->prn().system() == 'G' &&
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 (std::isnan(res) || fabs(res) > maxRes) {
327 std::isnan(res) ?
328 maxRes = res :
329 maxRes = fabs(res);
330 maxResIndex = ii;
331 }
332 }
333 }
334 if (!std::isnan(maxRes) && maxRes < BLUNDER) {
335 if (print && _numEpoProcessing == 1) {
336 LOG.setf(ios::fixed);
337 LOG << string(epoTime) << " BANCROFT:" << ' '
338 << setw(14) << setprecision(3) << xyzc[0] << ' '
339 << setw(14) << setprecision(3) << xyzc[1] << ' '
340 << setw(14) << setprecision(3) << xyzc[2] << ' '
341 << setw(14) << setprecision(3) << xyzc[3] * t_CST::c << endl << endl;
342 }
343 break;
344 }
345 else {
346 t_pppSatObs* satObs = obsVector.at(maxResIndex);
347 LOG << "t_pppClient::cmpBancroft outlier " << satObs->prn().toString()
348 << " " << maxRes << endl;
349 delete satObs;
350 obsVector.erase(obsVector.begin() + maxResIndex);
351 }
352 }
353
354 return success;
355}
356
357//
358//////////////////////////////////////////////////////////////////////////////
359void t_pppClient::initOutput(t_output* output) {
360 _output = output;
361 _output->_numSat = 0;
362 _output->_hDop = 0.0;
363 _output->_error = false;
364}
365
366//
367//////////////////////////////////////////////////////////////////////////////
368void t_pppClient::clearObs() {
369 for (unsigned ii = 0; ii < _obsRover.size(); ii++) {
370 delete _obsRover.at(ii);
371 }
372 _obsRover.clear();
373}
374
375//
376//////////////////////////////////////////////////////////////////////////////
377void t_pppClient::finish(t_irc irc, int ind) {
378
379 LOG << "t_pppClient::finish(" << ind << "): " << irc << endl;
380
381 clearObs();
382
383 _output->_epoTime = _epoTimeRover;
384
385 if (irc == success) {
386 _output->_xyzRover[0] = _staRover->xyzApr()[0] + _filter->x()[0];
387 _output->_xyzRover[1] = _staRover->xyzApr()[1] + _filter->x()[1];
388 _output->_xyzRover[2] = _staRover->xyzApr()[2] + _filter->x()[2];
389
390 xyz2neu(_staRover->ellApr().data(), _filter->x().data(), _output->_neu);
391
392 copy(&_filter->Q().data()[0], &_filter->Q().data()[6], _output->_covMatrix);
393
394 _output->_trp0 = t_tropo::delay_saast(_staRover->xyzApr(), M_PI/2.0);
395 _output->_trp = _filter->trp();
396 _output->_trpStdev = _filter->trpStdev();
397
398 _output->_numSat = _filter->numSat();
399 _output->_hDop = _filter->HDOP();
400 _output->_error = false;
401 }
402 else {
403 _output->_error = true;
404 if (OPT->_obsModelType == OPT->DCMcodeBias ||
405 OPT->_obsModelType == OPT->DCMphaseBias) {
406 reset();
407 }
408 }
409 _output->_log = _log->str();
410 delete _log; _log = new ostringstream();
411
412 return;
413}
414
415//
416//////////////////////////////////////////////////////////////////////////////
417t_irc t_pppClient::cmpModel(t_pppStation* station, const ColumnVector& xyzc,
418 vector<t_pppSatObs*>& obsVector) {
419 bncTime time;
420 time = _epoTimeRover;
421 station->setName(_opt->_roverName);
422 station->setAntName(_opt->_antNameRover);
423 station->setEpochTime(time);
424 if (_opt->xyzAprRoverSet()) {
425 station->setXyzApr(_opt->_xyzAprRover);
426 }
427 else {
428 station->setXyzApr(xyzc.Rows(1,3));
429 }
430 station->setNeuEcc(_opt->_neuEccRover);
431
432 // Receiver Clock
433 // --------------
434 station->setDClk(xyzc[3]);
435
436 // Tides
437 // -----
438 station->setTideDsplEarth(_tides->earth(time, station->xyzApr()));
439 station->setTideDsplOcean(_tides->ocean(time, station->xyzApr(), station->name()));
440
441 // Observation model
442 // -----------------
443 vector<t_pppSatObs*>::iterator it = obsVector.begin();
444 while (it != obsVector.end()) {
445 t_pppSatObs* satObs = *it;
446 t_irc modelSetup;
447 if (satObs->isValid()) {
448 modelSetup = satObs->cmpModel(station);
449 }
450 if (satObs->isValid() &&
451 satObs->eleSat() >= _opt->_minEle &&
452 modelSetup == success) {
453 ++it;
454 }
455 else {
456 delete satObs;
457 it = obsVector.erase(it);
458 }
459 }
460
461 return success;
462}
463
464//
465//////////////////////////////////////////////////////////////////////////////
466void t_pppClient::processEpoch(const vector<t_satObs*>& satObs, t_output* output) {
467
468 try {
469 initOutput(output);
470 bool epochReProcessing = false;
471 _numEpoProcessing = 0;
472 _historicalRefSats.clear();
473
474 do {
475 _numEpoProcessing++;
476#ifdef BNC_DEBUG_PPP
477 LOG << "_numEpoProcessing " << _numEpoProcessing << endl;
478#endif
479 if (_obsPool->refSatChanged()) {
480 if(_filter->datumTransformation(_refSatMap) != success) {
481 LOG << "t_pppFilter::datumTransformation() != success" << endl;
482 return finish(failure,1);
483 }
484 else {
485 LOG << "t_pppFilter::datumTransformation() == success" << endl;
486 _filter->rememberState(1);
487 }
488 }
489 // Prepare Observations of the Rover
490 // ---------------------------------
491 if (prepareObs(satObs, _obsRover, _epoTimeRover) != success) {
492 return finish(failure,2);
493 }
494
495 if (_numEpoProcessing == 1) {
496 LOG << "\nPPP of Epoch ";
497 if (!_epoTimeRover.undef()) LOG << string(_epoTimeRover);
498 LOG << "\n---------------------------------------------------------------\n";
499 }
500
501 for (int iter = 1; iter <= 2; iter++) {
502 ColumnVector xyzc(4); xyzc = 0.0;
503 bool print = (iter == 2);
504 if (cmpBancroft(_epoTimeRover, _obsRover, xyzc, print) != success) {
505 return finish(failure,3);
506 }
507 if (cmpModel(_staRover, xyzc, _obsRover) != success) {
508 return finish(failure,4);
509 }
510 }
511
512 if (_opt->_refSatRequired) {
513 if (handleRefSatellites(_obsRover) != success) {
514 return finish(failure,6);
515 }
516 if (_obsPool->refSatChanged()) {
517 LOG << "t_pppFilter: refSatChanged()" << endl;
518 epochReProcessing = true;
519 continue;
520 }
521 }
522
523 // use observations only if satellite code biases are available
524 // ------------------------------------------------------------
525 if (!_opt->_corrMount.empty() &&
526 (OPT->_obsModelType == OPT->DCMcodeBias || OPT->_obsModelType == OPT->DCMphaseBias)) {
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.