Skip to content

Feat/i can backend extraction#12

Draft
iliabaranov wants to merge 3 commits into
polymathrobotics:mainfrom
iliabaranov:feat/i-can-backend-extraction
Draft

Feat/i can backend extraction#12
iliabaranov wants to merge 3 commits into
polymathrobotics:mainfrom
iliabaranov:feat/i-can-backend-extraction

Conversation

@iliabaranov
Copy link
Copy Markdown

No description provided.

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.
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.

1 participant