7 Commits

Author SHA1 Message Date
fb671a7c34 Add X/Y/ZMODEM file transfer protocols with security hardening
File transfer protocols:
- XMODEM: 128/1024-byte blocks with checksum or CRC-16
- YMODEM: Batch transfers with file metadata in block 0
- ZMODEM: Streaming protocol with auto-resume capability

Security and robustness fixes:
- Atomic file creation (O_CREAT|O_EXCL) prevents TOCTOU races
- Transfer size limits (100MB default) prevent memory exhaustion
- Byte range validation (0-255) with clear error messages
- 4GB overflow handling for ZMODEM position encoding
- CRC-32 table initialized at module load for thread safety
- Timeout enforcement prevents indefinite hangs

Server enhancements:
- file_transfer_send/receive/send_batch tools
- atexit cleanup for open connections
- Thread-safety documentation for _connections registry
2026-01-28 12:27:48 -07:00
974f2ee6dc Add RS-485 specific tools
New tools for RS-485 half-duplex communication:

- check_rs485_support: Detect hardware RS-485 capability via udev/ioctl
  Reports driver type (FTDI/CP210x/CH340), kernel support, and recommendations

- rs485_transact: Send request and receive response with automatic
  TX/RX turnaround timing. Handles manual RTS control when needed.

- rs485_scan_addresses: Scan bus for responding devices (1-247)
  Useful for Modbus device discovery
2026-01-27 22:42:40 -07:00
948775968d Default to auto-baud detection when opening ports
open_serial_port() now auto-detects baud rate when baudrate=None (default).
Returns detection confidence and top candidates in response.

Falls back to DEFAULT_BAUDRATE (9600) if no data received or low confidence.

Optional autobaud_probe parameter for sync-based detection on echo devices.
2026-01-27 22:29:19 -07:00
8014b2833b Add smart baud rate auto-detection
Uses multiple heuristics for reliable detection:
- 0x55 sync pattern analysis (self-synchronizing byte)
- Bit transition counting (0x55 has 7 transitions vs ~3.5 avg)
- Byte distribution entropy (text clusters vs random)
- ASCII readability scoring with UTF-8 validation
- Line ending and null byte detection

Supports optional probe string (use "UUUUU" for sync-based detection
on echo-enabled devices). Returns top 5 candidates with confidence scores.
2026-01-27 22:26:26 -07:00
f9f5f3527f Add advanced pyserial features
Flow control:
- xonxoff, rtscts, dsrdtr in open_serial_port and configure_serial

Timeouts:
- write_timeout and inter_byte_timeout support

New tools:
- read_until: read until custom terminator (not just newline)
- set_rs485_mode: half-duplex RS-485 for industrial/Modbus
- set_low_latency_mode: reduce kernel buffering latency (Linux)
- set_break_condition: hold/release break state

Also:
- exclusive port locking option in open_serial_port
- updated get_connection_status with all new fields
2026-01-27 22:19:29 -07:00
96d6e3e86b Add RS-232 modem control line tools
New tools for hardware control:
- get_modem_lines: read all input (CTS/DSR/RI/CD) and output (RTS/DTR) lines
- set_modem_lines: set RTS/DTR states
- pulse_line: pulse RTS or DTR for reset sequences (ESP32, Arduino, etc.)
- send_break: send serial break signal

Also added RI and CD to get_connection_status and port status resource.
2026-01-27 22:15:03 -07:00
1a26109fc1 Initial MCP serial server implementation
FastMCP server for serial port access via Model Context Protocol:
- 10 tools: list, open, close, read, write, configure, flush, status
- 4 dynamic resources: ports list, data, status, raw hex
- USB device filtering (hides phantom ttyS ports by default)
- Full pyserial support with configurable baudrate/parity/etc
2026-01-27 22:05:59 -07:00