- Timestamp:
- Dec 25, 2011, 7:40:52 PM (13 years ago)
- Location:
- branches/BNC_LM
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/BNC_LM/bncgetthread.cpp
r3571 r3572 52 52 #include "bncapp.h" 53 53 #include "bncutils.h" 54 #include "bncrinex.h"55 54 #include "bnczerodecoder.h" 56 55 #include "bncnetqueryv0.h" … … 93 92 const QByteArray& longitude, 94 93 const QByteArray& nmea, 95 const QByteArray& ntripVersion, 96 const QByteArray& staIDextra) { 94 const QByteArray& ntripVersion) { 97 95 _rawFile = 0; 98 96 _mountPoint = mountPoint; 99 97 _staID = mountPoint.path().mid(1).toAscii(); 100 _staID_extra = staIDextra;101 98 _format = format; 102 99 _latitude = latitude; … … 111 108 112 109 initialize(); 110 initDecoder(); 113 111 } 114 112 … … 116 114 //////////////////////////////////////////////////////////////////////////// 117 115 void bncGetThread::initialize() { 116 117 bncSettings settings; 118 118 119 119 setTerminationEnabled(true); … … 125 125 126 126 _isToBeDeleted = false; 127 _decoder = 0;128 127 _query = 0; 129 128 _nextSleep = 0; 130 129 _PPPclient = 0; 131 132 bncSettings settings; 133 134 _miscMount = settings.value("miscMount").toString(); 135 136 // RINEX writer 137 // ------------ 138 _samplingRate = settings.value("rnxSampl").toInt(); 139 if ( settings.value("rnxPath").toString().isEmpty() ) { 140 _rnx = 0; 141 } 142 else { 143 _rnx = new bncRinex(_staID, _mountPoint, _latitude, 144 _longitude, _nmea, _ntripVersion); 145 } 130 _miscMount = settings.value("miscMount").toString(); 131 _decoder = 0; 146 132 147 133 // Serial Port … … 151 137 _serialPort = 0; 152 138 153 if (settings.value("serialMountPoint").toString() == _staID) { 139 if (!_staID.isEmpty() && 140 settings.value("serialMountPoint").toString() == _staID) { 154 141 _serialPort = new QextSerialPort(settings.value("serialPortName").toString() ); 155 142 _serialPort->setTimeout(0,100); … … 279 266 } 280 267 268 if (!_staID.isEmpty()) { 269 _latencyChecker = new latencyChecker(_staID); 270 } 271 else { 272 _latencyChecker = 0; 273 } 274 } 275 276 // Instantiate the decoder 277 ////////////////////////////////////////////////////////////////////////////// 278 t_irc bncGetThread::initDecoder() { 279 280 _decoder = 0; 281 282 if (_format.indexOf("RTCM_2") != -1 || _format.indexOf("RTCM2") != -1 || 283 _format.indexOf("RTCM 2") != -1 ) { 284 emit(newMessage(_staID + ": Get data in RTCM 2.x format", true)); 285 _decoder = new RTCM2Decoder(_staID.data()); 286 } 287 else if (_format.indexOf("RTCM_3") != -1 || _format.indexOf("RTCM3") != -1 || 288 _format.indexOf("RTCM 3") != -1 ) { 289 emit(newMessage(_staID + ": Get data in RTCM 3.x format", true)); 290 RTCM3Decoder* newDecoder = new RTCM3Decoder(_staID, _rawFile); 291 _decoder = newDecoder; 292 connect((RTCM3Decoder*) newDecoder, SIGNAL(newMessage(QByteArray,bool)), 293 this, SIGNAL(newMessage(QByteArray,bool))); 294 } 295 else if (_format.indexOf("GPSS") != -1 || _format.indexOf("BNC") != -1) { 296 emit(newMessage(_staID + ": Get Data in GPSS format", true)); 297 _decoder = new gpssDecoder(); 298 } 299 else if (_format.indexOf("ZERO") != -1) { 300 emit(newMessage(_staID + ": Get data in original format", true)); 301 _decoder = new bncZeroDecoder(_staID); 302 } 303 else if (_format.indexOf("RTNET") != -1) { 304 emit(newMessage(_staID + ": Get data in RTNet format", true)); 305 _decoder = new bncRtnetDecoder(); 306 } 307 else if (_format.indexOf("HASS2ASCII") != -1) { 308 emit(newMessage(_staID + ": Get data in HASS2ASCII format", true)); 309 _decoder = new hassDecoder(_staID); 310 } 311 else { 312 emit(newMessage(_staID + ": Unknown data format " + _format, true)); 313 _isToBeDeleted = true; 314 return failure; 315 } 316 317 msleep(100); //sleep 0.1 sec 318 319 //// _decoder->initRinex(_staID, _mountPoint, _latitude, _longitude, 320 //// _nmea, _ntripVersion); 321 322 if (_rawFile) { 323 _decodersRaw[_staID] = _decoder; 324 } 325 281 326 // Initialize PPP Client? 282 327 // ---------------------- 283 328 #ifndef MLS_SOFTWARE 329 bncSettings settings; 284 330 if (settings.value("pppMount").toString() == _staID) { 285 331 _PPPclient = new bncPPPclient(_staID); 332 bncApp* app = (bncApp*) qApp; 286 333 app->_bncPPPclient = _PPPclient; 287 334 qRegisterMetaType<bncTime>("bncTime"); … … 293 340 #endif 294 341 295 // Instantiate the decoder 296 // ----------------------- 297 if (_format.indexOf("RTCM_2") != -1 || _format.indexOf("RTCM2") != -1 || 298 _format.indexOf("RTCM 2") != -1 ) { 299 emit(newMessage(_staID + ": Get data in RTCM 2.x format", true)); 300 _decoder = new RTCM2Decoder(_staID.data()); 301 } 302 else if (_format.indexOf("RTCM_3") != -1 || _format.indexOf("RTCM3") != -1 || 303 _format.indexOf("RTCM 3") != -1 ) { 304 emit(newMessage(_staID + ": Get data in RTCM 3.x format", true)); 305 _decoder = new RTCM3Decoder(_staID, _rawFile); 306 connect((RTCM3Decoder*) _decoder, SIGNAL(newMessage(QByteArray,bool)), 307 this, SIGNAL(newMessage(QByteArray,bool))); 308 } 309 else if (_format.indexOf("GPSS") != -1 || _format.indexOf("BNC") != -1) { 310 emit(newMessage(_staID + ": Get Data in GPSS format", true)); 311 _decoder = new gpssDecoder(); 312 } 313 else if (_format.indexOf("ZERO") != -1) { 314 emit(newMessage(_staID + ": Get data in original format", true)); 315 _decoder = new bncZeroDecoder(_staID); 316 } 317 else if (_format.indexOf("RTNET") != -1) { 318 emit(newMessage(_staID + ": Get data in RTNet format", true)); 319 _decoder = new bncRtnetDecoder(); 320 } 321 else if (_format.indexOf("HASS2ASCII") != -1) { 322 emit(newMessage(_staID + ": Get data in HASS format", true)); 323 _decoder = new hassDecoder(_staID); 342 return success; 343 } 344 345 // Current decoder in use 346 //////////////////////////////////////////////////////////////////////////// 347 GPSDecoder* bncGetThread::decoder() { 348 if (!_rawFile) { 349 return _decoder; 324 350 } 325 351 else { 326 emit(newMessage(_staID + ": Unknown data format " + _format, true)); 327 _isToBeDeleted = true; 328 } 329 330 _latencyChecker = new latencyChecker(_staID); 331 332 msleep(100); //sleep 0.1 sec 352 if (_decodersRaw.contains(_staID) || initDecoder() == success) { 353 return _decodersRaw[_staID]; 354 } 355 } 356 return 0; 333 357 } 334 358 … … 344 368 } 345 369 delete _PPPclient; 346 delete _decoder; 347 delete _rnx; 370 if (_rawFile) { 371 QMapIterator<QString, GPSDecoder*> it(_decodersRaw); 372 while (it.hasNext()) { 373 it.next(); 374 delete it.value(); 375 } 376 } 377 else { 378 delete _decoder; 379 } 348 380 delete _rawFile; 349 381 delete _serialOutFile; … … 375 407 376 408 if (tryReconnect() != success) { 377 _latencyChecker->checkReconnect(); 409 if (_latencyChecker) { 410 _latencyChecker->checkReconnect(); 411 } 378 412 continue; 379 413 } … … 381 415 // Delete old observations 382 416 // ----------------------- 383 _decoder->_obsList.clear(); 417 if (_rawFile) { 418 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw); 419 while (itDec.hasNext()) { 420 itDec.next(); 421 GPSDecoder* decoder = itDec.value(); 422 decoder->_obsList.clear(); 423 } 424 } 425 else { 426 _decoder->_obsList.clear(); 427 } 384 428 385 429 // Read Data … … 391 435 else if (_rawFile) { 392 436 data = _rawFile->readChunk(); 437 _format = _rawFile->format(); 438 _staID = _rawFile->staID(); 393 439 394 440 if (data.isEmpty()) { 395 441 cout << "no more data" << endl; 442 ((bncApp*) qApp)->stopCombination(); 396 443 QThread::exit(0); 397 this->deleteLater();398 return;444 delete this; 445 ::exit(0); 399 446 } 400 447 } … … 404 451 // ------------------ 405 452 if (nBytes == 0) { 406 _latencyChecker->checkReconnect(); 453 if (_latencyChecker) { 454 _latencyChecker->checkReconnect(); 455 } 407 456 emit(newMessage(_staID + ": Data timeout, reconnecting", true)); 408 457 msleep(10000); //sleep 10 sec, G. Weber … … 428 477 // ----------- 429 478 vector<string> errmsg; 430 _decoder->_obsList.clear(); 431 t_irc irc = _decoder->Decode(data.data(), data.size(), errmsg); 479 if (!decoder()) { 480 _isToBeDeleted = true; 481 continue; 482 } 483 decoder()->_obsList.clear(); 484 t_irc irc = decoder()->Decode(data.data(), data.size(), errmsg); 432 485 433 486 // Perform various scans and checks 434 487 // -------------------------------- 435 _latencyChecker->checkOutage(irc == success); 436 _latencyChecker->checkObsLatency(_decoder->_obsList); 437 _latencyChecker->checkCorrLatency(_decoder->corrGPSEpochTime()); 438 439 emit newLatency(_staID, _latencyChecker->currentLatency()); 488 if (_latencyChecker) { 489 _latencyChecker->checkOutage(irc == success); 490 _latencyChecker->checkObsLatency(decoder()->_obsList); 491 _latencyChecker->checkCorrLatency(decoder()->corrGPSEpochTime()); 492 493 emit newLatency(_staID, _latencyChecker->currentLatency()); 494 } 440 495 441 496 scanRTCM(); … … 443 498 // Loop over all observations (observations output) 444 499 // ------------------------------------------------ 445 QListIterator<t_obs> it( _decoder->_obsList);500 QListIterator<t_obs> it(decoder()->_obsList); 446 501 bool firstObs = true; 447 502 while (it.hasNext()) { … … 455 510 // Check observation epoch 456 511 // ----------------------- 457 if (!_rawFile && !dynamic_cast<gpssDecoder*>( _decoder)) {512 if (!_rawFile && !dynamic_cast<gpssDecoder*>(decoder())) { 458 513 int week; 459 514 double sec; … … 469 524 // Check observations coming twice (e.g. KOUR0 Problem) 470 525 // ---------------------------------------------------- 471 QMap<QString, long>::const_iterator it = _prnLastEpo.find(prn); 472 if (it != _prnLastEpo.end()) { 473 long oldTime = it.value(); 474 if (obsTime < oldTime) { 475 emit( newMessage(_staID + 476 ": old observation " + prn.toAscii(), false)); 477 continue; 526 if (!_rawFile) { 527 QMap<QString, long>::const_iterator it = _prnLastEpo.find(prn); 528 if (it != _prnLastEpo.end()) { 529 long oldTime = it.value(); 530 if (obsTime < oldTime) { 531 emit( newMessage(_staID + 532 ": old observation " + prn.toAscii(), false)); 533 continue; 534 } 535 else if (obsTime == oldTime) { 536 emit( newMessage(_staID + 537 ": observation coming more than once " + prn.toAscii(), false)); 538 continue; 539 } 478 540 } 479 else if (obsTime == oldTime) { 480 emit( newMessage(_staID + 481 ": observation coming more than once " + prn.toAscii(), false)); 482 continue; 483 } 484 } 485 _prnLastEpo[prn] = obsTime; 486 487 // RINEX Output 488 // ------------ 489 if (_rnx) { 490 if (_samplingRate == 0 || iSec % _samplingRate == 0) { 491 _rnx->deepCopy(obs); 492 } 493 _rnx->dumpEpoch(_format, obsTime); 494 } 495 541 _prnLastEpo[prn] = obsTime; 542 } 543 544 //// decoder()->dumpRinexEpoch(obs, _format); 545 496 546 // PPP Client 497 547 // ---------- 498 548 #ifndef MLS_SOFTWARE 499 if (_PPPclient ) {549 if (_PPPclient && _staID == _PPPclient->staID()) { 500 550 _PPPclient->putNewObs(obs); 501 551 } … … 509 559 firstObs = false; 510 560 } 511 _decoder->_obsList.clear();561 decoder()->_obsList.clear(); 512 562 } 513 563 catch (Exception& exc) { … … 530 580 if (_query && _query->status() == bncNetQuery::running) { 531 581 _nextSleep = 0; 532 if (_rnx) { 533 _rnx->setReconnectFlag(false); 582 if (_rawFile) { 583 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw); 584 while (itDec.hasNext()) { 585 itDec.next(); 586 GPSDecoder* decoder = itDec.value(); 587 /// decoder->setRinexReconnectFlag(false); 588 } 589 } 590 else { 591 /// _decoder->setRinexReconnectFlag(false); 534 592 } 535 593 return success; … … 593 651 } 594 652 595 if (_rnx) { 596 _rnx->setReconnectFlag(true); 653 if (_rawFile) { 654 QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw); 655 while (itDec.hasNext()) { 656 itDec.next(); 657 GPSDecoder* decoder = itDec.value(); 658 /// decoder->setRinexReconnectFlag(false); 659 } 660 } 661 else { 662 /// _decoder->setRinexReconnectFlag(false); 597 663 } 598 664 … … 604 670 void bncGetThread::scanRTCM() { 605 671 672 if (!decoder()) { 673 return; 674 } 675 606 676 bncSettings settings; 607 677 if ( Qt::CheckState(settings.value("scanRTCM").toInt()) == Qt::Checked ) { … … 611 681 // RTCM message types 612 682 // ------------------ 613 for (int ii = 0; ii < _decoder->_typeList.size(); ii++) {614 QString type = QString("%1 ").arg( _decoder->_typeList[ii]);683 for (int ii = 0; ii <decoder()->_typeList.size(); ii++) { 684 QString type = QString("%1 ").arg(decoder()->_typeList[ii]); 615 685 emit(newMessage(_staID + ": Received message type " + type.toAscii(), true)); 616 686 } … … 618 688 // RTCMv3 antenna descriptor 619 689 // ------------------------- 620 for (int ii=0;ii< _decoder->_antType.size();ii++) {621 QString ant1 = QString("%1 ").arg( _decoder->_antType[ii]);690 for (int ii=0;ii<decoder()->_antType.size();ii++) { 691 QString ant1 = QString("%1 ").arg(decoder()->_antType[ii]); 622 692 emit(newMessage(_staID + ": Antenna descriptor " + ant1.toAscii(), true)); 623 693 } … … 625 695 // RTCM Antenna Coordinates 626 696 // ------------------------ 627 for (int ii=0; ii < _decoder->_antList.size(); ii++) {697 for (int ii=0; ii <decoder()->_antList.size(); ii++) { 628 698 QByteArray antT; 629 if ( _decoder->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {699 if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) { 630 700 antT = "ARP"; 631 701 } 632 else if ( _decoder->_antList[ii].type == GPSDecoder::t_antInfo::APC) {702 else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) { 633 703 antT = "APC"; 634 704 } 635 705 QByteArray ant1, ant2, ant3; 636 ant1 = QString("%1 ").arg( _decoder->_antList[ii].xx,0,'f',4).toAscii();637 ant2 = QString("%1 ").arg( _decoder->_antList[ii].yy,0,'f',4).toAscii();638 ant3 = QString("%1 ").arg( _decoder->_antList[ii].zz,0,'f',4).toAscii();706 ant1 = QString("%1 ").arg(decoder()->_antList[ii].xx,0,'f',4).toAscii(); 707 ant2 = QString("%1 ").arg(decoder()->_antList[ii].yy,0,'f',4).toAscii(); 708 ant3 = QString("%1 ").arg(decoder()->_antList[ii].zz,0,'f',4).toAscii(); 639 709 emit(newMessage(_staID + ": " + antT + " (ITRF) X " + ant1 + "m", true)); 640 710 emit(newMessage(_staID + ": " + antT + " (ITRF) Y " + ant2 + "m", true)); 641 711 emit(newMessage(_staID + ": " + antT + " (ITRF) Z " + ant3 + "m", true)); 642 if ( _decoder->_antList[ii].height_f) {643 QByteArray ant4 = QString("%1 ").arg( _decoder->_antList[ii].height,0,'f',4).toAscii();712 if (decoder()->_antList[ii].height_f) { 713 QByteArray ant4 = QString("%1 ").arg(decoder()->_antList[ii].height,0,'f',4).toAscii(); 644 714 emit(newMessage(_staID + ": Antenna height above marker " + ant4 + "m", true)); 645 715 } 646 emit(newAntCrd(_staID, _decoder->_antList[ii].xx,647 _decoder->_antList[ii].yy, _decoder->_antList[ii].zz,716 emit(newAntCrd(_staID, decoder()->_antList[ii].xx, 717 decoder()->_antList[ii].yy, decoder()->_antList[ii].zz, 648 718 antT)); 649 719 } … … 652 722 653 723 #ifdef MLS_SOFTWARE 654 for (int ii=0; ii < _decoder->_antList.size(); ii++) {724 for (int ii=0; ii <decoder()->_antList.size(); ii++) { 655 725 QByteArray antT; 656 if ( _decoder->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {726 if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) { 657 727 antT = "ARP"; 658 728 } 659 else if ( _decoder->_antList[ii].type == GPSDecoder::t_antInfo::APC) {729 else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) { 660 730 antT = "APC"; 661 731 } 662 emit(newAntCrd(_staID, _decoder->_antList[ii].xx,663 _decoder->_antList[ii].yy, _decoder->_antList[ii].zz,732 emit(newAntCrd(_staID, decoder()->_antList[ii].xx, 733 decoder()->_antList[ii].yy, decoder()->_antList[ii].zz, 664 734 antT)); 665 735 } 666 736 667 for (int ii = 0; ii < _decoder->_typeList.size(); ii++) {668 emit(newRTCMMessage(_staID, _decoder->_typeList[ii]));737 for (int ii = 0; ii <decoder()->_typeList.size(); ii++) { 738 emit(newRTCMMessage(_staID, decoder()->_typeList[ii])); 669 739 } 670 740 #endif 671 741 672 673 674 675 _decoder->_typeList.clear(); 676 _decoder->_antType.clear(); 677 _decoder->_antList.clear(); 742 decoder()->_typeList.clear(); 743 decoder()->_antType.clear(); 744 decoder()->_antList.clear(); 678 745 } 679 746 … … 704 771 } 705 772 } 706 707 //708 //////////////////////////////////////////////////////////////////////////////709 void bncGetThread::slotNewEphGPS(gpsephemeris gpseph) {710 RTCM2Decoder* decoder2 = dynamic_cast<RTCM2Decoder*>(_decoder);711 RTCM3Decoder* decoder3 = dynamic_cast<RTCM3Decoder*>(_decoder);712 713 if ( decoder2 ) {714 QMutexLocker locker(&_mutex);715 716 string storedPRN;717 vector<int> IODs;718 719 if ( decoder2->storeEph(gpseph, storedPRN, IODs) ) {720 #ifdef DEBUG_RTCM2_2021721 QString msg = _staID + QString(": stored eph %1 IODs").arg(storedPRN.c_str());722 723 for (unsigned ii = 0; ii < IODs.size(); ii++) {724 msg += QString(" %1").arg(IODs[ii],4);725 }726 727 emit(newMessage(msg.toAscii()));728 #endif729 }730 }731 732 if ( decoder3 ) {733 QMutexLocker locker(&_mutex);734 735 if ( decoder3->storeEph(gpseph) ) {736 #ifdef DEBUG_RTCM3737 QString msg = _staID + QString(": RTCM3Decoder, stored eph for satellite %1").arg(gpseph.satellite);738 emit(newMessage(msg.toAscii(),true));739 #endif740 }741 }742 }743 -
branches/BNC_LM/bncgetthread.h
r3510 r3572 38 38 #include "bncrawfile.h" 39 39 40 class bncRinex;41 40 class QextSerialPort; 42 41 class latencyChecker; … … 53 52 const QByteArray& longitude, 54 53 const QByteArray& nmea, 55 const QByteArray& ntripVersion, 56 const QByteArray& staIDextra = ""); 54 const QByteArray& ntripVersion); 57 55 58 56 bncNetQuery::queryStatus queryStatus() { … … 72 70 73 71 QByteArray staID() const {return _staID;} 74 QByteArray staIDextra() const {return _staID_extra;}75 72 QUrl mountPoint() const {return _mountPoint;} 76 73 QByteArray latitude() const {return _latitude;} … … 92 89 virtual void run(); 93 90 94 public slots:95 void slotNewEphGPS(gpsephemeris gpseph);96 97 91 private slots: 98 92 void slotSerialReadyRead(); … … 100 94 private: 101 95 enum t_serialNMEA {NO_NMEA, MANUAL_NMEA, AUTO_NMEA}; 96 t_irc initDecoder(); 97 GPSDecoder* decoder(); 102 98 103 99 void initialize(); … … 105 101 void scanRTCM(); 106 102 107 GPSDecoder* _decoder; 108 bncNetQuery* _query; 109 QUrl _mountPoint; 110 QByteArray _staID; 111 QByteArray _staID_extra; 112 QByteArray _format; 113 QByteArray _latitude; 114 QByteArray _longitude; 115 QByteArray _height; 116 QByteArray _nmea; 117 QByteArray _ntripVersion; 118 int _nextSleep; 119 int _iMount; 120 int _samplingRate; 121 bncRinex* _rnx; 122 bncRawFile* _rawFile; 123 QextSerialPort* _serialPort; 124 bool _isToBeDeleted; 125 latencyChecker* _latencyChecker; 126 QString _miscMount; 127 QFile* _serialOutFile; 128 t_serialNMEA _serialNMEA; 129 QMutex _mutex; 130 bncPPPclient* _PPPclient; 131 bool _rawOutput; 132 QMap<QString, long> _prnLastEpo; 103 QMap<QString, GPSDecoder*> _decodersRaw; 104 GPSDecoder* _decoder; 105 bncNetQuery* _query; 106 QUrl _mountPoint; 107 QByteArray _staID; 108 QByteArray _format; 109 QByteArray _latitude; 110 QByteArray _longitude; 111 QByteArray _height; 112 QByteArray _nmea; 113 QByteArray _ntripVersion; 114 int _nextSleep; 115 int _iMount; 116 bncRawFile* _rawFile; 117 QextSerialPort* _serialPort; 118 bool _isToBeDeleted; 119 latencyChecker* _latencyChecker; 120 QString _miscMount; 121 QFile* _serialOutFile; 122 t_serialNMEA _serialNMEA; 123 bncPPPclient* _PPPclient; 124 bool _rawOutput; 125 QMap<QString, long> _prnLastEpo; 133 126 }; 134 127
Note:
See TracChangeset
for help on using the changeset viewer.