smbpbi: Add support for PowerState config option
This change adds support for the `PowerState` configuration option for
SmbpbiVirtualEeprom sensor.
Tested:
- EM config
```
{
"Address": 79,
"Bus": 13,
"MaxValue": 127,
"MinValue": -128,
"Name": "HGX_GPU0_TEMP_C",
"PollRate": 1,
"PowerState": "On",
"ReadOffset": 288,
"Type": "SmbpbiVirtualEeprom",
"Units": "DegreesC",
"ValueType": "UINT64"
}
```
- Host state in running
```
root@bmc:~# busctl introspect xyz.openbmc_project.SMBPBI /xyz/openbmc_project/sensors/temperature/HGX_GPU0_TEMP_C xyz.openbmc_project.State.Decorator.Availability -l
NAME TYPE SIGNATURE RESULT/VALUE FLAGS
.Available property b true emits-change writable
root@bmc:~# busctl introspect xyz.openbmc_project.SMBPBI /xyz/openbmc_project/sensors/temperature/HGX_GPU0_TEMP_C xyz.openbmc_project.Sensor.Value -l
NAME TYPE SIGNATURE RESULT/VALUE FLAGS
.MaxValue property d 127 emits-change
.MinValue property d -128 emits-change
.Unit property s "xyz.openbmc_project.Sensor.Value.Unit.DegreesC" emits-change
.Value property d 79.1562 emits-change writable
```
- Host state is off
```
root@bmc:~# busctl introspect xyz.openbmc_project.SMBPBI /xyz/openbmc_project/sensors/temperature/HGX_GPU0_TEMP_C xyz.openbmc_project.State.Decorator.Availability -l
NAME TYPE SIGNATURE RESULT/VALUE FLAGS
.Available property b false emits-change writable
root@bmc:~# busctl introspect xyz.openbmc_project.SMBPBI /xyz/openbmc_project/sensors/temperature/HGX_GPU0_TEMP_C xyz.openbmc_project.Sensor.Value -l
NAME TYPE SIGNATURE RESULT/VALUE FLAGS
.MaxValue property d 127 emits-change
.MinValue property d -128 emits-change
.Unit property s "xyz.openbmc_project.Sensor.Value.Unit.DegreesC" emits-change
.Value property d nan emits-change writable
```
Change-Id: Ie088c28fe337c00265556df6b14664106be39b73
Signed-off-by: Potin Lai <potin.lai@quantatw.com>
diff --git a/src/smbpbi/SmbpbiSensor.cpp b/src/smbpbi/SmbpbiSensor.cpp
index 17e9192..d04deae 100644
--- a/src/smbpbi/SmbpbiSensor.cpp
+++ b/src/smbpbi/SmbpbiSensor.cpp
@@ -55,9 +55,10 @@
std::vector<thresholds::Threshold>&& thresholdData, uint8_t busId,
uint8_t addr, uint16_t offset, std::string& sensorUnits,
std::string& valueType, size_t pollTime, double minVal, double maxVal,
- std::string& path) :
+ std::string& path, const PowerState& powerState) :
Sensor(escapeName(sensorName), std::move(thresholdData),
- sensorConfiguration, objType, false, false, maxVal, minVal, conn),
+ sensorConfiguration, objType, false, false, maxVal, minVal, conn,
+ powerState),
busId(busId), addr(addr), offset(offset), sensorUnits(sensorUnits),
valueType(valueType), objectServer(objectServer),
inputDev(io, path, boost::asio::random_access_file::read_only),
@@ -406,6 +407,8 @@
uint16_t off = loadVariant<uint16_t>(entry.second, "ReadOffset");
+ PowerState pwrState = getPowerState(entry.second);
+
std::string sensorUnits =
loadVariant<std::string>(entry.second, "Units");
@@ -423,21 +426,22 @@
double minVal = loadVariant<double>(entry.second, "MinValue");
double maxVal = loadVariant<double>(entry.second, "MaxValue");
- lg2::debug(
- "Configuration parsed for \n\t {CONF}\nwith\n"
- "\tName: {NAME}\n"
- "\tBus: {BUS}\n"
- "\tAddress:{ADDR}\n"
- "\tOffset: {OFF}\n"
- "\tType : {TYPE}\n"
- "\tValue Type : {VALUETYPE}\n"
- "\tPollrate: {RATE}\n"
- "\tMinValue: {MIN}\n"
- "\tMaxValue: {MAX}\n",
- "CONF", entry.first, "NAME", name, "BUS",
- static_cast<int>(busId), "ADDR", static_cast<int>(addr), "OFF",
- static_cast<int>(off), "UNITS", sensorUnits, "VALUETYPE",
- valueType, "RATE", rate, "MIN", minVal, "MAX", maxVal);
+ lg2::debug("Configuration parsed for \n\t {CONF}\nwith\n"
+ "\tName: {NAME}\n"
+ "\tBus: {BUS}\n"
+ "\tAddress:{ADDR}\n"
+ "\tOffset: {OFF}\n"
+ "\tType : {TYPE}\n"
+ "\tValue Type : {VALUETYPE}\n"
+ "\tPollrate: {RATE}\n"
+ "\tMinValue: {MIN}\n"
+ "\tMaxValue: {MAX}\n"
+ "\tPowerState: {PWRSTATE}\n",
+ "CONF", entry.first, "NAME", name, "BUS",
+ static_cast<int>(busId), "ADDR", static_cast<int>(addr),
+ "OFF", static_cast<int>(off), "UNITS", sensorUnits,
+ "VALUETYPE", valueType, "RATE", rate, "MIN", minVal,
+ "MAX", maxVal, "PWRSTATE", pwrState);
auto& sensor = sensors[name];
sensor = nullptr;
@@ -447,7 +451,7 @@
sensor = std::make_unique<SmbpbiSensor>(
dbusConnection, io, name, pathPair.first, objectType,
objectServer, std::move(sensorThresholds), busId, addr, off,
- sensorUnits, valueType, rate, minVal, maxVal, path);
+ sensorUnits, valueType, rate, minVal, maxVal, path, pwrState);
sensor->init();
}
diff --git a/src/smbpbi/SmbpbiSensor.hpp b/src/smbpbi/SmbpbiSensor.hpp
index d27fce9..e63b5b9 100644
--- a/src/smbpbi/SmbpbiSensor.hpp
+++ b/src/smbpbi/SmbpbiSensor.hpp
@@ -5,6 +5,7 @@
#pragma once
#include "Thresholds.hpp"
+#include "Utils.hpp"
#include <boost/asio/io_context.hpp>
#include <boost/asio/random_access_file.hpp>
@@ -39,7 +40,7 @@
std::vector<thresholds::Threshold>&& thresholdData, uint8_t busId,
uint8_t addr, uint16_t offset, std::string& sensorUnits,
std::string& valueType, size_t pollTime, double minVal, double maxVal,
- std::string& path);
+ std::string& path, const PowerState& powerState);
~SmbpbiSensor() override;
void checkThresholds() override;