diff options
author | Emily Shaffer <emilyshaffer@google.com> | 2017-04-05 08:53:21 -0700 |
---|---|---|
committer | Emily Shaffer <emilyshaffer@google.com> | 2017-06-06 10:55:40 -0700 |
commit | 1fabf229f4cc5ae3121d7fdd738f683ff5401e95 (patch) | |
tree | d2be10d9780b14cd86b8d34a23ed4b8943e5b236 | |
parent | 7117441c5fbd7a8a0adbff7a363feedb8511c4d8 (diff) | |
download | phosphor-host-ipmid-1fabf229f4cc5ae3121d7fdd738f683ff5401e95.tar.gz phosphor-host-ipmid-1fabf229f4cc5ae3121d7fdd738f683ff5401e95.zip |
sensorhandler: modify Get Sensor Reading to use dbus interface
Change-Id: Ice16bda6c151b0865f3fa6e8234b8e2456d5b887
Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
-rw-r--r-- | sensorhandler.cpp | 56 | ||||
-rw-r--r-- | sensorhandler.h | 9 |
2 files changed, 65 insertions, 0 deletions
diff --git a/sensorhandler.cpp b/sensorhandler.cpp index 1d0f4c9..eacc274 100644 --- a/sensorhandler.cpp +++ b/sensorhandler.cpp @@ -1,4 +1,5 @@ #include <mapper.h> +#include <math.h> #include <stdio.h> #include <string.h> #include <bitset> @@ -556,6 +557,9 @@ ipmi_ret_t ipmi_sen_get_sensor_reading(ipmi_netfn_t netfn, ipmi_cmd_t cmd, *data_len=0; + int64_t raw_value, scale; + ipmi::sensor::Info sensor; + switch(type) { case 0xC3: case 0xC2: @@ -584,6 +588,58 @@ ipmi_ret_t ipmi_sen_get_sensor_reading(ipmi_netfn_t netfn, ipmi_cmd_t cmd, resp->indication[1] = 0; break; + case IPMI_SENSOR_TEMP: + case IPMI_SENSOR_VOLTAGE: + case IPMI_SENSOR_CURRENT: + case IPMI_SENSOR_FAN: + // Get reading for /xyz/openbmc_project/Sensor/Value.interface + + // Get value + r = sd_bus_get_property_trivial(bus, + a.bus, + a.path, + a.interface, + "Value", + NULL, + 'x', + &raw_value); + if (r < 0) { + fprintf(stderr, + "Failed to call sd_bus_get_property:%d, %s, 'value'\n", + r, + strerror(-r)); + fprintf(stderr, "Bus: %s, Path: %s, Interface: %s\n", + a.bus, a.path, a.interface); + break; + } + + // Get scale + r = sd_bus_get_property_trivial(bus, + a.bus, + a.path, + a.interface, + "Scale", + NULL, + 'x', + &scale); + if (r < 0) { + fprintf(stderr, + "Failed to call sd_bus_get_property:%d, %s (scale)\n", + r, + strerror(-r)); + fprintf(stderr, "Bus: %s, Path: %s, Interface: %s\n", + a.bus, a.path, a.interface); + break; + } + + resp->value = raw_value * pow(10,scale); + resp->operation = 0; + resp->indication[0] = 0; + resp->indication[1] = 0; + rc = IPMI_CC_OK; + *data_len=sizeof(sensorreadingresp_t); + break; + default: *data_len=0; rc = IPMI_CC_SENSOR_INVALID; diff --git a/sensorhandler.h b/sensorhandler.h index d58f640..cedb2e4 100644 --- a/sensorhandler.h +++ b/sensorhandler.h @@ -11,6 +11,15 @@ enum ipmi_netfn_sen_cmds IPMI_CMD_SET_SENSOR = 0x30, }; +// Discrete sensor types. +enum ipmi_sensor_types +{ + IPMI_SENSOR_TEMP = 0x01, + IPMI_SENSOR_VOLTAGE = 0x02, + IPMI_SENSOR_CURRENT = 0x03, + IPMI_SENSOR_FAN = 0x04, +}; + #define MAX_DBUS_PATH 128 struct dbus_interface_t { uint8_t sensornumber; |