Index: trunk/BNC/GPSS/gpssDecoder.cpp
===================================================================
--- trunk/BNC/GPSS/gpssDecoder.cpp	(revision 1424)
+++ trunk/BNC/GPSS/gpssDecoder.cpp	(revision 1425)
@@ -41,5 +41,4 @@
 gpssDecoder::gpssDecoder() : GPSDecoder() {
   _mode       = MODE_SEARCH;
-  _recordSize = 0;
 
   connect(this, SIGNAL(newGPSEph(gpsephemeris*)), 
@@ -58,104 +57,73 @@
   errmsg.clear();
 
-  if (_mode == MODE_SEARCH) {
-    _buffer.clear();
-    _recordSize = 0;
-  }
   _buffer.append(data, dataLen);
 
-  unsigned offset     = 0;
-  for (offset = 0; offset < _buffer.size(); offset++) { 
+  for (;;) { 
 
-    switch(_mode) {
+    if      (_mode == MODE_SEARCH) {
+      if (_buffer.size() < 1) return success;
+      if (_buffer[0] == 0x02) {
+        _mode = MODE_TYPE;
+      }
+      _buffer.erase(0,1);
+    }
 
-      case MODE_SEARCH:
-        if (_buffer[offset] == 0x02) {
-          _mode = MODE_TYPE;
-        }
-        continue;
+    else if (_mode == MODE_TYPE) {
+      if (_buffer.size() < 1) return success;
+      if        (_buffer[0] == 0x00) {
+        _mode = MODE_EPOCH;
+      } else if (_buffer[0] == 0x01) {
+        _mode = MODE_EPH;
+      } else {
+        errmsg.push_back("Unknown record type");
+        _mode = MODE_SEARCH;
+      }
+      _buffer.erase(0,1);
+    }
 
-      case MODE_TYPE:
-        if        (_buffer[offset] == 0x00) {
-          _mode = MODE_EPOCH;
-        } else if (_buffer[offset] == 0x01) {
-          _mode = MODE_EPH;
-        } else {
-          errmsg.push_back("Unknown record type");
-          _mode = MODE_SEARCH;
-        }
-        continue;
+    else if (_mode == MODE_EPOCH || _mode == MODE_EPH) {
+      int recordSize;
+      if (_buffer.size() < sizeof(recordSize)) return success;
+      memcpy(&recordSize, _buffer.data(), sizeof(recordSize)); 
+      if (_mode == MODE_EPOCH) {
+        _mode = MODE_EPOCH_BODY;
+      }
+      if (_mode == MODE_EPH) {
+        _mode = MODE_EPH_BODY;
+      }
+      _buffer.erase(0,sizeof(recordSize));
+    }
 
-      case MODE_EPOCH:
-      case MODE_EPH:
-        if (offset+sizeof(_recordSize) > _buffer.size()) {
-          errmsg.push_back("Record size too large (A)");
-          _mode = MODE_SEARCH;
-        } else {
-          memcpy(&_recordSize, &_buffer[offset], sizeof(_recordSize)); 
-          if (_mode == MODE_EPOCH) {
-            _mode = MODE_EPOCH_BODY;
-          }
-          if (_mode == MODE_EPH) {
-            _mode = MODE_EPH_BODY;
-          }
-          offset += sizeof(_recordSize) - 1;
-        }
-        continue;
+    else if (_mode == MODE_EPOCH_BODY) {
+      EPOCHHEADER epochHdr;
+      if (_buffer.size() < sizeof(epochHdr)) return success;    
+      memcpy(&epochHdr, _buffer.data(), sizeof(epochHdr));
+      _buffer.erase(0,sizeof(epochHdr));
+      for (int is = 1; is <= epochHdr.n_svs; is++) {
+        if (_buffer.size() < sizeof(t_obsInternal)) return success;
+        t_obs* obs = new t_obs();
+        memcpy(&(obs->_o), _buffer.data(), sizeof(t_obsInternal));
+        _obsList.push_back(obs);
+        _buffer.erase(0, sizeof(t_obsInternal));
+      }
+      _mode = MODE_EPOCH_CRC;
+    }
 
-      case MODE_EPOCH_BODY:
-        if (offset + _recordSize > _buffer.size()) {
-          errmsg.push_back("Record size too large (B)");
-          _mode = MODE_SEARCH;
-        } else {
-          EPOCHHEADER epochHdr;
-          memcpy(&epochHdr, &_buffer[offset], sizeof(epochHdr));
-          offset += sizeof(epochHdr);
-          for (int is = 1; is <= epochHdr.n_svs; is++) {
-            t_obs* obs = new t_obs();
-            memcpy(&(obs->_o), &_buffer[offset], sizeof(obs->_o));
-            _obsList.push_back(obs);
-            offset += sizeof(obs->_o);
-          }
-          _mode = MODE_EPOCH_CRC;
-          --offset;
-        }
-        continue;
+    else if (_mode == MODE_EPH_BODY) {
+      if (_buffer.size() < sizeof(gpsephemeris)) return success;
+      gpsephemeris* gpsEph = new gpsephemeris;
+      memcpy(gpsEph, _buffer.data(), sizeof(gpsephemeris));
+      emit newGPSEph(gpsEph);
+      _buffer.erase(0, sizeof(gpsephemeris));
+      _mode = MODE_EPH_CRC;
+    }
 
-      case MODE_EPH_BODY:
-        if (offset + _recordSize > _buffer.size()) {
-          errmsg.push_back("Record size too large (C)");
-          _mode = MODE_SEARCH;
-        } else {
-          gpsephemeris* gpsEph = new gpsephemeris;
-          memcpy(gpsEph, &_buffer[offset], sizeof(gpsephemeris));
-          emit newGPSEph(gpsEph);
-          offset += sizeof(gpsephemeris) - 1;
-          _mode = MODE_EPH_CRC;
-        }
-        continue;
-
-      case MODE_EPOCH_CRC:
-        _mode = MODE_EPOCH_ETX; // TODO: CRC check
-        continue;
-
-      case MODE_EPH_CRC:
-        _mode = MODE_EPH_ETX;   // TODO: CRC check
-        continue;
-
-      case MODE_EPOCH_ETX:
-        _mode = MODE_SEARCH;
-        continue;
-
-      case MODE_EPH_ETX:
-        _mode = MODE_SEARCH;
-        continue;
+    else {
+      if (_buffer.size() < 1) return success;
+      _buffer.erase(0,1);
+      _mode = MODE_SEARCH;
     }
   }
 
-  if (errmsg.size() == 0) {
-    return success;
-  }
-  else {
-    return failure;
-  }
+  return success;
 }
Index: trunk/BNC/GPSS/gpssDecoder.h
===================================================================
--- trunk/BNC/GPSS/gpssDecoder.h	(revision 1424)
+++ trunk/BNC/GPSS/gpssDecoder.h	(revision 1425)
@@ -22,5 +22,4 @@
  private:
   int         _mode;
-  int         _recordSize;
   std::string _buffer;
 } ;
Index: trunk/BNC/bnc.pro
===================================================================
--- trunk/BNC/bnc.pro	(revision 1424)
+++ trunk/BNC/bnc.pro	(revision 1425)
@@ -2,6 +2,6 @@
 # Switch to debug configuration
 # -----------------------------
-CONFIG -= debug
-CONFIG += release
+CONFIG += debug
+CONFIG -= release
 
 DEFINES += NO_RTCM3_MAIN 
