blob: f65ef3342c2dcf2563e3721314973b91e120af85 [file] [log] [blame]
Qiang XUe28d1fa2019-02-27 13:50:56 +08001#pragma once
2
ZhikuiRenba8a8bf2020-01-09 15:55:43 -08003#include <gpiod.hpp>
Patrick Venturefd6ba732019-10-31 14:27:39 -07004#include <memory>
Qiang XUe28d1fa2019-02-27 13:50:56 +08005#include <sdbusplus/asio/object_server.hpp>
Patrick Venturefd6ba732019-10-31 14:27:39 -07006#include <string>
Qiang XUe28d1fa2019-02-27 13:50:56 +08007
8enum IntrusionSensorType
9{
10 pch,
11 gpio
12};
13
14class 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,
ZhikuiRenba8a8bf2020-01-09 15:55:43 -080024 bool gpioInverted);
Qiang XUe28d1fa2019-02-27 13:50:56 +080025
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 XUe28d1fa2019-02-27 13:50:56 +080042 bool mGpioInverted;
ZhikuiRenba8a8bf2020-01-09 15:55:43 -080043 std::string mPinName = "CHASSIS_INTRUSION";
44 gpiod::line mGpioLine;
45 boost::asio::posix::stream_descriptor mGpioFd;
Qiang XUe28d1fa2019-02-27 13:50:56 +080046
47 // common members
Qiang XUe28d1fa2019-02-27 13:50:56 +080048 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();
ZhikuiRenba8a8bf2020-01-09 15:55:43 -080058 void initGpioDeviceFile();
Qiang XUe28d1fa2019-02-27 13:50:56 +080059 int setSensorValue(const std::string& req, std::string& propertyValue);
60};