Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | ca44b2f | 2019-10-31 11:02:26 -0700 | [diff] [blame] | 3 | #include "PwmSensor.hpp" |
| 4 | #include "Thresholds.hpp" |
| 5 | #include "sensor.hpp" |
| 6 | |
Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 7 | #include <memory> |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 8 | #include <sdbusplus/asio/object_server.hpp> |
Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 9 | #include <string> |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 10 | |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame^] | 11 | class PSUSensor : public Sensor, public std::enable_shared_from_this<PSUSensor> |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 12 | { |
| 13 | public: |
| 14 | PSUSensor(const std::string& path, const std::string& objectType, |
| 15 | sdbusplus::asio::object_server& objectServer, |
| 16 | std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 17 | boost::asio::io_service& io, const std::string& sensorName, |
| 18 | std::vector<thresholds::Threshold>&& thresholds, |
| 19 | const std::string& sensorConfiguration, |
| 20 | std::string& sensorTypeName, unsigned int factor, double max, |
Cheng C Yang | 6b1247a | 2020-03-09 23:48:39 +0800 | [diff] [blame] | 21 | double min, const std::string& label, size_t tSize); |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 22 | ~PSUSensor(); |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame^] | 23 | void setupRead(void); |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 24 | |
| 25 | private: |
| 26 | sdbusplus::asio::object_server& objServer; |
| 27 | boost::asio::posix::stream_descriptor inputDev; |
| 28 | boost::asio::deadline_timer waitTimer; |
Yong Li | bf8b1da | 2020-04-15 16:32:50 +0800 | [diff] [blame^] | 29 | std::shared_ptr<boost::asio::streambuf> readBuf; |
James Feist | 930fcde | 2019-05-28 12:58:43 -0700 | [diff] [blame] | 30 | std::string path; |
Brad Bishop | fbb44ad | 2019-11-08 09:42:37 -0500 | [diff] [blame] | 31 | size_t errCount; |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 32 | unsigned int sensorFactor; |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 33 | void handleResponse(const boost::system::error_code& err); |
| 34 | void checkThresholds(void) override; |
| 35 | |
Cheng C Yang | a97f134 | 2020-02-11 15:10:41 +0800 | [diff] [blame] | 36 | int fd; |
| 37 | static constexpr unsigned int sensorPollMs = 1000; |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 38 | static constexpr size_t warnAfterErrorCount = 10; |
| 39 | }; |
| 40 | |
| 41 | class PSUProperty |
| 42 | { |
| 43 | public: |
| 44 | PSUProperty(std::string name, double max, double min, unsigned int factor) : |
Cheng C Yang | e50345b | 2019-04-02 17:26:15 +0800 | [diff] [blame] | 45 | labelTypeName(name), maxReading(max), minReading(min), |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 46 | sensorScaleFactor(factor) |
| 47 | { |
| 48 | } |
| 49 | ~PSUProperty() = default; |
| 50 | |
Cheng C Yang | e50345b | 2019-04-02 17:26:15 +0800 | [diff] [blame] | 51 | std::string labelTypeName; |
Cheng C Yang | 209ec56 | 2019-03-12 16:37:44 +0800 | [diff] [blame] | 52 | double maxReading; |
| 53 | double minReading; |
| 54 | unsigned int sensorScaleFactor; |
| 55 | }; |