@Test public void sendCommandUnicast() throws Exception { System.out.println("--- " + Thread.currentThread().getStackTrace()[1].getMethodName()); ZigBeeDongleEzsp dongle = new ZigBeeDongleEzsp(null); EzspProtocolHandler handler = Mockito.mock(EzspProtocolHandler.class); TestUtilities.setField(ZigBeeDongleEzsp.class, dongle, "frameHandler", handler); ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1); TestUtilities.setField(ZigBeeDongleEzsp.class, dongle, "executorService", executorService); ZigBeeApsFrame apsFrame = new ZigBeeApsFrame(); apsFrame.setCluster(0); apsFrame.setProfile(ZigBeeProfileType.ZIGBEE_HOME_AUTOMATION.getKey()); apsFrame.setAddressMode(ZigBeeNwkAddressMode.DEVICE); apsFrame.setDestinationAddress(1234); apsFrame.setApsCounter(1); apsFrame.setRadius(30); apsFrame.setPayload(new int[] {}); dongle.sendCommand(1, apsFrame); Mockito.verify(handler, Mockito.timeout(TIMEOUT).times(1)) .sendEzspTransaction(ArgumentMatchers.any(EzspTransaction.class)); }
@Override public void sendCommand(final int msgTag, final ZigBeeApsFrame apsFrame) { if (frameHandler == null) { return; } lastSendCommand = System.currentTimeMillis(); EzspTransaction transaction; EmberApsFrame emberApsFrame = new EmberApsFrame(); emberApsFrame.setClusterId(apsFrame.getCluster()); emberApsFrame.setProfileId(apsFrame.getProfile()); emberApsFrame.setSourceEndpoint(apsFrame.getSourceEndpoint()); emberApsFrame.setDestinationEndpoint(apsFrame.getDestinationEndpoint()); emberApsFrame.setSequence(apsFrame.getApsCounter()); if (apsFrame.getAckRequest()) { 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.getSecurityEnabled()) { emberApsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_ENCRYPTION); } if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.DEVICE && !ZigBeeBroadcastDestination.isBroadcast(apsFrame.getDestinationAddress())) { EzspSendUnicastRequest emberUnicast = new EzspSendUnicastRequest(); emberUnicast.setIndexOrDestination(apsFrame.getDestinationAddress()); emberUnicast.setMessageTag(msgTag); emberUnicast.setType(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT); emberUnicast.setApsFrame(emberApsFrame); emberUnicast.setMessageContents(apsFrame.getPayload()); if (apsFrame instanceof ZigBeeApsFrameFragment) { ZigBeeApsFrameFragment fragment = (ZigBeeApsFrameFragment) apsFrame; emberApsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_FRAGMENT); emberApsFrame.setGroupId(fragment.getFragmentNumber() + (fragment.getFragmentTotal() << 8)); if (fragment.getFragmentNumber() != 0) { emberApsFrame.setSequence(fragmentationApsCounters.get(msgTag)); } if (fragment.getFragmentNumber() == fragment.getFragmentTotal() - 1) { fragmentationApsCounters.remove(msgTag); } } transaction = new EzspSingleResponseTransaction(emberUnicast, EzspSendUnicastResponse.class); } else if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.DEVICE && ZigBeeBroadcastDestination.isBroadcast(apsFrame.getDestinationAddress())) { EzspSendBroadcastRequest emberBroadcast = new EzspSendBroadcastRequest(); emberBroadcast.setDestination(apsFrame.getDestinationAddress()); emberBroadcast.setMessageTag(msgTag); emberBroadcast.setApsFrame(emberApsFrame); emberBroadcast.setRadius(apsFrame.getRadius()); emberBroadcast.setMessageContents(apsFrame.getPayload()); transaction = new EzspSingleResponseTransaction(emberBroadcast, EzspSendBroadcastResponse.class); } 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(msgTag); emberMulticast.setMessageContents(apsFrame.getPayload()); transaction = new EzspSingleResponseTransaction(emberMulticast, EzspSendMulticastResponse.class); } else { logger.debug("EZSP message not sent as unknown address mode: {}", apsFrame); return; } executorService.execute(new Runnable() { @Override public void run() { frameHandler.sendEzspTransaction(transaction); EmberStatus status = null; if (transaction.getResponse() instanceof EzspSendUnicastResponse) { fragmentationApsCounters.put(msgTag, ((EzspSendUnicastResponse) transaction.getResponse()).getSequence()); status = ((EzspSendUnicastResponse) transaction.getResponse()).getStatus(); } else if (transaction.getResponse() instanceof EzspSendBroadcastResponse) { status = ((EzspSendBroadcastResponse) transaction.getResponse()).getStatus(); } else if (transaction.getResponse() instanceof EzspSendMulticastResponse) { status = ((EzspSendMulticastResponse) transaction.getResponse()).getStatus(); } else { logger.debug("Unable to get response from {} :: {}", transaction.getRequest(), transaction.getResponse()); return; } if (status == EmberStatus.EMBER_SUCCESS) { return; } zigbeeTransportReceive.receiveCommandState(msgTag, ZigBeeTransportProgressState.TX_NAK); } }); }
ZigBeeDongleEzsp implements ZigBeeTransportTransmit, ZigBeeTransportFirmwareUpdate, EzspFrameHandler { @Override public void sendCommand(final int msgTag, final ZigBeeApsFrame apsFrame) { if (frameHandler == null) { return; } lastSendCommand = System.currentTimeMillis(); EzspTransaction transaction; EmberApsFrame emberApsFrame = new EmberApsFrame(); emberApsFrame.setClusterId(apsFrame.getCluster()); emberApsFrame.setProfileId(apsFrame.getProfile()); emberApsFrame.setSourceEndpoint(apsFrame.getSourceEndpoint()); emberApsFrame.setDestinationEndpoint(apsFrame.getDestinationEndpoint()); emberApsFrame.setSequence(apsFrame.getApsCounter()); if (apsFrame.getAckRequest()) { 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.getSecurityEnabled()) { emberApsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_ENCRYPTION); } if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.DEVICE && !ZigBeeBroadcastDestination.isBroadcast(apsFrame.getDestinationAddress())) { EzspSendUnicastRequest emberUnicast = new EzspSendUnicastRequest(); emberUnicast.setIndexOrDestination(apsFrame.getDestinationAddress()); emberUnicast.setMessageTag(msgTag); emberUnicast.setType(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT); emberUnicast.setApsFrame(emberApsFrame); emberUnicast.setMessageContents(apsFrame.getPayload()); if (apsFrame instanceof ZigBeeApsFrameFragment) { ZigBeeApsFrameFragment fragment = (ZigBeeApsFrameFragment) apsFrame; emberApsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_FRAGMENT); emberApsFrame.setGroupId(fragment.getFragmentNumber() + (fragment.getFragmentTotal() << 8)); if (fragment.getFragmentNumber() != 0) { emberApsFrame.setSequence(fragmentationApsCounters.get(msgTag)); } if (fragment.getFragmentNumber() == fragment.getFragmentTotal() - 1) { fragmentationApsCounters.remove(msgTag); } } transaction = new EzspSingleResponseTransaction(emberUnicast, EzspSendUnicastResponse.class); } else if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.DEVICE && ZigBeeBroadcastDestination.isBroadcast(apsFrame.getDestinationAddress())) { EzspSendBroadcastRequest emberBroadcast = new EzspSendBroadcastRequest(); emberBroadcast.setDestination(apsFrame.getDestinationAddress()); emberBroadcast.setMessageTag(msgTag); emberBroadcast.setApsFrame(emberApsFrame); emberBroadcast.setRadius(apsFrame.getRadius()); emberBroadcast.setMessageContents(apsFrame.getPayload()); transaction = new EzspSingleResponseTransaction(emberBroadcast, EzspSendBroadcastResponse.class); } 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(msgTag); emberMulticast.setMessageContents(apsFrame.getPayload()); transaction = new EzspSingleResponseTransaction(emberMulticast, EzspSendMulticastResponse.class); } else { logger.debug("EZSP message not sent as unknown address mode: {}", apsFrame); return; } executorService.execute(new Runnable() { @Override public void run() { frameHandler.sendEzspTransaction(transaction); EmberStatus status = null; if (transaction.getResponse() instanceof EzspSendUnicastResponse) { fragmentationApsCounters.put(msgTag, ((EzspSendUnicastResponse) transaction.getResponse()).getSequence()); status = ((EzspSendUnicastResponse) transaction.getResponse()).getStatus(); } else if (transaction.getResponse() instanceof EzspSendBroadcastResponse) { status = ((EzspSendBroadcastResponse) transaction.getResponse()).getStatus(); } else if (transaction.getResponse() instanceof EzspSendMulticastResponse) { status = ((EzspSendMulticastResponse) transaction.getResponse()).getStatus(); } else { logger.debug("Unable to get response from {} :: {}", transaction.getRequest(), transaction.getResponse()); return; } if (status == EmberStatus.EMBER_SUCCESS) { return; } zigbeeTransportReceive.receiveCommandState(msgTag, ZigBeeTransportProgressState.TX_NAK); } }); } }
ZigBeeDongleEzsp implements ZigBeeTransportTransmit, ZigBeeTransportFirmwareUpdate, EzspFrameHandler { @Override public void sendCommand(final int msgTag, final ZigBeeApsFrame apsFrame) { if (frameHandler == null) { return; } lastSendCommand = System.currentTimeMillis(); EzspTransaction transaction; EmberApsFrame emberApsFrame = new EmberApsFrame(); emberApsFrame.setClusterId(apsFrame.getCluster()); emberApsFrame.setProfileId(apsFrame.getProfile()); emberApsFrame.setSourceEndpoint(apsFrame.getSourceEndpoint()); emberApsFrame.setDestinationEndpoint(apsFrame.getDestinationEndpoint()); emberApsFrame.setSequence(apsFrame.getApsCounter()); if (apsFrame.getAckRequest()) { 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.getSecurityEnabled()) { emberApsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_ENCRYPTION); } if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.DEVICE && !ZigBeeBroadcastDestination.isBroadcast(apsFrame.getDestinationAddress())) { EzspSendUnicastRequest emberUnicast = new EzspSendUnicastRequest(); emberUnicast.setIndexOrDestination(apsFrame.getDestinationAddress()); emberUnicast.setMessageTag(msgTag); emberUnicast.setType(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT); emberUnicast.setApsFrame(emberApsFrame); emberUnicast.setMessageContents(apsFrame.getPayload()); if (apsFrame instanceof ZigBeeApsFrameFragment) { ZigBeeApsFrameFragment fragment = (ZigBeeApsFrameFragment) apsFrame; emberApsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_FRAGMENT); emberApsFrame.setGroupId(fragment.getFragmentNumber() + (fragment.getFragmentTotal() << 8)); if (fragment.getFragmentNumber() != 0) { emberApsFrame.setSequence(fragmentationApsCounters.get(msgTag)); } if (fragment.getFragmentNumber() == fragment.getFragmentTotal() - 1) { fragmentationApsCounters.remove(msgTag); } } transaction = new EzspSingleResponseTransaction(emberUnicast, EzspSendUnicastResponse.class); } else if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.DEVICE && ZigBeeBroadcastDestination.isBroadcast(apsFrame.getDestinationAddress())) { EzspSendBroadcastRequest emberBroadcast = new EzspSendBroadcastRequest(); emberBroadcast.setDestination(apsFrame.getDestinationAddress()); emberBroadcast.setMessageTag(msgTag); emberBroadcast.setApsFrame(emberApsFrame); emberBroadcast.setRadius(apsFrame.getRadius()); emberBroadcast.setMessageContents(apsFrame.getPayload()); transaction = new EzspSingleResponseTransaction(emberBroadcast, EzspSendBroadcastResponse.class); } 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(msgTag); emberMulticast.setMessageContents(apsFrame.getPayload()); transaction = new EzspSingleResponseTransaction(emberMulticast, EzspSendMulticastResponse.class); } else { logger.debug("EZSP message not sent as unknown address mode: {}", apsFrame); return; } executorService.execute(new Runnable() { @Override public void run() { frameHandler.sendEzspTransaction(transaction); EmberStatus status = null; if (transaction.getResponse() instanceof EzspSendUnicastResponse) { fragmentationApsCounters.put(msgTag, ((EzspSendUnicastResponse) transaction.getResponse()).getSequence()); status = ((EzspSendUnicastResponse) transaction.getResponse()).getStatus(); } else if (transaction.getResponse() instanceof EzspSendBroadcastResponse) { status = ((EzspSendBroadcastResponse) transaction.getResponse()).getStatus(); } else if (transaction.getResponse() instanceof EzspSendMulticastResponse) { status = ((EzspSendMulticastResponse) transaction.getResponse()).getStatus(); } else { logger.debug("Unable to get response from {} :: {}", transaction.getRequest(), transaction.getResponse()); return; } if (status == EmberStatus.EMBER_SUCCESS) { return; } zigbeeTransportReceive.receiveCommandState(msgTag, ZigBeeTransportProgressState.TX_NAK); } }); } ZigBeeDongleEzsp(final ZigBeePort serialPort);  ZigBeeDongleEzsp(final ZigBeePort serialPort, final EmberSerialProtocol protocol); }
ZigBeeDongleEzsp implements ZigBeeTransportTransmit, ZigBeeTransportFirmwareUpdate, EzspFrameHandler { @Override public void sendCommand(final int msgTag, final ZigBeeApsFrame apsFrame) { if (frameHandler == null) { return; } lastSendCommand = System.currentTimeMillis(); EzspTransaction transaction; EmberApsFrame emberApsFrame = new EmberApsFrame(); emberApsFrame.setClusterId(apsFrame.getCluster()); emberApsFrame.setProfileId(apsFrame.getProfile()); emberApsFrame.setSourceEndpoint(apsFrame.getSourceEndpoint()); emberApsFrame.setDestinationEndpoint(apsFrame.getDestinationEndpoint()); emberApsFrame.setSequence(apsFrame.getApsCounter()); if (apsFrame.getAckRequest()) { 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.getSecurityEnabled()) { emberApsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_ENCRYPTION); } if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.DEVICE && !ZigBeeBroadcastDestination.isBroadcast(apsFrame.getDestinationAddress())) { EzspSendUnicastRequest emberUnicast = new EzspSendUnicastRequest(); emberUnicast.setIndexOrDestination(apsFrame.getDestinationAddress()); emberUnicast.setMessageTag(msgTag); emberUnicast.setType(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT); emberUnicast.setApsFrame(emberApsFrame); emberUnicast.setMessageContents(apsFrame.getPayload()); if (apsFrame instanceof ZigBeeApsFrameFragment) { ZigBeeApsFrameFragment fragment = (ZigBeeApsFrameFragment) apsFrame; emberApsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_FRAGMENT); emberApsFrame.setGroupId(fragment.getFragmentNumber() + (fragment.getFragmentTotal() << 8)); if (fragment.getFragmentNumber() != 0) { emberApsFrame.setSequence(fragmentationApsCounters.get(msgTag)); } if (fragment.getFragmentNumber() == fragment.getFragmentTotal() - 1) { fragmentationApsCounters.remove(msgTag); } } transaction = new EzspSingleResponseTransaction(emberUnicast, EzspSendUnicastResponse.class); } else if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.DEVICE && ZigBeeBroadcastDestination.isBroadcast(apsFrame.getDestinationAddress())) { EzspSendBroadcastRequest emberBroadcast = new EzspSendBroadcastRequest(); emberBroadcast.setDestination(apsFrame.getDestinationAddress()); emberBroadcast.setMessageTag(msgTag); emberBroadcast.setApsFrame(emberApsFrame); emberBroadcast.setRadius(apsFrame.getRadius()); emberBroadcast.setMessageContents(apsFrame.getPayload()); transaction = new EzspSingleResponseTransaction(emberBroadcast, EzspSendBroadcastResponse.class); } 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(msgTag); emberMulticast.setMessageContents(apsFrame.getPayload()); transaction = new EzspSingleResponseTransaction(emberMulticast, EzspSendMulticastResponse.class); } else { logger.debug("EZSP message not sent as unknown address mode: {}", apsFrame); return; } executorService.execute(new Runnable() { @Override public void run() { frameHandler.sendEzspTransaction(transaction); EmberStatus status = null; if (transaction.getResponse() instanceof EzspSendUnicastResponse) { fragmentationApsCounters.put(msgTag, ((EzspSendUnicastResponse) transaction.getResponse()).getSequence()); status = ((EzspSendUnicastResponse) transaction.getResponse()).getStatus(); } else if (transaction.getResponse() instanceof EzspSendBroadcastResponse) { status = ((EzspSendBroadcastResponse) transaction.getResponse()).getStatus(); } else if (transaction.getResponse() instanceof EzspSendMulticastResponse) { status = ((EzspSendMulticastResponse) transaction.getResponse()).getStatus(); } else { logger.debug("Unable to get response from {} :: {}", transaction.getRequest(), transaction.getResponse()); return; } if (status == EmberStatus.EMBER_SUCCESS) { return; } zigbeeTransportReceive.receiveCommandState(msgTag, ZigBeeTransportProgressState.TX_NAK); } }); } ZigBeeDongleEzsp(final ZigBeePort serialPort);  ZigBeeDongleEzsp(final ZigBeePort serialPort, final EmberSerialProtocol protocol); void setEmberNcpResetProvider(EmberNcpResetProvider resetProvider); Integer updateDefaultConfiguration(EzspConfigId configId, Integer value); EzspDecisionId updateDefaultPolicy(EzspPolicyId policyId, EzspDecisionId decisionId); EmberMfglib getEmberMfglib(EmberMfglibListener mfglibListener); @Override void setDefaultProfileId(int defaultProfileId); @Override void setDefaultDeviceId(int defaultDeviceId); @Override ZigBeeStatus initialize(); @Override ZigBeeStatus startup(boolean reinitialize); void setPollRate(int pollRate); @Override void shutdown(); void passLoopbackMessages(boolean passLoopbackMessages); EmberNcp getEmberNcp(); EmberCbkeProvider getEmberCbkeProvider(); @Override IeeeAddress getIeeeAddress(); @Override Integer getNwkAddress(); @Override void sendCommand(final int msgTag, final ZigBeeApsFrame apsFrame); @Override void setZigBeeTransportReceive(ZigBeeTransportReceive zigbeeTransportReceive); @Override void setNodeDescriptor(IeeeAddress ieeeAddress, NodeDescriptor nodeDescriptor); @Override void handlePacket(EzspFrame response); @Override void handleLinkStateChange(final boolean linkState); @Override ZigBeeChannel getZigBeeChannel(); @Override ZigBeeStatus setZigBeeChannel(ZigBeeChannel channel); @Override int getZigBeePanId(); @Override ZigBeeStatus setZigBeePanId(int panId); @Override ExtendedPanId getZigBeeExtendedPanId(); @Override ZigBeeStatus setZigBeeExtendedPanId(ExtendedPanId extendedPanId); @Override ZigBeeStatus setZigBeeNetworkKey(final ZigBeeKey key); @Override ZigBeeKey getZigBeeNetworkKey(); @Override ZigBeeStatus setTcLinkKey(ZigBeeKey key); @Override ZigBeeKey getTcLinkKey(); @Override void updateTransportConfig(TransportConfig configuration); @Override String getVersionString(); @Override boolean updateFirmware(final InputStream firmware, final ZigBeeTransportFirmwareCallback callback); void bootloadComplete(); @Override String getFirmwareVersion(); @Override boolean cancelUpdateFirmware(); Map<String, Long> getCounters(); }
ZigBeeDongleEzsp implements ZigBeeTransportTransmit, ZigBeeTransportFirmwareUpdate, EzspFrameHandler { @Override public void sendCommand(final int msgTag, final ZigBeeApsFrame apsFrame) { if (frameHandler == null) { return; } lastSendCommand = System.currentTimeMillis(); EzspTransaction transaction; EmberApsFrame emberApsFrame = new EmberApsFrame(); emberApsFrame.setClusterId(apsFrame.getCluster()); emberApsFrame.setProfileId(apsFrame.getProfile()); emberApsFrame.setSourceEndpoint(apsFrame.getSourceEndpoint()); emberApsFrame.setDestinationEndpoint(apsFrame.getDestinationEndpoint()); emberApsFrame.setSequence(apsFrame.getApsCounter()); if (apsFrame.getAckRequest()) { 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.getSecurityEnabled()) { emberApsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_ENCRYPTION); } if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.DEVICE && !ZigBeeBroadcastDestination.isBroadcast(apsFrame.getDestinationAddress())) { EzspSendUnicastRequest emberUnicast = new EzspSendUnicastRequest(); emberUnicast.setIndexOrDestination(apsFrame.getDestinationAddress()); emberUnicast.setMessageTag(msgTag); emberUnicast.setType(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT); emberUnicast.setApsFrame(emberApsFrame); emberUnicast.setMessageContents(apsFrame.getPayload()); if (apsFrame instanceof ZigBeeApsFrameFragment) { ZigBeeApsFrameFragment fragment = (ZigBeeApsFrameFragment) apsFrame; emberApsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_FRAGMENT); emberApsFrame.setGroupId(fragment.getFragmentNumber() + (fragment.getFragmentTotal() << 8)); if (fragment.getFragmentNumber() != 0) { emberApsFrame.setSequence(fragmentationApsCounters.get(msgTag)); } if (fragment.getFragmentNumber() == fragment.getFragmentTotal() - 1) { fragmentationApsCounters.remove(msgTag); } } transaction = new EzspSingleResponseTransaction(emberUnicast, EzspSendUnicastResponse.class); } else if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.DEVICE && ZigBeeBroadcastDestination.isBroadcast(apsFrame.getDestinationAddress())) { EzspSendBroadcastRequest emberBroadcast = new EzspSendBroadcastRequest(); emberBroadcast.setDestination(apsFrame.getDestinationAddress()); emberBroadcast.setMessageTag(msgTag); emberBroadcast.setApsFrame(emberApsFrame); emberBroadcast.setRadius(apsFrame.getRadius()); emberBroadcast.setMessageContents(apsFrame.getPayload()); transaction = new EzspSingleResponseTransaction(emberBroadcast, EzspSendBroadcastResponse.class); } 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(msgTag); emberMulticast.setMessageContents(apsFrame.getPayload()); transaction = new EzspSingleResponseTransaction(emberMulticast, EzspSendMulticastResponse.class); } else { logger.debug("EZSP message not sent as unknown address mode: {}", apsFrame); return; } executorService.execute(new Runnable() { @Override public void run() { frameHandler.sendEzspTransaction(transaction); EmberStatus status = null; if (transaction.getResponse() instanceof EzspSendUnicastResponse) { fragmentationApsCounters.put(msgTag, ((EzspSendUnicastResponse) transaction.getResponse()).getSequence()); status = ((EzspSendUnicastResponse) transaction.getResponse()).getStatus(); } else if (transaction.getResponse() instanceof EzspSendBroadcastResponse) { status = ((EzspSendBroadcastResponse) transaction.getResponse()).getStatus(); } else if (transaction.getResponse() instanceof EzspSendMulticastResponse) { status = ((EzspSendMulticastResponse) transaction.getResponse()).getStatus(); } else { logger.debug("Unable to get response from {} :: {}", transaction.getRequest(), transaction.getResponse()); return; } if (status == EmberStatus.EMBER_SUCCESS) { return; } zigbeeTransportReceive.receiveCommandState(msgTag, ZigBeeTransportProgressState.TX_NAK); } }); } ZigBeeDongleEzsp(final ZigBeePort serialPort);  ZigBeeDongleEzsp(final ZigBeePort serialPort, final EmberSerialProtocol protocol); void setEmberNcpResetProvider(EmberNcpResetProvider resetProvider); Integer updateDefaultConfiguration(EzspConfigId configId, Integer value); EzspDecisionId updateDefaultPolicy(EzspPolicyId policyId, EzspDecisionId decisionId); EmberMfglib getEmberMfglib(EmberMfglibListener mfglibListener); @Override void setDefaultProfileId(int defaultProfileId); @Override void setDefaultDeviceId(int defaultDeviceId); @Override ZigBeeStatus initialize(); @Override ZigBeeStatus startup(boolean reinitialize); void setPollRate(int pollRate); @Override void shutdown(); void passLoopbackMessages(boolean passLoopbackMessages); EmberNcp getEmberNcp(); EmberCbkeProvider getEmberCbkeProvider(); @Override IeeeAddress getIeeeAddress(); @Override Integer getNwkAddress(); @Override void sendCommand(final int msgTag, final ZigBeeApsFrame apsFrame); @Override void setZigBeeTransportReceive(ZigBeeTransportReceive zigbeeTransportReceive); @Override void setNodeDescriptor(IeeeAddress ieeeAddress, NodeDescriptor nodeDescriptor); @Override void handlePacket(EzspFrame response); @Override void handleLinkStateChange(final boolean linkState); @Override ZigBeeChannel getZigBeeChannel(); @Override ZigBeeStatus setZigBeeChannel(ZigBeeChannel channel); @Override int getZigBeePanId(); @Override ZigBeeStatus setZigBeePanId(int panId); @Override ExtendedPanId getZigBeeExtendedPanId(); @Override ZigBeeStatus setZigBeeExtendedPanId(ExtendedPanId extendedPanId); @Override ZigBeeStatus setZigBeeNetworkKey(final ZigBeeKey key); @Override ZigBeeKey getZigBeeNetworkKey(); @Override ZigBeeStatus setTcLinkKey(ZigBeeKey key); @Override ZigBeeKey getTcLinkKey(); @Override void updateTransportConfig(TransportConfig configuration); @Override String getVersionString(); @Override boolean updateFirmware(final InputStream firmware, final ZigBeeTransportFirmwareCallback callback); void bootloadComplete(); @Override String getFirmwareVersion(); @Override boolean cancelUpdateFirmware(); Map<String, Long> getCounters();  }