Skip to content

Add cy_can module implementing Cyphal/CAN#48

Merged
pavel-kirienko merged 17 commits into
mainfrom
dev
Apr 7, 2026
Merged

Add cy_can module implementing Cyphal/CAN#48
pavel-kirienko merged 17 commits into
mainfrom
dev

Conversation

@pavel-kirienko
Copy link
Copy Markdown
Member

  • Implement cy_can — a platform-agnostic Cyphal/CAN transport glue layer backed by the new libcanard v5.

  • Add cy_can_socketcan — a Linux SocketCAN backend providing the cy_can_vtable_t implementation with poll-based I/O, non-blocking sockets, and automatic CAN FD capability probing.

  • Add comprehensive test suites for both cy_can (constructor validation, pub/sub with pinned/verbatim topics, reliable RPC, redundancy deduplication, backpressure retry, tombstone revival with extent preservation, OOM/capacity failure paths) and cy_udp_posix (basic API, pub/sub, RPC lifecycle, default constructor EUI-64 verification), all built as 32-bit C99 Unity tests.

  • Restructure examples to support runtime transport selection via iface= argv parsing (iface=socketcan:can0 or iface=192.168.1.21), rename from main_udp_* to example_*, extract shared example_platform.h, and decouple cy.c from transport libraries in CMake

  • Extend CI smoke test to run both UDP and vcan paths when a virtual CAN interface is available.

Key changes

  • cy.c: reader extent is now max(incumbent, requested) during tombstone revival, preventing extent shrinkage.

  • cy_platform.h: document that platform must initialize extent to zero or its initial value at reader construction; add reentrancy contract on spin.

  • cy_udp_posix: move static_asserts to file scope for C99 compatibility; add tombstone clarification comments; simplify eui64.h to use POSIX uname() instead of platform-specific /etc/machine-id and sysctl.

  • intrusive_fixture_utils.h: propagate extent into cy_subject_reader_t.extent field (was only stored in the test-local struct).

Copy link
Copy Markdown
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

Adds a new platform-agnostic Cyphal/CAN transport layer (cy_can) backed by libcanard v5, a Linux SocketCAN backend, expanded transport-focused test suites, and updates examples/CI to support runtime transport selection.

Changes:

  • Introduce cy_can transport glue + cy_can_socketcan Linux backend, plus extensive CAN/UDP POSIX Unity test suites.
  • Refactor examples to use a shared example_platform.h with iface= argv parsing and rename example binaries.
  • Improve tombstone reader extent handling and clarify platform contracts; update CI smoke test to exercise UDP and vcan paths when available.

Reviewed changes

Copilot reviewed 46 out of 47 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tools/ci_example_smoke.py Extend smoke test to run UDP + optional vcan/SocketCAN path with privilege probing.
tests/src/intrusive_fixture_utils.h Propagate reader extent into cy_subject_reader_t for fixtures.
README.md Document transport selection and update example filenames/includes.
examples/example_time_pub.c Use example_platform.h and argv-based platform selection.
examples/example_sub.c Use example_platform.h; simplify config to focus on subscriptions.
examples/example_streaming_server.c Use example_platform.h for runtime transport selection.
examples/example_streaming_client.c Use example_platform.h for runtime transport selection.
examples/example_pub.c Use example_platform.h; simplify config; adjust published message content.
examples/example_platform.h New helper to parse iface= and construct UDP or SocketCAN platforms.
examples/example_file_server.c Use example_platform.h for runtime transport selection.
examples/example_file_client.c Use example_platform.h for runtime transport selection and updated usage text.
examples/example_echo.c Use example_platform.h for runtime transport selection and updated usage text.
examples/cy_trace_stderr.c Minor include ordering/headers adjustment.
examples/CMakeLists.txt Restructure example build/linkage and add optional tracing support.
cy/cy.c Preserve larger incumbent extent on tombstone revival (max(old, requested)).
cy/cy_platform.h Clarify reader extent initialization contract; document spin() reentrancy constraint.
cy_udp_posix/tests/test_support.h New shared UDP POSIX test helpers.
cy_udp_posix/tests/test_support.c Implement UDP POSIX test helpers (spin helpers, payload helpers, UID parsing).
cy_udp_posix/tests/test_api_udp_posix_rpc_lifecycle.c New UDP POSIX RPC lifecycle tests.
cy_udp_posix/tests/test_api_udp_posix_pubsub.c New UDP POSIX pub/sub tests including reliable large transfer.
cy_udp_posix/tests/test_api_udp_posix_default_ctor.c New UDP POSIX default constructor UID prefix/flag tests with skip logic.
cy_udp_posix/tests/test_api_udp_posix_basic.c New UDP POSIX basic API tests (iface parse, ctor/home, namespace/time).
cy_udp_posix/tests/CMakeLists.txt New C99 Unity test targets for UDP POSIX (32-bit).
cy_udp_posix/eui64.h Simplify EUI-64 derivation to use uname() nodename hash + /dev/urandom.
cy_udp_posix/cy_udp_posix.h Update default ctor doc comment after EUI-64 change.
cy_udp_posix/cy_udp_posix.c Move/expand compile-time layout assertions; add tombstone/teardown clarifications.
cy_udp_posix/CMakeLists.txt Make cy_udp_posix transport-only library and add its new tests subdir.
cy_can/tests/test_support.h New shared CAN test harness declarations.
cy_can/tests/test_support.c Implement CAN in-memory bus + heap fault injection + vtable shims.
cy_can/tests/test_api_can_tombstone_revival.c New CAN tombstone revival/extent preservation tests.
cy_can/tests/test_api_can_socketcan_e2e.c New Linux SocketCAN vcan end-to-end smoke test with skip logic.
cy_can/tests/test_api_can_reliable_rpc.c New CAN reliable publish and RPC/streaming response tests.
cy_can/tests/test_api_can_redundancy_lifecycle.c New CAN redundancy, backpressure retry, and lifecycle tests.
cy_can/tests/test_api_can_pubsub.c New CAN pub/sub tests including pinned vs verbatim and FD/classic behavior.
cy_can/tests/test_api_can_failures.c New CAN OOM/capacity failure-path tests.
cy_can/tests/test_api_can_constructor.c New CAN constructor validation + filtering callback behavior tests.
cy_can/tests/CMakeLists.txt New C99 Unity test targets for CAN (32-bit) + conditional SocketCAN e2e on Linux.
cy_can/cy_can.h New public API for CAN transport layer and driver vtable contract.
cy_can/cy_can.c New platform-agnostic CAN transport implementation using libcanard v5.
cy_can/cy_can_socketcan.h New public API for Linux SocketCAN backend.
cy_can/cy_can_socketcan.c New poll-based non-blocking SocketCAN backend with FD probing and filter programming.
cy_can/CMakeLists.txt New build targets for cy_can + cy_can_socketcan + tests.
CMakeLists.txt Add formatting globs for new dirs and include cy_can subdirectory.
.idea/dictionaries/project.xml Add “destructions” to IDE dictionary.
.gitmodules Add libcanard submodule (experimental branch).
.github/workflows/main.yml Update CI to build/run renamed examples for smoke test.
Files not reviewed (1)
  • .idea/dictionaries/project.xml: Language not supported

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

Comment thread cy_can/CMakeLists.txt Outdated
Comment thread examples/CMakeLists.txt
Comment thread examples/example_platform.h
Comment thread cy_can/cy_can_socketcan.c
cy_can_socketcan is Linux-only but was built/linked unconditionally,
breaking configuration on non-Linux hosts. Guard the CMake target with
a platform check, use the platform_target parameter in cy_add_example,
and wrap SocketCAN references in example_platform.h with #if __linux__.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@pavel-kirienko pavel-kirienko marked this pull request as ready for review April 7, 2026 21:05
@pavel-kirienko pavel-kirienko merged commit ddf986c into main Apr 7, 2026
7 checks passed
@pavel-kirienko pavel-kirienko deleted the dev branch April 7, 2026 21:07
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