Handle Value::Unit::Percent unit correctly
Currently if a sensor unit is 'Value::Unit::Percent' the following
error message is generated:
"""
Unknown value unit type: = xyz.openbmc_project.Sensor.Value.Unit.Percent
"""
According to the IPMI specification if the sensor unit is percent the
'Percentage' bit should be set in the 'Sensor Units 1' field of the full
sensor record. Use 'set_percentage' function to set this field.
Also for consistency move the rest of the 'Sensor Units 1' field setting
inside the 'setUnitFieldsForObject' function.
Tested:
- Before
Each sensor with the 'Value::Unit::Percent' unit produces the 'Unknown
value unit type' error message
- After
No more 'Unknown value unit type' error messages from the percent unit
sensors.
Change-Id: I23048f91be0ca7ce749732c766d9f195e929c7b7
Signed-off-by: Konstantin Aladyshev <aladyshev22@gmail.com>
diff --git a/sensorhandler.cpp b/sensorhandler.cpp
index 6940134..a175f20 100644
--- a/sensorhandler.cpp
+++ b/sensorhandler.cpp
@@ -1082,6 +1082,8 @@
get_sdr::SensorDataFullRecordBody* body)
{
namespace server = sdbusplus::server::xyz::openbmc_project::sensor;
+ body->sensor_units_1 = info->sensorUnits1; // default is 0. unsigned, no
+ // rate, no modifier, not a %
try
{
auto unit = server::Value::convertUnitFromString(info->unit);
@@ -1110,6 +1112,9 @@
case server::Value::Unit::Watts:
body->sensor_units_2_base = get_sdr::SENSOR_UNIT_WATTS;
break;
+ case server::Value::Unit::Percent:
+ get_sdr::body::set_percentage(body);
+ break;
default:
// Cannot be hit.
std::fprintf(stderr, "Unknown value unit type: = %s\n",
@@ -1129,8 +1134,6 @@
/* Functional sensor case */
if (isAnalogSensor(info->propertyInterfaces.begin()->first))
{
- body->sensor_units_1 = info->sensorUnits1; // default is 0. unsigned, no
- // rate, no modifier, not a %
/* Unit info */
setUnitFieldsForObject(info, body);