Changeset 1377 in ntrip


Ignore:
Timestamp:
Dec 28, 2008, 11:36:11 PM (15 years ago)
Author:
mervart
Message:

* empty log message *

Location:
trunk/BNC
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/bncgetthread.cpp

    r1376 r1377  
    5454#include "bncrinex.h"
    5555#include "bnczerodecoder.h"
    56 #include "bncsocket.h"
     56#include "bncnetquery.h"
    5757
    5858#include "RTCM/RTCM2Decoder.h"
     
    120120
    121121  _decoder    = 0;
    122   _socket     = 0;
     122  _query      = 0;
    123123  _timeOut    = 20*1000; // 20 seconds
    124124  _nextSleep  = 1;       //  1 second
     
    288288////////////////////////////////////////////////////////////////////////////
    289289bncGetThread::~bncGetThread() {
    290   if (_socket) {
    291     _socket->close();
    292 #if QT_VERSION == 0x040203
    293     delete _socket;
    294 #else
    295     _socket->deleteLater();
    296 #endif
     290  if (_query) {
     291    _query->deleteLater();
    297292  }
    298293  delete _decoder;
     
    308303
    309304  if (!_rawInpFile) {
    310 
    311     // Initialize Socket
    312     // -----------------
    313     QString msg;
    314     delete _socket;
    315     _socket = new bncSocket;
    316     if (_socket->request(_mountPoint, _latitude, _longitude,
    317                          _nmea, _ntripVersion, _timeOut, msg) != success) {
    318       delete _socket;
    319       _socket = 0;
    320       return failure;
    321     }
    322    
    323     // Read Caster Response
    324     // --------------------
    325     if (_ntripVersion == "1") {
    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(),
    357                                     table);
    358           QString net;
    359           QStringListIterator it(table);
    360           while (it.hasNext()) {
    361             QString line = it.next();
    362             if (line.indexOf("STR") == 0) {
    363               QStringList tags = line.split(";");
    364               if (tags.at(1) == _staID_orig) {
    365                 net = tags.at(7);
    366                 break;
    367               }
    368             }
    369           }
    370      
    371           QString reg;
    372           it.toFront();
    373           while (it.hasNext()) {
    374             QString line = it.next();
    375             if (line.indexOf("NET") == 0) {
    376               QStringList tags = line.split(";");
    377               if (tags.at(1) == net) {
    378                 reg = tags.at(7);
    379                 break;
    380               }         
    381             }
    382           }
    383           emit(newMessage((_staID + ": Caster Response: " + line +
    384                            "          Adjust User-ID and Password Register, see"
    385                            "\n          " + reg).toAscii(), true));
    386           return fatal;
    387         }
    388         if (line.indexOf("ICY 200 OK") != 0) {
    389           emit(newMessage((_staID + ": Wrong Caster Response:\n" + line).toAscii(), true));
    390           return failure;
    391         }
    392       }
    393       else {
    394         emit(newMessage(_staID + ": Response Timeout", true));
    395         return failure;
    396       }
    397     }
     305    delete _query;
     306    _query = new bncNetQuery();
     307    _query->startRequest(_mountPoint);
    398308  }
    399309
     
    487397  while (true) {
    488398    try {
    489       if (_socket && _socket->state() != QAbstractSocket::ConnectedState) {
    490         emit(newMessage(_staID + ": Socket not connected, reconnecting", true));
     399      if (_query && _query->status() != bncNetQuery::running) {
     400        emit(newMessage(_staID + ": Internet query not running, reconnecting", true));
    491401        tryReconnect();
    492402      }
     
    500410      qint64 nBytes = 0;
    501411
    502       if      (_socket) {
    503         _socket->waitForReadyRead(_timeOut);
    504         nBytes = _socket->bytesAvailable();
     412      QByteArray data;
     413
     414      if      (_query) {
     415        _query->waitForReadyRead(data);
     416        nBytes = data.size();
    505417      }
    506418      else if (_rawInpFile) {
     
    512424        emit newBytes(_staID, nBytes);
    513425
    514         QByteArray data;
    515 
    516         if (_socket) {
    517           data = _socket->read(nBytes);
    518         }
    519         else if (_rawInpFile) {
     426        if (_rawInpFile) {
    520427          data = _rawInpFile->read(nBytes);
    521428          if (data.isEmpty()) {
     
    532439        if (_serialPort) {
    533440          _serialPort->write(data);
    534           ////          _serialPort->flush();
    535441        }
    536442
  • trunk/BNC/bncgetthread.h

    r1353 r1377  
    3737class bncRinex;
    3838class QextSerialPort;
    39 class bncSocket;
     39class bncNetQuery;
    4040
    4141class bncGetThread : public QThread {
     
    7979   void  callScript(const char* _comment);
    8080   GPSDecoder* _decoder;
    81    bncSocket*  _socket;
     81   bncNetQuery* _query;
    8282   QUrl        _mountPoint;
    8383   QByteArray  _staID;
Note: See TracChangeset for help on using the changeset viewer.