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