Add --byte-order=mixed for mixed endian encoding #13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Took me a while but finally got around to implement this #1
This takes advantage of the fact that umodbus gives us big-endian-unpacked words already. So implementing mixed endian reuses the step that repacked those to bytes, but instead of repacking as big endian again, it uses little endian, effectively byte swapping each register.
Then, a few lines below, it unpacks the bytes as little endian again, which means that 16 bit registers become exactly the same as what we got from umodbus at first, but 32/64 bit registers look very different.
That line is outside of the diff because it didn't require changes. The "pack" variable is little endian thanks to this part of the code in parse_access:
This implies that the user can still do per-register endianness overrides, so you can theoretically do the inverse type of mixed endian if you really want to. But the main point of that is to still keep the old way of specifying endianness working. Personally I think it's more convenient to specify endianness as globally as a commandline option does, and not encode it in every register specification.
From my manual testing this also works with 64 bit fields, doubles in my case: