Search in sources :

Example 1 with NetworkAddressRequest

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

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

the class ZigBeeNetworkDiscoverer method rediscoverNode.

/**
 * Starts a discovery on a node. This will send a {@link NetworkAddressRequest} as a broadcast and will receive
 * the response to trigger a full discovery.
 *
 * @param ieeeAddress the {@link IeeeAddress} of the node to discover
 */
public void rediscoverNode(final IeeeAddress ieeeAddress) {
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            logger.debug("{}: NWK Discovery starting node rediscovery", ieeeAddress);
            int retries = 0;
            try {
                do {
                    if (Thread.currentThread().isInterrupted()) {
                        break;
                    }
                    NetworkAddressRequest request = new NetworkAddressRequest();
                    request.setIeeeAddr(ieeeAddress);
                    request.setRequestType(0);
                    request.setStartIndex(0);
                    request.setDestinationAddress(new ZigBeeEndpointAddress(ZigBeeBroadcastDestination.BROADCAST_RX_ON.getKey()));
                    CommandResult response;
                    response = networkManager.unicast(request, request).get();
                    final NetworkAddressResponse nwkAddressResponse = response.getResponse();
                    if (nwkAddressResponse != null && nwkAddressResponse.getStatus() == ZdoStatus.SUCCESS) {
                        startNodeDiscovery(nwkAddressResponse.getNwkAddrRemoteDev());
                        break;
                    }
                    // We failed with the last request. Wait a bit then retry
                    try {
                        logger.debug("{}: NWK Discovery node rediscovery request failed. Wait before retry.", ieeeAddress);
                        Thread.sleep(retryPeriod);
                    } catch (InterruptedException e) {
                        break;
                    }
                } while (retries++ < retryCount);
            } catch (InterruptedException | ExecutionException e) {
                logger.debug("NWK Discovery error in rediscoverNode ", e);
            }
            logger.debug("{}: NWK Discovery finishing node rediscovery", ieeeAddress);
        }
    };
    networkManager.executeTask(runnable);
}
Also used : NetworkAddressRequest(com.zsmartsystems.zigbee.zdo.command.NetworkAddressRequest) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) ExecutionException(java.util.concurrent.ExecutionException) CommandResult(com.zsmartsystems.zigbee.CommandResult) NetworkAddressResponse(com.zsmartsystems.zigbee.zdo.command.NetworkAddressResponse)

Aggregations

CommandResult (com.zsmartsystems.zigbee.CommandResult)2 ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)2 NetworkAddressRequest (com.zsmartsystems.zigbee.zdo.command.NetworkAddressRequest)2 NetworkAddressResponse (com.zsmartsystems.zigbee.zdo.command.NetworkAddressResponse)2 ExecutionException (java.util.concurrent.ExecutionException)1