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, |
| 22 | std::string& sensorTypeName, unsigned int factor, double max, |
Cheng C Yang | 6b1247a | 2020-03-09 23:48:39 +0800 | [diff] [blame] | 23 | double min, const std::string& label, size_t tSize); |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 24 | ~PSUSensor() override; |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 25 | void setupRead(void); |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 26 | |
| 27 | private: |
| 28 | sdbusplus::asio::object_server& objServer; |
| 29 | boost::asio::posix::stream_descriptor inputDev; |
| 30 | boost::asio::deadline_timer waitTimer; |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame] | 31 | std::shared_ptr<boost::asio::streambuf> readBuf; |
James Feist | 930fcde | 2019-05-28 12:58:43 -0700 | [diff] [blame] | 32 | std::string path; |
Zbigniew Kurzynski | 484b9b3 | 2020-06-18 18:15:55 +0200 | [diff] [blame] | 33 | std::string pathRatedMax; |
Brad Bishop | feb19ef | 2019-11-07 18:02:16 -0500 | [diff] [blame] | 34 | std::string pathRatedMin; |
Brad Bishop | fbb44ad | 2019-11-08 09:42:37 -0500 | [diff] [blame] | 35 | size_t errCount; |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 36 | unsigned int sensorFactor; |
Zbigniew Kurzynski | 484b9b3 | 2020-06-18 18:15:55 +0200 | [diff] [blame] | 37 | uint8_t minMaxReadCounter; |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 38 | void handleResponse(const boost::system::error_code& err); |
| 39 | void checkThresholds(void) override; |
Zbigniew Kurzynski | 484b9b3 | 2020-06-18 18:15:55 +0200 | [diff] [blame] | 40 | void updateMinMaxValues(void); |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 41 | |
Cheng C Yang | a97f134 | 2020-02-11 15:10:41 +0800 | [diff] [blame] | 42 | int fd; |
| 43 | static constexpr unsigned int sensorPollMs = 1000; |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 44 | static constexpr size_t warnAfterErrorCount = 10; |
| 45 | }; |
| 46 | |
| 47 | class PSUProperty |
| 48 | { |
| 49 | public: |
| 50 | PSUProperty(std::string name, double max, double min, unsigned int factor) : |
Ed Tanous | 8a57ec0 | 2020-10-09 12:46:52 -0700 | [diff] [blame] | 51 | labelTypeName(std::move(name)), maxReading(max), minReading(min), |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 52 | sensorScaleFactor(factor) |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 53 | {} |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 54 | ~PSUProperty() = default; |
| 55 | |
Cheng C Yang | e50345b | 2019-04-02 17:26:15 +0800 | [diff] [blame] | 56 | std::string labelTypeName; |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 57 | double maxReading; |
| 58 | double minReading; |
| 59 | unsigned int sensorScaleFactor; |
| 60 | }; |