✨ feat(uart): add UART availability check, inter-step delays, and post-download Zynq status verification
- Add check_uart_available() to serial_monitor.py — detects port availability - Add verify_zynq_status() to boot_verifier.py — lightweight post-download check - Add uart_delay / inter_step_delay config fields (defaults: 3s / 2s) - Step 1: Check UART availability, show non-blocking 'UART 不可用' notification - Step 4: Add post-download Zynq status check (ping + serial) after TFTP - _run_steps_worker: Add configurable inter-step delays between all steps - Update step labels (4a→4b→4c→4d) for clarity
This commit is contained in:
@@ -108,6 +108,56 @@ def parse_boot_output(lines: list[str]) -> BootInfo:
|
||||
return info
|
||||
|
||||
|
||||
def check_uart_available(
|
||||
port: str,
|
||||
baudrate: int = 115200,
|
||||
timeout: float = 3.0,
|
||||
) -> tuple[bool, str]:
|
||||
"""Check whether the UART serial port is available and readable.
|
||||
|
||||
Attempts to open the port, clear buffers, and read a few lines.
|
||||
If the port opens but returns no data within the timeout, it is
|
||||
considered available (the device may simply not be outputting yet).
|
||||
If the port cannot be opened at all, it is unavailable.
|
||||
|
||||
Args:
|
||||
port: Serial port device path (e.g., '/dev/ttyUSB0').
|
||||
baudrate: Baud rate for serial communication.
|
||||
timeout: Seconds to wait for data after opening.
|
||||
|
||||
Returns:
|
||||
Tuple of (is_available, reason_string).
|
||||
- (True, "Port open") — port is usable
|
||||
- (True, "Port open, no data yet") — port open, no data currently
|
||||
- (False, "No serial ports detected") — system has no serial ports
|
||||
- (False, "Port not in detected ports") — configured port missing
|
||||
- (False, "Failed to open: <error>") — port open error
|
||||
"""
|
||||
# 1. Quick port list check
|
||||
ports = detect_serial_ports()
|
||||
if not ports:
|
||||
return False, "No serial ports detected"
|
||||
|
||||
# 2. Verify the configured port is among detected ones
|
||||
if port and port not in {p.device for p in ports}:
|
||||
return False, f"Port {port} not in detected ports"
|
||||
|
||||
# 3. Try to open and read
|
||||
try:
|
||||
with serial.Serial(port, baudrate, timeout=timeout) as ser:
|
||||
ser.reset_input_buffer()
|
||||
lines: list[str] = []
|
||||
while ser.in_waiting:
|
||||
line = ser.readline().decode("utf-8", errors="replace").strip()
|
||||
if line:
|
||||
lines.append(line)
|
||||
if lines:
|
||||
return True, "Port open"
|
||||
return True, "Port open, no data yet"
|
||||
except serial.SerialException as e:
|
||||
return False, f"Failed to open: {e}"
|
||||
|
||||
|
||||
def read_serial_stream(
|
||||
port: str,
|
||||
baudrate: int = 115200,
|
||||
|
||||
Reference in New Issue
Block a user