James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <Thresholds.hpp> |
| 4 | #include <sdbusplus/asio/object_server.hpp> |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 5 | #include <sensor.hpp> |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 6 | |
James Feist | 251c782 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 7 | class CPUSensor : public Sensor |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 8 | { |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 9 | public: |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 10 | 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 Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame] | 13 | boost::asio::io_service& io, const std::string& sensorName, |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 14 | std::vector<thresholds::Threshold>&& thresholds, |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame] | 15 | const std::string& configuration, int cpuId, bool show); |
Jae Hyun Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 16 | ~CPUSensor(); |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 17 | static constexpr unsigned int sensorScaleFactor = 1000; |
| 18 | static constexpr unsigned int sensorPollMs = 1000; |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame] | 19 | 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 Yoo | 8d9886d | 2018-10-22 15:24:29 -0700 | [diff] [blame] | 23 | |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 24 | private: |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 25 | sdbusplus::asio::object_server& objServer; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 26 | boost::asio::posix::stream_descriptor inputDev; |
| 27 | boost::asio::deadline_timer waitTimer; |
| 28 | boost::asio::streambuf readBuf; |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame] | 29 | std::string nameTcontrol; |
| 30 | double privTcontrol; |
| 31 | bool show; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 32 | int errCount; |
Jae Hyun Yoo | 9ced0a3 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 33 | void setupRead(void); |
James Feist | d870587 | 2019-02-08 13:26:09 -0800 | [diff] [blame] | 34 | void handleResponse(const boost::system::error_code& err); |
James Feist | ce3fca4 | 2018-11-21 12:58:24 -0800 | [diff] [blame] | 35 | void checkThresholds(void) override; |
James Feist | 6714a25 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 36 | }; |
Jae Hyun Yoo | 73ca551 | 2019-02-28 21:20:17 -0800 | [diff] [blame] | 37 | |
| 38 | extern boost::container::flat_map<std::string, std::unique_ptr<CPUSensor>> |
| 39 | gCpuSensors; |