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());
}
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());
}
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.");
}
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())));
}
}
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.");
}
Aggregations