Skip to content

feat(CanMsg): add Remote Transmission Request (RTR) frame support - #284

Open
pruthvi828 wants to merge 1 commit into
arduino:masterfrom
pruthvi828:feat/canmsg-rtr-remote-frame-support
Open

pruthvi828 wants to merge 1 commit into
arduino:masterfrom
pruthvi828:feat/canmsg-rtr-remote-frame-support

Conversation

@pruthvi828

Copy link
Copy Markdown

Feature

This PR adds first-class support for Remote Transmission Request (RTR) frames to CanMsg, closing #230.

Background

The CAN standard defines the RTR (Remote Transmission Request) bit in arbitration headers to differentiate remote request frames from data frames. Under Linux SocketCAN (linux/can.h), which CanMsg.h explicitly references in its comment block (lines 127–132):

  • Bit 31: Frame format flag (CAN_EFF_FLAG = 0x80000000U)
  • Bit 30: Remote transmission request flag (CAN_RTR_FLAG = 0x40000000U)

Prior to this PR, bit 30 was marked as /* reserved (future remote transmission request flag) */, but lacked definition and API helpers, preventing Arduino platforms (such as Renesas Uno R4 Minima/WiFi, ESP32, STM32) from representing or checking for RTR frames.

Changes

  1. api/CanMsg.h:

    • Defined static uint32_t constexpr CAN_RTR_FLAG = 0x40000000U;.
    • Updated constructor CanMsg(can_id, len, ptr, bool const rtr = false) with default argument rtr = false ensuring 100% backward compatibility with all existing code.
    • Added query methods:
      • bool isRtr() const: Returns true if CAN_RTR_FLAG is set.
      • bool isRemote() const: Alias matching isRtr().
    • Added free helper functions:
      • CanStandardRtrId(uint32_t const id): Constructs a standard 11-bit ID with RTR flag set.
      • CanExtendedRtrId(uint32_t const id): Constructs an extended 29-bit ID with EFF and RTR flags set.
    • Updated printTo(Print & p) to emit RTR indicator for remote request frames ([020 RTR] (0) : ) while leaving standard data frame output identical.
  2. Tests (test/src/CanMsg/):

    • Added test_isRtr.cpp with Catch2 test cases covering standard RTR, extended RTR, constructor flag, and false assertions on standard data frames.
    • Extended test_printTo.cpp with test cases for standard RTR and extended RTR frame serialization.
    • Registered test_isRtr.cpp in test/CMakeLists.txt.

Verification

  • Syntax and header validation verified with LLVM clang++ (-std=c++11 -Wall -Wextra).
  • All existing tests in test/src/CanMsg/ retain identical behavior and assertions.

Fixes #230

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.

Feature Request - add "remote" member to the CanMsg class to denote Remote Transfer Request (RTR) frames

1 participant