summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sensordatahandler.hpp34
-rw-r--r--sensorhandler.h14
2 files changed, 48 insertions, 0 deletions
diff --git a/sensordatahandler.hpp b/sensordatahandler.hpp
index 010772d..ba496e7 100644
--- a/sensordatahandler.hpp
+++ b/sensordatahandler.hpp
@@ -1,6 +1,8 @@
#pragma once
+#include "sensorhandler.h"
#include "types.hpp"
+#include "utils.hpp"
#include "host-ipmid/ipmid-api.h"
namespace ipmi
@@ -81,6 +83,38 @@ GetSensorResponse assertion(const Info& sensorInfo);
*/
GetSensorResponse eventdata2(const Info& sensorInfo);
+/**
+ * @brief readingAssertion is a case where the entire assertion state field
+ * serves as the sensor value.
+ *
+ * @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 readingAssertion(const Info& sensorInfo)
+{
+ sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
+ GetSensorResponse response {};
+ auto responseData = reinterpret_cast<GetReadingResponse*>(response.data());
+
+ 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);
+
+ setAssertionBytes(static_cast<uint16_t>(propValue.get<T>()), responseData);
+
+ return response;
+}
+
} //namespace get
namespace set
diff --git a/sensorhandler.h b/sensorhandler.h
index a078693..6ba5c34 100644
--- a/sensorhandler.h
+++ b/sensorhandler.h
@@ -510,6 +510,20 @@ inline void setReading(uint8_t value, ipmi::sensor::GetReadingResponse* resp)
resp->reading = value;
}
+/**
+ * @brief Map the value to the assertion bytes. The assertion states are stored
+ * in 2 bytes.
+ *
+ * @param[in] value - value to mapped to the assertion byte.
+ * @param[in/out] resp - get sensor reading response.
+ */
+inline void setAssertionBytes(uint16_t value,
+ ipmi::sensor::GetReadingResponse* resp)
+{
+ resp->assertOffset0_7 = static_cast<uint8_t>(value & 0x00FF);
+ resp->assertOffset8_14 = static_cast<uint8_t>(value >> 8);
+}
+
} // namespace sensor
} // namespace ipmi
OpenPOWER on IntegriCloud