Changeset 2831 in ntrip


Ignore:
Timestamp:
Dec 25, 2010, 5:45:22 PM (13 years ago)
Author:
mervart
Message:
 
Location:
trunk/BNC
Files:
3 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          }
  • trunk/BNC/bncrinex.cpp

    r2715 r2831  
    629629    // ---------------
    630630    if (_rinexVers == 3) {
    631       _out << rinexSatLine(obs, lli1, lli2, lli5);
     631      _out << rinexSatLine(obs, true, lli1, lli2, lli5);
    632632      _out << endl;
    633633    }
     
    671671// One Line in RINEX v3 (static)
    672672////////////////////////////////////////////////////////////////////////////
    673 string bncRinex::rinexSatLine(const t_obs& obs,
     673string bncRinex::rinexSatLine(const t_obs& obs, bool usells,
    674674                              char lli1, char lli2, char lli5) {
    675675  ostringstream str;
     
    680680        << setw(2) << setfill('0') << obs.satNum << setfill(' ')
    681681        << setw(14) << setprecision(3) << obs.C1  << ' '  << ' ' 
    682         << setw(14) << setprecision(3) << obs.L1C << lli1 << ' '
    683         << setw(14) << setprecision(3) << obs.D1C << ' '  << ' '
     682        << setw(14) << setprecision(3) << obs.L1C;
     683    if (usells) {
     684      str << lli1 << ' ';
     685    }
     686    else {
     687      str << ' ' << obs.slip_cnt_L1 << ' ';
     688    }
     689    str << setw(14) << setprecision(3) << obs.D1C << ' '  << ' '
    684690        << setw(14) << setprecision(3) << obs.S1C << ' '  << ' '
    685691        << setw(14) << setprecision(3) << obs.P1  << ' '  << ' ' 
    686         << setw(14) << setprecision(3) << obs.L1P << lli1 << ' '
    687         << setw(14) << setprecision(3) << obs.D1P << ' '  << ' '
     692        << setw(14) << setprecision(3) << obs.L1P;
     693    if (usells) {
     694      str << lli1 << ' ';
     695    }
     696    else {
     697      str << ' ' << obs.slip_cnt_L1 << ' ';
     698    }
     699    str << setw(14) << setprecision(3) << obs.D1P << ' '  << ' '
    688700        << setw(14) << setprecision(3) << obs.S1P << ' '  << ' '
    689701        << setw(14) << setprecision(3) << obs.P2  << ' '  << ' '
    690         << setw(14) << setprecision(3) << obs.L2P << lli2 << ' '
    691         << setw(14) << setprecision(3) << obs.D2P << ' '  << ' '
     702        << setw(14) << setprecision(3) << obs.L2P;
     703    if (usells) {
     704      str << lli2 << ' ';
     705    }
     706    else {
     707      str << ' ' << obs.slip_cnt_L2 << ' ';
     708    }
     709    str << setw(14) << setprecision(3) << obs.D2P << ' '  << ' '
    692710        << setw(14) << setprecision(3) << obs.S2P << ' '  << ' '
    693711        << setw(14) << setprecision(3) << obs.C2  << ' '  << ' ' 
    694         << setw(14) << setprecision(3) << obs.L2C << lli2 << ' '
    695         << setw(14) << setprecision(3) << obs.D2C << ' '  << ' '
     712        << setw(14) << setprecision(3) << obs.L2C;
     713    if (usells) {
     714      str << lli2 << ' ';
     715    }
     716    else {
     717      str << ' ' << obs.slip_cnt_L2 << ' ';
     718    }
     719    str << setw(14) << setprecision(3) << obs.D2C << ' '  << ' '
    696720        << setw(14) << setprecision(3) << obs.S2C << ' '  << ' '
    697721        << setw(14) << setprecision(3) << obs.C5  << ' '  << ' ' 
    698         << setw(14) << setprecision(3) << obs.L5  << lli5 << ' '
    699         << setw(14) << setprecision(3) << obs.D5  << ' '  << ' ' 
     722        << setw(14) << setprecision(3) << obs.L5;
     723    if (usells) {
     724      str << lli5 << ' ';
     725    }
     726    else {
     727      str << ' ' << obs.slip_cnt_L5 << ' ';
     728    }
     729    str << setw(14) << setprecision(3) << obs.D5  << ' '  << ' ' 
    700730        << setw(14) << setprecision(3) << obs.S5;
    701731  }
     
    704734        << setw(2) << setfill('0') << obs.satNum << setfill(' ')
    705735        << setw(14) << setprecision(3) << obs.C1  << ' '  << ' ' 
    706         << setw(14) << setprecision(3) << obs.L1C << lli1 << ' '
    707         << setw(14) << setprecision(3) << obs.D1C << ' '  << ' ' 
     736        << setw(14) << setprecision(3) << obs.L1C;
     737    if (usells) {
     738      str << lli1 << ' ';
     739    }
     740    else {
     741      str << ' ' << obs.slip_cnt_L1 << ' ';
     742    }
     743    str << setw(14) << setprecision(3) << obs.D1C << ' '  << ' ' 
    708744        << setw(14) << setprecision(3) << obs.S1C << ' '  << ' '
    709745        << setw(14) << setprecision(3) << obs.P1  << ' '  << ' ' 
    710         << setw(14) << setprecision(3) << obs.L1P << lli1 << ' '
    711         << setw(14) << setprecision(3) << obs.D1P << ' '  << ' ' 
     746        << setw(14) << setprecision(3) << obs.L1P;
     747    if (usells) {
     748      str << lli1 << ' ';
     749    }
     750    else {
     751      str << ' ' << obs.slip_cnt_L1 << ' ';
     752    }
     753    str << setw(14) << setprecision(3) << obs.D1P << ' '  << ' ' 
    712754        << setw(14) << setprecision(3) << obs.S1P << ' '  << ' '
    713755        << setw(14) << setprecision(3) << obs.P2  << ' '  << ' ' 
    714         << setw(14) << setprecision(3) << obs.L2P << lli2 << ' '
    715         << setw(14) << setprecision(3) << obs.D2P << ' '  << ' ' 
     756        << setw(14) << setprecision(3) << obs.L2P;
     757    if (usells) {
     758      str << lli2 << ' ';
     759    }
     760    else {
     761      str << ' ' << obs.slip_cnt_L2 << ' ';
     762    }
     763    str << setw(14) << setprecision(3) << obs.D2P << ' '  << ' ' 
    716764        << setw(14) << setprecision(3) << obs.S2P << ' '  << ' '
    717765        << setw(14) << setprecision(3) << obs.C2  << ' '  << ' '
    718         << setw(14) << setprecision(3) << obs.L2C << lli2 << ' '
    719         << setw(14) << setprecision(3) << obs.D2C << ' '  << ' ' 
     766        << setw(14) << setprecision(3) << obs.L2C;
     767    if (usells) {
     768      str << lli2 << ' ';
     769    }
     770    else {
     771      str << ' ' << obs.slip_cnt_L2 << ' ';
     772    }
     773    str << setw(14) << setprecision(3) << obs.D2C << ' '  << ' ' 
    720774        << setw(14) << setprecision(3) << obs.S2C;
    721775  }
     
    724778        << setw(2) << setfill('0') << obs.satNum << setfill(' ')
    725779        << setw(14) << setprecision(3) << obs.C1  << ' '  << ' ' 
    726         << setw(14) << setprecision(3) << obs.L1C << lli1 << ' '
    727         << setw(14) << setprecision(3) << obs.D1C << ' '  << ' ' 
     780        << setw(14) << setprecision(3) << obs.L1C;
     781    if (usells) {
     782      str << lli1 << ' ';
     783    }
     784    else {
     785      str << ' ' << obs.slip_cnt_L1 << ' ';
     786    }
     787    str << setw(14) << setprecision(3) << obs.D1C << ' '  << ' ' 
    728788        << setw(14) << setprecision(3) << obs.S1C << ' '  << ' '
    729789        << setw(14) << setprecision(3) << obs.P1  << ' '  << ' ' 
    730         << setw(14) << setprecision(3) << obs.L1P << lli1 << ' '
    731         << setw(14) << setprecision(3) << obs.D1P << ' '  << ' ' 
     790        << setw(14) << setprecision(3) << obs.L1P;
     791    if (usells) {
     792      str << lli1 << ' ';
     793    }
     794    else {
     795      str << ' ' << obs.slip_cnt_L1 << ' ';
     796    }
     797    str << setw(14) << setprecision(3) << obs.D1P << ' '  << ' ' 
    732798        << setw(14) << setprecision(3) << obs.S1P;
    733799  }
     
    736802        << setw(2) << setfill('0') << obs.satNum << setfill(' ')
    737803        << setw(14) << setprecision(3) << obs.C1  << ' '  << ' ' 
    738         << setw(14) << setprecision(3) << obs.L1C << lli1 << ' '
    739         << setw(14) << setprecision(3) << obs.D1C << ' '  << ' '
     804        << setw(14) << setprecision(3) << obs.L1C;
     805    if (usells) {
     806      str << lli1 << ' ';
     807    }
     808    else {
     809      str << ' ' << obs.slip_cnt_L1 << ' ';
     810    }
     811    str << setw(14) << setprecision(3) << obs.D1C << ' '  << ' '
    740812        << setw(14) << setprecision(3) << obs.S1C << ' '  << ' '
    741813        << setw(14) << setprecision(3) << obs.C5  << ' '  << ' ' 
    742         << setw(14) << setprecision(3) << obs.L5  << lli5 << ' '
    743         << setw(14) << setprecision(3) << obs.D5  << ' '  << ' ' 
     814        << setw(14) << setprecision(3) << obs.L5;
     815    if (usells) {
     816      str << lli5 << ' ';
     817    }
     818    else {
     819      str << ' ' << obs.slip_cnt_L5 << ' ';
     820    }
     821    str << setw(14) << setprecision(3) << obs.D5  << ' '  << ' ' 
    744822        << setw(14) << setprecision(3) << obs.S5;
    745823  }
  • trunk/BNC/bncrinex.h

    r2711 r2831  
    5555   }
    5656
    57    static std::string rinexSatLine(const t_obs& obs,
     57   static std::string rinexSatLine(const t_obs& obs, bool usells,
    5858                                   char lli1, char lli2, char lli5);
    5959
Note: See TracChangeset for help on using the changeset viewer.