Search in sources :

Example 1 with ZigBeeDongleTiCc2531

use of com.zsmartsystems.zigbee.dongle.cc2531.ZigBeeDongleTiCc2531 in project com.zsmartsystems.zigbee by zsmartsystems.

the class ZigBeeConsoleMain method main.

/**
 * The main method.
 *
 * @param args the command arguments
 */
public static void main(final String[] args) {
    DOMConfigurator.configure("./log4j.xml");
    final String serialPortName;
    final String dongleName;
    final int serialBaud;
    final int channel;
    final int pan;
    final ExtendedPanId extendedPan;
    final int[] networkKey;
    final TransportConfig transportOptions = new TransportConfig();
    boolean resetNetwork;
    try {
        dongleName = args[0];
        serialPortName = args[1];
        serialBaud = Integer.parseInt(args[2]);
        channel = Integer.parseInt(args[3]);
        pan = parseDecimalOrHexInt(args[4]);
        extendedPan = new ExtendedPanId(args[5]);
        if (args[6].equals("00000000000000000000000000000000")) {
            logger.info("ZigBee network key left as default according to command argument.");
            networkKey = null;
        } else {
            logger.info("ZigBee network key defined by command argument.");
            byte[] key = Hex.decode(args[6]);
            networkKey = new int[16];
            int cnt = 0;
            for (byte value : key) {
                networkKey[cnt++] = value & 0xff;
            }
        }
        if (networkKey != null && networkKey.length != 16) {
            logger.warn("ZigBee network key length should be 16 bytes.");
            return;
        }
        resetNetwork = args[7].equals("true");
    } catch (final Throwable t) {
        t.printStackTrace();
        System.out.println(USAGE);
        return;
    }
    FlowControl flowControl = FlowControl.FLOWCONTROL_OUT_NONE;
    if (dongleName.toUpperCase().equals("EMBER")) {
        flowControl = FlowControl.FLOWCONTROL_OUT_RTSCTS;
    }
    final ZigBeePort serialPort = new ZigBeeSerialPort(serialPortName, serialBaud, flowControl);
    System.out.println("Initialising ZigBee console...");
    List<Class<? extends ZigBeeConsoleCommand>> commands = new ArrayList<>();
    final ZigBeeTransportTransmit dongle;
    if (dongleName.toUpperCase().equals("CC2531")) {
        dongle = new ZigBeeDongleTiCc2531(serialPort);
    } else if (dongleName.toUpperCase().equals("EMBER")) {
        dongle = new ZigBeeDongleEzsp(serialPort);
        // Configure the concentrator
        // Max Hops defaults to system max
        ConcentratorConfig concentratorConfig = new ConcentratorConfig();
        concentratorConfig.setType(ConcentratorType.LOW_RAM);
        concentratorConfig.setMaxFailures(8);
        concentratorConfig.setMaxHops(0);
        concentratorConfig.setRefreshMinimum(60);
        concentratorConfig.setRefreshMaximum(3600);
        transportOptions.addOption(TransportConfigOption.CONCENTRATOR_CONFIG, concentratorConfig);
        // Add transport specific console commands
        commands.add(EmberConsoleNcpChildrenCommand.class);
        commands.add(EmberConsoleNcpCountersCommand.class);
        commands.add(EmberConsoleNcpStateCommand.class);
        commands.add(EmberConsoleNcpVersionCommand.class);
        commands.add(EmberConsoleNetworkStateCommand.class);
        commands.add(EmberConsoleSecurityStateCommand.class);
    } else if (dongleName.toUpperCase().equals("XBEE")) {
        dongle = new ZigBeeDongleXBee(serialPort);
    } else if (dongleName.toUpperCase().equals("CONBEE")) {
        dongle = new ZigBeeDongleConBee(serialPort);
    } else if (dongleName.toUpperCase().equals("TELEGESIS")) {
        ZigBeeDongleTelegesis telegesisDongle = new ZigBeeDongleTelegesis(serialPort);
        telegesisDongle.setTelegesisPassword("password");
        dongle = telegesisDongle;
        Set<Integer> clusters = new HashSet<Integer>();
        clusters.add(ZclIasZoneCluster.CLUSTER_ID);
        transportOptions.addOption(TransportConfigOption.SUPPORTED_OUTPUT_CLUSTERS, clusters);
        commands.add(TelegesisConsoleSecurityStateCommand.class);
    } else {
        dongle = null;
    }
    if (dongle == null) {
        System.out.println("Dongle not opened.");
        System.out.println(USAGE);
        return;
    }
    ZigBeeNetworkManager networkManager = new ZigBeeNetworkManager(dongle);
    ZigBeeNetworkStateSerializer networkStateSerializer = new ZigBeeNetworkStateSerializerImpl(dongleName);
    if (resetNetwork) {
    // networkStateSerializer.remove();
    }
    networkManager.setNetworkStateSerializer(networkStateSerializer);
    networkManager.setSerializer(DefaultSerializer.class, DefaultDeserializer.class);
    final ZigBeeConsole console = new ZigBeeConsole(networkManager, dongle, commands);
    // Initialise the network
    networkManager.initialize();
    System.out.println("PAN ID          = " + networkManager.getZigBeePanId());
    System.out.println("Extended PAN ID = " + networkManager.getZigBeeExtendedPanId());
    System.out.println("Channel         = " + networkManager.getZigBeeChannel());
    if (resetNetwork == true) {
        System.out.println("*** Resetting network");
        System.out.println("  * Channel          = " + channel);
        System.out.println("  * PAN ID           = " + pan);
        System.out.println("  * Extended PAN ID  = " + extendedPan);
        networkManager.setZigBeeChannel(channel);
        networkManager.setZigBeePanId(pan);
        networkManager.setZigBeeExtendedPanId(extendedPan);
        if (networkKey != null) {
            networkManager.setZigBeeNetworkKey(new ZigBeeKey(networkKey));
        }
    }
    dongle.updateTransportConfig(transportOptions);
    if (!networkManager.startup(resetNetwork)) {
        System.out.println("ZigBee console starting up ... [FAIL]");
    // return;
    } else {
        System.out.println("ZigBee console starting up ... [OK]");
    }
    // Start the mesh monitor
    ZigBeeNetworkMeshMonitor meshMonitor = new ZigBeeNetworkMeshMonitor(networkManager);
    meshMonitor.startup(60);
    networkManager.addSupportedCluster(ZclIasZoneCluster.CLUSTER_ID);
    console.start();
    System.out.println("Console closed.");
}
Also used : ZigBeeNetworkStateSerializer(com.zsmartsystems.zigbee.ZigBeeNetworkStateSerializer) ZigBeeNetworkMeshMonitor(com.zsmartsystems.zigbee.ZigBeeNetworkMeshMonitor) ConcentratorConfig(com.zsmartsystems.zigbee.transport.ConcentratorConfig) ZigBeeConsoleCommand(com.zsmartsystems.zigbee.console.ZigBeeConsoleCommand) ArrayList(java.util.ArrayList) EmberConsoleNcpChildrenCommand(com.zsmartsystems.zigbee.console.ember.EmberConsoleNcpChildrenCommand) ZigBeeNetworkManager(com.zsmartsystems.zigbee.ZigBeeNetworkManager) ZigBeeDongleEzsp(com.zsmartsystems.zigbee.dongle.ember.ZigBeeDongleEzsp) ZigBeeDongleConBee(com.zsmartsystems.zigbee.dongle.conbee.ZigBeeDongleConBee) ZigBeeDongleTiCc2531(com.zsmartsystems.zigbee.dongle.cc2531.ZigBeeDongleTiCc2531) EmberConsoleNcpCountersCommand(com.zsmartsystems.zigbee.console.ember.EmberConsoleNcpCountersCommand) HashSet(java.util.HashSet) ZigBeeDongleXBee(com.zsmartsystems.zigbee.dongle.xbee.ZigBeeDongleXBee) ExtendedPanId(com.zsmartsystems.zigbee.ExtendedPanId) EmberConsoleNcpStateCommand(com.zsmartsystems.zigbee.console.ember.EmberConsoleNcpStateCommand) EmberConsoleNetworkStateCommand(com.zsmartsystems.zigbee.console.ember.EmberConsoleNetworkStateCommand) FlowControl(com.zsmartsystems.zigbee.transport.ZigBeePort.FlowControl) ZigBeeSerialPort(com.zsmartsystems.zigbee.serial.ZigBeeSerialPort) EmberConsoleSecurityStateCommand(com.zsmartsystems.zigbee.console.ember.EmberConsoleSecurityStateCommand) ZigBeePort(com.zsmartsystems.zigbee.transport.ZigBeePort) TransportConfig(com.zsmartsystems.zigbee.transport.TransportConfig) ZigBeeTransportTransmit(com.zsmartsystems.zigbee.transport.ZigBeeTransportTransmit) EmberConsoleNcpVersionCommand(com.zsmartsystems.zigbee.console.ember.EmberConsoleNcpVersionCommand) ZigBeeDongleTelegesis(com.zsmartsystems.zigbee.dongle.telegesis.ZigBeeDongleTelegesis) ZigBeeKey(com.zsmartsystems.zigbee.ZigBeeKey)

Aggregations

ExtendedPanId (com.zsmartsystems.zigbee.ExtendedPanId)1 ZigBeeKey (com.zsmartsystems.zigbee.ZigBeeKey)1 ZigBeeNetworkManager (com.zsmartsystems.zigbee.ZigBeeNetworkManager)1 ZigBeeNetworkMeshMonitor (com.zsmartsystems.zigbee.ZigBeeNetworkMeshMonitor)1 ZigBeeNetworkStateSerializer (com.zsmartsystems.zigbee.ZigBeeNetworkStateSerializer)1 ZigBeeConsoleCommand (com.zsmartsystems.zigbee.console.ZigBeeConsoleCommand)1 EmberConsoleNcpChildrenCommand (com.zsmartsystems.zigbee.console.ember.EmberConsoleNcpChildrenCommand)1 EmberConsoleNcpCountersCommand (com.zsmartsystems.zigbee.console.ember.EmberConsoleNcpCountersCommand)1 EmberConsoleNcpStateCommand (com.zsmartsystems.zigbee.console.ember.EmberConsoleNcpStateCommand)1 EmberConsoleNcpVersionCommand (com.zsmartsystems.zigbee.console.ember.EmberConsoleNcpVersionCommand)1 EmberConsoleNetworkStateCommand (com.zsmartsystems.zigbee.console.ember.EmberConsoleNetworkStateCommand)1 EmberConsoleSecurityStateCommand (com.zsmartsystems.zigbee.console.ember.EmberConsoleSecurityStateCommand)1 ZigBeeDongleTiCc2531 (com.zsmartsystems.zigbee.dongle.cc2531.ZigBeeDongleTiCc2531)1 ZigBeeDongleConBee (com.zsmartsystems.zigbee.dongle.conbee.ZigBeeDongleConBee)1 ZigBeeDongleEzsp (com.zsmartsystems.zigbee.dongle.ember.ZigBeeDongleEzsp)1 ZigBeeDongleTelegesis (com.zsmartsystems.zigbee.dongle.telegesis.ZigBeeDongleTelegesis)1 ZigBeeDongleXBee (com.zsmartsystems.zigbee.dongle.xbee.ZigBeeDongleXBee)1 ZigBeeSerialPort (com.zsmartsystems.zigbee.serial.ZigBeeSerialPort)1 ConcentratorConfig (com.zsmartsystems.zigbee.transport.ConcentratorConfig)1 TransportConfig (com.zsmartsystems.zigbee.transport.TransportConfig)1