use of com.zsmartsystems.zigbee.CommandResult in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeNetworkDiscoverer method getIeeeAddress.
/**
* Get Node IEEE address
*
* @param networkAddress the network address of the node
* @return true if the message was processed ok
*/
private boolean getIeeeAddress(final int networkAddress) {
try {
Integer startIndex = 0;
int totalAssociatedDevices = 0;
Set<Integer> associatedDevices = new HashSet<Integer>();
IeeeAddress ieeeAddress = null;
do {
// Request extended response, start index for associated list is 0
final IeeeAddressRequest ieeeAddressRequest = new IeeeAddressRequest();
ieeeAddressRequest.setDestinationAddress(new ZigBeeEndpointAddress(networkAddress));
ieeeAddressRequest.setRequestType(1);
ieeeAddressRequest.setStartIndex(startIndex);
ieeeAddressRequest.setNwkAddrOfInterest(networkAddress);
CommandResult response = networkManager.unicast(ieeeAddressRequest, ieeeAddressRequest).get();
if (response.isError()) {
return false;
}
final IeeeAddressResponse ieeeAddressResponse = response.getResponse();
logger.debug("{}: NWK Discovery IeeeAddressRequest returned {}", networkAddress, ieeeAddressResponse);
if (ieeeAddressResponse != null && ieeeAddressResponse.getStatus() == ZdoStatus.SUCCESS) {
ieeeAddress = ieeeAddressResponse.getIeeeAddrRemoteDev();
if (startIndex.equals(ieeeAddressResponse.getStartIndex())) {
associatedDevices.addAll(ieeeAddressResponse.getNwkAddrAssocDevList());
startIndex += ieeeAddressResponse.getNwkAddrAssocDevList().size();
totalAssociatedDevices = ieeeAddressResponse.getNwkAddrAssocDevList().size();
}
}
} while (startIndex < totalAssociatedDevices);
addNode(ieeeAddress, networkAddress);
// Start discovery for any associated nodes
for (final int deviceNetworkAddress : associatedDevices) {
startNodeDiscovery(deviceNetworkAddress);
}
} catch (InterruptedException | ExecutionException e) {
logger.debug("NWK Discovery Error in checkIeeeAddressResponse ", e);
}
return true;
}
use of com.zsmartsystems.zigbee.CommandResult 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.CommandResult 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.CommandResult 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.CommandResult 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;
}
Aggregations