Changeset 2831 in ntrip for trunk/BNC/bnccaster.cpp


Ignore:
Timestamp:
Dec 25, 2010, 5:45:22 PM (13 years ago)
Author:
mervart
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/bnccaster.cpp

    r2829 r2831  
    4141#include <math.h>
    4242#include <unistd.h>
     43#include <iostream>
     44#include <iomanip>
     45#include <sstream>
    4346
    4447#include "bnccaster.h"
     
    4952#include "bncsettings.h"
    5053#include "RTCM/GPSDecoder.h"
     54
     55using namespace std;
    5156
    5257// Constructor
     
    158163  long newTime = obs.GPSWeek * 7*24*3600 + iSec;
    159164
    160   // Rename the Station
    161   // ------------------
    162   strncpy(obs.StatID, staID.constData(),sizeof(obs.StatID));
    163   obs.StatID[sizeof(obs.StatID)-1] = '\0';
    164 
    165   const char begObs[] = "BEGOBS";
    166   const int begObsNBytes = sizeof(begObs) - 1;
    167 
    168165  // Output into the socket
    169166  // ----------------------
    170167  if (_uSockets) {
     168
     169    ostringstream oStr;
     170    oStr.setf(ios::showpoint | ios::fixed);
     171    oStr << obs.StatID                                        << " "
     172         << obs.GPSWeek                                       << " "
     173         << setprecision(7) << obs.GPSWeeks                   << " "
     174         << bncRinex::rinexSatLine(obs, false, ' ', ' ', ' ') << endl;
     175
     176    string hlpStr = oStr.str();
     177
    171178    QMutableListIterator<QTcpSocket*> is(*_uSockets);
    172179    while (is.hasNext()) {
    173180      QTcpSocket* sock = is.next();
    174181      if (sock->state() == QAbstractSocket::ConnectedState) {
    175         bool ok = true;
    176         if (myWrite(sock, begObs, begObsNBytes) != begObsNBytes) {
    177           ok = false;
    178         }
    179         int numBytes = sizeof(obs);
    180         if (myWrite(sock, (const char*)(&obs), numBytes) != numBytes) {
    181           ok = false;
    182         }
    183         if (!ok) {
     182        int numBytes = hlpStr.length();
     183        if (myWrite(sock, hlpStr.c_str(), numBytes) != numBytes) {
    184184          delete sock;
    185185          is.remove();
     
    307307void bncCaster::dumpEpochs(long minTime, long maxTime) {
    308308
    309   const char begEpoch[] = "BEGEPOCH";
    310   const char endEpoch[] = "ENDEPOCH";
    311 
    312   const int begEpochNBytes = sizeof(begEpoch) - 1;
    313   const int endEpochNBytes = sizeof(endEpoch) - 1;
    314 
    315309  for (long sec = minTime; sec <= maxTime; sec++) {
    316310
     
    324318      if (_samplingRate == 0 || sec % _samplingRate == 0) {
    325319
    326         if (first) {
    327           QTime enomtime = QTime(0,0,0).addSecs(static_cast<int>(floor(obs.GPSWeeks+0.5)));
    328 //        emit( newMessage( QString("Epoch %1 dumped").arg(enomtime.toString("HH:mm:ss")).toAscii(), true) ); // weber
    329         }
    330         // Output into the file
    331         // --------------------
    332         if (_out) {
    333           if (first) {
    334             _out->setFieldWidth(1); *_out << begEpoch << endl;
     320        if (_out || _sockets) {
     321          ostringstream oStr;
     322          oStr.setf(ios::showpoint | ios::fixed);
     323          oStr << obs.StatID                                        << " "
     324               << obs.GPSWeek                                       << " "
     325               << setprecision(7) << obs.GPSWeeks                   << " "
     326               << bncRinex::rinexSatLine(obs, false, ' ', ' ', ' ') << endl;
     327          if (!it.hasNext()) {
     328            oStr << endl;
    335329          }
    336 
    337           *_out << obs.StatID << " " << obs.GPSWeek << " "; 
    338           _out->setRealNumberPrecision(7);
    339            *_out << obs.GPSWeeks << " ";
    340 
    341            *_out << bncRinex::rinexSatLine(obs, ' ', ' ', ' ').c_str()
    342                  << endl;
    343 
    344           if (!it.hasNext()) {
    345             _out->setFieldWidth(1); *_out << endEpoch << endl;
     330          string hlpStr = oStr.str();
     331
     332          // Output into the File
     333          // --------------------
     334          if (_out) {
     335            *_out << hlpStr.c_str();
     336            _out->flush();
    346337          }
    347           _out->flush();
    348         }
    349        
    350         // Output into the socket
    351         // ----------------------
    352         if (_sockets) {
    353           QMutableListIterator<QTcpSocket*> is(*_sockets);
    354           while (is.hasNext()) {
    355             QTcpSocket* sock = is.next();
    356             if (sock->state() == QAbstractSocket::ConnectedState) {
    357               bool ok = true;
    358               if (first) {
    359                 if (myWrite(sock, begEpoch, begEpochNBytes) != begEpochNBytes) {
    360                   ok = false;
     338
     339          // Output into the socket
     340          // ----------------------
     341          if (_sockets) {
     342            QMutableListIterator<QTcpSocket*> is(*_sockets);
     343            while (is.hasNext()) {
     344              QTcpSocket* sock = is.next();
     345              if (sock->state() == QAbstractSocket::ConnectedState) {
     346                int numBytes = hlpStr.length();
     347                if (myWrite(sock, hlpStr.c_str(), numBytes) != numBytes) {
     348                  delete sock;
     349                  is.remove();
    361350                }
    362351              }
    363               int numBytes = sizeof(obs);
    364               if (myWrite(sock, (const char*)(&obs), numBytes) != numBytes) {
    365                 ok = false;
    366               }
    367               if (!it.hasNext()) {
    368                 if (myWrite(sock, endEpoch, endEpochNBytes) != endEpochNBytes) {
    369                   ok = false;
    370                 }
    371               }
    372               if (!ok) {
     352              else if (sock->state() != QAbstractSocket::ConnectingState) {
    373353                delete sock;
    374354                is.remove();
    375355              }
    376             }
    377             else if (sock->state() != QAbstractSocket::ConnectingState) {
    378               delete sock;
    379               is.remove();
    380356            }
    381357          }
Note: See TracChangeset for help on using the changeset viewer.