summaryrefslogtreecommitdiffstats
path: root/sensordatahandler.hpp
diff options
context:
space:
mode:
authorTom Joseph <tomjoseph@in.ibm.com>2017-09-07 00:43:16 +0530
committerTom Joseph <tomjoseph@in.ibm.com>2017-09-14 18:48:14 +0530
commite05b292b8451eaa3ffb7bb28df231e0e1ed008b8 (patch)
tree8dfaf8dc017f0ea336caa10243d95da21e84040f /sensordatahandler.hpp
parent295f17e5257774f11d6c05ed6e00e28cb4039dbf (diff)
downloadphosphor-host-ipmid-e05b292b8451eaa3ffb7bb28df231e0e1ed008b8.zip
phosphor-host-ipmid-e05b292b8451eaa3ffb7bb28df231e0e1ed008b8.tar.gz
sensor: Map dbus info to sensor's reading field
Change-Id: I3e35bf78260b1fa29e992b00279f2dd166cd2fe1 Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
Diffstat (limited to 'sensordatahandler.hpp')
-rw-r--r--sensordatahandler.hpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/sensordatahandler.hpp b/sensordatahandler.hpp
index ba496e7..1b05342 100644
--- a/sensordatahandler.hpp
+++ b/sensordatahandler.hpp
@@ -115,6 +115,43 @@ GetSensorResponse readingAssertion(const Info& sensorInfo)
return response;
}
+/** @brief Map the Dbus info to the reading field in the Get sensor reading
+ * command response
+ *
+ * @tparam T - type of the dbus property related to sensor.
+ * @param[in] sensorInfo - Dbus info related to sensor.
+ *
+ * @return Response for get sensor reading command.
+ */
+template<typename T>
+GetSensorResponse readingData(const Info& sensorInfo)
+{
+ sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
+ GetSensorResponse response {};
+ auto responseData = reinterpret_cast<GetReadingResponse*>(response.data());
+
+ enableScanning(responseData);
+
+ auto service = ipmi::getService(bus,
+ sensorInfo.sensorInterface,
+ sensorInfo.sensorPath);
+
+ auto propValue = ipmi::getDbusProperty(
+ bus,
+ service,
+ sensorInfo.sensorPath,
+ sensorInfo.propertyInterfaces.begin()->first,
+ sensorInfo.propertyInterfaces.begin()->second.begin()->first);
+
+ auto value = static_cast<uint8_t>(
+ (propValue.get<T>() - sensorInfo.scaledOffset) /
+ (sensorInfo.coefficientM ? sensorInfo.coefficientM : 1));
+
+ setReading(value, responseData);
+
+ return response;
+}
+
} //namespace get
namespace set
OpenPOWER on IntegriCloud