Skip to content

Commit

Permalink
Add processing of extended flag (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorenkovnl authored May 2, 2024
1 parent 4d5efba commit dac19e1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/socketcan_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ 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));
Expand Down Expand Up @@ -104,11 +107,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);
Expand Down

0 comments on commit dac19e1

Please sign in to comment.