Search in sources :

Example 21 with ZigBeeEndpointAddress

use of com.zsmartsystems.zigbee.ZigBeeEndpointAddress 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());
}
Also used : IeeeAddressResponse(com.zsmartsystems.zigbee.zdo.command.IeeeAddressResponse) PowerDescriptorResponse(com.zsmartsystems.zigbee.zdo.command.PowerDescriptorResponse) NodeDescriptor(com.zsmartsystems.zigbee.zdo.field.NodeDescriptor) ArrayList(java.util.ArrayList) ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode) ActiveEndpointsResponse(com.zsmartsystems.zigbee.zdo.command.ActiveEndpointsResponse) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) SimpleDescriptor(com.zsmartsystems.zigbee.zdo.field.SimpleDescriptor) SimpleDescriptorResponse(com.zsmartsystems.zigbee.zdo.command.SimpleDescriptorResponse) NodeDescriptorResponse(com.zsmartsystems.zigbee.zdo.command.NodeDescriptorResponse) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) PowerDescriptor(com.zsmartsystems.zigbee.zdo.field.PowerDescriptor) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 22 with ZigBeeEndpointAddress

use of com.zsmartsystems.zigbee.ZigBeeEndpointAddress 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);
}
Also used : ZigBeeOtaFile(com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaFile) NodeDescriptor(com.zsmartsystems.zigbee.zdo.field.NodeDescriptor) ArrayList(java.util.ArrayList) ZigBeeNetworkManager(com.zsmartsystems.zigbee.ZigBeeNetworkManager) ZigBeeOtaStatusCallback(com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaStatusCallback) ZigBeeCommand(com.zsmartsystems.zigbee.ZigBeeCommand) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) ZigBeeOtaServerStatus(com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaServerStatus) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) HashSet(java.util.HashSet) ZigBeeOtaServer(com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaServer) ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode) ZclOtaUpgradeCluster(com.zsmartsystems.zigbee.zcl.clusters.ZclOtaUpgradeCluster) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Future(java.util.concurrent.Future) ImageNotifyCommand(com.zsmartsystems.zigbee.zcl.clusters.otaupgrade.ImageNotifyCommand) Test(org.junit.Test)

Example 23 with ZigBeeEndpointAddress

use of com.zsmartsystems.zigbee.ZigBeeEndpointAddress 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());
}
Also used : ZclOnOffCluster(com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster) ZigBeeCommand(com.zsmartsystems.zigbee.ZigBeeCommand) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) BindRequest(com.zsmartsystems.zigbee.zdo.command.BindRequest) ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) Test(org.junit.Test)

Example 24 with ZigBeeEndpointAddress

use of com.zsmartsystems.zigbee.ZigBeeEndpointAddress in project com.zsmartsystems.zigbee by zsmartsystems.

the class ConfigureReportingCommandTest method testSingle.

@Test
public void testSingle() {
    int[] packet = getPacketData("00 00 00 10 01 00 58 02");
    AttributeReportingConfigurationRecord record = new AttributeReportingConfigurationRecord();
    record.setAttributeIdentifier(0);
    record.setAttributeDataType(ZclDataType.BOOLEAN);
    record.setDirection(0);
    record.setTimeoutPeriod(0);
    record.setMinimumReportingInterval(1);
    record.setMaximumReportingInterval(600);
    ConfigureReportingCommand command = new ConfigureReportingCommand();
    command.setClusterId(6);
    command.setDestinationAddress(new ZigBeeEndpointAddress(31084, 18));
    command.setRecords(Arrays.asList(record));
    command.setTransactionId(23);
    System.out.println(command);
    DefaultSerializer serializer = new DefaultSerializer();
    ZclFieldSerializer fieldSerializer = new ZclFieldSerializer(serializer);
    command.serialize(fieldSerializer);
    assertTrue(Arrays.equals(packet, serializer.getPayload()));
}
Also used : DefaultSerializer(com.zsmartsystems.zigbee.serialization.DefaultSerializer) AttributeReportingConfigurationRecord(com.zsmartsystems.zigbee.zcl.field.AttributeReportingConfigurationRecord) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) ZclFieldSerializer(com.zsmartsystems.zigbee.zcl.ZclFieldSerializer) CommandTest(com.zsmartsystems.zigbee.CommandTest) Test(org.junit.Test)

Example 25 with ZigBeeEndpointAddress

use of com.zsmartsystems.zigbee.ZigBeeEndpointAddress in project com.zsmartsystems.zigbee by zsmartsystems.

the class MatchDescriptorResponseTest method testSendEndpoint2.

@Test
public void testSendEndpoint2() {
    MatchDescriptorResponse matchResponse = new MatchDescriptorResponse();
    matchResponse.setStatus(ZdoStatus.SUCCESS);
    List<Integer> matchList = new ArrayList<Integer>();
    matchList.add(1);
    matchList.add(2);
    matchResponse.setMatchList(matchList);
    matchResponse.setDestinationAddress(new ZigBeeEndpointAddress(1234, 5));
    matchResponse.setNwkAddrOfInterest(1234);
    System.out.println(matchResponse);
    ZigBeeSerializer serializer = new DefaultSerializer();
    ZclFieldSerializer fieldSerializer = new ZclFieldSerializer(serializer);
    matchResponse.serialize(fieldSerializer);
    assertTrue(Arrays.equals(getPacketData("00 00 D2 04 02 01 02"), serializer.getPayload()));
}
Also used : DefaultSerializer(com.zsmartsystems.zigbee.serialization.DefaultSerializer) ZigBeeSerializer(com.zsmartsystems.zigbee.serialization.ZigBeeSerializer) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) ArrayList(java.util.ArrayList) ZclFieldSerializer(com.zsmartsystems.zigbee.zcl.ZclFieldSerializer) CommandTest(com.zsmartsystems.zigbee.CommandTest) Test(org.junit.Test)

Aggregations

ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)35 Test (org.junit.Test)20 CommandResult (com.zsmartsystems.zigbee.CommandResult)10 ArrayList (java.util.ArrayList)10 ZigBeeEndpoint (com.zsmartsystems.zigbee.ZigBeeEndpoint)9 DefaultSerializer (com.zsmartsystems.zigbee.serialization.DefaultSerializer)8 ZclFieldSerializer (com.zsmartsystems.zigbee.zcl.ZclFieldSerializer)8 CommandTest (com.zsmartsystems.zigbee.CommandTest)6 IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)6 HashSet (java.util.HashSet)5 ZigBeeNode (com.zsmartsystems.zigbee.ZigBeeNode)4 MatchDescriptorRequest (com.zsmartsystems.zigbee.zdo.command.MatchDescriptorRequest)4 ZigBeeCommand (com.zsmartsystems.zigbee.ZigBeeCommand)3 ZigBeeSerializer (com.zsmartsystems.zigbee.serialization.ZigBeeSerializer)3 ZclOnOffCluster (com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster)3 BindRequest (com.zsmartsystems.zigbee.zdo.command.BindRequest)3 IeeeAddressResponse (com.zsmartsystems.zigbee.zdo.command.IeeeAddressResponse)3 ConBeeEnqueueSendDataRequest (com.zsmartsystems.zigbee.dongle.conbee.internal.frame.ConBeeEnqueueSendDataRequest)2 EzspFrameTest (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.EzspFrameTest)2 EmberApsFrame (com.zsmartsystems.zigbee.dongle.ember.internal.ezsp.structure.EmberApsFrame)2