diff --git a/proxyclient/addrdump.py b/proxyclient/addrdump.py index f9806cfe..b1ca9b8b 100755 --- a/proxyclient/addrdump.py +++ b/proxyclient/addrdump.py @@ -3,10 +3,7 @@ import serial, os from proxy import * -uartdev = os.environ.get("M1N1DEVICE", "/dev/ttyUSB0") -usbuart = serial.Serial(uartdev, 115200) - -iface = UartInterface(usbuart, debug=False) +iface = UartInterface() proxy = M1N1Proxy(iface, debug=False) SCRATCH = 0x24F00000 diff --git a/proxyclient/proxy.py b/proxyclient/proxy.py index a3064504..d369cb81 100755 --- a/proxyclient/proxy.py +++ b/proxyclient/proxy.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 # SPDX-License-Identifier: MIT -import os, sys, struct +import os, sys, struct, serial from serial.tools.miniterm import Miniterm def hexdump(s, sep=" "): @@ -80,8 +80,21 @@ class UartInterface: CMD_LEN = 56 REPLY_LEN = 36 - def __init__(self, device, debug=False): + def __init__(self, device=None, debug=False): self.debug = debug + self.devpath = None + if device is None: + device = os.environ.get("M1N1DEVICE", "/dev/ttyUSB0:115200") + if isinstance(device, str): + baud = 115200 + if ":" in device: + device, baud = device.rsplit(":", 1) + baud = int(baud) + self.devpath = device + self.baudrate = baud + + device = serial.Serial(self.devpath, baud) + self.dev = device self.dev.timeout = 0 self.dev.flushOutput() diff --git a/proxyclient/setup.py b/proxyclient/setup.py index 59c81fee..fcb58a84 100644 --- a/proxyclient/setup.py +++ b/proxyclient/setup.py @@ -3,21 +3,18 @@ from proxy import * from tgtypes import * from utils import * -uartdev = os.environ.get("M1N1DEVICE", "/dev/ttyUSB0") -uart = serial.Serial(uartdev, 115200) - -iface = UartInterface(uart, debug=False) +iface = UartInterface() p = M1N1Proxy(iface, debug=False) try: - uart.timeout = 0.15 + iface.dev.timeout = 0.15 iface.nop() p.set_baud(1500000) except UartTimeout: - uart.baudrate = 1500000 + iface.dev.baudrate = 1500000 iface.nop() -uart.timeout = 3 +iface.dev.timeout = 3 u = ProxyUtils(p) mon = RegMonitor(u)