use of com.zsmartsystems.zigbee.CommandResult in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZclCluster method discoverCommandsReceived.
/**
* Discovers the list of commands received by the cluster on the remote device. If the discovery is successful,
* users should call {@link ZclCluster#getSupportedCommandsReceived()} to get the list of supported commands.
* <p>
* If the discovery has already been completed, and rediscover is false, then the future will complete immediately
* and the user can use existing results. Normally there should not be a need to set rediscover to true.
*
* @param rediscover true to perform a discovery even if it was previously completed
* @return Command future {@link Boolean} with the success of the discovery
*/
public Future<Boolean> discoverCommandsReceived(final boolean rediscover) {
RunnableFuture<Boolean> future = new FutureTask<Boolean>(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
// cluster which would cause errors consolidating the responses
synchronized (supportedCommandsReceived) {
// If we don't want to rediscover, and we already have the list of attributes, then return
if (!rediscover && !supportedCommandsReceived.isEmpty()) {
return true;
}
int index = 0;
boolean complete = false;
Set<Integer> commands = new HashSet<Integer>();
do {
final DiscoverCommandsReceived command = new DiscoverCommandsReceived();
command.setClusterId(clusterId);
command.setDestinationAddress(zigbeeEndpoint.getEndpointAddress());
command.setStartCommandIdentifier(index);
command.setMaximumCommandIdentifiers(20);
CommandResult result = send(command).get();
if (result.isError()) {
return false;
}
DiscoverCommandsReceivedResponse response = (DiscoverCommandsReceivedResponse) result.getResponse();
complete = response.getDiscoveryComplete();
if (response.getCommandIdentifiers() != null) {
commands.addAll(response.getCommandIdentifiers());
index = Collections.max(commands) + 1;
}
} while (!complete);
supportedCommandsReceived.clear();
supportedCommandsReceived.addAll(commands);
}
return true;
}
});
// start the thread to execute it
new Thread(future).start();
return future;
}
use of com.zsmartsystems.zigbee.CommandResult 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;
}
use of com.zsmartsystems.zigbee.CommandResult 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.CommandResult 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.CommandResult 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