blob: 27041465b0492fd7fe6d55d0607cfdc9dacc1109 [file] [log] [blame]
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -05001#pragma once
2
Brandon Kim9cf85622019-06-19 12:05:08 -07003#include "config.h"
4
Patrick Venture46470a32018-09-07 19:26:25 -07005#include "sensorhandler.hpp"
Patrick Venture0b02be92018-08-31 11:55:55 -07006
Patrick Venture586d35b2018-09-07 19:56:18 -07007#include <cmath>
Vernon Mauerye08fbff2019-04-03 09:19:34 -07008#include <ipmid/api.hpp>
Vernon Mauery33250242019-03-12 16:49:26 -07009#include <ipmid/types.hpp>
Vernon Mauery6a98fe72019-03-11 15:57:48 -070010#include <ipmid/utils.hpp>
Tony Leec5324252019-10-31 17:24:16 +080011#include <phosphor-logging/elog-errors.hpp>
12#include <phosphor-logging/log.hpp>
William A. Kennington III4c008022018-10-12 17:18:14 -070013#include <sdbusplus/message/types.hpp>
Patrick Venture0b02be92018-08-31 11:55:55 -070014
Lei YU97140502021-09-17 13:49:43 +080015#ifdef FEATURE_SENSORS_CACHE
16extern ipmi::sensor::SensorCacheMap sensorCacheMap;
17#endif
18
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050019namespace ipmi
20{
21namespace sensor
22{
23
24using Assertion = uint16_t;
25using Deassertion = uint16_t;
26using AssertionSet = std::pair<Assertion, Deassertion>;
27
28using Service = std::string;
29using Path = std::string;
30using Interface = std::string;
31
32using ServicePath = std::pair<Path, Service>;
33
34using Interfaces = std::vector<Interface>;
35
36using MapperResponseType = std::map<Path, std::map<Service, Interfaces>>;
Tony Leec5324252019-10-31 17:24:16 +080037using namespace phosphor::logging;
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050038
39/** @brief get the D-Bus service and service path
40 * @param[in] bus - The Dbus bus object
41 * @param[in] interface - interface to the service
42 * @param[in] path - interested path in the list of objects
43 * @return pair of service path and service
44 */
45ServicePath getServiceAndPath(sdbusplus::bus::bus& bus,
46 const std::string& interface,
47 const std::string& path = std::string());
48
49/** @brief Make assertion set from input data
50 * @param[in] cmdData - Input sensor data
51 * @return pair of assertion and deassertion set
52 */
53AssertionSet getAssertionSet(const SetSensorReadingReq& cmdData);
54
55/** @brief send the message to DBus
56 * @param[in] msg - message to send
57 * @return failure status in IPMI error code
58 */
Dhruvaraj Subhashchandran2a444d02017-08-07 01:45:14 -050059ipmi_ret_t updateToDbus(IpmiUpdateData& msg);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -050060
Tom Joseph816e92b2017-09-06 19:23:00 +053061namespace get
62{
63
Tom Josephb0adbcd2018-01-24 11:51:29 +053064/** @brief Populate sensor name from the D-Bus property associated with the
65 * sensor. In the example entry from the yaml, the name of the D-bus
66 * property "AttemptsLeft" is the sensor name.
67 *
68 * 0x07:
69 * sensorType: 195
70 * path: /xyz/openbmc_project/state/host0
71 * sensorReadingType: 0x6F
72 * serviceInterface: org.freedesktop.DBus.Properties
73 * readingType: readingAssertion
74 * sensorNamePattern: nameProperty
75 * interfaces:
76 * xyz.openbmc_project.Control.Boot.RebootAttempts:
77 * AttemptsLeft:
78 * Offsets:
79 * 0xFF:
80 * type: uint32_t
81 *
82 *
83 * @param[in] sensorInfo - Dbus info related to sensor.
84 *
85 * @return On success return the sensor name for the sensor.
86 */
87inline SensorName nameProperty(const Info& sensorInfo)
88{
89 return sensorInfo.propertyInterfaces.begin()->second.begin()->first;
90}
91
92/** @brief Populate sensor name from the D-Bus object associated with the
93 * sensor. If the object path is /system/chassis/motherboard/dimm0 then
94 * the leaf dimm0 is considered as the sensor name.
95 *
96 * @param[in] sensorInfo - Dbus info related to sensor.
97 *
98 * @return On success return the sensor name for the sensor.
99 */
100inline SensorName nameLeaf(const Info& sensorInfo)
101{
102 return sensorInfo.sensorPath.substr(
Patrick Venture0b02be92018-08-31 11:55:55 -0700103 sensorInfo.sensorPath.find_last_of('/') + 1,
104 sensorInfo.sensorPath.length());
Tom Josephb0adbcd2018-01-24 11:51:29 +0530105}
106
107/** @brief Populate sensor name from the D-Bus object associated with the
Lotus Xu2101a442020-12-24 16:01:56 +0800108 * sensor and the property.
109 * If the object path is /xyz/openbmc_project/inventory/Fan0 and
110 * the property is Present, the leaf Fan0 and the Property is
111 * joined to Fan0_Present as the sensor name.
112 *
113 * @param[in] sensorInfo - Dbus info related to sensor.
114 *
115 * @return On success return the sensor name for the sensor.
116 */
117inline SensorName nameLeafProperty(const Info& sensorInfo)
118{
119 return nameLeaf(sensorInfo) + "_" + nameProperty(sensorInfo);
120}
121
122/** @brief Populate sensor name from the D-Bus object associated with the
Tom Josephb0adbcd2018-01-24 11:51:29 +0530123 * sensor. If the object path is /system/chassis/motherboard/cpu0/core0
124 * then the sensor name is cpu0_core0. The leaf and the parent is put
125 * together to get the sensor name.
126 *
127 * @param[in] sensorInfo - Dbus info related to sensor.
128 *
129 * @return On success return the sensor name for the sensor.
130 */
131SensorName nameParentLeaf(const Info& sensorInfo);
132
Tom Joseph816e92b2017-09-06 19:23:00 +0530133/**
134 * @brief Helper function to map the dbus info to sensor's assertion status
135 * for the get sensor reading command.
136 *
137 * @param[in] sensorInfo - Dbus info related to sensor.
138 * @param[in] path - Dbus object path.
139 * @param[in] interface - Dbus interface.
140 *
141 * @return Response for get sensor reading command.
142 */
143GetSensorResponse mapDbusToAssertion(const Info& sensorInfo,
144 const InstancePath& path,
145 const DbusInterface& interface);
146
Lei YU8c2c0482021-09-16 17:28:28 +0800147#ifndef FEATURE_SENSORS_CACHE
Tom Joseph816e92b2017-09-06 19:23:00 +0530148/**
149 * @brief Map the Dbus info to sensor's assertion status in the Get sensor
150 * reading command response.
151 *
152 * @param[in] sensorInfo - Dbus info related to sensor.
153 *
154 * @return Response for get sensor reading command.
155 */
156GetSensorResponse assertion(const Info& sensorInfo);
157
Tom Josephe4014fc2017-09-06 23:57:36 +0530158/**
159 * @brief Maps the Dbus info to the reading field in the Get sensor reading
160 * command response.
161 *
162 * @param[in] sensorInfo - Dbus info related to sensor.
163 *
164 * @return Response for get sensor reading command.
165 */
166GetSensorResponse eventdata2(const Info& sensorInfo);
167
Tom Joseph295f17e2017-09-07 00:09:46 +0530168/**
169 * @brief readingAssertion is a case where the entire assertion state field
170 * serves as the sensor value.
171 *
172 * @tparam T - type of the dbus property related to sensor.
173 * @param[in] sensorInfo - Dbus info related to sensor.
174 *
175 * @return Response for get sensor reading command.
176 */
Patrick Venture0b02be92018-08-31 11:55:55 -0700177template <typename T>
Tom Joseph295f17e2017-09-07 00:09:46 +0530178GetSensorResponse readingAssertion(const Info& sensorInfo)
179{
180 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
Patrick Venture0b02be92018-08-31 11:55:55 -0700181 GetSensorResponse response{};
Tom Joseph295f17e2017-09-07 00:09:46 +0530182
Jeremy Kerr3dc35582020-05-17 15:47:07 +0800183 enableScanning(&response);
184
Patrick Venture0b02be92018-08-31 11:55:55 -0700185 auto service = ipmi::getService(bus, sensorInfo.sensorInterface,
Tom Joseph295f17e2017-09-07 00:09:46 +0530186 sensorInfo.sensorPath);
187
188 auto propValue = ipmi::getDbusProperty(
Patrick Venture0b02be92018-08-31 11:55:55 -0700189 bus, service, sensorInfo.sensorPath,
190 sensorInfo.propertyInterfaces.begin()->first,
191 sensorInfo.propertyInterfaces.begin()->second.begin()->first);
Tom Joseph295f17e2017-09-07 00:09:46 +0530192
Sui Chen4cc42552019-09-11 10:28:35 -0700193 setAssertionBytes(static_cast<uint16_t>(std::get<T>(propValue)), &response);
Tom Joseph295f17e2017-09-07 00:09:46 +0530194
195 return response;
196}
197
Tom Josephe05b2922017-09-07 00:43:16 +0530198/** @brief Map the Dbus info to the reading field in the Get sensor reading
199 * command response
200 *
201 * @tparam T - type of the dbus property related to sensor.
202 * @param[in] sensorInfo - Dbus info related to sensor.
203 *
204 * @return Response for get sensor reading command.
205 */
Patrick Venture0b02be92018-08-31 11:55:55 -0700206template <typename T>
Tom Josephe05b2922017-09-07 00:43:16 +0530207GetSensorResponse readingData(const Info& sensorInfo)
208{
209 sdbusplus::bus::bus bus{ipmid_get_sd_bus_connection()};
Tom Josephe05b2922017-09-07 00:43:16 +0530210
Sui Chen4cc42552019-09-11 10:28:35 -0700211 GetSensorResponse response{};
212
213 enableScanning(&response);
Tom Josephe05b2922017-09-07 00:43:16 +0530214
Patrick Venture0b02be92018-08-31 11:55:55 -0700215 auto service = ipmi::getService(bus, sensorInfo.sensorInterface,
Tom Josephe05b2922017-09-07 00:43:16 +0530216 sensorInfo.sensorPath);
217
Brandon Kim9cf85622019-06-19 12:05:08 -0700218#ifdef UPDATE_FUNCTIONAL_ON_FAIL
219 // Check the OperationalStatus interface for functional property
220 if (sensorInfo.propertyInterfaces.begin()->first ==
221 "xyz.openbmc_project.Sensor.Value")
222 {
223 bool functional = true;
224 try
225 {
226 auto funcValue = ipmi::getDbusProperty(
227 bus, service, sensorInfo.sensorPath,
228 "xyz.openbmc_project.State.Decorator.OperationalStatus",
229 "Functional");
230 functional = std::get<bool>(funcValue);
231 }
232 catch (...)
233 {
234 // No-op if Functional property could not be found since this
235 // check is only valid for Sensor.Value read for hwmonio
236 }
237 if (!functional)
238 {
239 throw SensorFunctionalError();
240 }
241 }
242#endif
243
Tom Josephe05b2922017-09-07 00:43:16 +0530244 auto propValue = ipmi::getDbusProperty(
Patrick Venture0b02be92018-08-31 11:55:55 -0700245 bus, service, sensorInfo.sensorPath,
246 sensorInfo.propertyInterfaces.begin()->first,
247 sensorInfo.propertyInterfaces.begin()->second.begin()->first);
Tom Josephe05b2922017-09-07 00:43:16 +0530248
Vernon Maueryf442e112019-04-09 11:44:36 -0700249 double value = std::get<T>(propValue) *
Patrick Venture586d35b2018-09-07 19:56:18 -0700250 std::pow(10, sensorInfo.scale - sensorInfo.exponentR);
Tony Leec5324252019-10-31 17:24:16 +0800251 int32_t rawData =
252 (value - sensorInfo.scaledOffset) / sensorInfo.coefficientM;
Tom Josephe05b2922017-09-07 00:43:16 +0530253
Tony Leec5324252019-10-31 17:24:16 +0800254 constexpr uint8_t sensorUnitsSignedBits = 2 << 6;
255 constexpr uint8_t signedDataFormat = 0x80;
256 // if sensorUnits1 [7:6] = 10b, sensor is signed
257 if ((sensorInfo.sensorUnits1 & sensorUnitsSignedBits) == signedDataFormat)
258 {
259 if (rawData > std::numeric_limits<int8_t>::max() ||
260 rawData < std::numeric_limits<int8_t>::lowest())
261 {
262 log<level::ERR>("Value out of range");
263 throw std::out_of_range("Value out of range");
264 }
265 setReading(static_cast<int8_t>(rawData), &response);
266 }
267 else
268 {
269 if (rawData > std::numeric_limits<uint8_t>::max() ||
270 rawData < std::numeric_limits<uint8_t>::lowest())
271 {
272 log<level::ERR>("Value out of range");
273 throw std::out_of_range("Value out of range");
274 }
275 setReading(static_cast<uint8_t>(rawData), &response);
276 }
Tom Josephe05b2922017-09-07 00:43:16 +0530277
Konstantin Aladyshevf93b29c2021-05-05 14:49:14 +0300278 if (!std::isfinite(value))
279 {
280 response.readingOrStateUnavailable = 1;
281 }
282
Konstantin Aladyshev778f6592021-11-02 11:28:25 +0300283 bool critAlarmHigh;
284 try
285 {
286 critAlarmHigh = std::get<bool>(ipmi::getDbusProperty(
287 bus, service, sensorInfo.sensorPath,
288 "xyz.openbmc_project.Sensor.Threshold.Critical",
289 "CriticalAlarmHigh"));
290 }
291 catch (const std::exception& e)
292 {
293 critAlarmHigh = false;
294 }
295 bool critAlarmLow;
296 try
297 {
298 critAlarmLow = std::get<bool>(ipmi::getDbusProperty(
299 bus, service, sensorInfo.sensorPath,
300 "xyz.openbmc_project.Sensor.Threshold.Critical",
301 "CriticalAlarmLow"));
302 }
303 catch (const std::exception& e)
304 {
305 critAlarmLow = false;
306 }
307 bool warningAlarmHigh;
308 try
309 {
310 warningAlarmHigh = std::get<bool>(ipmi::getDbusProperty(
311 bus, service, sensorInfo.sensorPath,
312 "xyz.openbmc_project.Sensor.Threshold.Warning",
313 "WarningAlarmHigh"));
314 }
315 catch (const std::exception& e)
316 {
317 warningAlarmHigh = false;
318 }
319 bool warningAlarmLow;
320 try
321 {
322 warningAlarmLow = std::get<bool>(ipmi::getDbusProperty(
323 bus, service, sensorInfo.sensorPath,
324 "xyz.openbmc_project.Sensor.Threshold.Warning", "WarningAlarmlow"));
325 }
326 catch (const std::exception& e)
327 {
328 warningAlarmLow = false;
329 }
330 response.thresholdLevelsStates =
331 (static_cast<uint8_t>(critAlarmHigh) << 4) |
332 (static_cast<uint8_t>(warningAlarmHigh) << 3) |
333 (static_cast<uint8_t>(warningAlarmLow) << 2) |
334 (static_cast<uint8_t>(critAlarmLow) << 1);
335
Tom Josephe05b2922017-09-07 00:43:16 +0530336 return response;
337}
338
Lei YU8c2c0482021-09-16 17:28:28 +0800339#else
340
Lei YU8c2c0482021-09-16 17:28:28 +0800341/**
342 * @brief Map the Dbus info to sensor's assertion status in the Get sensor
343 * reading command response.
344 *
345 * @param[in] id - The sensor id
346 * @param[in] sensorInfo - Dbus info related to sensor.
347 * @param[in] msg - Dbus message from match callback.
348 *
349 * @return Response for get sensor reading command.
350 */
351std::optional<GetSensorResponse> assertion(uint8_t id, const Info& sensorInfo,
352 sdbusplus::message::message& msg);
353
354/**
355 * @brief Maps the Dbus info to the reading field in the Get sensor reading
356 * command response.
357 *
358 * @param[in] id - The sensor id
359 * @param[in] sensorInfo - Dbus info related to sensor.
360 * @param[in] msg - Dbus message from match callback.
361 *
362 * @return Response for get sensor reading command.
363 */
364std::optional<GetSensorResponse> eventdata2(uint8_t id, const Info& sensorInfo,
365 sdbusplus::message::message& msg);
366
367/**
368 * @brief readingAssertion is a case where the entire assertion state field
369 * serves as the sensor value.
370 *
371 * @tparam T - type of the dbus property related to sensor.
372 * @param[in] id - The sensor id
373 * @param[in] sensorInfo - Dbus info related to sensor.
374 * @param[in] msg - Dbus message from match callback.
375 *
376 * @return Response for get sensor reading command.
377 */
378template <typename T>
379std::optional<GetSensorResponse>
380 readingAssertion(uint8_t id, const Info& sensorInfo,
381 sdbusplus::message::message& msg)
382{
383 // TODO
384 return {};
385}
386
387/** @brief Get sensor reading from the dbus message from match
388 *
389 * @tparam T - type of the dbus property related to sensor.
390 * @param[in] id - The sensor id
391 * @param[in] sensorInfo - Dbus info related to sensor.
392 * @param[in] msg - Dbus message from match callback.
393 *
394 * @return Response for get sensor reading command.
395 */
396template <typename T>
397std::optional<GetSensorResponse> readingData(uint8_t id, const Info& sensorInfo,
398 sdbusplus::message::message& msg)
399{
Lei YU97140502021-09-17 13:49:43 +0800400 std::string interfaceName;
401 std::map<std::string, ipmi::Value> properties;
402 msg.read(interfaceName);
403
404 if (interfaceName ==
405 "xyz.openbmc_project.State.Decorator.OperationalStatus")
406 {
407 msg.read(properties);
408 auto val = properties.find("Functional");
409 if (val != properties.end())
410 {
411 sensorCacheMap[id]->functional = std::get<bool>(val->second);
412 }
413 return {};
414 }
415 if (interfaceName == "xyz.openbmc_project.State.Decorator.Availability")
416 {
417 msg.read(properties);
418 auto val = properties.find("Available");
419 if (val != properties.end())
420 {
421 sensorCacheMap[id]->available = std::get<bool>(val->second);
422 }
423 return {};
424 }
425
426 if (interfaceName != sensorInfo.sensorInterface)
427 {
428 // Not the interface we need
429 return {};
430 }
431
432#ifdef UPDATE_FUNCTIONAL_ON_FAIL
433 if (sensorCacheMap[id])
434 {
435 if (!sensorCacheMap[id]->functional)
436 {
437 throw SensorFunctionalError();
438 }
439 }
440#endif
441
442 GetSensorResponse response{};
443
444 enableScanning(&response);
445
446 msg.read(properties);
447
448 auto iter = properties.find(
449 sensorInfo.propertyInterfaces.begin()->second.begin()->first);
450 if (iter == properties.end())
451 {
452 return {};
453 }
454
455 double value = std::get<T>(iter->second) *
456 std::pow(10, sensorInfo.scale - sensorInfo.exponentR);
457 int32_t rawData =
458 (value - sensorInfo.scaledOffset) / sensorInfo.coefficientM;
459
460 constexpr uint8_t sensorUnitsSignedBits = 2 << 6;
461 constexpr uint8_t signedDataFormat = 0x80;
462 // if sensorUnits1 [7:6] = 10b, sensor is signed
463 if ((sensorInfo.sensorUnits1 & sensorUnitsSignedBits) == signedDataFormat)
464 {
465 if (rawData > std::numeric_limits<int8_t>::max() ||
466 rawData < std::numeric_limits<int8_t>::lowest())
467 {
468 log<level::ERR>("Value out of range");
469 throw std::out_of_range("Value out of range");
470 }
471 setReading(static_cast<int8_t>(rawData), &response);
472 }
473 else
474 {
475 if (rawData > std::numeric_limits<uint8_t>::max() ||
476 rawData < std::numeric_limits<uint8_t>::lowest())
477 {
478 log<level::ERR>("Value out of range");
479 throw std::out_of_range("Value out of range");
480 }
481 setReading(static_cast<uint8_t>(rawData), &response);
482 }
483
484 if (!std::isfinite(value))
485 {
486 response.readingOrStateUnavailable = 1;
487 }
488
489 if (!sensorCacheMap[id].has_value())
490 {
491 sensorCacheMap[id] = SensorData{};
492 }
493 sensorCacheMap[id]->response = response;
494
495 return response;
Lei YU8c2c0482021-09-16 17:28:28 +0800496}
497
498#endif // FEATURE_SENSORS_CACHE
499
Patrick Venture0b02be92018-08-31 11:55:55 -0700500} // namespace get
Tom Joseph816e92b2017-09-06 19:23:00 +0530501
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500502namespace set
503{
504
505/** @brief Make a DBus message for a Dbus call
506 * @param[in] updateInterface - Interface name
507 * @param[in] sensorPath - Path of the sensor
508 * @param[in] command - command to be executed
509 * @param[in] sensorInterface - DBus interface of sensor
510 * @return a dbus message
511 */
512IpmiUpdateData makeDbusMsg(const std::string& updateInterface,
513 const std::string& sensorPath,
514 const std::string& command,
515 const std::string& sensorInterface);
516
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500517/** @brief Update d-bus based on assertion type sensor data
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500518 * @param[in] cmdData - input sensor data
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500519 * @param[in] sensorInfo - sensor d-bus info
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500520 * @return a IPMI error code
521 */
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500522ipmi_ret_t assertion(const SetSensorReadingReq& cmdData,
523 const Info& sensorInfo);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500524
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500525/** @brief Update d-bus based on a reading assertion
526 * @tparam T - type of d-bus property mapping this sensor
527 * @param[in] cmdData - input sensor data
528 * @param[in] sensorInfo - sensor d-bus info
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500529 * @return a IPMI error code
530 */
Patrick Venture0b02be92018-08-31 11:55:55 -0700531template <typename T>
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500532ipmi_ret_t readingAssertion(const SetSensorReadingReq& cmdData,
533 const Info& sensorInfo)
534{
Patrick Venture0b02be92018-08-31 11:55:55 -0700535 auto msg =
536 makeDbusMsg("org.freedesktop.DBus.Properties", sensorInfo.sensorPath,
537 "Set", sensorInfo.sensorInterface);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500538
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500539 const auto& interface = sensorInfo.propertyInterfaces.begin();
540 msg.append(interface->first);
541 for (const auto& property : interface->second)
542 {
543 msg.append(property.first);
Andrew Geissler6467ed22020-05-16 16:03:53 -0500544 std::variant<T> value = static_cast<T>((cmdData.assertOffset8_14 << 8) |
545 cmdData.assertOffset0_7);
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500546 msg.append(value);
547 }
548 return updateToDbus(msg);
549}
550
Emily Shaffercc941e12017-06-14 13:06:26 -0700551/** @brief Update d-bus based on a discrete reading
552 * @param[in] cmdData - input sensor data
553 * @param[in] sensorInfo - sensor d-bus info
554 * @return an IPMI error code
555 */
Patrick Venture0b02be92018-08-31 11:55:55 -0700556template <typename T>
Emily Shaffercc941e12017-06-14 13:06:26 -0700557ipmi_ret_t readingData(const SetSensorReadingReq& cmdData,
558 const Info& sensorInfo)
559{
Patrick Venture0b02be92018-08-31 11:55:55 -0700560 T raw_value =
561 (sensorInfo.coefficientM * cmdData.reading) + sensorInfo.scaledOffset;
Tom Joseph22102152018-03-02 18:46:39 +0530562
Patrick Venture586d35b2018-09-07 19:56:18 -0700563 raw_value *= std::pow(10, sensorInfo.exponentR - sensorInfo.scale);
Tom Joseph22102152018-03-02 18:46:39 +0530564
Patrick Venture0b02be92018-08-31 11:55:55 -0700565 auto msg =
566 makeDbusMsg("org.freedesktop.DBus.Properties", sensorInfo.sensorPath,
567 "Set", sensorInfo.sensorInterface);
Emily Shaffercc941e12017-06-14 13:06:26 -0700568
569 const auto& interface = sensorInfo.propertyInterfaces.begin();
570 msg.append(interface->first);
571
Emily Shaffercc941e12017-06-14 13:06:26 -0700572 for (const auto& property : interface->second)
573 {
574 msg.append(property.first);
Vernon Mauery16b86932019-05-01 08:36:11 -0700575 std::variant<T> value = raw_value;
Emily Shaffercc941e12017-06-14 13:06:26 -0700576 msg.append(value);
577 }
578 return updateToDbus(msg);
579}
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500580
581/** @brief Update d-bus based on eventdata type sensor data
582 * @param[in] cmdData - input sensor data
583 * @param[in] sensorInfo - sensor d-bus info
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500584 * @return a IPMI error code
585 */
Patrick Venture0b02be92018-08-31 11:55:55 -0700586ipmi_ret_t eventdata(const SetSensorReadingReq& cmdData, const Info& sensorInfo,
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500587 uint8_t data);
588
589/** @brief Update d-bus based on eventdata1 type sensor data
590 * @param[in] cmdData - input sensor data
591 * @param[in] sensorInfo - sensor d-bus info
592 * @return a IPMI error code
593 */
594inline ipmi_ret_t eventdata1(const SetSensorReadingReq& cmdData,
595 const Info& sensorInfo)
596{
597 return eventdata(cmdData, sensorInfo, cmdData.eventData1);
598}
599
600/** @brief Update d-bus based on eventdata2 type sensor data
601 * @param[in] cmdData - input sensor data
602 * @param[in] sensorInfo - sensor d-bus info
603 * @return a IPMI error code
604 */
605inline ipmi_ret_t eventdata2(const SetSensorReadingReq& cmdData,
606 const Info& sensorInfo)
607{
608 return eventdata(cmdData, sensorInfo, cmdData.eventData2);
609}
610
611/** @brief Update d-bus based on eventdata3 type sensor data
612 * @param[in] cmdData - input sensor data
613 * @param[in] sensorInfo - sensor d-bus info
614 * @return a IPMI error code
615 */
616inline ipmi_ret_t eventdata3(const SetSensorReadingReq& cmdData,
617 const Info& sensorInfo)
618{
619 return eventdata(cmdData, sensorInfo, cmdData.eventData3);
620}
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500621
Patrick Venture0b02be92018-08-31 11:55:55 -0700622} // namespace set
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500623
624namespace notify
625{
626
627/** @brief Make a DBus message for a Dbus call
628 * @param[in] updateInterface - Interface name
629 * @param[in] sensorPath - Path of the sensor
630 * @param[in] command - command to be executed
631 * @param[in] sensorInterface - DBus interface of sensor
632 * @return a dbus message
633 */
634IpmiUpdateData makeDbusMsg(const std::string& updateInterface,
635 const std::string& sensorPath,
636 const std::string& command,
637 const std::string& sensorInterface);
638
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500639/** @brief Update d-bus based on assertion type sensor data
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500640 * @param[in] interfaceMap - sensor interface
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500641 * @param[in] cmdData - input sensor data
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500642 * @param[in] sensorInfo - sensor d-bus info
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500643 * @return a IPMI error code
644 */
Deepak Kodihalli1bb0d382017-08-12 02:01:27 -0500645ipmi_ret_t assertion(const SetSensorReadingReq& cmdData,
646 const Info& sensorInfo);
Dhruvaraj Subhashchandrane0af7202017-07-12 06:35:20 -0500647
Patrick Venture0b02be92018-08-31 11:55:55 -0700648} // namespace notify
Tom Joseph816e92b2017-09-06 19:23:00 +0530649
650namespace inventory
651{
652
653namespace get
654{
655
656/**
657 * @brief Map the Dbus info to sensor's assertion status in the Get sensor
658 * reading command response.
659 *
660 * @param[in] sensorInfo - Dbus info related to sensor.
661 *
662 * @return Response for get sensor reading command.
663 */
664GetSensorResponse assertion(const Info& sensorInfo);
665
666} // namespace get
667
668} // namespace inventory
Patrick Venture0b02be92018-08-31 11:55:55 -0700669} // namespace sensor
670} // namespace ipmi