Search in sources :

Example 1 with ZigBeeNode

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

the class ZclClusterTest method unbind.

@Test
public void unbind() {
    createNetworkManager();
    ZigBeeNode node = new ZigBeeNode(networkManager, new IeeeAddress());
    node.setNetworkAddress(1234);
    ZigBeeEndpoint device = new ZigBeeEndpoint(networkManager, node, 5);
    ZclCluster cluster = new ZclOnOffCluster(networkManager, device);
    cluster.unbind(new IeeeAddress("1234567890ABCDEF"), 11);
    assertEquals(1, commandCapture.getAllValues().size());
    ZigBeeCommand command = commandCapture.getValue();
    assertNotNull(command);
    System.out.println(command);
    assertTrue(command instanceof UnbindRequest);
    UnbindRequest unbindCommand = (UnbindRequest) command;
    assertEquals(new ZigBeeEndpointAddress(1234, 0), unbindCommand.getDestinationAddress());
    assertEquals(new IeeeAddress("1234567890ABCDEF"), unbindCommand.getDstAddress());
    assertEquals(Integer.valueOf(5), unbindCommand.getSrcEndpoint());
    assertEquals(Integer.valueOf(11), unbindCommand.getDstEndpoint());
    assertEquals(Integer.valueOf(3), unbindCommand.getDstAddrMode());
    assertEquals(Integer.valueOf(0x0022), unbindCommand.getClusterId());
    assertEquals(Integer.valueOf(6), unbindCommand.getBindCluster());
}
Also used : ZclOnOffCluster(com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster) ZigBeeCommand(com.zsmartsystems.zigbee.ZigBeeCommand) ZigBeeEndpointAddress(com.zsmartsystems.zigbee.ZigBeeEndpointAddress) ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) UnbindRequest(com.zsmartsystems.zigbee.zdo.command.UnbindRequest) Test(org.junit.Test)

Example 2 with ZigBeeNode

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

the class ZclClusterTest method getReporting.

@Test
public void getReporting() {
    createNetworkManager();
    ZigBeeNode node = new ZigBeeNode(networkManager, new IeeeAddress());
    node.setNetworkAddress(1234);
    ZigBeeEndpoint device = new ZigBeeEndpoint(networkManager, node, 5);
    ZclCluster cluster = new ZclOnOffCluster(networkManager, device);
    ZclAttribute attribute = cluster.getAttribute(0);
    cluster.getReporting(attribute);
    assertEquals(1, commandCapture.getAllValues().size());
    ZigBeeCommand command = commandCapture.getValue();
    assertNotNull(command);
    System.out.println(command);
    assertTrue(command instanceof ReadReportingConfigurationCommand);
    ReadReportingConfigurationCommand cfgCommand = (ReadReportingConfigurationCommand) command;
    assertEquals(1, cfgCommand.getRecords().size());
    AttributeRecord record = cfgCommand.getRecords().get(0);
    assertEquals(0, record.getAttributeIdentifier());
    assertEquals(0, record.getDirection());
}
Also used : ZclOnOffCluster(com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster) ZigBeeCommand(com.zsmartsystems.zigbee.ZigBeeCommand) AttributeRecord(com.zsmartsystems.zigbee.zcl.field.AttributeRecord) ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) ReadReportingConfigurationCommand(com.zsmartsystems.zigbee.zcl.clusters.general.ReadReportingConfigurationCommand) Test(org.junit.Test)

Example 3 with ZigBeeNode

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

the class ZigBeeNetworkStateSerializerImpl method deserialize.

/**
 * Deserializes the network state.
 *
 * @param networkState the network state
 */
@Override
public void deserialize(final ZigBeeNetworkManager networkState) {
    final File file = new File(networkId);
    boolean networkStateExists = file.exists();
    if (networkStateExists == false) {
        return;
    }
    logger.info("Loading network state...");
    try {
        XStream stream = openStream();
        BufferedReader reader;
        reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
        final List<Object> objects = (List<Object>) stream.fromXML(reader);
        for (final Object object : objects) {
            if (object instanceof ZigBeeNodeDao) {
                ZigBeeNodeDao nodeDao = (ZigBeeNodeDao) object;
                ZigBeeNode node = new ZigBeeNode(networkState, new IeeeAddress(nodeDao.getIeeeAddress()));
                node.setDao(nodeDao);
                networkState.addNode(node);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    logger.info("Loading network state complete.");
}
Also used : InputStreamReader(java.io.InputStreamReader) XStream(com.thoughtworks.xstream.XStream) ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) IeeeAddress(com.zsmartsystems.zigbee.IeeeAddress) ZigBeeNodeDao(com.zsmartsystems.zigbee.dao.ZigBeeNodeDao) BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Example 4 with ZigBeeNode

use of com.zsmartsystems.zigbee.ZigBeeNode 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())));
    }
}
Also used : BindingTable(com.zsmartsystems.zigbee.zdo.field.BindingTable) ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode)

Example 5 with ZigBeeNode

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

the class ZigBeeNetworkStateSerializerImpl method serialize.

/**
 * Serializes the network state.
 *
 * @param networkState the network state
 */
@Override
public void serialize(final ZigBeeNetworkManager networkState) {
    XStream stream = openStream();
    final List<ZigBeeNodeDao> destinations = new ArrayList<ZigBeeNodeDao>();
    for (ZigBeeNode node : networkState.getNodes()) {
        ZigBeeNodeDao nodeDao = node.getDao();
        destinations.add(nodeDao);
    }
    final File file = new File(networkId);
    try {
        BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
        stream.marshal(destinations, new PrettyPrintWriter(writer));
        writer.flush();
        writer.close();
    } catch (IOException e) {
        logger.error("Error writing network state", e);
    }
    logger.info("ZigBee saving network state complete.");
}
Also used : ZigBeeNodeDao(com.zsmartsystems.zigbee.dao.ZigBeeNodeDao) XStream(com.thoughtworks.xstream.XStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) ZigBeeNode(com.zsmartsystems.zigbee.ZigBeeNode) OutputStreamWriter(java.io.OutputStreamWriter) PrettyPrintWriter(com.thoughtworks.xstream.io.xml.PrettyPrintWriter) IOException(java.io.IOException) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

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