@Test public void sendCommand() { XBeeFrameHandler frameHandler = Mockito.mock(XBeeFrameHandler.class); ArgumentCaptor<XBeeCommand> commandCapture = ArgumentCaptor.forClass(XBeeCommand.class); Mockito.when(frameHandler.sendRequestAsync(commandCapture.capture())).thenReturn(null); ZigBeeDongleXBee dongle = new ZigBeeDongleXBee(null); Field field; try { field = dongle.getClass().getDeclaredField("frameHandler"); field.setAccessible(true); field.set(dongle, frameHandler); } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { e.printStackTrace(); } List<Integer> matchList = new ArrayList<>(); matchList.add(1); MatchDescriptorResponse command = new MatchDescriptorResponse(ZdoStatus.SUCCESS, 46946, matchList); command.setDestinationAddress(new ZigBeeEndpointAddress(46946)); command.setTransactionId(0x2A); ZigBeeApsFrame apsFrame = new ZigBeeApsFrame(); apsFrame.setDestinationAddress(46946); apsFrame.setDestinationEndpoint(0); apsFrame.setDestinationIeeeAddress(new IeeeAddress("000D6F00057CF7C6")); apsFrame.setCluster(32774); apsFrame.setAddressMode(ZigBeeNwkAddressMode.DEVICE); apsFrame.setRadius(31); apsFrame.setApsCounter(42); apsFrame.setAckRequest(true); apsFrame.setPayload(new int[] { 0x00, 0x00, 0x2E, 0x5B, 0x01, 0x01 }); System.out.println(command); System.out.println(apsFrame); dongle.sendCommand(1, apsFrame); assertEquals(1, commandCapture.getAllValues().size()); XBeeTransmitRequestExplicitCommand sentCommand = (XBeeTransmitRequestExplicitCommand) commandCapture.getValue(); sentCommand.setFrameId(32); System.out.println(sentCommand); int[] payload = new int[] { 0, 26, 17, 32, 0, 13, 111, 0, 5, 124, 247, 198, 183, 98, 0, 0, 128, 6, 0, 0, 0, 0, 0, 0, 46, 91, 1, 1, 234 }; int[] output = sentCommand.serialize(); assertTrue(Arrays.equals(payload, output)); }
@Override public void sendCommand(final int msgTag, final ZigBeeApsFrame apsFrame) { if (frameHandler == null) { logger.debug("XBee frame handler not set for send."); return; } XBeeTransmitRequestExplicitCommand command = new XBeeTransmitRequestExplicitCommand(); command.setNetworkAddress(apsFrame.getDestinationAddress()); command.setDestinationEndpoint(apsFrame.getDestinationEndpoint()); command.setSourceEndpoint(apsFrame.getSourceEndpoint()); command.setProfileId(apsFrame.getProfile()); command.setCluster(apsFrame.getCluster()); command.setBroadcastRadius(0); if (apsFrame.getDestinationAddress() > 0xFFF8) { command.setIeeeAddress(broadcastIeeeAddress); } else if (apsFrame.getDestinationIeeeAddress() == null) { if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.GROUP) { command.setIeeeAddress(groupIeeeAddress); } else { } command.setIeeeAddress(new IeeeAddress("FFFFFFFFFFFFFFFF")); } else { command.setIeeeAddress(apsFrame.getDestinationIeeeAddress()); } if (apsFrame.getSecurityEnabled()) { command.addOptions(TransmitOptions.ENABLE_APS_ENCRYPTION); } if (!apsFrame.getAckRequest()) { command.addOptions(TransmitOptions.DISABLE_RETRIES); } command.setData(apsFrame.getPayload()); command.setFrameId(msgTag); logger.debug("XBee send: {}", command.toString()); Future<XBeeResponse> responseFuture = frameHandler.sendRequestAsync(command); executorService.execute(new Runnable() { @Override public void run() { zigbeeTransportReceive.receiveCommandState(msgTag, ZigBeeTransportProgressState.TX_ACK); ZigBeeTransportProgressState sentHandlerState = ZigBeeTransportProgressState.RX_NAK; try { XBeeResponse response = responseFuture.get(RESPONSE_TIMEOUT, TimeUnit.MILLISECONDS); if (response instanceof XBeeTransmitStatusResponse) { XBeeTransmitStatusResponse sentHandler = (XBeeTransmitStatusResponse) response; if (sentHandler.getDeliveryStatus() == DeliveryStatus.SUCCESS) { sentHandlerState = ZigBeeTransportProgressState.RX_ACK; } } } catch (InterruptedException | ExecutionException | TimeoutException e) { } zigbeeTransportReceive.receiveCommandState(msgTag, sentHandlerState); } }); }
ZigBeeDongleXBee implements ZigBeeTransportTransmit, XBeeEventListener { @Override public void sendCommand(final int msgTag, final ZigBeeApsFrame apsFrame) { if (frameHandler == null) { logger.debug("XBee frame handler not set for send."); return; } XBeeTransmitRequestExplicitCommand command = new XBeeTransmitRequestExplicitCommand(); command.setNetworkAddress(apsFrame.getDestinationAddress()); command.setDestinationEndpoint(apsFrame.getDestinationEndpoint()); command.setSourceEndpoint(apsFrame.getSourceEndpoint()); command.setProfileId(apsFrame.getProfile()); command.setCluster(apsFrame.getCluster()); command.setBroadcastRadius(0); if (apsFrame.getDestinationAddress() > 0xFFF8) { command.setIeeeAddress(broadcastIeeeAddress); } else if (apsFrame.getDestinationIeeeAddress() == null) { if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.GROUP) { command.setIeeeAddress(groupIeeeAddress); } else { } command.setIeeeAddress(new IeeeAddress("FFFFFFFFFFFFFFFF")); } else { command.setIeeeAddress(apsFrame.getDestinationIeeeAddress()); } if (apsFrame.getSecurityEnabled()) { command.addOptions(TransmitOptions.ENABLE_APS_ENCRYPTION); } if (!apsFrame.getAckRequest()) { command.addOptions(TransmitOptions.DISABLE_RETRIES); } command.setData(apsFrame.getPayload()); command.setFrameId(msgTag); logger.debug("XBee send: {}", command.toString()); Future<XBeeResponse> responseFuture = frameHandler.sendRequestAsync(command); executorService.execute(new Runnable() { @Override public void run() { zigbeeTransportReceive.receiveCommandState(msgTag, ZigBeeTransportProgressState.TX_ACK); ZigBeeTransportProgressState sentHandlerState = ZigBeeTransportProgressState.RX_NAK; try { XBeeResponse response = responseFuture.get(RESPONSE_TIMEOUT, TimeUnit.MILLISECONDS); if (response instanceof XBeeTransmitStatusResponse) { XBeeTransmitStatusResponse sentHandler = (XBeeTransmitStatusResponse) response; if (sentHandler.getDeliveryStatus() == DeliveryStatus.SUCCESS) { sentHandlerState = ZigBeeTransportProgressState.RX_ACK; } } } catch (InterruptedException | ExecutionException | TimeoutException e) { } zigbeeTransportReceive.receiveCommandState(msgTag, sentHandlerState); } }); } }
ZigBeeDongleXBee implements ZigBeeTransportTransmit, XBeeEventListener { @Override public void sendCommand(final int msgTag, final ZigBeeApsFrame apsFrame) { if (frameHandler == null) { logger.debug("XBee frame handler not set for send."); return; } XBeeTransmitRequestExplicitCommand command = new XBeeTransmitRequestExplicitCommand(); command.setNetworkAddress(apsFrame.getDestinationAddress()); command.setDestinationEndpoint(apsFrame.getDestinationEndpoint()); command.setSourceEndpoint(apsFrame.getSourceEndpoint()); command.setProfileId(apsFrame.getProfile()); command.setCluster(apsFrame.getCluster()); command.setBroadcastRadius(0); if (apsFrame.getDestinationAddress() > 0xFFF8) { command.setIeeeAddress(broadcastIeeeAddress); } else if (apsFrame.getDestinationIeeeAddress() == null) { if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.GROUP) { command.setIeeeAddress(groupIeeeAddress); } else { } command.setIeeeAddress(new IeeeAddress("FFFFFFFFFFFFFFFF")); } else { command.setIeeeAddress(apsFrame.getDestinationIeeeAddress()); } if (apsFrame.getSecurityEnabled()) { command.addOptions(TransmitOptions.ENABLE_APS_ENCRYPTION); } if (!apsFrame.getAckRequest()) { command.addOptions(TransmitOptions.DISABLE_RETRIES); } command.setData(apsFrame.getPayload()); command.setFrameId(msgTag); logger.debug("XBee send: {}", command.toString()); Future<XBeeResponse> responseFuture = frameHandler.sendRequestAsync(command); executorService.execute(new Runnable() { @Override public void run() { zigbeeTransportReceive.receiveCommandState(msgTag, ZigBeeTransportProgressState.TX_ACK); ZigBeeTransportProgressState sentHandlerState = ZigBeeTransportProgressState.RX_NAK; try { XBeeResponse response = responseFuture.get(RESPONSE_TIMEOUT, TimeUnit.MILLISECONDS); if (response instanceof XBeeTransmitStatusResponse) { XBeeTransmitStatusResponse sentHandler = (XBeeTransmitStatusResponse) response; if (sentHandler.getDeliveryStatus() == DeliveryStatus.SUCCESS) { sentHandlerState = ZigBeeTransportProgressState.RX_ACK; } } } catch (InterruptedException | ExecutionException | TimeoutException e) { } zigbeeTransportReceive.receiveCommandState(msgTag, sentHandlerState); } }); } ZigBeeDongleXBee(final ZigBeePort serialPort); }
ZigBeeDongleXBee implements ZigBeeTransportTransmit, XBeeEventListener { @Override public void sendCommand(final int msgTag, final ZigBeeApsFrame apsFrame) { if (frameHandler == null) { logger.debug("XBee frame handler not set for send."); return; } XBeeTransmitRequestExplicitCommand command = new XBeeTransmitRequestExplicitCommand(); command.setNetworkAddress(apsFrame.getDestinationAddress()); command.setDestinationEndpoint(apsFrame.getDestinationEndpoint()); command.setSourceEndpoint(apsFrame.getSourceEndpoint()); command.setProfileId(apsFrame.getProfile()); command.setCluster(apsFrame.getCluster()); command.setBroadcastRadius(0); if (apsFrame.getDestinationAddress() > 0xFFF8) { command.setIeeeAddress(broadcastIeeeAddress); } else if (apsFrame.getDestinationIeeeAddress() == null) { if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.GROUP) { command.setIeeeAddress(groupIeeeAddress); } else { } command.setIeeeAddress(new IeeeAddress("FFFFFFFFFFFFFFFF")); } else { command.setIeeeAddress(apsFrame.getDestinationIeeeAddress()); } if (apsFrame.getSecurityEnabled()) { command.addOptions(TransmitOptions.ENABLE_APS_ENCRYPTION); } if (!apsFrame.getAckRequest()) { command.addOptions(TransmitOptions.DISABLE_RETRIES); } command.setData(apsFrame.getPayload()); command.setFrameId(msgTag); logger.debug("XBee send: {}", command.toString()); Future<XBeeResponse> responseFuture = frameHandler.sendRequestAsync(command); executorService.execute(new Runnable() { @Override public void run() { zigbeeTransportReceive.receiveCommandState(msgTag, ZigBeeTransportProgressState.TX_ACK); ZigBeeTransportProgressState sentHandlerState = ZigBeeTransportProgressState.RX_NAK; try { XBeeResponse response = responseFuture.get(RESPONSE_TIMEOUT, TimeUnit.MILLISECONDS); if (response instanceof XBeeTransmitStatusResponse) { XBeeTransmitStatusResponse sentHandler = (XBeeTransmitStatusResponse) response; if (sentHandler.getDeliveryStatus() == DeliveryStatus.SUCCESS) { sentHandlerState = ZigBeeTransportProgressState.RX_ACK; } } } catch (InterruptedException | ExecutionException | TimeoutException e) { } zigbeeTransportReceive.receiveCommandState(msgTag, sentHandlerState); } }); } ZigBeeDongleXBee(final ZigBeePort serialPort); @Override ZigBeeStatus initialize(); @Override ZigBeeStatus startup(boolean reinitialize); @Override void shutdown(); @Override IeeeAddress getIeeeAddress(); @Override Integer getNwkAddress(); @Override void sendCommand(final int msgTag, final ZigBeeApsFrame apsFrame); @Override void setZigBeeTransportReceive(ZigBeeTransportReceive zigbeeTransportReceive); @Override void xbeeEventReceived(XBeeEvent event); @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 String getVersionString(); @Override ZigBeeStatus setTcLinkKey(ZigBeeKey key); @Override ZigBeeKey getTcLinkKey(); @Override void updateTransportConfig(TransportConfig configuration); }
ZigBeeDongleXBee implements ZigBeeTransportTransmit, XBeeEventListener { @Override public void sendCommand(final int msgTag, final ZigBeeApsFrame apsFrame) { if (frameHandler == null) { logger.debug("XBee frame handler not set for send."); return; } XBeeTransmitRequestExplicitCommand command = new XBeeTransmitRequestExplicitCommand(); command.setNetworkAddress(apsFrame.getDestinationAddress()); command.setDestinationEndpoint(apsFrame.getDestinationEndpoint()); command.setSourceEndpoint(apsFrame.getSourceEndpoint()); command.setProfileId(apsFrame.getProfile()); command.setCluster(apsFrame.getCluster()); command.setBroadcastRadius(0); if (apsFrame.getDestinationAddress() > 0xFFF8) { command.setIeeeAddress(broadcastIeeeAddress); } else if (apsFrame.getDestinationIeeeAddress() == null) { if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.GROUP) { command.setIeeeAddress(groupIeeeAddress); } else { } command.setIeeeAddress(new IeeeAddress("FFFFFFFFFFFFFFFF")); } else { command.setIeeeAddress(apsFrame.getDestinationIeeeAddress()); } if (apsFrame.getSecurityEnabled()) { command.addOptions(TransmitOptions.ENABLE_APS_ENCRYPTION); } if (!apsFrame.getAckRequest()) { command.addOptions(TransmitOptions.DISABLE_RETRIES); } command.setData(apsFrame.getPayload()); command.setFrameId(msgTag); logger.debug("XBee send: {}", command.toString()); Future<XBeeResponse> responseFuture = frameHandler.sendRequestAsync(command); executorService.execute(new Runnable() { @Override public void run() { zigbeeTransportReceive.receiveCommandState(msgTag, ZigBeeTransportProgressState.TX_ACK); ZigBeeTransportProgressState sentHandlerState = ZigBeeTransportProgressState.RX_NAK; try { XBeeResponse response = responseFuture.get(RESPONSE_TIMEOUT, TimeUnit.MILLISECONDS); if (response instanceof XBeeTransmitStatusResponse) { XBeeTransmitStatusResponse sentHandler = (XBeeTransmitStatusResponse) response; if (sentHandler.getDeliveryStatus() == DeliveryStatus.SUCCESS) { sentHandlerState = ZigBeeTransportProgressState.RX_ACK; } } } catch (InterruptedException | ExecutionException | TimeoutException e) { } zigbeeTransportReceive.receiveCommandState(msgTag, sentHandlerState); } }); } ZigBeeDongleXBee(final ZigBeePort serialPort); @Override ZigBeeStatus initialize(); @Override ZigBeeStatus startup(boolean reinitialize); @Override void shutdown(); @Override IeeeAddress getIeeeAddress(); @Override Integer getNwkAddress(); @Override void sendCommand(final int msgTag, final ZigBeeApsFrame apsFrame); @Override void setZigBeeTransportReceive(ZigBeeTransportReceive zigbeeTransportReceive); @Override void xbeeEventReceived(XBeeEvent event); @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 String getVersionString(); @Override ZigBeeStatus setTcLinkKey(ZigBeeKey key); @Override ZigBeeKey getTcLinkKey(); @Override void updateTransportConfig(TransportConfig configuration);  }