Search in sources :

Example 11 with ZclFieldDeserializer

use of com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer 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 12 with ZclFieldDeserializer

use of com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer in project com.zsmartsystems.zigbee by zsmartsystems.

the class PowerDescriptorResponseTest method testReceiveNotSupported.

@Test
public void testReceiveNotSupported() {
    int[] packet = getPacketData("84 84");
    PowerDescriptorResponse descriptorResponse = new PowerDescriptorResponse();
    DefaultDeserializer deserializer = new DefaultDeserializer(packet);
    ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);
    descriptorResponse.deserialize(fieldDeserializer);
    System.out.println(descriptorResponse);
    assertEquals(ZdoStatus.NOT_SUPPORTED, descriptorResponse.getStatus());
    PowerDescriptor powerDescriptor = descriptorResponse.getPowerDescriptor();
    assertEquals(null, powerDescriptor);
}
Also used : DefaultDeserializer(com.zsmartsystems.zigbee.serialization.DefaultDeserializer) ZclFieldDeserializer(com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer) PowerDescriptor(com.zsmartsystems.zigbee.zdo.field.PowerDescriptor) CommandTest(com.zsmartsystems.zigbee.CommandTest) Test(org.junit.Test)

Example 13 with ZclFieldDeserializer

use of com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer in project com.zsmartsystems.zigbee by zsmartsystems.

the class SimpleDescriptorResponseTest method testReceiveError.

@Test
public void testReceiveError() {
    // int[] packet = getPacketData("00 00 00 00 10 C1");
    int[] packet = getPacketData("00 81 00 01");
    SimpleDescriptorResponse descriptorResponse = new SimpleDescriptorResponse();
    DefaultDeserializer deserializer = new DefaultDeserializer(packet);
    ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);
    descriptorResponse.deserialize(fieldDeserializer);
    System.out.println(descriptorResponse);
    SimpleDescriptor simpleDescriptor = descriptorResponse.getSimpleDescriptor();
    assertNull(simpleDescriptor);
    assertEquals(ZdoStatus.DEVICE_NOT_FOUND, descriptorResponse.getStatus());
}
Also used : DefaultDeserializer(com.zsmartsystems.zigbee.serialization.DefaultDeserializer) ZclFieldDeserializer(com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer) SimpleDescriptor(com.zsmartsystems.zigbee.zdo.field.SimpleDescriptor) CommandTest(com.zsmartsystems.zigbee.CommandTest) Test(org.junit.Test)

Example 14 with ZclFieldDeserializer

use of com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeNetworkManager method receiveCommand.

@Override
public void receiveCommand(final ZigBeeApsFrame apsFrame) {
    logger.debug("RX APS: {}", apsFrame);
    // Create the deserialiser
    Constructor<? extends ZigBeeDeserializer> constructor;
    ZigBeeDeserializer deserializer;
    try {
        constructor = deserializerClass.getConstructor(int[].class);
        deserializer = constructor.newInstance(new Object[] { apsFrame.getPayload() });
    } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
        logger.debug("Error creating deserializer", e);
        return;
    }
    ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);
    ZigBeeCommand command = null;
    switch(// TODO: Use ZigBeeProfileType
    apsFrame.getProfile()) {
        case 0x0000:
            command = receiveZdoCommand(fieldDeserializer, apsFrame);
            break;
        case 0x0104:
        case 0xC05E:
            command = receiveZclCommand(fieldDeserializer, apsFrame);
            break;
        default:
            logger.debug("Received message with unknown profile {}", String.format("%04X", apsFrame.getProfile()));
            break;
    }
    if (command == null) {
        logger.debug("Incoming message did not translate to command.");
        return;
    }
    // Create an address from the sourceAddress and endpoint
    command.setSourceAddress(new ZigBeeEndpointAddress(apsFrame.getSourceAddress(), apsFrame.getSourceEndpoint()));
    command.setDestinationAddress(new ZigBeeEndpointAddress(apsFrame.getDestinationAddress(), apsFrame.getDestinationEndpoint()));
    logger.debug("RX CMD: {}", command);
    // Notify the listeners
    commandNotifier.notifyCommandListeners(command);
}
Also used : InvocationTargetException(java.lang.reflect.InvocationTargetException) ZigBeeDeserializer(com.zsmartsystems.zigbee.serialization.ZigBeeDeserializer) ZclFieldDeserializer(com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer)

Example 15 with ZclFieldDeserializer

use of com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer in project com.zsmartsystems.zigbee by zsmartsystems.

the class ConfigureReportingResponseTest method testErrorInvalidDataType.

@Test
public void testErrorInvalidDataType() {
    int[] packet = getPacketData("08 6C 07 8D 00 00 00");
    ConfigureReportingResponse response = new ConfigureReportingResponse();
    DefaultDeserializer deserializer = new DefaultDeserializer(packet);
    ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);
    ZclHeader zclHeader = new ZclHeader(fieldDeserializer);
    System.out.println(zclHeader);
    response.deserialize(fieldDeserializer);
    System.out.println(response);
    assertNull(response.getStatus());
    assertEquals(1, response.getRecords().size());
    AttributeStatusRecord record = response.getRecords().get(0);
    assertEquals(0, record.getAttributeIdentifier());
    assertEquals(ZclStatus.INVALID_DATA_TYPE, record.getStatus());
}
Also used : DefaultDeserializer(com.zsmartsystems.zigbee.serialization.DefaultDeserializer) ZclFieldDeserializer(com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer) AttributeStatusRecord(com.zsmartsystems.zigbee.zcl.field.AttributeStatusRecord) ZclHeader(com.zsmartsystems.zigbee.zcl.ZclHeader) CommandTest(com.zsmartsystems.zigbee.CommandTest) Test(org.junit.Test)

Aggregations

ZclFieldDeserializer (com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer)29 CommandTest (com.zsmartsystems.zigbee.CommandTest)28 DefaultDeserializer (com.zsmartsystems.zigbee.serialization.DefaultDeserializer)28 Test (org.junit.Test)28 IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)6 ZclHeader (com.zsmartsystems.zigbee.zcl.ZclHeader)6 ReadAttributeStatusRecord (com.zsmartsystems.zigbee.zcl.field.ReadAttributeStatusRecord)3 AttributeStatusRecord (com.zsmartsystems.zigbee.zcl.field.AttributeStatusRecord)2 PowerDescriptor (com.zsmartsystems.zigbee.zdo.field.PowerDescriptor)2 SimpleDescriptor (com.zsmartsystems.zigbee.zdo.field.SimpleDescriptor)2 ZigBeeDeserializer (com.zsmartsystems.zigbee.serialization.ZigBeeDeserializer)1 AttributeInformation (com.zsmartsystems.zigbee.zcl.field.AttributeInformation)1 BindingTable (com.zsmartsystems.zigbee.zdo.field.BindingTable)1 NeighborTable (com.zsmartsystems.zigbee.zdo.field.NeighborTable)1 NodeDescriptor (com.zsmartsystems.zigbee.zdo.field.NodeDescriptor)1 RoutingTable (com.zsmartsystems.zigbee.zdo.field.RoutingTable)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1