use of com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacket in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZDO_POWER_DESC_RSP_Test method testReceive.
@Test
public void testReceive() {
ZToolPacket data = getPacket("FE 07 45 83 00 00 00 00 00 10 C1 10");
ZigBeeApsFrame apsFrame = ZdoPowerDescriptor.create(data);
assertEquals(0x0000, apsFrame.getSourceAddress());
assertEquals(0, apsFrame.getProfile());
assertEquals(0, apsFrame.getDestinationEndpoint());
assertTrue(Arrays.equals(getPacketData("00 00 00 00 10 C1"), apsFrame.getPayload()));
}
use of com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacket in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZDO_SIMPLE_DESC_RSP_Test method testReceive1.
@Test
public void testReceive1() {
ZToolPacket data = getPacket("FE 2E 45 84 00 00 00 00 00 28 01 04 01 00 00 00 00 10 00 00 01 00 02 00 03 00 04 00 05 00 06 00 07 00 08 00 09 00 0F 00 0A 00 0C 00 15 00 00 01 01 01 CF");
ZigBeeApsFrame apsFrame = ZdoSimpleDescriptor.create(data);
assertEquals(0x0000, apsFrame.getSourceAddress());
assertEquals(0, apsFrame.getProfile());
assertEquals(0, apsFrame.getDestinationEndpoint());
assertTrue(Arrays.equals(getPacketData("00 00 00 00 28 01 04 01 00 00 00 00 10 00 00 01 00 02 00 03 00 04 00 05 00 06 00 07 00 08 00 09 00 0F 00 0A 00 0C 00 15 00 00 01 01 01"), apsFrame.getPayload()));
}
use of com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacket in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeNetworkManager method sendRemoteRequest.
public <REQUEST extends ZToolPacket, RESPONSE extends ZToolPacket> RESPONSE sendRemoteRequest(REQUEST request) {
if (!waitForNetwork()) {
return null;
}
RESPONSE result;
waitAndLock3WayConversation(request);
final BlockingCommandReceiver waiter = new BlockingCommandReceiver(ZToolCMD.ZDO_MGMT_PERMIT_JOIN_RSP, commandInterface);
logger.trace("Sending {}", request);
ZToolPacket response = sendSynchronous(request);
if (response == null) {
logger.error("{} timed out waiting for synchronous local response.", request.getClass().getSimpleName());
waiter.cleanup();
return null;
} else {
logger.error("{} timed out waiting for asynchronous remote response.", request.getClass().getSimpleName());
result = (RESPONSE) waiter.getCommand(TIMEOUT);
unLock3WayConversation(request);
return result;
}
}
use of com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacket in project com.zsmartsystems.zigbee by zsmartsystems.
the class CommandInterfaceImpl method sendSynchronousCommand.
/**
* Sends synchronous command and adds listener.
*
* @param packet the command packet
* @param listener the synchronous command response listener
* @param timeoutMillis the timeout
* @throws IOException if IO exception occurs in packet sending
*/
@Override
public void sendSynchronousCommand(final ZToolPacket packet, final SynchronousCommandListener listener, final long timeoutMillis) throws IOException {
if (timeoutMillis == -1L) {
synchronousCommandListenerTimeouts.put(listener, -1L);
} else {
final long expirationTime = System.currentTimeMillis() + timeoutMillis;
synchronousCommandListenerTimeouts.put(listener, expirationTime);
}
final DoubleByte cmdId = packet.getCMD();
final int value = (cmdId.getMsb() & 0xE0);
if (value != 0x20) {
throw new IllegalArgumentException("You are trying to send a non SREQ packet as synchronous command. " + "Evaluated " + value + " instead of " + 0x20 + "\nPacket " + packet.getClass().getName() + "\n" + packet);
}
cleanExpiredSynchronousCommandListeners();
if (supportMultipleSynchrounsCommand) {
synchronized (synchronousCommandListeners) {
final short id = (short) (cmdId.get16BitValue() & 0x1FFF);
while (synchronousCommandListeners.get(cmdId) != null) {
try {
logger.trace("Waiting for other request {} to complete", id);
synchronousCommandListeners.wait(500);
cleanExpiredSynchronousCommandListeners();
} catch (InterruptedException ignored) {
}
}
synchronousCommandListeners.put(id, listener);
}
} else {
synchronized (synchronousCommandListeners) {
final short id = (short) (cmdId.get16BitValue() & 0x1FFF);
while (!synchronousCommandListeners.isEmpty()) {
try {
logger.trace("Waiting for other request to complete");
synchronousCommandListeners.wait(500);
cleanExpiredSynchronousCommandListeners();
} catch (InterruptedException ignored) {
}
}
logger.trace("Put synchronousCommandListeners listener for {} command", id);
synchronousCommandListeners.put(id, listener);
}
}
logger.trace("Sending SynchronousCommand {} ", packet);
sendPacket(packet);
}
use of com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacket in project com.zsmartsystems.zigbee by zsmartsystems.
the class CommandInterfaceImpl method notifySynchronousCommand.
/**
* Notifies listeners about synchronous command response.
*
* @param packet the received packet
*/
private void notifySynchronousCommand(final ZToolPacket packet) {
final DoubleByte cmdId = packet.getCMD();
synchronized (synchronousCommandListeners) {
final short id = (short) (cmdId.get16BitValue() & 0x1FFF);
final SynchronousCommandListener listener = synchronousCommandListeners.get(id);
if (listener != null) {
listener.receivedCommandResponse(packet);
synchronousCommandListeners.remove(id);
synchronousCommandListeners.notifyAll();
} else {
// Notify asynchronous command listeners of unclaimed asynchronous command responses.
final AsynchronousCommandListener[] listeners;
synchronized (asynchrounsCommandListeners) {
listeners = asynchrounsCommandListeners.toArray(new AsynchronousCommandListener[] {});
}
for (final AsynchronousCommandListener asynchronousCommandListener : listeners) {
try {
asynchronousCommandListener.receivedUnclaimedSynchronousCommandResponse(packet);
} catch (Throwable e) {
logger.error("Error in incoming asynchronous message processing: ", e);
}
}
}
}
}
Aggregations