Refactor checking thresholds

Made the following fixes to the code that checks sensor thresholds:

1) Check warning thresholds before critical ones.
    There may be external actions taken on the warning alarm even if the
    critical alarm is also passed, so always check the warning alarm and
    check it first so that a sensor jump from nominal to over critical
    still hits the warning alarm first, just as it would if it had taken
    smaller steps.

2) Change the threshold checks to >= and <=.
    This matches how the threshold checking is done in dbus-sensors and
    phosphor-hwmon.

3) Change the log level from ERR to INFO on the low threshold deasserts.
    This matches how it was done when deasserting the high threshold
    alarms.

Change-Id: I28781891e0cf06195a22303fa2f93fdc39404e3c
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/virtualSensor.cpp b/virtualSensor.cpp
index 25c127c..5c1a6b9 100644
--- a/virtualSensor.cpp
+++ b/virtualSensor.cpp
@@ -201,27 +201,7 @@
     auto warningHigh = WarningInterface::warningHigh();
     auto warningLow = WarningInterface::warningLow();
 
-    if (value > criticalHigh)
-    {
-        if (!CriticalInterface::criticalAlarmHigh())
-        {
-            CriticalInterface::criticalAlarmHigh(true);
-            log<level::ERR>("ASSERT: Virtual Sensor has exceeded "
-                            "critical high threshold",
-                            entry("NAME = %s", name.c_str()));
-        }
-        return;
-    }
-
-    if (CriticalInterface::criticalAlarmHigh())
-    {
-        CriticalInterface::criticalAlarmHigh(false);
-        log<level::INFO>("DEASSERT: Virtual Sensor is under "
-                         "critical high threshold",
-                         entry("NAME = %s", name.c_str()));
-    }
-
-    if (value > warningHigh)
+    if (value >= warningHigh)
     {
         if (!WarningInterface::warningAlarmHigh())
         {
@@ -230,10 +210,8 @@
                             "warning high threshold",
                             entry("NAME = %s", name.c_str()));
         }
-        return;
     }
-
-    if (WarningInterface::warningAlarmHigh())
+    else if (WarningInterface::warningAlarmHigh())
     {
         WarningInterface::warningAlarmHigh(false);
         log<level::INFO>("DEASSERT: Virtual Sensor is under "
@@ -241,27 +219,25 @@
                          entry("NAME = %s", name.c_str()));
     }
 
-    if (value < criticalLow)
+    if (value >= criticalHigh)
     {
-        if (!CriticalInterface::criticalAlarmLow())
+        if (!CriticalInterface::criticalAlarmHigh())
         {
-            CriticalInterface::criticalAlarmLow(true);
-            log<level::ERR>("ASSERT: Virtual Sensor is under "
-                            "critical low threshold",
+            CriticalInterface::criticalAlarmHigh(true);
+            log<level::ERR>("ASSERT: Virtual Sensor has exceeded "
+                            "critical high threshold",
                             entry("NAME = %s", name.c_str()));
         }
-        return;
     }
-
-    if (CriticalInterface::criticalAlarmLow())
+    else if (CriticalInterface::criticalAlarmHigh())
     {
-        CriticalInterface::criticalAlarmLow(false);
-        log<level::ERR>("DEASSERT: Virtual Sensor is above "
-                        "critical low threshold",
-                        entry("NAME = %s", name.c_str()));
+        CriticalInterface::criticalAlarmHigh(false);
+        log<level::INFO>("DEASSERT: Virtual Sensor is under "
+                         "critical high threshold",
+                         entry("NAME = %s", name.c_str()));
     }
 
-    if (value < warningLow)
+    if (value <= warningLow)
     {
         if (!WarningInterface::warningAlarmLow())
         {
@@ -270,15 +246,31 @@
                             "warning low threshold",
                             entry("NAME = %s", name.c_str()));
         }
-        return;
     }
-
-    if (WarningInterface::warningAlarmLow())
+    else if (WarningInterface::warningAlarmLow())
     {
         WarningInterface::warningAlarmLow(false);
-        log<level::ERR>("DEASSERT: Virtual Sensor is above "
-                        "warning low threshold",
-                        entry("NAME = %s", name.c_str()));
+        log<level::INFO>("DEASSERT: Virtual Sensor is above "
+                         "warning low threshold",
+                         entry("NAME = %s", name.c_str()));
+    }
+
+    if (value <= criticalLow)
+    {
+        if (!CriticalInterface::criticalAlarmLow())
+        {
+            CriticalInterface::criticalAlarmLow(true);
+            log<level::ERR>("ASSERT: Virtual Sensor is under "
+                            "critical low threshold",
+                            entry("NAME = %s", name.c_str()));
+        }
+    }
+    else if (CriticalInterface::criticalAlarmLow())
+    {
+        CriticalInterface::criticalAlarmLow(false);
+        log<level::INFO>("DEASSERT: Virtual Sensor is above "
+                         "critical low threshold",
+                         entry("NAME = %s", name.c_str()));
     }
 }