use of com.zsmartsystems.zigbee.ZigBeeEndpoint in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeConsoleDescribeNodeCommand method process.
@Override
public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out) throws IllegalArgumentException {
if (args.length != 2) {
throw new IllegalArgumentException("Invalid number of arguments");
}
final ZigBeeNode node = getNode(networkManager, args[1]);
out.println("IEEE Address : " + node.getIeeeAddress());
out.println("Network Address : " + node.getNetworkAddress());
out.println("Node Descriptor : " + node.getNodeDescriptor());
out.println("Power Descriptor : " + node.getPowerDescriptor());
out.println("Associations : " + node.getAssociatedDevices().toString());
out.println("Endpoints:");
for (ZigBeeEndpoint endpoint : node.getEndpoints()) {
out.println(endpoint.toString());
}
out.println("Neighbors:");
for (NeighborTable neighbor : node.getNeighbors()) {
out.println(neighbor.toString());
}
out.println("Routes:");
for (RoutingTable route : node.getRoutes()) {
out.println(route.toString());
}
}
use of com.zsmartsystems.zigbee.ZigBeeEndpoint in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeNodeDaoTest method testSerialize.
@Test
public void testSerialize() {
ZigBeeTransportTransmit mockedTransport = Mockito.mock(ZigBeeTransportTransmit.class);
ZigBeeNetworkManager networkManager = new ZigBeeNetworkManager(mockedTransport);
ZigBeeNode node = new ZigBeeNode(networkManager, new IeeeAddress("1234567890ABCDEF"));
node.setNetworkAddress(12345);
ZigBeeEndpoint endpoint;
endpoint = new ZigBeeEndpoint(networkManager, node, 1);
endpoint.setProfileId(123);
node.addEndpoint(endpoint);
endpoint = new ZigBeeEndpoint(networkManager, node, 2);
endpoint.setProfileId(321);
node.addEndpoint(endpoint);
/*
* ZigBeeNodeDao nodeDao = ZigBeeNodeDao.createFromZigBeeNode(node);
* assertEquals(new IeeeAddress("1234567890ABCDEF").toString(), nodeDao.getIeeeAddress());
* assertEquals(Integer.valueOf(12345), nodeDao.getNetworkAddress());
*
* node = ZigBeeNodeDao.createFromZigBeeDao(networkManager, nodeDao);
* assertEquals(new IeeeAddress("1234567890ABCDEF"), node.getIeeeAddress());
* assertEquals(Integer.valueOf(12345), node.getNetworkAddress());
* assertEquals(2, node.getEndpoints().size());
*
* endpoint = node.getEndpoint(1);
* assertEquals(123, endpoint.getProfileId());
*/
}
use of com.zsmartsystems.zigbee.ZigBeeEndpoint in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeOtaServerTest method testNotify.
@Test
public void testNotify() {
ArgumentCaptor<ZigBeeCommand> mockedCommandCaptor = ArgumentCaptor.forClass(ZigBeeCommand.class);
NodeDescriptor nodeDescriptor = new NodeDescriptor();
IeeeAddress ieeeAddress = new IeeeAddress("1234567890ABCDEF");
ZigBeeEndpointAddress networkAddress = new ZigBeeEndpointAddress(1234, 56);
ZigBeeNetworkManager mockedNetworkManager = Mockito.mock(ZigBeeNetworkManager.class);
ZigBeeNode node = new ZigBeeNode(mockedNetworkManager, ieeeAddress);
node.setNetworkAddress(networkAddress.getAddress());
node.setNodeDescriptor(nodeDescriptor);
ZigBeeEndpoint endpoint = new ZigBeeEndpoint(mockedNetworkManager, node, networkAddress.getEndpoint());
// device.setIeeeAddress(ieeeAddress);
List<Integer> outClusters = new ArrayList<Integer>();
outClusters.add(ZclOtaUpgradeCluster.CLUSTER_ID);
endpoint.setOutputClusterIds(outClusters);
ZigBeeOtaStatusCallback mockedCallback = Mockito.mock(ZigBeeOtaStatusCallback.class);
otaStatusCapture = new ArrayList<ZigBeeOtaServerStatus>();
Set<ZigBeeEndpoint> devices = new HashSet<ZigBeeEndpoint>();
devices.add(endpoint);
Mockito.when(mockedNetworkManager.getNode((IeeeAddress) Matchers.anyObject())).thenReturn(node);
// Mockito.when(mockedNetworkManager.getDevice((ZigBeeAddress) Matchers.anyObject())).thenReturn(endpoint);
// Mockito.when(mockedNetworkManager.getNodeDevices((IeeeAddress) Matchers.anyObject())).thenReturn(devices);
// ZigBeeTransportTransmit mockedTransport = Mockito.mock(ZigBeeTransportTransmit.class);
// ArgumentCaptor<ZigBeeApsFrame> mockedApsFrameListener = ArgumentCaptor.forClass(ZigBeeApsFrame.class);
// try {
// Mockito.doNothing().when(mockedTransport).sendCommand(mockedApsFrameListener.capture());
// } catch (ZigBeeException e) {
// e.printStackTrace();
// }
Mockito.doAnswer(new Answer<Integer>() {
@Override
public Integer answer(InvocationOnMock invocation) {
return 0;
}
}).when(mockedNetworkManager).sendCommand(mockedCommandCaptor.capture());
Mockito.doAnswer(new Answer<Future<CommandResult>>() {
@Override
public Future<CommandResult> answer(InvocationOnMock invocation) {
return null;
}
}).when(mockedNetworkManager).unicast(mockedCommandCaptor.capture(), (ZigBeeTransactionMatcher) Matchers.anyObject());
ZclOtaUpgradeCluster cluster = new ZclOtaUpgradeCluster(mockedNetworkManager, endpoint);
ZigBeeOtaServer server = new ZigBeeOtaServer();
assertTrue(server.appStartup(cluster));
server.addListener(this);
ZigBeeOtaFile otaFile = Mockito.mock(ZigBeeOtaFile.class);
// Set the firmware and send notification
server.setFirmware(otaFile);
assertEquals(1, mockedCommandCaptor.getAllValues().size());
org.awaitility.Awaitility.await().until(otaListenerUpdated(), org.hamcrest.Matchers.equalTo(1));
assertEquals(1, otaStatusCapture.size());
ZigBeeOtaServerStatus status = otaStatusCapture.get(0);
assertEquals(ZigBeeOtaServerStatus.OTA_WAITING, status);
ZigBeeCommand command = mockedCommandCaptor.getValue();
assertEquals(Integer.valueOf(0x19), command.getClusterId());
assertTrue(command instanceof ImageNotifyCommand);
ImageNotifyCommand notifyCommand = (ImageNotifyCommand) command;
assertEquals(new ZigBeeEndpointAddress(1234, 56), notifyCommand.getDestinationAddress());
assertTrue(notifyCommand.getQueryJitter() >= 1 && notifyCommand.getQueryJitter() <= 100);
}
use of com.zsmartsystems.zigbee.ZigBeeEndpoint in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZclClusterTest method bind.
@Test
public void bind() {
createNetworkManager();
ZigBeeNode node = new ZigBeeNode(networkManager, new IeeeAddress());
node.setNetworkAddress(1234);
ZigBeeEndpoint device = new ZigBeeEndpoint(networkManager, node, 5);
ZclCluster cluster = new ZclOnOffCluster(networkManager, device);
cluster.bind(new IeeeAddress("1234567890ABCDEF"), 11);
assertEquals(1, commandCapture.getAllValues().size());
ZigBeeCommand command = commandCapture.getValue();
assertNotNull(command);
System.out.println(command);
assertTrue(command instanceof BindRequest);
BindRequest bindCommand = (BindRequest) command;
assertEquals(new ZigBeeEndpointAddress(1234, 0), bindCommand.getDestinationAddress());
assertEquals(new IeeeAddress("1234567890ABCDEF"), bindCommand.getDstAddress());
assertEquals(Integer.valueOf(5), bindCommand.getSrcEndpoint());
assertEquals(Integer.valueOf(11), bindCommand.getDstEndpoint());
assertEquals(Integer.valueOf(3), bindCommand.getDstAddrMode());
assertEquals(Integer.valueOf(0x0021), bindCommand.getClusterId());
assertEquals(Integer.valueOf(6), bindCommand.getBindCluster());
}
use of com.zsmartsystems.zigbee.ZigBeeEndpoint in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZclClusterTest method isAttributeSupported.
@Test
public void isAttributeSupported() {
createNetworkManager();
ZigBeeNode node = new ZigBeeNode(networkManager, new IeeeAddress());
node.setNetworkAddress(1234);
ZigBeeEndpoint device = new ZigBeeEndpoint(networkManager, node, 5);
ZclCluster cluster = new ZclOnOffCluster(networkManager, device);
Set<Integer> set = new HashSet<Integer>();
set.add(1);
set.add(4);
set.add(2);
setSupportedClusters(cluster, set);
assertEquals(3, cluster.getSupportedAttributes().size());
assertTrue(cluster.isAttributeSupported(1));
assertTrue(cluster.isAttributeSupported(2));
assertFalse(cluster.isAttributeSupported(3));
}
Aggregations