Feat/i can backend extraction#12
Draft
iliabaranov wants to merge 3 commits into
Draft
Conversation
Adds socketcan_adapter/include/socketcan_adapter/i_can_backend.hpp — the cross-cutting CAN transport contract: open/close, send, receive, reception thread lifecycle, and on-receive/on-error callback hooks. Linux-specific knobs (filter vector, error mask, JOIN flag) stay concrete-only on SocketcanAdapter since they have no analog on non-SocketCAN backends. SocketcanAdapter now inherits from ICanBackend, with `override` annotations on the matching methods. The interface signatures were chosen to match SocketcanAdapter's existing public surface byte-for-byte, so this is a zero-behavior-change refactor: every existing call site continues to work, all 19 existing tests still pass, all three packages in the workspace (socketcan_adapter, socketcan_adapter_ros, axiomatic_adapter) build without modification. Why this is needed: enables a forthcoming AxiomaticFdBackend (Axiomatic AX140970 Dual CAN FD over Ethernet converter) to plug into SocketcanBridgeNode and other consumers via ICanBackend* without forking the runtime path. The legacy AxiomaticAdapter will be retrofitted in a follow-up patch (its API needs minor unification — currently uses chrono::milliseconds vs the interface's chrono::duration<float>, and lacks runtime setOnReceiveCallback / setOnErrorCallback).
Companion to the prior commit that extracted the ICanBackend interface and
made SocketcanAdapter implement it. With this change, both transport
adapters share a polymorphic base, so consumers can hold a non-owning
ICanBackend* and select the transport (kernel SocketCAN, Axiomatic
ETH-CAN bridge) at construction time without forking the runtime path.
Purely additive — every existing call site keeps working:
* TCPSocketState becomes an alias of polymath::socketcan::SocketState.
The two enums had identical numeric values; aliasing is source-compat
for any caller spelling out the legacy name.
* Existing methods get `override` annotations where they match the
interface byte-for-byte: openSocket, closeSocket, receive(CanFrame&),
startReceptionThread, send(const CanFrame&), is_thread_running,
get_socket_state.
* Four new methods added to satisfy the interface:
- joinReceptionThread(const std::chrono::duration<float>&) — converts
to the existing milliseconds-based overload.
- send(std::shared_ptr<const CanFrame>) — delegates to send(CanFrame&).
- setOnReceiveCallback(...) — runtime setter; mirrors SocketcanAdapter's
plain-assignment semantics. Set BEFORE startReceptionThread() to
avoid racing the rx thread (same convention as SocketcanAdapter).
- setOnErrorCallback(...) — same pattern.
* The existing constructor that takes receive + error callbacks remains
the canonical setup path. The new setters are additive — useful when
constructing through an ICanBackend* factory but not required.
Build: all 3 packages build clean (socketcan_adapter, socketcan_adapter_ros,
axiomatic_adapter). Tests: 19/19 existing tests pass — same as baseline.
Pure formatter output from running the new pre-commit hook (polymathrobotics/polymath_code_standard@v2.1.2 introduced upstream in polymathrobotics#9) over the four files touched by the prior two commits: socketcan_adapter/include/socketcan_adapter/i_can_backend.hpp socketcan_adapter/include/socketcan_adapter/socketcan_adapter.hpp axiomatic_adapter/include/axiomatic_adapter/axiomatic_adapter.hpp axiomatic_adapter/src/axiomatic_adapter.cpp Plus one cpplint suggestion: add #include <memory> in axiomatic_adapter.cpp for the std::shared_ptr usage in the new send(shared_ptr<const CanFrame>) overload. No logic changes; build remains clean and 19/19 existing tests still pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.