Changeset 3226 in ntrip


Ignore:
Timestamp:
Mar 31, 2011, 6:10:51 PM (13 years ago)
Author:
mervart
Message:
 
Location:
trunk/BNC/upload
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/upload/bncrtnetuploadcaster.cpp

    r3224 r3226  
    3535                      bncUploadCaster(mountpoint, outHost, outPort, password) {
    3636
    37   bncSettings settings;
    3837  _crdTrafo   = crdTrafo;
    3938  _CoM        = CoM;
     
    158157  }
    159158  else if (_crdTrafo == "Custom") {
     159    bncSettings settings;
    160160    _dx  = settings.value("trafo_dx").toDouble();
    161161    _dy  = settings.value("trafo_dy").toDouble();
     
    188188}
    189189
    190 // Endless Loop
    191 ////////////////////////////////////////////////////////////////////////////
    192 void bncRtnetUploadCaster::run() {
    193   while (true) {
    194     if (_isToBeDeleted) {
    195       QThread::quit();
    196       deleteLater();
    197       return;
    198     }
    199     open();
    200     uploadClockOrbitBias();
    201     msleep(10);
    202   }
    203 }
    204 
    205190//
    206191////////////////////////////////////////////////////////////////////////////
     
    211196  // Append to buffer
    212197  // ----------------
    213   const int MAXBUFFSIZE = 100000;
    214198  _rtnetStreamBuffer.append(QByteArray(buffer, bufLen));
    215   if (_rtnetStreamBuffer.size() > MAXBUFFSIZE) {
    216     _rtnetStreamBuffer = _rtnetStreamBuffer.right(MAXBUFFSIZE);
    217   }
    218 }
    219 
    220 // Function called in separate thread
    221 ////////////////////////////////////////////////////////////////////////
    222 void bncRtnetUploadCaster::uploadClockOrbitBias() {
    223 
    224   QMutexLocker locker(&_mutex);
     199  int iLastAsterix = _rtnetStreamBuffer.lastIndexOf('*'); // begin of last epoch
     200  if (iLastAsterix == -1) {
     201    _rtnetStreamBuffer.clear();
     202    return;
     203  }
     204  else {
     205    _rtnetStreamBuffer = _rtnetStreamBuffer.mid(iLastAsterix);
     206  }
    225207
    226208  // Prepare list of lines with satellite positions in SP3-like format
    227209  // -----------------------------------------------------------------
    228   QStringList lines;
    229   int iLast = _rtnetStreamBuffer.lastIndexOf('\n');
    230   if (iLast != -1) {
    231     QStringList hlpLines = _rtnetStreamBuffer.split('\n', QString::SkipEmptyParts);
    232     _rtnetStreamBuffer = _rtnetStreamBuffer.mid(iLast+1);
    233     for (int ii = 0; ii < hlpLines.size(); ii++) {
    234       if      (hlpLines[ii].indexOf('*') != -1) {
    235         lines.clear();
    236         QTextStream in(hlpLines[ii].toAscii());
    237         QString hlp;
    238         int     year, month, day, hour, min;
    239         double  sec;
    240         in >> hlp >> year >> month >> day >> hour >> min >> sec;
    241         _epoTime.set( year, month, day, hour, min, sec);
    242       }
    243       else if (_epoTime.valid()) {
    244         lines << hlpLines[ii];
    245       }
    246     }
    247   }
    248 
    249   if (lines.size() == 0) {
     210  QStringList lines = _rtnetStreamBuffer.split('\n', QString::SkipEmptyParts);
     211
     212  if (lines.size() < 2) {
    250213    return;
    251214  }
    252215
    253   unsigned year, month, day;
    254   _epoTime.civil_date(year, month, day);
    255  
     216  // Keep the last unfinished line in buffer
     217  // ---------------------------------------
     218  int iLastEOL = _rtnetStreamBuffer.lastIndexOf('\n');
     219  if (iLastEOL != -1) {
     220    _rtnetStreamBuffer = _rtnetStreamBuffer.mid(iLastEOL+1);
     221  }
     222
     223  // Read first line (with epoch time)
     224  // ---------------------------------
     225  QTextStream in(lines[0].toAscii());
     226  QString hlp;
     227  int     year, month, day, hour, min;
     228  double  sec;
     229  in >> hlp >> year >> month >> day >> hour >> min >> sec;
     230  bncTime epoTime; epoTime.set( year, month, day, hour, min, sec);
     231
    256232  struct ClockOrbit co;
    257233  memset(&co, 0, sizeof(co));
    258   co.GPSEpochTime      = static_cast<int>(_epoTime.gpssec());
    259   co.GLONASSEpochTime  = static_cast<int>(fmod(_epoTime.gpssec(), 86400.0))
     234  co.GPSEpochTime      = static_cast<int>(epoTime.gpssec());
     235  co.GLONASSEpochTime  = static_cast<int>(fmod(epoTime.gpssec(), 86400.0))
    260236                       + 3 * 3600 - gnumleap(year, month, day);
    261237  co.ClockDataSupplied = 1;
     
    265241  struct Bias bias;
    266242  memset(&bias, 0, sizeof(bias));
    267   bias.GPSEpochTime      = co.GPSEpochTime;
    268   bias.GLONASSEpochTime  = co.GLONASSEpochTime;
    269  
    270   for (int ii = 0; ii < lines.size(); ii++) {
    271   
     243  bias.GPSEpochTime     = co.GPSEpochTime;
     244  bias.GLONASSEpochTime = co.GLONASSEpochTime;
     245 
     246  for (int ii = 1; ii < lines.size(); ii++) {
     247 
    272248    QString      prn;
    273249    ColumnVector xx(14); xx = 0.0;
     
    315291      if (sd) {
    316292        QString outLine;
    317         processSatellite(eph, _epoTime.gpsw(), _epoTime.gpssec(), prn,
     293        processSatellite(eph, epoTime.gpsw(), epoTime.gpssec(), prn,
    318294                         xx, sd, outLine);
    319295        if (_outFile) {
    320           _outFile->write(_epoTime.gpsw(), _epoTime.gpssec(), outLine);
     296          _outFile->write(epoTime.gpsw(), epoTime.gpssec(), outLine);
    321297        }
    322298      }
     
    367343    int len = MakeClockOrbit(&co, COTYPE_AUTO, 0, obuffer, sizeof(obuffer));
    368344    if (len > 0) {
    369       this->write(obuffer, len);
     345      _outBuffer.append(QByteArray(obuffer, len));
    370346    }
    371347  }
     
    375351    int len = MakeBias(&bias, BTYPE_AUTO, 0, obuffer, sizeof(obuffer));
    376352    if (len > 0) {
    377       this->write(obuffer, len);
     353      _outBuffer.append(QByteArray(obuffer, len));
    378354    }
    379355  }
  • trunk/BNC/upload/bncrtnetuploadcaster.h

    r3225 r3226  
    2525                  const QString& rnxFileName,
    2626                  const QString& outFileName);
     27  void decodeRtnetStream(char* buffer, int bufLen);
    2728 protected:
    2829  virtual ~bncRtnetUploadCaster();
    29  public:
    30   virtual void run();
    31   void decodeRtnetStream(char* buffer, int bufLen);
    3230 private:
    3331  void uploadClockOrbitBias();
     
    4139  bncEphUser*    _ephUser;
    4240  QString        _rtnetStreamBuffer;
    43   bncTime        _epoTime;
    4441  QString        _crdTrafo;
    4542  bool           _CoM;
  • trunk/BNC/upload/bncuploadcaster.cpp

    r3224 r3226  
    3838  _sOpenTrial    = 0;
    3939  _isToBeDeleted = false;
    40 
    4140}
    4241
     
    5554  if (isRunning()) {
    5655    wait();
     56  }
     57}
     58
     59// Endless Loop
     60////////////////////////////////////////////////////////////////////////////
     61void bncUploadCaster::run() {
     62  while (true) {
     63    if (_isToBeDeleted) {
     64      QThread::quit();
     65      deleteLater();
     66      return;
     67    }
     68    open();
     69    if (_outSocket && _outSocket->state() == QAbstractSocket::ConnectedState) {
     70      QMutexLocker locker(&_mutex);
     71      _outSocket->write(_outBuffer);
     72      _outSocket->flush();
     73      _outBuffer.clear();
     74    }
     75    else {
     76      QMutexLocker locker(&_mutex);
     77      _outBuffer.clear();
     78    }
     79    sleep(5);
    5780  }
    5881}
     
    117140}
    118141
    119 // Write buffer
    120 ////////////////////////////////////////////////////////////////////////////
    121 void bncUploadCaster::write(char* buffer, unsigned len) {
    122   if (_outSocket && _outSocket->state() == QAbstractSocket::ConnectedState) {
    123     _outSocket->write(buffer, len);
    124     _outSocket->flush();
    125   }
    126 }
    127 
  • trunk/BNC/upload/bncuploadcaster.h

    r3224 r3226  
    1111                  const QString& password);
    1212  virtual void deleteSafely();
    13   virtual void run() = 0;
    1413
    1514 protected:
    16   virtual ~bncUploadCaster();
    17   void    open();
    18   void    write(char* buffer, unsigned len);
    19   QMutex  _mutex; 
    20   bool    _isToBeDeleted;
     15  virtual    ~bncUploadCaster();
     16  QMutex     _mutex; 
     17  QByteArray _outBuffer;
    2118
    2219 signals:
     
    2421
    2522 private:
    26   QString        _mountpoint;
    27   QString        _outHost;
    28   int            _outPort;
    29   QString        _password;
    30   QTcpSocket*    _outSocket;
    31   int            _sOpenTrial;
    32   QDateTime      _outSocketOpenTime;
     23  void         open();
     24  virtual void run();
     25  bool        _isToBeDeleted;
     26  QString     _mountpoint;
     27  QString     _outHost;
     28  int         _outPort;
     29  QString     _password;
     30  QTcpSocket* _outSocket;
     31  int         _sOpenTrial;
     32  QDateTime   _outSocketOpenTime;
    3333};
    3434
Note: See TracChangeset for help on using the changeset viewer.