Index: /branches/BNC_2.12/src/bncephuser.cpp
===================================================================
--- /branches/BNC_2.12/src/bncephuser.cpp	(revision 9270)
+++ /branches/BNC_2.12/src/bncephuser.cpp	(revision 9271)
@@ -153,10 +153,12 @@
   if (ephOld &&
       (ephOld->checkState() == t_eph::bad ||
-       ephOld->checkState() == t_eph::outdated)) {
+       ephOld->checkState() == t_eph::outdated ||
+       ephOld->checkState() == t_eph::unhealthy)) {
     ephOld = 0;
   }
 
   if (ephOld == 0 || newEph->isNewerThan(ephOld)) {
-    checkEphemeris(eph, realTime);
+    checkEphemeris(newEph, realTime);
+    eph->setCheckState(newEph->checkState());
   }
   else {
@@ -165,8 +167,10 @@
   }
 
-  if (eph->checkState() != t_eph::bad &&
-      eph->checkState() != t_eph::outdated) {
+  if (newEph->checkState() != t_eph::bad &&
+      newEph->checkState() != t_eph::outdated) {
     deque<t_eph*>& qq = _eph[prn];
-    qq.push_back(newEph);
+    if (qq.empty() || newEph->isNewerThan(qq.back())){
+      qq.push_back(newEph);
+    }
     if (qq.size() > _maxQueueSize) {
       delete qq.front();
@@ -261,6 +265,6 @@
   // Check consistency with older ephemeris
   // --------------------------------------
-  const double MAXDIFF = 1000.0;
-  const double MINDIFF =    1.0;
+  const double MAXDIFF = 10.0;
+  const double MINDIFF = 0.005;
   QString      prn     = QString(eph->prn().toInternalString().c_str());
   t_eph*       ephL    = ephLast(prn);
@@ -277,51 +281,12 @@
     double diffC = fabs(xc(4) - xcL(4)) * t_CST::c;
 
-    // some lines to allow update of ephemeris data sets after an outage
-    // update interval: 2h,
-    if      (eph->type() == t_eph::GPS     && dt >  2*3600.0) {
-      ephL->setCheckState(t_eph::outdated);
-      return;
-    }
-    // update interval: 3h,
-    else if (eph->type() == t_eph::Galileo && dt >  3*3600.0) {
-      ephL->setCheckState(t_eph::outdated);
-      return;
-    }
-    // updated every 30 minutes
-    else if (eph->type() == t_eph::GLONASS && dt >    1800.0) {
-      ephL->setCheckState(t_eph::outdated);
-      return;
-    }
-    // updated every ?
-    else if (eph->type() == t_eph::QZSS    && dt >  2*3600.0) {
-      ephL->setCheckState(t_eph::outdated);
-      return;
-    }
-    // maximum update interval: 300 sec
-    else if  (eph->type() == t_eph::SBAS   && dt >     300.0) {
-      ephL->setCheckState(t_eph::outdated);
-      return;
-    }
-    // updates 1h (GEO) up to 6 hours non-GEO
-    else if  (eph->type() == t_eph::BDS    && dt >  6*3600.0) {
-      ephL->setCheckState(t_eph::outdated);
-      return;
-    }
-    // update interval: up to 24 hours
-    else if  (eph->type() == t_eph::IRNSS  && dt > 24*3600.0) {
-      ephL->setCheckState(t_eph::outdated);
-      return;
-    }
-
-    if (diff < MAXDIFF || diffC < MAXDIFF) {
-      if (dt != 0.0) {
-        if (diff < MINDIFF && diffC < MINDIFF && ephL->checkState() == t_eph::ok) {
-          // to prevent the same data sets with different TOC values
-          eph->setCheckState(t_eph::bad);
-        }
-        else {
-          eph->setCheckState(t_eph::ok);
-          ephL->setCheckState(t_eph::ok);
-        }
+    if (diff < MAXDIFF && diffC < MAXDIFF) {
+      if (diff < MINDIFF && diffC < MINDIFF && ephL->checkState() == t_eph::ok) {
+        // to prevent the same data sets with different TOC values
+        eph->setCheckState(t_eph::bad);
+      }
+      else {
+        eph->setCheckState(t_eph::ok);
+        ephL->setCheckState(t_eph::ok);
       }
     }
@@ -331,4 +296,40 @@
       }
     }
-  }
-}
+    // some lines to allow update of ephemeris data sets after an outage
+    // update interval: 2h,
+    if      (eph->type() == t_eph::GPS     && dt > (2*3600.0 + 60.0)) {
+      ephL->setCheckState(t_eph::outdated);
+      return;
+    }
+    // update interval: 3h,
+    else if (eph->type() == t_eph::Galileo && dt > (3*3600.0 + 60.0)) {
+      ephL->setCheckState(t_eph::outdated);
+      return;
+    }
+    // updated every 30 minutes
+    else if (eph->type() == t_eph::GLONASS && dt > (1800.0 + 60.0)) {
+      ephL->setCheckState(t_eph::outdated);
+      return;
+    }
+    // updated every ?
+    else if (eph->type() == t_eph::QZSS    && dt > (2*3600.0 + 60.0)) {
+      ephL->setCheckState(t_eph::outdated);
+      return;
+    }
+    // maximum update interval: 300 sec
+    else if  (eph->type() == t_eph::SBAS   && dt > (   300.0)) {
+      ephL->setCheckState(t_eph::outdated);
+      return;
+    }
+    // updates 1h (GEO) up to 6 hours non-GEO
+    else if  (eph->type() == t_eph::BDS    && dt >  6*3600.0) {
+      ephL->setCheckState(t_eph::outdated);
+      return;
+    }
+    // update interval: up to 24 hours
+    else if  (eph->type() == t_eph::IRNSS  && dt > 24*3600.0) {
+      ephL->setCheckState(t_eph::outdated);
+      return;
+    }
+  }
+}
