use of com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacket in project com.zsmartsystems.zigbee by zsmartsystems.
the class CommandInterfaceImpl method notifyAsynchronousCommand.
/**
* Notifies listeners about asynchronous message.
*
* @param packet the packet containing the message
*/
private void notifyAsynchronousCommand(final ZToolPacket packet) {
final AsynchronousCommandListener[] listeners;
synchronized (asynchrounsCommandListeners) {
listeners = asynchrounsCommandListeners.toArray(new AsynchronousCommandListener[] {});
}
logger.debug("Received Async Cmd: {}", packet);
for (final AsynchronousCommandListener listener : listeners) {
try {
listener.receivedAsynchronousCommand(packet);
} catch (Throwable e) {
logger.error("Error in incoming asynchronous message processing: ", e);
}
}
}
use of com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacket in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZToolPacketStream method parsePacket.
public ZToolPacket parsePacket() throws IOException {
Exception exception;
done = false;
bytesRead = 0;
try {
final ZToolPacket response;
// int byteLength = this.read("Length");
this.length = read("Length");
// log.debug("data length is " + ByteUtils.formatByte(length.getLength()));
final int[] frameData;
final int apiIdMSB = this.read("API PROFILE_ID_HOME_AUTOMATION MSB");
final int apiIdLSB = this.read("API PROFILE_ID_HOME_AUTOMATION LSB");
final DoubleByte apiId = new DoubleByte(apiIdMSB, apiIdLSB);
// generic = true;
if (generic) {
// log.info("Parsing data as generic");
int i = 0;
frameData = new int[length];
// Read all data bytes without parsing
while (i < frameData.length) {
frameData[i] = this.read("Data " + i + "-th");
i++;
}
response = new ZToolPacket(apiId, frameData);
} else {
frameData = this.readRemainingBytes();
response = parsePayload(apiId, frameData);
}
// response.setFCS(this.read("Checksum"));
int fcs = this.read("Checksum");
// setDone(true);
if (fcs != response.getFCS()) {
// log.debug("Checksum of packet failed: received =" + fcs + " expected = " + response.getFCS());
throw new ZToolParseException("Packet checksum failed");
}
if (!this.isDone()) {
// TODO this is not the answer!
throw new ZToolParseException("Packet stream is not finished yet we seem to think it is");
}
return response;
} catch (Exception e) {
logger.error("Packet parsing failed due to exception.", e);
exception = e;
}
final ZToolPacket exceptionResponse = new ErrorPacket();
if (exception != null) {
exceptionResponse.setError(true);
exceptionResponse.setErrorMsg(exception.getMessage());
}
return exceptionResponse;
}
use of com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacket in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZDO_MGMT_RTG_RSP_Test method testReceive.
@Test
public void testReceive() {
ZToolPacket data = getPacket("FE 0B 45 B2 00 00 00 01 00 01 2A 2F 00 35 38 F4");
ZigBeeApsFrame apsFrame = ZdoManagementRouting.create(data);
assertEquals(0x0000, apsFrame.getSourceAddress());
assertEquals(0, apsFrame.getProfile());
assertEquals(0, apsFrame.getDestinationEndpoint());
assertTrue(Arrays.equals(getPacketData("00 00 01 00 01 2A 2F 00 35 38"), 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 testReceive2.
@Test
public void testReceive2() {
ZToolPacket data = getPacket("FE 18 45 84 21 A4 00 21 A4 12 02 04 01 01 00 00 02 00 00 03 00 03 05 00 06 00 08 00 C4");
ZigBeeApsFrame apsFrame = ZdoSimpleDescriptor.create(data);
assertEquals(42017, apsFrame.getSourceAddress());
assertEquals(0, apsFrame.getProfile());
assertEquals(0, apsFrame.getDestinationEndpoint());
assertTrue(Arrays.equals(getPacketData("A4 00 21 A4 12 02 04 01 01 00 00 02 00 00 03 00 03 05 00 06 00 08 00"), apsFrame.getPayload()));
}
use of com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacket in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeNetworkManagerTest method dongleSetChannel.
@Test
public void dongleSetChannel() {
CommandInterface commandInterface = getCommandInterface();
ZigBeeNetworkManager networkManager = new ZigBeeNetworkManager(commandInterface, null, 0);
networkManager.setRetryConfiguration(1, 0);
Method privateMethod;
try {
privateMethod = ZigBeeNetworkManager.class.getDeclaredMethod("dongleSetChannel", new Class[] { int[].class });
privateMethod.setAccessible(true);
// Channel 11
privateMethod.invoke(networkManager, new int[] { 0x00, 0x08, 0x00, 0x00 });
ZToolPacket packet = argumentPacket.getAllValues().get(0);
assertTrue(Arrays.equals(new int[] { 254, 6, 38, 5, 132, 0x04, 0x00, 0x08, 0x00, 0x00, 173 }, packet.getPacket()));
// Check channel 11 is set even when incorrect data
privateMethod.invoke(networkManager, new int[] { 0x01, 0x08, 0x00, 0x00 });
packet = argumentPacket.getAllValues().get(1);
assertTrue(Arrays.equals(new int[] { 254, 6, 38, 5, 132, 0x04, 0x00, 0x08, 0x00, 0x00, 173 }, packet.getPacket()));
// Check channel 11 is set when no channels are set
privateMethod.invoke(networkManager, new int[] { 0x00, 0x00, 0x00, 0x00 });
packet = argumentPacket.getAllValues().get(2);
assertTrue(Arrays.equals(new int[] { 254, 6, 38, 5, 132, 0x04, 0x00, 0x08, 0x00, 0x00, 173 }, packet.getPacket()));
// Check a number of channels are set
privateMethod.invoke(networkManager, new int[] { 0x00, 0xff, 0x00, 0x00 });
packet = argumentPacket.getAllValues().get(3);
assertTrue(Arrays.equals(new int[] { 254, 6, 38, 5, 132, 0x04, 0x00, 0xf8, 0x00, 0x00, 0x5D }, packet.getPacket()));
networkManager.setZigBeeChannel(12);
packet = argumentPacket.getAllValues().get(4);
assertTrue(Arrays.equals(new int[] { 254, 6, 38, 5, 132, 0x04, 0x00, 0x10, 0x00, 0x00, 0xB5 }, packet.getPacket()));
} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
e.printStackTrace();
}
}
Aggregations