Added Zigbee attribute listener
This commit is contained in:
parent
1adaf8bc46
commit
3a49b15dea
11 changed files with 530 additions and 81 deletions
|
|
@ -27,87 +27,122 @@ package se.hal.plugin.zigbee;
|
|||
import com.zsmartsystems.zigbee.ZigBeeEndpoint;
|
||||
import com.zsmartsystems.zigbee.ZigBeeNetworkManager;
|
||||
import com.zsmartsystems.zigbee.ZigBeeNode;
|
||||
import com.zsmartsystems.zigbee.zcl.ZclAttribute;
|
||||
import com.zsmartsystems.zigbee.zcl.ZclCluster;
|
||||
import zutil.log.CompactLogFormatter;
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Scanner;
|
||||
import java.util.logging.Level;
|
||||
|
||||
|
||||
public class HalZigbeeControllerTest {
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
public static void main(String[] args) throws IOException, InterruptedException {
|
||||
LogUtil.readConfiguration("logging.properties");
|
||||
LogUtil.setGlobalFormatter(new CompactLogFormatter());
|
||||
LogUtil.setGlobalLevel(Level.ALL);
|
||||
|
||||
HalZigbeeController controller = new HalZigbeeController();
|
||||
controller.initialize("COM3", HalZigbeeController.ZIGBEE_DONGLE_CC2531);
|
||||
controller.initialize("COM5", HalZigbeeController.ZIGBEE_DONGLE_CC2531);
|
||||
|
||||
handleConsoleInput('h', controller.networkManager);
|
||||
Scanner in = new Scanner(System.in);
|
||||
handleConsoleInput("h", in, controller.networkManager);
|
||||
|
||||
while (true) {
|
||||
char input = waitForInout();
|
||||
handleConsoleInput(input, controller.networkManager);
|
||||
System.out.print("");
|
||||
System.out.print("Input command and finish with ENTER: ");
|
||||
|
||||
if (input == 'q') break;
|
||||
while (!in.hasNext()) { Thread.sleep(200); }
|
||||
|
||||
String command = in.next().trim();
|
||||
handleConsoleInput(command, in, controller.networkManager);
|
||||
in.nextLine(); // read in the rest of the input line
|
||||
|
||||
if (command.equals("q")) break;
|
||||
}
|
||||
|
||||
controller.close();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
|
||||
private static void handleConsoleInput(char input, ZigBeeNetworkManager networkManager) {
|
||||
switch (input) {
|
||||
case 'i':
|
||||
private static void handleConsoleInput(String command, Scanner in, ZigBeeNetworkManager networkManager) {
|
||||
switch (command) {
|
||||
case "i":
|
||||
System.out.println("PAN ID = " + networkManager.getZigBeePanId());
|
||||
System.out.println("Extended PAN ID = " + networkManager.getZigBeeExtendedPanId());
|
||||
System.out.println("Channel = " + networkManager.getZigBeeChannel());
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
case "l":
|
||||
System.out.println("-----------------------------------------------------------------------");
|
||||
for (ZigBeeNode node : networkManager.getNodes()) {
|
||||
System.out.println(node + " (" + node.getNodeState() + ")");
|
||||
System.out.println("[node id: " + node.getNetworkAddress() + "] " + node + " (" + node.getNodeState() + ")");
|
||||
|
||||
for (ZigBeeEndpoint endpoint : node.getEndpoints()) {
|
||||
System.out.println(" - " + endpoint);
|
||||
System.out.println(" - [endpoint id: " + endpoint.getDeviceId() + "] " + endpoint);
|
||||
System.out.println(" - Input Clusters:");
|
||||
|
||||
for (int inputClusterId : endpoint.getInputClusterIds()) {
|
||||
ZclCluster cluster = endpoint.getInputCluster(inputClusterId);
|
||||
System.out.println(" - [cluster id: " + inputClusterId + "] " + cluster);
|
||||
|
||||
if (cluster != null) {
|
||||
for (ZclAttribute attr : cluster.getAttributes()) {
|
||||
System.out.println(" - [attr id: " + attr.getId() + "] " + attr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(" - Output Clusters:");
|
||||
|
||||
for (int outputClusterId : endpoint.getOutputClusterIds()) {
|
||||
ZclCluster cluster = endpoint.getInputCluster(outputClusterId);
|
||||
System.out.println(" - [cluster id: " + outputClusterId + "] " + endpoint);
|
||||
|
||||
if (cluster != null) {
|
||||
for (ZclAttribute attr : cluster.getAttributes()) {
|
||||
System.out.println(" - [attr id: " + attr.getId() + "] " + attr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(" Number of Endpoints: " + node.getEndpoints().size());
|
||||
System.out.println();
|
||||
}
|
||||
System.out.println("--------------------------");
|
||||
System.out.println("Number of ZigBee Nodes: " + networkManager.getNodes().size());
|
||||
System.out.println("-----------------------------------------------------------------------");
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
case "a":
|
||||
ZigBeeNode node = networkManager.getNode(in.nextInt());
|
||||
ZigBeeEndpoint endpoint = node.getEndpoint(in.nextInt());
|
||||
System.out.println(" - [id: " + endpoint.getDeviceId() + "]" + endpoint);
|
||||
break;
|
||||
|
||||
case "p":
|
||||
System.out.println("Enabling pairing.");
|
||||
networkManager.permitJoin(200);
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
case "q":
|
||||
System.out.println("Shutting down.");
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
case "h":
|
||||
default:
|
||||
System.out.println("Available commands:");
|
||||
System.out.println(" i: List network info");
|
||||
System.out.println(" l: List available ZigBee Nodes");
|
||||
System.out.println(" a <node id> <endpoint id> <attribute id>: read attribute");
|
||||
System.out.println(" p: Enable pairing of ZigBee devices");
|
||||
System.out.println(" q: Quit");
|
||||
System.out.println(" h: Help text");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static char waitForInout() throws IOException {
|
||||
System.out.print("");
|
||||
System.out.print("Input command and finish with ENTER: ");
|
||||
|
||||
while (true) {
|
||||
char input=(char)System.in.read();
|
||||
if (input != '\n')
|
||||
return input;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue