-
Notifications
You must be signed in to change notification settings - Fork 940
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
Simplify some BinaryPayload pack operations #2224
Conversation
28448cc
to
531cddf
Compare
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.
To be honest it is quite diffecult to see if the changes have any side effects.
This needed to be tested extra in the test harness, please do "protest --cov" and check that all code is covered.
pymodbus/utilities.py
Outdated
@@ -182,3 +186,11 @@ def hexlify_packets(packet): | |||
if not packet: | |||
return "" | |||
return " ".join([hex(int(x)) for x in packet]) | |||
|
|||
|
|||
def system_endian(): |
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 looks wrong, because byte order can be different from word order.
It seems wrong that we add endian utilities, we should avoid that.
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.
So the issue here is that the array class which I'm using (because it provides a nice way to operate on 16 bit integer lists as bytes) encodes integers with the system native byte format. In pymodbus AFAIU our registers list is encoded as a list of big endian integers so when converting from a register list to a python array(which has a convenient bytes method) we have to conditionally byteswap when converting if our native system byteformat is little endian so that the individual python array elements get ordered as big endian bytes. So this system endianness check is only actually being used when encoding/decoding the list of integers to/from bytes. We don't need to care about word order at this point either since we don't change word order when doing the register list to array to bytes conversions.
Once we are actually encoding/decoding integers i.e. in _pack_words
/_unpack_words
we can simply assume we are already big endian format and perform the byteswaping and wordswapping operations without having to care about system native byte format.
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.
Ended up just removing all the system native endian dependent array operations for now as it's a bit difficult to test without a big endian system.
bcad113
to
ecfc3ff
Compare
ecfc3ff
to
0a29862
Compare
I went ahead and removed the system endian dependent conversion operations, all these changes now should have full coverage. |
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.
LGTM, thanks.
Slightly cleaner and easier to read.