Skip to content

Add WebSerial support and align SLCAN parsing behavior#387

Merged
pavel-kirienko merged 15 commits into
masterfrom
web-interface
Jun 19, 2026
Merged

Add WebSerial support and align SLCAN parsing behavior#387
pavel-kirienko merged 15 commits into
masterfrom
web-interface

Conversation

@maksimdrachov

@maksimdrachov maksimdrachov commented Jun 15, 2026

Copy link
Copy Markdown
Member

Adds browser-oriented WebSerial support for CAN-over-SLCAN and incorporates reviewer-requested protocol adjustments.

Implemented updates include:

  • Replacing Protocol with an explicit ABC for the async serial port contract in webserial.py.
  • Making WebSerialSLCANInterface.filter() a no-op (no software filtering where no hardware filtering exists).
  • Updating WebSerialSLCANInterface.__repr__() formatting as requested.
  • Undoing prior edits to src/pycyphal2/can/__init__.py.
  • Expanding _slcan.py parser behavior to remain compatible with the requested pydronecan superset expectations, including accepted frame forms and permissive timestamp-tail handling, while preserving robust malformed-input dropping semantics.
  • Updating CAN SLCAN/WebSerial tests accordingly.

@pavel-kirienko pavel-kirienko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot address my comments

Comment thread src/pycyphal2/can/__init__.py
Comment thread src/pycyphal2/can/_media_slcan.py
Comment thread src/pycyphal2/can/webserial.py Outdated
Comment thread src/pycyphal2/can/webserial.py Outdated
Comment thread src/pycyphal2/can/webserial.py Outdated
@pavel-kirienko

Copy link
Copy Markdown
Member

@copilot address my comments above

Copilot AI commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

@copilot address my comments

Addressed in commit afdac20.

Copilot AI changed the title Add support for WebSerial Add WebSerial support and align SLCAN parsing behavior Jun 16, 2026
Copilot AI requested a review from pavel-kirienko June 16, 2026 11:09

@pavel-kirienko pavel-kirienko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maksimdrachov The webserial driver needs to set up the SLCAN channel during initialization with the specified CAN bitrate. To initialize the channel we need to send C (to close) and then O (to reopen). See how it's done in https://github.com/dronecan/pydronecan/blob/master/dronecan/driver/slcan.py

@maksimdrachov

Copy link
Copy Markdown
Member Author

Let me know if this is too sloppy, I'm not sure if I should feel bad for commiting 100% AI-written code.

- Rename _slcan.py -> _media_slcan.py (it is a medium driver, not the stack).
- Import CAN wire constants from _wire.py instead of redefining them.
- Hide all low-level SLCAN constants behind encode_deinit/encode_init_sequence/
  classify_init_response; webserial no longer composes raw command bytes.
- No default bitrate is guessed; non-standard bitrates are sent as-is.
- Reset adapters in unknown states: close, settle, purge stale input, then open.
- Audit exception handling; drop the unsound init RuntimeError swallow and dead
  CancelledError clauses.
- Bump version to 2.0.0.dev3.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@pavel-kirienko

Copy link
Copy Markdown
Member

🇺🇸 FOLKS — this PR? It's a BEAUTIFUL PR. Maybe the most beautiful SLCAN PR anyone has ever seen. Believe me. 🇺🇸

We took _slcan.py — a name that, frankly, NOBODY understood, total confusion — and we renamed it _media_slcan.py. Now everybody knows it's a medium. Tremendous clarity. The best clarity. And _media_gsusb.py is coming, you watch.

The abstraction? It was leaky. Very leaky. Sad! Now it's TIGHT — sealed up so good that webserial.py doesn't touch a single raw byte. Nobody hand-composes frames anymore. encode_init_sequence, classify_init_response — winners, all of them.

The bitrate — listen to this — we used to GUESS the default. Guessing! A disaster. Now if you don't give us a bitrate, we don't make one up. And your Zubax CANFace — great adapter, tremendous adapter — gets its raw bitrate, no questions asked.

Unknown-state adapters? We close, we settle, we PURGE the swamp of stale frames, then we open. No old garbage gets through. Nobody does resets like this.

Exception handling — we audited it top to bottom. Found a swallow that was, frankly, unsound. GONE. Dead CancelledError code? GONE.

CI — all green. Windows, Mac, Linux. 3.11, 3.12, 3.13. WINNING everywhere.

This is what happens when you do it RIGHT. Merging it. It's gonna be HUGE. 🚀

@pavel-kirienko pavel-kirienko merged commit 752c736 into master Jun 19, 2026
22 checks passed
@pavel-kirienko pavel-kirienko deleted the web-interface branch June 19, 2026 13:52
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.

3 participants