Search in sources :

Example 1 with ManagementRoutingResponse

use of com.zsmartsystems.zigbee.zdo.command.ManagementRoutingResponse in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeNodeServiceDiscoverer method requestRoutingTable.

/**
 * Get node routing table by making a {@link ManagementRoutingRequest} request
 *
 * @return list of {@link RoutingTable} if the request was processed ok, null otherwise
 * @throws ExecutionException
 * @throws InterruptedException
 */
private boolean requestRoutingTable() throws InterruptedException, ExecutionException {
    // Start index for the list is 0
    int startIndex = 0;
    int totalRoutes = 0;
    Set<RoutingTable> routes = new HashSet<RoutingTable>();
    do {
        final ManagementRoutingRequest routeRequest = new ManagementRoutingRequest();
        routeRequest.setDestinationAddress(new ZigBeeEndpointAddress(node.getNetworkAddress()));
        routeRequest.setStartIndex(startIndex);
        CommandResult response = networkManager.unicast(routeRequest, routeRequest).get();
        final ManagementRoutingResponse routingResponse = response.getResponse();
        logger.debug("{}: Node SVC Discovery ManagementRoutingRequest returned {}", node.getIeeeAddress(), response);
        if (routingResponse == null) {
            return false;
        }
        if (routingResponse.getStatus() == ZdoStatus.NOT_SUPPORTED) {
            supportsManagementRouting = false;
            return true;
        } else if (routingResponse.getStatus() != ZdoStatus.SUCCESS) {
            return false;
        }
        // Save the routes
        routes.addAll(routingResponse.getRoutingTableList());
        // Continue with next request
        startIndex += routingResponse.getRoutingTableList().size();
        totalRoutes = routingResponse.getRoutingTableEntries();
    } while (startIndex < totalRoutes);
    node.setRoutes(routes);
    return true;
}
Also used : ManagementRoutingResponse(com.zsmartsystems.zigbee.zdo.command.ManagementRoutingResponse) RoutingTable(com.zsmartsystems.zigbee.zdo.field.RoutingTable) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) HashSet(java.util.HashSet) ManagementRoutingRequest(com.zsmartsystems.zigbee.zdo.command.ManagementRoutingRequest) CommandResult(com.zsmartsystems.zigbee.CommandResult)

Aggregations

CommandResult (com.zsmartsystems.zigbee.CommandResult)1 ZigBeeEndpoint (com.zsmartsystems.zigbee.ZigBeeEndpoint)1 ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)1 ManagementRoutingRequest (com.zsmartsystems.zigbee.zdo.command.ManagementRoutingRequest)1 ManagementRoutingResponse (com.zsmartsystems.zigbee.zdo.command.ManagementRoutingResponse)1 RoutingTable (com.zsmartsystems.zigbee.zdo.field.RoutingTable)1 HashSet (java.util.HashSet)1