Changeset 658 in ntrip for trunk/BNC/bncgetthread.cpp
- Timestamp:
- Jan 28, 2008, 3:50:05 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/BNC/bncgetthread.cpp
r657 r658 103 103 _staID = _staID.left(_staID.length()-1) + QString("%1").arg(num).toAscii(); 104 104 } 105 106 // Notice threshold 107 // ---------------- 108 _inspSegm = settings.value("inspSegm").toInt(); 109 _noticeFail = settings.value("noticeFail").toInt(); 110 _noticeReco = settings.value("noticeReco").toInt(); 111 _noticeScript = settings.value("noticeScript").toString(); 112 expandEnvVar(_noticeScript); 105 113 106 114 // RINEX writer … … 374 382 } 375 383 384 bool decode = true; 385 int numSucc = 0; 386 int secSucc = 0; 387 int secFail = 0; 388 int initPause = 30; 389 int currPause = 0; 390 bool begCorrupt = false; 391 bool endCorrupt = false; 392 _decodeTime = QDateTime::currentDateTime(); 393 394 if (initPause < _inspSegm) { 395 initPause = _inspSegm; 396 } 397 if ( _noticeFail < 1 && _noticeReco < 1 ) { 398 initPause = 0; 399 } 400 currPause = initPause; 401 376 402 // Read Incoming Data 377 403 // ------------------ … … 397 423 _socket->read(data, nBytes); 398 424 399 if ( !_decodeFailure.isValid() || 400 _decodeFailure.secsTo(QDateTime::currentDateTime()) > 60 ) { 401 if ( _decoder->Decode(data, nBytes) == success ) { 402 _decodeFailure.setDate(QDate()); 403 _decodeFailure.setTime(QTime()); 404 } 405 else { 406 _decodeFailure = QDateTime::currentDateTime(); 425 if (_inspSegm<1) { 426 _decoder->Decode(data, nBytes); 427 } 428 else { 429 430 // Decode data 431 // ----------- 432 if (!_decodePause.isValid() || 433 _decodePause.secsTo(QDateTime::currentDateTime()) >= currPause ) { 434 435 if (decode) { 436 if ( _decoder->Decode(data, nBytes) == success ) { 437 numSucc += 1; 438 } 439 if ( _decodeTime.secsTo(QDateTime::currentDateTime()) > _inspSegm ) { 440 decode = false; 441 } 442 } 443 444 // Check - once per inspect segment 445 // -------------------------------- 446 if (!decode) { 447 _decodeTime = QDateTime::currentDateTime(); 448 if (numSucc>0) { 449 secSucc += _inspSegm; 450 if (secSucc > _noticeReco * 60) { 451 secSucc = _noticeReco * 60 + 1; 452 } 453 numSucc = 0; 454 currPause = initPause; 455 _decodePause.setDate(QDate()); 456 _decodePause.setTime(QTime()); 457 } 458 else { 459 secFail += _inspSegm; 460 secSucc = 0; 461 if (secFail > _noticeFail * 60) { 462 secFail = _noticeFail * 60 + 1; 463 } 464 if (!_decodePause.isValid()) { 465 _decodePause = QDateTime::currentDateTime(); 466 } 467 else { 468 _decodePause.setDate(QDate()); 469 _decodePause.setTime(QTime()); 470 secFail = secFail + currPause - _inspSegm; 471 currPause = currPause * 2; 472 if (currPause > 960) { 473 currPause = 960; 474 } 475 } 476 } 477 478 // End corrupt threshold 479 // --------------------- 480 if ( begCorrupt && !endCorrupt && secSucc > _noticeReco * 60 ) { 481 emit(newMessage(_staID + ": End_Corrupted threshold exceeded")); 482 callScript("End_Corrupted"); 483 endCorrupt = true; 484 begCorrupt = false; 485 secFail = 0; 486 } 487 else { 488 489 // Begin corrupt threshold 490 // ----------------------- 491 if ( !begCorrupt && secFail > _noticeFail * 60 ) { 492 emit(newMessage(_staID + ": Begin_Corrupted threshold exceeded")); 493 callScript("Begin_Corrupted"); 494 begCorrupt = true; 495 endCorrupt = false; 496 secSucc = 0; 497 numSucc = 0; 498 } 499 } 500 decode = true; 407 501 } 408 502 } 409 else { 410 if ( _decodeFailure.isValid() && 411 _decodeFailure.secsTo(QDateTime::currentDateTime()) < 5 && 412 _decoder->Decode(data, nBytes) == success ) { 413 _decodeFailure.setDate(QDate()); 414 _decodeFailure.setTime(QTime()); 415 } 416 } 503 } 504 505 // End outage threshold 506 // -------------------- 507 if ( _decodeStart.isValid() && _decodeStart.secsTo(QDateTime::currentDateTime()) > _noticeReco * 60 ) { 508 _decodeStart.setDate(QDate()); 509 _decodeStart.setTime(QTime()); 510 emit(newMessage(_staID + ": End_Outage threshold exceeded")); 511 callScript("End_Outage"); 512 } 417 513 418 514 delete [] data; … … 425 521 // ----------------------- 426 522 int week; 523 bool wrongEpoch = false; 427 524 double sec; 428 525 currentGPSWeeks(week, sec); … … 441 538 double dt = fabs(sec - obs->_o.GPSWeeks); 442 539 if (week != obs->_o.GPSWeek || dt > maxDt) { 443 emit( newMessage("Wrong observation epoch") ); 540 if (!wrongEpoch) { 541 emit( newMessage(_staID + ": Wrong observation epoch") ); 542 wrongEpoch = true; 543 } 444 544 delete obs; 445 545 continue; 546 } 547 else { 548 wrongEpoch = false; 446 549 } 447 550 … … 491 594 _rnx->setReconnectFlag(true); 492 595 } 596 if ( !_decodeStart.isValid()) { 597 _decodeStop = QDateTime::currentDateTime(); 598 } 493 599 while (1) { 494 600 delete _socket; _socket = 0; 495 601 sleep(_nextSleep); 496 602 if ( initRun() == success ) { 603 if ( !_decodeStop.isValid()) { 604 _decodeStart = QDateTime::currentDateTime(); 605 } 497 606 break; 498 607 } 499 608 else { 609 610 // Begin outage threshold 611 // ---------------------- 612 if ( _decodeStop.isValid() && _decodeStop.secsTo(QDateTime::currentDateTime()) > _noticeFail * 60 ) { 613 _decodeStop.setDate(QDate()); 614 _decodeStop.setTime(QTime()); 615 emit(newMessage(_staID + ": Begin_Outage threshold exceeded")); 616 callScript("Begin_Outage"); 617 } 500 618 _nextSleep *= 2; 501 619 if (_nextSleep > 256) { … … 507 625 _nextSleep = 1; 508 626 } 627 628 // Call notice advisory script 629 //////////////////////////////////////////////////////////////////////////// 630 void bncGetThread::callScript(const char* _comment) { 631 if (!_noticeScript.isEmpty()) { 632 #ifdef WIN32 633 QProcess::startDetached(_noticeScript, QStringList() << _staID << _comment) ; 634 #else 635 QProcess::startDetached("nohup", QStringList() << _noticeScript << _staID << _comment) ; 636 #endif 637 } 638 }
Note:
See TracChangeset
for help on using the changeset viewer.