sdev 0.7.0__tar.gz → 0.7.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {sdev-0.7.0/sdev.egg-info → sdev-0.7.2}/PKG-INFO +1 -1
- {sdev-0.7.0 → sdev-0.7.2}/pyproject.toml +1 -1
- {sdev-0.7.0 → sdev-0.7.2}/sdev/__init__.py +1 -1
- {sdev-0.7.0 → sdev-0.7.2}/sdev/modules/__init__.py +4 -4
- {sdev-0.7.0 → sdev-0.7.2}/sdev/modules/serial_notebook.py +2 -1
- {sdev-0.7.0 → sdev-0.7.2}/sdev/modules/serial_rw.py +0 -53
- {sdev-0.7.0 → sdev-0.7.2/sdev.egg-info}/PKG-INFO +1 -1
- {sdev-0.7.0 → sdev-0.7.2}/setup.py +1 -1
- {sdev-0.7.0 → sdev-0.7.2}/LICENSE +0 -0
- {sdev-0.7.0 → sdev-0.7.2}/MANIFEST.in +0 -0
- {sdev-0.7.0 → sdev-0.7.2}/README.md +0 -0
- {sdev-0.7.0 → sdev-0.7.2}/sdev/cli/__init__.py +0 -0
- {sdev-0.7.0 → sdev-0.7.2}/sdev/cli/__main__.py +0 -0
- {sdev-0.7.0 → sdev-0.7.2}/sdev/deprecated/demoboard.py +0 -0
- {sdev-0.7.0 → sdev-0.7.2}/sdev/modules/serial_rw_server.py +0 -0
- {sdev-0.7.0 → sdev-0.7.2}/sdev.egg-info/SOURCES.txt +0 -0
- {sdev-0.7.0 → sdev-0.7.2}/sdev.egg-info/dependency_links.txt +0 -0
- {sdev-0.7.0 → sdev-0.7.2}/sdev.egg-info/entry_points.txt +0 -0
- {sdev-0.7.0 → sdev-0.7.2}/sdev.egg-info/requires.txt +0 -0
- {sdev-0.7.0 → sdev-0.7.2}/sdev.egg-info/top_level.txt +0 -0
- {sdev-0.7.0 → sdev-0.7.2}/setup.cfg +0 -0
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from .serial_rw import SerialRW,
|
|
3
|
+
from .serial_rw import SerialRW, scan_serial_ports, check_port_alive_nonblock
|
|
4
4
|
from .serial_rw_server import SerialRWClient, SerialRWServer, DEFAULT_SERVICE_PORT
|
|
5
|
+
from .serial_notebook import SerialNotebook
|
|
5
6
|
|
|
6
7
|
__all__ = [
|
|
7
8
|
"SerialRW",
|
|
8
|
-
"
|
|
9
|
+
"SerialRWClient",
|
|
10
|
+
"SerialRWServer",
|
|
9
11
|
"scan_serial_ports",
|
|
10
12
|
"check_port_alive_nonblock",
|
|
11
13
|
"DEFAULT_SERVICE_PORT",
|
|
12
|
-
"SerialRWClient",
|
|
13
|
-
"SerialRWServer",
|
|
14
14
|
]
|
|
@@ -259,59 +259,6 @@ class SerialRW():
|
|
|
259
259
|
def serial_rw(device: str, baudrate: int = 115200):
|
|
260
260
|
return SerialRW(device, baudrate)
|
|
261
261
|
|
|
262
|
-
|
|
263
|
-
class SerialRunner:
|
|
264
|
-
"""基于 SerialRW 的运行控制器。"""
|
|
265
|
-
def __init__(self, core: SerialRW):
|
|
266
|
-
self._core = core
|
|
267
|
-
|
|
268
|
-
def run(self, cmd, prompt_flag=" #", overall_timeout=None, response_timeout=None, wait_forever=False, stream=False, display=False):
|
|
269
|
-
self._core.drain_buffer()
|
|
270
|
-
YELLOW, GREY, RED, RESET = "\033[33m", "\033[90m", "\033[31m", "\033[0m"
|
|
271
|
-
|
|
272
|
-
def _iter():
|
|
273
|
-
try:
|
|
274
|
-
if cmd and display:
|
|
275
|
-
sys.stdout.write(f"{YELLOW}> {cmd}{RESET}\n")
|
|
276
|
-
sys.stdout.flush()
|
|
277
|
-
for line in self._core.forward(x=cmd, flag=prompt_flag, timeout=None if wait_forever else response_timeout):
|
|
278
|
-
if line.kind == 'timeout': raise TimeoutError
|
|
279
|
-
if display and line.kind == 'body':
|
|
280
|
-
text = line.text
|
|
281
|
-
if prompt_flag in text:
|
|
282
|
-
text = text.replace(prompt_flag, f"\033[32m{prompt_flag}{RESET}{GREY}")
|
|
283
|
-
sys.stdout.write(f"{GREY}{text}{RESET}")
|
|
284
|
-
sys.stdout.flush()
|
|
285
|
-
yield line.text
|
|
286
|
-
if display:
|
|
287
|
-
sys.stdout.write("\n\n")
|
|
288
|
-
sys.stdout.flush()
|
|
289
|
-
except TimeoutError:
|
|
290
|
-
if display:
|
|
291
|
-
sys.stdout.write(f"\n{RED}<sdev timeout>{RESET}\n")
|
|
292
|
-
sys.stdout.flush()
|
|
293
|
-
else: raise
|
|
294
|
-
|
|
295
|
-
gen = _iter()
|
|
296
|
-
return gen if stream else list(gen)
|
|
297
|
-
|
|
298
|
-
def send_interrupt(self):
|
|
299
|
-
try:
|
|
300
|
-
self._core.dry_send(CTRL_C)
|
|
301
|
-
except:
|
|
302
|
-
pass
|
|
303
|
-
|
|
304
|
-
def check_model_type(self, timeout=2.0):
|
|
305
|
-
try:
|
|
306
|
-
lines = self.run("cat /proc/device-tree/model 2>/dev/null; echo", prompt_flag=" #", response_timeout=timeout)
|
|
307
|
-
for l in reversed(lines):
|
|
308
|
-
s = l.strip().replace("\x00", "")
|
|
309
|
-
if s and " #" not in s:
|
|
310
|
-
return s.split("/")[0].strip()[:16].lower()
|
|
311
|
-
except:
|
|
312
|
-
pass
|
|
313
|
-
return None
|
|
314
|
-
|
|
315
262
|
if __name__ == "__main__":
|
|
316
263
|
s = serial_rw("/dev/ttyUSB0", 115200)
|
|
317
264
|
s.connect()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|