blob: 0c4edb1e3e6b8f09a13330faf765d455f02155ea [file] [log] [blame]
Cheng C Yang209ec562019-03-12 16:37:44 +08001#pragma once
2
3#include <Thresholds.hpp>
4#include <sdbusplus/asio/object_server.hpp>
5#include <sensor.hpp>
6
Cheng C Yang209ec562019-03-12 16:37:44 +08007class 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
35class PSUProperty
36{
37 public:
38 PSUProperty(std::string name, double max, double min, unsigned int factor) :
Cheng C Yange50345b2019-04-02 17:26:15 +080039 labelTypeName(name), maxReading(max), minReading(min),
Cheng C Yang209ec562019-03-12 16:37:44 +080040 sensorScaleFactor(factor)
41 {
42 }
43 ~PSUProperty() = default;
44
Cheng C Yange50345b2019-04-02 17:26:15 +080045 std::string labelTypeName;
Cheng C Yang209ec562019-03-12 16:37:44 +080046 double maxReading;
47 double minReading;
48 unsigned int sensorScaleFactor;
49};