Search in sources :

Example 31 with ZigBeeEndpointAddress

use of com.zsmartsystems.zigbee.ZigBeeEndpointAddress 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)

Example 32 with ZigBeeEndpointAddress

use of com.zsmartsystems.zigbee.ZigBeeEndpointAddress 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)

Example 33 with ZigBeeEndpointAddress

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

the class ZigBeeNodeServiceDiscoverer method requestPowerDescriptor.

/**
 * Get node power descriptor
 *
 * @return true if the message was processed ok, or if the end device does not support the power descriptor
 * @throws ExecutionException
 * @throws InterruptedException
 */
private boolean requestPowerDescriptor() throws InterruptedException, ExecutionException {
    final PowerDescriptorRequest powerDescriptorRequest = new PowerDescriptorRequest();
    powerDescriptorRequest.setDestinationAddress(new ZigBeeEndpointAddress(node.getNetworkAddress()));
    powerDescriptorRequest.setNwkAddrOfInterest(node.getNetworkAddress());
    CommandResult response = networkManager.unicast(powerDescriptorRequest, powerDescriptorRequest).get();
    final PowerDescriptorResponse powerDescriptorResponse = (PowerDescriptorResponse) response.getResponse();
    logger.debug("{}: Node SVC Discovery PowerDescriptorResponse returned {}", node.getIeeeAddress(), powerDescriptorResponse);
    if (powerDescriptorResponse == null) {
        return false;
    }
    if (powerDescriptorResponse.getStatus() == ZdoStatus.SUCCESS) {
        node.setPowerDescriptor(powerDescriptorResponse.getPowerDescriptor());
        return true;
    } else if (powerDescriptorResponse.getStatus() == ZdoStatus.NOT_SUPPORTED) {
        return true;
    }
    return false;
}
Also used : PowerDescriptorRequest(com.zsmartsystems.zigbee.zdo.command.PowerDescriptorRequest) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) PowerDescriptorResponse(com.zsmartsystems.zigbee.zdo.command.PowerDescriptorResponse) CommandResult(com.zsmartsystems.zigbee.CommandResult)

Example 34 with ZigBeeEndpointAddress

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

the class ZigBeeNodeServiceDiscoverer method getSimpleDescriptor.

/**
 * Get the simple descriptor for an endpoint and create the {@link ZigBeeEndpoint}
 *
 * @param endpointId the endpoint id to request
 * @return the newly created {@link ZigBeeEndpoint} for the endpoint, or null on error
 * @throws ExecutionException
 * @throws InterruptedException
 */
private ZigBeeEndpoint getSimpleDescriptor(final int endpointId) throws InterruptedException, ExecutionException {
    final SimpleDescriptorRequest simpleDescriptorRequest = new SimpleDescriptorRequest();
    simpleDescriptorRequest.setDestinationAddress(new ZigBeeEndpointAddress(node.getNetworkAddress()));
    simpleDescriptorRequest.setNwkAddrOfInterest(node.getNetworkAddress());
    simpleDescriptorRequest.setEndpoint(endpointId);
    CommandResult response = networkManager.unicast(simpleDescriptorRequest, simpleDescriptorRequest).get();
    final SimpleDescriptorResponse simpleDescriptorResponse = (SimpleDescriptorResponse) response.getResponse();
    logger.debug("{}: Node SVC Discovery SimpleDescriptorResponse returned {}", node.getIeeeAddress(), simpleDescriptorResponse);
    if (simpleDescriptorResponse == null) {
        return null;
    }
    if (simpleDescriptorResponse.getStatus() == ZdoStatus.SUCCESS) {
        ZigBeeEndpoint endpoint = new ZigBeeEndpoint(networkManager, node, endpointId);
        SimpleDescriptor simpleDescriptor = simpleDescriptorResponse.getSimpleDescriptor();
        endpoint.setProfileId(simpleDescriptor.getProfileId());
        endpoint.setDeviceId(simpleDescriptor.getDeviceId());
        endpoint.setDeviceVersion(simpleDescriptor.getDeviceVersion());
        endpoint.setInputClusterIds(simpleDescriptor.getInputClusterList());
        endpoint.setOutputClusterIds(simpleDescriptor.getOutputClusterList());
        return endpoint;
    }
    return null;
}
Also used : SimpleDescriptorResponse(com.zsmartsystems.zigbee.zdo.command.SimpleDescriptorResponse) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) SimpleDescriptorRequest(com.zsmartsystems.zigbee.zdo.command.SimpleDescriptorRequest) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) CommandResult(com.zsmartsystems.zigbee.CommandResult) SimpleDescriptor(com.zsmartsystems.zigbee.zdo.field.SimpleDescriptor)

Example 35 with ZigBeeEndpointAddress

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

the class ZclCluster method bind.

/**
 * Adds a binding from the cluster to the destination {@link ZigBeeEndpoint}.
 *
 * @param address the destination {@link IeeeAddress}
 * @param endpointId the destination endpoint ID
 * @return Command future
 */
public Future<CommandResult> bind(IeeeAddress address, int endpointId) {
    final BindRequest command = new BindRequest();
    command.setDestinationAddress(new ZigBeeEndpointAddress(zigbeeEndpoint.getEndpointAddress().getAddress()));
    command.setSrcAddress(zigbeeEndpoint.getIeeeAddress());
    command.setSrcEndpoint(zigbeeEndpoint.getEndpointId());
    command.setBindCluster(clusterId);
    // 64 bit addressing
    command.setDstAddrMode(3);
    command.setDstAddress(address);
    command.setDstEndpoint(endpointId);
    return zigbeeManager.unicast(command, new BindRequest());
}
Also used : ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) BindRequest(com.zsmartsystems.zigbee.zdo.command.BindRequest)

Aggregations

ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)35 Test (org.junit.Test)20 CommandResult (com.zsmartsystems.zigbee.CommandResult)10 ArrayList (java.util.ArrayList)10 ZigBeeEndpoint (com.zsmartsystems.zigbee.ZigBeeEndpoint)9 DefaultSerializer (com.zsmartsystems.zigbee.serialization.DefaultSerializer)8 ZclFieldSerializer (com.zsmartsystems.zigbee.zcl.ZclFieldSerializer)8 CommandTest (com.zsmartsystems.zigbee.CommandTest)6 IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)6 HashSet (java.util.HashSet)5 ZigBeeNode (com.zsmartsystems.zigbee.ZigBeeNode)4 MatchDescriptorRequest (com.zsmartsystems.zigbee.zdo.command.MatchDescriptorRequest)4 ZigBeeCommand (com.zsmartsystems.zigbee.ZigBeeCommand)3 ZigBeeSerializer (com.zsmartsystems.zigbee.serialization.ZigBeeSerializer)3 ZclOnOffCluster (com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster)3 BindRequest (com.zsmartsystems.zigbee.zdo.command.BindRequest)3 IeeeAddressResponse (com.zsmartsystems.zigbee.zdo.command.IeeeAddressResponse)3 ConBeeEnqueueSendDataRequest (com.zsmartsystems.zigbee.dongle.conbee.internal.frame.ConBeeEnqueueSendDataRequest)2 EzspFrameTest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.EzspFrameTest)2 EmberApsFrame (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberApsFrame)2