blob: af275ecf8cb038e19dfbb1526f2ded077f36a298 [file] [log] [blame]
James Feist6714a252018-09-10 15:26:18 -07001#pragma once
2
Ed Tanous8a57ec02020-10-09 12:46:52 -07003#include <Thresholds.hpp>
Zev Weissd1c8f442022-07-29 11:54:41 -07004#include <boost/asio/random_access_file.hpp>
James Feist6714a252018-09-10 15:26:18 -07005#include <sdbusplus/asio/object_server.hpp>
Ed Tanous8a57ec02020-10-09 12:46:52 -07006#include <sensor.hpp>
James Feist38fb5982020-05-28 10:09:54 -07007
Patrick Venturefd6ba732019-10-31 14:27:39 -07008#include <string>
9#include <vector>
James Feist6714a252018-09-10 15:26:18 -070010
Bruce Mitchell544e7dc2021-07-29 18:05:49 -050011struct SensorParams
12{
13 double minValue;
14 double maxValue;
15 double offsetValue;
16 double scaleValue;
17 std::string units;
18 std::string typeName;
19};
20
James Feist38fb5982020-05-28 10:09:54 -070021class HwmonTempSensor :
22 public Sensor,
23 public std::enable_shared_from_this<HwmonTempSensor>
James Feist6714a252018-09-10 15:26:18 -070024{
25 public:
James Feistd8705872019-02-08 13:26:09 -080026 HwmonTempSensor(const std::string& path, const std::string& objectType,
27 sdbusplus::asio::object_server& objectServer,
28 std::shared_ptr<sdbusplus::asio::connection>& conn,
Bruce Mitchell5cf0f992021-07-30 08:49:12 -050029 boost::asio::io_service& io, const std::string& sensorName,
James Feistd8705872019-02-08 13:26:09 -080030 std::vector<thresholds::Threshold>&& thresholds,
Bruce Mitchell544e7dc2021-07-29 18:05:49 -050031 const struct SensorParams& thisSensorParameters,
Ed Tanous2049bd22022-07-09 07:20:26 -070032 float pollRate, const std::string& sensorConfiguration,
33 PowerState powerState);
Ed Tanous8a57ec02020-10-09 12:46:52 -070034 ~HwmonTempSensor() override;
Yong Lif3fd1912020-03-25 21:35:23 +080035 void setupRead(void);
James Feist6714a252018-09-10 15:26:18 -070036
37 private:
Zev Weissd1c8f442022-07-29 11:54:41 -070038 // Ordering is important here; readBuf is first so that it's not destroyed
39 // while async operations from other member fields might still be using it.
40 std::array<char, 128> readBuf{};
James Feistd8705872019-02-08 13:26:09 -080041 sdbusplus::asio::object_server& objServer;
Zev Weissd1c8f442022-07-29 11:54:41 -070042 boost::asio::random_access_file inputDev;
Ed Tanous9b4a20e2022-09-06 08:47:11 -070043 boost::asio::steady_timer waitTimer;
James Feist930fcde2019-05-28 12:58:43 -070044 std::string path;
Bruce Mitchell544e7dc2021-07-29 18:05:49 -050045 double offsetValue;
46 double scaleValue;
Jeff Lin87bc67f2020-12-04 20:58:01 +080047 unsigned int sensorPollMs;
Yong Lif3fd1912020-03-25 21:35:23 +080048
Zev Weissd1c8f442022-07-29 11:54:41 -070049 void handleResponse(const boost::system::error_code& err, size_t bytesRead);
Konstantin Aladysheva7345942021-04-28 17:09:02 +030050 void restartRead();
James Feistce3fca42018-11-21 12:58:24 -080051 void checkThresholds(void) override;
Patrick Ventureca44b2f2019-10-31 11:02:26 -070052};