summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--scripts/writesensor.mako.cpp9
-rw-r--r--sensorhandler.cpp54
-rw-r--r--types.hpp5
3 files changed, 46 insertions, 22 deletions
diff --git a/scripts/writesensor.mako.cpp b/scripts/writesensor.mako.cpp
index c5db13a..e081474 100644
--- a/scripts/writesensor.mako.cpp
+++ b/scripts/writesensor.mako.cpp
@@ -43,6 +43,9 @@ extern const IdInfoMap sensors = {
multiplier = sensor.get("multiplierM", 1)
offsetB = sensor.get("offsetB", 0)
exp = sensor.get("bExp", 0)
+ unit = sensor.get("unit", "")
+ scale = sensor.get("scale", 0)
+ hasScale = "true" if "scale" in sensor.keys() else "false"
valueReadingType = sensor["readingType"]
updateFunc = interfaceDict[serviceInterface]["updateFunc"]
updateFunc += sensor["readingType"]
@@ -61,7 +64,9 @@ extern const IdInfoMap sensors = {
mutability = sensor.get("mutability", "Mutability::Read")
%>
${sensorType},"${path}","${sensorInterface}",${readingType},${multiplier},
- ${offsetB},${exp},${offsetB * pow(10,exp)},${updateFunc},${getFunc},Mutability(${mutability}),{
+ ${offsetB},${exp},${offsetB * pow(10,exp)},
+ ${hasScale},${scale},"${unit}",
+ ${updateFunc},${getFunc},Mutability(${mutability}),{
% for interface,properties in interfaces.items():
{"${interface}",{
% for dbus_property,property_value in properties.items():
@@ -127,7 +132,7 @@ except KeyError, e:
% endfor
}},
% endfor
- }
+ },
}},
% endif
% endfor
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));
+ }
}
}
diff --git a/types.hpp b/types.hpp
index 0177c8f..a43c8c0 100644
--- a/types.hpp
+++ b/types.hpp
@@ -113,6 +113,8 @@ using Multiplier = uint16_t;
using OffsetB = uint16_t;
using Exponent = uint8_t;
using ScaledOffset = int64_t;
+using Scale = int16_t;
+using Unit = std::string;
enum class Mutability
{
@@ -142,6 +144,9 @@ struct Info
OffsetB coefficientB;
Exponent exponentB;
ScaledOffset scaledOffset;
+ bool hasScale;
+ Scale scale;
+ Unit unit;
std::function<uint8_t(SetSensorReadingReq&, const Info&)> updateFunc;
std::function<GetSensorResponse(const Info&)> getFunc;
Mutability mutability;
OpenPOWER on IntegriCloud