Skip to content

[Arduino_CAN] support both 11-Bit (standard) and 29-Bit (extended) IDs #709

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/Arduino_CAN/examples/CANWrite/CANWrite.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void loop()
*/
uint8_t const msg_data[] = {0xCA,0xFE,0,0,0,0,0,0};
memcpy((void *)(msg_data + 4), &msg_cnt, sizeof(msg_cnt));
CanMsg msg(CAN_ID, sizeof(msg_data), msg_data);
CanMsg msg(CanStandardId(CAN_ID), sizeof(msg_data), msg_data);

/* Transmit the CAN message, capture and display an
* error core in case of failure.
Expand Down
10 changes: 7 additions & 3 deletions libraries/Arduino_CAN/src/Arduino_CAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ void Arduino_CAN::end()

int Arduino_CAN::write(CanMsg const & msg)
{
bool const is_standard_id = msg.isStandardId();

mbed::CANMessage const can_msg(
msg.id,
is_standard_id ? msg.getStandardId() : msg.getExtendedId(),
msg.data,
msg.data_length,
CANData,
CANStandard);
is_standard_id ? CANStandard : CANExtended);

return _can.write(can_msg);
}
Expand All @@ -65,8 +67,10 @@ size_t Arduino_CAN::available()

if (msg_read)
{
bool const is_standard_id = (can_msg.format == CANStandard);

CanMsg const msg(
can_msg.id,
is_standard_id ? CanStandardId(can_msg.id) : CanExtendedId(can_msg.id),
can_msg.len,
can_msg.data);

Expand Down