Search in sources :

Example 26 with ZigBeeEndpointAddress

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

the class MatchDescriptorResponseTest method testSendEndpoint1.

@Test
public void testSendEndpoint1() {
    MatchDescriptorResponse matchResponse = new MatchDescriptorResponse();
    matchResponse.setStatus(ZdoStatus.SUCCESS);
    List<Integer> matchList = new ArrayList<Integer>();
    matchList.add(1);
    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 01 01"), 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)

Example 27 with ZigBeeEndpointAddress

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

the class ReadAttributesCommandTest method testSingle.

@Test
public void testSingle() {
    int[] packet = getPacketData("04 00");
    ReadAttributesCommand command = new ReadAttributesCommand();
    command.setClusterId(0);
    command.setDestinationAddress(new ZigBeeEndpointAddress(57337, 3));
    command.setIdentifiers(Arrays.asList(4));
    command.setTransactionId(1);
    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) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) ZclFieldSerializer(com.zsmartsystems.zigbee.zcl.ZclFieldSerializer) CommandTest(com.zsmartsystems.zigbee.CommandTest) Test(org.junit.Test)

Example 28 with ZigBeeEndpointAddress

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

the class ImageNotifyCommandTest method testSend.

@Test
public void testSend() {
    ImageNotifyCommand command = new ImageNotifyCommand();
    command.setSourceAddress(new ZigBeeEndpointAddress(0, 1));
    command.setDestinationAddress(new ZigBeeEndpointAddress(57337, 3));
    command.setImageType(6);
    command.setQueryJitter(72);
    command.setManufacturerCode(4364);
    command.setNewFileVersion(16909063);
    System.out.println(command);
    ZigBeeSerializer serializer = new DefaultSerializer();
    ZclFieldSerializer fieldSerializer = new ZclFieldSerializer(serializer);
    command.setPayloadType(0);
    command.serialize(fieldSerializer);
    assertTrue(Arrays.equals(getPacketData("00 48"), serializer.getPayload()));
    serializer = new DefaultSerializer();
    fieldSerializer = new ZclFieldSerializer(serializer);
    command.setPayloadType(1);
    command.serialize(fieldSerializer);
    assertTrue(Arrays.equals(getPacketData("01 48 0C 11"), serializer.getPayload()));
    serializer = new DefaultSerializer();
    fieldSerializer = new ZclFieldSerializer(serializer);
    command.setPayloadType(1);
    command.serialize(fieldSerializer);
    assertTrue(Arrays.equals(getPacketData("01 48 0C 11"), serializer.getPayload()));
    serializer = new DefaultSerializer();
    fieldSerializer = new ZclFieldSerializer(serializer);
    command.setPayloadType(2);
    command.serialize(fieldSerializer);
    assertTrue(Arrays.equals(getPacketData("02 48 0C 11 06 00"), serializer.getPayload()));
    serializer = new DefaultSerializer();
    fieldSerializer = new ZclFieldSerializer(serializer);
    command.setPayloadType(3);
    command.serialize(fieldSerializer);
    assertTrue(Arrays.equals(getPacketData("03 48 0C 11 06 00 07 03 02 01"), serializer.getPayload()));
}
Also used : DefaultSerializer(com.zsmartsystems.zigbee.serialization.DefaultSerializer) ZigBeeSerializer(com.zsmartsystems.zigbee.serialization.ZigBeeSerializer) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) ZclFieldSerializer(com.zsmartsystems.zigbee.zcl.ZclFieldSerializer) CommandTest(com.zsmartsystems.zigbee.CommandTest) Test(org.junit.Test)

Example 29 with ZigBeeEndpointAddress

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

the class ZigBeeNetworkDiscoverer method commandReceived.

@Override
public void commandReceived(final ZigBeeCommand command) {
    // ZCL command received from remote node. Perform discovery if it is not yet known.
    if (command instanceof ZclCommand) {
        final ZclCommand zclCommand = (ZclCommand) command;
        if (networkManager.getNode(zclCommand.getSourceAddress().getAddress()) == null) {
            // TODO: Protect against group address?
            ZigBeeEndpointAddress address = (ZigBeeEndpointAddress) zclCommand.getSourceAddress();
            startNodeDiscovery(address.getAddress());
        }
    }
    // Node has been announced.
    if (command instanceof DeviceAnnounce) {
        final DeviceAnnounce announce = (DeviceAnnounce) command;
        // startNodeDiscovery(address.getNwkAddrOfInterest());
        addNode(announce.getIeeeAddr(), announce.getNwkAddrOfInterest());
    }
}
Also used : ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) DeviceAnnounce(com.zsmartsystems.zigbee.zdo.command.DeviceAnnounce) ZclCommand(com.zsmartsystems.zigbee.zcl.ZclCommand)

Example 30 with ZigBeeEndpointAddress

use of com.zsmartsystems.zigbee.ZigBeeEndpointAddress 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;
}
Also used : IeeeAddressResponse(com.zsmartsystems.zigbee.zdo.command.IeeeAddressResponse) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) IeeeAddressRequest(com.zsmartsystems.zigbee.zdo.command.IeeeAddressRequest) ExecutionException(java.util.concurrent.ExecutionException) HashSet(java.util.HashSet) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) CommandResult(com.zsmartsystems.zigbee.CommandResult)

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