fix previously received data remains #18
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Relate #17
Description
If the DLC(Data Length Code) is less than 8, the previously received data remains in the "data" field of the topic sent by ros2_socketcan.
When supporting multiple types of HW with the same CAN-ID but different DLCs(*see below for further details), unintended behavior may occur if garbage is included in the reception result of can_receiver.
*Description about "CAN-ID but different DLCs".
For example, there are two HWs, HW1 and HW2, and the specification of HW1's CAN-ID: 100h is as follows.
In contrast to the above, if the HW2 CAN-ID: 100h specification is as follows, a malfunction may occur if the previously received data remains in the "data" field.
Current problem
The data length for memcopy was the DLC value in
SocketCanReceiver::receive
.As a result, when receiving data with a DLC length of less than 8, the data after the DLC data length was not initialized, and the previously received data remained in the buffer.
Countermeasures
Fixed data length to memcopy to be the size of the data field.
Review Procedure
I have confirmed that the unused data fields have been initialized by the steps described in the issue.