Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 3 | #include <gpiod.hpp> |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 4 | #include <sdbusplus/asio/object_server.hpp> |
James Feist | 38fb598 | 2020-05-28 10:09:54 -0700 | [diff] [blame] | 5 | |
| 6 | #include <memory> |
Patrick Venture | fd6ba73 | 2019-10-31 14:27:39 -0700 | [diff] [blame] | 7 | #include <string> |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 8 | |
| 9 | enum IntrusionSensorType |
| 10 | { |
| 11 | pch, |
| 12 | gpio |
| 13 | }; |
| 14 | |
| 15 | class ChassisIntrusionSensor |
| 16 | { |
| 17 | public: |
| 18 | ChassisIntrusionSensor( |
| 19 | boost::asio::io_service& io, |
| 20 | std::shared_ptr<sdbusplus::asio::dbus_interface> iface); |
| 21 | |
| 22 | ~ChassisIntrusionSensor(); |
| 23 | |
| 24 | void start(IntrusionSensorType type, int busId, int slaveAddr, |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 25 | bool gpioInverted); |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 26 | |
| 27 | private: |
| 28 | std::shared_ptr<sdbusplus::asio::dbus_interface> mIface; |
| 29 | std::shared_ptr<sdbusplus::asio::connection> mDbusConn; |
| 30 | |
| 31 | IntrusionSensorType mType; |
| 32 | |
| 33 | // intrusion status. 0: not intruded, 1: intruded |
| 34 | std::string mValue = "unknown"; |
| 35 | std::string mOldValue = "unknown"; |
| 36 | |
| 37 | // valid if it is PCH register via i2c |
| 38 | int mBusId; |
| 39 | int mSlaveAddr; |
| 40 | boost::asio::deadline_timer mPollTimer; |
| 41 | |
| 42 | // valid if it is via GPIO |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 43 | bool mGpioInverted; |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 44 | std::string mPinName = "CHASSIS_INTRUSION"; |
| 45 | gpiod::line mGpioLine; |
| 46 | boost::asio::posix::stream_descriptor mGpioFd; |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 47 | |
| 48 | // common members |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 49 | bool mOverridenState = false; |
| 50 | bool mInternalSet = false; |
| 51 | |
| 52 | bool mInitialized = false; |
| 53 | |
| 54 | void updateValue(const std::string newValue); |
| 55 | int i2cReadFromPch(int busId, int slaveAddr); |
| 56 | void pollSensorStatusByPch(); |
| 57 | void readGpio(); |
| 58 | void pollSensorStatusByGpio(); |
ZhikuiRen | ba8a8bf | 2020-01-09 15:55:43 -0800 | [diff] [blame] | 59 | void initGpioDeviceFile(); |
Qiang XU | e28d1fa | 2019-02-27 13:50:56 +0800 | [diff] [blame] | 60 | int setSensorValue(const std::string& req, std::string& propertyValue); |
| 61 | }; |