Index: trunk/BNC/upload/bncrtnetuploadcaster.cpp
===================================================================
--- trunk/BNC/upload/bncrtnetuploadcaster.cpp	(revision 3225)
+++ trunk/BNC/upload/bncrtnetuploadcaster.cpp	(revision 3226)
@@ -35,5 +35,4 @@
                       bncUploadCaster(mountpoint, outHost, outPort, password) {
 
-  bncSettings settings;
   _crdTrafo   = crdTrafo;
   _CoM        = CoM;
@@ -158,4 +157,5 @@
   }
   else if (_crdTrafo == "Custom") {
+    bncSettings settings;
     _dx  = settings.value("trafo_dx").toDouble();
     _dy  = settings.value("trafo_dy").toDouble();
@@ -188,19 +188,4 @@
 }
 
-// Endless Loop
-////////////////////////////////////////////////////////////////////////////
-void bncRtnetUploadCaster::run() {
-  while (true) {
-    if (_isToBeDeleted) {
-      QThread::quit();
-      deleteLater();
-      return;
-    }
-    open();
-    uploadClockOrbitBias();
-    msleep(10);
-  }
-}
-
 // 
 ////////////////////////////////////////////////////////////////////////////
@@ -211,51 +196,42 @@
   // Append to buffer
   // ----------------
-  const int MAXBUFFSIZE = 100000;
   _rtnetStreamBuffer.append(QByteArray(buffer, bufLen));
-  if (_rtnetStreamBuffer.size() > MAXBUFFSIZE) {
-    _rtnetStreamBuffer = _rtnetStreamBuffer.right(MAXBUFFSIZE);
-  }
-}
-
-// Function called in separate thread
-//////////////////////////////////////////////////////////////////////// 
-void bncRtnetUploadCaster::uploadClockOrbitBias() {
-
-  QMutexLocker locker(&_mutex);
+  int iLastAsterix = _rtnetStreamBuffer.lastIndexOf('*'); // begin of last epoch
+  if (iLastAsterix == -1) {
+    _rtnetStreamBuffer.clear();
+    return;
+  }
+  else {
+    _rtnetStreamBuffer = _rtnetStreamBuffer.mid(iLastAsterix);
+  }
 
   // Prepare list of lines with satellite positions in SP3-like format
   // -----------------------------------------------------------------
-  QStringList lines;
-  int iLast = _rtnetStreamBuffer.lastIndexOf('\n');
-  if (iLast != -1) {
-    QStringList hlpLines = _rtnetStreamBuffer.split('\n', QString::SkipEmptyParts);
-    _rtnetStreamBuffer = _rtnetStreamBuffer.mid(iLast+1);
-    for (int ii = 0; ii < hlpLines.size(); ii++) {
-      if      (hlpLines[ii].indexOf('*') != -1) {
-        lines.clear();
-        QTextStream in(hlpLines[ii].toAscii());
-        QString hlp;
-        int     year, month, day, hour, min;
-        double  sec;
-        in >> hlp >> year >> month >> day >> hour >> min >> sec;
-        _epoTime.set( year, month, day, hour, min, sec);
-      }
-      else if (_epoTime.valid()) {
-        lines << hlpLines[ii];
-      }
-    }
-  }
-
-  if (lines.size() == 0) {
+  QStringList lines = _rtnetStreamBuffer.split('\n', QString::SkipEmptyParts);
+
+  if (lines.size() < 2) {
     return;
   }
 
-  unsigned year, month, day;
-  _epoTime.civil_date(year, month, day);
-  
+  // Keep the last unfinished line in buffer
+  // ---------------------------------------
+  int iLastEOL = _rtnetStreamBuffer.lastIndexOf('\n');
+  if (iLastEOL != -1) {
+    _rtnetStreamBuffer = _rtnetStreamBuffer.mid(iLastEOL+1);
+  }
+
+  // Read first line (with epoch time)
+  // ---------------------------------
+  QTextStream in(lines[0].toAscii());
+  QString hlp;
+  int     year, month, day, hour, min;
+  double  sec;
+  in >> hlp >> year >> month >> day >> hour >> min >> sec;
+  bncTime epoTime; epoTime.set( year, month, day, hour, min, sec);
+
   struct ClockOrbit co;
   memset(&co, 0, sizeof(co));
-  co.GPSEpochTime      = static_cast<int>(_epoTime.gpssec());
-  co.GLONASSEpochTime  = static_cast<int>(fmod(_epoTime.gpssec(), 86400.0))
+  co.GPSEpochTime      = static_cast<int>(epoTime.gpssec());
+  co.GLONASSEpochTime  = static_cast<int>(fmod(epoTime.gpssec(), 86400.0))
                        + 3 * 3600 - gnumleap(year, month, day);
   co.ClockDataSupplied = 1;
@@ -265,9 +241,9 @@
   struct Bias bias;
   memset(&bias, 0, sizeof(bias));
-  bias.GPSEpochTime      = co.GPSEpochTime;
-  bias.GLONASSEpochTime  = co.GLONASSEpochTime;
-  
-  for (int ii = 0; ii < lines.size(); ii++) {
-  
+  bias.GPSEpochTime     = co.GPSEpochTime;
+  bias.GLONASSEpochTime = co.GLONASSEpochTime;
+  
+  for (int ii = 1; ii < lines.size(); ii++) {
+ 
     QString      prn;
     ColumnVector xx(14); xx = 0.0;
@@ -315,8 +291,8 @@
       if (sd) {
         QString outLine;
-        processSatellite(eph, _epoTime.gpsw(), _epoTime.gpssec(), prn, 
+        processSatellite(eph, epoTime.gpsw(), epoTime.gpssec(), prn, 
                          xx, sd, outLine);
         if (_outFile) {
-          _outFile->write(_epoTime.gpsw(), _epoTime.gpssec(), outLine);
+          _outFile->write(epoTime.gpsw(), epoTime.gpssec(), outLine);
         }
       }
@@ -367,5 +343,5 @@
     int len = MakeClockOrbit(&co, COTYPE_AUTO, 0, obuffer, sizeof(obuffer));
     if (len > 0) {
-      this->write(obuffer, len);
+      _outBuffer.append(QByteArray(obuffer, len));
     }
   }
@@ -375,5 +351,5 @@
     int len = MakeBias(&bias, BTYPE_AUTO, 0, obuffer, sizeof(obuffer));
     if (len > 0) {
-      this->write(obuffer, len);
+      _outBuffer.append(QByteArray(obuffer, len));
     }
   }
Index: trunk/BNC/upload/bncrtnetuploadcaster.h
===================================================================
--- trunk/BNC/upload/bncrtnetuploadcaster.h	(revision 3225)
+++ trunk/BNC/upload/bncrtnetuploadcaster.h	(revision 3226)
@@ -25,9 +25,7 @@
                   const QString& rnxFileName,
                   const QString& outFileName);
+  void decodeRtnetStream(char* buffer, int bufLen);
  protected:
   virtual ~bncRtnetUploadCaster();
- public:
-  virtual void run();
-  void decodeRtnetStream(char* buffer, int bufLen);
  private:
   void uploadClockOrbitBias();
@@ -41,5 +39,4 @@
   bncEphUser*    _ephUser;
   QString        _rtnetStreamBuffer;
-  bncTime        _epoTime;
   QString        _crdTrafo;
   bool           _CoM;
Index: trunk/BNC/upload/bncuploadcaster.cpp
===================================================================
--- trunk/BNC/upload/bncuploadcaster.cpp	(revision 3225)
+++ trunk/BNC/upload/bncuploadcaster.cpp	(revision 3226)
@@ -38,5 +38,4 @@
   _sOpenTrial    = 0;
   _isToBeDeleted = false;
-
 }
 
@@ -55,4 +54,28 @@
   if (isRunning()) {
     wait();
+  }
+}
+
+// Endless Loop
+////////////////////////////////////////////////////////////////////////////
+void bncUploadCaster::run() {
+  while (true) {
+    if (_isToBeDeleted) {
+      QThread::quit();
+      deleteLater();
+      return;
+    }
+    open();
+    if (_outSocket && _outSocket->state() == QAbstractSocket::ConnectedState) {
+      QMutexLocker locker(&_mutex);
+      _outSocket->write(_outBuffer);
+      _outSocket->flush();
+      _outBuffer.clear();
+    }
+    else {
+      QMutexLocker locker(&_mutex);
+      _outBuffer.clear();
+    }
+    sleep(5);
   }
 }
@@ -117,11 +140,2 @@
 }
 
-// Write buffer
-////////////////////////////////////////////////////////////////////////////
-void bncUploadCaster::write(char* buffer, unsigned len) {
-  if (_outSocket && _outSocket->state() == QAbstractSocket::ConnectedState) {
-    _outSocket->write(buffer, len);
-    _outSocket->flush();
-  }
-}
-
Index: trunk/BNC/upload/bncuploadcaster.h
===================================================================
--- trunk/BNC/upload/bncuploadcaster.h	(revision 3225)
+++ trunk/BNC/upload/bncuploadcaster.h	(revision 3226)
@@ -11,12 +11,9 @@
                   const QString& password);
   virtual void deleteSafely();
-  virtual void run() = 0;
 
  protected:
-  virtual ~bncUploadCaster();
-  void    open();
-  void    write(char* buffer, unsigned len);
-  QMutex  _mutex;  
-  bool    _isToBeDeleted;
+  virtual    ~bncUploadCaster();
+  QMutex     _mutex;  
+  QByteArray _outBuffer;
 
  signals:
@@ -24,11 +21,14 @@
 
  private:
-  QString        _mountpoint;
-  QString        _outHost;
-  int            _outPort;
-  QString        _password;
-  QTcpSocket*    _outSocket;
-  int            _sOpenTrial;
-  QDateTime      _outSocketOpenTime;
+  void         open();
+  virtual void run();
+  bool        _isToBeDeleted;
+  QString     _mountpoint;
+  QString     _outHost;
+  int         _outPort;
+  QString     _password;
+  QTcpSocket* _outSocket;
+  int         _sOpenTrial;
+  QDateTime   _outSocketOpenTime;
 };
 
