summaryrefslogtreecommitdiff
path: root/kvmd/plugins
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-10-13 19:47:30 +0300
committerDevaev Maxim <[email protected]>2020-10-13 19:47:30 +0300
commit48666a67418014ba2d61f4f9b86025269b129dd3 (patch)
tree0d357312eb12f1eab0fe624461005fa12a145b29 /kvmd/plugins
parentbee33f2df629a702dd61345e14d807720b94e3e9 (diff)
serial hid: clear queue on error
Diffstat (limited to 'kvmd/plugins')
-rw-r--r--kvmd/plugins/hid/serial.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/kvmd/plugins/hid/serial.py b/kvmd/plugins/hid/serial.py
index e1a85b1a..6c54b64e 100644
--- a/kvmd/plugins/hid/serial.py
+++ b/kvmd/plugins/hid/serial.py
@@ -344,7 +344,8 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
except queue.Empty:
self.__process_command(tty, b"\x01\x00\x00\x00\x00") # Ping
else:
- self.__process_command(tty, event.make_command())
+ if not self.__process_command(tty, event.make_command()):
+ self.clear_events()
except serial.SerialException as err:
if err.errno == errno.ENOENT:
@@ -361,10 +362,10 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
def __get_serial(self) -> serial.Serial:
return serial.Serial(self.__device_path, self.__speed, timeout=self.__read_timeout)
- def __process_command(self, tty: serial.Serial, command: bytes) -> None:
- self.__process_request(tty, self.__make_request(command))
+ def __process_command(self, tty: serial.Serial, command: bytes) -> bool:
+ return self.__process_request(tty, self.__make_request(command))
- def __process_request(self, tty: serial.Serial, request: bytes) -> None: # pylint: disable=too-many-branches
+ def __process_request(self, tty: serial.Serial, request: bytes) -> bool: # pylint: disable=too-many-branches
logger = get_logger()
errors: List[str] = []
runtime_errors = False
@@ -395,7 +396,7 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
raise _FatalRequestError("No previous command state inside HID, seems it was rebooted", online=True)
elif code == 0x20: # Done
self.__state_flags.update(online=True)
- return
+ return True
elif code & 0x80: # Pong with leds
self.__state_flags.update(
online=True,
@@ -403,7 +404,7 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
scroll=bool(code & 0x00000010),
num=bool(code & 0x00000100),
)
- return
+ return True
else:
raise _TempRequestError(f"Invalid response from HID: request={request!r}; code=0x{code:02X}")
@@ -430,6 +431,7 @@ class Plugin(BaseHid, multiprocessing.Process): # pylint: disable=too-many-inst
logger.error(msg)
if not (common_retries and read_retries):
logger.error("Can't process HID request due many errors: %r", request)
+ return False
def __send_request(self, tty: serial.Serial, request: bytes) -> bytes:
if not self.__noop: