blob: f66e655919a54ad8bf07c1576e9019ce5d1c0598 [file] [log] [blame]
James Feist6714a252018-09-10 15:26:18 -07001#pragma once
2
3#include <Thresholds.hpp>
4#include <sdbusplus/asio/object_server.hpp>
James Feist251c7822018-09-12 12:54:15 -07005#include <sensor.hpp>
James Feist6714a252018-09-10 15:26:18 -07006
James Feist251c7822018-09-12 12:54:15 -07007class CPUSensor : public Sensor
James Feist6714a252018-09-10 15:26:18 -07008{
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -07009 public:
James Feistd8705872019-02-08 13:26:09 -080010 CPUSensor(const std::string& path, const std::string& objectType,
11 sdbusplus::asio::object_server& objectServer,
12 std::shared_ptr<sdbusplus::asio::connection>& conn,
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -080013 boost::asio::io_service& io, const std::string& sensorName,
James Feistd8705872019-02-08 13:26:09 -080014 std::vector<thresholds::Threshold>&& thresholds,
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -080015 const std::string& configuration, int cpuId, bool show);
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -070016 ~CPUSensor();
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070017 static constexpr unsigned int sensorScaleFactor = 1000;
18 static constexpr unsigned int sensorPollMs = 1000;
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -080019 static constexpr size_t warnAfterErrorCount = 10;
20 static constexpr double maxReading = 127;
21 static constexpr double minReading = -128;
22 static constexpr const char* labelTcontrol = "Tcontrol";
Jae Hyun Yoo8d9886d2018-10-22 15:24:29 -070023
James Feist6714a252018-09-10 15:26:18 -070024 private:
James Feistd8705872019-02-08 13:26:09 -080025 sdbusplus::asio::object_server& objServer;
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070026 boost::asio::posix::stream_descriptor inputDev;
27 boost::asio::deadline_timer waitTimer;
28 boost::asio::streambuf readBuf;
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -080029 std::string nameTcontrol;
30 double privTcontrol;
31 bool show;
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070032 int errCount;
Jae Hyun Yoo9ced0a32018-10-25 10:42:39 -070033 void setupRead(void);
James Feistd8705872019-02-08 13:26:09 -080034 void handleResponse(const boost::system::error_code& err);
James Feistce3fca42018-11-21 12:58:24 -080035 void checkThresholds(void) override;
James Feist6714a252018-09-10 15:26:18 -070036};
Jae Hyun Yoo73ca5512019-02-28 21:20:17 -080037
38extern boost::container::flat_map<std::string, std::unique_ptr<CPUSensor>>
39 gCpuSensors;