Index: trunk/BNC/upload/bncrtnetdecoder.cpp
===================================================================
--- trunk/BNC/upload/bncrtnetdecoder.cpp	(revision 3203)
+++ trunk/BNC/upload/bncrtnetdecoder.cpp	(revision 3206)
@@ -49,24 +49,8 @@
 //////////////////////////////////////////////////////////////////////// 
 bncRtnetDecoder::bncRtnetDecoder() {
-}
-
-// Destructor
-//////////////////////////////////////////////////////////////////////// 
-bncRtnetDecoder::~bncRtnetDecoder() {
-  for (int ic = 0; ic < _casters->size(); ic++) {
-    delete _casters->at(ic);
-  }
-  delete _casters;
-}
-
-// Run
-//////////////////////////////////////////////////////////////////////// 
-void bncRtnetDecoder::run() {
-
   bncSettings settings;
 
   // List of upload casters
   // ----------------------
-  _casters = new QVector<bncUploadCaster*>;
   QListIterator<QString> it(settings.value("uploadMountpointsOut").toStringList());
   while (it.hasNext()) {
@@ -75,15 +59,18 @@
       int  outPort = hlp[1].toInt();
       bool CoM     = (hlp[5].toInt() == Qt::Checked);
-      _casters->push_back(new bncUploadCaster(hlp[2], hlp[0], outPort,
-                                             hlp[3], hlp[4], CoM,
-                                             hlp[6], "", ""));
+      bncUploadCaster* newCaster = new bncUploadCaster(hlp[2], hlp[0], outPort, 
+                                                       hlp[3], hlp[4], CoM,
+                                                       hlp[6], "", "");
+      newCaster->start();
+      _casters.push_back(newCaster);
     }
   }
+}
 
-  // Endless Loop - Decode
-  // ---------------------
-  while (true) {
-    DecodeInThread();
-    msleep(10);
+// Destructor
+//////////////////////////////////////////////////////////////////////// 
+bncRtnetDecoder::~bncRtnetDecoder() {
+  for (int ic = 0; ic < _casters.size(); ic++) {
+    delete _casters[ic];
   }
 }
@@ -94,42 +81,8 @@
   QMutexLocker locker(&_mutex);
   errmsg.clear();
-  _buffer.append(QByteArray(buffer, bufLen));
+  for (int ic = 0; ic < _casters.size(); ic++) {
+    _casters[ic]->decodeRtnetStream(buffer, bufLen, _eph);
+  }
   return success;
 }
 
-// Decode and upload in separate thread
-//////////////////////////////////////////////////////////////////////// 
-void bncRtnetDecoder::DecodeInThread() {
-  QMutexLocker locker(&_mutex);
-
-  // Prepare list of lines with satellite positions in SP3-like format
-  // -----------------------------------------------------------------
-  QStringList lines;
-  int iLast = _buffer.lastIndexOf('\n');
-  if (iLast != -1) {
-    QStringList hlpLines = _buffer.split('\n', QString::SkipEmptyParts);
-    _buffer = _buffer.mid(iLast+1);
-    for (int ii = 0; ii < hlpLines.size(); ii++) {
-      if      (hlpLines[ii].indexOf('*') != -1) {
-        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];
-      }
-    }
-  }
-
-  // Satellite positions to be processed
-  // -----------------------------------
-  if (lines.size() > 0) {
-    for (int ic = 0; ic < _casters->size(); ic++) {
-      _casters->at(ic)->uploadClockOrbitBias(_epoTime, _eph, lines);
-    }
-  }
-}
-
Index: trunk/BNC/upload/bncrtnetdecoder.h
===================================================================
--- trunk/BNC/upload/bncrtnetdecoder.h	(revision 3203)
+++ trunk/BNC/upload/bncrtnetdecoder.h	(revision 3206)
@@ -33,17 +33,12 @@
 #include "RTCM/GPSDecoder.h"
 
-class bncRtnetDecoder: public GPSDecoder, public bncEphUser, public QThread {
+class bncRtnetDecoder: public GPSDecoder, public bncEphUser {
  public:
   bncRtnetDecoder();
   ~bncRtnetDecoder();
-  virtual void run();
   virtual t_irc Decode(char* buffer, int bufLen, 
                        std::vector<std::string>& errmsg);
  private:
-  void DecodeInThread();
-  QVector<bncUploadCaster*>* _casters;
-  QString                    _buffer;
-  bncTime                    _epoTime;
-  QMutex                     _mutex;
+  QVector<bncUploadCaster*> _casters;
 };
 
Index: trunk/BNC/upload/bncuploadcaster.cpp
===================================================================
--- trunk/BNC/upload/bncuploadcaster.cpp	(revision 3203)
+++ trunk/BNC/upload/bncuploadcaster.cpp	(revision 3206)
@@ -34,5 +34,4 @@
                                  const QString& rnxFileName,
                                  const QString& outFileName) {
-
   bncSettings settings;
 
@@ -181,4 +180,8 @@
     _t0  = settings.value("trafo_t0").toDouble();
   }
+ 
+  // Deep copy of ephemerides
+  // ------------------------
+  _ephMap = 0;
 }
 
@@ -186,7 +189,25 @@
 ////////////////////////////////////////////////////////////////////////////
 bncUploadCaster::~bncUploadCaster() {
+  if (_ephMap) {
+    QMapIterator<QString, t_eph*> it(*_ephMap);
+    while (it.hasNext()) {
+      it.next();
+      t_eph* eph = it.value();
+      delete eph;
+    }
+    delete _ephMap;
+  }
   delete _outFile;
   delete _rnx;
   delete _sp3;
+}
+
+// Endless Loop
+////////////////////////////////////////////////////////////////////////////
+void bncUploadCaster::run() {
+  while (true) {
+    uploadClockOrbitBias();
+    msleep(10);
+  }
 }
 
@@ -260,18 +281,96 @@
 }
 
-// Encode and Upload Clocks, Orbits, and Biases
-////////////////////////////////////////////////////////////////////////////
-void bncUploadCaster::uploadClockOrbitBias(const bncTime& epoTime, 
-                            const QMap<QString, bncEphUser::t_ephPair*>& ephMap,
-                            const QStringList& lines) {
+// 
+////////////////////////////////////////////////////////////////////////////
+void bncUploadCaster::decodeRtnetStream(char* buffer, int bufLen,
+                      const QMap<QString, bncEphUser::t_ephPair*>& ephPairMap) {
+                                        
+  QMutexLocker locker(&_mutex);
+
+  // Delete old ephemeris
+  // --------------------
+  if (_ephMap) {
+    QMapIterator<QString, t_eph*> it(*_ephMap);
+    while (it.hasNext()) {
+      it.next();
+      t_eph* eph = it.value();
+      delete eph;
+    }
+    delete _ephMap;
+  }
+  _ephMap = new QMap<QString, t_eph*>;
+
+  // Make a deep copy of ephemeris
+  // -----------------------------
+  QMapIterator<QString, bncEphUser::t_ephPair*> it(ephPairMap);
+  while (it.hasNext()) {
+    it.next();
+    bncEphUser::t_ephPair* pair = it.value();
+    t_eph* ep = pair->last;
+    if (pair->prev && ep && 
+        ep->receptDateTime().secsTo(QDateTime::currentDateTime()) < 60) {
+      ep = pair->prev;
+    }
+    QString prn(ep->prn().c_str());
+    if      (prn[0] == 'G') {
+      t_ephGPS* epGPS = static_cast<t_ephGPS*>(ep);
+      (*_ephMap)[prn] = new t_ephGPS(*epGPS);
+    }
+    else if (prn[0] == 'R') {
+      t_ephGlo* epGlo = static_cast<t_ephGlo*>(ep);
+      (*_ephMap)[prn] = new t_ephGlo(*epGlo);
+    }
+    else if (prn[0] == 'E') {
+      t_ephGal* epGal = static_cast<t_ephGal*>(ep);
+      (*_ephMap)[prn] = new t_ephGal(*epGal);
+    }
+  }
+
+  // Append to buffer
+  // ----------------
+  _rtnetStreamBuffer.append(QByteArray(buffer, bufLen));
+}
+
+// Function called in separate thread
+//////////////////////////////////////////////////////////////////////// 
+void bncUploadCaster::uploadClockOrbitBias() {
+
+  QMutexLocker locker(&_mutex);
+
+  // 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) {
+        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) {
+    return;
+  }
+
   this->open();
 
   unsigned year, month, day;
-  epoTime.civil_date(year, month, day);
+  _epoTime.civil_date(year, month, day);
   
   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;
@@ -288,5 +387,4 @@
     QString      prn;
     ColumnVector xx(14); xx = 0.0;
-    bncEphUser::t_ephPair*   pair = 0;
   
     QTextStream in(lines[ii].toAscii());
@@ -297,5 +395,7 @@
     }
 
-    if ( ephMap.contains(prn) ) {
+    if ( _ephMap->contains(prn) ) {
+      t_eph* ep = (*_ephMap)[prn];
+
       in >> xx(1) >> xx(2) >> xx(3) >> xx(4) >> xx(5) 
          >> xx(6) >> xx(7) >> xx(8) >> xx(9) >> xx(10)
@@ -314,19 +414,4 @@
       xx(14) *= 1e3;         // z-crd at time + dT
   
-      pair = ephMap[prn];
-    }
-  
-    // Use old ephemeris if the new one is too recent
-    // ----------------------------------------------
-    t_eph* ep = 0;
-    if (pair) {
-      ep = pair->last;
-      if (pair->prev && ep && 
-          ep->receptDateTime().secsTo(QDateTime::currentDateTime()) < 60) {
-        ep = pair->prev;
-      }
-    }
-  
-    if (ep != 0) {
       struct ClockOrbit::SatData* sd = 0;
       if      (prn[0] == 'G') {
@@ -340,7 +425,7 @@
       if (sd) {
         QString outLine;
-        processSatellite(ep, epoTime.gpsw(), epoTime.gpssec(), prn, xx, sd, outLine);
+        processSatellite(ep, _epoTime.gpsw(), _epoTime.gpssec(), prn, xx, sd, outLine);
         if (_outFile) {
-          _outFile->write(epoTime.gpsw(), epoTime.gpssec(), outLine);
+          _outFile->write(_epoTime.gpsw(), _epoTime.gpssec(), outLine);
         }
       }
@@ -386,6 +471,5 @@
   }
   
-  if ( this->usedSocket() && 
-       (co.NumberOfGPSSat > 0 || co.NumberOfGLONASSSat > 0) ) {
+  if (_outSocket && (co.NumberOfGPSSat > 0 || co.NumberOfGLONASSSat > 0)) {
     char obuffer[CLOCKORBIT_BUFFERSIZE];
   
@@ -396,6 +480,5 @@
   }
   
-  if ( this->usedSocket() && 
-       (bias.NumberOfGPSSat > 0 || bias.NumberOfGLONASSSat > 0) ) {
+  if (_outSocket && (bias.NumberOfGPSSat > 0 || bias.NumberOfGLONASSSat > 0)) {
     char obuffer[CLOCKORBIT_BUFFERSIZE];
     int len = MakeBias(&bias, BTYPE_AUTO, 0, obuffer, sizeof(obuffer));
@@ -527,2 +610,3 @@
   xyz = sc * rMat * xyz + dx;
 }
+
Index: trunk/BNC/upload/bncuploadcaster.h
===================================================================
--- trunk/BNC/upload/bncuploadcaster.h	(revision 3203)
+++ trunk/BNC/upload/bncuploadcaster.h	(revision 3206)
@@ -10,5 +10,5 @@
 class bncSP3;
 
-class bncUploadCaster : public QObject {
+class bncUploadCaster : public QThread {
  Q_OBJECT
  public:
@@ -21,11 +21,7 @@
                   const QString& outFileName);
   virtual ~bncUploadCaster();
-  void open();
-  void write(char* buffer, unsigned len);
-  void printAscii(const QString& line);
-  bool usedSocket() const {return _outSocket;}
-  void uploadClockOrbitBias(const bncTime& epoTime, 
-                            const QMap<QString, bncEphUser::t_ephPair*>& ephMap,
-                            const QStringList& lines);
+  virtual void run();
+  void decodeRtnetStream(char* buffer, int bufLen,
+                         const QMap<QString, bncEphUser::t_ephPair*>& ephMap);
 
  signals:
@@ -33,4 +29,7 @@
 
  private:
+  void open();
+  void write(char* buffer, unsigned len);
+  void uploadClockOrbitBias();
   void processSatellite(t_eph* eph, int GPSweek, 
                         double GPSweeks, const QString& prn, 
@@ -39,4 +38,9 @@
                         QString& outLine);
   void crdTrafo(int GPSWeek, ColumnVector& xyz);
+
+  QMap<QString, t_eph*>* _ephMap;
+  QMutex                 _mutex;  
+  QString                _rtnetStreamBuffer;
+  bncTime                _epoTime;
   QString        _mountpoint;
   QString        _outHost;
