blob: 770a2869c171d14c8adff414ede9f216c14cedad [file] [log] [blame]
Thu Nguyen3c5486d2024-08-01 08:03:08 +00001#pragma once
2
3#include "libpldm/platform.h"
4#include "libpldm/pldm.h"
5
6#include "common/types.hpp"
7
8#include <sdbusplus/server/object.hpp>
9#include <xyz/openbmc_project/Association/Definitions/server.hpp>
10#include <xyz/openbmc_project/Sensor/Threshold/Critical/server.hpp>
11#include <xyz/openbmc_project/Sensor/Threshold/Warning/server.hpp>
12#include <xyz/openbmc_project/Sensor/Value/server.hpp>
13#include <xyz/openbmc_project/State/Decorator/Availability/server.hpp>
14#include <xyz/openbmc_project/State/Decorator/OperationalStatus/server.hpp>
15
16#include <string>
17
18namespace pldm
19{
20namespace platform_mc
21{
22
23using SensorUnit = sdbusplus::xyz::openbmc_project::Sensor::server::Value::Unit;
24using ValueIntf = sdbusplus::server::object_t<
25 sdbusplus::xyz::openbmc_project::Sensor::server::Value>;
26using ThresholdWarningIntf = sdbusplus::server::object_t<
27 sdbusplus::xyz::openbmc_project::Sensor::Threshold::server::Warning>;
28using ThresholdCriticalIntf = sdbusplus::server::object_t<
29 sdbusplus::xyz::openbmc_project::Sensor::Threshold::server::Critical>;
30using OperationalStatusIntf =
31 sdbusplus::server::object_t<sdbusplus::xyz::openbmc_project::State::
32 Decorator::server::OperationalStatus>;
33using AvailabilityIntf = sdbusplus::server::object_t<
34 sdbusplus::xyz::openbmc_project::State::Decorator::server::Availability>;
35using AssociationDefinitionsInft = sdbusplus::server::object_t<
36 sdbusplus::xyz::openbmc_project::Association::server::Definitions>;
37
38/**
39 * @brief NumericSensor
40 *
41 * This class handles sensor reading updated by sensor manager and export
42 * status to D-Bus interface.
43 */
44class NumericSensor
45{
46 public:
47 NumericSensor(const pldm_tid_t tid, const bool sensorDisabled,
48 std::shared_ptr<pldm_numeric_sensor_value_pdr> pdr,
49 std::string& sensorName, std::string& associationPath);
50
51 NumericSensor(const pldm_tid_t tid, const bool sensorDisabled,
52 std::shared_ptr<pldm_compact_numeric_sensor_pdr> pdr,
53 std::string& sensorName, std::string& associationPath);
54
Patrick Williams16c2a0a2024-08-16 15:20:59 -040055 ~NumericSensor() {};
Thu Nguyen3c5486d2024-08-01 08:03:08 +000056
57 /** @brief ConversionFormula is used to convert raw value to the unit
58 * specified in PDR
59 *
60 * @param[in] value - raw value
61 * @return double - converted value
62 */
63 double conversionFormula(double value);
64
65 /** @brief UnitModifier is used to apply the unit modifier specified in PDR
66 *
67 * @param[in] value - raw value
68 * @return double - converted value
69 */
70 double unitModifier(double value);
71
72 /** @brief Terminus ID which the sensor belongs to */
73 pldm_tid_t tid;
74
75 /** @brief Sensor ID */
76 uint16_t sensorId;
77
78 /** @brief The time of sensor update interval in usec */
79 uint64_t updateTime;
80
81 /** @brief sensorName */
82 std::string sensorName;
83
84 /** @brief sensorNameSpace */
85 std::string sensorNameSpace;
86
87 /** @brief indicate if sensor is polled in priority */
88 bool isPriority;
89
90 private:
91 std::unique_ptr<ValueIntf> valueIntf = nullptr;
92 std::unique_ptr<ThresholdWarningIntf> thresholdWarningIntf = nullptr;
93 std::unique_ptr<ThresholdCriticalIntf> thresholdCriticalIntf = nullptr;
94 std::unique_ptr<AvailabilityIntf> availabilityIntf = nullptr;
95 std::unique_ptr<OperationalStatusIntf> operationalStatusIntf = nullptr;
96 std::unique_ptr<AssociationDefinitionsInft> associationDefinitionsIntf =
97 nullptr;
98
99 /** @brief Amount of hysteresis associated with the sensor thresholds */
100 double hysteresis;
101
102 /** @brief The resolution of sensor in Units */
103 double resolution;
104
105 /** @brief A constant value that is added in as part of conversion process
106 * of converting a raw sensor reading to Units */
107 double offset;
108
109 /** @brief A power-of-10 multiplier for baseUnit */
110 int8_t baseUnitModifier;
111};
112} // namespace platform_mc
113} // namespace pldm