blob: 05590736c582a9ca43dfad275d6f6b85dfe0a852 [file] [log] [blame]
Cheng C Yang209ec562019-03-12 16:37:44 +08001#pragma once
2
Ed Tanous8a57ec02020-10-09 12:46:52 -07003#include <PwmSensor.hpp>
4#include <Thresholds.hpp>
James Feist8086aba2020-08-25 16:00:59 -07005#include <boost/asio/streambuf.hpp>
Cheng C Yang209ec562019-03-12 16:37:44 +08006#include <sdbusplus/asio/object_server.hpp>
Ed Tanous8a57ec02020-10-09 12:46:52 -07007#include <sensor.hpp>
James Feist38fb5982020-05-28 10:09:54 -07008
9#include <memory>
Patrick Venturefd6ba732019-10-31 14:27:39 -070010#include <string>
Ed Tanous8a57ec02020-10-09 12:46:52 -070011#include <utility>
Cheng C Yang209ec562019-03-12 16:37:44 +080012
Yong Libf8b1da2020-04-15 16:32:50 +080013class PSUSensor : public Sensor, public std::enable_shared_from_this<PSUSensor>
Cheng C Yang209ec562019-03-12 16:37:44 +080014{
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 Yang6b1247a2020-03-09 23:48:39 +080023 double min, const std::string& label, size_t tSize);
Ed Tanous8a57ec02020-10-09 12:46:52 -070024 ~PSUSensor() override;
Yong Libf8b1da2020-04-15 16:32:50 +080025 void setupRead(void);
Cheng C Yang209ec562019-03-12 16:37:44 +080026
27 private:
28 sdbusplus::asio::object_server& objServer;
29 boost::asio::posix::stream_descriptor inputDev;
30 boost::asio::deadline_timer waitTimer;
Yong Libf8b1da2020-04-15 16:32:50 +080031 std::shared_ptr<boost::asio::streambuf> readBuf;
James Feist930fcde2019-05-28 12:58:43 -070032 std::string path;
Zbigniew Kurzynski484b9b32020-06-18 18:15:55 +020033 std::string pathRatedMax;
Brad Bishopfeb19ef2019-11-07 18:02:16 -050034 std::string pathRatedMin;
Brad Bishopfbb44ad2019-11-08 09:42:37 -050035 size_t errCount;
Cheng C Yang209ec562019-03-12 16:37:44 +080036 unsigned int sensorFactor;
Zbigniew Kurzynski484b9b32020-06-18 18:15:55 +020037 uint8_t minMaxReadCounter;
Cheng C Yang209ec562019-03-12 16:37:44 +080038 void handleResponse(const boost::system::error_code& err);
39 void checkThresholds(void) override;
Zbigniew Kurzynski484b9b32020-06-18 18:15:55 +020040 void updateMinMaxValues(void);
Cheng C Yang209ec562019-03-12 16:37:44 +080041
Cheng C Yanga97f1342020-02-11 15:10:41 +080042 int fd;
43 static constexpr unsigned int sensorPollMs = 1000;
Cheng C Yang209ec562019-03-12 16:37:44 +080044 static constexpr size_t warnAfterErrorCount = 10;
45};
46
47class PSUProperty
48{
49 public:
50 PSUProperty(std::string name, double max, double min, unsigned int factor) :
Ed Tanous8a57ec02020-10-09 12:46:52 -070051 labelTypeName(std::move(name)), maxReading(max), minReading(min),
Cheng C Yang209ec562019-03-12 16:37:44 +080052 sensorScaleFactor(factor)
James Feist38fb5982020-05-28 10:09:54 -070053 {}
Cheng C Yang209ec562019-03-12 16:37:44 +080054 ~PSUProperty() = default;
55
Cheng C Yange50345b2019-04-02 17:26:15 +080056 std::string labelTypeName;
Cheng C Yang209ec562019-03-12 16:37:44 +080057 double maxReading;
58 double minReading;
59 unsigned int sensorScaleFactor;
60};