From c13f9324ecf0e4a1f020a71426ec35e53884690c Mon Sep 17 00:00:00 2001 From: Christian Wiche Date: Thu, 30 Dec 2021 13:11:33 -0300 Subject: [PATCH 1/2] Updated service join implementation to allow keyboard/signal interruptions --- embutils/utils/service.py | 3 ++- examples/stream_setup.py | 21 ++++----------------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/embutils/utils/service.py b/embutils/utils/service.py index 55502d7..275b772 100644 --- a/embutils/utils/service.py +++ b/embutils/utils/service.py @@ -118,7 +118,8 @@ def join(self) -> None: """ Wait until service is fully terminated. """ - self._ended.wait() + while not self._ended.is_set(): + time.sleep(self.TASK_DELAY_S) def _service(self) -> None: """ diff --git a/examples/stream_setup.py b/examples/stream_setup.py index d41e9ad..a8aca7d 100644 --- a/examples/stream_setup.py +++ b/examples/stream_setup.py @@ -139,25 +139,12 @@ def decode_stream(self, device: Device) -> Optional[AbstractSerialized]: Defines how to the serial device will be read to decode the desired serialized object. """ - # Read a single byte and check... - recv = device.read(size=1) + # Read until COBS end (0x00) + recv = device.read_until(expected=b"\x00") if recv is None: raise ConnectionError(f"Connection error while reading from {device}") if len(recv) == 0: return None - # Are we reading contents? - byte = ord(recv) - if byte != 0x00: - # Yes -> Byte is not stuff... frame incoming - data = bytearray(recv) - recv = device.read_until(expected=b"\x00") - if recv is None: - raise ConnectionError(f"Connection error while reading from {device}") - - # Process - data.extend(recv) - return SimplePacket.deserialize(data=COBS.decode(data=data)) - - # No -> Nothing to process - return None + # Process + return self._dtype.deserialize(data=COBS.decode(data=bytearray(recv))) From 902be2e9aa911b4ac5134f983c22fbf8ae8af960 Mon Sep 17 00:00:00 2001 From: Christian Wiche Date: Thu, 30 Dec 2021 13:13:37 -0300 Subject: [PATCH 2/2] Bump version --- embutils/__init__.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/embutils/__init__.py b/embutils/__init__.py index 1ef1319..c9880e6 100644 --- a/embutils/__init__.py +++ b/embutils/__init__.py @@ -1 +1 @@ -__version__ = '0.7.3' +__version__ = '0.7.4' diff --git a/pyproject.toml b/pyproject.toml index 919e51b..fa4767a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.poetry] -version = "0.7.3" +version = "0.7.4" name = "embutils" license = "MIT" readme = "README.md"