use of com.zsmartsystems.zigbee.zdo.field.BindingTable in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeConsoleBindingTableCommand method process.
@Override
public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out) throws IllegalArgumentException, InterruptedException, ExecutionException {
if (args.length != 2) {
throw new IllegalArgumentException("Invalid number of arguments");
}
ZigBeeNode node = getNode(networkManager, args[1]);
final Boolean result = node.updateBindingTable().get();
if (!result) {
out.println("Binding table read error");
return;
}
out.println("Binding table for node " + node.getNetworkAddress() + " [" + node.getIeeeAddress() + "]");
if (node.getBindingTable().isEmpty()) {
out.println("--- Empty");
return;
}
out.println("Src Address | Dest Address | Group | Mode | Cluster");
for (BindingTable entry : node.getBindingTable()) {
out.println(String.format("%s/%-3d | %s/%-3d | %5d | %4d | %04X:%s", entry.getSrcAddr().toString(), entry.getSrcEndpoint(), entry.getDstNodeAddr(), entry.getDstNodeEndpoint(), entry.getDstGroupAddr(), entry.getDstAddrMode(), entry.getClusterId(), ZclClusterType.getValueById(entry.getClusterId())));
}
}
use of com.zsmartsystems.zigbee.zdo.field.BindingTable in project com.zsmartsystems.zigbee by zsmartsystems.
the class ZigBeeNode method updateBindingTable.
/**
* Request an update of the binding table for this node.
* <p>
* This method returns a future to a boolean. Upon success the caller should call {@link #getBindingTable()}
*
* @return {@link Future} returning a {@link Boolean}
*/
public Future<Boolean> updateBindingTable() {
RunnableFuture<Boolean> future = new FutureTask<Boolean>(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
int index = 0;
int tableSize = 0;
List<BindingTable> bindingTable = new ArrayList<BindingTable>();
do {
ManagementBindRequest bindingRequest = new ManagementBindRequest();
bindingRequest.setDestinationAddress(new ZigBeeEndpointAddress(networkAddress));
bindingRequest.setStartIndex(index);
CommandResult result = networkManager.unicast(bindingRequest, new ManagementBindRequest()).get();
if (result.isError()) {
return false;
}
ManagementBindResponse response = (ManagementBindResponse) result.getResponse();
if (response.getStartIndex() == index) {
tableSize = response.getBindingTableEntries();
index += response.getBindingTableList().size();
bindingTable.addAll(response.getBindingTableList());
}
} while (index < tableSize);
setBindingTable(bindingTable);
return true;
}
});
// start the thread to execute it
new Thread(future).start();
return future;
}
use of com.zsmartsystems.zigbee.zdo.field.BindingTable in project com.zsmartsystems.zigbee by zsmartsystems.
the class DefaultDeserializer method readZigBeeType.
@Override
public /**
* {@inheritDoc}
*/
Object readZigBeeType(ZclDataType type) {
if (index == payload.length) {
return null;
}
Object[] value = new Object[1];
switch(type) {
case BOOLEAN:
value[0] = payload[index++] == 0 ? false : true;
break;
case CHARACTER_STRING:
case OCTET_STRING:
int size = payload[index++];
if (size == 255) {
value[0] = null;
break;
}
int length = size;
for (int cnt = 0; cnt < size; cnt++) {
if (payload[index + cnt] == 0) {
length = cnt;
}
}
value[0] = new String(payload, index, length);
index += size;
break;
case ENDPOINT:
case BITMAP_8_BIT:
case DATA_8_BIT:
case ENUMERATION_8_BIT:
value[0] = Integer.valueOf((byte) payload[index++] & 0xFF);
break;
case EXTENDED_PANID:
int[] panId = new int[8];
for (int iCnt = 7; iCnt >= 0; iCnt--) {
panId[iCnt] = payload[index + iCnt];
}
index += 8;
value[0] = new ExtendedPanId(panId);
break;
case IEEE_ADDRESS:
int[] address = new int[8];
for (int iCnt = 7; iCnt >= 0; iCnt--) {
address[iCnt] = payload[index + iCnt];
}
index += 8;
value[0] = new IeeeAddress(address);
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:
int cntN16 = Integer.valueOf((byte) payload[index++] & 0xFF);
List<Integer> arrayN16 = new ArrayList<Integer>(cntN16);
for (int arrayIndex = 0; arrayIndex < cntN16; arrayIndex++) {
arrayN16.add(Integer.valueOf(payload[index++] + ((payload[index++] << 8) & 0xffff)));
}
value[0] = arrayN16;
break;
case N_X_UNSIGNED_8_BIT_INTEGER:
int cntN8 = Integer.valueOf((byte) payload[index++] & 0xFF);
List<Integer> arrayN8 = new ArrayList<Integer>(cntN8);
for (int arrayIndex = 0; arrayIndex < cntN8; arrayIndex++) {
arrayN8.add(Integer.valueOf(payload[index++]));
}
value[0] = arrayN8;
break;
case X_UNSIGNED_8_BIT_INTEGER:
int cntX8 = payload.length - index;
List<Integer> arrayX8 = new ArrayList<Integer>(cntX8);
for (int arrayIndex = 0; arrayIndex < cntX8; arrayIndex++) {
arrayX8.add(Integer.valueOf(payload[index++]));
}
value[0] = arrayX8;
break;
case N_X_ATTRIBUTE_IDENTIFIER:
int cntX16 = (payload.length - index) / 2;
List<Integer> arrayX16 = new ArrayList<Integer>(cntX16);
for (int arrayIndex = 0; arrayIndex < cntX16; arrayIndex++) {
arrayX16.add(Integer.valueOf(payload[index++]));
}
value[0] = arrayX16;
break;
case UNSIGNED_8_BIT_INTEGER_ARRAY:
int cnt8Array = payload.length - index;
int[] intarray8 = new int[cnt8Array];
for (int arrayIndex = 0; arrayIndex < cnt8Array; arrayIndex++) {
intarray8[arrayIndex] = payload[index++];
}
value[0] = intarray8;
break;
case N_X_WRITE_ATTRIBUTE_RECORD:
break;
case N_X_WRITE_ATTRIBUTE_STATUS_RECORD:
break;
case CLUSTERID:
case NWK_ADDRESS:
case BITMAP_16_BIT:
case ENUMERATION_16_BIT:
case SIGNED_16_BIT_INTEGER:
case UNSIGNED_16_BIT_INTEGER:
short s = (short) (payload[index++] + (payload[index++] << 8));
if (type == ZclDataType.SIGNED_16_BIT_INTEGER) {
value[0] = Integer.valueOf(s);
} else {
value[0] = Integer.valueOf(s & 0xFFFF);
}
break;
case BITMAP_32_BIT:
case SIGNED_32_BIT_INTEGER:
case UNSIGNED_32_BIT_INTEGER:
value[0] = payload[index++] + (payload[index++] << 8) + (payload[index++] << 16) + (payload[index++] << 24);
break;
case SIGNED_8_BIT_INTEGER:
value[0] = Integer.valueOf((byte) payload[index++]);
break;
case UNSIGNED_8_BIT_INTEGER:
value[0] = Integer.valueOf((byte) payload[index++] & 0xFF);
break;
case UTCTIME:
break;
case ROUTING_TABLE:
RoutingTable routingTable = new RoutingTable();
routingTable.deserialize(this);
value[0] = routingTable;
break;
case NEIGHBOR_TABLE:
NeighborTable neighborTable = new NeighborTable();
neighborTable.deserialize(this);
value[0] = neighborTable;
break;
case NODE_DESCRIPTOR:
NodeDescriptor nodeDescriptor = new NodeDescriptor();
nodeDescriptor.deserialize(this);
value[0] = nodeDescriptor;
break;
case POWER_DESCRIPTOR:
PowerDescriptor powerDescriptor = new PowerDescriptor();
powerDescriptor.deserialize(this);
value[0] = powerDescriptor;
break;
case BINDING_TABLE:
BindingTable bindingTable = new BindingTable();
bindingTable.deserialize(this);
value[0] = bindingTable;
break;
case SIMPLE_DESCRIPTOR:
SimpleDescriptor simpleDescriptor = new SimpleDescriptor();
simpleDescriptor.deserialize(this);
value[0] = simpleDescriptor;
break;
case ZCL_STATUS:
value[0] = ZclStatus.getStatus(payload[index++]);
break;
case ZDO_STATUS:
value[0] = ZdoStatus.getStatus(payload[index++]);
break;
case ZIGBEE_DATA_TYPE:
value[0] = ZclDataType.getType(payload[index++]);
break;
case BYTE_ARRAY:
int cntB8 = Integer.valueOf((byte) payload[index++] & 0xFF);
byte[] arrayB8 = new byte[cntB8];
for (int arrayIndex = 0; arrayIndex < cntB8; arrayIndex++) {
arrayB8[arrayIndex] = (byte) (payload[index++] & 0xff);
}
value[0] = new ByteArray(arrayB8);
break;
default:
throw new IllegalArgumentException("No reader defined in " + ZigBeeDeserializer.class.getSimpleName() + " for " + type.toString() + " (" + type.getId() + ")");
}
return value[0];
}
use of com.zsmartsystems.zigbee.zdo.field.BindingTable 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());
}
Aggregations