Search in sources :

Example 1 with ManagementLqiResponse

use of com.zsmartsystems.zigbee.zdo.command.ManagementLqiResponse 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;
}
Also used : ManagementLqiResponse(com.zsmartsystems.zigbee.zdo.command.ManagementLqiResponse) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) NeighborTable(com.zsmartsystems.zigbee.zdo.field.NeighborTable) ManagementLqiRequest(com.zsmartsystems.zigbee.zdo.command.ManagementLqiRequest) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) HashSet(java.util.HashSet) CommandResult(com.zsmartsystems.zigbee.CommandResult)

Aggregations

CommandResult (com.zsmartsystems.zigbee.CommandResult)1 ZigBeeEndpoint (com.zsmartsystems.zigbee.ZigBeeEndpoint)1 ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)1 ManagementLqiRequest (com.zsmartsystems.zigbee.zdo.command.ManagementLqiRequest)1 ManagementLqiResponse (com.zsmartsystems.zigbee.zdo.command.ManagementLqiResponse)1 NeighborTable (com.zsmartsystems.zigbee.zdo.field.NeighborTable)1 HashSet (java.util.HashSet)1