Only load each wide integer once in MODBUS_SET_INT*_TO_INT*() macros#684
Open
nabijaczleweli wants to merge 1 commit intostephane:masterfrom
Open
Only load each wide integer once in MODBUS_SET_INT*_TO_INT*() macros#684nabijaczleweli wants to merge 1 commit intostephane:masterfrom
nabijaczleweli wants to merge 1 commit intostephane:masterfrom
Conversation
|
We require contributors to sign our Contributor License Agreement. In order for us to review and merge your code, please fill https://forms.gle/5635zjphDo5JEJQSA to get added. Your document will be manually checked by the maintainer. Be patient... |
Author
lmfao |
Author
|
yeah im not posting you all of my PII im not fucking insane. apply if you want, dont if you dont |
|
Insane or not the idea seems to be fine (macros as ugly in some cases) There is a little mistake in SET_INT16 and SET_INT32: |
If you have a union like this as part of the read data:
union {
uint8_t serial[6];
uint16_t serial_raw[3];
};
and do the obvious
for(size_t i = 0; i < sizeof(rdng.serial_raw) / sizeof(*rdng.serial_raw); ++i) {
MODBUS_SET_INT16_TO_INT8(rdng.serial, i*2, rdng.serial_raw[i]);
}
then because serial_raw[i] is updated through serial[i] at first, then
loaded again, you end up with rdng.serial[i*2]=rdng.serial[i*2+1] for
all i, which is both confusing and wrong; instead, you must do
for(size_t i = 0; i < sizeof(rdng.serial_raw) / sizeof(*rdng.serial_raw); ++i) {
uint16_t r = rdng.serial_raw[i];
MODBUS_SET_INT16_TO_INT8(rdng.serial, i*2, rdng.serial_raw[i]);
}
but there's really no reason to require this,
and this patch lets you use them directly
|
We require contributors to sign our Contributor License Agreement. In order for us to review and merge your code, please fill https://forms.gle/5635zjphDo5JEJQSA to get added. Your document will be manually checked by the maintainer. Be patient... |
Author
|
Yep; updated. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
If you have a union like this as part of the read data:
and do the obvious
then because
serial_raw[i]is updated throughserial[i]at first, then loaded again, you end up withrdng.serial[i*2]=rdng.serial[i*2+1]for all i, which is both confusing and wrong (for example, "PmpaF1" ends up as "PPppFF"); instead, you must dobut there's really no reason to require this, and this patch lets you use them directly