From 878f420e56a4193b47fc05388e32335552f71ea6 Mon Sep 17 00:00:00 2001 From: ismetatabay Date: Thu, 25 Jan 2024 16:14:53 +0300 Subject: [PATCH] init commit Signed-off-by: ismetatabay --- ros2_socketcan/src/socket_can_id.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ros2_socketcan/src/socket_can_id.cpp b/ros2_socketcan/src/socket_can_id.cpp index d3a9b77..5bf381e 100644 --- a/ros2_socketcan/src/socket_can_id.cpp +++ b/ros2_socketcan/src/socket_can_id.cpp @@ -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