Changeset 1783 in ntrip


Ignore:
Timestamp:
Apr 8, 2009, 1:14:21 PM (13 years ago)
Author:
mervart
Message:

* empty log message *

Location:
trunk/BNC
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/bncnetqueryudp0.cpp

    r1779 r1783  
    3030////////////////////////////////////////////////////////////////////////////
    3131bncNetQueryUdp0::bncNetQueryUdp0() {
    32   _port      = 0;
    3332  _udpSocket = 0;
    34   _eventLoop = new QEventLoop(this);
    35 
    36   _keepAlive[ 0] = 128;
    37   _keepAlive[ 1] =  96;
    38   for (int ii = 2; ii <=11; ii++) {
    39     _keepAlive[ii] = 0;
    40   }
    4133}
    4234
     
    4436////////////////////////////////////////////////////////////////////////////
    4537bncNetQueryUdp0::~bncNetQueryUdp0() {
    46   delete _eventLoop;
    4738  delete _udpSocket;
    4839}
     
    5142////////////////////////////////////////////////////////////////////////////
    5243void bncNetQueryUdp0::stop() {
    53   _eventLoop->quit();
     44#ifndef sparc
     45  if (_udpSocket) {
     46    _udpSocket->abort();
     47  }
     48#endif
    5449  _status = finished;
    55 }
    56 
    57 //
    58 ////////////////////////////////////////////////////////////////////////////
    59 void bncNetQueryUdp0::slotKeepAlive() {
    60   if (_udpSocket) {
    61     _udpSocket->writeDatagram(_keepAlive, 12, _address, _port);
    62   }
    63   QTimer::singleShot(15000, this, SLOT(slotKeepAlive()));
    6450}
    6551
     
    7258////////////////////////////////////////////////////////////////////////////
    7359void bncNetQueryUdp0::waitForReadyRead(QByteArray& outData) {
    74 
    75   // Wait Loop
    76   // ---------
    77   if (!_udpSocket->hasPendingDatagrams()) {
    78     _eventLoop->exec();
    79   }
    80 
    81   // Append Data
    82   // -----------
    83   QByteArray datagram;
    84   datagram.resize(_udpSocket->pendingDatagramSize());
    85   _udpSocket->readDatagram(datagram.data(), datagram.size());
    86 
    87   if (datagram.size() > 12) {
    88     outData.append(datagram.mid(12));
     60  if (_udpSocket) {
     61    while (true) {
     62      int nBytes = _udpSocket->bytesAvailable();
     63      if (nBytes > 0) {
     64        outData = _udpSocket->readAll();
     65        return;
     66      }
     67      else if (!_udpSocket->waitForReadyRead(_timeOut)) {
     68        delete _udpSocket;
     69        _udpSocket = 0;
     70        _status = error;
     71        emit newMessage(_url.path().toAscii() + " read timeout", true);
     72        return;
     73      }
     74    }
    8975  }
    9076}
     
    9278// Connect to Caster, send the Request
    9379////////////////////////////////////////////////////////////////////////////
    94 void bncNetQueryUdp0::startRequest(const QUrl& url, const QByteArray& gga) {
     80void bncNetQueryUdp0::startRequest(const QUrl& url, const QByteArray& /* gga */) {
    9581
    9682  _status = running;
     
    10692  }
    10793
    108   _port = _url.port();
    109 
    11094  delete _udpSocket;
    11195  _udpSocket = new QUdpSocket();
    112   _udpSocket->bind(0);
    113   connect(_udpSocket, SIGNAL(readyRead()), _eventLoop, SLOT(quit()));
    114 
    115   QHostInfo hInfo = QHostInfo::fromName(url.host());
    116 
    117   if (!hInfo.addresses().isEmpty()) {
    118 
    119     _address = hInfo.addresses().first();
    120 
    121     // Send Request
    122     // ------------
    123     QString uName = QUrl::fromPercentEncoding(_url.userName().toAscii());
    124     QString passW = QUrl::fromPercentEncoding(_url.password().toAscii());
    125     QByteArray userAndPwd;
    126    
    127     if(!uName.isEmpty() || !passW.isEmpty()) {
    128       userAndPwd = "Authorization: Basic " + (uName.toAscii() + ":" +
    129       passW.toAscii()).toBase64() + "\r\n";
    130     }
    131    
    132     QByteArray reqStr = "GET " + _url.path().toAscii() + " HTTP/1.1\r\n"
    133                       + "Host: " + _url.host().toAscii() + "\r\n"
    134                       + "Ntrip-Version: Ntrip/2.0\r\n"
    135                       + "User-Agent: NTRIP BNC/" BNCVERSION "\r\n";
    136     if (!gga.isEmpty()) {
    137       reqStr += "Ntrip-GGA: " + gga + "\r\n";
    138     }
    139     reqStr += userAndPwd + "Connection: close\r\n\r\n";
    140    
    141     char rtpbuffer[12 + reqStr.size()];
    142     rtpbuffer[0]  = 128;
    143     rtpbuffer[1]  =  97;
    144     for (int jj = 2; jj <= 11; jj++) {
    145       rtpbuffer[jj] = _keepAlive[jj];
    146     }
    147     for (int ii = 0; ii < reqStr.size(); ii++) {
    148       rtpbuffer[12+ii] = reqStr[ii];
    149     }
    150 
    151     _udpSocket->writeDatagram(rtpbuffer, 12 + reqStr.size(), _address, _port);
    152 
    153     // Wait for Reply, read Session Number
    154     // -----------------------------------
    155     QByteArray repl;
    156     waitForReadyRead(repl);
    157 
    158     QTextStream in(repl);
    159     QString line = in.readLine();
    160     while (!line.isEmpty()) {
    161       if (line.indexOf("Session:") == 0) {
    162         _session = line.mid(9).toInt();
    163         _keepAlive[ 8] = (_session >> 24) & 0xFF;
    164         _keepAlive[ 9] = (_session >> 16) & 0xFF;
    165         _keepAlive[10] = (_session >>  8) & 0xFF;
    166         _keepAlive[11] = (_session)       & 0xFF;
    167         break;
    168       }
    169       line = in.readLine();
    170     }
    171 
    172     QTimer::singleShot(15000, this, SLOT(slotKeepAlive()));
    173   }
     96  _udpSocket->connectToHost(_url.host(), _url.port());
    17497}
    17598
  • trunk/BNC/bncnetqueryudp0.h

    r1779 r1783  
    1414  virtual void startRequest(const QUrl& url, const QByteArray& gga);
    1515  virtual void waitForReadyRead(QByteArray& outData);
    16 
    17  private slots:
    18   void slotKeepAlive();
    19 
    2016 private:
    2117  QUdpSocket*  _udpSocket;
    22   QEventLoop*  _eventLoop;
    23   QHostAddress _address;
    24   int          _port;
    25   char         _keepAlive[12];
    26   int          _session;
    2718};
    2819
  • trunk/BNC/bncnetqueryv0.cpp

    r1716 r1783  
    7777// Connect to Caster, send the Request
    7878////////////////////////////////////////////////////////////////////////////
    79 void bncNetQueryV0::startRequest(const QUrl& url, const QByteArray& gga) {
     79void bncNetQueryV0::startRequest(const QUrl& url, const QByteArray& /* gga */) {
    8080
    8181  _status = running;
    82   QByteArray dummy = gga;
    8382
    8483  delete _socket;
Note: See TracChangeset for help on using the changeset viewer.