Search in sources :

Example 11 with ZigBeeEndpointAddress

use of com.zsmartsystems.zigbee.ZigBeeEndpointAddress in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeNodeServiceDiscoverer method requestNetworkAddress.

/**
 * Get node descriptor
 *
 * @return true if the message was processed ok
 * @throws ExecutionException
 * @throws InterruptedException
 */
private boolean requestNetworkAddress() throws InterruptedException, ExecutionException {
    NetworkAddressRequest networkAddressRequest = new NetworkAddressRequest();
    networkAddressRequest.setIeeeAddr(node.getIeeeAddress());
    networkAddressRequest.setRequestType(0);
    networkAddressRequest.setStartIndex(0);
    networkAddressRequest.setDestinationAddress(new ZigBeeEndpointAddress(ZigBeeBroadcastDestination.BROADCAST_ALL_DEVICES.getKey()));
    CommandResult response = networkManager.unicast(networkAddressRequest, networkAddressRequest).get();
    final NetworkAddressResponse networkAddressResponse = (NetworkAddressResponse) response.getResponse();
    logger.debug("{}: Node SVC Discovery NetworkAddressRequest returned {}", node.getNetworkAddress(), networkAddressResponse);
    if (networkAddressResponse == null) {
        return false;
    }
    if (networkAddressResponse.getStatus() == ZdoStatus.SUCCESS) {
        node.setNetworkAddress(networkAddressResponse.getNwkAddrRemoteDev());
        return true;
    }
    return false;
}
Also used : NetworkAddressRequest(com.zsmartsystems.zigbee.zdo.command.NetworkAddressRequest) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) CommandResult(com.zsmartsystems.zigbee.CommandResult) NetworkAddressResponse(com.zsmartsystems.zigbee.zdo.command.NetworkAddressResponse)

Example 12 with ZigBeeEndpointAddress

use of com.zsmartsystems.zigbee.ZigBeeEndpointAddress in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeNodeServiceDiscoverer method requestActiveEndpoints.

/**
 * Get the active endpoints for a node
 *
 * @return true if the message was processed ok
 * @throws ExecutionException
 * @throws InterruptedException
 */
private boolean requestActiveEndpoints() throws InterruptedException, ExecutionException {
    final ActiveEndpointsRequest activeEndpointsRequest = new ActiveEndpointsRequest();
    activeEndpointsRequest.setDestinationAddress(new ZigBeeEndpointAddress(node.getNetworkAddress()));
    activeEndpointsRequest.setNwkAddrOfInterest(node.getNetworkAddress());
    CommandResult response = networkManager.unicast(activeEndpointsRequest, activeEndpointsRequest).get();
    final ActiveEndpointsResponse activeEndpointsResponse = (ActiveEndpointsResponse) response.getResponse();
    logger.debug("{}: Node SVC Discovery ActiveEndpointsResponse returned {}", node.getIeeeAddress(), response);
    if (activeEndpointsResponse == null) {
        return false;
    }
    // Get the simple descriptors for all endpoints
    List<ZigBeeEndpoint> endpoints = new ArrayList<ZigBeeEndpoint>();
    for (final int endpointId : activeEndpointsResponse.getActiveEpList()) {
        ZigBeeEndpoint endpoint = getSimpleDescriptor(endpointId);
        if (endpoint == null) {
            return false;
        }
        endpoints.add(endpoint);
    }
    // All endpoints have been received, so add them to the node
    for (ZigBeeEndpoint endpoint : endpoints) {
        node.addEndpoint(endpoint);
    }
    return true;
}
Also used : ActiveEndpointsRequest(com.zsmartsystems.zigbee.zdo.command.ActiveEndpointsRequest) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) ArrayList(java.util.ArrayList) ActiveEndpointsResponse(com.zsmartsystems.zigbee.zdo.command.ActiveEndpointsResponse) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) CommandResult(com.zsmartsystems.zigbee.CommandResult)

Example 13 with ZigBeeEndpointAddress

use of com.zsmartsystems.zigbee.ZigBeeEndpointAddress in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeNodeServiceDiscoverer method requestRoutingTable.

/**
 * Get node routing table by making a {@link ManagementRoutingRequest} request
 *
 * @return list of {@link RoutingTable} if the request was processed ok, null otherwise
 * @throws ExecutionException
 * @throws InterruptedException
 */
private boolean requestRoutingTable() throws InterruptedException, ExecutionException {
    // Start index for the list is 0
    int startIndex = 0;
    int totalRoutes = 0;
    Set<RoutingTable> routes = new HashSet<RoutingTable>();
    do {
        final ManagementRoutingRequest routeRequest = new ManagementRoutingRequest();
        routeRequest.setDestinationAddress(new ZigBeeEndpointAddress(node.getNetworkAddress()));
        routeRequest.setStartIndex(startIndex);
        CommandResult response = networkManager.unicast(routeRequest, routeRequest).get();
        final ManagementRoutingResponse routingResponse = response.getResponse();
        logger.debug("{}: Node SVC Discovery ManagementRoutingRequest returned {}", node.getIeeeAddress(), response);
        if (routingResponse == null) {
            return false;
        }
        if (routingResponse.getStatus() == ZdoStatus.NOT_SUPPORTED) {
            supportsManagementRouting = false;
            return true;
        } else if (routingResponse.getStatus() != ZdoStatus.SUCCESS) {
            return false;
        }
        // Save the routes
        routes.addAll(routingResponse.getRoutingTableList());
        // Continue with next request
        startIndex += routingResponse.getRoutingTableList().size();
        totalRoutes = routingResponse.getRoutingTableEntries();
    } while (startIndex < totalRoutes);
    node.setRoutes(routes);
    return true;
}
Also used : ManagementRoutingResponse(com.zsmartsystems.zigbee.zdo.command.ManagementRoutingResponse) RoutingTable(com.zsmartsystems.zigbee.zdo.field.RoutingTable) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) HashSet(java.util.HashSet) ManagementRoutingRequest(com.zsmartsystems.zigbee.zdo.command.ManagementRoutingRequest) CommandResult(com.zsmartsystems.zigbee.CommandResult)

Example 14 with ZigBeeEndpointAddress

use of com.zsmartsystems.zigbee.ZigBeeEndpointAddress in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZclCluster method unbind.

/**
 * Removes a binding from the cluster to the destination {@link ZigBeeEndpoint}.
 *
 * @param address the destination {@link IeeeAddress}
 * @param endpointId the destination endpoint ID
 * @return Command future
 */
public Future<CommandResult> unbind(IeeeAddress address, int endpointId) {
    final UnbindRequest command = new UnbindRequest();
    command.setDestinationAddress(new ZigBeeEndpointAddress(zigbeeEndpoint.getEndpointAddress().getAddress()));
    command.setSrcAddress(zigbeeEndpoint.getIeeeAddress());
    command.setSrcEndpoint(zigbeeEndpoint.getEndpointId());
    command.setBindCluster(clusterId);
    // 64 bit addressing
    command.setDstAddrMode(3);
    command.setDstAddress(address);
    command.setDstEndpoint(endpointId);
    return zigbeeManager.unicast(command, new UnbindRequest());
}
Also used : ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) UnbindRequest(com.zsmartsystems.zigbee.zdo.command.UnbindRequest)

Example 15 with ZigBeeEndpointAddress

use of com.zsmartsystems.zigbee.ZigBeeEndpointAddress in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeDongleConBee method sendCommand.

@Override
public void sendCommand(final ZigBeeApsFrame apsFrame) {
    ConBeeEnqueueSendDataRequest request = new ConBeeEnqueueSendDataRequest();
    request.setRequestId(apsFrame.getSequence());
    request.setClusterId(apsFrame.getCluster());
    switch(apsFrame.getAddressMode()) {
        case DEVICE:
            request.setDestinationAddress(new ZigBeeEndpointAddress(apsFrame.getDestinationAddress(), apsFrame.getDestinationEndpoint()));
            request.setDestinationAddressMode(ConBeeAddressMode.NWK);
            if (apsFrame.getDestinationAddress() > 0xfff8) {
                // 
                request.setTxOptions(0);
            }
            break;
        case GROUP:
            request.setDestinationAddress(new ZigBeeGroupAddress(apsFrame.getDestinationAddress()));
            request.setDestinationAddressMode(ConBeeAddressMode.GROUP);
            break;
        default:
            break;
    }
    request.setProfileId(apsFrame.getProfile());
    request.setRadius(apsFrame.getRadius());
    request.setSourceEndpoint(apsFrame.getSourceEndpoint());
    // request.setTxOptions(txOptions);
    request.setAdsuData(apsFrame.getPayload());
    conbeeHandler.queueFrame(request);
}
Also used : ConBeeEnqueueSendDataRequest(com.zsmartsystems.zigbee.dongle.conbee.internal.frame.ConBeeEnqueueSendDataRequest) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) ZigBeeGroupAddress(com.zsmartsystems.zigbee.ZigBeeGroupAddress)

Aggregations

ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)35 Test (org.junit.Test)20 CommandResult (com.zsmartsystems.zigbee.CommandResult)10 ArrayList (java.util.ArrayList)10 ZigBeeEndpoint (com.zsmartsystems.zigbee.ZigBeeEndpoint)9 DefaultSerializer (com.zsmartsystems.zigbee.serialization.DefaultSerializer)8 ZclFieldSerializer (com.zsmartsystems.zigbee.zcl.ZclFieldSerializer)8 CommandTest (com.zsmartsystems.zigbee.CommandTest)6 IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)6 HashSet (java.util.HashSet)5 ZigBeeNode (com.zsmartsystems.zigbee.ZigBeeNode)4 MatchDescriptorRequest (com.zsmartsystems.zigbee.zdo.command.MatchDescriptorRequest)4 ZigBeeCommand (com.zsmartsystems.zigbee.ZigBeeCommand)3 ZigBeeSerializer (com.zsmartsystems.zigbee.serialization.ZigBeeSerializer)3 ZclOnOffCluster (com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster)3 BindRequest (com.zsmartsystems.zigbee.zdo.command.BindRequest)3 IeeeAddressResponse (com.zsmartsystems.zigbee.zdo.command.IeeeAddressResponse)3 ConBeeEnqueueSendDataRequest (com.zsmartsystems.zigbee.dongle.conbee.internal.frame.ConBeeEnqueueSendDataRequest)2 EzspFrameTest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.EzspFrameTest)2 EmberApsFrame (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberApsFrame)2