Skip to content
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

fix: checking can id #40

Merged
merged 1 commit into from
Sep 23, 2024
Merged
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
9 changes: 7 additions & 2 deletions ros2_socketcan/src/socket_can_id.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,13 @@ CanId & CanId::identifier(const IdT id)
constexpr auto MAX_STANDARD = 0x07EFU;
static_assert(MAX_EXTENDED <= EXTENDED_ID_MASK, "Max extended id value is wrong");
static_assert(MAX_STANDARD <= STANDARD_ID_MASK, "Max extended id value is wrong");
const auto max_id = is_extended() ? MAX_EXTENDED : MAX_STANDARD;
if (max_id < id) {
auto max_id = MAX_STANDARD;
auto unmasked_id = id;
if (is_extended()) {
max_id = MAX_EXTENDED;
unmasked_id = id & ~(EXTENDED_MASK);
}
if (max_id < unmasked_id) {
throw std::domain_error{"CanId would be truncated!"};
}
// Clear and set
Expand Down
Loading