Search in sources :

Example 1 with AttributeInformation

use of com.zsmartsystems.zigbee.zcl.field.AttributeInformation in project com.zsmartsystems.zigbee by zsmartsystems.

the class DiscoverAttributesResponseTest method testReceive.

@Test
public void testReceive() {
    int[] packet = getPacketData("00 02 00 21 03 00 21 04 00 21 07 00 21 08 00 30");
    DiscoverAttributesResponse response = new DiscoverAttributesResponse();
    DefaultDeserializer deserializer = new DefaultDeserializer(packet);
    ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);
    response.deserialize(fieldDeserializer);
    System.out.println(response);
    List<AttributeInformation> records = response.getAttributeInformation();
    assertEquals(5, records.size());
    AttributeInformation record = records.get(0);
    assertEquals(ZclDataType.UNSIGNED_16_BIT_INTEGER, record.getDataType());
    assertEquals(2, record.getIdentifier());
}
Also used : AttributeInformation(com.zsmartsystems.zigbee.zcl.field.AttributeInformation) DefaultDeserializer(com.zsmartsystems.zigbee.serialization.DefaultDeserializer) ZclFieldDeserializer(com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer) CommandTest(com.zsmartsystems.zigbee.CommandTest) Test(org.junit.Test)

Example 2 with AttributeInformation

use of com.zsmartsystems.zigbee.zcl.field.AttributeInformation in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZclCluster method discoverAttributes.

/**
 * Discovers the list of attributes supported by the cluster on the remote device.
 * <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.
 * <p>
 * This method returns a future to a boolean. Upon success the caller should call {@link #getSupportedAttributes()}
 * to get the list of supported attributes.
 *
 * @param rediscover true to perform a discovery even if it was previously completed
 * @return {@link Future} returning a {@link Boolean}
 */
public Future<Boolean> discoverAttributes(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 (supportedAttributes) {
                // If we don't want to rediscover, and we already have the list of attributes, then return
                if (!rediscover && !supportedAttributes.isEmpty()) {
                    return true;
                }
                int index = 0;
                boolean complete = false;
                Set<AttributeInformation> attributes = new HashSet<AttributeInformation>();
                do {
                    final DiscoverAttributesCommand command = new DiscoverAttributesCommand();
                    command.setClusterId(clusterId);
                    command.setDestinationAddress(zigbeeEndpoint.getEndpointAddress());
                    command.setStartAttributeIdentifier(index);
                    command.setMaximumAttributeIdentifiers(10);
                    CommandResult result = send(command).get();
                    if (result.isError()) {
                        return false;
                    }
                    DiscoverAttributesResponse response = (DiscoverAttributesResponse) result.getResponse();
                    complete = response.getDiscoveryComplete();
                    if (response.getAttributeInformation() != null) {
                        attributes.addAll(response.getAttributeInformation());
                        index = Collections.max(attributes).getIdentifier() + 1;
                    }
                } while (!complete);
                supportedAttributes.clear();
                for (AttributeInformation attribute : attributes) {
                    supportedAttributes.add(attribute.getIdentifier());
                }
            }
            return true;
        }
    });
    // start the thread to execute it
    new Thread(future).start();
    return future;
}
Also used : AttributeInformation(com.zsmartsystems.zigbee.zcl.field.AttributeInformation) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) DiscoverAttributesCommand(com.zsmartsystems.zigbee.zcl.clusters.general.DiscoverAttributesCommand) DiscoverAttributesResponse(com.zsmartsystems.zigbee.zcl.clusters.general.DiscoverAttributesResponse) ExecutionException(java.util.concurrent.ExecutionException) CommandResult(com.zsmartsystems.zigbee.CommandResult) FutureTask(java.util.concurrent.FutureTask)

Aggregations

AttributeInformation (com.zsmartsystems.zigbee.zcl.field.AttributeInformation)2 CommandResult (com.zsmartsystems.zigbee.CommandResult)1 CommandTest (com.zsmartsystems.zigbee.CommandTest)1 DefaultDeserializer (com.zsmartsystems.zigbee.serialization.DefaultDeserializer)1 ZclFieldDeserializer (com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer)1 DiscoverAttributesCommand (com.zsmartsystems.zigbee.zcl.clusters.general.DiscoverAttributesCommand)1 DiscoverAttributesResponse (com.zsmartsystems.zigbee.zcl.clusters.general.DiscoverAttributesResponse)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)1 ExecutionException (java.util.concurrent.ExecutionException)1 FutureTask (java.util.concurrent.FutureTask)1 Test (org.junit.Test)1