Index: trunk/BNC/GPSS/gpssDecoder.cpp
===================================================================
--- trunk/BNC/GPSS/gpssDecoder.cpp	(revision 1427)
+++ trunk/BNC/GPSS/gpssDecoder.cpp	(revision 1429)
@@ -1,3 +1,3 @@
-
+\
 /* -------------------------------------------------------------------------
  * BKG NTRIP Client
@@ -57,89 +57,52 @@
   errmsg.clear();
 
-  if (_mode == MODE_SEARCH) {
-    _buffer.clear();
-  }
-  _buffer.append(data, dataLen);
+  _buffer += QByteArray(data, dataLen);
 
-  for (;;) { 
+  int iBeg;
+  while ( (iBeg = _buffer.indexOf(0x02)) != -1) {
+    _buffer = _buffer.mid(iBeg);
 
-    if (_buffer.size() < 1) {
-      _mode = MODE_SEARCH;
-      return success;
+    // Record Size
+    // -----------
+    int recordSize;
+    if (_buffer.length() >= int(2 + sizeof(recordSize)) &&
+        ( char(_buffer[1]) == 0x00 || char(_buffer[1]) == 0x01) ) {
+      memcpy(&recordSize, _buffer.data()+2, sizeof(recordSize)); 
+    }
+    else {
+      break;
+    }
+   
+    // Observations
+    // ------------
+    if      (char(_buffer[1]) == 0x00) {
+      EPOCHHEADER epochHdr;
+      if (_buffer.length() >= int(2 + sizeof(recordSize) + sizeof(epochHdr))) {
+        memcpy(&epochHdr, _buffer.data() + 2 + sizeof(recordSize), 
+               sizeof(epochHdr));
+
+        if (_buffer.length() >= int(2 + sizeof(recordSize) + sizeof(epochHdr) +
+                                epochHdr.n_svs * sizeof(t_obsInternal))) {
+          for (int is = 1; is <= epochHdr.n_svs; is++) {
+            t_obs* obs = new t_obs();
+            memcpy(&(obs->_o), _buffer.data(), sizeof(t_obsInternal));
+            _obsList.push_back(obs);
+          }
+        }
+      }
     }
 
-    if      (_mode == MODE_SEARCH) {
-      if (_buffer[0] == 0x02) {
-        _mode = MODE_TYPE;
+    // Ephemeris
+    // ---------
+    else if (char(_buffer[1]) == 0x01) {
+      if (_buffer.length() >= int(2+sizeof(recordSize)+ sizeof(gpsephemeris))){
+        gpsephemeris* gpsEph = new gpsephemeris;
+        memcpy(gpsEph, _buffer.data(), sizeof(gpsephemeris));
+        emit newGPSEph(gpsEph);
       }
-      else {
-        _mode = MODE_SEARCH;
-      }
-      _buffer.erase(0,1);
-    }
-
-    else if (_mode == MODE_TYPE) {
-      if        (_buffer[0] == 0x00) {
-        _mode = MODE_EPOCH;
-      } else if (_buffer[0] == 0x01) {
-        _mode = MODE_EPH;
-      } else {
-        _mode = MODE_SEARCH;
-      }
-      _buffer.erase(0,1);
-    }
-
-    else if (_mode == MODE_EPOCH || _mode == MODE_EPH) {
-      int recordSize;
-      if (_buffer.size() < sizeof(recordSize)) {
-        _mode = MODE_SEARCH;
-        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));
-    }
-
-    else if (_mode == MODE_EPOCH_BODY) {
-      EPOCHHEADER epochHdr;
-      if (_buffer.size() < sizeof(epochHdr)) {
-        _mode = MODE_SEARCH;
-        return success;    
-      }
-      memcpy(&epochHdr, _buffer.data(), sizeof(epochHdr));
-      _buffer.erase(0,sizeof(epochHdr));
-      if (_buffer.size() < epochHdr.n_svs * sizeof(t_obsInternal)) {
-        _mode = MODE_SEARCH;
-        return success;
-      }
-      for (int is = 1; is <= epochHdr.n_svs; is++) {
-        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;
-    }
-
-    else if (_mode == MODE_EPH_BODY) {
-      if (_buffer.size() < sizeof(gpsephemeris)) {
-        _mode = MODE_SEARCH;
-        return success;
-      }
-      gpsephemeris* gpsEph = new gpsephemeris;
-      memcpy(gpsEph, _buffer.data(), sizeof(gpsephemeris));
-      emit newGPSEph(gpsEph);
-      _buffer.erase(0, sizeof(gpsephemeris));
-      _mode = MODE_EPH_CRC;
     }
 
     else {
-      _buffer.erase(0,1);
-      _mode = MODE_SEARCH;
+      _buffer == _buffer.mid(1);
     }
   }
