From e6b8d012f088ebceb3b0a72d48ed385cbba18db8 Mon Sep 17 00:00:00 2001 From: Dmytro Korenkov Date: Thu, 2 May 2024 14:09:29 +0200 Subject: [PATCH 1/2] process is_extended flag --- src/socketcan_bridge.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/socketcan_bridge.cpp b/src/socketcan_bridge.cpp index 1daa923..508252b 100644 --- a/src/socketcan_bridge.cpp +++ b/src/socketcan_bridge.cpp @@ -68,6 +68,10 @@ void SocketCanBridge::send(const can_msgs::msg::Frame & msg) can_frame frame; frame.can_id = msg.id; frame.len = msg.dlc; + if(msg.is_extended) + { + frame.can_id |= CAN_EFF_FLAG; + } std::copy(msg.data.begin(), msg.data.end(), frame.data); RCLCPP_DEBUG_STREAM(logger_, "Sending " << msg); auto n = write(socket_, &frame, sizeof(frame)); @@ -104,11 +108,12 @@ void SocketCanBridge::receive_loop(std::stop_token stoken) if (nbytes != sizeof(frame)) { throw std::runtime_error("Partial CAN frame received"); } - + const bool ext = ((frame.can_id & CAN_EFF_FLAG) == CAN_EFF_FLAG); can_msgs::msg::Frame msg; msg.header.stamp = clock_->now(); - msg.id = frame.can_id; + msg.id = frame.can_id & (ext ? CAN_EFF_MASK : CAN_SFF_MASK); msg.dlc = frame.len; + msg.is_extended = ext; std::copy_n(frame.data, sizeof(frame.data), msg.data.begin()); RCLCPP_DEBUG_STREAM(logger_, "Received " << msg); From 08563cef2a077d742403ec104037257d84535f0d Mon Sep 17 00:00:00 2001 From: Dmytro Korenkov Date: Thu, 2 May 2024 15:58:51 +0200 Subject: [PATCH 2/2] reformat --- src/socketcan_bridge.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/socketcan_bridge.cpp b/src/socketcan_bridge.cpp index 508252b..81dfdd6 100644 --- a/src/socketcan_bridge.cpp +++ b/src/socketcan_bridge.cpp @@ -68,8 +68,7 @@ void SocketCanBridge::send(const can_msgs::msg::Frame & msg) can_frame frame; frame.can_id = msg.id; frame.len = msg.dlc; - if(msg.is_extended) - { + if (msg.is_extended) { frame.can_id |= CAN_EFF_FLAG; } std::copy(msg.data.begin(), msg.data.end(), frame.data);