Changeset 6449 in ntrip


Ignore:
Timestamp:
Dec 26, 2014, 5:20:19 PM (9 years ago)
Author:
mervart
Message:
 
Location:
trunk/BNC/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/src/bnccaster.cpp

    r6447 r6449  
    112112  }
    113113
    114   _epochs = new QMultiMap<long, t_satObs>;
    115 
    116114  _samplingRate = settings.value("binSampl").toInt();
    117   _waitTime     = settings.value("waitTime").toInt();
    118   _lastDumpSec  = 0;
     115  _waitTime     = settings.value("waitTime").toDouble();
     116  if (_waitTime <= 0.0) {
     117    _waitTime = 0.01;
     118  }
    119119  _confInterval = -1;
    120120
     
    156156  delete _nmeaServer;
    157157  delete _nmeaSockets;
    158   delete _epochs;
    159158  delete _miscServer;
    160159  delete _miscSockets;
     
    175174    t_satObs& obs = it.next();
    176175
    177     long iSec    = long(floor(obs._time.gpssec()+0.5));
    178     long newTime = obs._time.gpsw() * 7*24*3600 + iSec;
    179    
    180176    // Rename the Station
    181177    // ------------------
     
    212208    }
    213209   
    214     // First time, set the _lastDumpSec immediately
    215     // --------------------------------------------
    216     if (_lastDumpSec == 0) {
    217       _lastDumpSec = newTime - 1;
     210    // First time: set the _lastDumpTime
     211    // ---------------------------------
     212    if (!_lastDumpTime.valid()) {
     213      _lastDumpTime = obs._time - 1.0;
    218214    }
    219215   
    220216    // An old observation - throw it away
    221217    // ----------------------------------
    222     if (newTime <= _lastDumpSec) {
     218    if (obs._time <= _lastDumpTime) {
    223219      if (index == 1) {
    224220        bncSettings settings;
    225221        if ( !settings.value("outFile").toString().isEmpty() ||
    226222             !settings.value("outPort").toString().isEmpty() ) {
    227    
    228           QTime enomtime = QTime(0,0,0).addSecs(iSec);
    229    
    230223          emit( newMessage(QString("%1: Old epoch %2 (%3) thrown away")
    231                            .arg(staID.data()).arg(iSec)
    232                            .arg(enomtime.toString("HH:mm:ss"))
     224                           .arg(staID.data()).arg(string(obs._time).c_str())
    233225                           .toAscii(), true) );
    234226        }
     
    239231    // Save the observation
    240232    // --------------------
    241     _epochs->insert(newTime, obs);
     233    _epochs[obs._time].push_back(obs);
    242234
    243235    // Dump Epochs
    244236    // -----------
    245     if (newTime - _waitTime > _lastDumpSec) {
    246       dumpEpochs(_lastDumpSec + 1, newTime - _waitTime);
    247       _lastDumpSec = newTime - _waitTime;
     237    if (obs._time - _waitTime > _lastDumpTime) {
     238      dumpEpochs(obs._time - _waitTime);
     239      _lastDumpTime = obs._time - _waitTime;
    248240    }
    249241  }
     
    324316// Dump Complete Epochs
    325317////////////////////////////////////////////////////////////////////////////
    326 void bncCaster::dumpEpochs(long minTime, long maxTime) {
    327 
    328   for (long sec = minTime; sec <= maxTime; sec++) {
    329 
    330     if ( (_out || _sockets) &&
    331          (_samplingRate == 0 || sec % _samplingRate == 0) ) {
    332 
    333       QList<t_satObs> allObs = _epochs->values(sec);
     318void bncCaster::dumpEpochs(const bncTime& maxTime) {
     319
     320  QMutableMapIterator<bncTime, QList<t_satObs> > itEpo(_epochs);
     321  while (itEpo.hasNext()) {
     322    itEpo.next();
     323    const bncTime& epoTime = itEpo.key();
     324    if (epoTime <= maxTime) {
     325      const QList<t_satObs>& allObs = itEpo.value();
     326      int sec = int(nint(epoTime.gpssec()));
     327      if ( (_out || _sockets) && (_samplingRate == 0 || sec % _samplingRate == 0) ) {
    334328     
    335       QListIterator<t_satObs> it(allObs);
    336       bool firstObs = true;
    337       while (it.hasNext()) {
    338         const t_satObs& obs = it.next();
    339 
    340         ostringstream oStr;
    341         oStr.setf(ios::showpoint | ios::fixed);
    342         if (firstObs) {
    343           firstObs = false;
    344           oStr << "> " << obs._time.gpsw() << ' '
    345                << setprecision(7) << obs._time.gpssec() << endl;;
    346         }
    347         oStr << obs._staID << ' ' << bncRinex::asciiSatLine(obs) << endl;
    348         if (!it.hasNext()) {
    349           oStr << endl;
    350         }
    351         string hlpStr = oStr.str();
    352 
    353         // Output into the File
    354         // --------------------
    355         if (_out) {
    356           *_out << hlpStr.c_str();
    357           _out->flush();
    358         }
    359 
    360         // Output into the socket
    361         // ----------------------
    362         if (_sockets) {
    363           QMutableListIterator<QTcpSocket*> is(*_sockets);
    364           while (is.hasNext()) {
    365             QTcpSocket* sock = is.next();
    366             if (sock->state() == QAbstractSocket::ConnectedState) {
    367               int numBytes = hlpStr.length();
    368               if (myWrite(sock, hlpStr.c_str(), numBytes) != numBytes) {
     329        QListIterator<t_satObs> it(allObs);
     330        bool firstObs = true;
     331        while (it.hasNext()) {
     332          const t_satObs& obs = it.next();
     333       
     334          ostringstream oStr;
     335          oStr.setf(ios::showpoint | ios::fixed);
     336          if (firstObs) {
     337            firstObs = false;
     338            oStr << "> " << obs._time.gpsw() << ' '
     339                 << setprecision(7) << obs._time.gpssec() << endl;;
     340          }
     341          oStr << obs._staID << ' ' << bncRinex::asciiSatLine(obs) << endl;
     342          if (!it.hasNext()) {
     343            oStr << endl;
     344          }
     345          string hlpStr = oStr.str();
     346       
     347          // Output into the File
     348          // --------------------
     349          if (_out) {
     350            *_out << hlpStr.c_str();
     351            _out->flush();
     352          }
     353       
     354          // Output into the socket
     355          // ----------------------
     356          if (_sockets) {
     357            QMutableListIterator<QTcpSocket*> is(*_sockets);
     358            while (is.hasNext()) {
     359              QTcpSocket* sock = is.next();
     360              if (sock->state() == QAbstractSocket::ConnectedState) {
     361                int numBytes = hlpStr.length();
     362                if (myWrite(sock, hlpStr.c_str(), numBytes) != numBytes) {
     363                  delete sock;
     364                  is.remove();
     365                }
     366              }
     367              else if (sock->state() != QAbstractSocket::ConnectingState) {
    369368                delete sock;
    370369                is.remove();
    371370              }
    372371            }
    373             else if (sock->state() != QAbstractSocket::ConnectingState) {
    374               delete sock;
    375               is.remove();
    376             }
    377372          }
    378373        }
    379374      }
    380     }
    381     _epochs->remove(sec);
     375      _epochs.remove(epoTime);
     376    }
    382377  }
    383378}
  • trunk/BNC/src/bnccaster.h

    r6447 r6449  
    6363
    6464 private:
    65    void dumpEpochs(long minTime, long maxTime);
     65   void dumpEpochs(const bncTime& maxTime);
    6666   static int myWrite(QTcpSocket* sock, const char* buf, int bufLen);
    6767   void reopenOutFile();
    6868
    69    QFile*                     _outFile;
    70    QTextStream*               _out;
    71    QMultiMap<long, t_satObs>* _epochs;
    72    long                       _lastDumpSec;
    73    QTcpServer*                _server;
    74    QTcpServer*                _uServer;
    75    QTcpServer*                _nmeaServer;
    76    QList<QTcpSocket*>*        _sockets;
    77    QList<QTcpSocket*>*        _uSockets;
    78    QList<QTcpSocket*>*        _nmeaSockets;
    79    QList<QByteArray>          _staIDs;
    80    QList<bncGetThread*>       _threads;
    81    int                        _samplingRate;
    82    long                       _waitTime;
    83    QMutex                     _mutex;
    84    int                        _confInterval;
    85    QString                    _miscMount;
    86    int                        _miscPort;
    87    QTcpServer*                _miscServer;
    88    QList<QTcpSocket*>*        _miscSockets;
     69   QFile*                          _outFile;
     70   QTextStream*                    _out;
     71   QMap<bncTime, QList<t_satObs> > _epochs;
     72   bncTime                         _lastDumpTime;
     73   QTcpServer*                     _server;
     74   QTcpServer*                     _uServer;
     75   QTcpServer*                     _nmeaServer;
     76   QList<QTcpSocket*>*             _sockets;
     77   QList<QTcpSocket*>*             _uSockets;
     78   QList<QTcpSocket*>*             _nmeaSockets;
     79   QList<QByteArray>               _staIDs;
     80   QList<bncGetThread*>            _threads;
     81   int                             _samplingRate;
     82   double                          _waitTime;
     83   QMutex                          _mutex;
     84   int                             _confInterval;
     85   QString                         _miscMount;
     86   int                             _miscPort;
     87   QTcpServer*                     _miscServer;
     88   QList<QTcpSocket*>*             _miscSockets;
    8989};
    9090
Note: See TracChangeset for help on using the changeset viewer.