Skip to content

Conversation

@JaagupAverin
Copy link
Contributor

@JaagupAverin JaagupAverin commented Nov 29, 2025

chore: Cleanup non-smp serial data handling.

Makes the buffer processing hopefully a bit more clear. Non-SMP data is no longer logged to stdout but can be accessed with the read_serial() function.

@JPHutchins
Copy link
Collaborator

Thanks! This should resolve #12, take a look for details. I hope it's possible to avoid creating tasks and rely on queues instead. Callback could be useful for flexibility, but I suspect that the average use case would be to await the device log "channel" - the queue.

The refactor does appear to simplify the code, nice work!

@JPHutchins
Copy link
Collaborator

Type ignores can be OK for mocking and monkey patching in the tests.

@JaagupAverin JaagupAverin force-pushed the main branch 3 times, most recently from 0737650 to f1108df Compare November 29, 2025 20:13
@JaagupAverin
Copy link
Contributor Author

I think a lot of use cases are going to need a separate task for handling the serial data anyways so I wanted to hide it underneath the library. But I understand you'd rather not have this complexity. Made quick force push with new implementation.
Will be testing and trying this out a bit more thoroughly in the next week myself.

@JaagupAverin JaagupAverin marked this pull request as draft December 1, 2025 14:05
@JaagupAverin JaagupAverin marked this pull request as ready for review December 2, 2025 12:59
@JaagupAverin JaagupAverin force-pushed the main branch 2 times, most recently from 835d6af to 634f5ce Compare December 18, 2025 09:04
@JaagupAverin JaagupAverin force-pushed the main branch 2 times, most recently from a135d38 to 4eace68 Compare January 15, 2026 13:24
Makes the buffer processing hopefully a bit more clear. Non-SMP data is no longer logged to stdout but can be accessed with the read_serial() function.
@JaagupAverin JaagupAverin force-pushed the main branch 3 times, most recently from 4eace68 to 74cf97f Compare January 15, 2026 13:27
@JaagupAverin
Copy link
Contributor Author

JaagupAverin commented Jan 15, 2026

Been using this for a bit now. Found and fixed a bug related to delimiter falling exactly on buffer boundary, but other than that its been churning gigabytes of intermingled serial and SMP data. So stability side it seems okay.
Will be looking to create a release internally in a week or two so would be good to know if this can get merged or we'll need an internal fork.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the serial data handling in SMPSerialTransport to improve clarity and maintainability. The changes separate SMP packet processing from non-SMP serial data handling, replacing the previous logging-based approach with a buffer-based API.

Changes:

  • Refactored buffer processing state machine for clearer separation of SMP and serial data
  • Introduced read_serial() method to access non-SMP serial data programmatically instead of logging it
  • Added _reset_state() to properly reset connection state between reconnections
  • Expanded test coverage for serial data handling scenarios

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
smpclient/transport/serial.py Refactored buffer processing logic with new state machine, added read_serial() method, and improved connection state management
tests/test_smp_serial_transport.py Updated tests to use new internal methods, added comprehensive tests for serial/SMP data separation, and added disconnect exception handling test

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"""Contains full SMP packets."""
self._serial_buffer = bytearray()
"""Contains any non-SMP serial data."""
self._buffer: bytearray = bytearray([])
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

The empty list argument [] in bytearray([]) is unnecessary. Use bytearray() directly for clarity.

Copilot uses AI. Check for mistakes.

self._smp_packet_queue = asyncio.Queue()
self._serial_buffer.clear()
self._buffer = bytearray([])
Copy link

Copilot AI Jan 15, 2026

Choose a reason for hiding this comment

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

The empty list argument [] in bytearray([]) is unnecessary. Use bytearray() directly for clarity.

Suggested change
self._buffer = bytearray([])
self._buffer = bytearray()

Copilot uses AI. Check for mistakes.
@JPHutchins
Copy link
Collaborator

Been using this for a bit now. Found and fixed a bug related to delimiter falling exactly on buffer boundary, but other than that its been churning gigabytes of intermingled serial and SMP data. So stability side it seems okay.

Will be looking to create a release internally in a week or two so would be good to know if this can get merged or we'll need an internal fork.

I'll review again, but it does look good to merge - thanks for testing!

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.

2 participants