Index: trunk/BNC/GPSS/gpssDecoder.cpp
===================================================================
--- trunk/BNC/GPSS/gpssDecoder.cpp	(revision 1433)
+++ trunk/BNC/GPSS/gpssDecoder.cpp	(revision 1434)
@@ -39,4 +39,25 @@
 } EPOCHHEADER;
 
+// Cyclic Redundancy Check
+////////////////////////////////////////////////////////////////////////////
+unsigned short cal_crc(char *buf, int num) {
+  unsigned short polynomial = 0x8408;
+  unsigned short crc = 0;
+  int i;
+  while ( num-- ) {
+    crc = ( crc & 0xFF00 ) | ( *buf++^( crc & 0x00FF ) );
+    for( i=0; i<8; i++ ){
+      if( crc & 0x0001 ){
+        crc >>= 1;
+        crc ^= polynomial;
+      }
+      else{
+        crc >>= 1;
+      }
+    }
+  }
+  return (crc);
+}
+
 // Constructor
 ////////////////////////////////////////////////////////////////////////////
@@ -61,4 +82,6 @@
   _buffer += QByteArray(data, dataLen);
 
+  cout << "Decode: buffer length = " << _buffer.length() << endl;
+
   int iBeg;
   while ( (iBeg = _buffer.indexOf(0x02)) != -1) {
@@ -74,6 +97,4 @@
       int reqLength = 2 + sizeof(recordSize) + sizeof(EPOCHHEADER);
 
-      cout << "Obs: " << _buffer.length() << " " << reqLength << endl;
-
       if (_buffer.length() >= reqLength) {
         EPOCHHEADER epochHdr;
@@ -84,4 +105,12 @@
 
         if (_buffer.length() >= reqLength) {
+
+          int checkLen = 2 + sizeof(recordSize) + sizeof(EPOCHHEADER) + 
+                         epochHdr.n_svs * sizeof(t_obsInternal);
+          memcpy(&crc, _buffer.data() + checkLen, sizeof(crc));
+          int crdCal = cal_crc(_buffer.data(), checkLen);
+
+          cout << "Obs: " << crc << " " << crdCal << endl;
+
           for (int is = 0; is < epochHdr.n_svs; is++) {
             t_obs* obs = new t_obs();
@@ -102,7 +131,12 @@
         sizeof(crc) + 1;
 
-      cout << "Eph: " << _buffer.length() << " " << reqLength << endl;
+      if (_buffer.length() >= reqLength) {
 
-      if (_buffer.length() >= reqLength) {
+        int checkLen = 2 + sizeof(recordSize) + sizeof(gpsephemeris);
+        memcpy(&crc, _buffer.data() + checkLen, sizeof(crc));
+        int crdCal = cal_crc(_buffer.data(), checkLen);
+
+        cout << "Obs: " << crc << " " << crdCal << endl;
+
         gpsephemeris* gpsEph = new gpsephemeris;
         memcpy(gpsEph, _buffer.data() + 2 + sizeof(recordSize), 
