#pragma once #include "DeviceMgmt.hpp" #include "Thresholds.hpp" #include "sensor.hpp" #include #include #include #include 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 { public: HwmonTempSensor(const std::string& path, const std::string& objectType, sdbusplus::asio::object_server& objectServer, std::shared_ptr& conn, boost::asio::io_context& io, const std::string& sensorName, std::vector&& thresholds, const struct SensorParams& thisSensorParameters, float pollRate, const std::string& sensorConfiguration, PowerState powerState, const std::shared_ptr& i2cDevice); ~HwmonTempSensor() override; void setupRead(); void activate(const std::string& newPath, const std::shared_ptr& newI2CDevice); void deactivate(); bool isActive(); std::shared_ptr 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 readBuf{}; std::shared_ptr 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; };