use of com.zsmartsystems.zigbee.dongle.xbee.ZigBeeDongleXBee 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.");
}
Aggregations