Search in sources :

Example 1 with IeeeAddressResponse

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

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

the class ZigBeeNetworkDiscovererTest method testNormal.

@Ignore
@Test
public void testNormal() {
    // Add all the required responses to a list
    IeeeAddressResponse ieeeResponse = new IeeeAddressResponse();
    ieeeResponse.setStatus(ZdoStatus.SUCCESS);
    ieeeResponse.setSourceAddress(new ZigBeeEndpointAddress(0));
    ieeeResponse.setDestinationAddress(new ZigBeeEndpointAddress(0));
    ieeeResponse.setIeeeAddrRemoteDev(new IeeeAddress("1234567890ABCDEF"));
    responses.put(ZdoCommandType.IEEE_ADDRESS_REQUEST.getClusterId(), ieeeResponse);
    NodeDescriptorResponse nodeResponse = new NodeDescriptorResponse();
    nodeResponse.setStatus(ZdoStatus.SUCCESS);
    nodeResponse.setSourceAddress(new ZigBeeEndpointAddress(0));
    nodeResponse.setDestinationAddress(new ZigBeeEndpointAddress(0));
    nodeResponse.setNwkAddrOfInterest(0);
    NodeDescriptor nodeDescriptor = new NodeDescriptor();
    nodeResponse.setNodeDescriptor(nodeDescriptor);
    responses.put(ZdoCommandType.NODE_DESCRIPTOR_REQUEST.getClusterId(), nodeResponse);
    PowerDescriptorResponse powerResponse = new PowerDescriptorResponse();
    powerResponse.setStatus(ZdoStatus.SUCCESS);
    powerResponse.setSourceAddress(new ZigBeeEndpointAddress(0));
    powerResponse.setDestinationAddress(new ZigBeeEndpointAddress(0));
    powerResponse.setNwkAddrOfInterest(0);
    PowerDescriptor powerDescriptor = new PowerDescriptor();
    powerResponse.setPowerDescriptor(powerDescriptor);
    responses.put(ZdoCommandType.POWER_DESCRIPTOR_REQUEST.getClusterId(), powerResponse);
    ActiveEndpointsResponse endpointsResponse = new ActiveEndpointsResponse();
    endpointsResponse.setStatus(ZdoStatus.SUCCESS);
    endpointsResponse.setSourceAddress(new ZigBeeEndpointAddress(0));
    endpointsResponse.setDestinationAddress(new ZigBeeEndpointAddress(0));
    endpointsResponse.setNwkAddrOfInterest(0);
    List<Integer> activeEpList = new ArrayList<Integer>();
    activeEpList.add(1);
    endpointsResponse.setActiveEpList(activeEpList);
    responses.put(ZdoCommandType.ACTIVE_ENDPOINTS_REQUEST.getClusterId(), endpointsResponse);
    SimpleDescriptorResponse simpleResponse = new SimpleDescriptorResponse();
    simpleResponse.setStatus(ZdoStatus.SUCCESS);
    simpleResponse.setSourceAddress(new ZigBeeEndpointAddress(0));
    simpleResponse.setDestinationAddress(new ZigBeeEndpointAddress(0, 1));
    simpleResponse.setNwkAddrOfInterest(0);
    SimpleDescriptor simpleDescriptor = new SimpleDescriptor();
    simpleDescriptor.setDeviceId(0);
    simpleDescriptor.setDeviceVersion(0);
    simpleDescriptor.setEndpoint(1);
    simpleDescriptor.setProfileId(0x104);
    List<Integer> inputClusterList = new ArrayList<Integer>();
    List<Integer> outputClusterList = new ArrayList<Integer>();
    simpleDescriptor.setInputClusterList(inputClusterList);
    simpleDescriptor.setOutputClusterList(outputClusterList);
    simpleResponse.setSimpleDescriptor(simpleDescriptor);
    responses.put(ZdoCommandType.SIMPLE_DESCRIPTOR_REQUEST.getClusterId(), simpleResponse);
    ZigBeeNetworkDiscoverer discoverer = new ZigBeeNetworkDiscoverer(networkManager);
    discoverer.setRetryPeriod(1);
    discoverer.startup();
    // Check that the listener registers for startup notifications
    Mockito.verify(networkManager).addNetworkStateListener(discoverer);
    // Put the system online so it initialises
    discoverer.networkStateUpdated(ZigBeeTransportState.ONLINE);
    // Check it registers listeners
    Mockito.verify(networkManager).addCommandListener(discoverer);
    Mockito.verify(networkManager).addAnnounceListener(discoverer);
    // Then wait for the node to be added
    Mockito.verify(networkManager, Mockito.timeout(5000).times(1)).addNode(nodeCapture.capture());
    ZigBeeNode node = nodeCapture.getValue();
    assertNotNull(node);
    assertEquals(Integer.valueOf(0), node.getNetworkAddress());
    assertEquals(new IeeeAddress("1234567890ABCDEF"), node.getIeeeAddress());
    assertEquals(1, node.getEndpoints().size());
}
Also used : IeeeAddressResponse(com.zsmartsystems.zigbee.zdo.command.IeeeAddressResponse) PowerDescriptorResponse(com.zsmartsystems.zigbee.zdo.command.PowerDescriptorResponse) NodeDescriptor(com.zsmartsystems.zigbee.zdo.field.NodeDescriptor) ArrayList(java.util.ArrayList) ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode) ActiveEndpointsResponse(com.zsmartsystems.zigbee.zdo.command.ActiveEndpointsResponse) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) SimpleDescriptor(com.zsmartsystems.zigbee.zdo.field.SimpleDescriptor) SimpleDescriptorResponse(com.zsmartsystems.zigbee.zdo.command.SimpleDescriptorResponse) NodeDescriptorResponse(com.zsmartsystems.zigbee.zdo.command.NodeDescriptorResponse) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) PowerDescriptor(com.zsmartsystems.zigbee.zdo.field.PowerDescriptor) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with IeeeAddressResponse

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

ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)3 IeeeAddressResponse (com.zsmartsystems.zigbee.zdo.command.IeeeAddressResponse)3 CommandResult (com.zsmartsystems.zigbee.CommandResult)2 IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)2 IeeeAddressRequest (com.zsmartsystems.zigbee.zdo.command.IeeeAddressRequest)2 HashSet (java.util.HashSet)2 ZigBeeEndpoint (com.zsmartsystems.zigbee.ZigBeeEndpoint)1 ZigBeeNode (com.zsmartsystems.zigbee.ZigBeeNode)1 ActiveEndpointsResponse (com.zsmartsystems.zigbee.zdo.command.ActiveEndpointsResponse)1 NodeDescriptorResponse (com.zsmartsystems.zigbee.zdo.command.NodeDescriptorResponse)1 PowerDescriptorResponse (com.zsmartsystems.zigbee.zdo.command.PowerDescriptorResponse)1 SimpleDescriptorResponse (com.zsmartsystems.zigbee.zdo.command.SimpleDescriptorResponse)1 NodeDescriptor (com.zsmartsystems.zigbee.zdo.field.NodeDescriptor)1 PowerDescriptor (com.zsmartsystems.zigbee.zdo.field.PowerDescriptor)1 SimpleDescriptor (com.zsmartsystems.zigbee.zdo.field.SimpleDescriptor)1 ArrayList (java.util.ArrayList)1 ExecutionException (java.util.concurrent.ExecutionException)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1