Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016-2020 CESNET, https://photonics.cesnet.cz/ |
| 3 | * |
| 4 | * Written by Tomáš Pecka <tomas.pecka@fit.cvut.cz> |
| 5 | * |
| 6 | */ |
| 7 | |
Václav Kubernát | 069d3a9 | 2021-11-14 12:37:46 +0100 | [diff] [blame] | 8 | #include <chrono> |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 9 | #include <utility> |
| 10 | #include "IETFHardware.h" |
| 11 | #include "utils/log.h" |
| 12 | #include "utils/time.h" |
| 13 | |
| 14 | using namespace std::literals; |
| 15 | |
| 16 | namespace { |
| 17 | |
Tomáš Pecka | 83b62e1 | 2020-12-16 14:50:49 +0100 | [diff] [blame] | 18 | static const std::string ietfHardwareStatePrefix = "/ietf-hardware:hardware"; |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 19 | |
| 20 | /** @brief Constructs a full XPath for a specific component */ |
| 21 | std::string xpathForComponent(const std::string& componentName) |
| 22 | { |
| 23 | return ietfHardwareStatePrefix + "/component[name='" + componentName + "']/"; |
| 24 | } |
| 25 | |
| 26 | /** @brief Prefix all properties from values DataTree with a component name (calculated from @p componentName) and push them into the DataTree */ |
| 27 | void addComponent(velia::ietf_hardware::DataTree& res, const std::string& componentName, const std::optional<std::string>& parent, const velia::ietf_hardware::DataTree& values) |
| 28 | { |
| 29 | auto componentPrefix = xpathForComponent(componentName); |
| 30 | |
| 31 | if (parent) { |
| 32 | res[componentPrefix + "parent"] = *parent; |
| 33 | } |
| 34 | for (const auto& [k, v] : values) { |
| 35 | res[componentPrefix + k] = v; |
| 36 | } |
Tomáš Pecka | 7eb0c42 | 2023-04-21 15:36:33 +0200 | [diff] [blame] | 37 | |
| 38 | res[componentPrefix + "state/oper-state"] = "enabled"; |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 39 | } |
| 40 | |
Tomáš Pecka | 655062c | 2023-12-11 15:37:58 +0100 | [diff] [blame^] | 41 | void writeSensorValue(velia::ietf_hardware::DataTree& res, const std::string& componentName, const std::string& value, const std::string& operStatus) |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 42 | { |
| 43 | const auto componentPrefix = xpathForComponent(componentName); |
| 44 | res[componentPrefix + "sensor-data/value"] = value; |
Tomáš Pecka | 655062c | 2023-12-11 15:37:58 +0100 | [diff] [blame^] | 45 | res[componentPrefix + "sensor-data/oper-status"] = operStatus; |
| 46 | } |
| 47 | |
| 48 | /** @brief Write a sensor-data @p value for a component @p componentName and push it into the @p res DataTree */ |
| 49 | void addSensorValue(velia::ietf_hardware::DataTree& res, const std::string& componentName, const int64_t& value) |
| 50 | { |
| 51 | writeSensorValue(res, componentName, std::to_string(value), "ok"); |
| 52 | } |
| 53 | |
| 54 | /** @brief Write a sensor-data @p value for a component @p componentName and push it into the @p res DataTree */ |
| 55 | void addSensorValue(velia::ietf_hardware::DataTree& res, const std::string& componentName, const std::string& value) |
| 56 | { |
| 57 | // TODO: Perhaps we should check if the string value is conforming to sensor-value type |
| 58 | writeSensorValue(res, componentName, value, "ok"); |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 59 | } |
| 60 | } |
| 61 | |
| 62 | namespace velia::ietf_hardware { |
| 63 | |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 64 | IETFHardware::IETFHardware() |
| 65 | : m_log(spdlog::get("hardware")) |
| 66 | { |
| 67 | } |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 68 | |
| 69 | IETFHardware::~IETFHardware() = default; |
| 70 | |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 71 | /** |
| 72 | * Calls individual registered data readers and processes information obtained from them. |
| 73 | * The sensor values are then passed to threshold watchers to detect if the new value violated a threshold. |
| 74 | * This function does not raise any alarms. It only returns the data tree *and* any changes in the threshold |
| 75 | * crossings (as a mapping from sensor XPath to threshold watcher State (@see Watcher)). |
| 76 | **/ |
| 77 | HardwareInfo IETFHardware::process() |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 78 | { |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 79 | DataTree dataTree; |
| 80 | std::map<std::string, State> alarms; |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 81 | |
| 82 | for (auto& dataReader : m_callbacks) { |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 83 | dataTree.merge(dataReader()); |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 84 | } |
| 85 | |
Tomáš Pecka | 0d8d8ee | 2023-05-10 12:22:58 +0200 | [diff] [blame] | 86 | for (auto& [sensorXPath, thresholdsWatcher] : m_thresholdsWatchers) { |
| 87 | std::optional<int64_t> newValue; |
| 88 | |
| 89 | if (auto it = dataTree.find(sensorXPath); it != dataTree.end()) { |
| 90 | newValue = std::stoll(it->second); |
| 91 | } else { |
| 92 | newValue = std::nullopt; |
| 93 | } |
| 94 | |
| 95 | if (auto newState = thresholdsWatcher.update(newValue)) { |
| 96 | m_log->debug("threshold: {} {}", sensorXPath, *newState); |
| 97 | alarms.emplace(sensorXPath, *newState); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | dataTree[ietfHardwareStatePrefix + "/last-change"] = velia::utils::yangTimeFormat(std::chrono::system_clock::now()); |
| 102 | |
| 103 | return {dataTree, alarms}; |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 104 | } |
| 105 | |
Tomáš Pecka | d2322ad | 2023-05-11 16:20:38 +0200 | [diff] [blame] | 106 | std::vector<std::string> IETFHardware::sensorsXPaths() const |
| 107 | { |
| 108 | std::vector<std::string> res; |
| 109 | |
| 110 | for (const auto& [sensorXPath, thresholds] : m_thresholdsWatchers) { |
| 111 | res.emplace_back(sensorXPath); |
| 112 | } |
| 113 | |
| 114 | return res; |
| 115 | } |
| 116 | |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 117 | /** @brief A namespace containing predefined data readers for IETFHardware class. |
| 118 | * @see IETFHardware for more information |
| 119 | */ |
| 120 | namespace data_reader { |
| 121 | |
| 122 | DataReader::DataReader(std::string componentName, std::optional<std::string> parent) |
| 123 | : m_componentName(std::move(componentName)) |
| 124 | , m_parent(std::move(parent)) |
| 125 | { |
| 126 | } |
| 127 | |
| 128 | /** @brief Constructs a component without any sensor-data and provide only the static data @p dataTree passed via constructor. |
| 129 | * @param componentName the name of the component in the resulting tree |
| 130 | * @param parent The component in YANG model has a link to parent. Specify who is the parent. |
| 131 | * @param dataTree static data to insert into the resulting tree. The dataTree keys should only contain the YANG node name, not full XPath. The full XPath is constructed from @componentName and the map key. |
| 132 | */ |
| 133 | StaticData::StaticData(std::string componentName, std::optional<std::string> parent, DataTree dataTree) |
| 134 | : DataReader(std::move(componentName), std::move(parent)) |
| 135 | { |
| 136 | addComponent(m_staticData, |
| 137 | m_componentName, |
| 138 | m_parent, |
| 139 | dataTree); |
| 140 | } |
| 141 | |
| 142 | DataTree StaticData::operator()() const { return m_staticData; } |
Tomáš Pecka | 4886db2 | 2023-05-10 10:46:15 +0200 | [diff] [blame] | 143 | ThresholdsBySensorPath StaticData::thresholds() const { return {}; } |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 144 | |
Tomáš Pecka | 4886db2 | 2023-05-10 10:46:15 +0200 | [diff] [blame] | 145 | Fans::Fans(std::string componentName, std::optional<std::string> parent, std::shared_ptr<sysfs::HWMon> hwmon, unsigned fanChannelsCount, Thresholds<int64_t> thresholds) |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 146 | : DataReader(std::move(componentName), std::move(parent)) |
| 147 | , m_hwmon(std::move(hwmon)) |
| 148 | , m_fanChannelsCount(fanChannelsCount) |
Tomáš Pecka | 4886db2 | 2023-05-10 10:46:15 +0200 | [diff] [blame] | 149 | , m_thresholds(std::move(thresholds)) |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 150 | { |
| 151 | // fans |
| 152 | addComponent(m_staticData, |
| 153 | m_componentName, |
| 154 | m_parent, |
Tomáš Pecka | 77e09c2 | 2023-05-04 20:39:57 +0200 | [diff] [blame] | 155 | DataTree{ |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 156 | {"class", "iana-hardware:module"}, // FIXME: Read (or pass via constructor) additional properties (mfg, model, ...). They should be in the fans' tray EEPROM. |
| 157 | }); |
| 158 | |
| 159 | for (unsigned i = 1; i <= m_fanChannelsCount; i++) { |
| 160 | // fans -> fan_i |
| 161 | addComponent(m_staticData, |
| 162 | m_componentName + ":fan" + std::to_string(i), |
| 163 | m_componentName, |
Tomáš Pecka | 77e09c2 | 2023-05-04 20:39:57 +0200 | [diff] [blame] | 164 | DataTree{ |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 165 | {"class", "iana-hardware:fan"}, |
| 166 | }); |
| 167 | |
| 168 | // fans -> fan_i -> sensor-data |
| 169 | addComponent(m_staticData, |
| 170 | m_componentName + ":fan" + std::to_string(i) + ":rpm", |
| 171 | m_componentName + ":fan" + std::to_string(i), |
Tomáš Pecka | 77e09c2 | 2023-05-04 20:39:57 +0200 | [diff] [blame] | 172 | DataTree{ |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 173 | {"class", "iana-hardware:sensor"}, |
| 174 | {"sensor-data/value-type", "rpm"}, |
| 175 | {"sensor-data/value-scale", "units"}, |
| 176 | {"sensor-data/value-precision", "0"}, |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 177 | }); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | DataTree Fans::operator()() const |
| 182 | { |
| 183 | DataTree res(m_staticData); |
| 184 | |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 185 | for (unsigned i = 1; i <= m_fanChannelsCount; i++) { |
| 186 | const auto sensorComponentName = m_componentName + ":fan" + std::to_string(i) + ":rpm"; |
| 187 | const auto attribute = "fan"s + std::to_string(i) + "_input"; |
| 188 | |
Tomáš Pecka | 655062c | 2023-12-11 15:37:58 +0100 | [diff] [blame^] | 189 | addSensorValue(res, sensorComponentName, m_hwmon->attribute(attribute)); |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | return res; |
| 193 | } |
| 194 | |
Tomáš Pecka | 4886db2 | 2023-05-10 10:46:15 +0200 | [diff] [blame] | 195 | ThresholdsBySensorPath Fans::thresholds() const |
| 196 | { |
| 197 | ThresholdsBySensorPath res; |
| 198 | |
| 199 | for (unsigned i = 1; i <= m_fanChannelsCount; i++) { |
| 200 | res.emplace(xpathForComponent(m_componentName + ":fan" + std::to_string(i) + ":rpm") + "sensor-data/value", m_thresholds); |
| 201 | } |
| 202 | |
| 203 | return res; |
| 204 | } |
| 205 | |
Václav Kubernát | 6c17d0a | 2021-03-29 04:55:31 +0200 | [diff] [blame] | 206 | std::string getSysfsFilename(const SensorType type, int sysfsChannelNr) |
| 207 | { |
| 208 | switch (type) { |
Tomáš Pecka | 77e09c2 | 2023-05-04 20:39:57 +0200 | [diff] [blame] | 209 | case SensorType::Temperature: |
| 210 | return "temp"s + std::to_string(sysfsChannelNr) + "_input"; |
| 211 | case SensorType::Current: |
| 212 | return "curr"s + std::to_string(sysfsChannelNr) + "_input"; |
| 213 | case SensorType::Power: |
| 214 | return "power"s + std::to_string(sysfsChannelNr) + "_input"; |
| 215 | case SensorType::VoltageAC: |
| 216 | case SensorType::VoltageDC: |
| 217 | return "in"s + std::to_string(sysfsChannelNr) + "_input"; |
Václav Kubernát | 6c17d0a | 2021-03-29 04:55:31 +0200 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | __builtin_unreachable(); |
| 221 | } |
| 222 | |
Tomáš Pecka | 77e09c2 | 2023-05-04 20:39:57 +0200 | [diff] [blame] | 223 | template <SensorType TYPE> |
| 224 | const DataTree sysfsStaticData; |
| 225 | template <> |
| 226 | const DataTree sysfsStaticData<SensorType::Temperature> = { |
Václav Kubernát | 6c17d0a | 2021-03-29 04:55:31 +0200 | [diff] [blame] | 227 | {"class", "iana-hardware:sensor"}, |
| 228 | {"sensor-data/value-type", "celsius"}, |
| 229 | {"sensor-data/value-scale", "milli"}, |
| 230 | {"sensor-data/value-precision", "0"}, |
Václav Kubernát | 6c17d0a | 2021-03-29 04:55:31 +0200 | [diff] [blame] | 231 | }; |
Tomáš Pecka | 77e09c2 | 2023-05-04 20:39:57 +0200 | [diff] [blame] | 232 | template <> |
| 233 | const DataTree sysfsStaticData<SensorType::Current> = { |
Václav Kubernát | 97e5ea1 | 2021-03-24 00:36:57 +0100 | [diff] [blame] | 234 | {"class", "iana-hardware:sensor"}, |
| 235 | {"sensor-data/value-type", "amperes"}, |
| 236 | {"sensor-data/value-scale", "milli"}, |
| 237 | {"sensor-data/value-precision", "0"}, |
Václav Kubernát | 97e5ea1 | 2021-03-24 00:36:57 +0100 | [diff] [blame] | 238 | }; |
Tomáš Pecka | 77e09c2 | 2023-05-04 20:39:57 +0200 | [diff] [blame] | 239 | template <> |
| 240 | const DataTree sysfsStaticData<SensorType::Power> = { |
Václav Kubernát | 97e5ea1 | 2021-03-24 00:36:57 +0100 | [diff] [blame] | 241 | {"class", "iana-hardware:sensor"}, |
| 242 | {"sensor-data/value-type", "watts"}, |
| 243 | {"sensor-data/value-scale", "micro"}, |
| 244 | {"sensor-data/value-precision", "0"}, |
Václav Kubernát | 97e5ea1 | 2021-03-24 00:36:57 +0100 | [diff] [blame] | 245 | }; |
Tomáš Pecka | 77e09c2 | 2023-05-04 20:39:57 +0200 | [diff] [blame] | 246 | template <> |
| 247 | const DataTree sysfsStaticData<SensorType::VoltageAC> = { |
Václav Kubernát | 97e5ea1 | 2021-03-24 00:36:57 +0100 | [diff] [blame] | 248 | {"class", "iana-hardware:sensor"}, |
| 249 | {"sensor-data/value-type", "volts-AC"}, |
Tomáš Pecka | 7632360 | 2022-05-11 09:33:59 +0200 | [diff] [blame] | 250 | {"sensor-data/value-scale", "milli"}, |
Václav Kubernát | 97e5ea1 | 2021-03-24 00:36:57 +0100 | [diff] [blame] | 251 | {"sensor-data/value-precision", "0"}, |
Tomáš Pecka | 5f07eea | 2023-12-11 15:23:01 +0100 | [diff] [blame] | 252 | }; |
Tomáš Pecka | 77e09c2 | 2023-05-04 20:39:57 +0200 | [diff] [blame] | 253 | template <> |
| 254 | const DataTree sysfsStaticData<SensorType::VoltageDC> = { |
Václav Kubernát | 97e5ea1 | 2021-03-24 00:36:57 +0100 | [diff] [blame] | 255 | {"class", "iana-hardware:sensor"}, |
| 256 | {"sensor-data/value-type", "volts-DC"}, |
Tomáš Pecka | 7632360 | 2022-05-11 09:33:59 +0200 | [diff] [blame] | 257 | {"sensor-data/value-scale", "milli"}, |
Václav Kubernát | 97e5ea1 | 2021-03-24 00:36:57 +0100 | [diff] [blame] | 258 | {"sensor-data/value-precision", "0"}, |
Tomáš Pecka | 5f07eea | 2023-12-11 15:23:01 +0100 | [diff] [blame] | 259 | }; |
Václav Kubernát | 6c17d0a | 2021-03-29 04:55:31 +0200 | [diff] [blame] | 260 | |
| 261 | template <SensorType TYPE> |
Tomáš Pecka | 4886db2 | 2023-05-10 10:46:15 +0200 | [diff] [blame] | 262 | SysfsValue<TYPE>::SysfsValue(std::string componentName, std::optional<std::string> parent, std::shared_ptr<sysfs::HWMon> hwmon, int sysfsChannelNr, Thresholds<int64_t> thresholds) |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 263 | : DataReader(std::move(componentName), std::move(parent)) |
| 264 | , m_hwmon(std::move(hwmon)) |
Václav Kubernát | 6c17d0a | 2021-03-29 04:55:31 +0200 | [diff] [blame] | 265 | , m_sysfsFile(getSysfsFilename(TYPE, sysfsChannelNr)) |
Tomáš Pecka | 4886db2 | 2023-05-10 10:46:15 +0200 | [diff] [blame] | 266 | , m_thresholds(std::move(thresholds)) |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 267 | { |
| 268 | addComponent(m_staticData, |
| 269 | m_componentName, |
| 270 | m_parent, |
Václav Kubernát | 6c17d0a | 2021-03-29 04:55:31 +0200 | [diff] [blame] | 271 | sysfsStaticData<TYPE>); |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 272 | } |
| 273 | |
Václav Kubernát | 6c17d0a | 2021-03-29 04:55:31 +0200 | [diff] [blame] | 274 | template <SensorType TYPE> |
| 275 | DataTree SysfsValue<TYPE>::operator()() const |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 276 | { |
| 277 | DataTree res(m_staticData); |
| 278 | |
Václav Kubernát | 0dee6b9 | 2021-04-13 09:14:04 +0200 | [diff] [blame] | 279 | int64_t sensorValue = m_hwmon->attribute(m_sysfsFile); |
Tomáš Pecka | 655062c | 2023-12-11 15:37:58 +0100 | [diff] [blame^] | 280 | addSensorValue(res, m_componentName, sensorValue); |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 281 | |
| 282 | return res; |
| 283 | } |
| 284 | |
Tomáš Pecka | 4886db2 | 2023-05-10 10:46:15 +0200 | [diff] [blame] | 285 | template <SensorType TYPE> |
| 286 | ThresholdsBySensorPath SysfsValue<TYPE>::thresholds() const |
| 287 | { |
| 288 | return {{xpathForComponent(m_componentName) + "sensor-data/value", m_thresholds}}; |
| 289 | } |
| 290 | |
Václav Kubernát | 97e5ea1 | 2021-03-24 00:36:57 +0100 | [diff] [blame] | 291 | template struct SysfsValue<SensorType::Current>; |
| 292 | template struct SysfsValue<SensorType::Power>; |
Václav Kubernát | 6c17d0a | 2021-03-29 04:55:31 +0200 | [diff] [blame] | 293 | template struct SysfsValue<SensorType::Temperature>; |
Václav Kubernát | 97e5ea1 | 2021-03-24 00:36:57 +0100 | [diff] [blame] | 294 | template struct SysfsValue<SensorType::VoltageAC>; |
| 295 | template struct SysfsValue<SensorType::VoltageDC>; |
Václav Kubernát | 6c17d0a | 2021-03-29 04:55:31 +0200 | [diff] [blame] | 296 | |
Tomáš Pecka | 4886db2 | 2023-05-10 10:46:15 +0200 | [diff] [blame] | 297 | EMMC::EMMC(std::string componentName, std::optional<std::string> parent, std::shared_ptr<sysfs::EMMC> emmc, Thresholds<int64_t> thresholds) |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 298 | : DataReader(std::move(componentName), std::move(parent)) |
| 299 | , m_emmc(std::move(emmc)) |
Tomáš Pecka | 4886db2 | 2023-05-10 10:46:15 +0200 | [diff] [blame] | 300 | , m_thresholds(std::move(thresholds)) |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 301 | { |
| 302 | auto emmcAttrs = m_emmc->attributes(); |
| 303 | |
| 304 | // date is specified in MM/YYYY format (source: kernel core/mmc.c) and mfg-date is unfortunately of type yang:date-and-time |
| 305 | std::string mfgDate = emmcAttrs.at("date"); |
Tomáš Pecka | f1cba74 | 2023-05-03 16:26:37 +0200 | [diff] [blame] | 306 | std::chrono::year_month_day calendarDate( |
| 307 | std::chrono::year(std::stoi(mfgDate.substr(3, 4))), |
| 308 | std::chrono::month(std::stoi(mfgDate.substr(0, 2))), |
| 309 | std::chrono::day(1)); |
| 310 | mfgDate = velia::utils::yangTimeFormat(std::chrono::sys_days{calendarDate}); |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 311 | |
| 312 | addComponent(m_staticData, |
| 313 | m_componentName, |
| 314 | m_parent, |
Tomáš Pecka | 77e09c2 | 2023-05-04 20:39:57 +0200 | [diff] [blame] | 315 | DataTree{ |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 316 | {"class", "iana-hardware:module"}, |
| 317 | {"mfg-date", mfgDate}, |
| 318 | {"serial-num", emmcAttrs.at("serial")}, |
| 319 | {"model-name", emmcAttrs.at("name")}, |
| 320 | }); |
| 321 | |
| 322 | addComponent(m_staticData, |
| 323 | m_componentName + ":lifetime", |
| 324 | m_componentName, |
Tomáš Pecka | 77e09c2 | 2023-05-04 20:39:57 +0200 | [diff] [blame] | 325 | DataTree{ |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 326 | {"class", "iana-hardware:sensor"}, |
| 327 | {"sensor-data/value-type", "other"}, |
| 328 | {"sensor-data/value-scale", "units"}, |
| 329 | {"sensor-data/value-precision", "0"}, |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 330 | {"sensor-data/units-display", "percent"s}, |
| 331 | }); |
| 332 | } |
| 333 | |
| 334 | DataTree EMMC::operator()() const |
| 335 | { |
| 336 | DataTree res(m_staticData); |
| 337 | |
| 338 | auto emmcAttrs = m_emmc->attributes(); |
| 339 | addSensorValue(res, m_componentName + ":lifetime", emmcAttrs.at("life_time")); |
| 340 | |
| 341 | return res; |
| 342 | } |
Tomáš Pecka | 2a4c9f6 | 2023-03-26 10:54:57 +0200 | [diff] [blame] | 343 | |
Tomáš Pecka | 4886db2 | 2023-05-10 10:46:15 +0200 | [diff] [blame] | 344 | ThresholdsBySensorPath EMMC::thresholds() const |
Tomáš Pecka | 2a4c9f6 | 2023-03-26 10:54:57 +0200 | [diff] [blame] | 345 | { |
Tomáš Pecka | 4886db2 | 2023-05-10 10:46:15 +0200 | [diff] [blame] | 346 | return {{xpathForComponent(m_componentName + ":lifetime") + "sensor-data/value", m_thresholds}}; |
Tomáš Pecka | 2a4c9f6 | 2023-03-26 10:54:57 +0200 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | DataTree Group::operator()() const |
| 350 | { |
| 351 | DataTree res; |
| 352 | for (const auto& reader : m_readers) { |
| 353 | res.merge(reader()); |
| 354 | } |
| 355 | return res; |
| 356 | } |
| 357 | |
Tomáš Pecka | 4886db2 | 2023-05-10 10:46:15 +0200 | [diff] [blame] | 358 | ThresholdsBySensorPath Group::thresholds() const |
| 359 | { |
| 360 | return m_thresholds; |
| 361 | } |
Tomáš Pecka | 339bc67 | 2020-11-11 15:59:03 +0100 | [diff] [blame] | 362 | } |
| 363 | } |