Skip to content
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

Fix SDO writes of empty strings. #551

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

willson556
Copy link

Previously, when attempting a write of "" to a VISIBLE_STRING, the expedited SDO request would not be sent and the transaction would timeout.

I traced this down to the BufferedWriter not issuing a write to the underlying stream when it has only been called with b"".

To resolve this, if the transaction size is known to be 0, the raw_stream is now returned. I also added a unit test to cover this case.

@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.42%. Comparing base (ffbd10f) to head (29597ae).

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #551      +/-   ##
==========================================
+ Coverage   71.36%   71.42%   +0.06%     
==========================================
  Files          26       26              
  Lines        3129     3129              
  Branches      480      480              
==========================================
+ Hits         2233     2235       +2     
+ Misses        765      764       -1     
+ Partials      131      130       -1     
Files with missing lines Coverage Δ
canopen/sdo/client.py 72.45% <100.00%> (+0.43%) ⬆️

Copy link
Collaborator

@acolomb acolomb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find and good job in fixing it. Some nit-picks, but nothing serious that would keep this from being merged.


def test_expedited_download_zero_length(self):
self.data = [
(TX, b'\x33\x00\x20\x00\x00\x00\x00\x00'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For an expedited download, the toggle bit should be zero, thus this byte sequence needs to start with 0x23, right?

@@ -215,7 +215,9 @@ def open(self, index, subindex=0, mode="rb", encoding="ascii",
raw_stream = BlockDownloadStream(self, index, subindex, size, request_crc_support=request_crc_support)
else:
raw_stream = WritableStream(self, index, subindex, size, force_segment)
if buffering:
if buffering and ((size is None) or size > 0):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if buffering and ((size is None) or size > 0):
if buffering and (size is None or size > 0):

Comment on lines +219 to +220
# BufferedWriter will omit the write if size is 0 and the expedited SDO will not be sent
# Therefore, skip the BufferedWriter if size is known to be 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to keep line lengths below 100 characters or even shorter. Especially for comments, longer lines are just annoying for those who user a narrow editor window ;-)

Suggested change
# BufferedWriter will omit the write if size is 0 and the expedited SDO will not be sent
# Therefore, skip the BufferedWriter if size is known to be 0
# BufferedWriter will omit the write if size is 0 and the expedited SDO will
# not be sent. Therefore, skip the BufferedWriter if size is known to be 0.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I also suggest that the comment here is not very clear (I had to read it twice and read the code to get it). Perhaps have it say something more concise like "BufferedWriter will omit the write if size is 0. For size 0 use the raw stream to ensure the message is sent."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants