Search in sources :

Example 1 with ZclBasicCluster

use of com.zsmartsystems.zigbee.zcl.clusters.ZclBasicCluster in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeConsoleDeviceInformationCommand 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");
    }
    Map<String, String> commands = new TreeMap<>();
    long refresh = Long.MAX_VALUE;
    for (int cnt = 2; cnt < args.length; cnt++) {
        String arg = args[cnt];
        String upperArg = arg.toUpperCase();
        if ("REFRESH".equals(upperArg)) {
            refresh = 0;
            continue;
        }
        commands.put(upperArg, "");
    }
    if (commands.isEmpty()) {
        commands.put("MANUFACTURER", "");
        commands.put("MODEL", "");
        commands.put("APPVERSION", "");
        commands.put("STKVERSION", "");
        commands.put("ZCLVERSION", "");
        commands.put("HWVERSION", "");
        commands.put("DATE", "");
    }
    final ZigBeeEndpoint endpoint = getEndpoint(networkManager, args[1]);
    if (endpoint == null) {
        throw new IllegalArgumentException("Endpoint '" + args[1] + "' not found.");
    }
    ZclBasicCluster basicCluster = (ZclBasicCluster) endpoint.getInputCluster(0);
    if (basicCluster == null) {
        throw new IllegalArgumentException("Can't find basic cluster for " + endpoint.getEndpointAddress());
    }
    for (String command : commands.keySet()) {
        out.println("Requesting " + command);
        Object response = null;
        switch(command) {
            case "MANUFACTURER":
                response = basicCluster.getManufacturerName(refresh);
                break;
            case "MODEL":
                response = basicCluster.getModelIdentifier(refresh);
                break;
            case "APPVERSION":
                response = basicCluster.getApplicationVersion(refresh);
                break;
            case "STKVERSION":
                response = basicCluster.getStackVersion(refresh);
                break;
            case "ZCLVERSION":
                response = basicCluster.getZclVersion(refresh);
                break;
            case "HWVERSION":
                response = basicCluster.getHwVersion(refresh);
                break;
            case "DATE":
                response = basicCluster.getDateCode(refresh);
                break;
            default:
                out.println("Unknown info type: " + command);
                break;
        }
        if (response != null) {
            commands.put(command, response.toString());
        }
    }
    out.println("Node Info     Value");
    for (Entry<String, String> command : commands.entrySet()) {
        out.println(String.format("%-12s  ", command.getKey()) + command.getValue());
    }
}
Also used : ZclBasicCluster(com.zsmartsystems.zigbee.zcl.clusters.ZclBasicCluster) TreeMap(java.util.TreeMap) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint) ZigBeeEndpoint(com.zsmartsystems.zigbee.ZigBeeEndpoint)

Aggregations

ZigBeeEndpoint (com.zsmartsystems.zigbee.ZigBeeEndpoint)1 ZclBasicCluster (com.zsmartsystems.zigbee.zcl.clusters.ZclBasicCluster)1 TreeMap (java.util.TreeMap)1