-
Notifications
You must be signed in to change notification settings - Fork 638
Adding direction to virutal bus messages #779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding direction to virutal bus messages #779
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #779 +/- ##
===========================================
+ Coverage 69.52% 69.54% +0.01%
===========================================
Files 70 70
Lines 6544 6547 +3
===========================================
+ Hits 4550 4553 +3
Misses 1994 1994 |
can/interfaces/virtual.py
Outdated
|
||
# Add message to all listening on this channel | ||
all_sent = True | ||
for bus_queue in self.channel: | ||
msg_to_send = msg_copy | ||
if bus_queue is self.queue and self.receive_own_messages: | ||
msg_to_send = deepcopy(msg_copy) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A regular copy would suffice here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@christiansandberg Isn't deepcopy better than copy? I mean doing msg.data = xx after receiving a message in one queue will modify the message for all other virtual interfaces.
Also the original implementation sends the same message instance on every virtual bus. Should we change that to send a different instance since the same argument applies there.
Yes I know we pass the same msg instance to all interfaces (mostly for performance reasons) and that could be a risk if one of them mutates it for some reason. In general I think a message should be seen as immutable and especially the data part but perhaps it is better to deepcopy all messages instead just to be sure. |
@christiansandberg changed implementation to create a new deep copied instance of message for each virtual bus queue |
Future improvement can be to implement a copy-on-write (CoW) for messages. |
Co-Authored-By: pierreluctg <pierreluctg@gmail.com>
Perhaps worth adding |
@sou1hacker can you please add unit tests to cover the new features?
Thank you |
… message_direction_virtual
…cker/python-can into message_direction_virtual
Co-Authored-By: pierreluctg <pierreluctg@gmail.com>
This adds can.Message direction (Rx/Tx) to virtual interface