blob: 2dc621653795d70e5c940a52d681e015a891f4b8 [file] [log] [blame]
James Feist139cb572018-09-10 15:26:18 -07001#pragma once
2
3#include <Thresholds.hpp>
4#include <sdbusplus/asio/object_server.hpp>
James Feistaf79dd32018-09-12 12:54:15 -07005#include <sensor.hpp>
James Feist139cb572018-09-10 15:26:18 -07006
James Feist7c391352018-10-26 14:09:45 -07007constexpr const char *gpioPath = "/sys/class/gpio/";
8class 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 Feistaf79dd32018-09-12 12:54:15 -070026class TachSensor : public Sensor
James Feist139cb572018-09-10 15:26:18 -070027{
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 Feist7c391352018-10-26 14:09:45 -070034 std::unique_ptr<PresenceSensor> &&presence,
Jae Hyun Yoof78ec412018-10-25 10:42:39 -070035 boost::asio::io_service &io, const std::string &fanName,
James Feist139cb572018-09-10 15:26:18 -070036 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 Feist7c391352018-10-26 14:09:45 -070044 std::unique_ptr<PresenceSensor> presence;
Jae Hyun Yoof78ec412018-10-25 10:42:39 -070045 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 Feistaf79dd32018-09-12 12:54:15 -070055
Jae Hyun Yoof78ec412018-10-25 10:42:39 -070056 void setInitialProperties(
James Feist139cb572018-09-10 15:26:18 -070057 std::shared_ptr<sdbusplus::asio::connection> &conn);
58};