Add support for debug card critical sensors

List of critical sensors read from json file cri_sensors.json
and its name along with current values will be displayed on
debug card screen.

Tested: verified with lcd debug card screen.

Change-Id: I1c7968b1d57efa9bf5e4cf8c7396fbeecbfbfd3a
Signed-off-by: Vijay Khemka <vijaykhemka@fb.com>
diff --git a/src/storagecommands.cpp b/src/storagecommands.cpp
index d64ebf4..d38008e 100644
--- a/src/storagecommands.cpp
+++ b/src/storagecommands.cpp
@@ -810,6 +810,56 @@
     return IPMI_CC_OK;
 }
 
+static int getSensorConnectionByName(std::string &name, std::string &connection,
+                                     std::string &path)
+{
+    if (sensorTree.empty() && !getSensorSubtree(sensorTree))
+    {
+        return -1;
+    }
+
+    for (const auto &sensor : sensorTree)
+    {
+        path = sensor.first;
+        if (path.find(name) != std::string::npos)
+        {
+            connection = sensor.second.begin()->first;
+            return 0;
+        }
+    }
+    return -1;
+}
+
+int getSensorValue(std::string &name, double &val)
+{
+    std::string connection;
+    std::string path;
+    int ret = -1;
+
+    ret = getSensorConnectionByName(name, connection, path);
+    if (ret < 0)
+    {
+        return ret;
+    }
+
+    SensorMap sensorMap;
+    if (!getSensorMap(connection, path, sensorMap))
+    {
+        return ret;
+    }
+    auto sensorObject = sensorMap.find("xyz.openbmc_project.Sensor.Value");
+
+    if (sensorObject == sensorMap.end() ||
+        sensorObject->second.find("Value") == sensorObject->second.end())
+    {
+        return ret;
+    }
+    auto &valueVariant = sensorObject->second["Value"];
+    val = std::visit(VariantToDoubleVisitor(), valueVariant);
+
+    return 0;
+}
+
 void registerStorageFunctions()
 {
     // <READ FRU Data>