use of com.zsmartsystems.zigbee.ZigBeeEndpointAddress in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeNetworkDiscoverer method rediscoverNode.
/**
* Starts a discovery on a node. This will send a {@link NetworkAddressRequest} as a broadcast and will receive
* the response to trigger a full discovery.
*
* @param ieeeAddress the {@link IeeeAddress} of the node to discover
*/
public void rediscoverNode(final IeeeAddress ieeeAddress) {
Runnable runnable = new Runnable() {
@Override
public void run() {
logger.debug("{}: NWK Discovery starting node rediscovery", ieeeAddress);
int retries = 0;
try {
do {
if (Thread.currentThread().isInterrupted()) {
break;
}
NetworkAddressRequest request = new NetworkAddressRequest();
request.setIeeeAddr(ieeeAddress);
request.setRequestType(0);
request.setStartIndex(0);
request.setDestinationAddress(new ZigBeeEndpointAddress(ZigBeeBroadcastDestination.BROADCAST_RX_ON.getKey()));
CommandResult response;
response = networkManager.unicast(request, request).get();
final NetworkAddressResponse nwkAddressResponse = response.getResponse();
if (nwkAddressResponse != null && nwkAddressResponse.getStatus() == ZdoStatus.SUCCESS) {
startNodeDiscovery(nwkAddressResponse.getNwkAddrRemoteDev());
break;
}
// We failed with the last request. Wait a bit then retry
try {
logger.debug("{}: NWK Discovery node rediscovery request failed. Wait before retry.", ieeeAddress);
Thread.sleep(retryPeriod);
} catch (InterruptedException e) {
break;
}
} while (retries++ < retryCount);
} catch (InterruptedException | ExecutionException e) {
logger.debug("NWK Discovery error in rediscoverNode ", e);
}
logger.debug("{}: NWK Discovery finishing node rediscovery", ieeeAddress);
}
};
networkManager.executeTask(runnable);
}
use of com.zsmartsystems.zigbee.ZigBeeEndpointAddress in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeNodeServiceDiscoverer method requestNeighborTable.
/**
* Get node neighbor table by making a {@link ManagementLqiRequest} call.
*
* @return list of {@link NeighborTable} if the request was processed ok, null otherwise
* @throws ExecutionException
* @throws InterruptedException
*/
private boolean requestNeighborTable() throws InterruptedException, ExecutionException {
// Start index for the list is 0
int startIndex = 0;
int totalNeighbors = 0;
Set<NeighborTable> neighbors = new HashSet<NeighborTable>();
do {
final ManagementLqiRequest neighborRequest = new ManagementLqiRequest();
neighborRequest.setDestinationAddress(new ZigBeeEndpointAddress(node.getNetworkAddress()));
neighborRequest.setStartIndex(startIndex);
CommandResult response = networkManager.unicast(neighborRequest, neighborRequest).get();
final ManagementLqiResponse neighborResponse = response.getResponse();
logger.debug("{}: Node SVC Discovery ManagementLqiRequest response {}", node.getIeeeAddress(), response);
if (neighborResponse == null) {
return false;
}
if (neighborResponse.getStatus() == ZdoStatus.NOT_SUPPORTED) {
supportsManagementLqi = false;
return true;
} else if (neighborResponse.getStatus() != ZdoStatus.SUCCESS) {
return false;
}
// To avoid a loop, we need to check if there's any response.
if (neighborResponse.getNeighborTableList().size() == 0) {
break;
}
// Save the neighbors
neighbors.addAll(neighborResponse.getNeighborTableList());
// Continue with next request
startIndex += neighborResponse.getNeighborTableList().size();
totalNeighbors = neighborResponse.getNeighborTableEntries();
} while (startIndex < totalNeighbors);
node.setNeighbors(neighbors);
return true;
}
use of com.zsmartsystems.zigbee.ZigBeeEndpointAddress in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeNodeServiceDiscoverer method requestPowerDescriptor.
/**
* Get node power descriptor
*
* @return true if the message was processed ok, or if the end device does not support the power descriptor
* @throws ExecutionException
* @throws InterruptedException
*/
private boolean requestPowerDescriptor() throws InterruptedException, ExecutionException {
final PowerDescriptorRequest powerDescriptorRequest = new PowerDescriptorRequest();
powerDescriptorRequest.setDestinationAddress(new ZigBeeEndpointAddress(node.getNetworkAddress()));
powerDescriptorRequest.setNwkAddrOfInterest(node.getNetworkAddress());
CommandResult response = networkManager.unicast(powerDescriptorRequest, powerDescriptorRequest).get();
final PowerDescriptorResponse powerDescriptorResponse = (PowerDescriptorResponse) response.getResponse();
logger.debug("{}: Node SVC Discovery PowerDescriptorResponse returned {}", node.getIeeeAddress(), powerDescriptorResponse);
if (powerDescriptorResponse == null) {
return false;
}
if (powerDescriptorResponse.getStatus() == ZdoStatus.SUCCESS) {
node.setPowerDescriptor(powerDescriptorResponse.getPowerDescriptor());
return true;
} else if (powerDescriptorResponse.getStatus() == ZdoStatus.NOT_SUPPORTED) {
return true;
}
return false;
}
use of com.zsmartsystems.zigbee.ZigBeeEndpointAddress in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeNodeServiceDiscoverer method getSimpleDescriptor.
/**
* Get the simple descriptor for an endpoint and create the {@link ZigBeeEndpoint}
*
* @param endpointId the endpoint id to request
* @return the newly created {@link ZigBeeEndpoint} for the endpoint, or null on error
* @throws ExecutionException
* @throws InterruptedException
*/
private ZigBeeEndpoint getSimpleDescriptor(final int endpointId) throws InterruptedException, ExecutionException {
final SimpleDescriptorRequest simpleDescriptorRequest = new SimpleDescriptorRequest();
simpleDescriptorRequest.setDestinationAddress(new ZigBeeEndpointAddress(node.getNetworkAddress()));
simpleDescriptorRequest.setNwkAddrOfInterest(node.getNetworkAddress());
simpleDescriptorRequest.setEndpoint(endpointId);
CommandResult response = networkManager.unicast(simpleDescriptorRequest, simpleDescriptorRequest).get();
final SimpleDescriptorResponse simpleDescriptorResponse = (SimpleDescriptorResponse) response.getResponse();
logger.debug("{}: Node SVC Discovery SimpleDescriptorResponse returned {}", node.getIeeeAddress(), simpleDescriptorResponse);
if (simpleDescriptorResponse == null) {
return null;
}
if (simpleDescriptorResponse.getStatus() == ZdoStatus.SUCCESS) {
ZigBeeEndpoint endpoint = new ZigBeeEndpoint(networkManager, node, endpointId);
SimpleDescriptor simpleDescriptor = simpleDescriptorResponse.getSimpleDescriptor();
endpoint.setProfileId(simpleDescriptor.getProfileId());
endpoint.setDeviceId(simpleDescriptor.getDeviceId());
endpoint.setDeviceVersion(simpleDescriptor.getDeviceVersion());
endpoint.setInputClusterIds(simpleDescriptor.getInputClusterList());
endpoint.setOutputClusterIds(simpleDescriptor.getOutputClusterList());
return endpoint;
}
return null;
}
use of com.zsmartsystems.zigbee.ZigBeeEndpointAddress in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZclCluster method bind.
/**
* Adds a binding from the cluster to the destination {@link ZigBeeEndpoint}.
*
* @param address the destination {@link IeeeAddress}
* @param endpointId the destination endpoint ID
* @return Command future
*/
public Future<CommandResult> bind(IeeeAddress address, int endpointId) {
final BindRequest command = new BindRequest();
command.setDestinationAddress(new ZigBeeEndpointAddress(zigbeeEndpoint.getEndpointAddress().getAddress()));
command.setSrcAddress(zigbeeEndpoint.getIeeeAddress());
command.setSrcEndpoint(zigbeeEndpoint.getEndpointId());
command.setBindCluster(clusterId);
// 64 bit addressing
command.setDstAddrMode(3);
command.setDstAddress(address);
command.setDstEndpoint(endpointId);
return zigbeeManager.unicast(command, new BindRequest());
}
Aggregations