-
Notifications
You must be signed in to change notification settings - Fork 207
Fix SDO truncation of unknown datatypes #447
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -429,6 +429,16 @@ def decode_raw(self, data: bytes) -> Union[int, float, str, bytes, bytearray]: | |
# Strip any trailing NUL characters from C-based systems | ||
return data.decode("utf_16_le", errors="ignore").rstrip("\x00") | ||
elif self.data_type in self.STRUCT_TYPES: | ||
size = self.STRUCT_TYPES[self.data_type].size | ||
logger.warning(f"Decoding data {data!r} of type 0x%X at %s", | ||
self.data_type, pretty_index(self.index, self.subindex)) | ||
logger.warning(f"Size: {size} bytes, data length: {len(data)} bytes") | ||
if len(data) > size: | ||
logger.warning("Excessive data in %s. Data type 0x%X expects %s bytes, got %s", | ||
pretty_index(self.index, self.subindex), self.data_type, | ||
size, len(data)) | ||
# Truncate the data to the expected size | ||
data = data[:size] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's way easier switching to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to remove the warning altogether. |
||
try: | ||
value, = self.STRUCT_TYPES[self.data_type].unpack(data) | ||
return value | ||
|
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.
This is definitely too much logging, both by number of messages and at a too high severity level.
And please try to stick to the previously discussed rule:
logging
methods use%
formats and parameters, and f-strings for everything else.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.
Yes, I agree. These are left-overs from my own debugging. My bad. I'll remove them.