James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Andrew Jeffery | e73bd0a | 2023-01-25 10:39:57 +1030 | [diff] [blame] | 3 | #include "DeviceMgmt.hpp" |
| 4 | #include "Thresholds.hpp" |
| 5 | #include "sensor.hpp" |
| 6 | |
Zev Weiss | d1c8f44 | 2022-07-29 11:54:41 -0700 | [diff] [blame] | 7 | #include <boost/asio/random_access_file.hpp> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 8 | #include <sdbusplus/asio/object_server.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 9 | |
Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 10 | #include <string> |
| 11 | #include <vector> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 12 | |
Bruce Mitchell | 544e7dc | 2021-07-29 18:05:49 -0500 | [diff] [blame] | 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 | |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 23 | class HwmonTempSensor : |
| 24 | public Sensor, |
| 25 | public std::enable_shared_from_this<HwmonTempSensor> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 26 | { |
| 27 | public: |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 28 | HwmonTempSensor(const std::string& path, const std::string& objectType, |
| 29 | sdbusplus::asio::object_server& objectServer, |
| 30 | std::shared_ptr<sdbusplus::asio::connection>& conn, |
Ed Tanous | 1f97863 | 2023-02-28 18:16:39 -0800 | [diff] [blame] | 31 | boost::asio::io_context& io, const std::string& sensorName, |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 32 | std::vector<thresholds::Threshold>&& thresholds, |
Bruce Mitchell | 544e7dc | 2021-07-29 18:05:49 -0500 | [diff] [blame] | 33 | const struct SensorParams& thisSensorParameters, |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 34 | float pollRate, const std::string& sensorConfiguration, |
Zev Weiss | a1456c4 | 2022-07-18 16:59:35 -0700 | [diff] [blame] | 35 | PowerState powerState, |
| 36 | const std::shared_ptr<I2CDevice>& i2cDevice); |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 37 | ~HwmonTempSensor() override; |
Yong Li | f3fd191 | 2020-03-25 21:35:23 +0800 | [diff] [blame] | 38 | void setupRead(void); |
Zev Weiss | a1456c4 | 2022-07-18 16:59:35 -0700 | [diff] [blame] | 39 | void activate(const std::string& newPath, |
| 40 | const std::shared_ptr<I2CDevice>& newI2CDevice); |
| 41 | void deactivate(void); |
| 42 | bool isActive(void); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 43 | |
Zev Weiss | 7627c86 | 2022-11-17 14:23:04 -0800 | [diff] [blame] | 44 | std::shared_ptr<I2CDevice> getI2CDevice() const |
| 45 | { |
| 46 | return i2cDevice; |
| 47 | } |
| 48 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 49 | private: |
Zev Weiss | d1c8f44 | 2022-07-29 11:54:41 -0700 | [diff] [blame] | 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{}; |
Zev Weiss | a1456c4 | 2022-07-18 16:59:35 -0700 | [diff] [blame] | 53 | std::shared_ptr<I2CDevice> i2cDevice; |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 54 | sdbusplus::asio::object_server& objServer; |
Zev Weiss | d1c8f44 | 2022-07-29 11:54:41 -0700 | [diff] [blame] | 55 | boost::asio::random_access_file inputDev; |
Ed Tanous | 9b4a20e | 2022-09-06 08:47:11 -0700 | [diff] [blame] | 56 | boost::asio::steady_timer waitTimer; |
James Feist | 930fcde | 2019-05-28 12:58:43 -0700 | [diff] [blame] | 57 | std::string path; |
Bruce Mitchell | 544e7dc | 2021-07-29 18:05:49 -0500 | [diff] [blame] | 58 | double offsetValue; |
| 59 | double scaleValue; |
Jeff Lin | 87bc67f | 2020-12-04 20:58:01 +0800 | [diff] [blame] | 60 | unsigned int sensorPollMs; |
Yong Li | f3fd191 | 2020-03-25 21:35:23 +0800 | [diff] [blame] | 61 | |
Zev Weiss | d1c8f44 | 2022-07-29 11:54:41 -0700 | [diff] [blame] | 62 | void handleResponse(const boost::system::error_code& err, size_t bytesRead); |
Konstantin Aladyshev | a734594 | 2021-04-28 17:09:02 +0300 | [diff] [blame] | 63 | void restartRead(); |
James Feist | ce3fca4 | 2018-11-21 12:58:24 -0800 | [diff] [blame] | 64 | void checkThresholds(void) override; |
Patrick Venture | ca44b2f | 2019-10-31 11:02:26 -0700 | [diff] [blame] | 65 | }; |