use of com.zsmartsystems.zigbee.dongle.xbee.internal.protocol.XBeeCommand 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.dongle.xbee.internal.protocol.XBeeCommand in project com.zsmartsystems.zigbee by zsmartsystems.
the class XBeeFrameHandler method sendNextFrame.
private void sendNextFrame() {
synchronized (commandLock) {
// Are we already processing a command?
if (sentCommand != null) {
logger.trace("TX XBEE Frame outstanding: {}", sentCommand);
return;
}
XBeeCommand nextFrame = sendQueue.poll();
if (nextFrame == null) {
logger.trace("XBEE TX: Nothing to send");
// Nothing to send
stopTimer();
return;
}
logger.debug("TX XBEE: {}", nextFrame);
// Remember the command we're processing
sentCommand = nextFrame;
serialPort.write(XBEE_FLAG);
// Send the data
StringBuilder builder = new StringBuilder();
for (int sendByte : nextFrame.serialize()) {
builder.append(String.format(" %02X", sendByte));
if (escapeCodes.contains(sendByte)) {
serialPort.write(XBEE_ESCAPE);
serialPort.write(sendByte ^ XBEE_XOR);
} else {
serialPort.write(sendByte);
}
}
logger.debug("TX XBEE Data:{}", builder.toString());
// Start the timeout
startTimer();
}
}
Aggregations