Search in sources :

Example 6 with CommandResult

use of com.zsmartsystems.zigbee.CommandResult in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeNodeServiceDiscoverer method requestNodeDescriptor.

/**
 * Get node descriptor
 *
 * @return true if the message was processed ok
 * @throws ExecutionException
 * @throws InterruptedException
 */
private boolean requestNodeDescriptor() throws InterruptedException, ExecutionException {
    final NodeDescriptorRequest nodeDescriptorRequest = new NodeDescriptorRequest();
    nodeDescriptorRequest.setDestinationAddress(new ZigBeeEndpointAddress(node.getNetworkAddress()));
    nodeDescriptorRequest.setNwkAddrOfInterest(node.getNetworkAddress());
    CommandResult response = networkManager.unicast(nodeDescriptorRequest, nodeDescriptorRequest).get();
    final NodeDescriptorResponse nodeDescriptorResponse = (NodeDescriptorResponse) response.getResponse();
    logger.debug("{}: Node SVC Discovery NodeDescriptorResponse returned {}", node.getIeeeAddress(), nodeDescriptorResponse);
    if (nodeDescriptorResponse == null) {
        return false;
    }
    if (nodeDescriptorResponse.getStatus() == ZdoStatus.SUCCESS) {
        node.setNodeDescriptor(nodeDescriptorResponse.getNodeDescriptor());
        return true;
    }
    return false;
}
Also used : NodeDescriptorResponse(com.zsmartsystems.zigbee.zdo.command.NodeDescriptorResponse) NodeDescriptorRequest(com.zsmartsystems.zigbee.zdo.command.NodeDescriptorRequest) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) CommandResult(com.zsmartsystems.zigbee.CommandResult)

Example 7 with CommandResult

use of com.zsmartsystems.zigbee.CommandResult in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeNodeServiceDiscoverer method requestAssociatedNodes.

/**
 * Get Node Network address and the list of associated devices
 *
 * @return true if the message was processed ok
 * @throws ExecutionException
 * @throws InterruptedException
 */
private boolean requestAssociatedNodes() throws InterruptedException, ExecutionException {
    Integer startIndex = 0;
    int totalAssociatedDevices = 0;
    Set<Integer> associatedDevices = new HashSet<Integer>();
    do {
        // Request extended response, to get associated list
        final IeeeAddressRequest ieeeAddressRequest = new IeeeAddressRequest();
        ieeeAddressRequest.setDestinationAddress(new ZigBeeEndpointAddress(node.getNetworkAddress()));
        ieeeAddressRequest.setRequestType(1);
        ieeeAddressRequest.setStartIndex(startIndex);
        ieeeAddressRequest.setNwkAddrOfInterest(node.getNetworkAddress());
        CommandResult response = networkManager.unicast(ieeeAddressRequest, ieeeAddressRequest).get();
        final IeeeAddressResponse ieeeAddressResponse = response.getResponse();
        logger.debug("{}: Node SVC Discovery IeeeAddressResponse returned {}", node.getIeeeAddress(), ieeeAddressResponse);
        if (ieeeAddressResponse != null && ieeeAddressResponse.getStatus() == ZdoStatus.SUCCESS) {
            associatedDevices.addAll(ieeeAddressResponse.getNwkAddrAssocDevList());
            startIndex += ieeeAddressResponse.getNwkAddrAssocDevList().size();
            totalAssociatedDevices = ieeeAddressResponse.getNwkAddrAssocDevList().size();
        }
    } while (startIndex < totalAssociatedDevices);
    node.setAssociatedDevices(associatedDevices);
    return true;
}
Also used : IeeeAddressResponse(com.zsmartsystems.zigbee.zdo.command.IeeeAddressResponse) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) IeeeAddressRequest(com.zsmartsystems.zigbee.zdo.command.IeeeAddressRequest) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) HashSet(java.util.HashSet) CommandResult(com.zsmartsystems.zigbee.CommandResult)

Example 8 with CommandResult

use of com.zsmartsystems.zigbee.CommandResult in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeNodeServiceDiscoverer method requestNetworkAddress.

/**
 * Get node descriptor
 *
 * @return true if the message was processed ok
 * @throws ExecutionException
 * @throws InterruptedException
 */
private boolean requestNetworkAddress() throws InterruptedException, ExecutionException {
    NetworkAddressRequest networkAddressRequest = new NetworkAddressRequest();
    networkAddressRequest.setIeeeAddr(node.getIeeeAddress());
    networkAddressRequest.setRequestType(0);
    networkAddressRequest.setStartIndex(0);
    networkAddressRequest.setDestinationAddress(new ZigBeeEndpointAddress(ZigBeeBroadcastDestination.BROADCAST_ALL_DEVICES.getKey()));
    CommandResult response = networkManager.unicast(networkAddressRequest, networkAddressRequest).get();
    final NetworkAddressResponse networkAddressResponse = (NetworkAddressResponse) response.getResponse();
    logger.debug("{}: Node SVC Discovery NetworkAddressRequest returned {}", node.getNetworkAddress(), networkAddressResponse);
    if (networkAddressResponse == null) {
        return false;
    }
    if (networkAddressResponse.getStatus() == ZdoStatus.SUCCESS) {
        node.setNetworkAddress(networkAddressResponse.getNwkAddrRemoteDev());
        return true;
    }
    return false;
}
Also used : NetworkAddressRequest(com.zsmartsystems.zigbee.zdo.command.NetworkAddressRequest) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) CommandResult(com.zsmartsystems.zigbee.CommandResult) NetworkAddressResponse(com.zsmartsystems.zigbee.zdo.command.NetworkAddressResponse)

Example 9 with CommandResult

use of com.zsmartsystems.zigbee.CommandResult in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeNodeServiceDiscoverer method requestActiveEndpoints.

/**
 * Get the active endpoints for a node
 *
 * @return true if the message was processed ok
 * @throws ExecutionException
 * @throws InterruptedException
 */
private boolean requestActiveEndpoints() throws InterruptedException, ExecutionException {
    final ActiveEndpointsRequest activeEndpointsRequest = new ActiveEndpointsRequest();
    activeEndpointsRequest.setDestinationAddress(new ZigBeeEndpointAddress(node.getNetworkAddress()));
    activeEndpointsRequest.setNwkAddrOfInterest(node.getNetworkAddress());
    CommandResult response = networkManager.unicast(activeEndpointsRequest, activeEndpointsRequest).get();
    final ActiveEndpointsResponse activeEndpointsResponse = (ActiveEndpointsResponse) response.getResponse();
    logger.debug("{}: Node SVC Discovery ActiveEndpointsResponse returned {}", node.getIeeeAddress(), response);
    if (activeEndpointsResponse == null) {
        return false;
    }
    // Get the simple descriptors for all endpoints
    List<ZigBeeEndpoint> endpoints = new ArrayList<ZigBeeEndpoint>();
    for (final int endpointId : activeEndpointsResponse.getActiveEpList()) {
        ZigBeeEndpoint endpoint = getSimpleDescriptor(endpointId);
        if (endpoint == null) {
            return false;
        }
        endpoints.add(endpoint);
    }
    // All endpoints have been received, so add them to the node
    for (ZigBeeEndpoint endpoint : endpoints) {
        node.addEndpoint(endpoint);
    }
    return true;
}
Also used : ActiveEndpointsRequest(com.zsmartsystems.zigbee.zdo.command.ActiveEndpointsRequest) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) ArrayList(java.util.ArrayList) ActiveEndpointsResponse(com.zsmartsystems.zigbee.zdo.command.ActiveEndpointsResponse) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) CommandResult(com.zsmartsystems.zigbee.CommandResult)

Example 10 with CommandResult

use of com.zsmartsystems.zigbee.CommandResult 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)22 ZigBeeEndpoint (com.zsmartsystems.zigbee.ZigBeeEndpoint)12 ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)10 ZclCluster (com.zsmartsystems.zigbee.zcl.ZclCluster)7 HashSet (java.util.HashSet)7 ExecutionException (java.util.concurrent.ExecutionException)6 ZclAttribute (com.zsmartsystems.zigbee.zcl.ZclAttribute)5 ZclStatus (com.zsmartsystems.zigbee.zcl.ZclStatus)5 IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)3 ReadAttributesResponse (com.zsmartsystems.zigbee.zcl.clusters.general.ReadAttributesResponse)3 Set (java.util.Set)3 TreeSet (java.util.TreeSet)3 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)3 FutureTask (java.util.concurrent.FutureTask)3 ConfigureReportingResponse (com.zsmartsystems.zigbee.zcl.clusters.general.ConfigureReportingResponse)2 IeeeAddressRequest (com.zsmartsystems.zigbee.zdo.command.IeeeAddressRequest)2 IeeeAddressResponse (com.zsmartsystems.zigbee.zdo.command.IeeeAddressResponse)2 NetworkAddressRequest (com.zsmartsystems.zigbee.zdo.command.NetworkAddressRequest)2 NetworkAddressResponse (com.zsmartsystems.zigbee.zdo.command.NetworkAddressResponse)2 CommandResultFuture (com.zsmartsystems.zigbee.CommandResultFuture)1