Search in sources :

Example 1 with XBeeTransmitRequestExplicitCommand

use of com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeTransmitRequestExplicitCommand in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeDongleXBee method sendCommand.

@Override
public void sendCommand(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.getDestinationAddress() < 0xFFF8 && apsFrame.getDestinationAddress() != 0) {
        // There seems to be a bug in the XBee that causes it to hang if APS Encryption is
        // enabled when sending a command to the local coordinator. Don't do it!
        command.addOptions(TransmitOptions.ENABLE_APS_ENCRYPTION);
    }
    command.setData(apsFrame.getPayload());
    logger.debug("XBee send: {}", command.toString());
    frameHandler.sendRequestAsync(command);
}
Also used : XBeeTransmitRequestExplicitCommand(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeTransmitRequestExplicitCommand) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress)

Example 2 with XBeeTransmitRequestExplicitCommand

use of com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeTransmitRequestExplicitCommand in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeDongleXBeeTest method sendCommand.

@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();
    }
    MatchDescriptorResponse command = new MatchDescriptorResponse();
    command.setDestinationAddress(new ZigBeeEndpointAddress(46946));
    command.setNwkAddrOfInterest(46946);
    command.setStatus(ZdoStatus.SUCCESS);
    command.setTransactionId(0x2A);
    List<Integer> matchList = new ArrayList<>();
    matchList.add(1);
    command.setMatchList(matchList);
    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.setSequence(42);
    apsFrame.setPayload(new int[] { 0x00, 0x00, 0x2E, 0x5B, 0x01, 0x01 });
    System.out.println(command);
    System.out.println(apsFrame);
    dongle.sendCommand(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, 32, 0, 0, 46, 91, 1, 1, 202 };
    int[] output = sentCommand.serialize();
    assertTrue(Arrays.equals(payload, output));
}
Also used : XBeeCommand(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeCommand) ZigBeeApsFrame(com.zsmartsystems.zigbee.ZigBeeApsFrame) XBeeFrameHandler(com.zsmartsystems.zigbee.dongle.xbee.internal.XBeeFrameHandler) MatchDescriptorResponse(com.zsmartsystems.zigbee.zdo.command.MatchDescriptorResponse) ArrayList(java.util.ArrayList) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) Field(java.lang.reflect.Field) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) XBeeTransmitRequestExplicitCommand(com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeTransmitRequestExplicitCommand) Test(org.junit.Test)

Aggregations

IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)2 XBeeTransmitRequestExplicitCommand (com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeTransmitRequestExplicitCommand)2 ZigBeeApsFrame (com.zsmartsystems.zigbee.ZigBeeApsFrame)1 ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)1 XBeeFrameHandler (com.zsmartsystems.zigbee.dongle.xbee.internal.XBeeFrameHandler)1 XBeeCommand (com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeCommand)1 MatchDescriptorResponse (com.zsmartsystems.zigbee.zdo.command.MatchDescriptorResponse)1 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1