From 13b87a3ee204a79d5c31dfc0c3540fb207006833 Mon Sep 17 00:00:00 2001 From: Tom Joseph Date: Fri, 16 Feb 2018 09:37:43 +0530 Subject: sensor: Refactor get sensor reading command Use the functor in the generated yaml to get the sensor reading for analog sensors. Change-Id: I2535cd5015096c3e1e2baa5f9a865fc6b27e6875 Signed-off-by: Tom Joseph --- sensordatahandler.hpp | 11 ++++++---- sensorhandler.cpp | 61 +++++---------------------------------------------- 2 files changed, 12 insertions(+), 60 deletions(-) diff --git a/sensordatahandler.hpp b/sensordatahandler.hpp index 01b8e4f..a3253b9 100644 --- a/sensordatahandler.hpp +++ b/sensordatahandler.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include "sensorhandler.h" #include "types.hpp" #include "utils.hpp" @@ -197,11 +198,13 @@ GetSensorResponse readingData(const Info& sensorInfo) sensorInfo.propertyInterfaces.begin()->first, sensorInfo.propertyInterfaces.begin()->second.begin()->first); - auto value = static_cast( - (propValue.get() - sensorInfo.scaledOffset) / - (sensorInfo.coefficientM ? sensorInfo.coefficientM : 1)); + double value = propValue.get() * pow(10, + sensorInfo.scale - sensorInfo.exponentR); - setReading(value, responseData); + auto rawData = static_cast( + (value - sensorInfo.scaledOffset) / sensorInfo.coefficientM); + + setReading(rawData, responseData); return response; } diff --git a/sensorhandler.cpp b/sensorhandler.cpp index e52ab69..f9294eb 100644 --- a/sensorhandler.cpp +++ b/sensorhandler.cpp @@ -523,9 +523,6 @@ ipmi_ret_t ipmi_sen_get_sensor_reading(ipmi_netfn_t netfn, ipmi_cmd_t cmd, *data_len=0; - int64_t raw_value; - ipmi::sensor::Info sensor; - switch(type) { case 0xC2: case 0xC8: @@ -586,59 +583,6 @@ 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 - if(sensors.find(reqptr->sennum) == sensors.end()) - { - fprintf(stderr, "Failed to find config entry for Sensor 0x%02x\n", - reqptr->sennum); - return IPMI_CC_SENSOR_INVALID; - } - - sensor = sensors.at(reqptr->sennum); - if (ipmi::sensor::Mutability::Read != - (sensor.mutability & ipmi::sensor::Mutability::Read)) - { - log("Sensor was not readable.\n"); - return IPMI_CC_SENSOR_INVALID; - } - - - // 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; - } - - // Prevent div0 - if (sensor.coefficientM == 0) { - sensor.coefficientM = 1; - }; - - resp->value = static_cast( - (raw_value - sensor.scaledOffset) / sensor.coefficientM); - resp->operation = 1 << scanningEnabledBit; // scanning enabled - resp->indication[0] = 0; // not a threshold sensor. ignore - resp->indication[1] = 0; - rc = IPMI_CC_OK; - *data_len=sizeof(sensorreadingresp_t); - break; default: { const auto iter = sensors.find(reqptr->sennum); @@ -646,6 +590,11 @@ ipmi_ret_t ipmi_sen_get_sensor_reading(ipmi_netfn_t netfn, ipmi_cmd_t cmd, { return IPMI_CC_SENSOR_INVALID; } + if (ipmi::sensor::Mutability::Read != + (iter->second.mutability & ipmi::sensor::Mutability::Read)) + { + return IPMI_CC_SENSOR_INVALID; + } try { -- cgit v1.2.1