Skip to content

Commit

Permalink
* (bluefox) Corrected the error with alignment of addresses: #539
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanBluefox committed Aug 29, 2024
1 parent e95ea34 commit 5db0f20
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 1,130 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ There are some programs in folder `test` to test the TCP communication:
### **WORK IN PROGRESS**
-->
## Changelog
### **WORK IN PROGRESS**
* (bluefox) Corrected the error with alignment of addresses

### 6.3.0 (2024-08-28)
* (Apollon77) Fix Timeout management to prevent leaking memory
* (bluefox) Added information about connected clients in the server mode
Expand Down
17 changes: 16 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ function iterateAddresses(isBools, deviceId, result, regName, regType, localOpti
lastAddress = blockStart + config[i].len;
}

// try to detect next block
// try to detect the next block
if (result.blocks) {
if ((config[i].address - lastAddress > 10 && config[i].len < 10) || (lastAddress - blockStart >= maxBlock)) {
if (!result.blocks.map(obj => obj.start).includes(blockStart)) {
Expand All @@ -747,15 +747,30 @@ function iterateAddresses(isBools, deviceId, result, regName, regType, localOpti
if (config.length) {
result.length = result.addressHigh - result.addressLow;
if (isBools && !localOptions.doNotRoundAddressToWord) {
const oldStart = result.addressLow;

// align addresses to 16 bit. E.g 30 => 16, 31 => 16, 32 => 32
result.addressLow = (result.addressLow >> 4) << 4;

// increase the length on the alignment if any
result.length += oldStart - result.addressLow;

// If the length is not a multiple of 16
if (result.length % 16) {
// then round it up to the next multiple of 16
result.length = ((result.length >> 4) + 1) << 4;
}

if (result.blocks) {
for (let b = 0; b < result.blocks.length; b++) {
const _oldStart = result.blocks[b].start;

// align addresses to 16 bit. E.g 30 => 16, 31 => 16, 32 => 32
result.blocks[b].start = (result.blocks[b].start >> 4) << 4;

// increase the length on the alignment if any
result.blocks[b].count += (_oldStart - result.blocks[b].start);

if (result.blocks[b].count % 16) {
result.blocks[b].count = ((result.blocks[b].count >> 4) + 1) << 4;
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"@alcalzone/release-script-plugin-iobroker": "^3.7.2",
"@alcalzone/release-script-plugin-license": "^3.7.0",
"@iobroker/testing": "^4.1.3",
"@iobroker/legacy-testing": "^1.0.13",
"gulp": "^4.0.2",
"mocha": "^10.7.3",
"chai": "^4.5.0",
Expand Down
Loading

0 comments on commit 5db0f20

Please sign in to comment.