summaryrefslogtreecommitdiffstats
path: root/sensorhandler.cpp
diff options
context:
space:
mode:
authorEmily Shaffer <emilyshaffer@google.com>2017-06-14 13:06:26 -0700
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2017-12-10 05:49:24 +0000
commit6223561894d2ab60cf4af2c5b5cc930c0a26d8c2 (patch)
treeddd825a857344df4ac21f50925b913e6556d1ad1 /sensorhandler.cpp
parentdd9943119afe553f930694214d7fa40771f7f89b (diff)
downloadphosphor-host-ipmid-6223561894d2ab60cf4af2c5b5cc930c0a26d8c2.tar.gz
phosphor-host-ipmid-6223561894d2ab60cf4af2c5b5cc930c0a26d8c2.zip
sensorhandler: allow preconfigured unit and scale
Allow specifying the scale and unit for a sensor in the YAML configuration. This can save clock time by no longer requiring the daemon to reach out to the sensor owner for the information. Change-Id: I5f63286fc32fb9d64ebab7d86d1dbb7ff40591f4 Signed-off-by: Emily Shaffer <emilyshaffer@google.com> Signed-off-by: Patrick Venture <venture@google.com>
Diffstat (limited to 'sensorhandler.cpp')
-rw-r--r--sensorhandler.cpp54
1 files changed, 34 insertions, 20 deletions
diff --git a/sensorhandler.cpp b/sensorhandler.cpp
index 582f16b..3358b83 100644
--- a/sensorhandler.cpp
+++ b/sensorhandler.cpp
@@ -697,20 +697,27 @@ void setUnitFieldsForObject(sd_bus *bus,
"xyz.openbmc_project.Sensor.Value")
{
std::string result {};
- char *raw_cstr = NULL;
- if (0 > sd_bus_get_property_string(bus, iface.bus, iface.path,
- iface.interface, "Unit", NULL,
- &raw_cstr))
+ if (info->unit.empty())
{
- log<level::WARNING>("Unit interface missing.",
- entry("BUS=%s", iface.bus),
- entry("PATH=%s", iface.path));
+ 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
{
- result = raw_cstr;
+ result = info->unit;
}
- free(raw_cstr);
namespace server = sdbusplus::xyz::openbmc_project::Sensor::server;
try {
@@ -758,17 +765,24 @@ int64_t getScaleForObject(sd_bus *bus,
if (info->propertyInterfaces.begin()->first ==
"xyz.openbmc_project.Sensor.Value")
{
- 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));
+ 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));
+ }
}
}
OpenPOWER on IntegriCloud