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