Identifying a local BACnet address
Brought to you by:
joelhaggar,
mlohbihler
The code in function com.serotonin.bacnet4j.service.unconfirmed.IAMRequest.handle(...) to determine if we received a message from ourselves (lines 77-82) won't accommodate the situation where there are multiple 'local' addresses as happens when the host is running multiple network interfaces for example.
The test should be if the From MAC address is one of the Local addresses then ignore. Whereas the logic will register the From address if it is a Local address but not the first Local address.
My suggested remedy is to replace the existing lines 77-82:
for (Address addr : localDevice.getAllLocalAddresses()) {
if (addr.getMacAddress().equals(from.getMacAddress()))
// This is a local address, so ignore.
return;
LOGGER.warning("Another instance with my device instance ID found!");
}
with:
if (Arrays.asList(localDevice.getAllLocalAddresses()).contains(from.getMacAddress())) {
// This is a local address, so ignore.
return;
}
LOGGER.warning("Another instance with my device instance ID found!");
Hope this helps. Thanks for all your hard work on BACnet4J, its much appreciated.
cheers,
Brenton
Even better:
for (Address addr : localDevice.getAllLocalAddresses()) {
if (addr.getMacAddress().equals(from.getMacAddress()))
// This is a local address, so ignore.
return;
}
LOGGER.warning("Another instance with my device instance ID found!");