1 #pragma once
2 
3 #include "DeviceMgmt.hpp"
4 #include "Thresholds.hpp"
5 #include "sensor.hpp"
6 
7 #include <boost/asio/random_access_file.hpp>
8 #include <sdbusplus/asio/object_server.hpp>
9 
10 #include <string>
11 #include <vector>
12 
13 struct SensorParams
14 {
15     double minValue;
16     double maxValue;
17     double offsetValue;
18     double scaleValue;
19     std::string units;
20     std::string typeName;
21 };
22 
23 class HwmonTempSensor :
24     public Sensor,
25     public std::enable_shared_from_this<HwmonTempSensor>
26 {
27   public:
28     HwmonTempSensor(const std::string& path, const std::string& objectType,
29                     sdbusplus::asio::object_server& objectServer,
30                     std::shared_ptr<sdbusplus::asio::connection>& conn,
31                     boost::asio::io_context& io, const std::string& sensorName,
32                     std::vector<thresholds::Threshold>&& thresholds,
33                     const struct SensorParams& thisSensorParameters,
34                     float pollRate, const std::string& sensorConfiguration,
35                     PowerState powerState,
36                     const std::shared_ptr<I2CDevice>& i2cDevice);
37     ~HwmonTempSensor() override;
38     void setupRead();
39     void activate(const std::string& newPath,
40                   const std::shared_ptr<I2CDevice>& newI2CDevice);
41     void deactivate();
42     bool isActive();
43 
getI2CDevice() const44     std::shared_ptr<I2CDevice> getI2CDevice() const
45     {
46         return i2cDevice;
47     }
48 
49   private:
50     // Ordering is important here; readBuf is first so that it's not destroyed
51     // while async operations from other member fields might still be using it.
52     std::array<char, 128> readBuf{};
53     std::shared_ptr<I2CDevice> i2cDevice;
54     sdbusplus::asio::object_server& objServer;
55     boost::asio::random_access_file inputDev;
56     boost::asio::steady_timer waitTimer;
57     std::string path;
58     double offsetValue;
59     double scaleValue;
60     unsigned int sensorPollMs;
61 
62     void handleResponse(const boost::system::error_code& err, size_t bytesRead);
63     void restartRead();
64     void checkThresholds() override;
65 };
66