sensor: Add function to map dbus info to assertion status

Change-Id: I30aae9abd7905ae3299856d798d41e10859fed7f
Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
diff --git a/sensorhandler.h b/sensorhandler.h
index 0b4c4e5..576c803 100644
--- a/sensorhandler.h
+++ b/sensorhandler.h
@@ -2,6 +2,7 @@
 #define __HOST_IPMI_SEN_HANDLER_H__
 
 #include <stdint.h>
+#include "types.hpp"
 
 // IPMI commands for net functions.
 enum ipmi_netfn_sen_cmds
@@ -39,25 +40,6 @@
 int find_openbmc_path(uint8_t , dbus_interface_t *);
 
 /**
- * @struct SetSensorReadingReq
- *
- * IPMI Request data for Set Sensor Reading and Event Status Command
- */
-struct SetSensorReadingReq
-{
-    uint8_t number;
-    uint8_t operation;
-    uint8_t reading;
-    uint8_t assertOffset0_7;
-    uint8_t assertOffset8_14;
-    uint8_t deassertOffset0_7;
-    uint8_t deassertOffset8_14;
-    uint8_t eventData1;
-    uint8_t eventData2;
-    uint8_t eventData3;
-} __attribute__((packed));
-
-/**
  * Get SDR Info
  */
 
@@ -489,4 +471,35 @@
 } __attribute__((packed));
 
 } // get_sdr
+
+namespace ipmi
+{
+
+namespace sensor
+{
+
+/**
+ * @brief Map offset to the corresponding bit in the assertion byte.
+ *
+ * The discrete sensors support upto 14 states. 0-7 offsets are stored in one
+ * byte and offsets 8-14 in the second byte.
+ *
+ * @param[in] offset - offset number.
+ * @param[in/out] resp - get sensor reading response.
+ */
+inline void setOffset(uint8_t offset, ipmi::sensor::GetReadingResponse* resp)
+{
+    if (offset > 7)
+    {
+        resp->assertOffset8_14 |= 1 << (offset - 8);
+    }
+    else
+    {
+        resp->assertOffset0_7 |= 1 << offset;
+    }
+}
+
+} // namespace sensor
+
+} // namespace ipmi
 #endif