Search in sources :

Example 1 with RoutingTable

use of com.zsmartsystems.zigbee.zdo.field.RoutingTable in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeNodeServiceDiscoverer method requestRoutingTable.

/**
 * Get node routing table by making a {@link ManagementRoutingRequest} request
 *
 * @return list of {@link RoutingTable} if the request was processed ok, null otherwise
 * @throws ExecutionException
 * @throws InterruptedException
 */
private boolean requestRoutingTable() throws InterruptedException, ExecutionException {
    // Start index for the list is 0
    int startIndex = 0;
    int totalRoutes = 0;
    Set<RoutingTable> routes = new HashSet<RoutingTable>();
    do {
        final ManagementRoutingRequest routeRequest = new ManagementRoutingRequest();
        routeRequest.setDestinationAddress(new ZigBeeEndpointAddress(node.getNetworkAddress()));
        routeRequest.setStartIndex(startIndex);
        CommandResult response = networkManager.unicast(routeRequest, routeRequest).get();
        final ManagementRoutingResponse routingResponse = response.getResponse();
        logger.debug("{}: Node SVC Discovery ManagementRoutingRequest returned {}", node.getIeeeAddress(), response);
        if (routingResponse == null) {
            return false;
        }
        if (routingResponse.getStatus() == ZdoStatus.NOT_SUPPORTED) {
            supportsManagementRouting = false;
            return true;
        } else if (routingResponse.getStatus() != ZdoStatus.SUCCESS) {
            return false;
        }
        // Save the routes
        routes.addAll(routingResponse.getRoutingTableList());
        // Continue with next request
        startIndex += routingResponse.getRoutingTableList().size();
        totalRoutes = routingResponse.getRoutingTableEntries();
    } while (startIndex < totalRoutes);
    node.setRoutes(routes);
    return true;
}
Also used : ManagementRoutingResponse(com.zsmartsystems.zigbee.zdo.command.ManagementRoutingResponse) RoutingTable(com.zsmartsystems.zigbee.zdo.field.RoutingTable) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) HashSet(java.util.HashSet) ManagementRoutingRequest(com.zsmartsystems.zigbee.zdo.command.ManagementRoutingRequest) CommandResult(com.zsmartsystems.zigbee.CommandResult)

Example 2 with RoutingTable

use of com.zsmartsystems.zigbee.zdo.field.RoutingTable 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];
}
Also used : ExtendedPanId(com.zsmartsystems.zigbee.ExtendedPanId) ArrayList(java.util.ArrayList) NodeDescriptor(com.zsmartsystems.zigbee.zdo.field.NodeDescriptor) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) SimpleDescriptor(com.zsmartsystems.zigbee.zdo.field.SimpleDescriptor) RoutingTable(com.zsmartsystems.zigbee.zdo.field.RoutingTable) BindingTable(com.zsmartsystems.zigbee.zdo.field.BindingTable) NeighborTable(com.zsmartsystems.zigbee.zdo.field.NeighborTable) ByteArray(com.zsmartsystems.zigbee.zcl.field.ByteArray) PowerDescriptor(com.zsmartsystems.zigbee.zdo.field.PowerDescriptor)

Example 3 with RoutingTable

use of com.zsmartsystems.zigbee.zdo.field.RoutingTable in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeConsoleDescribeNodeCommand method process.

@Override
public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out) throws IllegalArgumentException {
    if (args.length != 2) {
        throw new IllegalArgumentException("Invalid number of arguments");
    }
    final ZigBeeNode node = getNode(networkManager, args[1]);
    out.println("IEEE Address     : " + node.getIeeeAddress());
    out.println("Network Address  : " + node.getNetworkAddress());
    out.println("Node Descriptor  : " + node.getNodeDescriptor());
    out.println("Power Descriptor : " + node.getPowerDescriptor());
    out.println("Associations     : " + node.getAssociatedDevices().toString());
    out.println("Endpoints:");
    for (ZigBeeEndpoint endpoint : node.getEndpoints()) {
        out.println(endpoint.toString());
    }
    out.println("Neighbors:");
    for (NeighborTable neighbor : node.getNeighbors()) {
        out.println(neighbor.toString());
    }
    out.println("Routes:");
    for (RoutingTable route : node.getRoutes()) {
        out.println(route.toString());
    }
}
Also used : RoutingTable(com.zsmartsystems.zigbee.zdo.field.RoutingTable) ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode) NeighborTable(com.zsmartsystems.zigbee.zdo.field.NeighborTable) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint)

Example 4 with RoutingTable

use of com.zsmartsystems.zigbee.zdo.field.RoutingTable in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeNodeTest method testRoutingTableUpdate.

@Test
public void testRoutingTableUpdate() {
    ZigBeeNode node = new ZigBeeNode(Mockito.mock(ZigBeeNetworkManager.class), new IeeeAddress());
    Set<RoutingTable> routes;
    RoutingTable route1 = new RoutingTable();
    route1.setDestinationAddress(12345);
    route1.setNextHopAddress(98765);
    route1.setStatus(DiscoveryState.ACTIVE);
    route1.setRouteRecordRequired(false);
    RoutingTable route2 = new RoutingTable();
    route2.setDestinationAddress(12345);
    route2.setNextHopAddress(98765);
    route2.setStatus(DiscoveryState.ACTIVE);
    route2.setRouteRecordRequired(false);
    RoutingTable route3 = new RoutingTable();
    route3.setDestinationAddress(12345);
    route3.setNextHopAddress(98765);
    route3.setStatus(DiscoveryState.INACTIVE);
    route3.setRouteRecordRequired(false);
    RoutingTable route4 = new RoutingTable();
    route4.setDestinationAddress(54321);
    route4.setNextHopAddress(98765);
    route4.setStatus(DiscoveryState.INACTIVE);
    route4.setRouteRecordRequired(false);
    routes = new HashSet<RoutingTable>();
    routes.add(route1);
    assertTrue(node.setRoutes(routes));
    routes = new HashSet<RoutingTable>();
    routes.add(route2);
    assertFalse(node.setRoutes(routes));
    routes = new HashSet<RoutingTable>();
    routes.add(route3);
    assertTrue(node.setRoutes(routes));
    routes = new HashSet<RoutingTable>();
    routes.add(route1);
    routes.add(route4);
    assertTrue(node.setRoutes(routes));
    assertEquals(2, node.getRoutes().size());
    assertTrue(node.setRoutes(null));
    assertEquals(0, node.getRoutes().size());
}
Also used : RoutingTable(com.zsmartsystems.zigbee.zdo.field.RoutingTable) Test(org.junit.Test)

Example 5 with RoutingTable

use of com.zsmartsystems.zigbee.zdo.field.RoutingTable in project com.zsmartsystems.zigbee by zsmartsystems.

the class ManagementRoutingResponseTest method testReceive.

@Test
public void testReceive() {
    // Short response - ie not extended
    int[] packet = getPacketData("00 00 01 00 01 2A 2F 00 35 38");
    ManagementRoutingResponse routingResponse = new ManagementRoutingResponse();
    DefaultDeserializer deserializer = new DefaultDeserializer(packet);
    ZclFieldDeserializer fieldDeserializer = new ZclFieldDeserializer(deserializer);
    routingResponse.deserialize(fieldDeserializer);
    System.out.println(routingResponse);
    assertEquals(1, (int) routingResponse.getRoutingTableEntries());
    assertEquals(0, (int) routingResponse.getStartIndex());
    List<RoutingTable> routes = routingResponse.getRoutingTableList();
    assertEquals(1, routes.size());
    assertEquals(12074, (int) routes.get(0).getDestinationAddress());
    assertEquals(14389, (int) routes.get(0).getNextHopAddress());
    assertEquals(DiscoveryState.ACTIVE, routes.get(0).getStatus());
}
Also used : RoutingTable(com.zsmartsystems.zigbee.zdo.field.RoutingTable) DefaultDeserializer(com.zsmartsystems.zigbee.serialization.DefaultDeserializer) ZclFieldDeserializer(com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer) CommandTest(com.zsmartsystems.zigbee.CommandTest) Test(org.junit.Test)

Aggregations

RoutingTable (com.zsmartsystems.zigbee.zdo.field.RoutingTable)5 ZigBeeEndpoint (com.zsmartsystems.zigbee.ZigBeeEndpoint)2 NeighborTable (com.zsmartsystems.zigbee.zdo.field.NeighborTable)2 Test (org.junit.Test)2 CommandResult (com.zsmartsystems.zigbee.CommandResult)1 CommandTest (com.zsmartsystems.zigbee.CommandTest)1 ExtendedPanId (com.zsmartsystems.zigbee.ExtendedPanId)1 IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)1 ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)1 ZigBeeNode (com.zsmartsystems.zigbee.ZigBeeNode)1 DefaultDeserializer (com.zsmartsystems.zigbee.serialization.DefaultDeserializer)1 ZclFieldDeserializer (com.zsmartsystems.zigbee.zcl.ZclFieldDeserializer)1 ByteArray (com.zsmartsystems.zigbee.zcl.field.ByteArray)1 ManagementRoutingRequest (com.zsmartsystems.zigbee.zdo.command.ManagementRoutingRequest)1 ManagementRoutingResponse (com.zsmartsystems.zigbee.zdo.command.ManagementRoutingResponse)1 BindingTable (com.zsmartsystems.zigbee.zdo.field.BindingTable)1 NodeDescriptor (com.zsmartsystems.zigbee.zdo.field.NodeDescriptor)1 PowerDescriptor (com.zsmartsystems.zigbee.zdo.field.PowerDescriptor)1 SimpleDescriptor (com.zsmartsystems.zigbee.zdo.field.SimpleDescriptor)1 ArrayList (java.util.ArrayList)1