Changeset 1558 in ntrip


Ignore:
Timestamp:
Feb 2, 2009, 2:31:28 PM (15 years ago)
Author:
mervart
Message:

* empty log message *

Location:
trunk/BNC
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/bnc.pro

    r1556 r1558  
    3030          bncconst.h bnchtml.h bnctableitem.h bnczerodecoder.h        \
    3131          bncnetquery.h bncnetqueryv1.h bncnetqueryv2.h               \
    32           bncnetqueryrtp.h bncsettings.h                              \
     32          bncnetqueryrtp.h bncsettings.h latencychecker.h             \
    3333          RTCM/GPSDecoder.h RTCM/RTCM2.h RTCM/RTCM2Decoder.h          \
    3434          RTCM/RTCM2_2021.h RTCM/rtcm_utils.h                         \
     
    4949          bncconst.cpp bnchtml.cpp bnchlpdlg.cpp bnctableitem.cpp     \
    5050          bnczerodecoder.cpp bncnetqueryv1.cpp bncnetqueryv2.cpp      \
    51           bncnetqueryrtp.cpp bncsettings.cpp                          \
     51          bncnetqueryrtp.cpp bncsettings.cpp latencychecker.cpp       \
    5252          RTCM/RTCM2.cpp RTCM/RTCM2Decoder.cpp                        \
    5353          RTCM/RTCM2_2021.cpp RTCM/rtcm_utils.cpp                     \
  • trunk/BNC/bncgetthread.cpp

    r1557 r1558  
    5858#include "bncnetqueryrtp.h"
    5959#include "bncsettings.h"
     60#include "latencychecker.h"
    6061
    6162#include "RTCM/RTCM2Decoder.h"
     
    277278  }
    278279
    279   _latencyChecker = new bncGetThread::latencyChecker(_staID);
     280  _latencyChecker = new latencyChecker(_staID);
    280281
    281282  msleep(100); //sleep 0.1 sec
     
    532533}
    533534
    534 // Constructor
    535 //////////////////////////////////////////////////////////////////////////////
    536 bncGetThread::latencyChecker::latencyChecker(QByteArray staID) {
    537 
    538   _staID = staID;
    539 
    540   bncApp* app = (bncApp*) qApp;
    541   connect(this, SIGNAL(newMessage(QByteArray,bool)),
    542           app, SLOT(slotMessage(const QByteArray,bool)));
    543 
    544   bncSettings settings;
    545 
    546   // Notice threshold
    547   // ----------------
    548   QString obsRate = settings.value("obsRate").toString();
    549   _inspSegm = 0;
    550   if      ( obsRate.isEmpty() ) {
    551     _inspSegm = 0;
    552   }
    553   else if ( obsRate.indexOf("5 Hz")   != -1 ) {
    554     _inspSegm = 20;
    555   }
    556   else if ( obsRate.indexOf("1 Hz")   != -1 ) {
    557     _inspSegm = 10;
    558   }
    559   else if ( obsRate.indexOf("0.5 Hz") != -1 ) {
    560     _inspSegm = 20;
    561   }
    562   else if ( obsRate.indexOf("0.2 Hz") != -1 ) {
    563     _inspSegm = 40;
    564   }
    565   else if ( obsRate.indexOf("0.1 Hz") != -1 ) {
    566     _inspSegm = 50;
    567   }
    568   _adviseFail = settings.value("adviseFail").toInt();
    569   _adviseReco = settings.value("adviseReco").toInt();
    570   if ( Qt::CheckState(settings.value("makePause").toInt()) == Qt::Checked) {
    571     _makePause = true;
    572   }
    573   else {
    574     _makePause = false;
    575   }
    576   _adviseScript = settings.value("adviseScript").toString();
    577   expandEnvVar(_adviseScript);
    578 
    579   // Latency interval/average
    580   // ------------------------
    581   _perfIntr = 0;
    582   QString perfIntr = settings.value("perfIntr").toString();
    583   if      ( perfIntr.isEmpty() ) {
    584     _perfIntr = 0;
    585   }
    586   else if ( perfIntr.indexOf("2 sec")   != -1 ) {
    587     _perfIntr = 2;
    588   }
    589   else if ( perfIntr.indexOf("10 sec")  != -1 ) {
    590     _perfIntr = 10;
    591   }
    592   else if ( perfIntr.indexOf("1 min")   != -1 ) {
    593     _perfIntr = 60;
    594   }
    595   else if ( perfIntr.indexOf("5 min")   != -1 ) {
    596     _perfIntr = 300;
    597   }
    598   else if ( perfIntr.indexOf("15 min")  != -1 ) {
    599     _perfIntr = 900;
    600   }
    601   else if ( perfIntr.indexOf("1 hour")  != -1 ) {
    602     _perfIntr = 3600;
    603   }
    604   else if ( perfIntr.indexOf("6 hours") != -1 ) {
    605     _perfIntr = 21600;
    606   }
    607   else if ( perfIntr.indexOf("1 day")   != -1 ) {
    608     _perfIntr = 86400;
    609   }
    610 
    611   // RTCM message types
    612   // ------------------
    613   _checkMountPoint = settings.value("miscMount").toString();
    614 
    615   // Initialize private members
    616   // --------------------------
    617   _maxDt      = 600.0;  // Check observation epoch
    618   _wrongEpoch = false;
    619   _decode     = true;
    620   _numSucc    = 0;
    621   _secSucc    = 0;
    622   _secFail    = 0;
    623   _initPause  = 30;  // Initial pause for corrupted streams
    624   _currPause  = 0;
    625   _begCorrupt = false;
    626   _endCorrupt = false;
    627   _followSec  = false;
    628   _oldSecGPS  = 0;
    629   _newSecGPS  = 0;
    630   _numGaps    = 0;
    631   _diffSecGPS = 0;
    632   _numLat     = 0;
    633   _sumLat     = 0.0;
    634   _sumLatQ    = 0.0;
    635   _meanDiff   = 0.0;
    636   _minLat     =  _maxDt;
    637   _maxLat     = -_maxDt;
    638   _curLat     = 0.0;
    639 
    640   _decodeTime = QDateTime::currentDateTime();
    641   _decodeSucc = QDateTime::currentDateTime();
    642 }
    643 
    644 // Destructor
    645 //////////////////////////////////////////////////////////////////////////////
    646 bncGetThread::latencyChecker::~latencyChecker() {
    647 
    648 }
    649 
    650 // Perform latency checks
    651 //////////////////////////////////////////////////////////////////////////////
    652 void bncGetThread::latencyChecker::check(GPSDecoder* decoder) {
    653 
    654   // Check - once per inspect segment
    655   // --------------------------------
    656   if (decoder->_obsList.size() > 0) {
    657 
    658     _decodeTime = QDateTime::currentDateTime();
    659 
    660     if (_numSucc > 0) {
    661       _secSucc += _inspSegm;
    662       _decodeSucc = QDateTime::currentDateTime();
    663       if (_secSucc > _adviseReco * 60) {
    664         _secSucc = _adviseReco * 60 + 1;
    665       }
    666       _numSucc = 0;
    667       _currPause = _initPause;
    668       _decodePause.setDate(QDate());
    669       _decodePause.setTime(QTime());
    670     }
    671     else {
    672       _secFail += _inspSegm;
    673       _secSucc = 0;
    674       if (_secFail > _adviseFail * 60) {
    675         _secFail = _adviseFail * 60 + 1;
    676       }
    677       if (!_decodePause.isValid() || !_makePause) {
    678         _decodePause = QDateTime::currentDateTime();
    679       }
    680       else {
    681         _decodePause.setDate(QDate());
    682         _decodePause.setTime(QTime());
    683         _secFail = _secFail + _currPause - _inspSegm;
    684         _currPause = _currPause * 2;
    685         if (_currPause > 960) {
    686           _currPause = 960;
    687         }
    688       }
    689     }
    690  
    691     // End corrupt threshold
    692     // ---------------------
    693     if ( _begCorrupt && !_endCorrupt && _secSucc > _adviseReco * 60 ) {
    694       _endDateCor = QDateTime::currentDateTime().addSecs(- _adviseReco * 60).toUTC().date().toString("yy-MM-dd");
    695       _endTimeCor = QDateTime::currentDateTime().addSecs(- _adviseReco * 60).toUTC().time().toString("hh:mm:ss");
    696       emit(newMessage((_staID + ": Recovery threshold exceeded, corruption ended "
    697                       + _endDateCor + " " + _endTimeCor).toAscii(), true));
    698       callScript(("End_Corrupted " + _endDateCor + " " + _endTimeCor + " Begin was " + _begDateCor + " " + _begTimeCor).toAscii());
    699       _endCorrupt = true;
    700       _begCorrupt = false;
    701       _secFail = 0;
    702     }
    703     else {
    704  
    705       // Begin corrupt threshold
    706       // -----------------------
    707       if ( !_begCorrupt && _secFail > _adviseFail * 60 ) {
    708         _begDateCor = _decodeSucc.toUTC().date().toString("yy-MM-dd");
    709         _begTimeCor = _decodeSucc.toUTC().time().toString("hh:mm:ss");
    710         emit(newMessage((_staID + ": Failure threshold exceeded, corrupted since "
    711                         + _begDateCor + " " + _begTimeCor).toAscii(), true));
    712         callScript(("Begin_Corrupted " + _begDateCor + " " + _begTimeCor).toAscii());
    713         _begCorrupt = true;
    714         _endCorrupt = false;
    715         _secSucc = 0;
    716         _numSucc = 0;
    717       }
    718     }
    719   }
    720      
    721   // End outage threshold
    722   // --------------------
    723   if ( _decodeStart.isValid() && _decodeStart.secsTo(QDateTime::currentDateTime()) > _adviseReco * 60 ) {
    724     _decodeStart.setDate(QDate());
    725     _decodeStart.setTime(QTime());
    726     if (_inspSegm > 0) {
    727       _endDateOut = QDateTime::currentDateTime().addSecs(- _adviseReco * 60).toUTC().date().toString("yy-MM-dd");
    728       _endTimeOut = QDateTime::currentDateTime().addSecs(- _adviseReco * 60).toUTC().time().toString("hh:mm:ss");
    729       emit(newMessage((_staID + ": Recovery threshold exceeded, outage ended "
    730                       + _endDateOut + " " + _endTimeOut).toAscii(), true));
    731       callScript(("End_Outage " + _endDateOut + " " + _endTimeOut + " Begin was " + _begDateOut + " " + _begTimeOut).toAscii());
    732     }
    733   }
    734      
    735   // Latency and completeness
    736   // ------------------------
    737   if ( _checkMountPoint == _staID || _checkMountPoint == "ALL" ) {
    738     if (_perfIntr > 0 ) {
    739 
    740       QListIterator<p_obs> it(decoder->_obsList);
    741       while (it.hasNext()) {
    742         p_obs obs = it.next();
    743      
    744         _newSecGPS = static_cast<int>(obs->_o.GPSWeeks);
    745         if (_newSecGPS != _oldSecGPS) {
    746           if (_newSecGPS % _perfIntr < _oldSecGPS % _perfIntr) {
    747             if (_numLat > 0) {
    748               if (_meanDiff > 0.0) {
    749                 emit( newMessage(QString("%1: Mean latency %2 sec, min %3, max %4, rms %5, %6 epochs, %7 gaps")
    750                   .arg(_staID.data())
    751                   .arg(int(_sumLat/_numLat*100)/100.)
    752                   .arg(int(_minLat*100)/100.)
    753                   .arg(int(_maxLat*100)/100.)
    754                   .arg(int((sqrt((_sumLatQ - _sumLat * _sumLat / _numLat)/_numLat))*100)/100.)
    755                   .arg(_numLat)
    756                   .arg(_numGaps)
    757                   .toAscii(), true) );
    758               } else {
    759                 emit( newMessage(QString("%1: Mean latency %2 sec, min %3, max %4, rms %5, %6 epochs")
    760                   .arg(_staID.data())
    761                   .arg(int(_sumLat/_numLat*100)/100.)
    762                   .arg(int(_minLat*100)/100.)
    763                   .arg(int(_maxLat*100)/100.)
    764                   .arg(int((sqrt((_sumLatQ - _sumLat * _sumLat / _numLat)/_numLat))*100)/100.)
    765                   .arg(_numLat)
    766                   .toAscii(), true) );
    767               }
    768             }
    769             _meanDiff  = _diffSecGPS / _numLat;
    770             _diffSecGPS = 0;
    771             _numGaps    = 0;
    772             _sumLat     = 0.0;
    773             _sumLatQ    = 0.0;
    774             _numLat     = 0;
    775             _minLat     = _maxDt;
    776             _maxLat     = -_maxDt;
    777           }
    778           if (_followSec) {
    779             _diffSecGPS += _newSecGPS - _oldSecGPS;
    780             if (_meanDiff>0.) {
    781               if (_newSecGPS - _oldSecGPS > 1.5 * _meanDiff) {
    782                 _numGaps += 1;
    783               }
    784             }
    785           }
    786 
    787           // Compute the observations latency
    788           // --------------------------------
    789           int week;
    790           double sec;
    791           currentGPSWeeks(week, sec);
    792           const double secPerWeek = 7.0 * 24.0 * 3600.0;
    793           if (week < obs->_o.GPSWeek) {
    794             week += 1;
    795             sec  -= secPerWeek;
    796           }
    797           if (week > obs->_o.GPSWeek) {
    798             week -= 1;
    799             sec  += secPerWeek;
    800           }
    801 
    802           _curLat   = sec - obs->_o.GPSWeeks;
    803           _sumLat  += _curLat;
    804           _sumLatQ += _curLat * _curLat;
    805           if (_curLat < _minLat) {
    806             _minLat = _curLat;
    807           }
    808           if (_curLat >= _maxLat) {
    809             _maxLat = _curLat;
    810           }
    811           _numLat += 1;
    812           _oldSecGPS = _newSecGPS;
    813           _followSec = true;
    814         }
    815       }
    816     }
    817   }
    818 }
    819 
    820 // Call advisory notice script   
    821 ////////////////////////////////////////////////////////////////////////////
    822 void bncGetThread::latencyChecker::callScript(const char* comment) {
    823   if (!_adviseScript.isEmpty()) {
    824     msleep(1);
    825 #ifdef WIN32
    826     QProcess::startDetached(_adviseScript, QStringList() << _staID << comment) ;
    827 #else
    828     QProcess::startDetached("nohup", QStringList() << _adviseScript << _staID << comment) ;
    829 #endif
    830   }
    831 }
  • trunk/BNC/bncgetthread.h

    r1557 r1558  
    3838class QextSerialPort;
    3939class bncNetQuery;
     40class latencyChecker;
    4041
    4142class bncGetThread : public QThread {
     
    7475
    7576 private:
    76 
    77    class latencyChecker : public QObject {
    78    Q_OBJECT
    79    public:
    80      latencyChecker(QByteArray staID);
    81      ~latencyChecker();
    82      void check(GPSDecoder* decoder);
    83    signals:
    84      void newMessage(QByteArray msg, bool showOnScreen);
    85    private:
    86      void callScript(const char* comment);
    87      int        _inspSegm;
    88      int        _adviseFail;
    89      int        _adviseReco;
    90      int        _perfIntr;
    91      int        _numSucc;
    92      int        _secSucc;
    93      int        _secFail;
    94      int        _initPause;
    95      int        _currPause;
    96      int        _oldSecGPS;
    97      int        _newSecGPS;
    98      int        _numGaps;
    99      int        _diffSecGPS;
    100      int        _numLat;
    101      bool       _makePause;
    102      bool       _wrongEpoch;
    103      bool       _decode;
    104      bool       _begCorrupt;
    105      bool       _endCorrupt;
    106      bool       _followSec;
    107      double     _maxDt;
    108      double     _sumLat;
    109      double     _sumLatQ;
    110      double     _meanDiff;
    111      double     _minLat;
    112      double     _maxLat;
    113      double     _curLat;
    114      QByteArray _staID;
    115      QString    _adviseScript;
    116      QString    _checkMountPoint;
    117      QString    _begDateCor;
    118      QString    _begTimeCor;
    119      QString    _begDateOut;
    120      QString    _begTimeOut;
    121      QString    _endDateCor;
    122      QString    _endTimeCor;
    123      QString    _endDateOut;
    124      QString    _endTimeOut;
    125      QDateTime  _decodeTime;
    126      QDateTime  _decodeSucc;
    127      QDateTime  _decodeFailure;
    128      QDateTime  _decodeStart;
    129      QDateTime  _decodeStop;
    130      QDateTime  _decodePause;
    131    };
    132 
    13377   void  initialize();
    13478   t_irc tryReconnect();
Note: See TracChangeset for help on using the changeset viewer.