Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 3 | #include <PwmSensor.hpp> |
| 4 | #include <Thresholds.hpp> |
James Feist | 8086aba | 2020-08-25 16:00:59 -0700 | [diff] [blame] | 5 | #include <boost/asio/streambuf.hpp> |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [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 | |
| 9 | #include <memory> |
Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 10 | #include <string> |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 11 | #include <utility> |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 12 | |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 13 | class PSUSensor : public Sensor, public std::enable_shared_from_this<PSUSensor> |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 14 | { |
| 15 | public: |
| 16 | PSUSensor(const std::string& path, const std::string& objectType, |
| 17 | sdbusplus::asio::object_server& objectServer, |
| 18 | std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 19 | boost::asio::io_service& io, const std::string& sensorName, |
| 20 | std::vector<thresholds::Threshold>&& thresholds, |
| 21 | const std::string& sensorConfiguration, |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 22 | const PowerState& powerState, const std::string& sensorUnits, |
| 23 | unsigned int factor, double max, double min, double offset, |
| 24 | const std::string& label, size_t tSize, double pollRate); |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 25 | ~PSUSensor() override; |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 26 | void setupRead(void); |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 27 | |
| 28 | private: |
| 29 | sdbusplus::asio::object_server& objServer; |
| 30 | boost::asio::posix::stream_descriptor inputDev; |
| 31 | boost::asio::deadline_timer waitTimer; |
James Feist | 930fcde | 2019-05-28 12:58:43 -0700 | [diff] [blame] | 32 | std::string path; |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 33 | unsigned int sensorFactor; |
Jeff Lin | e41d52f | 2021-04-07 19:38:51 +0800 | [diff] [blame] | 34 | double sensorOffset; |
Konstantin Aladyshev | c7a1ae6 | 2021-04-30 08:50:43 +0000 | [diff] [blame] | 35 | thresholds::ThresholdTimer thresholdTimer; |
| 36 | void restartRead(); |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 37 | void handleResponse(const boost::system::error_code& err); |
| 38 | void checkThresholds(void) override; |
Lei YU | 7170a23 | 2021-02-04 16:19:27 +0800 | [diff] [blame] | 39 | unsigned int sensorPollMs = defaultSensorPollMs; |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 40 | |
Cheng C Yang | a97f134 | 2020-02-11 15:10:41 +0800 | [diff] [blame] | 41 | int fd; |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 42 | static constexpr size_t warnAfterErrorCount = 10; |
Lei YU | 7170a23 | 2021-02-04 16:19:27 +0800 | [diff] [blame] | 43 | |
| 44 | public: |
| 45 | static constexpr double defaultSensorPoll = 1.0; |
| 46 | static constexpr unsigned int defaultSensorPollMs = |
| 47 | static_cast<unsigned int>(defaultSensorPoll * 1000); |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | class PSUProperty |
| 51 | { |
| 52 | public: |
Jeff Lin | e41d52f | 2021-04-07 19:38:51 +0800 | [diff] [blame] | 53 | PSUProperty(std::string name, double max, double min, unsigned int factor, |
| 54 | double offset) : |
| 55 | labelTypeName(std::move(name)), |
| 56 | maxReading(max), minReading(min), sensorScaleFactor(factor), |
| 57 | sensorOffset(offset) |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 58 | {} |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 59 | ~PSUProperty() = default; |
| 60 | |
Cheng C Yang | e50345b | 2019-04-02 17:26:15 +0800 | [diff] [blame] | 61 | std::string labelTypeName; |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 62 | double maxReading; |
| 63 | double minReading; |
| 64 | unsigned int sensorScaleFactor; |
Jeff Lin | e41d52f | 2021-04-07 19:38:51 +0800 | [diff] [blame] | 65 | double sensorOffset; |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 66 | }; |