Search in sources :

Example 1 with DefaultSerializer

use of com.zsmartsystems.zigbee.serialization.DefaultSerializer in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZclHeaderTest method testDeserialize.

@Test
public void testDeserialize() {
    int[] packet = getPacketData("11 04 01");
    DefaultDeserializer deserializer = new DefaultDeserializer(packet);
    ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);
    ZclHeader zclHeader = new ZclHeader(fieldDeserializer);
    System.out.println(zclHeader);
    assertEquals(1, zclHeader.getCommandId());
    assertEquals(ZclFrameType.CLUSTER_SPECIFIC_COMMAND, zclHeader.getFrameType());
    assertEquals(false, zclHeader.isManufacturerSpecific());
    assertEquals(true, zclHeader.isDisableDefaultResponse());
    assertEquals(4, zclHeader.getSequenceNumber());
    DefaultSerializer serializer = new DefaultSerializer();
    ZclFieldSerializer fieldSerializer = new ZclFieldSerializer(serializer);
    assertTrue(Arrays.equals(packet, zclHeader.serialize(fieldSerializer, new int[] {})));
}
Also used : DefaultSerializer(com.zsmartsystems.zigbee.serialization.DefaultSerializer) DefaultDeserializer(com.zsmartsystems.zigbee.serialization.DefaultDeserializer) CommandTest(com.zsmartsystems.zigbee.CommandTest) Test(org.junit.Test)

Example 2 with DefaultSerializer

use of com.zsmartsystems.zigbee.serialization.DefaultSerializer in project com.zsmartsystems.zigbee by zsmartsystems.

the class ManagementPermitJoiningRequestTest method testReceive.

@Test
public void testReceive() {
    // Short response - ie not extended
    int[] packet = getPacketData("00 FF 01");
    ManagementPermitJoiningRequest request = new ManagementPermitJoiningRequest();
    request.setDestinationAddress(new ZigBeeEndpointAddress(0));
    request.setTcSignificance(true);
    request.setPermitDuration(255);
    DefaultSerializer serializer = new DefaultSerializer();
    ZclFieldSerializer fieldSerializer = new ZclFieldSerializer(serializer);
    request.serialize(fieldSerializer);
    assertTrue(Arrays.equals(packet, serializer.getPayload()));
}
Also used : DefaultSerializer(com.zsmartsystems.zigbee.serialization.DefaultSerializer) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) ZclFieldSerializer(com.zsmartsystems.zigbee.zcl.ZclFieldSerializer) CommandTest(com.zsmartsystems.zigbee.CommandTest) Test(org.junit.Test)

Example 3 with DefaultSerializer

use of com.zsmartsystems.zigbee.serialization.DefaultSerializer 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 4 with DefaultSerializer

use of com.zsmartsystems.zigbee.serialization.DefaultSerializer in project com.zsmartsystems.zigbee by zsmartsystems.

the class EzspSendUnicastTest method testSendPermitJoining.

@Test
public void testSendPermitJoining() {
    EzspFrame.setEzspVersion(4);
    ManagementPermitJoiningRequest permitJoining = new ManagementPermitJoiningRequest();
    permitJoining.setDestinationAddress(new ZigBeeEndpointAddress(0x401C));
    permitJoining.setSourceAddress(new ZigBeeEndpointAddress(0));
    permitJoining.setTcSignificance(false);
    permitJoining.setPermitDuration(60);
    DefaultSerializer serializer = new DefaultSerializer();
    ZclFieldSerializer fieldSerializer = new ZclFieldSerializer(serializer);
    permitJoining.serialize(fieldSerializer);
    int[] payload = serializer.getPayload();
    EzspSendUnicastRequest emberUnicast = new EzspSendUnicastRequest();
    EmberApsFrame apsFrame = new EmberApsFrame();
    apsFrame.setClusterId(permitJoining.getClusterId());
    apsFrame.setProfileId(0);
    apsFrame.setSourceEndpoint(1);
    apsFrame.setDestinationEndpoint(0);
    apsFrame.setSequence(0x88);
    apsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_RETRY);
    apsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_ENABLE_ADDRESS_DISCOVERY);
    apsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_ENABLE_ROUTE_DISCOVERY);
    apsFrame.setGroupId(0xffff);
    emberUnicast.setMessageTag(0x99);
    emberUnicast.setSequenceNumber(0xaa);
    emberUnicast.setType(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT);
    emberUnicast.setApsFrame(apsFrame);
    emberUnicast.setIndexOrDestination(permitJoining.getDestinationAddress().getAddress());
    emberUnicast.setMessageContents(payload);
    int[] messageToSend = emberUnicast.serialize();
    System.out.println(emberUnicast.toString());
    System.out.println(Arrays.toString(messageToSend));
    String out = "";
    for (int c : messageToSend) {
        out += String.format("%02X ", c);
    }
    System.out.println(out);
}
Also used : DefaultSerializer(com.zsmartsystems.zigbee.serialization.DefaultSerializer) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) EmberApsFrame(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberApsFrame) ZclFieldSerializer(com.zsmartsystems.zigbee.zcl.ZclFieldSerializer) ManagementPermitJoiningRequest(com.zsmartsystems.zigbee.zdo.command.ManagementPermitJoiningRequest) EzspFrameTest(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.EzspFrameTest) Test(org.junit.Test)

Example 5 with DefaultSerializer

use of com.zsmartsystems.zigbee.serialization.DefaultSerializer in project com.zsmartsystems.zigbee by zsmartsystems.

the class EzspSendBroadcastTest method testSendPermitJoining.

@Test
public void testSendPermitJoining() {
    ManagementPermitJoiningRequest permitJoining = new ManagementPermitJoiningRequest();
    permitJoining.setDestinationAddress(new ZigBeeEndpointAddress(0xFFFC));
    permitJoining.setSourceAddress(new ZigBeeEndpointAddress(0));
    permitJoining.setTcSignificance(true);
    permitJoining.setPermitDuration(255);
    DefaultSerializer serializer = new DefaultSerializer();
    ZclFieldSerializer fieldSerializer = new ZclFieldSerializer(serializer);
    permitJoining.serialize(fieldSerializer);
    int[] payload = serializer.getPayload();
    EzspSendBroadcastRequest emberBroadcast = new EzspSendBroadcastRequest();
    EmberApsFrame apsFrame = new EmberApsFrame();
    apsFrame.setClusterId(permitJoining.getClusterId());
    apsFrame.setProfileId(0);
    apsFrame.setSourceEndpoint(0);
    apsFrame.setDestinationEndpoint(0);
    apsFrame.setSequence(5);
    apsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_RETRY);
    apsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_ENABLE_ADDRESS_DISCOVERY);
    apsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_ENABLE_ROUTE_DISCOVERY);
    apsFrame.setGroupId(0);
    emberBroadcast.setMessageTag(5);
    emberBroadcast.setSequenceNumber(5);
    emberBroadcast.setApsFrame(apsFrame);
    emberBroadcast.setDestination(permitJoining.getDestinationAddress().getAddress());
    emberBroadcast.setMessageContents(payload);
    emberBroadcast.setRadius(31);
    int[] messageToSend = emberBroadcast.serialize();
    String out = "";
    for (int c : messageToSend) {
        out += String.format("%02X ", c);
    }
    System.out.println(out);
    assertTrue(Arrays.equals(getPacketData("05 00 36 FC FF 00 00 36 00 00 00 40 11 00 00 05 1F 05 03 00 FF 01"), messageToSend));
}
Also used : DefaultSerializer(com.zsmartsystems.zigbee.serialization.DefaultSerializer) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) EzspSendBroadcastRequest(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspSendBroadcastRequest) EmberApsFrame(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberApsFrame) ZclFieldSerializer(com.zsmartsystems.zigbee.zcl.ZclFieldSerializer) ManagementPermitJoiningRequest(com.zsmartsystems.zigbee.zdo.command.ManagementPermitJoiningRequest) EzspFrameTest(com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.EzspFrameTest) Test(org.junit.Test)

Aggregations

DefaultSerializer (com.zsmartsystems.zigbee.serialization.DefaultSerializer)12 Test (org.junit.Test)12 ZclFieldSerializer (com.zsmartsystems.zigbee.zcl.ZclFieldSerializer)10 CommandTest (com.zsmartsystems.zigbee.CommandTest)9 ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)8 ZigBeeSerializer (com.zsmartsystems.zigbee.serialization.ZigBeeSerializer)3 ArrayList (java.util.ArrayList)3 EzspFrameTest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.EzspFrameTest)2 EmberApsFrame (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberApsFrame)2 DefaultDeserializer (com.zsmartsystems.zigbee.serialization.DefaultDeserializer)2 ManagementPermitJoiningRequest (com.zsmartsystems.zigbee.zdo.command.ManagementPermitJoiningRequest)2 EzspSendBroadcastRequest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.command.EzspSendBroadcastRequest)1 ZclHeader (com.zsmartsystems.zigbee.zcl.ZclHeader)1 ReadAttributesCommand (com.zsmartsystems.zigbee.zcl.clusters.general.ReadAttributesCommand)1 AttributeReportingConfigurationRecord (com.zsmartsystems.zigbee.zcl.field.AttributeReportingConfigurationRecord)1 ExtensionFieldSet (com.zsmartsystems.zigbee.zcl.field.ExtensionFieldSet)1