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()));
}
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()));
}
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()));
}
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());
}
}
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;
}
Aggregations