Search in sources :

Example 1 with ZclHeader

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

the class ZoneEnrollRequestCommandTest method test.

@Test
public void test() {
    int[] packet = getPacketData("09 63 01 0D 00 4E 10");
    ZoneEnrollRequestCommand command = new ZoneEnrollRequestCommand();
    DefaultDeserializer deserializer = new DefaultDeserializer(packet);
    ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);
    ZclHeader zclHeader = new ZclHeader(fieldDeserializer);
    System.out.println(zclHeader);
    command.deserialize(fieldDeserializer);
    System.out.println(command);
    assertEquals(Integer.valueOf(0x500), command.getClusterId());
    assertEquals(Integer.valueOf(13), command.getZoneType());
    assertEquals(Integer.valueOf(4174), command.getManufacturerCode());
}
Also used : DefaultDeserializer(com.zsmartsystems.zigbee.serialization.DefaultDeserializer) ZclFieldDeserializer(com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer) ZclHeader(com.zsmartsystems.zigbee.zcl.ZclHeader) CommandTest(com.zsmartsystems.zigbee.CommandTest) Test(org.junit.Test)

Example 2 with ZclHeader

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

the class ZoneStatusChangeNotificationCommandTest method test.

@Test
public void test() {
    int[] packet = getPacketData("09 7B 00 24 00 00 00 00 00");
    ZoneStatusChangeNotificationCommand command = new ZoneStatusChangeNotificationCommand();
    DefaultDeserializer deserializer = new DefaultDeserializer(packet);
    ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);
    ZclHeader zclHeader = new ZclHeader(fieldDeserializer);
    System.out.println(zclHeader);
    command.deserialize(fieldDeserializer);
    System.out.println(command);
    assertEquals(Integer.valueOf(0x500), command.getClusterId());
    assertEquals(Integer.valueOf(36), command.getZoneStatus());
}
Also used : DefaultDeserializer(com.zsmartsystems.zigbee.serialization.DefaultDeserializer) ZclFieldDeserializer(com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer) ZclHeader(com.zsmartsystems.zigbee.zcl.ZclHeader) CommandTest(com.zsmartsystems.zigbee.CommandTest) Test(org.junit.Test)

Example 3 with ZclHeader

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

the class OffWithEffectCommandTest method deserialize.

@Test
public void deserialize() {
    int[] packet = getPacketData("01 12 40 00 00");
    OffWithEffectCommand command = new OffWithEffectCommand();
    DefaultDeserializer deserializer = new DefaultDeserializer(packet);
    ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);
    ZclHeader zclHeader = new ZclHeader(fieldDeserializer);
    System.out.println(zclHeader);
    command.deserialize(fieldDeserializer);
    System.out.println(command);
    assertEquals(Integer.valueOf(0), command.getEffectIdentifier());
    assertEquals(Integer.valueOf(0), command.getEffectVariant());
}
Also used : DefaultDeserializer(com.zsmartsystems.zigbee.serialization.DefaultDeserializer) ZclFieldDeserializer(com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer) ZclHeader(com.zsmartsystems.zigbee.zcl.ZclHeader) CommandTest(com.zsmartsystems.zigbee.CommandTest) Test(org.junit.Test)

Example 4 with ZclHeader

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

the class ZigBeeNetworkManagerTest method testReceiveZclCommand.

@Test
public void testReceiveZclCommand() {
    ZigBeeNetworkManager networkManager = mockZigBeeNetworkManager();
    networkManager.setSerializer(DefaultSerializer.class, DefaultDeserializer.class);
    ZigBeeApsFrame apsFrame = new ZigBeeApsFrame();
    apsFrame.setSourceAddress(1234);
    apsFrame.setDestinationAddress(0);
    apsFrame.setSequence(1);
    apsFrame.setCluster(6);
    apsFrame.setDestinationEndpoint(2);
    apsFrame.setProfile(0x104);
    apsFrame.setSourceEndpoint(5);
    ZclHeader zclHeader = new ZclHeader();
    zclHeader.setCommandId(0);
    zclHeader.setFrameType(ZclFrameType.ENTIRE_PROFILE_COMMAND);
    zclHeader.setSequenceNumber(1);
    DefaultSerializer serializer = new DefaultSerializer();
    ZclFieldSerializer fieldSerializer = new ZclFieldSerializer(serializer);
    apsFrame.setPayload(zclHeader.serialize(fieldSerializer, new int[] {}));
    networkManager.receiveCommand(apsFrame);
    org.awaitility.Awaitility.await().until(commandListenerUpdated(), org.hamcrest.Matchers.equalTo(1));
    ReadAttributesCommand response = (ReadAttributesCommand) commandListenerCapture.get(0);
    assertEquals(6, (int) response.getClusterId());
    assertEquals(0, (int) response.getCommandId());
    assertEquals(1, (int) response.getTransactionId());
    assertEquals(new ZigBeeEndpointAddress(1234, 5), response.getSourceAddress());
}
Also used : DefaultSerializer(com.zsmartsystems.zigbee.serialization.DefaultSerializer) ReadAttributesCommand(com.zsmartsystems.zigbee.zcl.clusters.general.ReadAttributesCommand) ZclFieldSerializer(com.zsmartsystems.zigbee.zcl.ZclFieldSerializer) ZclHeader(com.zsmartsystems.zigbee.zcl.ZclHeader) Test(org.junit.Test)

Example 5 with ZclHeader

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

the class ZigBeeNetworkManager method receiveZclCommand.

private ZigBeeCommand receiveZclCommand(final ZclFieldDeserializer fieldDeserializer, final ZigBeeApsFrame apsFrame) {
    // Process the ZCL header
    ZclHeader zclHeader = new ZclHeader(fieldDeserializer);
    logger.debug("RX ZCL: {}", zclHeader);
    // Get the command type
    ZclCommandType commandType = null;
    if (zclHeader.getFrameType() == ZclFrameType.ENTIRE_PROFILE_COMMAND) {
        commandType = ZclCommandType.getGeneric(zclHeader.getCommandId());
    } else {
        commandType = ZclCommandType.getCommandType(apsFrame.getCluster(), zclHeader.getCommandId(), zclHeader.getDirection());
    }
    if (commandType == null) {
        logger.debug("No command type found for {}, cluster={}, command={}, direction={}", zclHeader.getFrameType(), apsFrame.getCluster(), zclHeader.getCommandId(), zclHeader.getDirection());
        return null;
    }
    ZclCommand command = commandType.instantiateCommand();
    if (command == null) {
        logger.debug("No command found for {}, cluster={}, command={}", zclHeader.getFrameType(), apsFrame.getCluster(), zclHeader.getCommandId());
        return null;
    }
    command.setCommandDirection(zclHeader.getDirection());
    command.deserialize(fieldDeserializer);
    command.setClusterId(apsFrame.getCluster());
    command.setTransactionId(zclHeader.getSequenceNumber());
    return command;
}
Also used : ZclCommandType(com.zsmartsystems.zigbee.zcl.protocol.ZclCommandType) ZclHeader(com.zsmartsystems.zigbee.zcl.ZclHeader) ZclCommand(com.zsmartsystems.zigbee.zcl.ZclCommand)

Aggregations

ZclHeader (com.zsmartsystems.zigbee.zcl.ZclHeader)9 Test (org.junit.Test)7 CommandTest (com.zsmartsystems.zigbee.CommandTest)6 DefaultDeserializer (com.zsmartsystems.zigbee.serialization.DefaultDeserializer)6 ZclFieldDeserializer (com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer)6 ZclCommand (com.zsmartsystems.zigbee.zcl.ZclCommand)2 ZclFieldSerializer (com.zsmartsystems.zigbee.zcl.ZclFieldSerializer)2 AttributeStatusRecord (com.zsmartsystems.zigbee.zcl.field.AttributeStatusRecord)2 DefaultSerializer (com.zsmartsystems.zigbee.serialization.DefaultSerializer)1 ZigBeeSerializer (com.zsmartsystems.zigbee.serialization.ZigBeeSerializer)1 ReadAttributesCommand (com.zsmartsystems.zigbee.zcl.clusters.general.ReadAttributesCommand)1 ZclCommandType (com.zsmartsystems.zigbee.zcl.protocol.ZclCommandType)1 ZdoCommand (com.zsmartsystems.zigbee.zdo.ZdoCommand)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1