convert sysfs gpio usage to libgpiod
Updated Chassis Intrusion Sensor monitoring
to use pin name and gpiod APIs. Number based sysfs
framework is deprecated and replaced by descriptor
based gpiod framework. With named gpio pin,
code is more portable provided the device tree
defines GPIO pin name consistently.
This requires device tree change (227661) and
configuration file change (entity-manager/+/28350)
Tested:
Build and run changes together and verified chassis intrusion sensor
value gets updated correctly through D-Bus object.
Signed-off-by: ZhikuiRen <zhikui.ren@intel.com>
Change-Id: I03c50e32059936902432d5a8bc498dabb812ea5e
diff --git a/src/IntrusionSensorMain.cpp b/src/IntrusionSensorMain.cpp
index 96da5f6..b89f628 100644
--- a/src/IntrusionSensorMain.cpp
+++ b/src/IntrusionSensorMain.cpp
@@ -53,7 +53,7 @@
static bool getIntrusionSensorConfig(
std::shared_ptr<sdbusplus::asio::connection>& dbusConnection,
- IntrusionSensorType* pType, int* pBusId, int* pSlaveAddr, int* pGpioIndex,
+ IntrusionSensorType* pType, int* pBusId, int* pSlaveAddr,
bool* pGpioInverted)
{
// find matched configuration according to sensor type
@@ -105,30 +105,17 @@
// case to find GPIO info
if (*pType == IntrusionSensorType::gpio)
{
- auto gpioConfig =
- sensorData->find(sensorType + std::string(".GpioIntrusion"));
+ auto findGpioPolarity =
+ baseConfiguration->second.find("GpioPolarity");
- if (gpioConfig == sensorData->end())
+ if (findGpioPolarity == baseConfiguration->second.end())
{
- std::cerr
- << "error finding GpioIntrusion info in configuration \n";
- continue;
- }
-
- auto findGpioIndex = gpioConfig->second.find("Index");
- auto findGpioPolarity = gpioConfig->second.find("Polarity");
-
- if (findGpioIndex == gpioConfig->second.end() ||
- findGpioPolarity == gpioConfig->second.end())
- {
- std::cerr << "error finding gpio info in configuration \n";
+ std::cerr << "error finding gpio polarity in configuration \n";
continue;
}
try
{
- *pGpioIndex = sdbusplus::message::variant_ns::get<uint64_t>(
- findGpioIndex->second);
*pGpioInverted =
(sdbusplus::message::variant_ns::get<std::string>(
findGpioPolarity->second) == "Low");
@@ -141,9 +128,9 @@
if (DEBUG)
{
- std::cout << "find matched GPIO index " << *pGpioIndex
- << ", polarity inverted flag is " << *pGpioInverted
- << "\n";
+ std::cout << "find chassis intrusion sensor polarity inverted "
+ "flag is "
+ << *pGpioInverted << "\n";
}
return true;
@@ -187,7 +174,6 @@
"sensor. \n";
*pBusId = -1;
*pSlaveAddr = -1;
- *pGpioIndex = -1;
return false;
}
@@ -457,7 +443,8 @@
int main()
{
- int busId = -1, slaveAddr = -1, gpioIndex = -1;
+ int busId = -1;
+ int slaveAddr = -1;
bool gpioInverted = false;
IntrusionSensorType type = IntrusionSensorType::gpio;
@@ -477,10 +464,9 @@
ChassisIntrusionSensor chassisIntrusionSensor(io, ifaceChassis);
if (getIntrusionSensorConfig(systemBus, &type, &busId, &slaveAddr,
- &gpioIndex, &gpioInverted))
+ &gpioInverted))
{
- chassisIntrusionSensor.start(type, busId, slaveAddr, gpioIndex,
- gpioInverted);
+ chassisIntrusionSensor.start(type, busId, slaveAddr, gpioInverted);
}
// callback to handle configuration change
@@ -494,9 +480,9 @@
std::cout << "rescan due to configuration change \n";
if (getIntrusionSensorConfig(systemBus, &type, &busId, &slaveAddr,
- &gpioIndex, &gpioInverted))
+ &gpioInverted))
{
- chassisIntrusionSensor.start(type, busId, slaveAddr, gpioIndex,
+ chassisIntrusionSensor.start(type, busId, slaveAddr,
gpioInverted);
}
};