use of com.zsmartsystems.zigbee.zdo.field.NeighborTable in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeNodeTest method testNeighborTableUpdate.
@Test
public void testNeighborTableUpdate() {
ZigBeeNode node = new ZigBeeNode(Mockito.mock(ZigBeeNetworkManager.class), new IeeeAddress());
Set<NeighborTable> neighbors;
NeighborTable neighbor1 = getNeighborTable(12345, "123456789", 0);
NeighborTable neighbor2 = getNeighborTable(12345, "123456789", 0);
NeighborTable neighbor3 = getNeighborTable(54321, "987654321", 0);
neighbors = new HashSet<NeighborTable>();
neighbors.add(neighbor1);
assertTrue(node.setNeighbors(neighbors));
neighbors = new HashSet<NeighborTable>();
neighbors.add(neighbor2);
assertFalse(node.setNeighbors(neighbors));
neighbors = new HashSet<NeighborTable>();
neighbors.add(neighbor3);
neighbors.add(neighbor1);
assertTrue(node.setNeighbors(neighbors));
neighbors = new HashSet<NeighborTable>();
neighbors.add(neighbor1);
neighbors.add(neighbor3);
assertFalse(node.setNeighbors(neighbors));
assertEquals(2, node.getNeighbors().size());
}
use of com.zsmartsystems.zigbee.zdo.field.NeighborTable in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeNodeServiceDiscoverer method requestNeighborTable.
/**
* Get node neighbor table by making a {@link ManagementLqiRequest} call.
*
* @return list of {@link NeighborTable} if the request was processed ok, null otherwise
* @throws ExecutionException
* @throws InterruptedException
*/
private boolean requestNeighborTable() throws InterruptedException, ExecutionException {
// Start index for the list is 0
int startIndex = 0;
int totalNeighbors = 0;
Set<NeighborTable> neighbors = new HashSet<NeighborTable>();
do {
final ManagementLqiRequest neighborRequest = new ManagementLqiRequest();
neighborRequest.setDestinationAddress(new ZigBeeEndpointAddress(node.getNetworkAddress()));
neighborRequest.setStartIndex(startIndex);
CommandResult response = networkManager.unicast(neighborRequest, neighborRequest).get();
final ManagementLqiResponse neighborResponse = response.getResponse();
logger.debug("{}: Node SVC Discovery ManagementLqiRequest response {}", node.getIeeeAddress(), response);
if (neighborResponse == null) {
return false;
}
if (neighborResponse.getStatus() == ZdoStatus.NOT_SUPPORTED) {
supportsManagementLqi = false;
return true;
} else if (neighborResponse.getStatus() != ZdoStatus.SUCCESS) {
return false;
}
// To avoid a loop, we need to check if there's any response.
if (neighborResponse.getNeighborTableList().size() == 0) {
break;
}
// Save the neighbors
neighbors.addAll(neighborResponse.getNeighborTableList());
// Continue with next request
startIndex += neighborResponse.getNeighborTableList().size();
totalNeighbors = neighborResponse.getNeighborTableEntries();
} while (startIndex < totalNeighbors);
node.setNeighbors(neighbors);
return true;
}
Aggregations