summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Joseph <tomjoseph@in.ibm.com>2018-02-16 09:59:57 +0530
committerTom Joseph <tomjoseph@in.ibm.com>2018-03-01 05:34:21 +0000
commitdc212b235dbf0251f5da787316f629d615ede997 (patch)
treeff5fd67b8527375cd06e24c072fccc6bb162f8b6
parent13b87a3ee204a79d5c31dfc0c3540fb207006833 (diff)
downloadphosphor-host-ipmid-dc212b235dbf0251f5da787316f629d615ede997.tar.gz
phosphor-host-ipmid-dc212b235dbf0251f5da787316f629d615ede997.zip
sensor: Updates to the get device sdr command implementation
Change-Id: Ibf5989b144ebe4ec75bd8d42c1d1167d7b16ecda Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
-rw-r--r--sensorhandler.cpp140
-rw-r--r--sensorhandler.h6
2 files changed, 43 insertions, 103 deletions
diff --git a/sensorhandler.cpp b/sensorhandler.cpp
index f9294eb..2bd022b 100644
--- a/sensorhandler.cpp
+++ b/sensorhandler.cpp
@@ -797,105 +797,49 @@ ipmi_ret_t ipmi_sen_reserve_sdr(ipmi_netfn_t netfn, ipmi_cmd_t cmd,
return IPMI_CC_OK;
}
-void setUnitFieldsForObject(sd_bus *bus,
- const dbus_interface_t &iface,
- const ipmi::sensor::Info *info,
+void setUnitFieldsForObject(const ipmi::sensor::Info *info,
get_sdr::SensorDataFullRecordBody *body)
{
- if (info->propertyInterfaces.begin()->first ==
- "xyz.openbmc_project.Sensor.Value")
+ namespace server = sdbusplus::xyz::openbmc_project::Sensor::server;
+ try
{
- std::string result {};
- if (info->unit.empty())
- {
- char *raw_cstr = NULL;
- if (0 > sd_bus_get_property_string(bus, iface.bus, iface.path,
- iface.interface, "Unit", NULL,
- &raw_cstr))
- {
- log<level::WARNING>("Unit interface missing.",
- entry("BUS=%s", iface.bus),
- entry("PATH=%s", iface.path));
- }
- else
- {
- result = raw_cstr;
- }
- free(raw_cstr);
- }
- else
+ auto unit = server::Value::convertUnitFromString(info->unit);
+ // Unit strings defined in
+ // phosphor-dbus-interfaces/xyz/openbmc_project/Sensor/Value.interface.yaml
+ switch (unit)
{
- result = info->unit;
- }
-
- namespace server = sdbusplus::xyz::openbmc_project::Sensor::server;
- try {
- auto unit = server::Value::convertUnitFromString(result);
- // Unit strings defined in
- // phosphor-dbus-interfaces/xyz/openbmc_project/Sensor/Value.interface.yaml
- switch (unit)
- {
- case server::Value::Unit::DegreesC:
- body->sensor_units_2_base = get_sdr::SENSOR_UNIT_DEGREES_C;
- break;
- case server::Value::Unit::RPMS:
- body->sensor_units_2_base = get_sdr::SENSOR_UNIT_REVOLUTIONS; // revolutions
- get_sdr::body::set_rate_unit(0b100, body); // per minute
- break;
- case server::Value::Unit::Volts:
- body->sensor_units_2_base = get_sdr::SENSOR_UNIT_VOLTS;
- break;
- case server::Value::Unit::Meters:
- body->sensor_units_2_base = get_sdr::SENSOR_UNIT_METERS;
- break;
- case server::Value::Unit::Amperes:
- body->sensor_units_2_base = get_sdr::SENSOR_UNIT_AMPERES;
- break;
- case server::Value::Unit::Joules:
- body->sensor_units_2_base = get_sdr::SENSOR_UNIT_JOULES;
- break;
- default:
- // Cannot be hit.
- fprintf(stderr, "Unknown value unit type: = %s\n", result.c_str());
- }
- }
- catch (sdbusplus::exception::InvalidEnumString e)
- {
- log<level::WARNING>("Warning: no unit provided for sensor!");
+ case server::Value::Unit::DegreesC:
+ body->sensor_units_2_base = get_sdr::SENSOR_UNIT_DEGREES_C;
+ break;
+ case server::Value::Unit::RPMS:
+ body->sensor_units_2_base = get_sdr::SENSOR_UNIT_REVOLUTIONS; // revolutions
+ get_sdr::body::set_rate_unit(0b100, body); // per minute
+ break;
+ case server::Value::Unit::Volts:
+ body->sensor_units_2_base = get_sdr::SENSOR_UNIT_VOLTS;
+ break;
+ case server::Value::Unit::Meters:
+ body->sensor_units_2_base = get_sdr::SENSOR_UNIT_METERS;
+ break;
+ case server::Value::Unit::Amperes:
+ body->sensor_units_2_base = get_sdr::SENSOR_UNIT_AMPERES;
+ break;
+ case server::Value::Unit::Joules:
+ body->sensor_units_2_base = get_sdr::SENSOR_UNIT_JOULES;
+ break;
+ case server::Value::Unit::Watts:
+ body->sensor_units_2_base = get_sdr::SENSOR_UNIT_WATTS;
+ break;
+ default:
+ // Cannot be hit.
+ fprintf(stderr, "Unknown value unit type: = %s\n",
+ info->unit.c_str());
}
}
-}
-
-int64_t getScaleForObject(sd_bus *bus,
- const dbus_interface_t& iface,
- const ipmi::sensor::Info *info)
-{
- int64_t result = 0;
- if (info->propertyInterfaces.begin()->first ==
- "xyz.openbmc_project.Sensor.Value")
+ catch (sdbusplus::exception::InvalidEnumString e)
{
- if (info->hasScale)
- {
- result = info->scale;
- }
- else
- {
- if (0 > sd_bus_get_property_trivial(bus,
- iface.bus,
- iface.path,
- iface.interface,
- "Scale",
- NULL,
- 'x',
- &result)) {
- log<level::WARNING>("Scale interface missing.",
- entry("BUS=%s", iface.bus),
- entry("PATH=%s", iface.path));
- }
- }
+ log<level::WARNING>("Warning: no unit provided for sensor!");
}
-
- return result;
}
ipmi_ret_t populate_record_from_dbus(get_sdr::SensorDataFullRecordBody *body,
@@ -905,26 +849,16 @@ ipmi_ret_t populate_record_from_dbus(get_sdr::SensorDataFullRecordBody *body,
/* Functional sensor case */
if (isAnalogSensor(info->propertyInterfaces.begin()->first))
{
- // Get bus
- sd_bus *bus = ipmid_get_sd_bus_connection();
- dbus_interface_t iface;
-
- if (0 > find_openbmc_path(body->entity_id, &iface))
- return IPMI_CC_SENSOR_INVALID;
body->sensor_units_1 = 0; // unsigned, no rate, no modifier, not a %
/* Unit info */
- setUnitFieldsForObject(bus, iface, info, body);
-
- /* Modifiers to reading info */
- // Get scale
- int64_t scale = getScaleForObject(bus, iface, info);
+ setUnitFieldsForObject(info, body);
get_sdr::body::set_b(info->coefficientB, body);
get_sdr::body::set_m(info->coefficientM, body);
get_sdr::body::set_b_exp(info->exponentB, body);
- get_sdr::body::set_r_exp(scale, body);
+ get_sdr::body::set_r_exp(info->exponentR, body);
get_sdr::body::set_id_type(0b00, body); // 00 = unicode
}
diff --git a/sensorhandler.h b/sensorhandler.h
index f5b5c94..4dd079d 100644
--- a/sensorhandler.h
+++ b/sensorhandler.h
@@ -527,6 +527,11 @@ inline uint8_t get_device_id_strlen(SensorDataFruRecordBody* body)
return body->deviceIDLen & LENGTH_MASK;
};
+inline void set_readable_mask(uint8_t mask, SensorDataFullRecordBody* body)
+{
+ body->discrete_reading_setting_mask[1] = mask & 0x3F;
+}
+
} // namespace body
// More types contained in section 43.17 Sensor Unit Type Codes,
@@ -537,6 +542,7 @@ enum SensorUnitTypeCodes
SENSOR_UNIT_DEGREES_C = 1,
SENSOR_UNIT_VOLTS = 4,
SENSOR_UNIT_AMPERES = 5,
+ SENSOR_UNIT_WATTS = 6,
SENSOR_UNIT_JOULES = 7,
SENSOR_UNIT_METERS = 34,
SENSOR_UNIT_REVOLUTIONS = 41,
OpenPOWER on IntegriCloud