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