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;
diff --git a/power-supply/power_supply.hpp b/power-supply/power_supply.hpp
index 2723bfe..b1ac71a 100644
--- a/power-supply/power_supply.hpp
+++ b/power-supply/power_supply.hpp
@@ -153,6 +153,14 @@
         /** @brief Used to subscribe to D-Bus power on state changes */
         std::unique_ptr<sdbusplus::bus::match_t> powerOnMatch;
 
+        /** @brief Indicates that a read failure has occurred.
+         *
+         * @details This will be incremented each time a read failure is
+         *          encountered. If it is incremented to FAULT_COUNT, an error
+         *          will be logged.
+         */
+        size_t readFail = 0;
+
         /** @brief Has a PMBus read failure already been logged? */
         bool readFailLogged = false;