Search in sources :

Example 1 with MatchDescriptorResponse

use of com.zsmartsystems.zigbee.zdo.command.MatchDescriptorResponse 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)

Example 2 with MatchDescriptorResponse

use of com.zsmartsystems.zigbee.zdo.command.MatchDescriptorResponse in project com.zsmartsystems.zigbee by zsmartsystems.

the class ClusterMatcher method commandReceived.

@Override
public void commandReceived(ZigBeeCommand command) {
    // If we have local servers matching the request, then we need to respond
    if (command instanceof MatchDescriptorRequest) {
        MatchDescriptorRequest matchRequest = (MatchDescriptorRequest) command;
        logger.debug("{}: ClusterMatcher received request {}", networkManager.getZigBeeExtendedPanId(), matchRequest);
        if (matchRequest.getProfileId() != 0x104) {
            // TODO: Do we need to restrict the profile? Remove this check?
            return;
        }
        // requested clusters in the requests cluster list
        if (Collections.disjoint(matchRequest.getInClusterList(), clusters) && Collections.disjoint(matchRequest.getOutClusterList(), clusters)) {
            logger.debug("{}: ClusterMatcher no match", networkManager.getZigBeeExtendedPanId());
            return;
        }
        MatchDescriptorResponse matchResponse = new MatchDescriptorResponse();
        matchResponse.setStatus(ZdoStatus.SUCCESS);
        List<Integer> matchList = new ArrayList<Integer>();
        matchList.add(1);
        matchResponse.setMatchList(matchList);
        matchResponse.setDestinationAddress(command.getSourceAddress());
        matchResponse.setNwkAddrOfInterest(command.getSourceAddress().getAddress());
        logger.debug("{}: ClusterMatcher sending match {}", networkManager.getZigBeeExtendedPanId(), matchResponse);
        networkManager.sendCommand(matchResponse);
    }
}
Also used : MatchDescriptorResponse(com.zsmartsystems.zigbee.zdo.command.MatchDescriptorResponse) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MatchDescriptorRequest(com.zsmartsystems.zigbee.zdo.command.MatchDescriptorRequest)

Example 3 with MatchDescriptorResponse

use of com.zsmartsystems.zigbee.zdo.command.MatchDescriptorResponse in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeNode method commandReceived.

@Override
public void commandReceived(ZigBeeCommand command) {
    // Check if it's our address
    if (command.getSourceAddress().getAddress() != networkAddress) {
        return;
    }
    // If we have local servers matching the request, then we need to respond
    if (command instanceof MatchDescriptorRequest) {
        MatchDescriptorRequest matchRequest = (MatchDescriptorRequest) command;
        if (matchRequest.getProfileId() != 0x104) {
            // TODO: Remove this constant ?
            return;
        }
        // We want to match any of our local servers (ie our input clusters) with any
        // requested clusters in the requests cluster list
        boolean matched = false;
        for (ZigBeeEndpoint endpoint : endpoints.values()) {
            for (int clusterId : matchRequest.getInClusterList()) {
                if (endpoint.getApplication(clusterId) != null) {
                    matched = true;
                    break;
                }
            }
            if (matched) {
                break;
            }
        }
        if (!matched) {
            return;
        }
        MatchDescriptorResponse matchResponse = new MatchDescriptorResponse();
        matchResponse.setStatus(ZdoStatus.SUCCESS);
        List<Integer> matchList = new ArrayList<Integer>();
        matchList.add(1);
        matchResponse.setMatchList(matchList);
        matchResponse.setDestinationAddress(command.getSourceAddress());
        networkManager.sendCommand(matchResponse);
    }
    if (!(command instanceof ZclCommand)) {
        return;
    }
    ZclCommand zclCommand = (ZclCommand) command;
    ZigBeeEndpointAddress endpointAddress = (ZigBeeEndpointAddress) zclCommand.getSourceAddress();
    ZigBeeEndpoint endpoint = endpoints.get(endpointAddress.getEndpoint());
    if (endpoint == null) {
        return;
    }
    endpoint.commandReceived(zclCommand);
}
Also used : MatchDescriptorResponse(com.zsmartsystems.zigbee.zdo.command.MatchDescriptorResponse) ArrayList(java.util.ArrayList) MatchDescriptorRequest(com.zsmartsystems.zigbee.zdo.command.MatchDescriptorRequest) ZclCommand(com.zsmartsystems.zigbee.zcl.ZclCommand)

Aggregations

MatchDescriptorResponse (com.zsmartsystems.zigbee.zdo.command.MatchDescriptorResponse)3 ArrayList (java.util.ArrayList)3 MatchDescriptorRequest (com.zsmartsystems.zigbee.zdo.command.MatchDescriptorRequest)2 IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)1 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 XBeeTransmitRequestExplicitCommand (com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeTransmitRequestExplicitCommand)1 ZclCommand (com.zsmartsystems.zigbee.zcl.ZclCommand)1 Field (java.lang.reflect.Field)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Test (org.junit.Test)1