ros2_socketcan icon indicating copy to clipboard operation
ros2_socketcan copied to clipboard

fix: checking can id

Open ismetatabay opened this issue 1 year ago • 4 comments

Description

At the Extended Can ID, the most significant bit determines the EFF flag (CAN_EFF_FLAG). For example, if our Extended CAN ID will be: 0x01F0A020 (00000001111100001010000000100000) and if it's EFF Flag is 1, the value will be 0x81F0A020 (10000001111100001010000000100000).

Therefore, the CAN ID value is exceeds the 29 bit max value. (~536million - 0x1FBF'FFFFU). If we want to check can id value, we need to unmask it first. This PR fixes this problem.

ismetatabay avatar Jan 25 '24 13:01 ismetatabay

@JWhitleyWork can you check this fix?

ismetatabay avatar Jan 25 '24 13:01 ismetatabay

There are two ways to test for standard vs extended frames in SocketCAN: First mask the ID with the largest extended CAN ID and then check the value of the CAN ID and see if it is larger than the maximum standard frame ID (how it is done in the code now) or check the EFF bit returned in the unmasked ID. Both are valid so I don't think this change is necessary. Let me know if you feel differently.

JWhitleyWork avatar Jan 25 '24 17:01 JWhitleyWork

@JWhitleyWork Thanks for the fast response, but I couldn't handle the following situation:

In case, my extended ID will be: 0x01F0A020, and if I give this ID to my can_msgs Frame message,

is_extended() function returns False:

https://github.com/autowarefoundation/ros2_socketcan/blob/8996cdbbb32b01894f7bf046e994a8e0f55d36ce/ros2_socketcan/src/socket_can_id.cpp#L77-L81

If I set the my can id:0x81F0A020 at can_msgs::Frame msg, is_extended() function returns true but I get this error since it exceeds the maximum limit:

https://github.com/autowarefoundation/ros2_socketcan/blob/8996cdbbb32b01894f7bf046e994a8e0f55d36ce/ros2_socketcan/src/socket_can_id.cpp#L139-L142

At this point, what do you recommend me to do in this situation?

Thanks in advance @JWhitleyWork

ismetatabay avatar Jan 26 '24 08:01 ismetatabay

@JWhitleyWork friendly reminder :smiley:

ismetatabay avatar Jan 30 '24 08:01 ismetatabay