James Feist | 139cb57 | 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 | af79dd3 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 5 | #include <sensor.hpp> |
James Feist | 139cb57 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 6 | |
James Feist | 7c39135 | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 7 | constexpr const char *gpioPath = "/sys/class/gpio/"; |
| 8 | class PresenceSensor |
| 9 | { |
| 10 | |
| 11 | public: |
| 12 | PresenceSensor(const size_t index, bool inverted, |
| 13 | boost::asio::io_service &io); |
| 14 | ~PresenceSensor(); |
| 15 | |
| 16 | void monitorPresence(void); |
| 17 | void read(void); |
| 18 | bool getValue(void); |
| 19 | |
| 20 | private: |
| 21 | bool status = true; |
| 22 | bool inverted; |
| 23 | boost::asio::ip::tcp::socket inputDev; |
| 24 | int fd; |
| 25 | }; |
James Feist | af79dd3 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 26 | class TachSensor : public Sensor |
James Feist | 139cb57 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 27 | { |
| 28 | public: |
| 29 | std::string name; |
| 30 | std::string configuration; |
| 31 | TachSensor(const std::string &path, |
| 32 | sdbusplus::asio::object_server &objectServer, |
| 33 | std::shared_ptr<sdbusplus::asio::connection> &conn, |
James Feist | 7c39135 | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 34 | std::unique_ptr<PresenceSensor> &&presence, |
Jae Hyun Yoo | f78ec41 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 35 | boost::asio::io_service &io, const std::string &fanName, |
James Feist | 139cb57 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 36 | std::vector<thresholds::Threshold> &&thresholds, |
| 37 | const std::string &sensorConfiguration); |
| 38 | ~TachSensor(); |
| 39 | |
| 40 | private: |
| 41 | std::string path; |
| 42 | sdbusplus::asio::object_server &objServer; |
| 43 | std::shared_ptr<sdbusplus::asio::connection> dbusConnection; |
James Feist | 7c39135 | 2018-10-26 14:09:45 -0700 | [diff] [blame] | 44 | std::unique_ptr<PresenceSensor> presence; |
Jae Hyun Yoo | f78ec41 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 45 | boost::asio::posix::stream_descriptor inputDev; |
| 46 | boost::asio::deadline_timer waitTimer; |
| 47 | boost::asio::streambuf readBuf; |
| 48 | int errCount; |
| 49 | double maxValue; |
| 50 | double minValue; |
| 51 | void setupRead(void); |
| 52 | void handleResponse(const boost::system::error_code &err); |
| 53 | void checkThresholds(void); |
| 54 | void updateValue(const double &newValue); |
James Feist | af79dd3 | 2018-09-12 12:54:15 -0700 | [diff] [blame] | 55 | |
Jae Hyun Yoo | f78ec41 | 2018-10-25 10:42:39 -0700 | [diff] [blame] | 56 | void setInitialProperties( |
James Feist | 139cb57 | 2018-09-10 15:26:18 -0700 | [diff] [blame] | 57 | std::shared_ptr<sdbusplus::asio::connection> &conn); |
| 58 | }; |