Implement de-glitch for read failures

If three consecutive read failures in a row occur, one second apart,
create and log an error.

Change-Id: Iaed04c307de2419c614b7916a99dd36a6aa2c106
Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
diff --git a/power-supply/power_supply.cpp b/power-supply/power_supply.cpp
index eb93b91..38898bd 100644
--- a/power-supply/power_supply.cpp
+++ b/power-supply/power_supply.cpp
@@ -115,6 +115,7 @@
 
             // Read the 2 byte STATUS_WORD value to check for faults.
             statusWord = pmbusIntf.read(STATUS_WORD, Type::Debug);
+            readFail = 0;
 
             //TODO: openbmc/openbmc#2484 Three consecutive reads should be
             // performed.
@@ -138,7 +139,12 @@
     }
     catch (ReadFailure& e)
     {
-        if (!readFailLogged)
+        if (readFail < FAULT_COUNT)
+        {
+            readFail++;
+        }
+
+        if (!readFailLogged && readFail >= FAULT_COUNT)
         {
             commit<ReadFailure>();
             readFailLogged = true;
@@ -526,6 +532,7 @@
 
 void PowerSupply::clearFaults()
 {
+    readFail = 0;
     readFailLogged = false;
     inputFault = false;
     powerOnFault = 0;