Index: trunk/BNC/bncgetthread.cpp
===================================================================
--- trunk/BNC/bncgetthread.cpp	(revision 3522)
+++ trunk/BNC/bncgetthread.cpp	(revision 3523)
@@ -111,4 +111,5 @@
 
   initialize();
+  initDecoder();
 }
 
@@ -125,6 +126,4 @@
 
   _isToBeDeleted = false;
-  _decoder       = 0;
-  _decoderAux    = 0;
   _query         = 0;
   _nextSleep     = 0;
@@ -294,42 +293,59 @@
 #endif
 
-  // Instantiate the decoder
-  // -----------------------
+  _latencyChecker = new latencyChecker(_staID);
+}
+
+// Instantiate the decoder
+//////////////////////////////////////////////////////////////////////////////
+t_irc bncGetThread::initDecoder() {
+
   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());
+    _decoders[_staID] = 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)), 
+    _decoders[_staID] = 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();
+    _decoders[_staID] = new gpssDecoder();
   }
   else if (_format.indexOf("ZERO") != -1) {
     emit(newMessage(_staID + ": Get data in original format", true));
-    _decoder = new bncZeroDecoder(_staID);
+    _decoders[_staID] = new bncZeroDecoder(_staID);
   }
   else if (_format.indexOf("RTNET") != -1) {
     emit(newMessage(_staID + ": Get data in RTNet format", true));
-    _decoder = new bncRtnetDecoder();
+    _decoders[_staID] = new bncRtnetDecoder();
   }
   else if (_format.indexOf("HASS2ASCII") != -1) {
     emit(newMessage(_staID + ": Get data in HASS2ASCII format", true));
-    _decoder = new hassDecoder(_staID);
+    _decoders[_staID] = new hassDecoder(_staID);
   }
   else {
     emit(newMessage(_staID + ": Unknown data format " + _format, true));
     _isToBeDeleted = true;
-  }
-
-  _latencyChecker = new latencyChecker(_staID);
+    return failure;
+  }
 
   msleep(100); //sleep 0.1 sec
+  
+  return success;
+}
+
+// Current decoder in use
+////////////////////////////////////////////////////////////////////////////
+GPSDecoder* bncGetThread::decoder() {
+  if (_decoders.contains(_staID) || initDecoder() == success) {
+    return _decoders.value(_staID);
+  }
+  else {
+    return 0;
+  }
 }
 
@@ -345,6 +361,9 @@
   }
   delete _PPPclient;
-  delete _decoder;
-  delete _decoderAux;
+  QMapIterator<QString, GPSDecoder*> it(_decoders);
+  while (it.hasNext()) {
+    it.next();
+    delete it.value();
+  }
   delete _rnx;
   delete _rawFile;
@@ -383,10 +402,10 @@
       // Delete old observations
       // -----------------------
-      _decoder->_obsList.clear();
-      if (_decoderAux) {
-        _decoderAux->_obsList.clear();
-      }
-
-      GPSDecoder* decoderUsed = _decoder;
+      QMapIterator<QString, GPSDecoder*> itDec(_decoders);
+      while (itDec.hasNext()) {
+        itDec.next();
+        GPSDecoder* decoder = itDec.value();
+        decoder->_obsList.clear();
+      }
 
       // Read Data
@@ -398,11 +417,6 @@
       else if (_rawFile) {
         data = _rawFile->readChunk();
-        if (_rawFile->format() == "HASS2ASCII") {
-          if (_decoderAux == 0) {
-            emit(newMessage(_rawFile->staID() + ": Get data in HASS2ASCII format", true));
-            _decoderAux = new hassDecoder(_rawFile->staID());
-          }
-          decoderUsed = _decoderAux;
-        }
+        _format = _rawFile->format();
+        _staID  = _rawFile->staID();
 
         if (data.isEmpty()) {
@@ -442,12 +456,12 @@
       // -----------
       vector<string> errmsg;
-      decoderUsed->_obsList.clear();
-      t_irc irc = decoderUsed->Decode(data.data(), data.size(), errmsg);
+      decoder()->_obsList.clear();
+      t_irc irc = decoder()->Decode(data.data(), data.size(), errmsg);
 
       // Perform various scans and checks
       // --------------------------------
       _latencyChecker->checkOutage(irc == success);
-      _latencyChecker->checkObsLatency(decoderUsed->_obsList);
-      _latencyChecker->checkCorrLatency(decoderUsed->corrGPSEpochTime());
+      _latencyChecker->checkObsLatency(decoder()->_obsList);
+      _latencyChecker->checkCorrLatency(decoder()->corrGPSEpochTime());
 
       emit newLatency(_staID, _latencyChecker->currentLatency());
@@ -457,5 +471,5 @@
       // Loop over all observations (observations output)
       // ------------------------------------------------
-      QListIterator<t_obs> it(decoderUsed->_obsList);
+      QListIterator<t_obs> it(decoder()->_obsList);
       bool firstObs = true;
       while (it.hasNext()) {
@@ -469,5 +483,5 @@
         // Check observation epoch
         // -----------------------
-        if (!_rawFile && !dynamic_cast<gpssDecoder*>(decoderUsed)) {
+        if (!_rawFile && !dynamic_cast<gpssDecoder*>(decoder())) {
           int    week;
           double sec;
@@ -523,5 +537,5 @@
         firstObs = false;
       }
-      decoderUsed->_obsList.clear();
+      decoder()->_obsList.clear();
     }
     catch (Exception& exc) {
@@ -625,6 +639,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));
       }
@@ -632,6 +646,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));
       }
@@ -639,25 +653,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));
       }
@@ -666,19 +680,19 @@
 
 #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
@@ -687,7 +701,7 @@
 
 
-  _decoder->_typeList.clear();
-  _decoder->_antType.clear();
-  _decoder->_antList.clear();
+  decoder()->_typeList.clear();
+  decoder()->_antType.clear();
+  decoder()->_antList.clear();
 }
 
@@ -722,6 +736,6 @@
 //////////////////////////////////////////////////////////////////////////////
 void bncGetThread::slotNewEphGPS(gpsephemeris gpseph) {
-  RTCM2Decoder* decoder2 = dynamic_cast<RTCM2Decoder*>(_decoder);
-  RTCM3Decoder* decoder3 = dynamic_cast<RTCM3Decoder*>(_decoder);
+  RTCM2Decoder* decoder2 = dynamic_cast<RTCM2Decoder*>(decoder());
+  RTCM3Decoder* decoder3 = dynamic_cast<RTCM3Decoder*>(decoder());
 
   if ( decoder2 ) {
Index: trunk/BNC/bncgetthread.h
===================================================================
--- trunk/BNC/bncgetthread.h	(revision 3522)
+++ trunk/BNC/bncgetthread.h	(revision 3523)
@@ -100,4 +100,6 @@
  private:
    enum t_serialNMEA {NO_NMEA, MANUAL_NMEA, AUTO_NMEA};
+   t_irc        initDecoder();
+   GPSDecoder* decoder();
 
    void  initialize();
@@ -105,31 +107,30 @@
    void  scanRTCM();
 
-   GPSDecoder*     _decoder;
-   GPSDecoder*     _decoderAux;
-   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*> _decoders;
+   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;
 };
 
