Search in sources :

Example 6 with ZigBeeNode

use of com.zsmartsystems.zigbee.ZigBeeNode in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeConsoleNetworkLeaveCommand method process.

@Override
public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out) throws IllegalArgumentException {
    if (args.length > 3) {
        throw new IllegalArgumentException("Invalid number of arguments");
    }
    ZigBeeNode leaver = getNode(networkManager, args[1]);
    if (args.length == 2) {
        networkManager.leave(leaver.getNetworkAddress(), leaver.getIeeeAddress());
        return;
    }
    if (args.length == 3) {
        ZigBeeNode parent = getNode(networkManager, args[2]);
        networkManager.leave(parent.getNetworkAddress(), leaver.getIeeeAddress());
        return;
    }
}
Also used : ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode)

Example 7 with ZigBeeNode

use of com.zsmartsystems.zigbee.ZigBeeNode in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeConsoleNodeListCommand method process.

@Override
public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out) throws IllegalArgumentException {
    final Set<ZigBeeNode> nodes = networkManager.getNodes();
    final List<Integer> nodeIds = new ArrayList<Integer>();
    for (ZigBeeNode node : nodes) {
        nodeIds.add(node.getNetworkAddress());
    }
    Collections.sort(nodeIds);
    out.println("Network Addr  IEEE Address      Device Type  EP   Profile");
    for (Integer nodeId : nodeIds) {
        ZigBeeNode node = networkManager.getNode(nodeId);
        out.print(String.format("%-6d  %04X  %s  %-11s", node.getNetworkAddress(), node.getNetworkAddress(), node.getIeeeAddress(), node.getLogicalType()));
        List<Integer> endpointIds = new ArrayList<Integer>();
        for (final ZigBeeEndpoint endpoint : node.getEndpoints()) {
            endpointIds.add(endpoint.getEndpointId());
        }
        Collections.sort(endpointIds);
        boolean first = true;
        for (Integer endpointId : endpointIds) {
            if (!first) {
                out.print("                                             ");
            }
            first = false;
            ZigBeeEndpoint endpoint = node.getEndpoint(endpointId);
            out.println(String.format("%-3d  %s", endpoint.getEndpointId(), ZigBeeProfileType.getProfileType(endpoint.getProfileId())));
        }
        if (first) {
            out.println();
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint)

Example 8 with ZigBeeNode

use of com.zsmartsystems.zigbee.ZigBeeNode 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 9 with ZigBeeNode

use of com.zsmartsystems.zigbee.ZigBeeNode in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeConsoleNetworkJoinCommand method process.

@Override
public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out) throws IllegalArgumentException {
    if (args.length < 2 | args.length > 3) {
        throw new IllegalArgumentException("Invalid number of arguments");
    }
    final int join;
    if ("enable".equalsIgnoreCase(args[1])) {
        join = 255;
    } else if ("disable".equalsIgnoreCase(args[1])) {
        join = 0;
    } else {
        join = Integer.parseInt(args[1]);
    }
    if (args.length == 3) {
        // Node defined
        ZigBeeNode node = getNode(networkManager, args[2]);
        node.permitJoin(join);
        if (join != 0) {
            out.println("Permit join enable node " + node.getNetworkAddress() + " success.");
        } else {
            out.println("Permit join disable " + node.getNetworkAddress() + " success.");
        }
    } else {
        networkManager.permitJoin(join);
        if (join != 0) {
            out.println("Permit join enable broadcast success.");
        } else {
            out.println("Permit join disable broadcast success.");
        }
    }
}
Also used : ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode)

Example 10 with ZigBeeNode

use of com.zsmartsystems.zigbee.ZigBeeNode in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeNodeDaoTest method testSerialize.

@Test
public void testSerialize() {
    ZigBeeTransportTransmit mockedTransport = Mockito.mock(ZigBeeTransportTransmit.class);
    ZigBeeNetworkManager networkManager = new ZigBeeNetworkManager(mockedTransport);
    ZigBeeNode node = new ZigBeeNode(networkManager, new IeeeAddress("1234567890ABCDEF"));
    node.setNetworkAddress(12345);
    ZigBeeEndpoint endpoint;
    endpoint = new ZigBeeEndpoint(networkManager, node, 1);
    endpoint.setProfileId(123);
    node.addEndpoint(endpoint);
    endpoint = new ZigBeeEndpoint(networkManager, node, 2);
    endpoint.setProfileId(321);
    node.addEndpoint(endpoint);
/*
         * ZigBeeNodeDao nodeDao = ZigBeeNodeDao.createFromZigBeeNode(node);
         * assertEquals(new IeeeAddress("1234567890ABCDEF").toString(), nodeDao.getIeeeAddress());
         * assertEquals(Integer.valueOf(12345), nodeDao.getNetworkAddress());
         * 
         * node = ZigBeeNodeDao.createFromZigBeeDao(networkManager, nodeDao);
         * assertEquals(new IeeeAddress("1234567890ABCDEF"), node.getIeeeAddress());
         * assertEquals(Integer.valueOf(12345), node.getNetworkAddress());
         * assertEquals(2, node.getEndpoints().size());
         * 
         * endpoint = node.getEndpoint(1);
         * assertEquals(123, endpoint.getProfileId());
         */
}
Also used : ZigBeeTransportTransmit(com.zsmartsystems.zigbee.transport.ZigBeeTransportTransmit) ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) ZigBeeNetworkManager(com.zsmartsystems.zigbee.ZigBeeNetworkManager) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) Test(org.junit.Test)

Aggregations

ZigBeeNode (com.zsmartsystems.zigbee.ZigBeeNode)19 IeeeAddress (com.zsmartsystems.zigbee.IeeeAddress)12 ZigBeeEndpoint (com.zsmartsystems.zigbee.ZigBeeEndpoint)12 Test (org.junit.Test)11 ZclOnOffCluster (com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster)7 ArrayList (java.util.ArrayList)6 ZigBeeCommand (com.zsmartsystems.zigbee.ZigBeeCommand)5 ZigBeeEndpointAddress (com.zsmartsystems.zigbee.ZigBeeEndpointAddress)4 XStream (com.thoughtworks.xstream.XStream)2 ZigBeeNetworkManager (com.zsmartsystems.zigbee.ZigBeeNetworkManager)2 ZigBeeNodeDao (com.zsmartsystems.zigbee.dao.ZigBeeNodeDao)2 NodeDescriptor (com.zsmartsystems.zigbee.zdo.field.NodeDescriptor)2 File (java.io.File)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 PrettyPrintWriter (com.thoughtworks.xstream.io.xml.PrettyPrintWriter)1 ZigBeeOtaFile (com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaFile)1 ZigBeeOtaServer (com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaServer)1 ZigBeeOtaServerStatus (com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaServerStatus)1 ZigBeeOtaStatusCallback (com.zsmartsystems.zigbee.app.otaserver.ZigBeeOtaStatusCallback)1