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