Search in sources :

Example 1 with ManagementBindResponse

use of com.zsmartsystems.zigbee.zdo.command.ManagementBindResponse in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeNode method updateBindingTable.

/**
 * Request an update of the binding table for this node.
 * <p>
 * This method returns a future to a boolean. Upon success the caller should call {@link #getBindingTable()}
 *
 * @return {@link Future} returning a {@link Boolean}
 */
public Future<Boolean> updateBindingTable() {
    RunnableFuture<Boolean> future = new FutureTask<Boolean>(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            int index = 0;
            int tableSize = 0;
            List<BindingTable> bindingTable = new ArrayList<BindingTable>();
            do {
                ManagementBindRequest bindingRequest = new ManagementBindRequest();
                bindingRequest.setDestinationAddress(new ZigBeeEndpointAddress(networkAddress));
                bindingRequest.setStartIndex(index);
                CommandResult result = networkManager.unicast(bindingRequest, new ManagementBindRequest()).get();
                if (result.isError()) {
                    return false;
                }
                ManagementBindResponse response = (ManagementBindResponse) result.getResponse();
                if (response.getStartIndex() == index) {
                    tableSize = response.getBindingTableEntries();
                    index += response.getBindingTableList().size();
                    bindingTable.addAll(response.getBindingTableList());
                }
            } while (index < tableSize);
            setBindingTable(bindingTable);
            return true;
        }
    });
    // start the thread to execute it
    new Thread(future).start();
    return future;
}
Also used : ManagementBindRequest(com.zsmartsystems.zigbee.zdo.command.ManagementBindRequest) ManagementBindResponse(com.zsmartsystems.zigbee.zdo.command.ManagementBindResponse) FutureTask(java.util.concurrent.FutureTask) BindingTable(com.zsmartsystems.zigbee.zdo.field.BindingTable) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

ManagementBindRequest (com.zsmartsystems.zigbee.zdo.command.ManagementBindRequest)1 ManagementBindResponse (com.zsmartsystems.zigbee.zdo.command.ManagementBindResponse)1 BindingTable (com.zsmartsystems.zigbee.zdo.field.BindingTable)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 FutureTask (java.util.concurrent.FutureTask)1