use of com.zsmartsystems.zigbee.zdo.command.SimpleDescriptorResponse in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeNetworkDiscovererTest method testNormal.
@Ignore
@Test
public void testNormal() {
// Add all the required responses to a list
IeeeAddressResponse ieeeResponse = new IeeeAddressResponse();
ieeeResponse.setStatus(ZdoStatus.SUCCESS);
ieeeResponse.setSourceAddress(new ZigBeeEndpointAddress(0));
ieeeResponse.setDestinationAddress(new ZigBeeEndpointAddress(0));
ieeeResponse.setIeeeAddrRemoteDev(new IeeeAddress("1234567890ABCDEF"));
responses.put(ZdoCommandType.IEEE_ADDRESS_REQUEST.getClusterId(), ieeeResponse);
NodeDescriptorResponse nodeResponse = new NodeDescriptorResponse();
nodeResponse.setStatus(ZdoStatus.SUCCESS);
nodeResponse.setSourceAddress(new ZigBeeEndpointAddress(0));
nodeResponse.setDestinationAddress(new ZigBeeEndpointAddress(0));
nodeResponse.setNwkAddrOfInterest(0);
NodeDescriptor nodeDescriptor = new NodeDescriptor();
nodeResponse.setNodeDescriptor(nodeDescriptor);
responses.put(ZdoCommandType.NODE_DESCRIPTOR_REQUEST.getClusterId(), nodeResponse);
PowerDescriptorResponse powerResponse = new PowerDescriptorResponse();
powerResponse.setStatus(ZdoStatus.SUCCESS);
powerResponse.setSourceAddress(new ZigBeeEndpointAddress(0));
powerResponse.setDestinationAddress(new ZigBeeEndpointAddress(0));
powerResponse.setNwkAddrOfInterest(0);
PowerDescriptor powerDescriptor = new PowerDescriptor();
powerResponse.setPowerDescriptor(powerDescriptor);
responses.put(ZdoCommandType.POWER_DESCRIPTOR_REQUEST.getClusterId(), powerResponse);
ActiveEndpointsResponse endpointsResponse = new ActiveEndpointsResponse();
endpointsResponse.setStatus(ZdoStatus.SUCCESS);
endpointsResponse.setSourceAddress(new ZigBeeEndpointAddress(0));
endpointsResponse.setDestinationAddress(new ZigBeeEndpointAddress(0));
endpointsResponse.setNwkAddrOfInterest(0);
List<Integer> activeEpList = new ArrayList<Integer>();
activeEpList.add(1);
endpointsResponse.setActiveEpList(activeEpList);
responses.put(ZdoCommandType.ACTIVE_ENDPOINTS_REQUEST.getClusterId(), endpointsResponse);
SimpleDescriptorResponse simpleResponse = new SimpleDescriptorResponse();
simpleResponse.setStatus(ZdoStatus.SUCCESS);
simpleResponse.setSourceAddress(new ZigBeeEndpointAddress(0));
simpleResponse.setDestinationAddress(new ZigBeeEndpointAddress(0, 1));
simpleResponse.setNwkAddrOfInterest(0);
SimpleDescriptor simpleDescriptor = new SimpleDescriptor();
simpleDescriptor.setDeviceId(0);
simpleDescriptor.setDeviceVersion(0);
simpleDescriptor.setEndpoint(1);
simpleDescriptor.setProfileId(0x104);
List<Integer> inputClusterList = new ArrayList<Integer>();
List<Integer> outputClusterList = new ArrayList<Integer>();
simpleDescriptor.setInputClusterList(inputClusterList);
simpleDescriptor.setOutputClusterList(outputClusterList);
simpleResponse.setSimpleDescriptor(simpleDescriptor);
responses.put(ZdoCommandType.SIMPLE_DESCRIPTOR_REQUEST.getClusterId(), simpleResponse);
ZigBeeNetworkDiscoverer discoverer = new ZigBeeNetworkDiscoverer(networkManager);
discoverer.setRetryPeriod(1);
discoverer.startup();
// Check that the listener registers for startup notifications
Mockito.verify(networkManager).addNetworkStateListener(discoverer);
// Put the system online so it initialises
discoverer.networkStateUpdated(ZigBeeTransportState.ONLINE);
// Check it registers listeners
Mockito.verify(networkManager).addCommandListener(discoverer);
Mockito.verify(networkManager).addAnnounceListener(discoverer);
// Then wait for the node to be added
Mockito.verify(networkManager, Mockito.timeout(5000).times(1)).addNode(nodeCapture.capture());
ZigBeeNode node = nodeCapture.getValue();
assertNotNull(node);
assertEquals(Integer.valueOf(0), node.getNetworkAddress());
assertEquals(new IeeeAddress("1234567890ABCDEF"), node.getIeeeAddress());
assertEquals(1, node.getEndpoints().size());
}
use of com.zsmartsystems.zigbee.zdo.command.SimpleDescriptorResponse 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