Search in sources :

Example 1 with ReadAttributesResponse

use of com.zsmartsystems.zigbee.zcl.clusters.general.ReadAttributesResponse in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeConsoleAttributeReadCommand 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 Integer clusterId = parseCluster(args[2]);
    ZclCluster cluster = endpoint.getInputCluster(clusterId);
    if (cluster != null) {
        out.println("Using input cluster");
    } else {
        cluster = endpoint.getOutputCluster(clusterId);
        if (cluster != null) {
            out.println("Using output cluster");
        } else {
            out.println("Cluster not found");
            return;
        }
    }
    final Integer attributeId = parseAttribute(args[3]);
    String attributeName;
    ZclAttribute attribute = cluster.getAttribute(attributeId);
    if (attribute == null) {
        attributeName = "Attribute " + attributeId;
    } else {
        attributeName = attribute.getName();
    }
    out.println("Reading " + cluster.getClusterName() + ", " + attributeName);
    CommandResult result;
    result = cluster.read(attributeId).get();
    if (result.isSuccess()) {
        final ReadAttributesResponse response = result.getResponse();
        if (response.getRecords().size() == 0) {
            out.println("No records returned");
            return;
        }
        final ZclStatus statusCode = response.getRecords().get(0).getStatus();
        if (statusCode == ZclStatus.SUCCESS) {
            out.println("Cluster " + String.format("%04X", 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);
        }
        return;
    } else {
        out.println("Error executing command: " + result);
        return;
    }
}
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) CommandResult(com.zsmartsystems.zigbee.CommandResult)

Example 2 with ReadAttributesResponse

use of com.zsmartsystems.zigbee.zcl.clusters.general.ReadAttributesResponse 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 3 with ReadAttributesResponse

use of com.zsmartsystems.zigbee.zcl.clusters.general.ReadAttributesResponse in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZclGeneralCluster method readAttributesResponse.

/**
 * The Read Attributes Response
 * <p>
 * The read attributes response command is generated in response to a read attributes
 * or read attributes structured command. The command frame shall contain a read
 * attribute status record for each attribute identifier specified in the original read
 * attributes or read attributes structured command. For each read attribute status
 * record, the attribute identifier field shall contain the identifier specified in the
 * original read attributes or read attributes structured command.
 *
 * @param records {@link List<ReadAttributeStatusRecord>} Records
 * @return the {@link Future<CommandResult>} command result future
 */
public Future<CommandResult> readAttributesResponse(List<ReadAttributeStatusRecord> records) {
    ReadAttributesResponse command = new ReadAttributesResponse();
    // Set the fields
    command.setRecords(records);
    return send(command);
}
Also used : ReadAttributesResponse(com.zsmartsystems.zigbee.zcl.clusters.general.ReadAttributesResponse)

Example 4 with ReadAttributesResponse

use of com.zsmartsystems.zigbee.zcl.clusters.general.ReadAttributesResponse in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZclCluster method readSync.

/**
 * Read an attribute
 *
 * @param attribute the {@link ZclAttribute} to read
 * @return
 */
protected Object readSync(final ZclAttribute attribute) {
    logger.debug("readSync request: {}", attribute);
    CommandResult result;
    try {
        result = read(attribute).get();
    } catch (InterruptedException e) {
        logger.debug("readSync interrupted");
        return null;
    } catch (ExecutionException e) {
        logger.debug("readSync exception ", e);
        return null;
    }
    if (!result.isSuccess()) {
        return null;
    }
    ReadAttributesResponse response = result.getResponse();
    if (response.getRecords().get(0).getStatus() == ZclStatus.SUCCESS) {
        ReadAttributeStatusRecord attributeRecord = response.getRecords().get(0);
        return normalizer.normalizeZclData(attribute.getDataType(), attributeRecord.getAttributeValue());
    }
    return null;
}
Also used : ReadAttributesResponse(com.zsmartsystems.zigbee.zcl.clusters.general.ReadAttributesResponse) ReadAttributeStatusRecord(com.zsmartsystems.zigbee.zcl.field.ReadAttributeStatusRecord) ExecutionException(java.util.concurrent.ExecutionException) CommandResult(com.zsmartsystems.zigbee.CommandResult)

Example 5 with ReadAttributesResponse

use of com.zsmartsystems.zigbee.zcl.clusters.general.ReadAttributesResponse 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)

Aggregations

ReadAttributesResponse (com.zsmartsystems.zigbee.zcl.clusters.general.ReadAttributesResponse)5 CommandResult (com.zsmartsystems.zigbee.CommandResult)3 ZclCluster (com.zsmartsystems.zigbee.zcl.ZclCluster)3 ZigBeeEndpoint (com.zsmartsystems.zigbee.ZigBeeEndpoint)2 ZclAttribute (com.zsmartsystems.zigbee.zcl.ZclAttribute)2 ZclStatus (com.zsmartsystems.zigbee.zcl.ZclStatus)2 ZigBeeApplication (com.zsmartsystems.zigbee.app.ZigBeeApplication)1 ReportAttributesCommand (com.zsmartsystems.zigbee.zcl.clusters.general.ReportAttributesCommand)1 ReadAttributeStatusRecord (com.zsmartsystems.zigbee.zcl.field.ReadAttributeStatusRecord)1 ExecutionException (java.util.concurrent.ExecutionException)1