Add tach sensor functional delay

Add ability to define a delay to marking a tach sensor as functional
when it transitions from a nonfunctional state. Essentially this gives
the option to wait a given amount of time that a tach sensor must be
within the allowed deviation before being updated to functional.

Default functional delay = 0 seconds

Tested: Current fan definition values function the same

Change-Id: I58bf70d2335e27c06037b755cbee8dae81528a5a
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/monitor/example/monitor.yaml b/monitor/example/monitor.yaml
index 4819d12..7676fde 100644
--- a/monitor/example/monitor.yaml
+++ b/monitor/example/monitor.yaml
@@ -7,6 +7,9 @@
 #fans:
 # - inventory:
 #    [The system inventory location for the fan]
+#  functional_delay:
+#    [Delay (in secs) before a fan is marked functional after returning
+#     within the allowed deviation]
 #  allowed_out_of_range_time:
 #    [Time (in secs) actual speed can be outside of deviation of
 #     target speed]
@@ -53,6 +56,7 @@
 #Example entries for 1 fan system:
 #fans:
 #  - inventory: /system/chassis/motherboard/fan0
+#    functional_delay: 5
 #    allowed_out_of_range_time: 15
 #    deviation: 15
 #    num_sensors_nonfunc_for_fan_nonfunc: 1
diff --git a/monitor/fan.cpp b/monitor/fan.cpp
index 256d0cb..228ecd3 100644
--- a/monitor/fan.cpp
+++ b/monitor/fan.cpp
@@ -53,6 +53,7 @@
                             *this,
                             std::get<sensorNameField>(s),
                             std::get<hasTargetField>(s),
+                            std::get<funcDelay>(def),
                             std::get<targetInterfaceField>(s),
                             std::get<factorField>(s),
                             std::get<offsetField>(s),
diff --git a/monitor/gen-fan-monitor-defs.py b/monitor/gen-fan-monitor-defs.py
index 7a1b874..83dcbc0 100755
--- a/monitor/gen-fan-monitor-defs.py
+++ b/monitor/gen-fan-monitor-defs.py
@@ -28,6 +28,7 @@
 {
 %for fan_data in data.get('fans', {}):
     FanDefinition{"${fan_data['inventory']}",
+                  ${fan_data.get('functional_delay', 0)},
                   ${fan_data['allowed_out_of_range_time']},
                   ${fan_data['deviation']},
                   ${fan_data['num_sensors_nonfunc_for_fan_nonfunc']},
diff --git a/monitor/tach_sensor.cpp b/monitor/tach_sensor.cpp
index d725729..03c34e2 100644
--- a/monitor/tach_sensor.cpp
+++ b/monitor/tach_sensor.cpp
@@ -68,6 +68,7 @@
                        Fan& fan,
                        const std::string& id,
                        bool hasTarget,
+                       size_t funcDelay,
                        const std::string& interface,
                        size_t factor,
                        size_t offset,
@@ -78,6 +79,7 @@
     _name(FAN_SENSOR_PATH + id),
     _invName(path(fan.getName()) / id),
     _hasTarget(hasTarget),
+    _funcDelay(funcDelay),
     _interface(interface),
     _factor(factor),
     _offset(offset),
diff --git a/monitor/tach_sensor.hpp b/monitor/tach_sensor.hpp
index 2cd0f4a..ed8caf8 100644
--- a/monitor/tach_sensor.hpp
+++ b/monitor/tach_sensor.hpp
@@ -62,6 +62,7 @@
          * @param[in] id - the id of the sensor
          * @param[in] hasTarget - if the sensor supports
          *                        setting the speed
+         * @param[in] funcDelay - Delay to mark functional
          * @param[in] interface - the interface of the target
          * @param[in] factor - the factor of the sensor target
          * @param[in] offset - the offset of the sensor target
@@ -73,6 +74,7 @@
                    Fan& fan,
                    const std::string& id,
                    bool hasTarget,
+                   size_t funcDelay,
                    const std::string& interface,
                    size_t factor,
                    size_t offset,
@@ -247,6 +249,11 @@
         const bool _hasTarget;
 
         /**
+         * @brief Amount of time to delay updating to functional
+         */
+        const size_t _funcDelay;
+
+        /**
          * @brief The interface that the target implements
          */
         const std::string _interface;
diff --git a/monitor/types.hpp b/monitor/types.hpp
index b4baa9c..3d8306d 100644
--- a/monitor/types.hpp
+++ b/monitor/types.hpp
@@ -29,15 +29,17 @@
                                     size_t>;
 
 constexpr auto fanNameField = 0;
-constexpr auto timeoutField = 1;
-constexpr auto fanDeviationField = 2;
-constexpr auto numSensorFailsForNonfuncField = 3;
-constexpr auto sensorListField = 4;
+constexpr auto funcDelay = 1;
+constexpr auto timeoutField = 2;
+constexpr auto fanDeviationField = 3;
+constexpr auto numSensorFailsForNonfuncField = 4;
+constexpr auto sensorListField = 5;
 
 using FanDefinition = std::tuple<std::string,
                                  size_t,
                                  size_t,
                                  size_t,
+                                 size_t,
                                  std::vector<SensorDefinition>>;
 
 }