refactor(dbus): piControl driver reset with PiControlIoctl class
Replaces inline ioctl logic with the new `PiControlIoctl` class for cleaner and reusable code. This improves readability, encapsulates device operations, and simplifies error handling for resetting the piControl driver.
This commit is contained in:
@@ -2,13 +2,11 @@
|
||||
# SPDX-FileCopyrightText: 2025 KUNBUS GmbH
|
||||
# SPDX-License-Identifier: GPL-2.0-or-later
|
||||
"""D-Bus interfaces for piControl."""
|
||||
import os
|
||||
from fcntl import ioctl
|
||||
from logging import getLogger
|
||||
|
||||
from pydbus.generic import signal
|
||||
|
||||
from .process_image_helper import ResetDriverWatchdog
|
||||
from .process_image_helper import PiControlIoctl, ResetDriverWatchdog
|
||||
|
||||
log = getLogger(__name__)
|
||||
|
||||
@@ -41,21 +39,9 @@ class InterfacePiControl:
|
||||
log.debug("enter InterfacePiControl.ResetDriver")
|
||||
|
||||
try:
|
||||
fd = os.open(self.picontrol_device, os.O_WRONLY)
|
||||
except Exception as e:
|
||||
log.warning(f"could not open ${self.picontrol_device} to reset driver")
|
||||
raise e
|
||||
|
||||
execption = None
|
||||
try:
|
||||
# KB_RESET _IO('K', 12 ) // reset the piControl driver including the config file
|
||||
ioctl(fd, 19212)
|
||||
picontrol_ioctl = PiControlIoctl(self.picontrol_device)
|
||||
picontrol_ioctl.ioctl(PiControlIoctl.IOCTL_RESET_DRIVER)
|
||||
log.info("reset piControl driver")
|
||||
except Exception as e:
|
||||
log.warning(f"could not reset piControl driver: ${e}")
|
||||
execption = e
|
||||
finally:
|
||||
os.close(fd)
|
||||
|
||||
if execption:
|
||||
raise execption
|
||||
raise e
|
||||
|
||||
Reference in New Issue
Block a user