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