Add support for sensor override value
Write support Value property under xyz.openbmc_project.Sensor.Value
interface is added which will be used to do sensor override.
Sensor can be overridden by setting a value, which will be preserved,
till the service is restarted or Value is overridden again with NaN.
Change-Id: Ia606031a97e532cd12d768e36f1feaa4c7350620
Signed-off-by: Richard Marian Thomaiyar <richard.marian.thomaiyar@linux.intel.com>
Signed-off-by: James Feist <james.feist@linux.intel.com>
diff --git a/src/ADCSensor.cpp b/src/ADCSensor.cpp
index 09c62cf..4ce6dda 100644
--- a/src/ADCSensor.cpp
+++ b/src/ADCSensor.cpp
@@ -101,9 +101,11 @@
try
{
float nvalue = std::stof(response);
-
nvalue = (nvalue / sensorScaleFactor) / scaleFactor;
-
+ if (!isnan(overriddenValue))
+ {
+ nvalue = overriddenValue;
+ }
if (nvalue != value)
{
updateValue(nvalue);
@@ -157,7 +159,10 @@
void ADCSensor::updateValue(const double &newValue)
{
+ // Indicate that it is internal set call
+ internalSet = true;
bool ret = sensorInterface->set_property("Value", newValue);
+ internalSet = false;
value = newValue;
checkThresholds();
}
@@ -168,7 +173,10 @@
// todo, get max and min from configuration
sensorInterface->register_property("MaxValue", maxValue);
sensorInterface->register_property("MinValue", minValue);
- sensorInterface->register_property("Value", value);
+ sensorInterface->register_property(
+ "Value", value, [&](const double &newValue, double &oldValue) {
+ return setSensorValue(newValue, oldValue);
+ });
for (auto &threshold : thresholds)
{