@Test public void updateBindingTable() throws InterruptedException, ExecutionException { System.out.println("--- " + Thread.currentThread().getStackTrace()[1].getMethodName()); ZigBeeNetworkManager networkManager = getMocketNetworkManager(); Map<Integer, ZigBeeCommand> responses = new HashMap<Integer, ZigBeeCommand>(); Mockito.doAnswer(new Answer<Future<CommandResult>>() { @Override public Future<CommandResult> answer(InvocationOnMock invocation) { ZigBeeCommand command = (ZigBeeCommand) invocation.getArguments()[0]; ZigBeeTransactionFuture commandFuture = new ZigBeeTransactionFuture( Mockito.mock(ZigBeeTransaction.class)); CommandResult result = new CommandResult(responses.get(command.getClusterId())); commandFuture.set(result); return commandFuture; } }).when(networkManager).sendTransaction(ArgumentMatchers.any(ZigBeeCommand.class), ArgumentMatchers.any(ZigBeeTransactionMatcher.class)); ZigBeeNode node = new ZigBeeNode(networkManager, new IeeeAddress("1234567890")); assertTrue(node.setNetworkAddress(1)); ManagementBindResponse nodeResponse = new ManagementBindResponse(ZdoStatus.NOT_SUPPORTED, null, null, null); nodeResponse.setSourceAddress(new ZigBeeEndpointAddress(123)); nodeResponse.setDestinationAddress(new ZigBeeEndpointAddress(0)); responses.put(ZdoCommandType.MANAGEMENT_BIND_REQUEST.getClusterId(), nodeResponse); Future<ZigBeeStatus> future = node.updateBindingTable(); assertEquals(ZigBeeStatus.UNSUPPORTED, future.get()); nodeResponse = new ManagementBindResponse(ZdoStatus.NOT_PERMITTED, null, null, null); nodeResponse.setSourceAddress(new ZigBeeEndpointAddress(123)); nodeResponse.setDestinationAddress(new ZigBeeEndpointAddress(0)); responses.put(ZdoCommandType.MANAGEMENT_BIND_REQUEST.getClusterId(), nodeResponse); future = node.updateBindingTable(); assertEquals(ZigBeeStatus.INVALID_STATE, future.get()); nodeResponse = new ManagementBindResponse(ZdoStatus.NO_DESCRIPTOR, null, null, null); nodeResponse.setSourceAddress(new ZigBeeEndpointAddress(123)); nodeResponse.setDestinationAddress(new ZigBeeEndpointAddress(0)); responses.put(ZdoCommandType.MANAGEMENT_BIND_REQUEST.getClusterId(), nodeResponse); future = node.updateBindingTable(); assertEquals(ZigBeeStatus.FAILURE, future.get()); }
public Future<ZigBeeStatus> updateBindingTable() { RunnableFuture<ZigBeeStatus> future = new FutureTask<ZigBeeStatus>(new Callable<ZigBeeStatus>() { @Override public ZigBeeStatus call() throws Exception { int index = 0; int tableSize = 0; List<BindingTable> bindingTable = new ArrayList<>(); do { ManagementBindRequest bindingRequest = new ManagementBindRequest(index); bindingRequest.setDestinationAddress(new ZigBeeEndpointAddress(getNetworkAddress())); CommandResult result = networkManager.sendTransaction(bindingRequest, bindingRequest).get(); if (result.isTimeout()) { return ZigBeeStatus.FAILURE; } ManagementBindResponse response = (ManagementBindResponse) result.getResponse(); if (response.getStatus() == ZdoStatus.NOT_SUPPORTED) { return ZigBeeStatus.UNSUPPORTED; } if (response.getStatus() == ZdoStatus.NOT_PERMITTED) { return ZigBeeStatus.INVALID_STATE; } if (response.getStatus() != ZdoStatus.SUCCESS) { return ZigBeeStatus.FAILURE; } if (response.getStartIndex() == index) { tableSize = response.getBindingTableEntries(); index += response.getBindingTableList().size(); bindingTable.addAll(response.getBindingTableList()); } } while (index < tableSize); setBindingTable(bindingTable); return ZigBeeStatus.SUCCESS; } }); new Thread(future, "UpdateBindingTable" + getIeeeAddress()).start(); return future; }
ZigBeeNode { public Future<ZigBeeStatus> updateBindingTable() { RunnableFuture<ZigBeeStatus> future = new FutureTask<ZigBeeStatus>(new Callable<ZigBeeStatus>() { @Override public ZigBeeStatus call() throws Exception { int index = 0; int tableSize = 0; List<BindingTable> bindingTable = new ArrayList<>(); do { ManagementBindRequest bindingRequest = new ManagementBindRequest(index); bindingRequest.setDestinationAddress(new ZigBeeEndpointAddress(getNetworkAddress())); CommandResult result = networkManager.sendTransaction(bindingRequest, bindingRequest).get(); if (result.isTimeout()) { return ZigBeeStatus.FAILURE; } ManagementBindResponse response = (ManagementBindResponse) result.getResponse(); if (response.getStatus() == ZdoStatus.NOT_SUPPORTED) { return ZigBeeStatus.UNSUPPORTED; } if (response.getStatus() == ZdoStatus.NOT_PERMITTED) { return ZigBeeStatus.INVALID_STATE; } if (response.getStatus() != ZdoStatus.SUCCESS) { return ZigBeeStatus.FAILURE; } if (response.getStartIndex() == index) { tableSize = response.getBindingTableEntries(); index += response.getBindingTableList().size(); bindingTable.addAll(response.getBindingTableList()); } } while (index < tableSize); setBindingTable(bindingTable); return ZigBeeStatus.SUCCESS; } }); new Thread(future, "UpdateBindingTable" + getIeeeAddress()).start(); return future; } }
ZigBeeNode { public Future<ZigBeeStatus> updateBindingTable() { RunnableFuture<ZigBeeStatus> future = new FutureTask<ZigBeeStatus>(new Callable<ZigBeeStatus>() { @Override public ZigBeeStatus call() throws Exception { int index = 0; int tableSize = 0; List<BindingTable> bindingTable = new ArrayList<>(); do { ManagementBindRequest bindingRequest = new ManagementBindRequest(index); bindingRequest.setDestinationAddress(new ZigBeeEndpointAddress(getNetworkAddress())); CommandResult result = networkManager.sendTransaction(bindingRequest, bindingRequest).get(); if (result.isTimeout()) { return ZigBeeStatus.FAILURE; } ManagementBindResponse response = (ManagementBindResponse) result.getResponse(); if (response.getStatus() == ZdoStatus.NOT_SUPPORTED) { return ZigBeeStatus.UNSUPPORTED; } if (response.getStatus() == ZdoStatus.NOT_PERMITTED) { return ZigBeeStatus.INVALID_STATE; } if (response.getStatus() != ZdoStatus.SUCCESS) { return ZigBeeStatus.FAILURE; } if (response.getStartIndex() == index) { tableSize = response.getBindingTableEntries(); index += response.getBindingTableList().size(); bindingTable.addAll(response.getBindingTableList()); } } while (index < tableSize); setBindingTable(bindingTable); return ZigBeeStatus.SUCCESS; } }); new Thread(future, "UpdateBindingTable" + getIeeeAddress()).start(); return future; } ZigBeeNode(ZigBeeNetworkManager networkManager, IeeeAddress ieeeAddress);  ZigBeeNode(ZigBeeNetworkManager networkManager, IeeeAddress ieeeAddress, Integer networkAddress); }
ZigBeeNode { public Future<ZigBeeStatus> updateBindingTable() { RunnableFuture<ZigBeeStatus> future = new FutureTask<ZigBeeStatus>(new Callable<ZigBeeStatus>() { @Override public ZigBeeStatus call() throws Exception { int index = 0; int tableSize = 0; List<BindingTable> bindingTable = new ArrayList<>(); do { ManagementBindRequest bindingRequest = new ManagementBindRequest(index); bindingRequest.setDestinationAddress(new ZigBeeEndpointAddress(getNetworkAddress())); CommandResult result = networkManager.sendTransaction(bindingRequest, bindingRequest).get(); if (result.isTimeout()) { return ZigBeeStatus.FAILURE; } ManagementBindResponse response = (ManagementBindResponse) result.getResponse(); if (response.getStatus() == ZdoStatus.NOT_SUPPORTED) { return ZigBeeStatus.UNSUPPORTED; } if (response.getStatus() == ZdoStatus.NOT_PERMITTED) { return ZigBeeStatus.INVALID_STATE; } if (response.getStatus() != ZdoStatus.SUCCESS) { return ZigBeeStatus.FAILURE; } if (response.getStartIndex() == index) { tableSize = response.getBindingTableEntries(); index += response.getBindingTableList().size(); bindingTable.addAll(response.getBindingTableList()); } } while (index < tableSize); setBindingTable(bindingTable); return ZigBeeStatus.SUCCESS; } }); new Thread(future, "UpdateBindingTable" + getIeeeAddress()).start(); return future; } ZigBeeNode(ZigBeeNetworkManager networkManager, IeeeAddress ieeeAddress);  ZigBeeNode(ZigBeeNetworkManager networkManager, IeeeAddress ieeeAddress, Integer networkAddress); void shutdown(); IeeeAddress getIeeeAddress(); boolean setNetworkAddress(Integer networkAddress); Integer getNetworkAddress(); void setNodeDescriptor(NodeDescriptor nodeDescriptor); NodeDescriptor getNodeDescriptor(); void setPowerDescriptor(PowerDescriptor powerDescriptor); PowerDescriptor getPowerDescriptor(); void permitJoin(final int duration); void permitJoin(final boolean enable); @Deprecated boolean isFullFuntionDevice(); boolean isFullFunctionDevice(); @Deprecated boolean isReducedFuntionDevice(); boolean isReducedFunctionDevice(); boolean isSecurityCapable(); boolean isPrimaryTrustCenter(); LogicalType getLogicalType(); Set<BindingTable> getBindingTable(); Future<ZigBeeStatus> updateBindingTable(); Collection<ZigBeeEndpoint> getEndpoints(); ZigBeeEndpoint getEndpoint(final int endpointId); void addEndpoint(final ZigBeeEndpoint endpoint); void updateEndpoint(final ZigBeeEndpoint endpoint); void removeEndpoint(final int endpointId); void addNetworkEndpointListener(final ZigBeeNetworkEndpointListener networkDeviceListener); void removeNetworkEndpointListener(final ZigBeeNetworkEndpointListener networkDeviceListener); Set<NeighborTable> getNeighbors(); boolean setNeighbors(Set<NeighborTable> neighbors); Set<Integer> getAssociatedDevices(); boolean setAssociatedDevices(Set<Integer> associatedDevices); Collection<RoutingTable> getRoutes(); boolean setRoutes(Set<RoutingTable> routes); void setLastUpdateTime(); Date getLastUpdateTime(); void commandReceived(ZigBeeCommand command, Integer rssi, Integer lqi); boolean isDiscovered(); ZigBeeNodeDao getDao(); void setDao(ZigBeeNodeDao dao); void sendTransaction(ZigBeeCommand command); Future<CommandResult> sendTransaction(ZigBeeCommand command, ZigBeeTransactionMatcher responseMatcher); boolean setNodeState(ZigBeeNodeState state); ZigBeeNodeState getNodeState(); NotificationService getNotificationService(); ZigBeeLinkQualityStatistics getLinkQualityStatistics(); @Override String toString(); }
ZigBeeNode { public Future<ZigBeeStatus> updateBindingTable() { RunnableFuture<ZigBeeStatus> future = new FutureTask<ZigBeeStatus>(new Callable<ZigBeeStatus>() { @Override public ZigBeeStatus call() throws Exception { int index = 0; int tableSize = 0; List<BindingTable> bindingTable = new ArrayList<>(); do { ManagementBindRequest bindingRequest = new ManagementBindRequest(index); bindingRequest.setDestinationAddress(new ZigBeeEndpointAddress(getNetworkAddress())); CommandResult result = networkManager.sendTransaction(bindingRequest, bindingRequest).get(); if (result.isTimeout()) { return ZigBeeStatus.FAILURE; } ManagementBindResponse response = (ManagementBindResponse) result.getResponse(); if (response.getStatus() == ZdoStatus.NOT_SUPPORTED) { return ZigBeeStatus.UNSUPPORTED; } if (response.getStatus() == ZdoStatus.NOT_PERMITTED) { return ZigBeeStatus.INVALID_STATE; } if (response.getStatus() != ZdoStatus.SUCCESS) { return ZigBeeStatus.FAILURE; } if (response.getStartIndex() == index) { tableSize = response.getBindingTableEntries(); index += response.getBindingTableList().size(); bindingTable.addAll(response.getBindingTableList()); } } while (index < tableSize); setBindingTable(bindingTable); return ZigBeeStatus.SUCCESS; } }); new Thread(future, "UpdateBindingTable" + getIeeeAddress()).start(); return future; } ZigBeeNode(ZigBeeNetworkManager networkManager, IeeeAddress ieeeAddress);  ZigBeeNode(ZigBeeNetworkManager networkManager, IeeeAddress ieeeAddress, Integer networkAddress); void shutdown(); IeeeAddress getIeeeAddress(); boolean setNetworkAddress(Integer networkAddress); Integer getNetworkAddress(); void setNodeDescriptor(NodeDescriptor nodeDescriptor); NodeDescriptor getNodeDescriptor(); void setPowerDescriptor(PowerDescriptor powerDescriptor); PowerDescriptor getPowerDescriptor(); void permitJoin(final int duration); void permitJoin(final boolean enable); @Deprecated boolean isFullFuntionDevice(); boolean isFullFunctionDevice(); @Deprecated boolean isReducedFuntionDevice(); boolean isReducedFunctionDevice(); boolean isSecurityCapable(); boolean isPrimaryTrustCenter(); LogicalType getLogicalType(); Set<BindingTable> getBindingTable(); Future<ZigBeeStatus> updateBindingTable(); Collection<ZigBeeEndpoint> getEndpoints(); ZigBeeEndpoint getEndpoint(final int endpointId); void addEndpoint(final ZigBeeEndpoint endpoint); void updateEndpoint(final ZigBeeEndpoint endpoint); void removeEndpoint(final int endpointId); void addNetworkEndpointListener(final ZigBeeNetworkEndpointListener networkDeviceListener); void removeNetworkEndpointListener(final ZigBeeNetworkEndpointListener networkDeviceListener); Set<NeighborTable> getNeighbors(); boolean setNeighbors(Set<NeighborTable> neighbors); Set<Integer> getAssociatedDevices(); boolean setAssociatedDevices(Set<Integer> associatedDevices); Collection<RoutingTable> getRoutes(); boolean setRoutes(Set<RoutingTable> routes); void setLastUpdateTime(); Date getLastUpdateTime(); void commandReceived(ZigBeeCommand command, Integer rssi, Integer lqi); boolean isDiscovered(); ZigBeeNodeDao getDao(); void setDao(ZigBeeNodeDao dao); void sendTransaction(ZigBeeCommand command); Future<CommandResult> sendTransaction(ZigBeeCommand command, ZigBeeTransactionMatcher responseMatcher); boolean setNodeState(ZigBeeNodeState state); ZigBeeNodeState getNodeState(); NotificationService getNotificationService(); ZigBeeLinkQualityStatistics getLinkQualityStatistics(); @Override String toString();  }