| #ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_SENSORS_HWMON_TEMP_SENSOR_H_ |
| #define THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_SENSORS_HWMON_TEMP_SENSOR_H_ |
| |
| #include <cstddef> |
| #include <memory> |
| #include <optional> |
| #include <string> |
| #include <string_view> |
| #include <vector> |
| |
| #include "absl/base/thread_annotations.h" |
| #include "absl/status/statusor.h" |
| #include "absl/synchronization/mutex.h" |
| #include "boost/asio.hpp" //NOLINT: boost::asio is commonly used in BMC |
| #include "boost/circular_buffer.hpp" //NOLINT: boost is commonly used in BMC |
| #include "entity_common_config.pb.h" |
| #include "hwmon_temp_sensor_config.pb.h" |
| #include "i2c_common_config.pb.h" |
| #include "reading_range_config.pb.h" |
| #include "threshold_config.pb.h" |
| #include "tlbmc/hal/sysfs/i2c.h" |
| #include "sensor.pb.h" |
| #include "tlbmc/sensors/i2c_hwmon_based_sensor.h" |
| #include "tlbmc/sensors/sensor.h" |
| |
| namespace milotic_tlbmc { |
| class HwmonTempSensor : public I2cHwmonBasedSensor { |
| private: |
| class Token; |
| |
| public: |
| // Load the device if not already loaded and returns a list of sensors that |
| // can be used to read the temperature from the device. Note: |
| // 1. The `io_context` must run only on a single thread. |
| static absl::StatusOr<std::vector<std::shared_ptr<Sensor>>> Create( |
| const HwmonTempSensorConfig& config, |
| const std::shared_ptr<boost::asio::io_context>& io_context, |
| const I2cSysfs& i2c_sysfs, |
| std::optional<NotificationCb> on_batch_notify = std::nullopt); |
| |
| HwmonTempSensor(Token token, HwmonTempSensorType sensor_type, |
| const std::string& input_dev_path, |
| const std::string& sensor_name, |
| const I2cCommonConfig& i2c_common_config, |
| const ThresholdConfigs& threshold_configs, |
| const ReadingRangeConfigs& reading_range_configs, |
| const EntityCommonConfig& entity_common_config, |
| const std::shared_ptr<boost::asio::io_context>& io_context, |
| std::optional<NotificationCb> on_batch_notify); |
| |
| ~HwmonTempSensor() override = default; |
| |
| void HandleRefreshResult(const boost::system::error_code& error, |
| size_t bytes_read) override |
| ABSL_LOCKS_EXCLUDED(sensor_data_mutex_); |
| |
| protected: |
| HwmonTempSensor() = default; |
| |
| // Returns the driver name for the given sensor type. |
| static absl::StatusOr<std::string_view> GetDriverName( |
| HwmonTempSensorType sensor_type); |
| |
| private: |
| class Token { |
| private: |
| explicit Token() = default; |
| friend HwmonTempSensor; |
| }; |
| |
| const HwmonTempSensorType sensor_type_ = HWMON_TEMP_SENSOR_TYPE0_UNKNOWN; |
| const std::string sensor_name_; |
| const std::string board_config_name_; |
| const double scale_ = 1.0; |
| const double offset_ = 0.0; |
| }; |
| |
| } // namespace milotic_tlbmc |
| |
| #endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_SENSORS_HWMON_TEMP_SENSOR_H_ |