use of com.zsmartsystems.zigbee.zdo.command.ManagementLqiRequest 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