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


Ignore:
Timestamp:
Sep 8, 2006, 9:24:23 AM (18 years ago)
Author:
mervart
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/bncgetthread.cpp

    r93 r136  
    2828using namespace std;
    2929
    30 const int timeOut = 300*1000;
    31 
    3230// Constructor
    3331////////////////////////////////////////////////////////////////////////////
    3432bncGetThread::bncGetThread(const QUrl& mountPoint, const QByteArray& format) {
     33  _decoder    = 0;
    3534  _mountPoint = mountPoint;
    3635  _staID      = mountPoint.path().mid(1).toAscii();
    3736  _format     = format;
    3837  _socket     = 0;
     38  _timeOut    = 10*1000;  // 10 seconds
    3939}
    4040
     
    4343bncGetThread::~bncGetThread() {
    4444  delete _socket;
     45  delete _decoder;
    4546}
    4647
    4748// Connect to Caster, send the Request (static)
    4849////////////////////////////////////////////////////////////////////////////
    49 QTcpSocket* bncGetThread::request(const QUrl& mountPoint, QString& msg) {
     50QTcpSocket* bncGetThread::request(const QUrl& mountPoint, int timeOut,
     51                                  QString& msg) {
    5052
    5153  // Connect the Socket
     
    98100}
    99101
    100 // Run
     102// Init Run
    101103////////////////////////////////////////////////////////////////////////////
    102 void bncGetThread::run() {
     104void bncGetThread::initRun() {
    103105
    104106  // Send the Request
     
    106108  QString msg;
    107109
    108   _socket = bncGetThread::request(_mountPoint, msg);
     110  _socket = bncGetThread::request(_mountPoint, _timeOut, msg);
    109111
    110112  emit(newMessage(msg.toAscii()));
     
    116118  // Read Caster Response
    117119  // --------------------
    118   _socket->waitForReadyRead(timeOut);
     120  _socket->waitForReadyRead(_timeOut);
    119121  if (_socket->canReadLine()) {
    120122    QString line = _socket->readLine();
     
    131133  // Instantiate the filter
    132134  // ----------------------
    133   GPSDecoder* decoder;
     135  if (!_decoder) {
     136    if      (_format.indexOf("RTCM_2") != -1) {
     137      emit(newMessage("Get Data: " + _staID + " in RTCM 2.x format"));
     138      _decoder = new RTCM('A',true);
     139    }
     140    else if (_format.indexOf("RTCM_3") != -1) {
     141      emit(newMessage("Get Data: " + _staID + " in RTCM 3.0 format"));
     142      _decoder = new rtcm3();
     143    }
     144    else if (_format.indexOf("RTIGS") != -1) {
     145      emit(newMessage("Get Data: " + _staID + " in RTIGS format"));
     146      _decoder = new rtigs();
     147    }
     148    else {
     149      emit(newMessage(_staID + " Unknown data format " + _format));
     150      return exit(1);
     151    }
     152  }
     153}
    134154
    135   if      (_format.indexOf("RTCM_2") != -1) {
    136     emit(newMessage("Get Data: " + _staID + " in RTCM 2.x format"));
    137     decoder = new RTCM('A',true);
    138   }
    139   else if (_format.indexOf("RTCM_3") != -1) {
    140     emit(newMessage("Get Data: " + _staID + " in RTCM 3.0 format"));
    141     decoder = new rtcm3();
    142   }
    143   else if (_format.indexOf("RTIGS") != -1) {
    144     emit(newMessage("Get Data: " + _staID + " in RTIGS format"));
    145     decoder = new rtigs();
    146   }
    147   else {
    148     emit(newMessage(_staID + " Unknown data format " + _format));
    149     return exit(1);
    150   }
     155// Run
     156////////////////////////////////////////////////////////////////////////////
     157void bncGetThread::run() {
     158
     159  initRun();
    151160
    152161  // Read Incoming Data
    153162  // ------------------
    154163  while (true) {
    155     _socket->waitForReadyRead(timeOut);
     164    _socket->waitForReadyRead(_timeOut);
    156165    qint64 nBytes = _socket->bytesAvailable();
    157166    if (nBytes > 0) {
    158167      char* data = new char[nBytes];
    159168      _socket->read(data, nBytes);
    160       decoder->Decode(data, nBytes);
     169      _decoder->Decode(data, nBytes);
    161170      delete data;
    162       for (list<Observation*>::iterator it = decoder->m_lObsList.begin();
    163            it != decoder->m_lObsList.end(); it++) {
     171      for (list<Observation*>::iterator it = _decoder->m_lObsList.begin();
     172           it != _decoder->m_lObsList.end(); it++) {
    164173        emit newObs(_staID, *it);
    165174      }
    166       decoder->m_lObsList.clear();
     175      _decoder->m_lObsList.clear();
    167176    }
    168177    else {
    169       emit(newMessage("Data Timeout"));
    170       return exit(1);
     178      emit(newMessage("Data Timeout, reconnecting"));
     179      tryReconnect();
    171180    }
    172181  }
    173   delete decoder;
    174182}
    175183
     
    183191}
    184192
     193// Try Re-Connect
     194////////////////////////////////////////////////////////////////////////////
     195void bncGetThread::tryReconnect() {
     196
     197}
Note: See TracChangeset for help on using the changeset viewer.