Search in sources :

Example 11 with ZigBeeEndpoint

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

the class ZigBeeApi method on.

/**
 * Switches destination on.
 *
 * @param destination the {@link ZigBeeAddress}
 * @return the command result future.
 */
public Future<CommandResult> on(final ZigBeeAddress destination) {
    if (!(destination instanceof ZigBeeEndpointAddress)) {
        return null;
    }
    ZigBeeEndpointAddress endpointAddress = (ZigBeeEndpointAddress) destination;
    ZigBeeEndpoint endpoint = networkManager.getNode(endpointAddress.getAddress()).getEndpoint(endpointAddress.getEndpoint());
    if (endpoint == null) {
        return null;
    }
    ZclOnOffCluster cluster = (ZclOnOffCluster) endpoint.getInputCluster(ZclOnOffCluster.CLUSTER_ID);
    return cluster.onCommand();
}
Also used : ZclOnOffCluster(com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint)

Example 12 with ZigBeeEndpoint

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

the class ZigBeeConsoleNodeListCommand method process.

@Override
public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out) throws IllegalArgumentException {
    final Set<ZigBeeNode> nodes = networkManager.getNodes();
    final List<Integer> nodeIds = new ArrayList<Integer>();
    for (ZigBeeNode node : nodes) {
        nodeIds.add(node.getNetworkAddress());
    }
    Collections.sort(nodeIds);
    out.println("Network Addr  IEEE Address      Device Type  EP   Profile");
    for (Integer nodeId : nodeIds) {
        ZigBeeNode node = networkManager.getNode(nodeId);
        out.print(String.format("%-6d  %04X  %s  %-11s", node.getNetworkAddress(), node.getNetworkAddress(), node.getIeeeAddress(), node.getLogicalType()));
        List<Integer> endpointIds = new ArrayList<Integer>();
        for (final ZigBeeEndpoint endpoint : node.getEndpoints()) {
            endpointIds.add(endpoint.getEndpointId());
        }
        Collections.sort(endpointIds);
        boolean first = true;
        for (Integer endpointId : endpointIds) {
            if (!first) {
                out.print("                                             ");
            }
            first = false;
            ZigBeeEndpoint endpoint = node.getEndpoint(endpointId);
            out.println(String.format("%-3d  %s", endpoint.getEndpointId(), ZigBeeProfileType.getProfileType(endpoint.getProfileId())));
        }
        if (first) {
            out.println();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint)

Example 13 with ZigBeeEndpoint

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

the class ZigBeeConsoleReportingConfigCommand method process.

@Override
public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out) throws IllegalArgumentException, InterruptedException, ExecutionException {
    if (args.length != 4) {
        throw new IllegalArgumentException("Invalid number of arguments");
    }
    final ZigBeeEndpoint endpoint = getEndpoint(networkManager, args[1]);
    final int clusterId = parseCluster(args[3]);
    final ZclCluster cluster;
    final String direction = args[2].toUpperCase();
    if ("IN".equals(direction)) {
        cluster = endpoint.getInputCluster(clusterId);
    } else if ("OUT".equals(direction)) {
        cluster = endpoint.getOutputCluster(clusterId);
    } else {
        throw new IllegalArgumentException("Cluster direction must be IN or OUT");
    }
    final int attributeId = parseAttribute(args[4]);
    final ZclAttribute attribute = cluster.getAttribute(attributeId);
    final CommandResult result = cluster.getReporting(attribute).get();
    if (result.isSuccess()) {
        final ReadAttributesResponse response = result.getResponse();
        final ZclStatus statusCode = response.getRecords().get(0).getStatus();
        if (statusCode == ZclStatus.SUCCESS) {
            out.println("Cluster " + response.getClusterId() + ", Attribute " + response.getRecords().get(0).getAttributeIdentifier() + ", type " + response.getRecords().get(0).getAttributeDataType() + ", value: " + response.getRecords().get(0).getAttributeValue());
        } else {
            out.println("Attribute value read error: " + statusCode);
        }
    } else {
        out.println("Error executing command: " + result);
    }
}
Also used : ZclStatus(com.zsmartsystems.zigbee.zcl.ZclStatus) ZclAttribute(com.zsmartsystems.zigbee.zcl.ZclAttribute) ReadAttributesResponse(com.zsmartsystems.zigbee.zcl.clusters.general.ReadAttributesResponse) ZclCluster(com.zsmartsystems.zigbee.zcl.ZclCluster) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) CommandResult(com.zsmartsystems.zigbee.CommandResult)

Example 14 with ZigBeeEndpoint

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

the class ZigBeeConsoleReportingSubscribeCommand method process.

@Override
public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out) throws IllegalArgumentException, InterruptedException, ExecutionException {
    if (args.length < 7) {
        throw new IllegalArgumentException("Invalid number of arguments");
    }
    final ZigBeeEndpoint endpoint = getEndpoint(networkManager, args[1]);
    final int clusterId = parseCluster(args[3]);
    final ZclCluster cluster;
    final String direction = args[2].toUpperCase();
    if ("IN".equals(direction)) {
        cluster = endpoint.getInputCluster(clusterId);
    } else if ("OUT".equals(direction)) {
        cluster = endpoint.getOutputCluster(clusterId);
    } else {
        throw new IllegalArgumentException("Cluster direction must be IN or OUT");
    }
    final int minInterval;
    try {
        minInterval = Integer.parseInt(args[5]);
    } catch (final NumberFormatException e) {
        throw new IllegalArgumentException("Min Interval has invalid format");
    }
    final int maxInterval;
    try {
        maxInterval = Integer.parseInt(args[6]);
    } catch (final NumberFormatException e) {
        throw new IllegalArgumentException("Max Interval has invalid format");
    }
    final int attributeId = parseAttribute(args[4]);
    final ZclAttribute attribute = cluster.getAttribute(attributeId);
    final Object reportableChange;
    if (args.length > 6) {
        reportableChange = parseValue(args[7], attribute.getDataType());
    } else {
        reportableChange = null;
    }
    final CommandResult result = cluster.setReporting(attribute, minInterval, maxInterval, reportableChange).get();
    if (result.isSuccess()) {
        final ConfigureReportingResponse response = result.getResponse();
        final ZclStatus statusCode = response.getRecords().get(0).getStatus();
        if (statusCode == ZclStatus.SUCCESS) {
            out.println("Attribute value configure reporting success.");
        } else {
            out.println("Attribute value configure reporting error: " + statusCode);
        }
    } else {
        out.println("Error executing command: " + result);
    }
}
Also used : ZclStatus(com.zsmartsystems.zigbee.zcl.ZclStatus) ZclAttribute(com.zsmartsystems.zigbee.zcl.ZclAttribute) ZclCluster(com.zsmartsystems.zigbee.zcl.ZclCluster) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) CommandResult(com.zsmartsystems.zigbee.CommandResult) ConfigureReportingResponse(com.zsmartsystems.zigbee.zcl.clusters.general.ConfigureReportingResponse)

Example 15 with ZigBeeEndpoint

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

the class ZigBeeConsoleAttributeWriteCommand method process.

@Override
public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out) throws IllegalArgumentException, InterruptedException, ExecutionException {
    if (args.length != 5) {
        throw new IllegalArgumentException("Invalid number of arguments");
    }
    final ZigBeeEndpoint endpoint = getEndpoint(networkManager, args[1]);
    final int clusterId = parseCluster(args[3]);
    final int attributeId = parseAttribute(args[4]);
    final ZclCluster cluster;
    final String direction = args[2].toUpperCase();
    if ("IN".equals(direction)) {
        cluster = endpoint.getInputCluster(clusterId);
    } else if ("OUT".equals(direction)) {
        cluster = endpoint.getOutputCluster(clusterId);
    } else {
        throw new IllegalArgumentException("Cluster direction must be IN or OUT");
    }
    final ZclAttribute attribute = cluster.getAttribute(attributeId);
    final Object value = parseValue(args[4], attribute.getDataType());
    final CommandResult result = cluster.write(attribute, value).get();
    if (result.isSuccess()) {
        final WriteAttributesResponse response = result.getResponse();
        final int statusCode = response.getRecords().get(0).getStatus();
        if (statusCode == 0) {
            out.println("Attribute value write success.");
        } else {
            final ZclStatus status = ZclStatus.getStatus((byte) statusCode);
            out.println("Attribute value write error: " + status);
        }
    } else {
        out.println("Error executing command: " + result);
    }
}
Also used : ZclStatus(com.zsmartsystems.zigbee.zcl.ZclStatus) ZclAttribute(com.zsmartsystems.zigbee.zcl.ZclAttribute) WriteAttributesResponse(com.zsmartsystems.zigbee.zcl.clusters.general.WriteAttributesResponse) ZclCluster(com.zsmartsystems.zigbee.zcl.ZclCluster) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) CommandResult(com.zsmartsystems.zigbee.CommandResult)

Aggregations

ZigBeeEndpoint (com.zsmartsystems.zigbee.ZigBeeEndpoint)25 IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)12 ZigBeeNode (com.zsmartsystems.zigbee.ZigBeeNode)12 Test (org.junit.Test)10 CommandResult (com.zsmartsystems.zigbee.CommandResult)9 ZclCluster (com.zsmartsystems.zigbee.zcl.ZclCluster)8 ZclOnOffCluster (com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster)8 ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)6 ZclAttribute (com.zsmartsystems.zigbee.zcl.ZclAttribute)6 ZigBeeCommand (com.zsmartsystems.zigbee.ZigBeeCommand)5 ZclStatus (com.zsmartsystems.zigbee.zcl.ZclStatus)5 ArrayList (java.util.ArrayList)4 ZigBeeNetworkManager (com.zsmartsystems.zigbee.ZigBeeNetworkManager)2 ConfigureReportingResponse (com.zsmartsystems.zigbee.zcl.clusters.general.ConfigureReportingResponse)2 ReadAttributesResponse (com.zsmartsystems.zigbee.zcl.clusters.general.ReadAttributesResponse)2 HashSet (java.util.HashSet)2 ZigBeeOtaFile (com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaFile)1 ZigBeeOtaServer (com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaServer)1 ZigBeeOtaServerStatus (com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaServerStatus)1 ZigBeeOtaStatusCallback (com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaStatusCallback)1