Changeset 10034 in ntrip for trunk/BNC/src/PPP/pppClient.cpp
- Timestamp:
- Apr 21, 2023, 11:48:24 AM (12 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/src/PPP/pppClient.cpp
r10031 r10034 20 20 #include <iomanip> 21 21 #include <cmath> 22 #include <stdlib.h> 22 23 #include <string.h> 23 24 #include <stdexcept> … … 54 55 _obsPool = new t_pppObsPool(); 55 56 _staRover = new t_pppStation(); 56 _filter = new t_pppFilter( _obsPool);57 _filter = new t_pppFilter(); 57 58 _tides = new t_tides(); 58 59 _antex = 0; … … 65 66 } 66 67 } 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 68 _offGlo = 0.0; 69 _offGal = 0.0; 70 _offBds = 0.0; 75 71 CLIENTS.setLocalData(this); // CLIENTS takes ownership over "this" 76 72 } … … 81 77 delete _log; 82 78 delete _opt; 83 delete _filter;84 79 delete _ephPool; 85 80 delete _obsPool; … … 88 83 delete _antex; 89 84 } 85 delete _filter; 90 86 delete _tides; 91 87 clearObs(); 92 QMapIterator<char, t_pppRefSat*> it(_refSatMap);93 while (it.hasNext()) {94 it.next();95 delete it.value();96 }97 _refSatMap.clear();98 88 } 99 89 … … 165 155 // ------- 166 156 epoTime.reset(); 167 clearObs();157 //clearObs(); 168 158 169 159 // Create vector of valid observations … … 218 208 while (it != obsVector.end()) { 219 209 t_pppSatObs* satObs = *it; 220 char sys = satObs->prn().system(); 221 t_pppRefSat* refSat = _refSatMap[sys]; 222 double stecRef = refSat->stecValue(); 223 if (stecRef && !satObs->isReference()) { 224 pseudoObsIono = true; 225 satObs->setPseudoObsIono(t_frequency::G1, stecRef); 226 } 210 pseudoObsIono = satObs->setPseudoObsIono(t_frequency::G1); 227 211 it++; 228 212 } 229 213 } 230 231 /* 232 vector<t_pppSatObs*>::iterator it = obsVector.begin(); 214 /*vector<t_pppSatObs*>::iterator it = obsVector.begin(); 233 215 while (it != obsVector.end()) { 234 216 t_pppSatObs* satObs = *it; 235 217 satObs->printObsMinusComputed(); 236 218 it++; 237 } 238 */ 219 }*/ 220 239 221 return pseudoObsIono; 240 222 } … … 330 312 } 331 313 if (maxRes < BLUNDER) { 332 if (print && _numEpoProcessing == 1) {314 if (print) { 333 315 LOG.setf(ios::fixed); 334 316 LOG << "\nPPP of Epoch "; … … 354 336 return success; 355 337 } 356 338 // Compute A Priori Glonass Receiver Clock Offset 339 ////////////////////////////////////////////////////////////////////////////// 340 double t_pppClient::cmpOffGlo(vector<t_pppSatObs*>& obsVector) { 341 342 t_lc::type tLC = t_lc::dummy; 343 double offGlo = 0.0; 344 345 if (OPT->useSystem('R')) { 346 347 while (obsVector.size() > 0) { 348 offGlo = 0.0; 349 double maxRes = 0.0; 350 int maxResIndex = -1; 351 t_prn maxResPrn; 352 unsigned nObs = 0; 353 for (unsigned ii = 0; ii < obsVector.size(); ii++) { 354 t_pppSatObs* satObs = obsVector.at(ii); 355 if (satObs->prn().system() == 'R') { 356 if (tLC == t_lc::dummy) { 357 tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1; 358 } 359 if (satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= OPT->_minEle)) { 360 double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC); 361 ++nObs; 362 offGlo += ll; 363 if (fabs(ll) > fabs(maxRes)) { 364 maxRes = ll; 365 maxResIndex = ii; 366 maxResPrn = satObs->prn(); 367 } 368 } 369 } 370 } 371 372 if (nObs > 0) { 373 offGlo = offGlo / nObs; 374 } 375 else { 376 offGlo = 0.0; 377 } 378 379 if (fabs(maxRes) > 1000.0) { 380 LOG << "t_pppClient::cmpOffGlo outlier " << maxResPrn.toString() << " " << maxRes << endl; 381 obsVector.erase(obsVector.begin() + maxResIndex); 382 } 383 else { 384 break; 385 } 386 } 387 } 388 389 return offGlo; 390 } 391 392 // Compute A Priori Galileo Receiver Clock Offset 393 ////////////////////////////////////////////////////////////////////////////// 394 double t_pppClient::cmpOffGal(vector<t_pppSatObs*>& obsVector) { 395 396 t_lc::type tLC = t_lc::dummy; 397 double offGal = 0.0; 398 399 if (OPT->useSystem('E')) { 400 401 while (obsVector.size() > 0) { 402 offGal = 0.0; 403 double maxRes = 0.0; 404 int maxResIndex = -1; 405 t_prn maxResPrn; 406 unsigned nObs = 0; 407 for (unsigned ii = 0; ii < obsVector.size(); ii++) { 408 t_pppSatObs* satObs = obsVector.at(ii); 409 if (satObs->prn().system() == 'E') { 410 if (tLC == t_lc::dummy) { 411 tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1; 412 } 413 if (satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= OPT->_minEle)) { 414 double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC); 415 ++nObs; 416 offGal += ll; 417 if (fabs(ll) > fabs(maxRes)) { 418 maxRes = ll; 419 maxResIndex = ii; 420 maxResPrn = satObs->prn(); 421 } 422 } 423 } 424 } 425 426 if (nObs > 0) { 427 offGal = offGal / nObs; 428 } 429 else { 430 offGal = 0.0; 431 } 432 433 if (fabs(maxRes) > 1000.0) { 434 LOG << "t_pppClient::cmpOffGal outlier " << maxResPrn.toString() << " " << maxRes << endl; 435 obsVector.erase(obsVector.begin() + maxResIndex); 436 } 437 else { 438 break; 439 } 440 } 441 } 442 443 return offGal; 444 } 445 446 447 // Compute A Priori BDS Receiver Clock Offset 448 ////////////////////////////////////////////////////////////////////////////// 449 double t_pppClient::cmpOffBds(vector<t_pppSatObs*>& obsVector) { 450 451 t_lc::type tLC = t_lc::dummy; 452 double offBds = 0.0; 453 454 if (_opt->useSystem('C')) { 455 while (obsVector.size() > 0) { 456 offBds = 0.0; 457 double maxRes = 0.0; 458 int maxResIndex = -1; 459 t_prn maxResPrn; 460 unsigned nObs = 0; 461 for (unsigned ii = 0; ii < obsVector.size(); ii++) { 462 const t_pppSatObs* satObs = obsVector.at(ii); 463 if (satObs->prn().system() == 'C') { 464 if (tLC == t_lc::dummy) { 465 tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1; 466 } 467 if (satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle)) { 468 double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC); 469 ++nObs; 470 offBds += ll; 471 if (fabs(ll) > fabs(maxRes)) { 472 maxRes = ll; 473 maxResIndex = ii; 474 maxResPrn = satObs->prn(); 475 } 476 } 477 } 478 } 479 480 if (nObs > 0) { 481 offBds = offBds / nObs; 482 } 483 else { 484 offBds = 0.0; 485 } 486 487 if (fabs(maxRes) > 1000.0) { 488 LOG << "t_pppClient::cmpOffBds outlier " << maxResPrn.toString() << " " << maxRes << endl; 489 delete obsVector.at(maxResIndex); 490 obsVector.erase(obsVector.begin() + maxResIndex); 491 } 492 else { 493 break; 494 } 495 } 496 } 497 return offBds; 498 } 357 499 // 358 500 ////////////////////////////////////////////////////////////////////////////// … … 403 545 else { 404 546 _output->_error = true; 405 if (OPT->_obsModelType == OPT->DCMcodeBias || 406 OPT->_obsModelType == OPT->DCMphaseBias) { 407 if (ind == 1 || ind == 6 || ind > 7) { 408 reset(); 409 } 410 //else {_filter->restoreState(ind);} 411 } 412 } 547 } 548 413 549 _output->_log = _log->str(); 414 550 delete _log; _log = new ostringstream(); … … 426 562 station->setAntName(_opt->_antNameRover); 427 563 station->setEpochTime(time); 564 428 565 if (_opt->xyzAprRoverSet()) { 429 566 station->setXyzApr(_opt->_xyzAprRover); … … 472 609 try { 473 610 initOutput(output); 474 bool epochReProcessing = false; 475 _numEpoProcessing = 0; 476 if (!_historicalRefSats.isEmpty()) { 477 _historicalRefSats.clear(); 478 } 479 480 do { 481 if ((_numEpoProcessing++) > 30) { 482 LOG << "t_pppClient::processEpoch: _numEpoProcessing > 30" << endl; 483 return finish(failure,12); 484 } 485 486 if (_obsPool->refSatChanged()) { 487 if(_filter->datumTransformation(_refSatMap) != success) { 488 LOG << "t_pppFilter::datumTransformation() != success" << endl; 489 return finish(failure,1); 490 } 491 else { 492 LOG << "t_pppFilter::datumTransformation() == success" << endl; 493 _filter->rememberState(1); 494 } 495 } 496 497 // Prepare Observations of the Rover 498 // --------------------------------- 499 if (prepareObs(satObs, _obsRover, _epoTimeRover) != success) { 500 return finish(failure,2); 501 } 502 503 for (int iter = 1; iter <= 2; iter++) { 504 ColumnVector xyzc(4); xyzc = 0.0; 505 bool print = (iter == 2); 506 if (cmpBancroft(_epoTimeRover, _obsRover, xyzc, print) != success) { 507 return finish(failure,3); 508 } 509 510 if (cmpModel(_staRover, xyzc, _obsRover) != success) { 511 return finish(failure,4); 512 } 513 } 514 // use observations only if satellite code biases are available 515 // ------------------------------------------------------------ 516 if (!_opt->_corrMount.empty() && 517 (OPT->_obsModelType == OPT->DCMcodeBias || 518 OPT->_obsModelType == OPT->DCMphaseBias)) { 611 612 // Prepare Observations of the Rover 613 // --------------------------------- 614 if (prepareObs(satObs, _obsRover, _epoTimeRover) != success) { 615 return finish(failure, 1); 616 } 617 618 for (int iter = 1; iter <= 2; iter++) { 619 ColumnVector xyzc(4); xyzc = 0.0; 620 bool print = (iter == 2); 621 if (cmpBancroft(_epoTimeRover, _obsRover, xyzc, print) != success) { 622 return finish(failure, 2); 623 } 624 if (cmpModel(_staRover, xyzc, _obsRover) != success) { 625 return finish(failure, 3); 626 } 627 } 628 // use observations only if satellite code biases are available 629 /* ------------------------------------------------------------ 630 if (!_opt->_corrMount.empty() { 519 631 useObsWithCodeBiasesOnly(_obsRover); 520 } 521 522 if (int(_obsRover.size()) < _opt->_minObs) { 523 LOG << "t_pppClient::processEpoch not enough observations" << endl; 524 return finish(failure,5); 525 } 526 527 if (_opt->_refSatRequired) { 528 if (handleRefSatellites(_obsRover) != success) { 529 return finish(failure,6); 530 } 531 if (_obsPool->refSatChanged()) { 532 epochReProcessing = true; 533 continue; 534 } 535 } 536 537 // Prepare Pseudo Observations of the Rover 538 // ---------------------------------------- 539 _pseudoObsIono = preparePseudoObs(_obsRover); 540 541 // Store last epoch of data 542 // ------------------------ 543 _obsPool->putEpoch(_epoTimeRover, _obsRover, _pseudoObsIono, _refSatMap); 544 #ifdef BNC_DEBUG_PPP 545 LOG << "PUT EPOCH t_pppClient::processEpoch " << _epoTimeRover.timestr().c_str() << endl; 546 #endif 547 548 // Process Epoch in Filter 549 // ----------------------- 550 if (_filter->processEpoch(_numEpoProcessing) != success) { 551 LOG << "filter->processEpoch() != success" << endl; 552 return finish(failure,7); 553 } 554 555 // Epoch re-processing required? 556 // ----------------------------- 557 if (_obsPool->refSatChangeRequired() && //SLIP 558 _opt->_obsModelType != t_pppOptions::UncombPPP) { 559 LOG << "pppClient: _obsPool->refSatChangeRequired() " << endl; 560 epochReProcessing = true; 561 #ifdef BNC_DEBUG_PPP 562 LOG << "DELETE EPOCH" << endl; 563 #endif 564 _obsPool->deleteLastEpoch(); 565 _filter->restoreState(0); 566 setHistoricalRefSats(); 567 } 568 else { 569 epochReProcessing = false; 570 if (OPT->_obsModelType == OPT->DCMcodeBias || 571 OPT->_obsModelType == OPT->DCMphaseBias) { 572 _filter->rememberState(0); 573 } 574 } 575 } while (epochReProcessing); 576 632 }*/ 633 634 if (int(_obsRover.size()) < _opt->_minObs) { 635 LOG << "t_pppClient::processEpoch not enough observations" << endl; 636 return finish(failure, 4); 637 } 638 639 _offGlo = cmpOffGlo(_obsRover); 640 _offGal = cmpOffGal(_obsRover); 641 _offBds = cmpOffBds(_obsRover); 642 643 // Prepare Pseudo Observations of the Rover 644 // ---------------------------------------- 645 _pseudoObsIono = preparePseudoObs(_obsRover); 646 647 // Store last epoch of data 648 // ------------------------ 649 _obsPool->putEpoch(_epoTimeRover, _obsRover, _pseudoObsIono); 650 651 // Process Epoch in Filter 652 // ----------------------- 653 if (_filter->processEpoch(_obsPool) != success) { 654 LOG << "filter->processEpoch() != success" << endl; 655 return finish(failure, 5); 656 } 577 657 } 578 658 catch (Exception& exc) { 579 659 LOG << exc.what() << endl; 580 return finish(failure, 8);660 return finish(failure, 6); 581 661 } 582 662 catch (t_except msg) { 583 663 LOG << msg.what() << endl; 584 return finish(failure, 9);664 return finish(failure, 7); 585 665 } 586 666 catch (const char* msg) { 587 667 LOG << msg << endl; 588 return finish(failure, 10);668 return finish(failure, 8); 589 669 } 590 670 catch (...) { 591 671 LOG << "unknown exception" << endl; 592 return finish(failure, 11);593 } 594 return finish(success, 0);672 return finish(failure, 9); 673 } 674 return finish(success, 0); 595 675 } 596 676 … … 684 764 // 685 765 ////////////////////////////////////////////////////////////////////////////// 686 void t_pppClient::setRefSatellites(std::vector<t_pppSatObs*>& obsVector) { 687 // reference satellite definition per system 688 for (unsigned iSys = 0; iSys < _opt->systems().size(); iSys++) { 689 t_irc refSatReDefinition = success; 690 char sys = _opt->systems()[iSys]; 691 bool refSatDefined = false; 692 t_pppRefSat* refSat = _refSatMap[sys]; 693 for (unsigned ii = 0; ii < obsVector.size(); ii++) { 694 t_pppSatObs* satObs = obsVector.at(ii); 695 if (satObs->eleSat() < _opt->_minEle) { 696 continue; 697 } 698 // reference satellite is unchanged 699 // ================================ 700 if ( !_obsPool->refSatChangeRequired(sys) && refSat->prn() == satObs->prn()) { 701 refSatDefined = true; 702 obsVector[ii]->setAsReference(); 703 } 704 // reference satellite has changed 705 // =============================== 706 else if ( _obsPool->refSatChangeRequired(sys) && refSat->prn() != satObs->prn()) { 707 if (satObs->prn().system() == sys) { 708 if (!_historicalRefSats[sys].contains(satObs->prn())) { 709 refSatDefined = true; 710 obsVector[ii]->setAsReference(); 711 refSat->setPrn(satObs->prn()); 712 } 713 else if ( _historicalRefSats[sys].contains(satObs->prn())) { 714 refSatReDefinition = failure; 715 } 716 } 717 } 718 if (refSatDefined) { 719 if (OPT->_pseudoObsIono) { 720 refSat->setStecValue(satObs->getIonoCodeDelay(t_frequency::G1)); 721 } 722 break; 723 } 724 } 725 726 // all available satellites were already tried to use 727 if ((!refSatDefined) && (refSatReDefinition == failure)) { 728 refSat->setPrn(t_prn(sys, 99)); 729 _obsPool->setRefSatChangeRequired(sys, false); 730 return; 731 } 732 733 // reference satellite has to be initialized 734 // ========================================= 735 if (!refSatDefined) { 736 for (unsigned ii = 0; ii < obsVector.size(); ii++) { 737 t_pppSatObs* satObs = obsVector.at(ii); 738 if (satObs->eleSat() < _opt->_minEle) { 739 continue; 740 } 741 if (satObs->prn().system() == sys && 742 !_historicalRefSats[sys].contains(satObs->prn())) { 743 obsVector[ii]->setAsReference(); 744 refSat->setPrn(satObs->prn()); 745 if (OPT->_pseudoObsIono) { 746 refSat->setStecValue(satObs->getIonoCodeDelay(t_frequency::G1)); 747 } 748 refSatDefined = true; 749 break; 750 } 751 } 752 } 753 754 // no observations for that system 755 // =============================== 756 if (!refSatDefined) { 757 refSat->setPrn(t_prn()); 758 } 759 _obsPool->setRefSatChangeRequired(sys, false); // done or impossible 760 } 761 762 return; 763 } 764 765 // 766 ////////////////////////////////////////////////////////////////////////////// 767 t_irc t_pppClient::handleRefSatellites(std::vector<t_pppSatObs*>& obsVector) { 768 769 // set refSats in current epoch 770 // ============================ 771 setRefSatellites(obsVector); // current epoch 772 LOG.setf(ios::fixed); 773 t_pppObsPool::t_epoch* epoch = _obsPool->lastEpoch(); 774 const QMap<char, t_pppRefSat*>& refSatMapLastEpoch = epoch->refSatMap(); 775 776 QMapIterator<char, t_pppRefSat*> it(_refSatMap); 777 while (it.hasNext()) { 778 it.next(); 779 char sys = it.key(); 780 t_prn prn = it.value()->prn(); 781 t_prn refSatLastEpochPrn = t_prn(); 782 if (epoch) { 783 refSatLastEpochPrn = refSatMapLastEpoch[sys]->prn(); 784 } 785 if (prn.number() == 0) { // no obs for that system available 786 continue; 787 } 788 else if (prn.number() == 99) { // refSat re-definition not possible 789 LOG << " => refSat re-definition impossible: " << sys << endl; 790 return failure; 791 } 792 QString str; 793 if (prn == refSatLastEpochPrn || refSatLastEpochPrn == t_prn() ) { 794 _obsPool->setRefSatChanged(sys, false); 795 str = " SET "; 796 } 797 else { 798 _obsPool->setRefSatChanged(sys, true); 799 str = " RESET "; 800 } 801 LOG << string(_epoTimeRover) << str.toStdString() << " REFSAT " << sys << ": " << prn.toString() << endl; 802 } 803 return success; 804 } 805 806 void t_pppClient::setHistoricalRefSats() { 807 QMapIterator<char, t_pppRefSat*> it(_refSatMap); 808 while (it.hasNext()) { 809 it.next(); 810 t_prn prn = it.value()->prn(); 811 char sys = prn.system(); 812 if (_obsPool->refSatChangeRequired(sys)) { 813 _historicalRefSats[sys].append(prn); 814 } 815 } 816 } 817 818 // 819 ////////////////////////////////////////////////////////////////////////////// 820 void t_pppClient::reset() {LOG << "t_pppClient::reset()" << endl; 766 void t_pppClient::reset() {cout << "t_pppClient::reset()" << endl; 821 767 822 768 // to delete old orbit and clock corrections … … 830 776 // to delete all parameters 831 777 delete _filter; 832 _filter = new t_pppFilter( _obsPool);833 834 } 778 _filter = new t_pppFilter(); 779 780 }
Note:
See TracChangeset
for help on using the changeset viewer.