Search in sources :

Example 1 with ZigBeePort

use of com.zsmartsystems.zigbee.transport.ZigBeePort in project com.zsmartsystems.zigbee by zsmartsystems.

the class TelegesisFirmwareUpdateHandlerTest method getBlPrompt.

private boolean getBlPrompt(String packet) {
    ByteArrayInputStream stream = new ByteArrayInputStream(packet.getBytes());
    ZigBeePort port = new TestPort(stream);
    TelegesisFirmwareUpdateHandler firmwareHandler = new TelegesisFirmwareUpdateHandler(null, null, port, null);
    Method privateMethod;
    try {
        privateMethod = TelegesisFirmwareUpdateHandler.class.getDeclaredMethod("getBlPrompt");
        privateMethod.setAccessible(true);
        return (boolean) privateMethod.invoke(firmwareHandler);
    } catch (NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
        e.printStackTrace();
    }
    return false;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Method(java.lang.reflect.Method) ZigBeePort(com.zsmartsystems.zigbee.transport.ZigBeePort) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with ZigBeePort

use of com.zsmartsystems.zigbee.transport.ZigBeePort in project com.zsmartsystems.zigbee by zsmartsystems.

the class TelegesisFrameHandlerTest method getPacket.

private int[] getPacket(String packet) {
    TelegesisFrameHandler frameHandler = new TelegesisFrameHandler();
    ByteArrayInputStream stream = new ByteArrayInputStream(packet.getBytes());
    ZigBeePort port = new TestPort(stream, null);
    Method privateMethod;
    try {
        Field field = frameHandler.getClass().getDeclaredField("serialPort");
        field.setAccessible(true);
        field.set(frameHandler, port);
        privateMethod = TelegesisFrameHandler.class.getDeclaredMethod("getPacket");
        privateMethod.setAccessible(true);
        return (int[]) privateMethod.invoke(frameHandler);
    } catch (NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException | InvocationTargetException | NoSuchFieldException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : Method(java.lang.reflect.Method) ZigBeePort(com.zsmartsystems.zigbee.transport.ZigBeePort) InvocationTargetException(java.lang.reflect.InvocationTargetException) Field(java.lang.reflect.Field) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 3 with ZigBeePort

use of com.zsmartsystems.zigbee.transport.ZigBeePort in project com.zsmartsystems.zigbee by zsmartsystems.

the class Cc2351TestPacket method getPacket.

protected ZToolPacket getPacket(String stringData) {
    int[] packet = getPacketData(stringData);
    byte[] byteArray = new byte[packet.length - 1];
    for (int c = 1; c < packet.length; c++) {
        byteArray[c - 1] = (byte) packet[c];
    }
    ByteArrayInputStream stream = new ByteArrayInputStream(byteArray);
    ZigBeePort port = new TestPort(stream, null);
    try {
        ZToolPacket ztoolPacket = new ZToolPacketStream(port).parsePacket();
        assertFalse(ztoolPacket.isError());
        return ztoolPacket;
    } catch (IOException e) {
        return null;
    }
}
Also used : ZToolPacket(com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacket) ZToolPacketStream(com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacketStream) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) ZigBeePort(com.zsmartsystems.zigbee.transport.ZigBeePort)

Example 4 with ZigBeePort

use of com.zsmartsystems.zigbee.transport.ZigBeePort in project com.zsmartsystems.zigbee by zsmartsystems.

the class EmberFirmwareUpdateHandlerTest method getBlPrompt.

private boolean getBlPrompt(String packet) {
    ByteArrayInputStream stream = new ByteArrayInputStream(packet.getBytes());
    ZigBeePort port = new TestPort(stream);
    EmberFirmwareUpdateHandler firmwareHandler = new EmberFirmwareUpdateHandler(null, null, port, null);
    Method privateMethod;
    try {
        privateMethod = EmberFirmwareUpdateHandler.class.getDeclaredMethod("getBlPrompt");
        privateMethod.setAccessible(true);
        return (boolean) privateMethod.invoke(firmwareHandler);
    } catch (NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
        e.printStackTrace();
    }
    return false;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Method(java.lang.reflect.Method) ZigBeePort(com.zsmartsystems.zigbee.transport.ZigBeePort) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 5 with ZigBeePort

use of com.zsmartsystems.zigbee.transport.ZigBeePort 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

ZigBeePort (com.zsmartsystems.zigbee.transport.ZigBeePort)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 Method (java.lang.reflect.Method)7 Field (java.lang.reflect.Field)3 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 ZToolPacket (com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacket)1 ZToolPacketStream (com.zsmartsystems.zigbee.dongle.cc2531.network.packet.ZToolPacketStream)1