Skip to content

Commit

Permalink
[nsh] Fix broken wait_for() implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
niklaut committed Sep 3, 2024
1 parent 39abc64 commit 8dd263e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.5.5

- Fix NSH protocol `wait_for()` function implementation.

## 1.5.4

- Allow NSH port to be opened by filepath.
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ dependencies = [
dynamic = ["version"]

[project.urls]
"Docs" = "https://auterion.github.io/embedded-debug-tools/emdbg.html"
"GitHub" = "https://github.com/auterion/embedded-debug-tools"
"Changelog" = "https://github.com/auterion/embedded-debug-tools/blob/main/CHANGELOG.md"

Expand Down
11 changes: 5 additions & 6 deletions src/emdbg/serial/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,15 @@ def wait_for(self, pattern: str, timeout: float = _TIMEOUT) -> str | None:
:return: received lines until matched pattern or None on timeout
"""
lines = []
lines = ""
start = time.time()
while True:
if time.time() - start > timeout:
break
new_lines = self.read_lines(0)
lines.append(new_lines)
for line in new_lines:
if re.search(pattern, line):
return self._join(lines)
if (new_lines := self.read_lines(0)) is not None:
lines += new_lines
if re.search(pattern, new_lines):
return lines
time.sleep(0.1)
_LOGGER.warning(f"Waiting for '{pattern}' timed out after {timeout:.1f}s!")
return None
Expand Down

0 comments on commit 8dd263e

Please sign in to comment.