Changeset 1138 in ntrip for trunk/BNC/bncgetthread.cpp


Ignore:
Timestamp:
Oct 2, 2008, 3:23:09 PM (16 years ago)
Author:
mervart
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/bncgetthread.cpp

    r1137 r1138  
    6262// Constructor
    6363////////////////////////////////////////////////////////////////////////////
     64bncGetThread::bncGetThread(const QByteArray& rawInpFileName,
     65                           const QByteArray& format) {
     66
     67  _decoder    = 0;
     68  _socket     = 0;
     69  _rawOutFile = 0;
     70  _format     = format;
     71 
     72  _rawInpFile = new QFile(rawInpFileName);
     73  _rawInpFile->open(QIODevice::ReadOnly);
     74}
     75
    6476bncGetThread::bncGetThread(const QUrl& mountPoint,
    6577                           const QByteArray& format,
     
    8294  _nextSleep  =  1;       //  1 second
    8395  _iMount     = iMount;   // index in mountpoints array
     96  _rawInpFile = 0;
    8497
    8598  // Check name conflict
     
    151164  // ----------
    152165  if (false) {    // special option used for testing
    153     QByteArray rawFileName = "./" + _staID + ".raw";
    154     _rawFile = new QFile(rawFileName);
    155     _rawFile->open(QIODevice::WriteOnly);
     166    QByteArray rawOutFileName = "./" + _staID + ".raw";
     167    _rawOutFile = new QFile(rawOutFileName);
     168    _rawOutFile->open(QIODevice::WriteOnly);
    156169  }
    157170  else {
    158     _rawFile = 0;
     171    _rawOutFile = 0;
    159172  }
    160173
     
    175188  delete _decoder;
    176189  delete _rnx;
    177   delete _rawFile;
     190  delete _rawInpFile;
     191  delete _rawOutFile;
    178192}
    179193
     
    297311t_irc bncGetThread::initRun() {
    298312
    299   // Initialize Socket
    300   // -----------------
    301   QString msg;
    302   _socket = this->request(_mountPoint, _latitude, _longitude,
    303                           _nmea, _timeOut, msg);
    304   if (!_socket) {
    305     return failure;
    306   }
    307 
    308   // Read Caster Response
    309   // --------------------
    310   _socket->waitForReadyRead(_timeOut);
    311   if (_socket->canReadLine()) {
    312     QString line = _socket->readLine();
    313 
    314     // Skip messages from proxy server
    315     // -------------------------------
    316     if (line.indexOf("ICY 200 OK") == -1 &&
    317         line.indexOf("200 OK")     != -1 ) {
    318       bool proxyRespond = true;
    319       while (true) {
    320         if (_socket->canReadLine()) {
    321           line = _socket->readLine();
    322           if (!proxyRespond) {
    323             break;
    324           }
    325           if (line.trimmed().isEmpty()) {
    326             proxyRespond = false;
    327           }
    328         }
    329         else {
    330           _socket->waitForReadyRead(_timeOut);
    331           if (_socket->bytesAvailable() <= 0) {
    332             break;
    333           }
    334         }
    335       }
    336     }
    337 
    338     if (line.indexOf("Unauthorized") != -1) {
    339       QStringList table;
    340       bncTableDlg::getFullTable(_mountPoint.host(), _mountPoint.port(), table);
    341       QString net;
    342       QStringListIterator it(table);
    343       while (it.hasNext()) {
    344         QString line = it.next();
    345         if (line.indexOf("STR") == 0) {
    346           QStringList tags = line.split(";");
    347           if (tags.at(1) == _staID_orig) {
    348             net = tags.at(7);
    349             break;
    350           }
    351         }
    352       }
    353 
    354       QString reg;
    355       it.toFront();
    356       while (it.hasNext()) {
    357         QString line = it.next();
    358         if (line.indexOf("NET") == 0) {
    359           QStringList tags = line.split(";");
    360           if (tags.at(1) == net) {
    361             reg = tags.at(7);
    362             break;
    363           }         
    364         }
    365       }
    366       emit(newMessage((_staID + ": Caster Response: " + line +
    367                        "          Adjust User-ID and Password Register, see"
    368                        "\n          " + reg).toAscii()));
    369       return fatal;
    370     }
    371     if (line.indexOf("ICY 200 OK") != 0) {
    372       emit(newMessage((_staID + ": Wrong Caster Response:\n" + line).toAscii()));
     313  if (!_rawInpFile) {
     314
     315    // Initialize Socket
     316    // -----------------
     317    QString msg;
     318    _socket = this->request(_mountPoint, _latitude, _longitude,
     319                            _nmea, _timeOut, msg);
     320    if (!_socket) {
    373321      return failure;
    374322    }
    375   }
    376   else {
    377     emit(newMessage(_staID + ": Response Timeout"));
    378     return failure;
     323   
     324    // Read Caster Response
     325    // --------------------
     326    _socket->waitForReadyRead(_timeOut);
     327    if (_socket->canReadLine()) {
     328      QString line = _socket->readLine();
     329   
     330      // Skip messages from proxy server
     331      // -------------------------------
     332      if (line.indexOf("ICY 200 OK") == -1 &&
     333          line.indexOf("200 OK")     != -1 ) {
     334        bool proxyRespond = true;
     335        while (true) {
     336          if (_socket->canReadLine()) {
     337            line = _socket->readLine();
     338            if (!proxyRespond) {
     339              break;
     340            }
     341            if (line.trimmed().isEmpty()) {
     342              proxyRespond = false;
     343            }
     344          }
     345          else {
     346            _socket->waitForReadyRead(_timeOut);
     347            if (_socket->bytesAvailable() <= 0) {
     348              break;
     349            }
     350          }
     351        }
     352      }
     353   
     354      if (line.indexOf("Unauthorized") != -1) {
     355        QStringList table;
     356        bncTableDlg::getFullTable(_mountPoint.host(), _mountPoint.port(), table);
     357        QString net;
     358        QStringListIterator it(table);
     359        while (it.hasNext()) {
     360          QString line = it.next();
     361          if (line.indexOf("STR") == 0) {
     362            QStringList tags = line.split(";");
     363            if (tags.at(1) == _staID_orig) {
     364              net = tags.at(7);
     365              break;
     366            }
     367          }
     368        }
     369   
     370        QString reg;
     371        it.toFront();
     372        while (it.hasNext()) {
     373          QString line = it.next();
     374          if (line.indexOf("NET") == 0) {
     375            QStringList tags = line.split(";");
     376            if (tags.at(1) == net) {
     377              reg = tags.at(7);
     378              break;
     379            }         
     380          }
     381        }
     382        emit(newMessage((_staID + ": Caster Response: " + line +
     383                         "          Adjust User-ID and Password Register, see"
     384                         "\n          " + reg).toAscii()));
     385        return fatal;
     386      }
     387      if (line.indexOf("ICY 200 OK") != 0) {
     388        emit(newMessage((_staID + ": Wrong Caster Response:\n" + line).toAscii()));
     389        return failure;
     390      }
     391    }
     392    else {
     393      emit(newMessage(_staID + ": Response Timeout"));
     394      return failure;
     395    }
    379396  }
    380397
     
    458475  while (true) {
    459476    try {
    460       if (_socket->state() != QAbstractSocket::ConnectedState) {
     477      if (_socket && _socket->state() != QAbstractSocket::ConnectedState) {
    461478        emit(newMessage(_staID + ": Socket not connected, reconnecting"));
    462479        tryReconnect();
     
    469486      _decoder->_obsList.clear();
    470487
    471       _socket->waitForReadyRead(_timeOut);
    472       qint64 nBytes = _socket->bytesAvailable();
     488      qint64 nBytes = 0;
     489
     490      if      (_socket) {
     491        _socket->waitForReadyRead(_timeOut);
     492        nBytes = _socket->bytesAvailable();
     493      }
     494      else if (_rawInpFile) {
     495        const qint64 maxBytes = 1024;
     496        nBytes = maxBytes;
     497      }
     498
    473499      if (nBytes > 0) {
    474500        emit newBytes(_staID, nBytes);
    475501
    476502        char* data = new char[nBytes];
    477         _socket->read(data, nBytes);
    478 
    479         if (_rawFile) {
    480           _rawFile->write(data, nBytes);
    481           _rawFile->flush();
     503
     504        if (_socket) {
     505          _socket->read(data, nBytes);
     506        }
     507        else if (_rawInpFile) {
     508          nBytes = _rawInpFile->read(data, nBytes);
     509          cout << "nBytes = " << nBytes << endl;
     510          if (nBytes <= 0) {
     511            cout << "no more data" << endl;
     512            ::exit(0);
     513          }
     514        }
     515
     516        if (_rawOutFile) {
     517          _rawOutFile->write(data, nBytes);
     518          _rawOutFile->flush();
    482519        }
    483520
Note: See TracChangeset for help on using the changeset viewer.