@Test public void sendCommandBroadcast() throws Exception { ZigBeeDongleTelegesis dongle = new ZigBeeDongleTelegesis(null); TelegesisFrameHandler handler = Mockito.mock(TelegesisFrameHandler.class); TestUtilities.setField(ZigBeeDongleTelegesis.class, dongle, "frameHandler", handler); TestUtilities.setField(ZigBeeDongleTelegesis.class, dongle, "zigbeeTransportReceive", Mockito.mock(ZigBeeTransportReceive.class)); ZigBeeApsFrame apsFrame = new ZigBeeApsFrame(); apsFrame.setCluster(0); apsFrame.setProfile(ZigBeeProfileType.ZIGBEE_HOME_AUTOMATION.getKey()); apsFrame.setAddressMode(ZigBeeNwkAddressMode.DEVICE); apsFrame.setDestinationAddress(0xfff9); apsFrame.setApsCounter(1); apsFrame.setRadius(30); apsFrame.setPayload(new int[] {}); dongle.sendCommand(1, apsFrame); Mockito.verify(handler, Mockito.timeout(TIMEOUT).times(1)) .sendRequest(ArgumentMatchers.any(TelegesisSendMulticastCommand.class)); }
@Override public void sendCommand(final int msgTag, final ZigBeeApsFrame apsFrame) { if (frameHandler == null) { logger.debug("Telegesis frame handler not set for send."); return; } lastSendCommand = System.currentTimeMillis(); TelegesisCommand command; if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.DEVICE && !ZigBeeBroadcastDestination.isBroadcast(apsFrame.getDestinationAddress())) { TelegesisSendUnicastCommand unicastCommand = new TelegesisSendUnicastCommand(); unicastCommand.setAddress(apsFrame.getDestinationAddress()); unicastCommand.setDestEp(apsFrame.getDestinationEndpoint()); unicastCommand.setSourceEp(apsFrame.getSourceEndpoint()); unicastCommand.setProfileId(apsFrame.getProfile()); unicastCommand.setClusterId(apsFrame.getCluster()); unicastCommand.setMessageData(apsFrame.getPayload()); command = unicastCommand; } else if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.DEVICE && ZigBeeBroadcastDestination.isBroadcast(apsFrame.getDestinationAddress())) { TelegesisSendMulticastCommand multicastCommand = new TelegesisSendMulticastCommand(); multicastCommand.setAddress(apsFrame.getDestinationAddress()); multicastCommand.setDestEp(apsFrame.getDestinationEndpoint()); multicastCommand.setProfileId(apsFrame.getProfile()); multicastCommand.setClusterId(apsFrame.getCluster()); multicastCommand.setRadius(apsFrame.getRadius()); multicastCommand.setMessageData(apsFrame.getPayload()); multicastCommand.setSourceEp(apsFrame.getSourceEndpoint()); command = multicastCommand; } else if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.GROUP) { TelegesisSendMulticastCommand multicastCommand = new TelegesisSendMulticastCommand(); command = multicastCommand; } else { logger.debug("Telegesis message not sent: {}", apsFrame); return; } logger.debug("Telegesis send: {}", command.toString()); commandScheduler.execute(new Runnable() { @Override public void run() { frameHandler.sendRequest(command); zigbeeTransportReceive.receiveCommandState(msgTag, command.getStatus() == TelegesisStatusCode.SUCCESS ? ZigBeeTransportProgressState.TX_ACK : ZigBeeTransportProgressState.TX_NAK); if (command instanceof TelegesisSendMulticastCommand) { return; } if (((TelegesisSendUnicastCommand) command).getMessageId() != null) { messageIdMap.put(((TelegesisSendUnicastCommand) command).getMessageId(), msgTag); } } }); }
ZigBeeDongleTelegesis implements ZigBeeTransportTransmit, ZigBeeTransportFirmwareUpdate, TelegesisEventListener { @Override public void sendCommand(final int msgTag, final ZigBeeApsFrame apsFrame) { if (frameHandler == null) { logger.debug("Telegesis frame handler not set for send."); return; } lastSendCommand = System.currentTimeMillis(); TelegesisCommand command; if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.DEVICE && !ZigBeeBroadcastDestination.isBroadcast(apsFrame.getDestinationAddress())) { TelegesisSendUnicastCommand unicastCommand = new TelegesisSendUnicastCommand(); unicastCommand.setAddress(apsFrame.getDestinationAddress()); unicastCommand.setDestEp(apsFrame.getDestinationEndpoint()); unicastCommand.setSourceEp(apsFrame.getSourceEndpoint()); unicastCommand.setProfileId(apsFrame.getProfile()); unicastCommand.setClusterId(apsFrame.getCluster()); unicastCommand.setMessageData(apsFrame.getPayload()); command = unicastCommand; } else if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.DEVICE && ZigBeeBroadcastDestination.isBroadcast(apsFrame.getDestinationAddress())) { TelegesisSendMulticastCommand multicastCommand = new TelegesisSendMulticastCommand(); multicastCommand.setAddress(apsFrame.getDestinationAddress()); multicastCommand.setDestEp(apsFrame.getDestinationEndpoint()); multicastCommand.setProfileId(apsFrame.getProfile()); multicastCommand.setClusterId(apsFrame.getCluster()); multicastCommand.setRadius(apsFrame.getRadius()); multicastCommand.setMessageData(apsFrame.getPayload()); multicastCommand.setSourceEp(apsFrame.getSourceEndpoint()); command = multicastCommand; } else if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.GROUP) { TelegesisSendMulticastCommand multicastCommand = new TelegesisSendMulticastCommand(); command = multicastCommand; } else { logger.debug("Telegesis message not sent: {}", apsFrame); return; } logger.debug("Telegesis send: {}", command.toString()); commandScheduler.execute(new Runnable() { @Override public void run() { frameHandler.sendRequest(command); zigbeeTransportReceive.receiveCommandState(msgTag, command.getStatus() == TelegesisStatusCode.SUCCESS ? ZigBeeTransportProgressState.TX_ACK : ZigBeeTransportProgressState.TX_NAK); if (command instanceof TelegesisSendMulticastCommand) { return; } if (((TelegesisSendUnicastCommand) command).getMessageId() != null) { messageIdMap.put(((TelegesisSendUnicastCommand) command).getMessageId(), msgTag); } } }); } }
ZigBeeDongleTelegesis implements ZigBeeTransportTransmit, ZigBeeTransportFirmwareUpdate, TelegesisEventListener { @Override public void sendCommand(final int msgTag, final ZigBeeApsFrame apsFrame) { if (frameHandler == null) { logger.debug("Telegesis frame handler not set for send."); return; } lastSendCommand = System.currentTimeMillis(); TelegesisCommand command; if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.DEVICE && !ZigBeeBroadcastDestination.isBroadcast(apsFrame.getDestinationAddress())) { TelegesisSendUnicastCommand unicastCommand = new TelegesisSendUnicastCommand(); unicastCommand.setAddress(apsFrame.getDestinationAddress()); unicastCommand.setDestEp(apsFrame.getDestinationEndpoint()); unicastCommand.setSourceEp(apsFrame.getSourceEndpoint()); unicastCommand.setProfileId(apsFrame.getProfile()); unicastCommand.setClusterId(apsFrame.getCluster()); unicastCommand.setMessageData(apsFrame.getPayload()); command = unicastCommand; } else if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.DEVICE && ZigBeeBroadcastDestination.isBroadcast(apsFrame.getDestinationAddress())) { TelegesisSendMulticastCommand multicastCommand = new TelegesisSendMulticastCommand(); multicastCommand.setAddress(apsFrame.getDestinationAddress()); multicastCommand.setDestEp(apsFrame.getDestinationEndpoint()); multicastCommand.setProfileId(apsFrame.getProfile()); multicastCommand.setClusterId(apsFrame.getCluster()); multicastCommand.setRadius(apsFrame.getRadius()); multicastCommand.setMessageData(apsFrame.getPayload()); multicastCommand.setSourceEp(apsFrame.getSourceEndpoint()); command = multicastCommand; } else if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.GROUP) { TelegesisSendMulticastCommand multicastCommand = new TelegesisSendMulticastCommand(); command = multicastCommand; } else { logger.debug("Telegesis message not sent: {}", apsFrame); return; } logger.debug("Telegesis send: {}", command.toString()); commandScheduler.execute(new Runnable() { @Override public void run() { frameHandler.sendRequest(command); zigbeeTransportReceive.receiveCommandState(msgTag, command.getStatus() == TelegesisStatusCode.SUCCESS ? ZigBeeTransportProgressState.TX_ACK : ZigBeeTransportProgressState.TX_NAK); if (command instanceof TelegesisSendMulticastCommand) { return; } if (((TelegesisSendUnicastCommand) command).getMessageId() != null) { messageIdMap.put(((TelegesisSendUnicastCommand) command).getMessageId(), msgTag); } } }); } ZigBeeDongleTelegesis(final ZigBeePort serialPort); }
ZigBeeDongleTelegesis implements ZigBeeTransportTransmit, ZigBeeTransportFirmwareUpdate, TelegesisEventListener { @Override public void sendCommand(final int msgTag, final ZigBeeApsFrame apsFrame) { if (frameHandler == null) { logger.debug("Telegesis frame handler not set for send."); return; } lastSendCommand = System.currentTimeMillis(); TelegesisCommand command; if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.DEVICE && !ZigBeeBroadcastDestination.isBroadcast(apsFrame.getDestinationAddress())) { TelegesisSendUnicastCommand unicastCommand = new TelegesisSendUnicastCommand(); unicastCommand.setAddress(apsFrame.getDestinationAddress()); unicastCommand.setDestEp(apsFrame.getDestinationEndpoint()); unicastCommand.setSourceEp(apsFrame.getSourceEndpoint()); unicastCommand.setProfileId(apsFrame.getProfile()); unicastCommand.setClusterId(apsFrame.getCluster()); unicastCommand.setMessageData(apsFrame.getPayload()); command = unicastCommand; } else if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.DEVICE && ZigBeeBroadcastDestination.isBroadcast(apsFrame.getDestinationAddress())) { TelegesisSendMulticastCommand multicastCommand = new TelegesisSendMulticastCommand(); multicastCommand.setAddress(apsFrame.getDestinationAddress()); multicastCommand.setDestEp(apsFrame.getDestinationEndpoint()); multicastCommand.setProfileId(apsFrame.getProfile()); multicastCommand.setClusterId(apsFrame.getCluster()); multicastCommand.setRadius(apsFrame.getRadius()); multicastCommand.setMessageData(apsFrame.getPayload()); multicastCommand.setSourceEp(apsFrame.getSourceEndpoint()); command = multicastCommand; } else if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.GROUP) { TelegesisSendMulticastCommand multicastCommand = new TelegesisSendMulticastCommand(); command = multicastCommand; } else { logger.debug("Telegesis message not sent: {}", apsFrame); return; } logger.debug("Telegesis send: {}", command.toString()); commandScheduler.execute(new Runnable() { @Override public void run() { frameHandler.sendRequest(command); zigbeeTransportReceive.receiveCommandState(msgTag, command.getStatus() == TelegesisStatusCode.SUCCESS ? ZigBeeTransportProgressState.TX_ACK : ZigBeeTransportProgressState.TX_NAK); if (command instanceof TelegesisSendMulticastCommand) { return; } if (((TelegesisSendUnicastCommand) command).getMessageId() != null) { messageIdMap.put(((TelegesisSendUnicastCommand) command).getMessageId(), msgTag); } } }); } ZigBeeDongleTelegesis(final ZigBeePort serialPort); TelegesisNcp getTelegesisNcp(); @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 telegesisEventReceived(TelegesisEvent event); void telegesisEventReceivedRunnable(TelegesisEvent 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(); void setTelegesisPassword(String telegesisPassword); @Override boolean updateFirmware(final InputStream firmware, final ZigBeeTransportFirmwareCallback callback); void bootloadComplete(); @Override String getFirmwareVersion(); @Override boolean cancelUpdateFirmware(); @Override ZigBeeStatus setTcLinkKey(ZigBeeKey key); @Override ZigBeeKey getTcLinkKey(); @SuppressWarnings("unchecked") @Override void updateTransportConfig(TransportConfig configuration); void reinitializeDongle(Integer panId, ExtendedPanId epanId, Long frameCounter); void notifyStateUpdate(boolean state); }
ZigBeeDongleTelegesis implements ZigBeeTransportTransmit, ZigBeeTransportFirmwareUpdate, TelegesisEventListener { @Override public void sendCommand(final int msgTag, final ZigBeeApsFrame apsFrame) { if (frameHandler == null) { logger.debug("Telegesis frame handler not set for send."); return; } lastSendCommand = System.currentTimeMillis(); TelegesisCommand command; if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.DEVICE && !ZigBeeBroadcastDestination.isBroadcast(apsFrame.getDestinationAddress())) { TelegesisSendUnicastCommand unicastCommand = new TelegesisSendUnicastCommand(); unicastCommand.setAddress(apsFrame.getDestinationAddress()); unicastCommand.setDestEp(apsFrame.getDestinationEndpoint()); unicastCommand.setSourceEp(apsFrame.getSourceEndpoint()); unicastCommand.setProfileId(apsFrame.getProfile()); unicastCommand.setClusterId(apsFrame.getCluster()); unicastCommand.setMessageData(apsFrame.getPayload()); command = unicastCommand; } else if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.DEVICE && ZigBeeBroadcastDestination.isBroadcast(apsFrame.getDestinationAddress())) { TelegesisSendMulticastCommand multicastCommand = new TelegesisSendMulticastCommand(); multicastCommand.setAddress(apsFrame.getDestinationAddress()); multicastCommand.setDestEp(apsFrame.getDestinationEndpoint()); multicastCommand.setProfileId(apsFrame.getProfile()); multicastCommand.setClusterId(apsFrame.getCluster()); multicastCommand.setRadius(apsFrame.getRadius()); multicastCommand.setMessageData(apsFrame.getPayload()); multicastCommand.setSourceEp(apsFrame.getSourceEndpoint()); command = multicastCommand; } else if (apsFrame.getAddressMode() == ZigBeeNwkAddressMode.GROUP) { TelegesisSendMulticastCommand multicastCommand = new TelegesisSendMulticastCommand(); command = multicastCommand; } else { logger.debug("Telegesis message not sent: {}", apsFrame); return; } logger.debug("Telegesis send: {}", command.toString()); commandScheduler.execute(new Runnable() { @Override public void run() { frameHandler.sendRequest(command); zigbeeTransportReceive.receiveCommandState(msgTag, command.getStatus() == TelegesisStatusCode.SUCCESS ? ZigBeeTransportProgressState.TX_ACK : ZigBeeTransportProgressState.TX_NAK); if (command instanceof TelegesisSendMulticastCommand) { return; } if (((TelegesisSendUnicastCommand) command).getMessageId() != null) { messageIdMap.put(((TelegesisSendUnicastCommand) command).getMessageId(), msgTag); } } }); } ZigBeeDongleTelegesis(final ZigBeePort serialPort); TelegesisNcp getTelegesisNcp(); @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 telegesisEventReceived(TelegesisEvent event); void telegesisEventReceivedRunnable(TelegesisEvent 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(); void setTelegesisPassword(String telegesisPassword); @Override boolean updateFirmware(final InputStream firmware, final ZigBeeTransportFirmwareCallback callback); void bootloadComplete(); @Override String getFirmwareVersion(); @Override boolean cancelUpdateFirmware(); @Override ZigBeeStatus setTcLinkKey(ZigBeeKey key); @Override ZigBeeKey getTcLinkKey(); @SuppressWarnings("unchecked") @Override void updateTransportConfig(TransportConfig configuration); void reinitializeDongle(Integer panId, ExtendedPanId epanId, Long frameCounter); void notifyStateUpdate(boolean state);  }