From 1d69e19255e4195f85539200842d88c0dec426f1 Mon Sep 17 00:00:00 2001 From: Alexander Filippov Date: Thu, 21 Mar 2019 18:12:07 +0300 Subject: Add support for sensorName field in yaml 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 --- occ_sensor.mako.hpp | 9 +++++++-- occ_status.cpp | 9 +++++---- occ_status.hpp | 48 +++++++++++++++++++++++++++++++++++++++++++----- 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 +#include +#include namespace open_power { @@ -14,15 +16,18 @@ namespace occ using instanceID = int; using sensorID = uint8_t; -const std::map Status::sensorMap = { +using sensorName = std::string; +using sensorDefs = std::tuple; +const std::map 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(sensorMap.at(instance))); + method.append(sdbusplus::message::variant( + 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("Error resetting the OCC.", - entry("PATH=%s", path.c_str()), - entry("SENSORID=0x%X", sensorMap.at(instance))); + log( + "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; + // 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 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 sensorMap; + /** @brief OCC instance to Sensor definitions mapping */ + static const std::map 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 -- cgit v1.2.1