blob: f7ed88f4df6fee017fbb1a88434b3b8bb702d6e3 [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>
Cheng C Yang209ec562019-03-12 16:37:44 +08008
Cheng C Yang209ec562019-03-12 16:37:44 +08009class PSUSensor : public Sensor
10{
11 public:
12 PSUSensor(const std::string& path, const std::string& objectType,
13 sdbusplus::asio::object_server& objectServer,
14 std::shared_ptr<sdbusplus::asio::connection>& conn,
15 boost::asio::io_service& io, const std::string& sensorName,
16 std::vector<thresholds::Threshold>&& thresholds,
17 const std::string& sensorConfiguration,
18 std::string& sensorTypeName, unsigned int factor, double max,
19 double min);
20 ~PSUSensor();
21
22 private:
23 sdbusplus::asio::object_server& objServer;
24 boost::asio::posix::stream_descriptor inputDev;
25 boost::asio::deadline_timer waitTimer;
26 boost::asio::streambuf readBuf;
James Feist930fcde2019-05-28 12:58:43 -070027 std::string path;
Cheng C Yang209ec562019-03-12 16:37:44 +080028 int errCount;
29 unsigned int sensorFactor;
30 void setupRead(void);
31 void handleResponse(const boost::system::error_code& err);
32 void checkThresholds(void) override;
33
34 static constexpr unsigned int sensorPollMs = 500;
35 static constexpr size_t warnAfterErrorCount = 10;
36};
37
38class PSUProperty
39{
40 public:
41 PSUProperty(std::string name, double max, double min, unsigned int factor) :
Cheng C Yange50345b2019-04-02 17:26:15 +080042 labelTypeName(name), maxReading(max), minReading(min),
Cheng C Yang209ec562019-03-12 16:37:44 +080043 sensorScaleFactor(factor)
44 {
45 }
46 ~PSUProperty() = default;
47
Cheng C Yange50345b2019-04-02 17:26:15 +080048 std::string labelTypeName;
Cheng C Yang209ec562019-03-12 16:37:44 +080049 double maxReading;
50 double minReading;
51 unsigned int sensorScaleFactor;
52};