Search in sources :

Example 1 with NodeDescriptor

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

the class NodeDescriptorResponseTest method testReceive.

@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());
}
Also used : DefaultDeserializer(com.zsmartsystems.zigbee.serialization.DefaultDeserializer) NodeDescriptor(com.zsmartsystems.zigbee.zdo.field.NodeDescriptor) ZclFieldDeserializer(com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer) CommandTest(com.zsmartsystems.zigbee.CommandTest) Test(org.junit.Test)

Example 2 with NodeDescriptor

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

the class DefaultDeserializer method readZigBeeType.

@Override
public /**
 * {@inheritDoc}
 */
Object readZigBeeType(ZclDataType type) {
    if (index == payload.length) {
        return null;
    }
    Object[] value = new Object[1];
    switch(type) {
        case BOOLEAN:
            value[0] = payload[index++] == 0 ? false : true;
            break;
        case CHARACTER_STRING:
        case OCTET_STRING:
            int size = payload[index++];
            if (size == 255) {
                value[0] = null;
                break;
            }
            int length = size;
            for (int cnt = 0; cnt < size; cnt++) {
                if (payload[index + cnt] == 0) {
                    length = cnt;
                }
            }
            value[0] = new String(payload, index, length);
            index += size;
            break;
        case ENDPOINT:
        case BITMAP_8_BIT:
        case DATA_8_BIT:
        case ENUMERATION_8_BIT:
            value[0] = Integer.valueOf((byte) payload[index++] & 0xFF);
            break;
        case EXTENDED_PANID:
            int[] panId = new int[8];
            for (int iCnt = 7; iCnt >= 0; iCnt--) {
                panId[iCnt] = payload[index + iCnt];
            }
            index += 8;
            value[0] = new ExtendedPanId(panId);
            break;
        case IEEE_ADDRESS:
            int[] address = new int[8];
            for (int iCnt = 7; iCnt >= 0; iCnt--) {
                address[iCnt] = payload[index + iCnt];
            }
            index += 8;
            value[0] = new IeeeAddress(address);
            break;
        case N_X_ATTRIBUTE_INFORMATION:
            break;
        case N_X_ATTRIBUTE_RECORD:
            break;
        case N_X_ATTRIBUTE_REPORT:
            break;
        case N_X_ATTRIBUTE_REPORTING_CONFIGURATION_RECORD:
            break;
        case N_X_ATTRIBUTE_SELECTOR:
            break;
        case N_X_ATTRIBUTE_STATUS_RECORD:
            break;
        case N_X_EXTENSION_FIELD_SET:
            break;
        case N_X_NEIGHBORS_INFORMATION:
            break;
        case N_X_READ_ATTRIBUTE_STATUS_RECORD:
            break;
        case N_X_UNSIGNED_16_BIT_INTEGER:
            int cntN16 = Integer.valueOf((byte) payload[index++] & 0xFF);
            List<Integer> arrayN16 = new ArrayList<Integer>(cntN16);
            for (int arrayIndex = 0; arrayIndex < cntN16; arrayIndex++) {
                arrayN16.add(Integer.valueOf(payload[index++] + ((payload[index++] << 8) & 0xffff)));
            }
            value[0] = arrayN16;
            break;
        case N_X_UNSIGNED_8_BIT_INTEGER:
            int cntN8 = Integer.valueOf((byte) payload[index++] & 0xFF);
            List<Integer> arrayN8 = new ArrayList<Integer>(cntN8);
            for (int arrayIndex = 0; arrayIndex < cntN8; arrayIndex++) {
                arrayN8.add(Integer.valueOf(payload[index++]));
            }
            value[0] = arrayN8;
            break;
        case X_UNSIGNED_8_BIT_INTEGER:
            int cntX8 = payload.length - index;
            List<Integer> arrayX8 = new ArrayList<Integer>(cntX8);
            for (int arrayIndex = 0; arrayIndex < cntX8; arrayIndex++) {
                arrayX8.add(Integer.valueOf(payload[index++]));
            }
            value[0] = arrayX8;
            break;
        case N_X_ATTRIBUTE_IDENTIFIER:
            int cntX16 = (payload.length - index) / 2;
            List<Integer> arrayX16 = new ArrayList<Integer>(cntX16);
            for (int arrayIndex = 0; arrayIndex < cntX16; arrayIndex++) {
                arrayX16.add(Integer.valueOf(payload[index++]));
            }
            value[0] = arrayX16;
            break;
        case UNSIGNED_8_BIT_INTEGER_ARRAY:
            int cnt8Array = payload.length - index;
            int[] intarray8 = new int[cnt8Array];
            for (int arrayIndex = 0; arrayIndex < cnt8Array; arrayIndex++) {
                intarray8[arrayIndex] = payload[index++];
            }
            value[0] = intarray8;
            break;
        case N_X_WRITE_ATTRIBUTE_RECORD:
            break;
        case N_X_WRITE_ATTRIBUTE_STATUS_RECORD:
            break;
        case CLUSTERID:
        case NWK_ADDRESS:
        case BITMAP_16_BIT:
        case ENUMERATION_16_BIT:
        case SIGNED_16_BIT_INTEGER:
        case UNSIGNED_16_BIT_INTEGER:
            short s = (short) (payload[index++] + (payload[index++] << 8));
            if (type == ZclDataType.SIGNED_16_BIT_INTEGER) {
                value[0] = Integer.valueOf(s);
            } else {
                value[0] = Integer.valueOf(s & 0xFFFF);
            }
            break;
        case BITMAP_32_BIT:
        case SIGNED_32_BIT_INTEGER:
        case UNSIGNED_32_BIT_INTEGER:
            value[0] = payload[index++] + (payload[index++] << 8) + (payload[index++] << 16) + (payload[index++] << 24);
            break;
        case SIGNED_8_BIT_INTEGER:
            value[0] = Integer.valueOf((byte) payload[index++]);
            break;
        case UNSIGNED_8_BIT_INTEGER:
            value[0] = Integer.valueOf((byte) payload[index++] & 0xFF);
            break;
        case UTCTIME:
            break;
        case ROUTING_TABLE:
            RoutingTable routingTable = new RoutingTable();
            routingTable.deserialize(this);
            value[0] = routingTable;
            break;
        case NEIGHBOR_TABLE:
            NeighborTable neighborTable = new NeighborTable();
            neighborTable.deserialize(this);
            value[0] = neighborTable;
            break;
        case NODE_DESCRIPTOR:
            NodeDescriptor nodeDescriptor = new NodeDescriptor();
            nodeDescriptor.deserialize(this);
            value[0] = nodeDescriptor;
            break;
        case POWER_DESCRIPTOR:
            PowerDescriptor powerDescriptor = new PowerDescriptor();
            powerDescriptor.deserialize(this);
            value[0] = powerDescriptor;
            break;
        case BINDING_TABLE:
            BindingTable bindingTable = new BindingTable();
            bindingTable.deserialize(this);
            value[0] = bindingTable;
            break;
        case SIMPLE_DESCRIPTOR:
            SimpleDescriptor simpleDescriptor = new SimpleDescriptor();
            simpleDescriptor.deserialize(this);
            value[0] = simpleDescriptor;
            break;
        case ZCL_STATUS:
            value[0] = ZclStatus.getStatus(payload[index++]);
            break;
        case ZDO_STATUS:
            value[0] = ZdoStatus.getStatus(payload[index++]);
            break;
        case ZIGBEE_DATA_TYPE:
            value[0] = ZclDataType.getType(payload[index++]);
            break;
        case BYTE_ARRAY:
            int cntB8 = Integer.valueOf((byte) payload[index++] & 0xFF);
            byte[] arrayB8 = new byte[cntB8];
            for (int arrayIndex = 0; arrayIndex < cntB8; arrayIndex++) {
                arrayB8[arrayIndex] = (byte) (payload[index++] & 0xff);
            }
            value[0] = new ByteArray(arrayB8);
            break;
        default:
            throw new IllegalArgumentException("No reader defined in " + ZigBeeDeserializer.class.getSimpleName() + " for " + type.toString() + " (" + type.getId() + ")");
    }
    return value[0];
}
Also used : ExtendedPanId(com.zsmartsystems.zigbee.ExtendedPanId) ArrayList(java.util.ArrayList) NodeDescriptor(com.zsmartsystems.zigbee.zdo.field.NodeDescriptor) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) SimpleDescriptor(com.zsmartsystems.zigbee.zdo.field.SimpleDescriptor) RoutingTable(com.zsmartsystems.zigbee.zdo.field.RoutingTable) BindingTable(com.zsmartsystems.zigbee.zdo.field.BindingTable) NeighborTable(com.zsmartsystems.zigbee.zdo.field.NeighborTable) ByteArray(com.zsmartsystems.zigbee.zcl.field.ByteArray) PowerDescriptor(com.zsmartsystems.zigbee.zdo.field.PowerDescriptor)

Example 3 with NodeDescriptor

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

the class ZigBeeNodeTest method isDiscovered.

@Test
public void isDiscovered() {
    ZigBeeNode node = new ZigBeeNode(Mockito.mock(ZigBeeNetworkManager.class), new IeeeAddress("1234567890"));
    assertFalse(node.isDiscovered());
    NodeDescriptor descriptor = new NodeDescriptor(0, 3333, 74, true, 6666, 0, 6, 4444, true, 8);
    node.setNodeDescriptor(descriptor);
    assertFalse(node.isDiscovered());
    node.addEndpoint(new ZigBeeEndpoint(Mockito.mock(ZigBeeNetworkManager.class), node, 1));
    assertTrue(node.isDiscovered());
}
Also used : NodeDescriptor(com.zsmartsystems.zigbee.zdo.field.NodeDescriptor) Test(org.junit.Test)

Example 4 with NodeDescriptor

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

the class ZigBeeNodeTest method testDeviceTypes.

@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());
}
Also used : NodeDescriptor(com.zsmartsystems.zigbee.zdo.field.NodeDescriptor) Test(org.junit.Test)

Example 5 with NodeDescriptor

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

Aggregations

NodeDescriptor (com.zsmartsystems.zigbee.zdo.field.NodeDescriptor)6 Test (org.junit.Test)5 IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)3 ArrayList (java.util.ArrayList)3 ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)2 ZigBeeNode (com.zsmartsystems.zigbee.ZigBeeNode)2 PowerDescriptor (com.zsmartsystems.zigbee.zdo.field.PowerDescriptor)2 SimpleDescriptor (com.zsmartsystems.zigbee.zdo.field.SimpleDescriptor)2 CommandTest (com.zsmartsystems.zigbee.CommandTest)1 ExtendedPanId (com.zsmartsystems.zigbee.ExtendedPanId)1 ZigBeeCommand (com.zsmartsystems.zigbee.ZigBeeCommand)1 ZigBeeEndpoint (com.zsmartsystems.zigbee.ZigBeeEndpoint)1 ZigBeeNetworkManager (com.zsmartsystems.zigbee.ZigBeeNetworkManager)1 ZigBeeOtaFile (com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaFile)1 ZigBeeOtaServer (com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaServer)1 ZigBeeOtaServerStatus (com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaServerStatus)1 ZigBeeOtaStatusCallback (com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaStatusCallback)1 DefaultDeserializer (com.zsmartsystems.zigbee.serialization.DefaultDeserializer)1 ZclFieldDeserializer (com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer)1 ZclOtaUpgradeCluster (com.zsmartsystems.zigbee.zcl.clusters.ZclOtaUpgradeCluster)1