blob: a54299eaec2d58ac067b7549f9fa330965f420bc [file] [log] [blame]
Qiang XUe28d1fa2019-02-27 13:50:56 +08001#pragma once
2
ZhikuiRenba8a8bf2020-01-09 15:55:43 -08003#include <gpiod.hpp>
Qiang XUe28d1fa2019-02-27 13:50:56 +08004#include <sdbusplus/asio/object_server.hpp>
James Feist38fb5982020-05-28 10:09:54 -07005
6#include <memory>
Patrick Venturefd6ba732019-10-31 14:27:39 -07007#include <string>
Qiang XUe28d1fa2019-02-27 13:50:56 +08008
9enum IntrusionSensorType
10{
11 pch,
12 gpio
13};
14
15class 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,
ZhikuiRenba8a8bf2020-01-09 15:55:43 -080025 bool gpioInverted);
Qiang XUe28d1fa2019-02-27 13:50:56 +080026
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 XUe28d1fa2019-02-27 13:50:56 +080043 bool mGpioInverted;
ZhikuiRenba8a8bf2020-01-09 15:55:43 -080044 std::string mPinName = "CHASSIS_INTRUSION";
45 gpiod::line mGpioLine;
46 boost::asio::posix::stream_descriptor mGpioFd;
Qiang XUe28d1fa2019-02-27 13:50:56 +080047
48 // common members
Qiang XUe28d1fa2019-02-27 13:50:56 +080049 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();
ZhikuiRenba8a8bf2020-01-09 15:55:43 -080059 void initGpioDeviceFile();
Qiang XUe28d1fa2019-02-27 13:50:56 +080060 int setSensorValue(const std::string& req, std::string& propertyValue);
61};