| #ifndef THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_SENSORS_FAN_PWM_H_ |
| #define THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_SENSORS_FAN_PWM_H_ |
| |
| #include <cstddef> |
| #include <memory> |
| #include <optional> |
| #include <string> |
| #include <vector> |
| |
| #include "absl/base/thread_annotations.h" |
| #include "absl/status/status.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 "fan_pwm_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/fan_controller.h" |
| #include "tlbmc/sensors/i2c_hwmon_based_sensor.h" |
| #include "tlbmc/sensors/sensor.h" |
| |
| namespace milotic_tlbmc { |
| |
| class FanPwm : public I2cHwmonBasedSensor { |
| private: |
| class Token; |
| |
| public: |
| // Enables the PWM if not already enabled and returns a sensor that can be |
| // used to read the PWM from the device. |
| // Note: |
| // 1. The `io_context` must run only on a single thread. |
| static absl::StatusOr<std::shared_ptr<Sensor>> Create( |
| const FanPwmConfig& config, const FanController& fan_controller, |
| const std::shared_ptr<boost::asio::io_context>& io_context, |
| const I2cSysfs& i2c_sysfs, |
| std::optional<NotificationCb> on_batch_notify = std::nullopt); |
| |
| static absl::Status EnablePwm(const boost::filesystem::path& pwm_enable_path); |
| |
| FanPwm(Token token, FanPwmType 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 ReadingTransformConfig& reading_transform_config, |
| const EntityCommonConfig& entity_common_config, |
| const std::shared_ptr<boost::asio::io_context>& io_context, |
| std::optional<NotificationCb> on_batch_notify); |
| |
| ~FanPwm() override = default; |
| |
| void HandleRefreshResult(const boost::system::error_code& error, |
| size_t bytes_read) override |
| ABSL_LOCKS_EXCLUDED(sensor_data_mutex_); |
| |
| protected: |
| FanPwm() = default; |
| |
| private: |
| class Token { |
| private: |
| explicit Token() = default; |
| friend FanPwm; |
| }; |
| |
| const FanPwmType sensor_type_ = PWM_SENSOR_TYPE_UNKNOWN; |
| const std::string sensor_name_; |
| const std::string board_config_name_; |
| }; |
| |
| } // namespace milotic_tlbmc |
| |
| #endif // THIRD_PARTY_MILOTIC_EXTERNAL_CC_TLBMC_SENSORS_FAN_PWM_H_ |