Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Disregard OD variable description in SdoClient.upload() #592

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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

acolomb
Copy link
Member

@acolomb acolomb commented Jun 15, 2025

The upload method should behave as a raw producer of byte data.
Interpretation of the returned data based on the Object Dictionary is
the responsibility of the SdoVariable class, which delegates to the
generic ODVariable decoding functions.

Move the data truncation to the method SdoVariable.get_data(), where
access to the ODVariable is certain.

The only truncation that still happens is based on the response size
specified by the server, which might be smaller for e.g. expedited
upload. Extend the upload() function docstring to clarify the changed
behavior. Adjust the test case for expedited upload with unspecified
size in the response, which is the only incompatible change.

This is based on, and includes the changes of, #591.

acolomb added 2 commits June 15, 2025 18:09
When an OD entry is found in SdoClient.upload(), the truncation is
currently skipped only for those types explicitly listed as variable
length data (domain, strings).  That causes unknown types to be
truncated to whatever their length indicates, which is usually one
byte.

Invert the condition to check all types with an explicitly known size,
a.k.a. those listed in STRUCT_TYPES where the required length can be
deduced from the structure format.

Re-enable the unit tests which were skipped based on the previously
buggy behavior.
The upload method should behave as a raw producer of byte data.
Interpretation of the returned data based on the Object Dictionary is
the responsibility of the SdoVariable class, which delegates to the
generic ODVariable decoding functions.

Move the data truncation to the method SdoVariable.get_data(), where
access to the ODVariable is certain.

The only truncation that still happens is based on the response size
specified by the server, which might be smaller for e.g. expedited
upload.  Extend the upload() function docstring to clarify the changed
behavior.  Adjust the test case for expedited upload with unspecified
size in the response, which is the only incompatible change.
Copy link

codecov bot commented Jun 15, 2025

Codecov Report

All modified and coverable lines are covered by tests βœ…

πŸ“’ Thoughts on this report? Let us know!

@acolomb
Copy link
Member Author

acolomb commented Jun 16, 2025

Alright, this is ready for prime time with now complete test coverage. Would still like to postpone it past the next release, as it significantly changes the return value of SdoClient.upload() in case an OD description is available.

@acolomb acolomb added this to the v3.0.0 milestone Jun 18, 2025
Comment on lines +128 to +129
if response_size and response_size < len(data):
data = data[:response_size]
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm a little conflicted on what takes precedence: The actual amount of data transferred in the SDO, or the data size indicated by the size fields. Does the 301 standard mention this at all?

Copy link
Member Author

Choose a reason for hiding this comment

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

I haven't found any solution to this dilemma in the standard. My interpretation is that specifying the size in advance is the definitive answer. I doubt it will ever make a difference, as that would be a pretty awful server implementation.

In the end, what counts is the receiver's (client's) understanding of the data. And for that, the OD is needed anyway. If someone needs the full data in addition to the indicated size (to check for differences), they can just use the .open() API directly, without this mid-level convenience API.

Copy link
Collaborator

@sveinse sveinse Jun 22, 2025

Choose a reason for hiding this comment

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

When making protocol one should hope for the best and plan for the worst and not just expect happy path. So I believe its just to figure out how to resolve when a remote server replies with odd responses.

There are datatypes which is variable, such as string (which happens to be used in the test for this PR), so the OD cannot resolve them all.

Many times I'd wished that the protocol test suite from CiA would be public so we could see how they resolve it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, one almost sound reason I could see for sending extra data would be string termination. For convenience, the size might indicate the string length, but the data could be extended to include a NUL terminator byte. Which kind of makes sense in a C-based implementation.

Anyway, since there is already an alternative API in this library (file stream), let's wait and see if anybody comes back complaining about this change. I doubt many people are even using this API directly.

@acolomb
Copy link
Member Author

acolomb commented Jun 22, 2025

Anyway, this is v3.0.0 stuff by the way. #594 has higher priority on my agenda, then getting out the release.

Copy link
Collaborator

@sveinse sveinse left a comment

Choose a reason for hiding this comment

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

These changes looks good. There are probably more corner cases that can be pursued for SDO transfers, but that will have to be addressed in other PRs. Approved.

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.

2 participants