Skip to content

Fix CPX UART flow-control handling#600

Open
ataffanel wants to merge 2 commits into
masterfrom
ataffane/fix-cpx-uart-flow-control
Open

Fix CPX UART flow-control handling#600
ataffanel wants to merge 2 commits into
masterfrom
ataffane/fix-cpx-uart-flow-control

Conversation

@ataffanel

Copy link
Copy Markdown
Member

Summary

Fix CPX UART flow-control handling in UARTTransport.

The previous implementation used one Lock both to serialize outgoing writes and to represent incoming UART CTS (0xFF 0x00). This could crash with:

RuntimeError: release unlocked lock

when duplicate or unsolicited CTS frames arrived while no write was pending.

This PR replaces that lock-as-CTS mechanism with explicit flow-control state:

  • Use threading.Event to track peer CTS
  • Use a separate TX lock to serialize outgoing packets
  • Use a raw serial write lock to avoid interleaving data frames and CTS replies
  • Treat duplicate/unsolicited 0xFF 0x00 frames as harmless CTS events
  • Discard CRC-bad frames and continue reading until a valid CPX packet arrives
  • Add fake-serial unit tests for CTS handling, CRC recovery, and CTS-gated writes

Fixes #599.

Testing

  • python -m unittest test.cpx.test_uart_transport
  • python -m unittest discover test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exception while reading transport, link probably closed? - Bolt UART CFLib Connection Issues

1 participant