Commit bce2a89
committed
Only load each wide integer once in MODBUS_SET_INT*_TO_INT*() macros
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 directly1 parent b25629b commit bce2a89
1 file changed
+17
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
283 | 283 | | |
284 | 284 | | |
285 | 285 | | |
286 | | - | |
287 | | - | |
288 | | - | |
289 | | - | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
290 | 291 | | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
295 | 297 | | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
302 | 305 | | |
303 | 306 | | |
304 | 307 | | |
| |||
0 commit comments