Changeset 934 in ntrip for trunk/BNC/RTCM3/RTCM3coDecoder.cpp


Ignore:
Timestamp:
Jun 8, 2008, 4:33:04 PM (16 years ago)
Author:
mervart
Message:

* empty log message *

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/RTCM3/RTCM3coDecoder.cpp

    r920 r934  
    4444#include "RTCM3coDecoder.h"
    4545#include "bncutils.h"
     46#include "bncrinex.h"
    4647
    4748using namespace std;
     
    4950// Constructor
    5051////////////////////////////////////////////////////////////////////////////
    51 RTCM3coDecoder::RTCM3coDecoder(const QString& fileName)
    52   : bncZeroDecoder(fileName) {
     52RTCM3coDecoder::RTCM3coDecoder(const QString& fileName) {
     53
     54  // File Output
     55  // -----------
     56  QSettings settings;
     57  QString path = settings.value("corrPath").toString();
     58  if (!path.isEmpty()) {
     59    expandEnvVar(path);
     60    if ( path.length() > 0 && path[path.length()-1] != QDir::separator() ) {
     61      path += QDir::separator();
     62    }
     63    _fileNameSkl = path + fileName;
     64  }
     65  _out = 0;
     66
     67  // Socket Server
     68  // -------------
     69  int port = settings.value("corrPort").toInt();
     70  if (port != 0) {
     71    _server = new QTcpServer;
     72    _server->listen(QHostAddress::Any, port);
     73    connect(_server, SIGNAL(newConnection()), this, SLOT(slotNewConnection()));
     74    _sockets = new QList<QTcpSocket*>;
     75  }
     76  else {
     77    delete _sockets;
     78    delete _server;
     79  }
    5380}
    5481
     
    5683////////////////////////////////////////////////////////////////////////////
    5784RTCM3coDecoder::~RTCM3coDecoder() {
     85}
     86
     87// Reopen Output File
     88////////////////////////////////////////////////////////////////////////
     89void RTCM3coDecoder::reopen() {
     90
     91  if (!_fileNameSkl.isEmpty()) {
     92
     93    QSettings settings;
     94
     95    QDateTime datTim = QDateTime::currentDateTime().toUTC();
     96
     97    QString hlpStr = bncRinex::nextEpochStr(datTim,
     98                                      settings.value("corrIntr").toString());
     99
     100    QString fileName = _fileNameSkl
     101      + QString("%1").arg(datTim.date().dayOfYear(), 3, 10, QChar('0'))
     102      + datTim.toString(".yyC");
     103
     104    if (_fileName == fileName) {
     105      return;
     106    }
     107    else {
     108      _fileName = fileName;
     109    }
     110
     111    delete _out;
     112    _out = new ofstream( _fileName.toAscii().data() );
     113  }
     114}
     115
     116// New Connection
     117////////////////////////////////////////////////////////////////////////////
     118void RTCM3coDecoder::slotNewConnection() {
     119  _sockets->push_back( _server->nextPendingConnection() );
    58120}
    59121
     
    126188               _co.Sat[ii].Orbit.DeltaAlongTrack,
    127189               _co.Sat[ii].Orbit.DeltaCrossTrack);
    128         *_out << line.toAscii().data();
     190        printLine(line);
    129191      }
    130192      for(int ii = CLOCKORBIT_NUMGPS;
     
    137199               _co.Sat[ii].Orbit.DeltaAlongTrack,
    138200               _co.Sat[ii].Orbit.DeltaCrossTrack);
    139         *_out << line.toAscii().data();
    140       }
    141       _out->flush();
     201        printLine(line);
     202      }
    142203      _buffer = _buffer.substr(bytesused);
    143204      return success;
     
    151212  }
    152213}
     214
     215//
     216////////////////////////////////////////////////////////////////////////////
     217void RTCM3coDecoder::printLine(const QString& line) {
     218
     219  if (_out) {
     220    *_out << line.toAscii().data();
     221    _out->flush();
     222  }
     223
     224  if (_sockets) {
     225    QMutableListIterator<QTcpSocket*> is(*_sockets);
     226    while (is.hasNext()) {
     227      QTcpSocket* sock = is.next();
     228      if (sock->state() == QAbstractSocket::ConnectedState) {
     229        if (sock->write(line.toAscii()) == -1) {
     230          delete sock;
     231          is.remove();
     232        }
     233      }
     234      else if (sock->state() != QAbstractSocket::ConnectingState) {
     235        delete sock;
     236        is.remove();
     237      }
     238    }
     239  }
     240}
Note: See TracChangeset for help on using the changeset viewer.