Index: trunk/BNC/RTCM/RTCM2.cpp
===================================================================
--- trunk/BNC/RTCM/RTCM2.cpp	(revision 253)
+++ trunk/BNC/RTCM/RTCM2.cpp	(revision 254)
@@ -6,4 +6,19 @@
 //
 //   Module for extraction of RTCM2 messages
+//
+// References:
+//
+//   RTCM 10402.3 Recommended Standards for Differential GNSS (Global
+//     Navigation Satellite Systems) Service; RTCM Paper 136-2001/SC104-STD,
+//     Version 2.3, 20 Aug. 2001; Radio Technical Commission For Maritime 
+//     Services, Alexandria, Virgina (2001).
+//   ICD-GPS-200; Navstar GPS Space Segment / Navigation User Interfaces;
+//     Revison C; 25 Sept. 1997; Arinc Research Corp., El Segundo (1997).
+//   Jensen M.; RTCM2ASC Documentation;
+//     URL http://kom.aau.dk/~borre/masters/receiver/rtcm2asc.htm;
+//     last accessed 17 Sep. 2006
+//   Sager J.; Decoder for RTCM SC-104 data from a DGPS beacon receiver;
+//     URL http://www.wsrcc.com/wolfgang/ftp/rtcm-0.3.tar.gz;
+//     last accessed 17 Sep. 2006
 //
 // Notes: 
@@ -21,4 +36,5 @@
 //   2006/10/14  LMV  Exception handling
 //   2006/10/17  OMO  Removed obsolete check of multiple message indicator
+//   2006/10/17  OMO  Fixed parity handling 
 //
 // (c) DLR/GSOC
@@ -26,4 +42,5 @@
 //------------------------------------------------------------------------------
 
+#include <bitset>
 #include <cmath>
 #include <fstream>
@@ -35,4 +52,8 @@
 #include "RTCM2.h"
 
+// Activate (1) or deactivate (0) debug output for tracing parity errors and
+// undersized packets in get(Unsigned)Bits
+
+#define DEBUG 0    
 
 using namespace std;
@@ -166,5 +187,5 @@
         byteParity[(t>>16)&0xff] ^ byteParity[(t>>24)     ]   );
 
-  return ( (W!=0) && ((W &0x3f) == p));
+  return ( (W & 0x3f) == p);
 
 };
@@ -256,4 +277,10 @@
   buf.erase(0,5);
 
+#if (DEBUG>0) 
+  if (!validParity()) {
+    cout << "Parity error " 
+         << bitset<32>(all()) << endl;
+  };
+#endif
   failure = false;
 
@@ -272,4 +299,10 @@
   };
 
+#if (DEBUG>0) 
+  if (!validParity()) {
+    cout << "Parity error " 
+         << bitset<32>(all()) << endl;
+  };
+#endif
   failure = false;
 
@@ -299,4 +332,10 @@
   buf.erase(0,i);
 
+#if (DEBUG>0) 
+  if (!validParity()) {
+    cout << "Parity error " 
+         << bitset<32>(all()) << endl;
+  };
+#endif
   failure = false;
 
@@ -317,4 +356,10 @@
   };
 
+#if (DEBUG>0) 
+  if (!validParity()) {
+    cout << "Parity error " 
+         << bitset<32>(all()) << endl;
+  };
+#endif
   failure = false;
 
@@ -383,9 +428,11 @@
   W.getHeader(buf); 
   H1 = W.value(); 
-  if (W.fail()) { clear(); W=W_old; buf=buf_old; return; }
+  if (W.fail()) { clear(); W=W_old; buf=buf_old; return; };
+  if (!W.validParity()) { clear(); return; };
   
   W.get(buf);       
   H2 = W.value(); 
-  if (W.fail()) { clear(); W=W_old; buf=buf_old; return; }
+  if (W.fail()) { clear(); W=W_old; buf=buf_old; return; };
+  if (!W.validParity()) { clear(); return; };
 
   n = nDataWords();
@@ -394,5 +441,6 @@
     W.get(buf); 
     DW[i] = W.value(); 
-    if (W.fail()) { clear(); W=W_old; buf=buf_old; return; }
+    if (W.fail()) { clear(); W=W_old; buf=buf_old; return; };
+    if (!W.validParity()) { clear(); return; };
   };
 
@@ -412,9 +460,9 @@
   W.getHeader(inp); 
   H1 = W.value(); 
-  if (W.fail()) { clear(); return; }
+  if (W.fail() || !W.validParity()) { clear(); return; }
   
   W.get(inp);       
   H2 = W.value(); 
-  if (W.fail()) { clear(); return; }
+  if (W.fail() || !W.validParity()) { clear(); return; }
 
   n = nDataWords();
@@ -423,5 +471,5 @@
     W.get(inp); 
     DW[i] = W.value(); 
-    if (W.fail()) { clear(); return; }
+    if (W.fail() || !W.validParity()) { clear(); return; }
   };
 
@@ -433,5 +481,5 @@
 // Input operator
 //
-// Reads an RTCM3 packet from the input stream. 
+// Reads an RTCM2 packet from the input stream. 
 //
 
@@ -509,4 +557,15 @@
   
   if ( 24*DW.size() < start+n-1 ) {
+#if (DEBUG>0)
+    cerr << "Debug output RTCM2packet::getUnsignedBits" << endl
+         << "  P.msgType:    " << setw(5) << msgType()    << endl
+         << "  P.nDataWords: " << setw(5) << nDataWords() << endl
+         << "  start:        " << setw(5) << start        << endl
+         << "  n:            " << setw(5) << n            << endl
+         << "  P.H1:         " << setw(5) << bitset<32>(H1) << endl
+         << "  P.H2:         " << setw(5) << bitset<32>(H2) << endl
+         << endl
+         << flush;
+#endif
     throw("Error: Packet too short in RTCM2packet::getUnsignedBits");
   }
@@ -558,4 +617,15 @@
   
   if ( 24*DW.size() < start+n-1 ) {
+#if (DEBUG>0)
+    cerr << "Debug output RTCM2packet::getUnsignedBits" << endl
+         << "  P.msgType:    " << setw(5) << msgType()    << endl
+         << "  P.nDataWords: " << setw(5) << nDataWords() << endl
+         << "  start:        " << setw(5) << start        << endl
+         << "  n:            " << setw(5) << n            << endl
+         << "  P.H1:         " << setw(5) << bitset<32>(H1) << endl
+         << "  P.H2:         " << setw(5) << bitset<32>(H2) << endl
+         << endl
+         << flush;
+#endif
     throw("Error: Packet too short in RTCM2packet::getBits");
   }
Index: trunk/BNC/RTCM/RTCM2.h
===================================================================
--- trunk/BNC/RTCM/RTCM2.h	(revision 253)
+++ trunk/BNC/RTCM/RTCM2.h	(revision 254)
@@ -18,5 +18,5 @@
 //     URL http://kom.aau.dk/~borre/masters/receiver/rtcm2asc.htm;
 //     last accessed 17 Sep. 2006
-//   Sager J.;Decoder for RTCM SC-104 data from a DGPS beacon receiver;
+//   Sager J.; Decoder for RTCM SC-104 data from a DGPS beacon receiver;
 //     URL http://www.wsrcc.com/wolfgang/ftp/rtcm-0.3.tar.gz;
 //     last accessed 17 Sep. 2006
