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 | |
| 7 | enum class SensorType |
| 8 | { |
| 9 | tempSensor, |
| 10 | currSensor, |
| 11 | powerSensor, |
| 12 | voltSensor |
| 13 | }; |
| 14 | |
| 15 | class PSUSensor : public Sensor |
| 16 | { |
| 17 | public: |
| 18 | PSUSensor(const std::string& path, const std::string& objectType, |
| 19 | sdbusplus::asio::object_server& objectServer, |
| 20 | std::shared_ptr<sdbusplus::asio::connection>& conn, |
| 21 | boost::asio::io_service& io, const std::string& sensorName, |
| 22 | std::vector<thresholds::Threshold>&& thresholds, |
| 23 | const std::string& sensorConfiguration, |
| 24 | std::string& sensorTypeName, unsigned int factor, double max, |
| 25 | double min); |
| 26 | ~PSUSensor(); |
| 27 | |
| 28 | private: |
| 29 | sdbusplus::asio::object_server& objServer; |
| 30 | boost::asio::posix::stream_descriptor inputDev; |
| 31 | boost::asio::deadline_timer waitTimer; |
| 32 | boost::asio::streambuf readBuf; |
| 33 | int errCount; |
| 34 | unsigned int sensorFactor; |
| 35 | void setupRead(void); |
| 36 | void handleResponse(const boost::system::error_code& err); |
| 37 | void checkThresholds(void) override; |
| 38 | |
| 39 | static constexpr unsigned int sensorPollMs = 500; |
| 40 | static constexpr size_t warnAfterErrorCount = 10; |
| 41 | }; |
| 42 | |
| 43 | class PSUProperty |
| 44 | { |
| 45 | public: |
| 46 | PSUProperty(std::string name, double max, double min, unsigned int factor) : |
| 47 | sensorTypeName(name), maxReading(max), minReading(min), |
| 48 | sensorScaleFactor(factor) |
| 49 | { |
| 50 | } |
| 51 | ~PSUProperty() = default; |
| 52 | |
| 53 | std::string sensorTypeName; |
| 54 | double maxReading; |
| 55 | double minReading; |
| 56 | unsigned int sensorScaleFactor; |
| 57 | }; |