use of com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberApsFrame 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.dongle.ember.internal.ezsp.structure.EmberApsFrame in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeDongleEzsp method sendCommand.
@Override
public void sendCommand(final ZigBeeApsFrame apsFrame) {
if (ashHandler == null) {
return;
}
EzspFrameRequest emberCommand;
EmberApsFrame emberApsFrame = new EmberApsFrame();
emberApsFrame.setClusterId(apsFrame.getCluster());
emberApsFrame.setProfileId(apsFrame.getProfile());
emberApsFrame.setSourceEndpoint(apsFrame.getSourceEndpoint());
emberApsFrame.setDestinationEndpoint(apsFrame.getDestinationEndpoint());
emberApsFrame.setSequence(apsFrame.getApsCounter());
emberApsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_RETRY);
emberApsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_ENABLE_ROUTE_DISCOVERY);
emberApsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_ENABLE_ADDRESS_DISCOVERY);
if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.DEVICE && apsFrame.getDestinationAddress() < 0xfff8) {
EzspSendUnicastRequest emberUnicast = new EzspSendUnicastRequest();
emberUnicast.setIndexOrDestination(apsFrame.getDestinationAddress());
emberUnicast.setMessageTag(apsFrame.getSequence());
emberUnicast.setSequenceNumber(apsFrame.getSequence());
emberUnicast.setType(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT);
emberUnicast.setApsFrame(emberApsFrame);
emberUnicast.setMessageContents(apsFrame.getPayload());
emberCommand = emberUnicast;
} else if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.DEVICE && apsFrame.getDestinationAddress() >= 0xfff8) {
EzspSendBroadcastRequest emberBroadcast = new EzspSendBroadcastRequest();
emberBroadcast.setDestination(apsFrame.getDestinationAddress());
emberBroadcast.setMessageTag(apsFrame.getSequence());
emberBroadcast.setSequenceNumber(apsFrame.getSequence());
emberBroadcast.setApsFrame(emberApsFrame);
emberBroadcast.setRadius(apsFrame.getRadius());
emberBroadcast.setMessageContents(apsFrame.getPayload());
emberCommand = emberBroadcast;
} else if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.GROUP) {
emberApsFrame.setGroupId(apsFrame.getGroupAddress());
EzspSendMulticastRequest emberMulticast = new EzspSendMulticastRequest();
emberMulticast.setApsFrame(emberApsFrame);
emberMulticast.setHops(apsFrame.getRadius());
emberMulticast.setNonmemberRadius(apsFrame.getNonMemberRadius());
emberMulticast.setMessageTag(apsFrame.getSequence());
emberMulticast.setMessageContents(apsFrame.getPayload());
emberCommand = emberMulticast;
} else {
logger.debug("EZSP message not sent: {}, {}", apsFrame);
// apsFrame.setGroupId(groupAddress.getGroupId());
return;
}
logger.debug(emberCommand.toString());
ashHandler.queueFrame(emberCommand);
// emberUnicast = (EzspSendUnicast) ashHandler.sendEzspRequestAsync(emberUnicast);
}
use of com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberApsFrame in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeDongleEzsp method handlePacket.
@Override
public void handlePacket(EzspFrame response) {
logger.debug("RX: " + response.toString());
if (response instanceof EzspIncomingMessageHandler) {
EzspIncomingMessageHandler incomingMessage = (EzspIncomingMessageHandler) response;
EmberApsFrame emberApsFrame = incomingMessage.getApsFrame();
ZigBeeApsFrame apsFrame = new ZigBeeApsFrame();
apsFrame.setApsCounter(emberApsFrame.getSequence());
apsFrame.setCluster(emberApsFrame.getClusterId());
apsFrame.setDestinationEndpoint(emberApsFrame.getDestinationEndpoint());
apsFrame.setProfile(emberApsFrame.getProfileId());
apsFrame.setSourceEndpoint(emberApsFrame.getSourceEndpoint());
apsFrame.setSequence(incomingMessage.getSequenceNumber());
apsFrame.setSourceAddress(incomingMessage.getSender());
apsFrame.setPayload(incomingMessage.getMessageContents());
zigbeeTransportReceive.receiveCommand(apsFrame);
return;
}
// TODO: Check if this should be done only after initialisation is complete?
if (response instanceof EzspStackStatusHandler) {
switch(((EzspStackStatusHandler) response).getStatus()) {
case EMBER_NETWORK_BUSY:
break;
case EMBER_NETWORK_DOWN:
zigbeeTransportReceive.setNetworkState(ZigBeeTransportState.OFFLINE);
break;
case EMBER_NETWORK_UP:
break;
default:
break;
}
return;
}
if (response instanceof EzspTrustCenterJoinHandler) {
EzspTrustCenterJoinHandler joinHandler = (EzspTrustCenterJoinHandler) response;
ZigBeeNodeStatus status;
switch(joinHandler.getStatus()) {
case EMBER_HIGH_SECURITY_UNSECURED_JOIN:
case EMBER_STANDARD_SECURITY_UNSECURED_JOIN:
status = ZigBeeNodeStatus.UNSECURED_JOIN;
break;
case EMBER_HIGH_SECURITY_UNSECURED_REJOIN:
case EMBER_STANDARD_SECURITY_UNSECURED_REJOIN:
status = ZigBeeNodeStatus.UNSECURED_REJOIN;
break;
case EMBER_HIGH_SECURITY_SECURED_REJOIN:
case EMBER_STANDARD_SECURITY_SECURED_REJOIN:
status = ZigBeeNodeStatus.SECURED_REJOIN;
break;
case EMBER_DEVICE_LEFT:
status = ZigBeeNodeStatus.DEVICE_LEFT;
break;
default:
logger.debug("Unknown state in trust centre join handler {}", joinHandler.getStatus());
return;
}
zigbeeTransportReceive.nodeStatusUpdate(status, joinHandler.getNewNodeId(), joinHandler.getNewNodeEui64());
return;
}
if (response instanceof EzspChildJoinHandler) {
EzspChildJoinHandler joinHandler = (EzspChildJoinHandler) response;
zigbeeTransportReceive.nodeStatusUpdate(ZigBeeNodeStatus.UNSECURED_JOIN, joinHandler.getChildId(), joinHandler.getChildEui64());
return;
}
logger.debug("Unhandled EZSP Frame: {}", response.toString());
}
use of com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberApsFrame in project com.zsmartsystems.zigbee by zsmartsystems.
the class EzspMessageSentHandlerTest method testReceive2.
@Test
public void testReceive2() {
EzspFrame.setEzspVersion(4);
EzspMessageSentHandler messageSentHandler = new EzspMessageSentHandler(getPacketData("04 90 3F 00 00 00 00 00 04 00 00 00 40 11 00 00 78 04 00 00"));
System.out.println(messageSentHandler);
assertTrue(messageSentHandler.isResponse());
assertEquals(EmberStatus.EMBER_SUCCESS, messageSentHandler.getStatus());
assertEquals(0, messageSentHandler.getMessageContents().length);
assertEquals(0, messageSentHandler.getIndexOrDestination());
assertEquals(4, messageSentHandler.getMessageTag());
assertEquals(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT, messageSentHandler.getType());
EmberApsFrame apsFrame = messageSentHandler.getApsFrame();
assertNotNull(apsFrame);
assertEquals(3, apsFrame.getOptions().size());
assertTrue(apsFrame.getOptions().contains(EmberApsOption.EMBER_APS_OPTION_RETRY));
assertTrue(apsFrame.getOptions().contains(EmberApsOption.EMBER_APS_OPTION_ENABLE_ROUTE_DISCOVERY));
assertTrue(apsFrame.getOptions().contains(EmberApsOption.EMBER_APS_OPTION_ENABLE_ADDRESS_DISCOVERY));
assertEquals(4, apsFrame.getClusterId());
assertEquals(0, apsFrame.getProfileId());
assertEquals(120, apsFrame.getSequence());
}
use of com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberApsFrame 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