dcmi: get temperature readings: read temp sensors

This commit adds the code to read temperatures from various sensors. A
JSON config file tells what D-Bus object(s) to look up for a specific
temperature reading.

Resolves openbmc/openbmc#2626

Change-Id: Ic357ec2a53ff250a2517d68defe5850ef353568a
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/dcmihandler.hpp b/dcmihandler.hpp
index a7cfe8a..e23c8da 100644
--- a/dcmihandler.hpp
+++ b/dcmihandler.hpp
@@ -5,6 +5,7 @@
 #include <string>
 #include <vector>
 #include <sdbusplus/bus.hpp>
+#include "nlohmann/json.hpp"
 
 namespace dcmi
 {
@@ -50,6 +51,8 @@
     static constexpr auto maxDataSets = 8;
     static constexpr auto maxInstances = 255;
     static constexpr auto maxTemp = 128; // degrees C
+    static constexpr auto configFile =
+        "/usr/share/ipmi-providers/dcmi_temp_readings.json";
 
     /** @struct Response
      *
@@ -70,6 +73,10 @@
 
     using ResponseList = std::vector<Response>;
     using NumInstances = size_t;
+    using Value = uint8_t;
+    using Sign = bool;
+    using Temperature = std::tuple<Value, Sign>;
+    using Json = nlohmann::json;
 }
 
 static constexpr auto groupExtId = 0xDC;
@@ -375,6 +382,24 @@
 
 namespace temp_readings
 {
+    /** @brief Read temperature from a d-bus object, scale it as per dcmi
+     *         get temperature reading requirements.
+     *
+     *  @param[in] dbusService - the D-Bus service
+     *  @param[in] dbusPath - the D-Bus path
+     *
+     *  @return A temperature reading
+     */
+    Temperature readTemp(const std::string& dbusService,
+                         const std::string& dbusPath);
+
+    /** @brief Parse out JSON config file containing information
+     *         related to temperature readings.
+     *
+     *  @return A json object
+     */
+    Json parseConfig();
+
     /** @brief Read temperatures and fill up DCMI response for the Get
      *         Temperature Readings command. This looks at a specific
      *         instance.