blob: b63e76770a6f18615e79c7a29738c0a91bab7c45 [file] [log] [blame]
Cheng C Yang209ec562019-03-12 16:37:44 +08001#pragma once
2
Patrick Ventureca44b2f2019-10-31 11:02:26 -07003#include "PwmSensor.hpp"
4#include "Thresholds.hpp"
5#include "sensor.hpp"
6
Cheng C Yang209ec562019-03-12 16:37:44 +08007#include <sdbusplus/asio/object_server.hpp>
James Feist38fb5982020-05-28 10:09:54 -07008
9#include <memory>
Patrick Venturefd6ba732019-10-31 14:27:39 -070010#include <string>
Cheng C Yang209ec562019-03-12 16:37:44 +080011
Yong Libf8b1da2020-04-15 16:32:50 +080012class PSUSensor : public Sensor, public std::enable_shared_from_this<PSUSensor>
Cheng C Yang209ec562019-03-12 16:37:44 +080013{
14 public:
15 PSUSensor(const std::string& path, const std::string& objectType,
16 sdbusplus::asio::object_server& objectServer,
17 std::shared_ptr<sdbusplus::asio::connection>& conn,
18 boost::asio::io_service& io, const std::string& sensorName,
19 std::vector<thresholds::Threshold>&& thresholds,
20 const std::string& sensorConfiguration,
21 std::string& sensorTypeName, unsigned int factor, double max,
Cheng C Yang6b1247a2020-03-09 23:48:39 +080022 double min, const std::string& label, size_t tSize);
Cheng C Yang209ec562019-03-12 16:37:44 +080023 ~PSUSensor();
Yong Libf8b1da2020-04-15 16:32:50 +080024 void setupRead(void);
Cheng C Yang209ec562019-03-12 16:37:44 +080025
26 private:
27 sdbusplus::asio::object_server& objServer;
28 boost::asio::posix::stream_descriptor inputDev;
29 boost::asio::deadline_timer waitTimer;
Yong Libf8b1da2020-04-15 16:32:50 +080030 std::shared_ptr<boost::asio::streambuf> readBuf;
James Feist930fcde2019-05-28 12:58:43 -070031 std::string path;
Brad Bishopfbb44ad2019-11-08 09:42:37 -050032 size_t errCount;
Cheng C Yang209ec562019-03-12 16:37:44 +080033 unsigned int sensorFactor;
Cheng C Yang209ec562019-03-12 16:37:44 +080034 void handleResponse(const boost::system::error_code& err);
35 void checkThresholds(void) override;
36
Cheng C Yanga97f1342020-02-11 15:10:41 +080037 int fd;
38 static constexpr unsigned int sensorPollMs = 1000;
Cheng C Yang209ec562019-03-12 16:37:44 +080039 static constexpr size_t warnAfterErrorCount = 10;
40};
41
42class PSUProperty
43{
44 public:
45 PSUProperty(std::string name, double max, double min, unsigned int factor) :
Cheng C Yange50345b2019-04-02 17:26:15 +080046 labelTypeName(name), maxReading(max), minReading(min),
Cheng C Yang209ec562019-03-12 16:37:44 +080047 sensorScaleFactor(factor)
James Feist38fb5982020-05-28 10:09:54 -070048 {}
Cheng C Yang209ec562019-03-12 16:37:44 +080049 ~PSUProperty() = default;
50
Cheng C Yange50345b2019-04-02 17:26:15 +080051 std::string labelTypeName;
Cheng C Yang209ec562019-03-12 16:37:44 +080052 double maxReading;
53 double minReading;
54 unsigned int sensorScaleFactor;
55};