Add cy_can module implementing Cyphal/CAN#48
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
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_cantransport glue +cy_can_socketcanLinux backend, plus extensive CAN/UDP POSIX Unity test suites. - Refactor examples to use a shared
example_platform.hwithiface=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.
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>
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.
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:can0oriface=192.168.1.21), rename frommain_udp_*toexample_*, extract sharedexample_platform.h, and decouplecy.cfrom transport libraries in CMakeExtend 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; simplifyeui64.hto use POSIXuname()instead of platform-specific/etc/machine-idandsysctl.intrusive_fixture_utils.h: propagate extent intocy_subject_reader_t.extentfield (was only stored in the test-local struct).