Skip to content

Commit

Permalink
Fix init of grp addr filter table
Browse files Browse the repository at this point in the history
  • Loading branch information
bmalinowsky committed May 16, 2024
1 parent 868fea2 commit 242291a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/io/calimero/server/Launcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,8 @@ private void waitForTermination()
}

private void setGroupAddressFilter(final RouterObject routerObj, final Set<GroupAddress> filter) {
final var table = new BitSet((1 << 16) / 8);
final int filterSize = (1 << 16) / 8;
final var table = new BitSet(filterSize);

RoutingConfig route7000 = RoutingConfig.All; // default config for group addresses ≥ 0x7000
if (filter.isEmpty())
Expand All @@ -905,7 +906,11 @@ private void setGroupAddressFilter(final RouterObject routerObj, final Set<Group
// use location of Filter Table Realisation Type 2, which shall start at memory address 0x0200
final int filterTableLocation = 0x200;
routerObj.set(PID.TABLE_REFERENCE, ByteBuffer.allocate(4).putInt(filterTableLocation).array());
server.device().deviceMemory().set(filterTableLocation, table.toByteArray());
final var memory = server.device().deviceMemory();
// table.toByteArray is only so big to contain the index of the highest set bit in the bitset
// we need to clear all bits first, so we don't retain any filter loaded from disk during init of device
memory.set(filterTableLocation, new byte[filterSize]);
memory.set(filterTableLocation, table.toByteArray());

final int config = (1 << 4 | route7000.ordinal() << 2 | RoutingConfig.Route.ordinal());
routerObj.set(PID.MAIN_LCGROUPCONFIG, (byte) config);
Expand Down

0 comments on commit 242291a

Please sign in to comment.