Search in sources :

Example 6 with NeighborTable

use of com.zsmartsystems.zigbee.zdo.field.NeighborTable in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeNodeTest method testNeighborTableUpdate.

@Test
public void testNeighborTableUpdate() {
    ZigBeeNode node = new ZigBeeNode(Mockito.mock(ZigBeeNetworkManager.class), new IeeeAddress());
    Set<NeighborTable> neighbors;
    NeighborTable neighbor1 = getNeighborTable(12345, "123456789", 0);
    NeighborTable neighbor2 = getNeighborTable(12345, "123456789", 0);
    NeighborTable neighbor3 = getNeighborTable(54321, "987654321", 0);
    neighbors = new HashSet<NeighborTable>();
    neighbors.add(neighbor1);
    assertTrue(node.setNeighbors(neighbors));
    neighbors = new HashSet<NeighborTable>();
    neighbors.add(neighbor2);
    assertFalse(node.setNeighbors(neighbors));
    neighbors = new HashSet<NeighborTable>();
    neighbors.add(neighbor3);
    neighbors.add(neighbor1);
    assertTrue(node.setNeighbors(neighbors));
    neighbors = new HashSet<NeighborTable>();
    neighbors.add(neighbor1);
    neighbors.add(neighbor3);
    assertFalse(node.setNeighbors(neighbors));
    assertEquals(2, node.getNeighbors().size());
}
Also used : NeighborTable(com.zsmartsystems.zigbee.zdo.field.NeighborTable) Test(org.junit.Test)

Example 7 with NeighborTable

use of com.zsmartsystems.zigbee.zdo.field.NeighborTable 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)

Aggregations

NeighborTable (com.zsmartsystems.zigbee.zdo.field.NeighborTable)7 IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)2 ZigBeeEndpoint (com.zsmartsystems.zigbee.ZigBeeEndpoint)2 DefaultDeserializer (com.zsmartsystems.zigbee.serialization.DefaultDeserializer)2 RoutingTable (com.zsmartsystems.zigbee.zdo.field.RoutingTable)2 Test (org.junit.Test)2 CommandResult (com.zsmartsystems.zigbee.CommandResult)1 CommandTest (com.zsmartsystems.zigbee.CommandTest)1 ExtendedPanId (com.zsmartsystems.zigbee.ExtendedPanId)1 ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)1 ZigBeeNode (com.zsmartsystems.zigbee.ZigBeeNode)1 ZclFieldDeserializer (com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer)1 ByteArray (com.zsmartsystems.zigbee.zcl.field.ByteArray)1 ManagementLqiRequest (com.zsmartsystems.zigbee.zdo.command.ManagementLqiRequest)1 ManagementLqiResponse (com.zsmartsystems.zigbee.zdo.command.ManagementLqiResponse)1 BindingTable (com.zsmartsystems.zigbee.zdo.field.BindingTable)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 Field (java.lang.reflect.Field)1