| #pragma once |
| |
| #include "DeviceMgmt.hpp" |
| #include "Thresholds.hpp" |
| #include "sensor.hpp" |
| |
| #include <boost/asio/random_access_file.hpp> |
| #include <sdbusplus/asio/object_server.hpp> |
| |
| #include <string> |
| #include <vector> |
| |
| struct SensorParams |
| { |
| double minValue; |
| double maxValue; |
| double offsetValue; |
| double scaleValue; |
| std::string units; |
| std::string typeName; |
| }; |
| |
| class HwmonTempSensor : |
| public Sensor, |
| public std::enable_shared_from_this<HwmonTempSensor> |
| { |
| public: |
| HwmonTempSensor(const std::string& path, const std::string& objectType, |
| sdbusplus::asio::object_server& objectServer, |
| std::shared_ptr<sdbusplus::asio::connection>& conn, |
| boost::asio::io_context& io, const std::string& sensorName, |
| std::vector<thresholds::Threshold>&& thresholds, |
| const struct SensorParams& thisSensorParameters, |
| float pollRate, const std::string& sensorConfiguration, |
| PowerState powerState, |
| const std::shared_ptr<I2CDevice>& i2cDevice); |
| ~HwmonTempSensor() override; |
| void setupRead(); |
| void activate(const std::string& newPath, |
| const std::shared_ptr<I2CDevice>& newI2CDevice); |
| void deactivate(); |
| bool isActive(); |
| |
| std::shared_ptr<I2CDevice> getI2CDevice() const |
| { |
| return i2cDevice; |
| } |
| |
| private: |
| // Ordering is important here; readBuf is first so that it's not destroyed |
| // while async operations from other member fields might still be using it. |
| std::array<char, 128> readBuf{}; |
| std::shared_ptr<I2CDevice> i2cDevice; |
| sdbusplus::asio::object_server& objServer; |
| boost::asio::random_access_file inputDev; |
| boost::asio::steady_timer waitTimer; |
| std::string path; |
| double offsetValue; |
| double scaleValue; |
| unsigned int sensorPollMs; |
| |
| void handleResponse(const boost::system::error_code& err, size_t bytesRead); |
| void restartRead(); |
| void checkThresholds() override; |
| }; |