Index: /branches/BNC_LM/bncgetthread.cpp
===================================================================
--- /branches/BNC_LM/bncgetthread.cpp	(revision 3571)
+++ /branches/BNC_LM/bncgetthread.cpp	(revision 3572)
@@ -52,5 +52,4 @@
 #include "bncapp.h"
 #include "bncutils.h"
-#include "bncrinex.h"
 #include "bnczerodecoder.h"
 #include "bncnetqueryv0.h"
@@ -93,10 +92,8 @@
                            const QByteArray& longitude,
                            const QByteArray& nmea, 
-                           const QByteArray& ntripVersion,
-                           const QByteArray& staIDextra) {
+                           const QByteArray& ntripVersion) {
   _rawFile      = 0;
   _mountPoint   = mountPoint;
   _staID        = mountPoint.path().mid(1).toAscii();
-  _staID_extra  = staIDextra;
   _format       = format;
   _latitude     = latitude;
@@ -111,4 +108,5 @@
 
   initialize();
+  initDecoder();
 }
 
@@ -116,4 +114,6 @@
 ////////////////////////////////////////////////////////////////////////////
 void bncGetThread::initialize() {
+
+  bncSettings settings;
 
   setTerminationEnabled(true);
@@ -125,23 +125,9 @@
 
   _isToBeDeleted = false;
-  _decoder       = 0;
   _query         = 0;
   _nextSleep     = 0;
   _PPPclient     = 0;
-
-  bncSettings settings;
-
-  _miscMount = settings.value("miscMount").toString();
-
-  // RINEX writer
-  // ------------
-  _samplingRate = settings.value("rnxSampl").toInt();
-  if ( settings.value("rnxPath").toString().isEmpty() ) { 
-    _rnx = 0;
-  }
-  else {
-    _rnx = new bncRinex(_staID, _mountPoint, _latitude, 
-                        _longitude, _nmea, _ntripVersion);
-  }
+  _miscMount     = settings.value("miscMount").toString();
+  _decoder   = 0;
 
   // Serial Port
@@ -151,5 +137,6 @@
   _serialPort    = 0;
 
-  if (settings.value("serialMountPoint").toString() == _staID) {
+  if (!_staID.isEmpty() &&
+      settings.value("serialMountPoint").toString() == _staID) {
     _serialPort = new QextSerialPort(settings.value("serialPortName").toString() );
     _serialPort->setTimeout(0,100);
@@ -279,9 +266,69 @@
   }
 
+  if (!_staID.isEmpty()) {
+    _latencyChecker = new latencyChecker(_staID);
+  }
+  else {
+    _latencyChecker = 0;
+  }
+}
+
+// Instantiate the decoder
+//////////////////////////////////////////////////////////////////////////////
+t_irc bncGetThread::initDecoder() {
+
+  _decoder = 0;
+
+  if      (_format.indexOf("RTCM_2") != -1 || _format.indexOf("RTCM2") != -1 ||
+           _format.indexOf("RTCM 2") != -1 ) {
+    emit(newMessage(_staID + ": Get data in RTCM 2.x format", true));
+    _decoder = new RTCM2Decoder(_staID.data());
+  }
+  else if (_format.indexOf("RTCM_3") != -1 || _format.indexOf("RTCM3") != -1 ||
+           _format.indexOf("RTCM 3") != -1 ) {
+    emit(newMessage(_staID + ": Get data in RTCM 3.x format", true));
+    RTCM3Decoder* newDecoder = new RTCM3Decoder(_staID, _rawFile);
+    _decoder = newDecoder;
+    connect((RTCM3Decoder*) newDecoder, SIGNAL(newMessage(QByteArray,bool)), 
+            this, SIGNAL(newMessage(QByteArray,bool)));
+  }
+  else if (_format.indexOf("GPSS") != -1 || _format.indexOf("BNC") != -1) {
+    emit(newMessage(_staID + ": Get Data in GPSS format", true));
+    _decoder = new gpssDecoder();
+  }
+  else if (_format.indexOf("ZERO") != -1) {
+    emit(newMessage(_staID + ": Get data in original format", true));
+    _decoder = new bncZeroDecoder(_staID);
+  }
+  else if (_format.indexOf("RTNET") != -1) {
+    emit(newMessage(_staID + ": Get data in RTNet format", true));
+    _decoder = new bncRtnetDecoder();
+  }
+  else if (_format.indexOf("HASS2ASCII") != -1) {
+    emit(newMessage(_staID + ": Get data in HASS2ASCII format", true));
+    _decoder = new hassDecoder(_staID);
+  }
+  else {
+    emit(newMessage(_staID + ": Unknown data format " + _format, true));
+    _isToBeDeleted = true;
+    return failure;
+  }
+
+  msleep(100); //sleep 0.1 sec
+  
+////  _decoder->initRinex(_staID, _mountPoint, _latitude, _longitude, 
+////                               _nmea, _ntripVersion);
+
+  if (_rawFile) {
+    _decodersRaw[_staID] = _decoder;
+  }
+
   // Initialize PPP Client?
   // ----------------------
 #ifndef MLS_SOFTWARE
+  bncSettings settings;
   if (settings.value("pppMount").toString() == _staID) {
     _PPPclient = new bncPPPclient(_staID);
+    bncApp* app = (bncApp*) qApp;
     app->_bncPPPclient = _PPPclient;
     qRegisterMetaType<bncTime>("bncTime");
@@ -293,42 +340,19 @@
 #endif
 
-  // Instantiate the decoder
-  // -----------------------
-  if      (_format.indexOf("RTCM_2") != -1 || _format.indexOf("RTCM2") != -1 ||
-           _format.indexOf("RTCM 2") != -1 ) {
-    emit(newMessage(_staID + ": Get data in RTCM 2.x format", true));
-    _decoder = new RTCM2Decoder(_staID.data());
-  }
-  else if (_format.indexOf("RTCM_3") != -1 || _format.indexOf("RTCM3") != -1 ||
-           _format.indexOf("RTCM 3") != -1 ) {
-    emit(newMessage(_staID + ": Get data in RTCM 3.x format", true));
-    _decoder = new RTCM3Decoder(_staID, _rawFile);
-    connect((RTCM3Decoder*) _decoder, SIGNAL(newMessage(QByteArray,bool)), 
-            this, SIGNAL(newMessage(QByteArray,bool)));
-  }
-  else if (_format.indexOf("GPSS") != -1 || _format.indexOf("BNC") != -1) {
-    emit(newMessage(_staID + ": Get Data in GPSS format", true));
-    _decoder = new gpssDecoder();
-  }
-  else if (_format.indexOf("ZERO") != -1) {
-    emit(newMessage(_staID + ": Get data in original format", true));
-    _decoder = new bncZeroDecoder(_staID);
-  }
-  else if (_format.indexOf("RTNET") != -1) {
-    emit(newMessage(_staID + ": Get data in RTNet format", true));
-    _decoder = new bncRtnetDecoder();
-  }
-  else if (_format.indexOf("HASS2ASCII") != -1) {
-    emit(newMessage(_staID + ": Get data in HASS format", true));
-    _decoder = new hassDecoder(_staID);
+  return success;
+}
+
+// Current decoder in use
+////////////////////////////////////////////////////////////////////////////
+GPSDecoder* bncGetThread::decoder() {
+  if (!_rawFile) {
+    return _decoder;
   }
   else {
-    emit(newMessage(_staID + ": Unknown data format " + _format, true));
-    _isToBeDeleted = true;
-  }
-
-  _latencyChecker = new latencyChecker(_staID);
-
-  msleep(100); //sleep 0.1 sec
+    if (_decodersRaw.contains(_staID) || initDecoder() == success) {
+      return _decodersRaw[_staID];
+    }
+  }
+  return 0;
 }
 
@@ -344,6 +368,14 @@
   }
   delete _PPPclient;
-  delete _decoder;
-  delete _rnx;
+  if (_rawFile) {
+    QMapIterator<QString, GPSDecoder*> it(_decodersRaw);
+    while (it.hasNext()) {
+      it.next();
+      delete it.value();
+    }
+  }
+  else {
+    delete _decoder;
+  }
   delete _rawFile;
   delete _serialOutFile;
@@ -375,5 +407,7 @@
 
       if (tryReconnect() != success) {
-        _latencyChecker->checkReconnect();
+        if (_latencyChecker) {
+          _latencyChecker->checkReconnect();
+        }
         continue;
       }
@@ -381,5 +415,15 @@
       // Delete old observations
       // -----------------------
-      _decoder->_obsList.clear();
+      if (_rawFile) {
+        QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
+        while (itDec.hasNext()) {
+          itDec.next();
+          GPSDecoder* decoder = itDec.value();
+          decoder->_obsList.clear();
+        }
+      }
+      else {
+        _decoder->_obsList.clear();
+      }
 
       // Read Data
@@ -391,10 +435,13 @@
       else if (_rawFile) {
         data = _rawFile->readChunk();
+        _format = _rawFile->format();
+        _staID  = _rawFile->staID();
 
         if (data.isEmpty()) {
           cout << "no more data" << endl;
+          ((bncApp*) qApp)->stopCombination();
           QThread::exit(0);
-          this->deleteLater();
-          return;
+          delete this;
+          ::exit(0);
         }
       }
@@ -404,5 +451,7 @@
       // ------------------
       if (nBytes == 0) {
-        _latencyChecker->checkReconnect();
+        if (_latencyChecker) {
+          _latencyChecker->checkReconnect();
+        }
         emit(newMessage(_staID + ": Data timeout, reconnecting", true));
         msleep(10000); //sleep 10 sec, G. Weber
@@ -428,14 +477,20 @@
       // -----------
       vector<string> errmsg;
-      _decoder->_obsList.clear();
-      t_irc irc = _decoder->Decode(data.data(), data.size(), errmsg);
+      if (!decoder()) {
+        _isToBeDeleted = true;
+        continue;
+      }
+      decoder()->_obsList.clear();
+      t_irc irc = decoder()->Decode(data.data(), data.size(), errmsg);
 
       // Perform various scans and checks
       // --------------------------------
-      _latencyChecker->checkOutage(irc == success);
-      _latencyChecker->checkObsLatency(_decoder->_obsList);
-      _latencyChecker->checkCorrLatency(_decoder->corrGPSEpochTime());
-
-      emit newLatency(_staID, _latencyChecker->currentLatency());
+      if (_latencyChecker) {
+        _latencyChecker->checkOutage(irc == success);
+        _latencyChecker->checkObsLatency(decoder()->_obsList);
+        _latencyChecker->checkCorrLatency(decoder()->corrGPSEpochTime());
+        
+        emit newLatency(_staID, _latencyChecker->currentLatency());
+      }
 
       scanRTCM();            
@@ -443,5 +498,5 @@
       // Loop over all observations (observations output)
       // ------------------------------------------------
-      QListIterator<t_obs> it(_decoder->_obsList);
+      QListIterator<t_obs> it(decoder()->_obsList);
       bool firstObs = true;
       while (it.hasNext()) {
@@ -455,5 +510,5 @@
         // Check observation epoch
         // -----------------------
-        if (!_rawFile && !dynamic_cast<gpssDecoder*>(_decoder)) {
+        if (!_rawFile && !dynamic_cast<gpssDecoder*>(decoder())) {
           int    week;
           double sec;
@@ -469,33 +524,28 @@
         // Check observations coming twice (e.g. KOUR0 Problem)
         // ----------------------------------------------------
-        QMap<QString, long>::const_iterator it = _prnLastEpo.find(prn);
-        if (it != _prnLastEpo.end()) {
-          long oldTime = it.value();
-          if      (obsTime <  oldTime) {
-            emit( newMessage(_staID + 
-               ": old observation " + prn.toAscii(), false));
-            continue;
+        if (!_rawFile) {
+          QMap<QString, long>::const_iterator it = _prnLastEpo.find(prn);
+          if (it != _prnLastEpo.end()) {
+            long oldTime = it.value();
+            if      (obsTime <  oldTime) {
+              emit( newMessage(_staID + 
+                 ": old observation " + prn.toAscii(), false));
+              continue;
+            }
+            else if (obsTime == oldTime) {
+              emit( newMessage(_staID + 
+                 ": observation coming more than once " + prn.toAscii(), false));
+              continue;
+            }
           }
-          else if (obsTime == oldTime) {
-            emit( newMessage(_staID + 
-               ": observation coming more than once " + prn.toAscii(), false));
-            continue;
-          }
-        }
-        _prnLastEpo[prn] = obsTime;
-
-        // RINEX Output
-        // ------------
-        if (_rnx) {
-          if (_samplingRate == 0 || iSec % _samplingRate == 0) {
-            _rnx->deepCopy(obs);
-          }
-          _rnx->dumpEpoch(_format, obsTime);
-        }
-      
+          _prnLastEpo[prn] = obsTime;
+        }
+
+	////        decoder()->dumpRinexEpoch(obs, _format);
+
         // PPP Client
         // ----------
 #ifndef MLS_SOFTWARE
-        if (_PPPclient) {
+        if (_PPPclient && _staID == _PPPclient->staID()) {
           _PPPclient->putNewObs(obs);
         }
@@ -509,5 +559,5 @@
         firstObs = false;
       }
-      _decoder->_obsList.clear();
+      decoder()->_obsList.clear();
     }
     catch (Exception& exc) {
@@ -530,6 +580,14 @@
   if (_query && _query->status() == bncNetQuery::running) {
     _nextSleep = 0;
-    if (_rnx) {
-      _rnx->setReconnectFlag(false);
+    if (_rawFile) {
+      QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
+      while (itDec.hasNext()) {
+        itDec.next();
+        GPSDecoder* decoder = itDec.value();
+	///        decoder->setRinexReconnectFlag(false);
+      }
+    }
+    else {
+      ///      _decoder->setRinexReconnectFlag(false);
     }
     return success;
@@ -593,6 +651,14 @@
   }
 
-  if (_rnx) {
-    _rnx->setReconnectFlag(true);
+  if (_rawFile) {
+    QMapIterator<QString, GPSDecoder*> itDec(_decodersRaw);
+    while (itDec.hasNext()) {
+      itDec.next();
+      GPSDecoder* decoder = itDec.value();
+      ///      decoder->setRinexReconnectFlag(false);
+    }
+  }
+  else {
+    ///   _decoder->setRinexReconnectFlag(false);
   }
 
@@ -604,4 +670,8 @@
 void bncGetThread::scanRTCM() {
 
+  if (!decoder()) {
+    return;
+  }
+
   bncSettings settings;
   if ( Qt::CheckState(settings.value("scanRTCM").toInt()) == Qt::Checked ) {
@@ -611,6 +681,6 @@
       // RTCM message types
       // ------------------
-      for (int ii = 0; ii <_decoder->_typeList.size(); ii++) {
-        QString type =  QString("%1 ").arg(_decoder->_typeList[ii]);
+      for (int ii = 0; ii <decoder()->_typeList.size(); ii++) {
+        QString type =  QString("%1 ").arg(decoder()->_typeList[ii]);
         emit(newMessage(_staID + ": Received message type " + type.toAscii(), true));
       }
@@ -618,6 +688,6 @@
       // RTCMv3 antenna descriptor
       // -------------------------
-      for (int ii=0;ii<_decoder->_antType.size();ii++) {
-        QString ant1 =  QString("%1 ").arg(_decoder->_antType[ii]);
+      for (int ii=0;ii<decoder()->_antType.size();ii++) {
+        QString ant1 =  QString("%1 ").arg(decoder()->_antType[ii]);
         emit(newMessage(_staID + ": Antenna descriptor " + ant1.toAscii(), true));
       }
@@ -625,25 +695,25 @@
       // RTCM Antenna Coordinates
       // ------------------------
-      for (int ii=0; ii <_decoder->_antList.size(); ii++) {
+      for (int ii=0; ii <decoder()->_antList.size(); ii++) {
         QByteArray antT;
-        if      (_decoder->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
+        if      (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
           antT = "ARP";
         }
-        else if (_decoder->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
+        else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
           antT = "APC";
         }
         QByteArray ant1, ant2, ant3;
-        ant1 = QString("%1 ").arg(_decoder->_antList[ii].xx,0,'f',4).toAscii();
-        ant2 = QString("%1 ").arg(_decoder->_antList[ii].yy,0,'f',4).toAscii();
-        ant3 = QString("%1 ").arg(_decoder->_antList[ii].zz,0,'f',4).toAscii();
+        ant1 = QString("%1 ").arg(decoder()->_antList[ii].xx,0,'f',4).toAscii();
+        ant2 = QString("%1 ").arg(decoder()->_antList[ii].yy,0,'f',4).toAscii();
+        ant3 = QString("%1 ").arg(decoder()->_antList[ii].zz,0,'f',4).toAscii();
         emit(newMessage(_staID + ": " + antT + " (ITRF) X " + ant1 + "m", true));
         emit(newMessage(_staID + ": " + antT + " (ITRF) Y " + ant2 + "m", true));
         emit(newMessage(_staID + ": " + antT + " (ITRF) Z " + ant3 + "m", true));
-        if (_decoder->_antList[ii].height_f) {
-          QByteArray ant4 = QString("%1 ").arg(_decoder->_antList[ii].height,0,'f',4).toAscii();
+        if (decoder()->_antList[ii].height_f) {
+          QByteArray ant4 = QString("%1 ").arg(decoder()->_antList[ii].height,0,'f',4).toAscii();
           emit(newMessage(_staID + ": Antenna height above marker "  + ant4 + "m", true));
         }
-        emit(newAntCrd(_staID, _decoder->_antList[ii].xx, 
-                       _decoder->_antList[ii].yy, _decoder->_antList[ii].zz, 
+        emit(newAntCrd(_staID, decoder()->_antList[ii].xx, 
+                       decoder()->_antList[ii].yy, decoder()->_antList[ii].zz, 
                        antT));
       }
@@ -652,28 +722,25 @@
 
 #ifdef MLS_SOFTWARE
-  for (int ii=0; ii <_decoder->_antList.size(); ii++) {
+  for (int ii=0; ii <decoder()->_antList.size(); ii++) {
         QByteArray antT;
-        if      (_decoder->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
+        if      (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::ARP) {
           antT = "ARP";
         }
-        else if (_decoder->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
+        else if (decoder()->_antList[ii].type == GPSDecoder::t_antInfo::APC) {
           antT = "APC";
         }
-        emit(newAntCrd(_staID, _decoder->_antList[ii].xx, 
-                       _decoder->_antList[ii].yy, _decoder->_antList[ii].zz, 
+        emit(newAntCrd(_staID, decoder()->_antList[ii].xx, 
+                       decoder()->_antList[ii].yy, decoder()->_antList[ii].zz, 
                        antT));
   }
 
-  for (int ii = 0; ii <_decoder->_typeList.size(); ii++) {
-    emit(newRTCMMessage(_staID, _decoder->_typeList[ii]));
+  for (int ii = 0; ii <decoder()->_typeList.size(); ii++) {
+    emit(newRTCMMessage(_staID, decoder()->_typeList[ii]));
   }
 #endif
 
-
-
-
-  _decoder->_typeList.clear();
-  _decoder->_antType.clear();
-  _decoder->_antList.clear();
+  decoder()->_typeList.clear();
+  decoder()->_antType.clear();
+  decoder()->_antList.clear();
 }
 
@@ -704,40 +771,2 @@
   }
 }
-
-//
-//////////////////////////////////////////////////////////////////////////////
-void bncGetThread::slotNewEphGPS(gpsephemeris gpseph) {
-  RTCM2Decoder* decoder2 = dynamic_cast<RTCM2Decoder*>(_decoder);
-  RTCM3Decoder* decoder3 = dynamic_cast<RTCM3Decoder*>(_decoder);
-
-  if ( decoder2 ) {
-    QMutexLocker locker(&_mutex);
-  
-    string storedPRN;
-    vector<int> IODs;
-    
-    if ( decoder2->storeEph(gpseph, storedPRN, IODs) ) {
-#ifdef DEBUG_RTCM2_2021
-      QString msg = _staID + QString(": stored eph %1 IODs").arg(storedPRN.c_str());
-      
-      for (unsigned ii = 0; ii < IODs.size(); ii++) {
-        msg += QString(" %1").arg(IODs[ii],4);
-      }
-      
-      emit(newMessage(msg.toAscii()));
-#endif
-    }
-  }
-
-  if ( decoder3 ) {
-    QMutexLocker locker(&_mutex);
-  
-    if ( decoder3->storeEph(gpseph) ) {
-#ifdef DEBUG_RTCM3
-      QString msg = _staID + QString(": RTCM3Decoder, stored eph for satellite %1").arg(gpseph.satellite);
-      emit(newMessage(msg.toAscii(),true));
-#endif
-    }
-  }
-}
-
Index: /branches/BNC_LM/bncgetthread.h
===================================================================
--- /branches/BNC_LM/bncgetthread.h	(revision 3571)
+++ /branches/BNC_LM/bncgetthread.h	(revision 3572)
@@ -38,5 +38,4 @@
 #include "bncrawfile.h"
 
-class bncRinex;
 class QextSerialPort;
 class latencyChecker;
@@ -53,6 +52,5 @@
                 const QByteArray& longitude,
                 const QByteArray& nmea, 
-                const QByteArray& ntripVersion,
-                const QByteArray& staIDextra = "");
+                const QByteArray& ntripVersion);
 
    bncNetQuery::queryStatus queryStatus() {
@@ -72,5 +70,4 @@
 
    QByteArray staID() const {return _staID;}
-   QByteArray staIDextra() const {return _staID_extra;}
    QUrl       mountPoint() const {return _mountPoint;}
    QByteArray latitude() const {return _latitude;}
@@ -92,7 +89,4 @@
    virtual void run();
 
- public slots:
-   void slotNewEphGPS(gpsephemeris gpseph);
-
  private slots:
    void slotSerialReadyRead();
@@ -100,4 +94,6 @@
  private:
    enum t_serialNMEA {NO_NMEA, MANUAL_NMEA, AUTO_NMEA};
+   t_irc        initDecoder();
+   GPSDecoder* decoder();
 
    void  initialize();
@@ -105,30 +101,27 @@
    void  scanRTCM();
 
-   GPSDecoder*     _decoder;
-   bncNetQuery*    _query;
-   QUrl            _mountPoint;
-   QByteArray      _staID;
-   QByteArray      _staID_extra;
-   QByteArray      _format;
-   QByteArray      _latitude;
-   QByteArray      _longitude;
-   QByteArray      _height;
-   QByteArray      _nmea;
-   QByteArray      _ntripVersion;
-   int             _nextSleep;
-   int             _iMount;
-   int             _samplingRate;
-   bncRinex*       _rnx;
-   bncRawFile*     _rawFile;
-   QextSerialPort* _serialPort;
-   bool            _isToBeDeleted;
-   latencyChecker* _latencyChecker;
-   QString         _miscMount;
-   QFile*          _serialOutFile;
-   t_serialNMEA    _serialNMEA;
-   QMutex          _mutex;
-   bncPPPclient*   _PPPclient;
-   bool            _rawOutput;
-   QMap<QString, long> _prnLastEpo;
+   QMap<QString, GPSDecoder*> _decodersRaw;
+   GPSDecoder*                _decoder;
+   bncNetQuery*               _query;
+   QUrl                       _mountPoint;
+   QByteArray                 _staID;
+   QByteArray                 _format;
+   QByteArray                 _latitude;
+   QByteArray                 _longitude;
+   QByteArray                 _height;
+   QByteArray                 _nmea;
+   QByteArray                 _ntripVersion;
+   int                        _nextSleep;
+   int                        _iMount;
+   bncRawFile*                _rawFile;
+   QextSerialPort*            _serialPort;
+   bool                       _isToBeDeleted;
+   latencyChecker*            _latencyChecker;
+   QString                    _miscMount;
+   QFile*                     _serialOutFile;
+   t_serialNMEA               _serialNMEA;
+   bncPPPclient*              _PPPclient;
+   bool                       _rawOutput;
+   QMap<QString, long>        _prnLastEpo;
 };
 
