summaryrefslogtreecommitdiffstats
path: root/sensordatahandler.hpp
diff options
context:
space:
mode:
authorEmily Shaffer <emilyshaffer@google.com>2017-06-14 13:06:26 -0700
committerPatrick Williams <patrick@stwcx.xyz>2017-09-13 21:42:57 +0000
commitcc941e150007d56b2d7f2fc0c8248e6d74dd659d (patch)
treeb1107d9a2c0dbc7eef9d3626b58c5915ee41da50 /sensordatahandler.hpp
parent16fe26d83f06719077da41b054d99d78c065091e (diff)
downloadphosphor-host-ipmid-cc941e150007d56b2d7f2fc0c8248e6d74dd659d.tar.gz
phosphor-host-ipmid-cc941e150007d56b2d7f2fc0c8248e6d74dd659d.zip
sensorhandler: support setting analog sensors
Refactor YAML format to denote mutability of sensors. Sensors which expect different formats for reads and writes should present two entries in the sensor YAML, one with the read interface and one with the write interface. Sensors which share a format for both reads and writes may present only one entry in the YAML with both readable and writable enums specified. If a sensor receives a write which has an interface of Sensor.Value, the "Set" message is sent via DBus to the path provided in the YAML. The previous codepath is maintained. Change-Id: I292f95b6fe936de759fd65ce72c842a1bfe66448 Signed-off-by: Emily Shaffer <emilyshaffer@google.com> Signed-off-by: Patrick Venture <venture@google.com>
Diffstat (limited to 'sensordatahandler.hpp')
-rw-r--r--sensordatahandler.hpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/sensordatahandler.hpp b/sensordatahandler.hpp
index 68a122d..ca82666 100644
--- a/sensordatahandler.hpp
+++ b/sensordatahandler.hpp
@@ -95,6 +95,42 @@ ipmi_ret_t readingAssertion(const SetSensorReadingReq& cmdData,
return updateToDbus(msg);
}
+/** @brief Update d-bus based on a discrete reading
+ * @param[in] cmdData - input sensor data
+ * @param[in] sensorInfo - sensor d-bus info
+ * @return an IPMI error code
+ */
+template<typename T>
+ipmi_ret_t readingData(const SetSensorReadingReq& cmdData,
+ const Info& sensorInfo)
+{
+ auto msg = makeDbusMsg(
+ "org.freedesktop.DBus.Properties",
+ sensorInfo.sensorPath,
+ "Set",
+ sensorInfo.sensorInterface);
+
+ const auto& interface = sensorInfo.propertyInterfaces.begin();
+ msg.append(interface->first);
+
+ ipmi::sensor::Multiplier m = sensorInfo.coefficientM;
+ if (0 == m)
+ {
+ m = 1; // Avoid * 0
+ }
+
+ // TODO: Refactor this into a generated function depending on the type
+ // of conversion for the value between IPMI and dbus.
+ T raw_value = (m * cmdData.reading) + sensorInfo.scaledOffset;
+
+ for (const auto& property : interface->second)
+ {
+ msg.append(property.first);
+ sdbusplus::message::variant<T> value = raw_value;
+ msg.append(value);
+ }
+ return updateToDbus(msg);
+}
/** @brief Update d-bus based on eventdata type sensor data
* @param[in] cmdData - input sensor data
OpenPOWER on IntegriCloud