Index: trunk/BNC/src/RTCM3/RTCM3Decoder.cpp
===================================================================
--- trunk/BNC/src/RTCM3/RTCM3Decoder.cpp	(revision 10540)
+++ trunk/BNC/src/RTCM3/RTCM3Decoder.cpp	(revision 10544)
@@ -1042,6 +1042,25 @@
 
     GETBITS(i, 6)
+    if (i < 1 || i > 63 ) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (G) PRN# is out of range: %3!")
+           .arg(_staID)
+           .arg(1019,4)
+           .arg(i).toLatin1(), true));
+#endif
+      return false;
+    }
     eph._prn.set('G', i);
     GETBITS(week, 10)
+    if (week < 0 || week > 1023) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (%3) WEEK # is out of range: %4!")
+           .arg(_staID)
+           .arg(1019,4)
+           .arg(eph._prn.toString().c_str())
+           .arg(week).toLatin1(), true));
+#endif
+      return false;
+    }
     GETBITS(i, 4)
     eph._ura = accuracyFromIndex(i, eph.type());
@@ -1051,4 +1070,14 @@
     GETBITS(i, 16)
     i <<= 4;
+    if (i < 0 || i > 604784) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (%3) TOC is out of range: %4!")
+           .arg(_staID)
+           .arg(1019,4)
+           .arg(eph._prn.toString().c_str())
+           .arg(i).toLatin1(), true));
+#endif
+      return false;
+    }
     eph._TOC.set(i * 1000);
     GETFLOATSIGN(eph._clock_driftrate, 8, 1.0 / (double )(1 << 30) / (double )(1 << 25))
@@ -1073,4 +1102,14 @@
     GETBITS(i, 16)
     i <<= 4;
+    if (i < 0 || i > 604784) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (%3) TOE is out of range: %4!")
+           .arg(_staID)
+           .arg(1019,4)
+           .arg(eph._prn.toString().c_str())
+           .arg(i).toLatin1(), true));
+#endif
+      return false;
+    }
     eph._TOEsec = i;
     bncTime t;
@@ -1123,26 +1162,65 @@
 
     GETBITS(sv, 6)
+    if (sv < 1 || sv > 63) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (R):  SLOT# is unknown (0) or out of range: %3!")
+           .arg(_staID)
+           .arg(1020,4)
+           .arg(sv).toLatin1(), true));
+#endif
+      return false;
+    }
     eph._prn.set('R', sv);
 
     GETBITS(i, 5)
+    if (i < 0 || i > 20) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (%3): FRQ CHN# is out of range: %4")
+           .arg(_staID)
+           .arg(1020,4)
+           .arg(eph._prn.toString().c_str())
+           .arg(i).toLatin1(), true));
+#endif
+      return false;
+    }
     eph._frequency_number = i - 7;
     GETBITS(eph._almanac_health, 1) /* almanac healthy */
     GETBITS(eph._almanac_health_availablility_indicator, 1) /* almanac health ok */
-/*
-    if (eph._almanac_health_availablility_indicator == 0.0) {
-#ifdef BNC_DEBUG_BCEP
-      emit(newMessage(QString("%1: Block %2 (%3): ALM = %4: missing data!")
-           .arg(_staID).arg(1020,4).arg(eph._prn.toString().c_str())
-           .arg(eph._almanac_health_availablility_indicator).toLatin1(), true));
-#endif
-      return false;
-    }
-*/
     GETBITS(eph._P1, 2) /*  P1 */
     GETBITS(i, 5)
+    if (i < 0 || i > 23) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (%3): T_k (bits 11-7) is out of range: %4")
+           .arg(_staID)
+           .arg(1020,4)
+           .arg(eph._prn.toString().c_str())
+           .arg(i).toLatin1(), true));
+#endif
+      return false;
+    }
     tk = i * 60 * 60;
     GETBITS(i, 6)
+    if (i < 0 || i > 59) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (%3): T_k (bits 6-1) is out of range: %4")
+           .arg(_staID)
+           .arg(1020,4)
+           .arg(eph._prn.toString().c_str())
+           .arg(i).toLatin1(), true));
+#endif
+      return false;
+    }
     tk += i * 60;
     GETBITS(i, 1)
+    if (i < 0 || i > 1) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (%3): T_k (bit 0) is out of range: %4")
+           .arg(_staID)
+           .arg(1020,4)
+           .arg(eph._prn.toString().c_str())
+           .arg(i).toLatin1(), true));
+#endif
+      return false;
+    }
     tk += i * 30;
     eph._tki = tk - 3*60*60;
@@ -1153,5 +1231,16 @@
     GETBITS(eph._P2, 1)  /* P2 */
     GETBITS(i, 7)
-    eph._TOC.setTk(i * 15 * 60 * 1000); /* tb */
+    i *= 15;
+    if (i < 15 || i > 1425) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (%3): T_b is out of range: %4")
+           .arg(_staID)
+           .arg(1020,4)
+           .arg(eph._prn.toString().c_str())
+           .arg(i).toLatin1(), true));
+#endif
+      return false;
+    }
+    eph._TOC.setTk(i * 60 * 1000); /* tb */
 
     GETFLOATSIGNM(eph._x_velocity,    24, 1.0 / (double )(1 << 20))
@@ -1252,8 +1341,27 @@
 
     GETBITS(i, 4)
+    if (i < 1 || i > 10 ) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (J) SAT ID is out of range: %3!")
+           .arg(_staID)
+           .arg(1044,4)
+           .arg(i).toLatin1(), true));
+#endif
+      return false;
+    }
     eph._prn.set('J', i);
 
     GETBITS(i, 16)
     i <<= 4;
+    if (i < 0 || i > 604784) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (%3) TOC is out of range: %4!")
+           .arg(_staID)
+           .arg(1044,4)
+           .arg(eph._prn.toString().c_str())
+           .arg(i).toLatin1(), true));
+#endif
+      return false;
+    }
     eph._TOC.set(i * 1000);
 
@@ -1279,4 +1387,14 @@
     GETBITS(i, 16)
     i <<= 4;
+    if (i < 0 || i > 604784) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (%3) TOE is out of range: %4!")
+           .arg(_staID)
+           .arg(1044,4)
+           .arg(eph._prn.toString().c_str())
+           .arg(i).toLatin1(), true));
+#endif
+      return false;
+    }
     eph._TOEsec = i;
     bncTime t;
@@ -1293,4 +1411,14 @@
     GETBITS(eph._L2Codes, 2)
     GETBITS(week, 10)
+    if (week < 0 || week > 1023) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (%3) WEEK # is out of range: %4!")
+           .arg(_staID)
+           .arg(1044,4)
+           .arg(eph._prn.toString().c_str())
+           .arg(week).toLatin1(), true));
+#endif
+      return false;
+    }
     int numOfRollOvers = int(floor(t.gpsw()/1024.0));
     week += (numOfRollOvers * 1024);
@@ -1336,6 +1464,25 @@
 
     GETBITS(i, 6)
+    if (i < 1 || i > 63 ) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (I) PRN# is out of range: %3!")
+           .arg(_staID)
+           .arg(1041,4)
+           .arg(i).toLatin1(), true));
+#endif
+      return false;
+    }
     eph._prn.set('I', i);
     GETBITS(week, 10)
+    if (week < 0 || week > 1023) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (%3) WEEK # is out of range: %4!")
+           .arg(_staID)
+           .arg(1041,4)
+           .arg(eph._prn.toString().c_str())
+           .arg(week).toLatin1(), true));
+#endif
+      return false;
+    }
     GETFLOATSIGN(eph._clock_bias,     22, 1.0 / (double )(1 << 30) / (double )(1 << 1))
     GETFLOATSIGN(eph._clock_drift,    16, 1.0 / (double )(1 << 30) / (double )(1 << 13))
@@ -1345,4 +1492,14 @@
     GETBITS(i, 16)
     i <<= 4;
+    if (i < 0 || i > 1048560) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (%3) TOC is out of range: %4!")
+           .arg(_staID)
+           .arg(1041,4)
+           .arg(eph._prn.toString().c_str())
+           .arg(i).toLatin1(), true));
+#endif
+      return false;
+    }
     eph._TOC.set(i * 1000);
     GETFLOATSIGN(eph._TGD, 8, 1.0 / (double )(1 << 30) / (double )(1 <<  1))
@@ -1377,4 +1534,14 @@
     GETBITS(i, 16)
     i <<= 4;
+    if (i < 0 || i > 1048560) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (%3) TOE is out of range: %4!")
+           .arg(_staID)
+           .arg(1041,4)
+           .arg(eph._prn.toString().c_str())
+           .arg(i).toLatin1(), true));
+#endif
+      return false;
+    }
     eph._TOEsec = i;
     bncTime t;
@@ -1428,8 +1595,27 @@
 
     GETBITS(i, 6)
-    eph._prn.set('S', 20 + i);
+    if (i < 40 || i > 58 ) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (S) PRN# is out of range: %3!")
+           .arg(_staID)
+           .arg(1043,4)
+           .arg(i).toLatin1(), true));
+#endif
+      return false;
+    }
+    eph._prn.set('S', 80 + i);
     GETBITS(eph._IODN, 8)
     GETBITS(i, 13)
     i <<= 4;
+    if (i < 0 || i > 86384) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (%3) TOC is out of range: %4!")
+           .arg(_staID)
+           .arg(1043,4)
+           .arg(eph._prn.toString().c_str())
+           .arg(i).toLatin1(), true));
+#endif
+      return false;
+    }
     eph._TOC.setTOD(i * 1000);
     GETBITS(i, 4)
@@ -1471,5 +1657,5 @@
   bool decoded = false;
   uint64_t numbits = 0, bitfield = 0;
-  int i;
+  int i, week, mnum;
 
   data += 3; /* header */
@@ -1479,5 +1665,4 @@
   if ((i == 1046 && size == 61) || (i == 1045 && size == 60)) {
     t_ephGal eph;
-
     eph._receptDateTime = currentDateAndTimeGPS();
     eph._receptStaID = _staID;
@@ -1485,8 +1670,29 @@
     eph._inav = (i == 1046);
     eph._fnav = (i == 1045);
+    mnum = i;
     GETBITS(i, 6)
+    if (i < 1 || i > 36 ) { // max. constellation within I/NAV / F/NAV frames is 36
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (E) PRN# is out of range: %3!")
+           .arg(_staID)
+           .arg(mnum,4)
+           .arg(i).toLatin1(), true));
+#endif
+      return false;
+    }
     eph._prn.set('E', i, eph._inav ? 1 : 0);
 
-    GETBITS(eph._TOEweek, 12) //FIXME: roll-over after week 4095!!
+    GETBITS(week, 12) //FIXME: roll-over after week 4095!!
+    if (week < 0 || week > 4095) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (%3) WEEK # is out of range: %4!")
+           .arg(_staID)
+           .arg(mnum,4)
+           .arg(eph._prn.toString().c_str())
+           .arg(week).toLatin1(), true));
+#endif
+      return false;
+    }
+    eph._TOEweek = week;
     GETBITS(eph._IODnav, 10)
     GETBITS(i, 8)
@@ -1494,5 +1700,15 @@
     GETFLOATSIGN(eph._IDOT, 14, R2R_PI/(double)(1<<30)/(double)(1<<13))
     GETBITSFACTOR(i, 14, 60)
-    eph._TOC.set(1024 + eph._TOEweek, i);
+    if (i < 0 || i > 604740) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (%3) TOC is out of range: %4!")
+           .arg(_staID)
+           .arg(mnum,4)
+           .arg(eph._prn.toString().c_str())
+           .arg(i).toLatin1(), true));
+#endif
+      return false;
+    }
+    eph._TOC.set(1024 + eph._TOEweek, i);// Period #2 = + 1 x 1024 (has to be determined)
     GETFLOATSIGN(eph._clock_driftrate, 6, 1.0 / (double )(1 << 30) / (double )(1 << 29))
     GETFLOATSIGN(eph._clock_drift,    21, 1.0 / (double )(1 << 30) / (double )(1 << 16))
@@ -1506,4 +1722,14 @@
     GETFLOAT(eph._sqrt_A,             32, 1.0 / (double )(1 << 19))
     GETBITSFACTOR(eph._TOEsec, 14, 60)
+    if (i < 0 || i > 604740) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (%3) TOE is out of range: %4!")
+           .arg(_staID)
+           .arg(mnum,4)
+           .arg(eph._prn.toString().c_str())
+           .arg(i).toLatin1(), true));
+#endif
+      return false;
+    }
     /* FIXME: overwrite value, copied from old code */
     eph._TOEsec = eph._TOC.gpssec();
@@ -1582,5 +1808,5 @@
   if (size == 70) {
     t_ephBDS eph;
-    int i;
+    int i, week;
     uint64_t numbits = 0, bitfield = 0;
 
@@ -1593,7 +1819,27 @@
 
     GETBITS(i, 6)
+    if (i < 1 || i > 63 ) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (C) PRN# is out of range: %3!")
+           .arg(_staID)
+           .arg(1042,4)
+           .arg(i).toLatin1(), true));
+#endif
+      return false;
+    }
     eph._prn.set('C', i);
 
-    GETBITS(eph._BDTweek, 13)
+    GETBITS(week, 13)
+    if (week < 0 || week > 8191) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (%3) WEEK # is out of range: %4!")
+           .arg(_staID)
+           .arg(1042,4)
+           .arg(eph._prn.toString().c_str())
+           .arg(week).toLatin1(), true));
+#endif
+      return false;
+    }
+    eph._BDTweek = week;
     GETBITS(i, 4)
     eph._URA = accuracyFromIndex(i, eph.type());
@@ -1602,4 +1848,14 @@
     GETBITS(i, 17)
     i <<= 3;
+    if (i < 0 || i > 604792) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (%3) TOC is out of range: %4!")
+           .arg(_staID)
+           .arg(1042,4)
+           .arg(eph._prn.toString().c_str())
+           .arg(i).toLatin1(), true));
+#endif
+      return false;
+    }
     eph._TOC.setBDS(eph._BDTweek, i);
     GETFLOATSIGN(eph._clock_driftrate, 11,  1.0 / (double )(1 << 30) / (double )(1 << 30) / (double )(1 << 6))
@@ -1624,4 +1880,14 @@
     GETBITS(i, 17)
     i <<= 3;
+    if (i < 0 || i > 604792) {
+#ifdef BNC_DEBUG_BCEP
+      emit(newMessage(QString("%1: Block %2 (%3) TOE is out of range: %4!")
+           .arg(_staID)
+           .arg(1042,4)
+           .arg(eph._prn.toString().c_str())
+           .arg(i).toLatin1(), true));
+#endif
+      return false;
+    }
     eph._TOEsec = i;
     eph._TOE.setBDS(eph._BDTweek, i);
@@ -2082,2 +2348,6 @@
           _coDecoders.begin().value()->corrGPSEpochTime() : -1;
 }
+
+
+
+
Index: trunk/BNC/src/RTCM3/RTCM3Decoder.h
===================================================================
--- trunk/BNC/src/RTCM3/RTCM3Decoder.h	(revision 10540)
+++ trunk/BNC/src/RTCM3/RTCM3Decoder.h	(revision 10544)
@@ -189,4 +189,5 @@
    */
   bool DecodeRTCMCRS(unsigned char* buffer, int bufLen);
+
   /** Current station description, dynamic in case of raw input file handling */
   QString                _staID;
