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);
}
}
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);
}
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations