Changeset 1061 in ntrip for trunk


Ignore:
Timestamp:
Aug 27, 2008, 11:23:17 AM (16 years ago)
Author:
mervart
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNS/bns.cpp

    r1059 r1061  
    7373  // Socket and file for outputting the results
    7474  // -------------------------------------------
    75   _outSocket          = 0;
    76   _outSocketOpenTrial = 0;
     75  _caster = new t_bnscaster(settings.value("mountpoint").toString());
    7776
    7877  QIODevice::OpenMode oMode;
     
    155154  delete _clkServer;
    156155  delete _clkSocket;
    157   delete _outSocket;
     156  delete _caster;
    158157  delete _outStream;
    159158  delete _logStream;
     
    209208}
    210209
    211 // Start the Communication with NTRIP Caster
    212 ////////////////////////////////////////////////////////////////////////////
    213 void t_bns::openCaster() {
    214 
    215   delete _outSocket; _outSocket = 0;
    216 
    217   double minDt = exp2(_outSocketOpenTrial);
    218   if (++_outSocketOpenTrial > 8) {
    219     _outSocketOpenTrial = 8;
    220   }
    221   if (_outSocketOpenTime.isValid() &&
    222       _outSocketOpenTime.secsTo(QDateTime::currentDateTime()) < minDt) {
    223     return;
    224   }
    225   else {
    226     _outSocketOpenTime = QDateTime::currentDateTime();
    227   }
    228 
    229   QSettings settings;
    230   _outSocket = new QTcpSocket();
    231   _outSocket->connectToHost(settings.value("outHost").toString(),
    232                             settings.value("outPort").toInt());
    233 
    234   const int timeOut = 100;  // 0.1 seconds
    235   if (!_outSocket->waitForConnected(timeOut)) {
    236     delete _outSocket;
    237     _outSocket = 0;
    238     emit(error("bns::openCaster Connect Timeout"));
    239     return;
    240   }
    241 
    242   QString mountpoint = settings.value("mountpoint").toString();
    243   QString password   = settings.value("password").toString();
    244 
    245   QByteArray msg = "SOURCE " + password.toAscii() + " /" +
    246                    mountpoint.toAscii() + "\r\n" +
    247                    "Source-Agent: NTRIP BNS/1.0\r\n\r\n";
    248 
    249   _outSocket->write(msg);
    250   _outSocket->waitForBytesWritten();
    251 
    252   _outSocket->waitForReadyRead();
    253   QByteArray ans = _outSocket->readLine();
    254 
    255   if (ans.indexOf("OK") == -1) {
    256     delete _outSocket;
    257     _outSocket = 0;
    258     slotMessage("bns::openCaster socket deleted");
    259   }
    260   else {
    261     slotMessage("bns::openCaster socket OK");
    262     _outSocketOpenTrial = 0;
    263   }
    264 }
    265 
    266210//
    267211////////////////////////////////////////////////////////////////////////////
     
    316260    if (_clkSocket && _clkSocket->state() == QAbstractSocket::ConnectedState) {
    317261      if ( _clkSocket->canReadLine()) {
    318         if (_outSocket == 0 ||
    319             _outSocket->state() != QAbstractSocket::ConnectedState) {
    320           openCaster();
    321         }
     262        _caster->open();
    322263        readEpoch();
    323264      }
     
    417358      }
    418359   
    419       if ( (_outSocket || _outFile) &&
     360      if ( (_caster->used() || _outFile) &&
    420361           (co.NumberOfGPSSat > 0 || co.NumberOfGLONASSSat > 0) ) {
    421362        char obuffer[CLOCKORBIT_BUFFERSIZE];
     
    423364        if (len > 0) {
    424365          emit(newOutBytes(len));
    425           if (_outSocket) {
    426             _outSocket->write(obuffer, len);
    427             _outSocket->flush();
    428           }
     366          _caster->write(obuffer, len);
    429367        }
    430368      }
Note: See TracChangeset for help on using the changeset viewer.