Search in sources :

Example 6 with ZclCluster

use of com.zsmartsystems.zigbee.zcl.ZclCluster in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeEndpoint method commandReceived.

/**
 * Incoming command handler. The endpoint will process any commands addressed to this endpoint ID and pass o
 * clusters and applications
 *
 * @param command the {@link ZclCommand} received
 */
public void commandReceived(ZclCommand command) {
    if (!command.getSourceAddress().equals(getEndpointAddress())) {
        return;
    }
    // Pass all commands received from this endpoint to any registered applications
    synchronized (applications) {
        for (ZigBeeApplication application : applications.values()) {
            application.commandReceived(command);
        }
    }
    // Get the cluster
    ZclCluster cluster = getReceiveCluster(command.getClusterId(), command.getCommandDirection());
    if (cluster == null) {
        logger.debug("{}: Cluster {} not found for attribute response", getEndpointAddress(), command.getClusterId());
        return;
    }
    if (command instanceof ReportAttributesCommand) {
        ReportAttributesCommand attributeCommand = (ReportAttributesCommand) command;
        // Pass the reports to the cluster
        cluster.handleAttributeReport(attributeCommand.getReports());
        return;
    }
    if (command instanceof ReadAttributesResponse) {
        ReadAttributesResponse attributeCommand = (ReadAttributesResponse) command;
        // Pass the reports to the cluster
        cluster.handleAttributeStatus(attributeCommand.getRecords());
        return;
    }
    // If this is a specific cluster command, pass the command to the cluster command handler
    if (!command.isGenericCommand()) {
        cluster.handleCommand(command);
    }
}
Also used : ZigBeeApplication(com.zsmartsystems.zigbee.app.ZigBeeApplication) ReportAttributesCommand(com.zsmartsystems.zigbee.zcl.clusters.general.ReportAttributesCommand) ReadAttributesResponse(com.zsmartsystems.zigbee.zcl.clusters.general.ReadAttributesResponse) ZclCluster(com.zsmartsystems.zigbee.zcl.ZclCluster)

Example 7 with ZclCluster

use of com.zsmartsystems.zigbee.zcl.ZclCluster in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeEndpoint method setDao.

public void setDao(ZigBeeEndpointDao dao) {
    endpointId = dao.getEndpointId();
    if (dao.getProfileId() != null) {
        profileId = dao.getProfileId();
    }
    if (dao.getInputClusterIds() != null) {
        for (ZclClusterDao clusterDao : dao.getInputClusters()) {
            ZclCluster cluster = getClusterClass(clusterDao.getClusterId());
            cluster.setDao(clusterDao);
            inputClusters.put(clusterDao.getClusterId(), cluster);
        }
    }
    if (dao.getOutputClusterIds() != null) {
        for (ZclClusterDao clusterDao : dao.getOutputClusters()) {
            ZclCluster cluster = getClusterClass(clusterDao.getClusterId());
            cluster.setDao(clusterDao);
            outputClusters.put(clusterDao.getClusterId(), cluster);
        }
    }
}
Also used : ZclClusterDao(com.zsmartsystems.zigbee.dao.ZclClusterDao) ZclCluster(com.zsmartsystems.zigbee.zcl.ZclCluster)

Example 8 with ZclCluster

use of com.zsmartsystems.zigbee.zcl.ZclCluster 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 9 with ZclCluster

use of com.zsmartsystems.zigbee.zcl.ZclCluster 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 10 with ZclCluster

use of com.zsmartsystems.zigbee.zcl.ZclCluster 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

ZclCluster (com.zsmartsystems.zigbee.zcl.ZclCluster)15 ZigBeeEndpoint (com.zsmartsystems.zigbee.ZigBeeEndpoint)8 CommandResult (com.zsmartsystems.zigbee.CommandResult)7 ZclAttribute (com.zsmartsystems.zigbee.zcl.ZclAttribute)6 ZclStatus (com.zsmartsystems.zigbee.zcl.ZclStatus)5 ReadAttributesResponse (com.zsmartsystems.zigbee.zcl.clusters.general.ReadAttributesResponse)3 IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)2 ZclClusterDao (com.zsmartsystems.zigbee.dao.ZclClusterDao)2 ConfigureReportingResponse (com.zsmartsystems.zigbee.zcl.clusters.general.ConfigureReportingResponse)2 ZigBeeApplication (com.zsmartsystems.zigbee.app.ZigBeeApplication)1 ZigBeeEndpointDao (com.zsmartsystems.zigbee.dao.ZigBeeEndpointDao)1 ReportAttributesCommand (com.zsmartsystems.zigbee.zcl.clusters.general.ReportAttributesCommand)1 WriteAttributesResponse (com.zsmartsystems.zigbee.zcl.clusters.general.WriteAttributesResponse)1 ZclClusterType (com.zsmartsystems.zigbee.zcl.protocol.ZclClusterType)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1