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" |
Ed Tanous | 18b6186 | 2025-01-30 10:56:28 -0800 | [diff] [blame] | 5 | #include "Utils.hpp" |
Andrew Jeffery | e73bd0a | 2023-01-25 10:39:57 +1030 | [diff] [blame] | 6 | #include "sensor.hpp" |
| 7 | |
Ed Tanous | 18b6186 | 2025-01-30 10:56:28 -0800 | [diff] [blame] | 8 | #include <boost/asio/io_context.hpp> |
Zev Weiss | d1c8f44 | 2022-07-29 11:54:41 -0700 | [diff] [blame] | 9 | #include <boost/asio/random_access_file.hpp> |
Ed Tanous | 18b6186 | 2025-01-30 10:56:28 -0800 | [diff] [blame] | 10 | #include <boost/asio/steady_timer.hpp> |
| 11 | #include <sdbusplus/asio/connection.hpp> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 12 | #include <sdbusplus/asio/object_server.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 13 | |
Ed Tanous | 18b6186 | 2025-01-30 10:56:28 -0800 | [diff] [blame] | 14 | #include <array> |
| 15 | #include <cstddef> |
| 16 | #include <memory> |
Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 17 | #include <string> |
| 18 | #include <vector> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 19 | |
Bruce Mitchell | 544e7dc | 2021-07-29 18:05:49 -0500 | [diff] [blame] | 20 | struct SensorParams |
| 21 | { |
| 22 | double minValue; |
| 23 | double maxValue; |
| 24 | double offsetValue; |
| 25 | double scaleValue; |
| 26 | std::string units; |
| 27 | std::string typeName; |
| 28 | }; |
| 29 | |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 30 | class HwmonTempSensor : |
| 31 | public Sensor, |
| 32 | public std::enable_shared_from_this<HwmonTempSensor> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 33 | { |
| 34 | public: |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 35 | HwmonTempSensor(const std::string& path, const std::string& objectType, |
| 36 | sdbusplus::asio::object_server& objectServer, |
| 37 | std::shared_ptr<sdbusplus::asio::connection>& conn, |
Ed Tanous | 1f97863 | 2023-02-28 18:16:39 -0800 | [diff] [blame] | 38 | boost::asio::io_context& io, const std::string& sensorName, |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 39 | std::vector<thresholds::Threshold>&& thresholds, |
Bruce Mitchell | 544e7dc | 2021-07-29 18:05:49 -0500 | [diff] [blame] | 40 | const struct SensorParams& thisSensorParameters, |
Ed Tanous | 2049bd2 | 2022-07-09 07:20:26 -0700 | [diff] [blame] | 41 | float pollRate, const std::string& sensorConfiguration, |
Zev Weiss | a1456c4 | 2022-07-18 16:59:35 -0700 | [diff] [blame] | 42 | PowerState powerState, |
| 43 | const std::shared_ptr<I2CDevice>& i2cDevice); |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 44 | ~HwmonTempSensor() override; |
Ed Tanous | 201a101 | 2024-04-03 18:07:28 -0700 | [diff] [blame] | 45 | void setupRead(); |
Zev Weiss | a1456c4 | 2022-07-18 16:59:35 -0700 | [diff] [blame] | 46 | void activate(const std::string& newPath, |
| 47 | const std::shared_ptr<I2CDevice>& newI2CDevice); |
Ed Tanous | 201a101 | 2024-04-03 18:07:28 -0700 | [diff] [blame] | 48 | void deactivate(); |
| 49 | bool isActive(); |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 50 | |
Zev Weiss | 7627c86 | 2022-11-17 14:23:04 -0800 | [diff] [blame] | 51 | std::shared_ptr<I2CDevice> getI2CDevice() const |
| 52 | { |
| 53 | return i2cDevice; |
| 54 | } |
| 55 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 56 | private: |
Zev Weiss | d1c8f44 | 2022-07-29 11:54:41 -0700 | [diff] [blame] | 57 | // Ordering is important here; readBuf is first so that it's not destroyed |
| 58 | // while async operations from other member fields might still be using it. |
| 59 | std::array<char, 128> readBuf{}; |
Zev Weiss | a1456c4 | 2022-07-18 16:59:35 -0700 | [diff] [blame] | 60 | std::shared_ptr<I2CDevice> i2cDevice; |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 61 | sdbusplus::asio::object_server& objServer; |
Zev Weiss | d1c8f44 | 2022-07-29 11:54:41 -0700 | [diff] [blame] | 62 | boost::asio::random_access_file inputDev; |
Ed Tanous | 9b4a20e | 2022-09-06 08:47:11 -0700 | [diff] [blame] | 63 | boost::asio::steady_timer waitTimer; |
James Feist | 930fcde | 2019-05-28 12:58:43 -0700 | [diff] [blame] | 64 | std::string path; |
Bruce Mitchell | 544e7dc | 2021-07-29 18:05:49 -0500 | [diff] [blame] | 65 | double offsetValue; |
| 66 | double scaleValue; |
Jeff Lin | 87bc67f | 2020-12-04 20:58:01 +0800 | [diff] [blame] | 67 | unsigned int sensorPollMs; |
Yong Li | f3fd191 | 2020-03-25 21:35:23 +0800 | [diff] [blame] | 68 | |
Zev Weiss | d1c8f44 | 2022-07-29 11:54:41 -0700 | [diff] [blame] | 69 | void handleResponse(const boost::system::error_code& err, size_t bytesRead); |
Konstantin Aladyshev | a734594 | 2021-04-28 17:09:02 +0300 | [diff] [blame] | 70 | void restartRead(); |
Ed Tanous | 201a101 | 2024-04-03 18:07:28 -0700 | [diff] [blame] | 71 | void checkThresholds() override; |
Patrick Venture | ca44b2f | 2019-10-31 11:02:26 -0700 | [diff] [blame] | 72 | }; |