use of com.zsmartsystems.zigbee.ZigBeeEndpointAddress in project com.zsmartsystems.zigbee by zsmartsystems.
the class ManagementPermitJoiningRequestTest method testReceive.
@Test
public void testReceive() {
// Short response - ie not extended
int[] packet = getPacketData("00 FF 01");
ManagementPermitJoiningRequest request = new ManagementPermitJoiningRequest();
request.setDestinationAddress(new ZigBeeEndpointAddress(0));
request.setTcSignificance(true);
request.setPermitDuration(255);
DefaultSerializer serializer = new DefaultSerializer();
ZclFieldSerializer fieldSerializer = new ZclFieldSerializer(serializer);
request.serialize(fieldSerializer);
assertTrue(Arrays.equals(packet, serializer.getPayload()));
}
use of com.zsmartsystems.zigbee.ZigBeeEndpointAddress in project com.zsmartsystems.zigbee by zsmartsystems.
the class EzspSendUnicastTest method testSendPermitJoining.
@Test
public void testSendPermitJoining() {
EzspFrame.setEzspVersion(4);
ManagementPermitJoiningRequest permitJoining = new ManagementPermitJoiningRequest();
permitJoining.setDestinationAddress(new ZigBeeEndpointAddress(0x401C));
permitJoining.setSourceAddress(new ZigBeeEndpointAddress(0));
permitJoining.setTcSignificance(false);
permitJoining.setPermitDuration(60);
DefaultSerializer serializer = new DefaultSerializer();
ZclFieldSerializer fieldSerializer = new ZclFieldSerializer(serializer);
permitJoining.serialize(fieldSerializer);
int[] payload = serializer.getPayload();
EzspSendUnicastRequest emberUnicast = new EzspSendUnicastRequest();
EmberApsFrame apsFrame = new EmberApsFrame();
apsFrame.setClusterId(permitJoining.getClusterId());
apsFrame.setProfileId(0);
apsFrame.setSourceEndpoint(1);
apsFrame.setDestinationEndpoint(0);
apsFrame.setSequence(0x88);
apsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_RETRY);
apsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_ENABLE_ADDRESS_DISCOVERY);
apsFrame.addOptions(EmberApsOption.EMBER_APS_OPTION_ENABLE_ROUTE_DISCOVERY);
apsFrame.setGroupId(0xffff);
emberUnicast.setMessageTag(0x99);
emberUnicast.setSequenceNumber(0xaa);
emberUnicast.setType(EmberOutgoingMessageType.EMBER_OUTGOING_DIRECT);
emberUnicast.setApsFrame(apsFrame);
emberUnicast.setIndexOrDestination(permitJoining.getDestinationAddress().getAddress());
emberUnicast.setMessageContents(payload);
int[] messageToSend = emberUnicast.serialize();
System.out.println(emberUnicast.toString());
System.out.println(Arrays.toString(messageToSend));
String out = "";
for (int c : messageToSend) {
out += String.format("%02X ", c);
}
System.out.println(out);
}
use of com.zsmartsystems.zigbee.ZigBeeEndpointAddress in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeDongleXBeeTest method sendCommand.
@Test
public void sendCommand() {
XBeeFrameHandler frameHandler = Mockito.mock(XBeeFrameHandler.class);
ArgumentCaptor<XBeeCommand> commandCapture = ArgumentCaptor.forClass(XBeeCommand.class);
Mockito.when(frameHandler.sendRequestAsync(commandCapture.capture())).thenReturn(null);
ZigBeeDongleXBee dongle = new ZigBeeDongleXBee(null);
Field field;
try {
field = dongle.getClass().getDeclaredField("frameHandler");
field.setAccessible(true);
field.set(dongle, frameHandler);
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
MatchDescriptorResponse command = new MatchDescriptorResponse();
command.setDestinationAddress(new ZigBeeEndpointAddress(46946));
command.setNwkAddrOfInterest(46946);
command.setStatus(ZdoStatus.SUCCESS);
command.setTransactionId(0x2A);
List<Integer> matchList = new ArrayList<>();
matchList.add(1);
command.setMatchList(matchList);
ZigBeeApsFrame apsFrame = new ZigBeeApsFrame();
apsFrame.setDestinationAddress(46946);
apsFrame.setDestinationEndpoint(0);
apsFrame.setDestinationIeeeAddress(new IeeeAddress("000D6F00057CF7C6"));
apsFrame.setCluster(32774);
apsFrame.setAddressMode(ZigBeeNwkAddressMode.DEVICE);
apsFrame.setRadius(31);
apsFrame.setSequence(42);
apsFrame.setPayload(new int[] { 0x00, 0x00, 0x2E, 0x5B, 0x01, 0x01 });
System.out.println(command);
System.out.println(apsFrame);
dongle.sendCommand(apsFrame);
assertEquals(1, commandCapture.getAllValues().size());
XBeeTransmitRequestExplicitCommand sentCommand = (XBeeTransmitRequestExplicitCommand) commandCapture.getValue();
sentCommand.setFrameId(32);
System.out.println(sentCommand);
int[] payload = new int[] { 0, 26, 17, 32, 0, 13, 111, 0, 5, 124, 247, 198, 183, 98, 0, 0, 128, 6, 0, 0, 0, 32, 0, 0, 46, 91, 1, 1, 202 };
int[] output = sentCommand.serialize();
assertTrue(Arrays.equals(payload, output));
}
use of com.zsmartsystems.zigbee.ZigBeeEndpointAddress in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeNodeServiceDiscoverer method requestNodeDescriptor.
/**
* Get node descriptor
*
* @return true if the message was processed ok
* @throws ExecutionException
* @throws InterruptedException
*/
private boolean requestNodeDescriptor() throws InterruptedException, ExecutionException {
final NodeDescriptorRequest nodeDescriptorRequest = new NodeDescriptorRequest();
nodeDescriptorRequest.setDestinationAddress(new ZigBeeEndpointAddress(node.getNetworkAddress()));
nodeDescriptorRequest.setNwkAddrOfInterest(node.getNetworkAddress());
CommandResult response = networkManager.unicast(nodeDescriptorRequest, nodeDescriptorRequest).get();
final NodeDescriptorResponse nodeDescriptorResponse = (NodeDescriptorResponse) response.getResponse();
logger.debug("{}: Node SVC Discovery NodeDescriptorResponse returned {}", node.getIeeeAddress(), nodeDescriptorResponse);
if (nodeDescriptorResponse == null) {
return false;
}
if (nodeDescriptorResponse.getStatus() == ZdoStatus.SUCCESS) {
node.setNodeDescriptor(nodeDescriptorResponse.getNodeDescriptor());
return true;
}
return false;
}
use of com.zsmartsystems.zigbee.ZigBeeEndpointAddress in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeNodeServiceDiscoverer method requestAssociatedNodes.
/**
* Get Node Network address and the list of associated devices
*
* @return true if the message was processed ok
* @throws ExecutionException
* @throws InterruptedException
*/
private boolean requestAssociatedNodes() throws InterruptedException, ExecutionException {
Integer startIndex = 0;
int totalAssociatedDevices = 0;
Set<Integer> associatedDevices = new HashSet<Integer>();
do {
// Request extended response, to get associated list
final IeeeAddressRequest ieeeAddressRequest = new IeeeAddressRequest();
ieeeAddressRequest.setDestinationAddress(new ZigBeeEndpointAddress(node.getNetworkAddress()));
ieeeAddressRequest.setRequestType(1);
ieeeAddressRequest.setStartIndex(startIndex);
ieeeAddressRequest.setNwkAddrOfInterest(node.getNetworkAddress());
CommandResult response = networkManager.unicast(ieeeAddressRequest, ieeeAddressRequest).get();
final IeeeAddressResponse ieeeAddressResponse = response.getResponse();
logger.debug("{}: Node SVC Discovery IeeeAddressResponse returned {}", node.getIeeeAddress(), ieeeAddressResponse);
if (ieeeAddressResponse != null && ieeeAddressResponse.getStatus() == ZdoStatus.SUCCESS) {
associatedDevices.addAll(ieeeAddressResponse.getNwkAddrAssocDevList());
startIndex += ieeeAddressResponse.getNwkAddrAssocDevList().size();
totalAssociatedDevices = ieeeAddressResponse.getNwkAddrAssocDevList().size();
}
} while (startIndex < totalAssociatedDevices);
node.setAssociatedDevices(associatedDevices);
return true;
}
Aggregations