summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Filippov <a.filippov@yadro.com>2019-03-21 18:12:07 +0300
committerEdward A. James <eajames@us.ibm.com>2019-04-10 17:05:56 +0000
commit1d69e19255e4195f85539200842d88c0dec426f1 (patch)
tree96e1c1ef7b9ce27a0f2de0a92fd1a7e9b35bca07
parentb35cd0df3927cd12f670d7db70489dd0bf19441a (diff)
downloadopenpower-occ-control-master.tar.gz
openpower-occ-control-master.zip
Add support for sensorName field in yamlHEADmaster
We want to have ability to specify the human readable names for the OCC sensors. E.g. `CPU0_OCC` instead of `occ_4_0050`. This commit allows to specify a `sensorName` field in the YAML config for each sensor, and this name will be used in the sensor object DBus path. If the field is not specified, previous behavior will be used. Tested: the command `busctl tree org.open_power.OCC.Control --list` must show specified names. Change-Id: I2f05f7bf44120554ea07b9ee0aac9cfbd33ac376 Signed-off-by: Alexander Filippov <a.filippov@yadro.com>
-rwxr-xr-xocc_sensor.mako.hpp9
-rw-r--r--occ_status.cpp9
-rw-r--r--occ_status.hpp48
3 files changed, 55 insertions, 11 deletions
diff --git a/occ_sensor.mako.hpp b/occ_sensor.mako.hpp
index b5fac53..19c785f 100755
--- a/occ_sensor.mako.hpp
+++ b/occ_sensor.mako.hpp
@@ -6,6 +6,8 @@
#pragma once
#include <map>
+#include <string>
+#include <tuple>
namespace open_power
{
@@ -14,15 +16,18 @@ namespace occ
using instanceID = int;
using sensorID = uint8_t;
-const std::map<instanceID, sensorID> Status::sensorMap = {
+using sensorName = std::string;
+using sensorDefs = std::tuple<sensorID, sensorName>;
+const std::map<instanceID, sensorDefs> Status::sensorMap = {
\
% for occ in occDict:
<%
instance = occ.get("Instance")
id = occ.get("SensorID")
+ name = occ.get("SensorName")
%>\
\
- { ${instance}, ${id} },\
+ { ${instance}, { ${id}, "${name}" }},\
% endfor
};
diff --git a/occ_status.cpp b/occ_status.cpp
index c2c4bae..0782f87 100644
--- a/occ_status.cpp
+++ b/occ_status.cpp
@@ -95,7 +95,8 @@ void Status::resetOCC()
method.append(convertForMessage(Control::Host::Command::OCCReset).c_str());
// OCC Sensor ID for callout reasons
- method.append(sdbusplus::message::variant<uint8_t>(sensorMap.at(instance)));
+ method.append(sdbusplus::message::variant<uint8_t>(
+ std::get<0>(sensorMap.at(instance))));
bus.call_noreply(method);
return;
}
@@ -122,9 +123,9 @@ void Status::hostControlEvent(sdbusplus::message::message& msg)
Control::Host::Command::OCCReset)
{
// Must be a Timeout. Log an Error trace
- log<level::ERR>("Error resetting the OCC.",
- entry("PATH=%s", path.c_str()),
- entry("SENSORID=0x%X", sensorMap.at(instance)));
+ log<level::ERR>(
+ "Error resetting the OCC.", entry("PATH=%s", path.c_str()),
+ entry("SENSORID=0x%X", std::get<0>(sensorMap.at(instance))));
}
}
return;
diff --git a/occ_status.hpp b/occ_status.hpp
index 859b5b0..1617d12 100644
--- a/occ_status.hpp
+++ b/occ_status.hpp
@@ -31,6 +31,12 @@ using instanceID = int;
// IPMI sensor ID for a given OCC instance
using sensorID = uint8_t;
+// Human readable sensor name for DBus tree. E.g. "CPU0_OCC"
+using sensorName = std::string;
+
+// OCC sensors definitions in the map
+using sensorDefs = std::tuple<sensorID, sensorName>;
+
// OCC sysfs name prefix
const std::string sysfsName = "occ-hwmon";
@@ -60,9 +66,8 @@ class Status : public Interface
Status(sdbusplus::bus::bus& bus, EventPtr& event, const char* path,
const Manager& manager,
std::function<void(bool)> callBack = nullptr) :
- Interface(bus, path, true),
- bus(bus), path(path), callBack(callBack),
- instance(((this->path.back() - '0'))),
+ Interface(bus, getDbusPath(path).c_str(), true),
+ bus(bus), path(path), callBack(callBack), instance(getInstance(path)),
device(event,
#ifdef I2C_OCC
fs::path(DEV_PATH) / i2c_occ::getI2cDeviceName(path),
@@ -140,8 +145,8 @@ class Status : public Interface
/** @brief OCC instance number. Ex, 0,1, etc */
int instance;
- /** @brief OCC instance to Sensor ID mapping */
- static const std::map<instanceID, sensorID> sensorMap;
+ /** @brief OCC instance to Sensor definitions mapping */
+ static const std::map<instanceID, sensorDefs> sensorMap;
/** @brief OCC device object to do bind and unbind */
Device device;
@@ -169,6 +174,39 @@ class Status : public Interface
/** @brief Sends a message to host control command handler to reset OCC
*/
void resetOCC();
+
+ /** @brief Determines the instance ID by specified object path.
+ * @param[in] path Estimated OCC Dbus object path
+ * @return Instance number
+ */
+ static int getInstance(const std::string& path)
+ {
+ return (path.empty() ? 0 : path.back() - '0');
+ }
+
+ /** @brief Override the sensor name with name from the definition.
+ * @param[in] estimatedPath - Estimated OCC Dbus object path
+ * @return Fixed OCC DBus object path
+ */
+ static std::string getDbusPath(const std::string& estimatedPath)
+ {
+ if (!estimatedPath.empty())
+ {
+ auto it = sensorMap.find(getInstance(estimatedPath));
+ if (sensorMap.end() != it)
+ {
+ auto& name = std::get<1>(it->second);
+ if (!name.empty() && name != "None")
+ {
+ auto path = fs::path(estimatedPath);
+ path.replace_filename(name);
+ return path.string();
+ }
+ }
+ }
+
+ return estimatedPath;
+ }
};
} // namespace occ
OpenPOWER on IntegriCloud