use of com.zsmartsystems.zigbee.IeeeAddress in project com.zsmartsystems.zigbee by zsmartsystems.
the class IeeeAddressResponseTest method testReceiveVeryShort.
@Test
public void testReceiveVeryShort() {
// Short response - ie not extended. This is from the Ember response!
int[] packet = getPacketData("00 00 42 CC 12 00 00 24 E5 7C AD B8");
IeeeAddressResponse addressResponse = new IeeeAddressResponse();
DefaultDeserializer deserializer = new DefaultDeserializer(packet);
ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);
addressResponse.deserialize(fieldDeserializer);
System.out.println(addressResponse);
assertEquals(ZdoStatus.SUCCESS, addressResponse.getStatus());
assertEquals(new IeeeAddress("7CE524000012CC42"), addressResponse.getIeeeAddrRemoteDev());
assertEquals(Integer.valueOf(47277), addressResponse.getNwkAddrRemoteDev());
assertEquals(0x8001, (int) addressResponse.getClusterId());
}
use of com.zsmartsystems.zigbee.IeeeAddress in project com.zsmartsystems.zigbee by zsmartsystems.
the class IeeeAddressResponseTest method testReceive.
@Test
public void testReceive() {
int[] packet = getPacketData("00 00 EC A1 A5 01 00 8D 15 00 35 38 00 01 2A 2F");
IeeeAddressResponse addressResponse = new IeeeAddressResponse();
DefaultDeserializer deserializer = new DefaultDeserializer(packet);
ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);
addressResponse.deserialize(fieldDeserializer);
System.out.println(addressResponse);
assertEquals(new IeeeAddress("00158D0001A5A1EC"), addressResponse.getIeeeAddrRemoteDev());
assertEquals(0x8001, (int) addressResponse.getClusterId());
assertEquals(ZdoStatus.SUCCESS, addressResponse.getStatus());
}
use of com.zsmartsystems.zigbee.IeeeAddress in project com.zsmartsystems.zigbee by zsmartsystems.
the class ManagementBindResponseTest method testReceive.
@Test
public void testReceive() {
int[] packet = getPacketData("00 00 01 00 01 43 1D A5 00 AA 3E B0 7C 03 06 00 03 62 39 05 0D 00 6F 0D 00 01");
ManagementBindResponse response = new ManagementBindResponse();
DefaultDeserializer deserializer = new DefaultDeserializer(packet);
ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);
response.deserialize(fieldDeserializer);
System.out.println(response);
assertEquals(1, (int) response.getBindingTableEntries());
assertEquals(0, (int) response.getStartIndex());
List<BindingTable> table = response.getBindingTableList();
assertEquals(1, table.size());
BindingTable entry = table.get(0);
assertEquals(6, entry.getClusterId());
assertEquals(3, entry.getDstAddrMode());
assertEquals(new IeeeAddress("7CB03EAA00A51D43"), entry.getSrcAddr());
assertEquals(3, entry.getSrcEndpoint());
assertEquals(new IeeeAddress("000D6F000D053962"), entry.getDstNodeAddr());
assertEquals(1, entry.getDstNodeEndpoint());
}
use of com.zsmartsystems.zigbee.IeeeAddress 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;
}
use of com.zsmartsystems.zigbee.IeeeAddress in project com.zsmartsystems.zigbee by zsmartsystems.
the class DefaultSerializer method appendZigBeeType.
@Override
public void appendZigBeeType(Object data, ZclDataType type) throws IllegalArgumentException {
if (data == null) {
throw new IllegalArgumentException("You can not append null data to a stream");
}
switch(type) {
case BOOLEAN:
buffer[length++] = (Boolean) data ? 1 : 0;
break;
case NWK_ADDRESS:
case BITMAP_16_BIT:
case SIGNED_16_BIT_INTEGER:
case UNSIGNED_16_BIT_INTEGER:
case ENUMERATION_16_BIT:
case CLUSTERID:
final short shortValue = ((Number) data).shortValue();
buffer[length++] = shortValue & 0xFF;
buffer[length++] = (shortValue >> 8) & 0xFF;
break;
case ENDPOINT:
case DATA_8_BIT:
case BITMAP_8_BIT:
case SIGNED_8_BIT_INTEGER:
case UNSIGNED_8_BIT_INTEGER:
case ENUMERATION_8_BIT:
final byte byteValue = ((Number) data).byteValue();
buffer[length++] = byteValue & 0xFF;
break;
case EXTENDED_PANID:
int[] panId = ((ExtendedPanId) data).getValue();
buffer[length++] = panId[0];
buffer[length++] = panId[1];
buffer[length++] = panId[2];
buffer[length++] = panId[3];
buffer[length++] = panId[4];
buffer[length++] = panId[5];
buffer[length++] = panId[6];
buffer[length++] = panId[7];
break;
case IEEE_ADDRESS:
int[] address = ((IeeeAddress) data).getValue();
buffer[length++] = address[0];
buffer[length++] = address[1];
buffer[length++] = address[2];
buffer[length++] = address[3];
buffer[length++] = address[4];
buffer[length++] = address[5];
buffer[length++] = address[6];
buffer[length++] = address[7];
break;
case N_X_ATTRIBUTE_INFORMATION:
break;
case N_X_ATTRIBUTE_RECORD:
break;
case N_X_ATTRIBUTE_REPORT:
break;
case N_X_ATTRIBUTE_REPORTING_CONFIGURATION_RECORD:
break;
case N_X_ATTRIBUTE_SELECTOR:
break;
case N_X_ATTRIBUTE_STATUS_RECORD:
break;
case N_X_EXTENSION_FIELD_SET:
break;
case N_X_NEIGHBORS_INFORMATION:
break;
case N_X_READ_ATTRIBUTE_STATUS_RECORD:
break;
case N_X_UNSIGNED_16_BIT_INTEGER:
List<Integer> intArray16 = (List<Integer>) data;
buffer[length++] = intArray16.size();
for (int value : intArray16) {
buffer[length++] = value & 0xFF;
buffer[length++] = (value >> 8) & 0xFF;
}
break;
case N_X_UNSIGNED_8_BIT_INTEGER:
List<Integer> intArrayNX8 = (List<Integer>) data;
buffer[length++] = intArrayNX8.size();
for (int value : intArrayNX8) {
buffer[length++] = value & 0xFF;
}
break;
case UNSIGNED_8_BIT_INTEGER_ARRAY:
int[] intArrayN8 = (int[]) data;
for (int value : intArrayN8) {
buffer[length++] = value & 0xFF;
}
break;
case X_UNSIGNED_8_BIT_INTEGER:
List<Integer> intArrayX8 = (List<Integer>) data;
for (int value : intArrayX8) {
buffer[length++] = value & 0xFF;
}
break;
case N_X_ATTRIBUTE_IDENTIFIER:
List<Integer> intArrayX16 = (List<Integer>) data;
for (int value : intArrayX16) {
buffer[length++] = value & 0xFF;
buffer[length++] = (value >> 8) & 0xFF;
}
break;
case N_X_WRITE_ATTRIBUTE_RECORD:
break;
case N_X_WRITE_ATTRIBUTE_STATUS_RECORD:
break;
case CHARACTER_STRING:
case OCTET_STRING:
final String str = (String) data;
buffer[length++] = ((byte) (str.length() & (0xFF)));
for (int strByte : str.getBytes()) {
buffer[length++] = strByte;
}
break;
case SIGNED_32_BIT_INTEGER:
final int intValue = (Integer) data;
buffer[length++] = intValue & 0xFF;
buffer[length++] = (intValue >> 8) & 0xFF;
buffer[length++] = (intValue >> 16) & 0xFF;
buffer[length++] = (intValue >> 24) & 0xFF;
break;
case BITMAP_32_BIT:
case UNSIGNED_32_BIT_INTEGER:
final int uintValue = (Integer) data;
buffer[length++] = uintValue & 0xFF;
buffer[length++] = (uintValue >> 8) & 0xFF;
buffer[length++] = (uintValue >> 16) & 0xFF;
buffer[length++] = (uintValue >> 24) & 0xFF;
break;
case UTCTIME:
break;
case ZDO_STATUS:
buffer[length++] = ((ZdoStatus) data).getId();
break;
case ZCL_STATUS:
buffer[length++] = ((ZclStatus) data).getId();
break;
case BYTE_ARRAY:
final ByteArray byteArray = (ByteArray) data;
buffer[length++] = byteArray.size();
for (byte valByte : byteArray.get()) {
buffer[length++] = valByte & 0xff;
}
break;
case ZIGBEE_DATA_TYPE:
buffer[length++] = ((ZclDataType) data).getId();
break;
default:
throw new IllegalArgumentException("No writer defined in " + ZigBeeDeserializer.class.getSimpleName() + " for " + type.toString() + " (" + type.getId() + ")");
}
}
Aggregations