blob: 40be3bb1a3a5945c6d6f5998424efe49d4f28488 [file] [log] [blame]
James Feist6714a252018-09-10 15:26:18 -07001#pragma once
2
Zev Weissa1456c42022-07-18 16:59:35 -07003#include <DeviceMgmt.hpp>
Ed Tanous8a57ec02020-10-09 12:46:52 -07004#include <Thresholds.hpp>
Zev Weissd1c8f442022-07-29 11:54:41 -07005#include <boost/asio/random_access_file.hpp>
James Feist6714a252018-09-10 15:26:18 -07006#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
Patrick Venturefd6ba732019-10-31 14:27:39 -07009#include <string>
10#include <vector>
James Feist6714a252018-09-10 15:26:18 -070011
Bruce Mitchell544e7dc2021-07-29 18:05:49 -050012struct SensorParams
13{
14 double minValue;
15 double maxValue;
16 double offsetValue;
17 double scaleValue;
18 std::string units;
19 std::string typeName;
20};
21
James Feist38fb5982020-05-28 10:09:54 -070022class HwmonTempSensor :
23 public Sensor,
24 public std::enable_shared_from_this<HwmonTempSensor>
James Feist6714a252018-09-10 15:26:18 -070025{
26 public:
James Feistd8705872019-02-08 13:26:09 -080027 HwmonTempSensor(const std::string& path, const std::string& objectType,
28 sdbusplus::asio::object_server& objectServer,
29 std::shared_ptr<sdbusplus::asio::connection>& conn,
Bruce Mitchell5cf0f992021-07-30 08:49:12 -050030 boost::asio::io_service& io, const std::string& sensorName,
James Feistd8705872019-02-08 13:26:09 -080031 std::vector<thresholds::Threshold>&& thresholds,
Bruce Mitchell544e7dc2021-07-29 18:05:49 -050032 const struct SensorParams& thisSensorParameters,
Ed Tanous2049bd22022-07-09 07:20:26 -070033 float pollRate, const std::string& sensorConfiguration,
Zev Weissa1456c42022-07-18 16:59:35 -070034 PowerState powerState,
35 const std::shared_ptr<I2CDevice>& i2cDevice);
Ed Tanous8a57ec02020-10-09 12:46:52 -070036 ~HwmonTempSensor() override;
Yong Lif3fd1912020-03-25 21:35:23 +080037 void setupRead(void);
Zev Weissa1456c42022-07-18 16:59:35 -070038 void activate(const std::string& newPath,
39 const std::shared_ptr<I2CDevice>& newI2CDevice);
40 void deactivate(void);
41 bool isActive(void);
James Feist6714a252018-09-10 15:26:18 -070042
Zev Weiss7627c862022-11-17 14:23:04 -080043 std::shared_ptr<I2CDevice> getI2CDevice() const
44 {
45 return i2cDevice;
46 }
47
James Feist6714a252018-09-10 15:26:18 -070048 private:
Zev Weissd1c8f442022-07-29 11:54:41 -070049 // Ordering is important here; readBuf is first so that it's not destroyed
50 // while async operations from other member fields might still be using it.
51 std::array<char, 128> readBuf{};
Zev Weissa1456c42022-07-18 16:59:35 -070052 std::shared_ptr<I2CDevice> i2cDevice;
James Feistd8705872019-02-08 13:26:09 -080053 sdbusplus::asio::object_server& objServer;
Zev Weissd1c8f442022-07-29 11:54:41 -070054 boost::asio::random_access_file inputDev;
Ed Tanous9b4a20e2022-09-06 08:47:11 -070055 boost::asio::steady_timer waitTimer;
James Feist930fcde2019-05-28 12:58:43 -070056 std::string path;
Bruce Mitchell544e7dc2021-07-29 18:05:49 -050057 double offsetValue;
58 double scaleValue;
Jeff Lin87bc67f2020-12-04 20:58:01 +080059 unsigned int sensorPollMs;
Yong Lif3fd1912020-03-25 21:35:23 +080060
Zev Weissd1c8f442022-07-29 11:54:41 -070061 void handleResponse(const boost::system::error_code& err, size_t bytesRead);
Konstantin Aladysheva7345942021-04-28 17:09:02 +030062 void restartRead();
James Feistce3fca42018-11-21 12:58:24 -080063 void checkThresholds(void) override;
Patrick Ventureca44b2f2019-10-31 11:02:26 -070064};