Search in sources :

Example 1 with MatchDescriptorRequest

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

the class ClusterMatcherTest method testMatcherMatchIn.

@Test
public void testMatcherMatchIn() {
    ClusterMatcher matcher = getMatcher();
    matcher.addCluster(0x500);
    matcher.addCluster(0x600);
    List<Integer> clusterListIn = new ArrayList<Integer>();
    List<Integer> clusterListOut = new ArrayList<Integer>();
    clusterListIn.add(0x500);
    MatchDescriptorRequest request = new MatchDescriptorRequest();
    request.setSourceAddress(new ZigBeeEndpointAddress(1234, 5));
    request.setProfileId(0x104);
    request.setInClusterList(clusterListIn);
    request.setOutClusterList(clusterListOut);
    matcher.commandReceived(request);
    assertEquals(1, mockedCommandCaptor.getAllValues().size());
}
Also used : ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) ArrayList(java.util.ArrayList) MatchDescriptorRequest(com.zsmartsystems.zigbee.zdo.command.MatchDescriptorRequest) Test(org.junit.Test)

Example 2 with MatchDescriptorRequest

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

the class ClusterMatcherTest method testMatcherNoMatch.

@Test
public void testMatcherNoMatch() {
    ClusterMatcher matcher = getMatcher();
    matcher.addCluster(0x500);
    List<Integer> clusterListIn = new ArrayList<Integer>();
    List<Integer> clusterListOut = new ArrayList<Integer>();
    MatchDescriptorRequest request = new MatchDescriptorRequest();
    request.setSourceAddress(new ZigBeeEndpointAddress(1234, 5));
    request.setProfileId(0x104);
    request.setInClusterList(clusterListIn);
    request.setOutClusterList(clusterListOut);
    matcher.commandReceived(request);
    assertEquals(0, mockedCommandCaptor.getAllValues().size());
}
Also used : ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) ArrayList(java.util.ArrayList) MatchDescriptorRequest(com.zsmartsystems.zigbee.zdo.command.MatchDescriptorRequest) Test(org.junit.Test)

Example 3 with MatchDescriptorRequest

use of com.zsmartsystems.zigbee.zdo.command.MatchDescriptorRequest 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 4 with MatchDescriptorRequest

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

Example 5 with MatchDescriptorRequest

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

the class ClusterMatcherTest method testMatcherMatchOut.

@Test
public void testMatcherMatchOut() {
    ClusterMatcher matcher = getMatcher();
    matcher.addCluster(0x500);
    matcher.addCluster(0x600);
    List<Integer> clusterListIn = new ArrayList<Integer>();
    List<Integer> clusterListOut = new ArrayList<Integer>();
    clusterListOut.add(0x500);
    MatchDescriptorRequest request = new MatchDescriptorRequest();
    request.setSourceAddress(new ZigBeeEndpointAddress(1234, 5));
    request.setProfileId(0x104);
    request.setInClusterList(clusterListIn);
    request.setOutClusterList(clusterListOut);
    matcher.commandReceived(request);
    assertEquals(1, mockedCommandCaptor.getAllValues().size());
}
Also used : ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) ArrayList(java.util.ArrayList) MatchDescriptorRequest(com.zsmartsystems.zigbee.zdo.command.MatchDescriptorRequest) Test(org.junit.Test)

Aggregations

MatchDescriptorRequest (com.zsmartsystems.zigbee.zdo.command.MatchDescriptorRequest)6 ArrayList (java.util.ArrayList)6 ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)4 Test (org.junit.Test)4 MatchDescriptorResponse (com.zsmartsystems.zigbee.zdo.command.MatchDescriptorResponse)2 ZclCommand (com.zsmartsystems.zigbee.zcl.ZclCommand)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1