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[] {})));
}
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()));
}
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());
}
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);
}
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));
}
Aggregations