Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zstack driver #1280

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
24 changes: 24 additions & 0 deletions com.zsmartsystems.zigbee.console.main/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
<version>1.4.3-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>com.zsmartsystems.zigbee</groupId>
<artifactId>com.zsmartsystems.zigbee.dongle.zstack</artifactId>
<version>1.4.3-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>com.zsmartsystems.zigbee</groupId>
<artifactId>com.zsmartsystems.zigbee.dongle.xbee</artifactId>
Expand Down Expand Up @@ -74,6 +80,24 @@
<version>1.4.3-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>com.zsmartsystems.zigbee</groupId>
<artifactId>com.zsmartsystems.zigbee.console.zstack</artifactId>
<version>1.4.3-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>

<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>

<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,17 @@
import com.zsmartsystems.zigbee.console.ember.EmberConsoleSecurityStateCommand;
import com.zsmartsystems.zigbee.console.ember.EmberConsoleTransientKeyCommand;
import com.zsmartsystems.zigbee.console.telegesis.TelegesisConsoleSecurityStateCommand;
import com.zsmartsystems.zigbee.console.zstack.ZstackConsoleNcpDiagnosticsCommand;
import com.zsmartsystems.zigbee.console.zstack.ZstackConsoleNcpSecurityCommand;
import com.zsmartsystems.zigbee.console.zstack.ZstackConsoleNcpStateCommand;
import com.zsmartsystems.zigbee.database.ZigBeeNetworkDataStore;
import com.zsmartsystems.zigbee.dongle.cc2531.ZigBeeDongleTiCc2531;
import com.zsmartsystems.zigbee.dongle.conbee.ZigBeeDongleConBee;
import com.zsmartsystems.zigbee.dongle.ember.ZigBeeDongleEzsp;
import com.zsmartsystems.zigbee.dongle.ember.ezsp.structure.EzspConfigId;
import com.zsmartsystems.zigbee.dongle.telegesis.ZigBeeDongleTelegesis;
import com.zsmartsystems.zigbee.dongle.xbee.ZigBeeDongleXBee;
import com.zsmartsystems.zigbee.dongle.zstack.ZigBeeDongleZstack;
import com.zsmartsystems.zigbee.security.ZigBeeKey;
import com.zsmartsystems.zigbee.serial.ZigBeeSerialPort;
import com.zsmartsystems.zigbee.serialization.DefaultDeserializer;
Expand Down Expand Up @@ -134,11 +138,12 @@ public static void main(final String[] args) {

Options options = new Options();
options.addOption(Option.builder("d").longOpt("dongle").hasArg().argName("dongle type")
.desc("Set the dongle type to use (EMBER | CC2531 | TELEGESIS | CONBEE | XBEE)").required().build());
.desc("Set the dongle type to use (EMBER | CC2531 | ZSTACK | TELEGESIS | CONBEE | XBEE)").required()
.build());
options.addOption(Option.builder("p").longOpt("port").argName("port name").hasArg().desc("Set the port")
.required().build());
options.addOption(
Option.builder("b").longOpt("baud").hasArg().argName("baud").desc("Set the port baud rate").build());
Option.builder("b").longOpt("baud").hasArg().argName("baud").desc("Set the port baud rate").required().build());
options.addOption(Option.builder("f").longOpt("flow").hasArg().argName("type")
.desc("Set the flow control (none | hardware | software)").build());
options.addOption(Option.builder("c").longOpt("channel").hasArg().argName("channel id")
Expand Down Expand Up @@ -234,6 +239,13 @@ public static void main(final String[] args) {
if (dongleName.toUpperCase().equals("CC2531")) {
dongle = new ZigBeeDongleTiCc2531(serialPort);
transportOptions.addOption(TransportConfigOption.RADIO_TX_POWER, 3);
} else if (dongleName.toUpperCase().equals("ZSTACK")) {
dongle = new ZigBeeDongleZstack(serialPort);
transportOptions.addOption(TransportConfigOption.RADIO_TX_POWER, 3);

commands.add(ZstackConsoleNcpStateCommand.class);
commands.add(ZstackConsoleNcpSecurityCommand.class);
commands.add(ZstackConsoleNcpDiagnosticsCommand.class);
} else if (dongleName.toUpperCase().equals("EMBER")) {
ZigBeeDongleEzsp emberDongle = new ZigBeeDongleEzsp(serialPort);
dongle = emberDongle;
Expand Down Expand Up @@ -413,12 +425,20 @@ public static void main(final String[] args) {
System.out.println("ZigBee console starting up ... [OK]");
}

if (dongleName.toUpperCase().equals("CC2531")) {
networkManager.addSupportedCluster(ZclIasZoneCluster.CLUSTER_ID);

if (dongleName.equalsIgnoreCase("CC2531")) {
ZigBeeDongleTiCc2531 tiDongle = (ZigBeeDongleTiCc2531) dongle;
tiDongle.setLedMode(1, false);
tiDongle.setLedMode(2, false);
}

if (dongleName.equalsIgnoreCase("ZSTACK")) {
// Required to allow HA1.2 devices to join the ZB3.0 compatible coordinator
ZigBeeDongleZstack zstackDongle = (ZigBeeDongleZstack) dongle;
zstackDongle.requireKeyExchange(false);
}

console.start();

System.out.println("Console closed.");
Expand Down
23 changes: 23 additions & 0 deletions com.zsmartsystems.zigbee.console.zstack/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.zsmartsystems.zigbee.console.zstack</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
7 changes: 7 additions & 0 deletions com.zsmartsystems.zigbee.console.zstack/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
group = 'com.zsmartsystems.zigbee'
description = ''
dependencies {
compile project(':com.zsmartsystems.zigbee')
compile project(':com.zsmartsystems.zigbee.console')
compile project(':com.zsmartsystems.zigbee.dongle.zstack’)
}
38 changes: 38 additions & 0 deletions com.zsmartsystems.zigbee.console.zstack/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.zsmartsystems.zigbee</groupId>
<artifactId>com.zsmartsystems.zigbee.console.zstack</artifactId>
<packaging>jar</packaging>

<parent>
<groupId>com.zsmartsystems</groupId>
<artifactId>zigbee</artifactId>
<version>1.4.3-SNAPSHOT</version>
</parent>

<dependencies>

<dependency>
<groupId>com.zsmartsystems.zigbee</groupId>
<artifactId>com.zsmartsystems.zigbee</artifactId>
<version>1.4.3-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>com.zsmartsystems.zigbee</groupId>
<artifactId>com.zsmartsystems.zigbee.console</artifactId>
<version>1.4.3-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>com.zsmartsystems.zigbee</groupId>
<artifactId>com.zsmartsystems.zigbee.dongle.zstack</artifactId>
<version>1.4.3-SNAPSHOT</version>
</dependency>

</dependencies>

</project>

Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* Copyright (c) 2016-2019 by the respective copyright holders.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package com.zsmartsystems.zigbee.console.zstack;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

import com.zsmartsystems.zigbee.ZigBeeNetworkManager;
import com.zsmartsystems.zigbee.console.ZigBeeConsoleCommand;
import com.zsmartsystems.zigbee.dongle.zstack.ZigBeeDongleZstack;
import com.zsmartsystems.zigbee.dongle.zstack.ZstackNcp;

/**
*
* @author Chris Jackson - Initial Contribution
*
*/
public abstract class ZstackConsoleAbstractCommand implements ZigBeeConsoleCommand {
private static String CFG_UNSUPPORTED = "Not Supported";

protected ZstackNcp getZstackNcp(ZigBeeNetworkManager networkManager)
throws IllegalArgumentException, IllegalStateException {
if (!(networkManager.getZigBeeTransport() instanceof ZigBeeDongleZstack)) {
throw new IllegalArgumentException("Dongle is not an ZStack NCP.");
}
ZigBeeDongleZstack dongle = (ZigBeeDongleZstack) networkManager.getZigBeeTransport();
if (dongle == null) {
throw new IllegalStateException("Dongle is not an ZStack NCP.");
}
return dongle.getZstackNcp();
}

protected String hex2Boolean(int[] bytes) {
if (bytes == null) {
return CFG_UNSUPPORTED;
}

return Boolean.valueOf(bytes[0] != 0).toString();
}

protected String hex2Uint8(int[] bytes) {
if (bytes == null) {
return CFG_UNSUPPORTED;
}

return Integer.valueOf(bytes[0]).toString();
}

protected String hex2Uint16(int[] bytes) {
if (bytes == null) {
return CFG_UNSUPPORTED;
}

return Integer.valueOf(bytes[0] + (bytes[1] * 256)).toString();
}

protected String hex2String(int[] bytes) {
if (bytes == null) {
return CFG_UNSUPPORTED;
}

int length = bytes.length;
byte[] output = new byte[length];

for (int cnt = 0; cnt < bytes.length; cnt++) {
output[cnt] = (byte) bytes[cnt];
if (output[cnt] == 0) {
length = cnt;
break;
}
}
try {
return new String(Arrays.copyOfRange(output, 0, length), "UTF-8");
} catch (UnsupportedEncodingException e) {
return null;
}
}

protected String hexDump(int[] bytes) {
if (bytes == null) {
return CFG_UNSUPPORTED;
}

StringBuilder builder = new StringBuilder(bytes.length * 3);

for (int value : bytes) {
builder.append(String.format("%02X ", value));
}

return builder.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Copyright (c) 2016-2019 by the respective copyright holders.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package com.zsmartsystems.zigbee.console.zstack;

import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import com.zsmartsystems.zigbee.ZigBeeNetworkManager;
import com.zsmartsystems.zigbee.dongle.zstack.ZstackNcp;
import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackDiagnosticAttribute;

/**
*
* @author Chris Jackson
*
*/
public class ZstackConsoleNcpDiagnosticsCommand extends ZstackConsoleAbstractCommand {
@Override
public String getCommand() {
return "ncpdiags";
}

@Override
public String getDescription() {
return "Gets the NCP diagnostics counters.";
}

@Override
public String getSyntax() {
return "";
}

@Override
public String getHelp() {
return "";
}

@Override
public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out)
throws IllegalArgumentException {
ZstackNcp ncp = getZstackNcp(networkManager);
Map<ZstackDiagnosticAttribute, Long> diagnostics = new HashMap<>();

for (ZstackDiagnosticAttribute attribute : ZstackDiagnosticAttribute.values()) {
if (attribute == ZstackDiagnosticAttribute.UNKNOWN) {
continue;
}

Long value = ncp.getDiagnosticsAttribute(attribute);

if (value == null) {
continue;
}
diagnostics.put(attribute, value);
}

for (Entry<ZstackDiagnosticAttribute, Long> diagnosticsEntry : diagnostics.entrySet()) {
out.println(String.format("%-40s %d", diagnosticsEntry.getKey(), diagnosticsEntry.getValue()));
}
}

}
Loading