/** * Gets the {@link LogicalType} of the node. * <p> * Possible types are -: * <ul> * <li>{@link LogicalType#COORDINATOR} * <li>{@link LogicalType#ROUTER} * <li>{@link LogicalType#END_DEVICE} * <ul> * * @return the {@link LogicalType} of the node */ public LogicalType getLogicalType() { return nodeDescriptor.getLogicalType(); }
public boolean isSecurityCapable() { if (nodeDescriptor == null) { return false; } return nodeDescriptor.getMacCapabilities().contains(MacCapabilitiesType.SECURITY_CAPABLE); }
public boolean isPrimaryTrustCenter() { if (nodeDescriptor == null) { return false; } return nodeDescriptor.getServerCapabilities().contains(ServerCapabilitiesType.PRIMARY_TRUST_CENTER); }
@Test public void testNodeDescriptor() { NodeDescriptor descriptor = new NodeDescriptor(0, 3333, 74, true, 6666, 0, 6, 4444, true, 8); assertTrue(descriptor.isComplexDescriptorAvailable()); assertTrue(descriptor.isUserDescriptorAvailable()); assertEquals(4444, descriptor.getIncomingTransferSize()); assertEquals(6666, descriptor.getManufacturerCode()); assertEquals(3333, descriptor.getBufferSize()); assertTrue(descriptor.getFrequencyBands().contains(FrequencyBandType.FREQ_2400_MHZ)); assertEquals(LogicalType.COORDINATOR, descriptor.getLogicalType()); assertEquals(0, descriptor.getApsFlags()); assertTrue(descriptor.getServerCapabilities().contains(ServerCapabilitiesType.PRIMARY_BINDING_TABLE_CACHE)); assertTrue(descriptor.getServerCapabilities().contains(ServerCapabilitiesType.BACKUP_TRUST_CENTER)); assertTrue(descriptor.getMacCapabilities().contains(MacCapabilitiesType.SECURITY_CAPABLE)); assertTrue(descriptor.getMacCapabilities().contains(MacCapabilitiesType.RECEIVER_ON_WHEN_IDLE)); assertTrue(descriptor.getMacCapabilities().contains(MacCapabilitiesType.FULL_FUNCTION_DEVICE)); }
@Test public void testNodeDescriptorDeserialize() { int[] packet = getPacketData("00 00 00 00 00 40 8F CD AB 52 80 00 41 2A 80 00 00"); NodeDescriptor descriptor = new NodeDescriptor(); DefaultDeserializer deserializer = new DefaultDeserializer(packet); descriptor.deserialize(deserializer); System.out.println(descriptor); assertEquals(0, descriptor.getManufacturerCode()); assertEquals(LogicalType.COORDINATOR, descriptor.getLogicalType()); }
@Test public void testNodeDescriptorR21() { NodeDescriptor descriptor = new NodeDescriptor(0, 0, 0, true, 0, 0, 0x2A00, 0, true, 0); assertEquals(21, descriptor.getStackCompliance()); }
break; case NODE_DESCRIPTOR: NodeDescriptor nodeDescriptor = new NodeDescriptor(); nodeDescriptor.deserialize(this); value[0] = nodeDescriptor; break;
Mockito.when(initialNodeDescriptor.getLogicalType()).thenReturn(LogicalType.UNKNOWN); Mockito.when(node.getNodeDescriptor()).thenReturn(initialNodeDescriptor); nodeResponse.setDestinationAddress(new ZigBeeEndpointAddress(0)); nodeResponse.setNwkAddrOfInterest(0); NodeDescriptor nodeDescriptor = new NodeDescriptor(); nodeResponse.setNodeDescriptor(nodeDescriptor); responses.put(ZdoCommandType.NODE_DESCRIPTOR_REQUEST.getClusterId(), nodeResponse);
ArgumentCaptor<ZigBeeCommand> mockedCommandCaptor = ArgumentCaptor.forClass(ZigBeeCommand.class); NodeDescriptor nodeDescriptor = new NodeDescriptor(); IeeeAddress ieeeAddress = new IeeeAddress("1234567890ABCDEF"); ZigBeeEndpointAddress networkAddress = new ZigBeeEndpointAddress(1234, 56);
@Test public void testReceive() { int[] packet = getPacketData("00 00 00 00 00 40 8F CD AB 52 80 00 41 2A 80 00 00"); // data=01 90 45 00 00 00 02 80 00 00 40 01 00 00 36 FF 00 00 00 FF FF 11 00 00 00 00 00 40 8F CD AB 52 80 00 41 // 2A // 80 00 00] NodeDescriptorResponse descriptorResponse = new NodeDescriptorResponse(); DefaultDeserializer deserializer = new DefaultDeserializer(packet); ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer); descriptorResponse.deserialize(fieldDeserializer); System.out.println(descriptorResponse); NodeDescriptor nodeDescriptor = descriptorResponse.getNodeDescriptor(); assertEquals(82, nodeDescriptor.getBufferSize()); assertEquals(128, nodeDescriptor.getIncomingTransferSize()); assertEquals(43981, nodeDescriptor.getManufacturerCode()); } }
properties.put(ZigBeeBindingConstants.THING_PROPERTY_NETWORKADDRESS, node.getNetworkAddress().toString()); properties.put(ZigBeeBindingConstants.THING_PROPERTY_STACKCOMPLIANCE, Integer.toString(node.getNodeDescriptor().getStackCompliance()));
if (!nodeDescriptor.equals(node.getNodeDescriptor())) { updated = true; nodeDescriptor = node.getNodeDescriptor();
@Test public void isDiscovered() { ZigBeeNode node = new ZigBeeNode(Mockito.mock(ZigBeeNetworkManager.class), new IeeeAddress("1234567890")); ZigBeeNetworkEndpointListener listener = Mockito.mock(ZigBeeNetworkEndpointListener.class); node.addNetworkEndpointListener(listener); assertFalse(node.isDiscovered()); assertNotNull(node.getEndpoints()); NodeDescriptor descriptor = new NodeDescriptor(0, 3333, 74, true, 6666, 0, 6, 4444, true, 8); node.setNodeDescriptor(descriptor); assertFalse(node.isDiscovered()); ZigBeeEndpoint endpoint = new ZigBeeEndpoint(node, 1); node.addEndpoint(endpoint); assertTrue(node.isDiscovered()); Mockito.verify(listener, Mockito.timeout(TIMEOUT)).deviceAdded(endpoint); assertEquals(endpoint, node.getEndpoint(1)); assertEquals(1, node.getEndpoints().size()); node.removeEndpoint(1); assertEquals(0, node.getEndpoints().size()); Mockito.verify(listener, Mockito.timeout(TIMEOUT)).deviceRemoved(endpoint); node.removeNetworkEndpointListener(listener); }
/** * Checks if basic device discovery is complete. This ensures that we have received the {@link NodeDescriptor} and * the {@link SimpleDescriptor} so that we know the endpoints. * * @return true if basic device information is known */ public boolean isDiscovered() { return nodeDescriptor.getLogicalType() != LogicalType.UNKNOWN && endpoints.size() != 0; }
/** * Returns true if the node is a Full Function Device. Returns false if not an FFD or logical type is unknown. * <p> * A FFD (Full Function Device) is a device that has full levels of functionality. * It can be used for sending and receiving data, but it can also route data from other nodes. * FFDs are Coordinators and Routers * * @return true if the device is a Full Function Device. Returns false if not an FFD or logical type is unknown. */ public boolean isFullFuntionDevice() { if (nodeDescriptor == null) { return false; } return nodeDescriptor.getMacCapabilities().contains(MacCapabilitiesType.FULL_FUNCTION_DEVICE); }
@Test public void testDeviceTypes() { ZigBeeNode node = new ZigBeeNode(Mockito.mock(ZigBeeNetworkManager.class), new IeeeAddress()); assertFalse(node.isFullFuntionDevice()); assertFalse(node.isReducedFuntionDevice()); assertFalse(node.isPrimaryTrustCenter()); assertFalse(node.isSecurityCapable()); assertEquals(LogicalType.UNKNOWN, node.getLogicalType()); NodeDescriptor nodeDescriptor = new NodeDescriptor(); node.setNodeDescriptor(nodeDescriptor); assertFalse(node.isFullFuntionDevice()); assertFalse(node.isReducedFuntionDevice()); assertFalse(node.isPrimaryTrustCenter()); assertFalse(node.isSecurityCapable()); nodeDescriptor = new NodeDescriptor(0, 0, 0xff, false, 0, 0, 0xff, 0, false, 0); node.setNodeDescriptor(nodeDescriptor); assertNotNull(node.getNodeDescriptor()); assertTrue(node.isFullFuntionDevice()); assertFalse(node.isReducedFuntionDevice()); assertTrue(node.isPrimaryTrustCenter()); assertTrue(node.isSecurityCapable()); nodeDescriptor = new NodeDescriptor(0, 0, 0x00, false, 0, 0, 0xff, 0, false, 0); node.setNodeDescriptor(nodeDescriptor); assertFalse(node.isFullFuntionDevice()); assertTrue(node.isReducedFuntionDevice()); assertEquals(LogicalType.COORDINATOR, node.getLogicalType()); }
@Override public String toString() { StringBuilder builder = new StringBuilder(100); builder.append("ZigBeeNode [state="); builder.append(nodeState); builder.append(", IEEE="); builder.append(ieeeAddress); builder.append(String.format(", NWK=%04X", networkAddress)); if (nodeDescriptor != null) { builder.append(", Type="); builder.append(nodeDescriptor.getLogicalType()); } builder.append(']'); return builder.toString(); }
/** * Returns true if the node is a Reduced Function Device. Returns false if not an RFD or logical type is unknown. * <p> * An RFD (Reduced Function Device) is a device that has a reduced level of functionality. * Typically it is an end node which may be typically a sensor or switch. RFDs can only talk to FFDs * as they contain no routing functionality. These devices can be very low power devices because they * do not need to route other traffic and they can be put into a sleep mode when they are not in use. * * @return true if the device is a Reduced Function Device */ public boolean isReducedFuntionDevice() { if (nodeDescriptor == null) { return false; } return nodeDescriptor.getMacCapabilities().contains(MacCapabilitiesType.REDUCED_FUNCTION_DEVICE); }
/** * Starts service discovery for the node in order to update the mesh. This adds the * {@link NodeDiscoveryTask#NEIGHBORS} and {@link NodeDiscoveryTask#ROUTES} tasks to the task list. * <p> * Note that {@link NodeDiscoveryTask#ROUTES} is not added for end devices. */ public void updateMesh() { logger.debug("{}: Node SVC Discovery: Update mesh", node.getIeeeAddress()); Set<NodeDiscoveryTask> tasks = new HashSet<NodeDiscoveryTask>(); tasks.add(NodeDiscoveryTask.NEIGHBORS); if (node.getNodeDescriptor().getLogicalType() != LogicalType.END_DEVICE) { tasks.add(NodeDiscoveryTask.ROUTES); } startDiscovery(tasks); }
/** * Starts service discovery for the node. */ public void startDiscovery() { logger.debug("{}: Node SVC Discovery: start discovery", node.getIeeeAddress()); Set<NodeDiscoveryTask> tasks = new HashSet<NodeDiscoveryTask>(); // Always request the network address - in case it's changed tasks.add(NodeDiscoveryTask.NWK_ADDRESS); if (node.getNodeDescriptor().getLogicalType() == LogicalType.UNKNOWN) { tasks.add(NodeDiscoveryTask.NODE_DESCRIPTOR); } if (node.getPowerDescriptor().getCurrentPowerMode() == CurrentPowerModeType.UNKNOWN) { tasks.add(NodeDiscoveryTask.POWER_DESCRIPTOR); } if (node.getEndpoints().size() == 0 && node.getNetworkAddress() != networkManager.getLocalNwkAddress()) { tasks.add(NodeDiscoveryTask.ACTIVE_ENDPOINTS); } tasks.add(NodeDiscoveryTask.NEIGHBORS); startDiscovery(tasks); }