Search in sources :

Example 1 with IeeeAddressRequest

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

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

the class ZigBeeNetworkDiscoverer method getIeeeAddress.

/**
 * Get Node IEEE address
 *
 * @param networkAddress the network address of the node
 * @return true if the message was processed ok
 */
private boolean getIeeeAddress(final int networkAddress) {
    try {
        Integer startIndex = 0;
        int totalAssociatedDevices = 0;
        Set<Integer> associatedDevices = new HashSet<Integer>();
        IeeeAddress ieeeAddress = null;
        do {
            // Request extended response, start index for associated list is 0
            final IeeeAddressRequest ieeeAddressRequest = new IeeeAddressRequest();
            ieeeAddressRequest.setDestinationAddress(new ZigBeeEndpointAddress(networkAddress));
            ieeeAddressRequest.setRequestType(1);
            ieeeAddressRequest.setStartIndex(startIndex);
            ieeeAddressRequest.setNwkAddrOfInterest(networkAddress);
            CommandResult response = networkManager.unicast(ieeeAddressRequest, ieeeAddressRequest).get();
            if (response.isError()) {
                return false;
            }
            final IeeeAddressResponse ieeeAddressResponse = response.getResponse();
            logger.debug("{}: NWK Discovery IeeeAddressRequest returned {}", networkAddress, ieeeAddressResponse);
            if (ieeeAddressResponse != null && ieeeAddressResponse.getStatus() == ZdoStatus.SUCCESS) {
                ieeeAddress = ieeeAddressResponse.getIeeeAddrRemoteDev();
                if (startIndex.equals(ieeeAddressResponse.getStartIndex())) {
                    associatedDevices.addAll(ieeeAddressResponse.getNwkAddrAssocDevList());
                    startIndex += ieeeAddressResponse.getNwkAddrAssocDevList().size();
                    totalAssociatedDevices = ieeeAddressResponse.getNwkAddrAssocDevList().size();
                }
            }
        } while (startIndex < totalAssociatedDevices);
        addNode(ieeeAddress, networkAddress);
        // Start discovery for any associated nodes
        for (final int deviceNetworkAddress : associatedDevices) {
            startNodeDiscovery(deviceNetworkAddress);
        }
    } catch (InterruptedException | ExecutionException e) {
        logger.debug("NWK Discovery Error in checkIeeeAddressResponse ", e);
    }
    return true;
}
Also used : IeeeAddressResponse(com.zsmartsystems.zigbee.zdo.command.IeeeAddressResponse) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) IeeeAddressRequest(com.zsmartsystems.zigbee.zdo.command.IeeeAddressRequest) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) CommandResult(com.zsmartsystems.zigbee.CommandResult)

Aggregations

CommandResult (com.zsmartsystems.zigbee.CommandResult)2 ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)2 IeeeAddressRequest (com.zsmartsystems.zigbee.zdo.command.IeeeAddressRequest)2 IeeeAddressResponse (com.zsmartsystems.zigbee.zdo.command.IeeeAddressResponse)2 HashSet (java.util.HashSet)2 IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)1 ZigBeeEndpoint (com.zsmartsystems.zigbee.ZigBeeEndpoint)1 ExecutionException (java.util.concurrent.ExecutionException)1