diff --git a/com.zsmartsystems.zigbee.console.main/pom.xml b/com.zsmartsystems.zigbee.console.main/pom.xml index 741e963431..040b5601fd 100644 --- a/com.zsmartsystems.zigbee.console.main/pom.xml +++ b/com.zsmartsystems.zigbee.console.main/pom.xml @@ -32,6 +32,12 @@ 1.4.3-SNAPSHOT + + com.zsmartsystems.zigbee + com.zsmartsystems.zigbee.dongle.zstack + 1.4.3-SNAPSHOT + + com.zsmartsystems.zigbee com.zsmartsystems.zigbee.dongle.xbee @@ -74,6 +80,24 @@ 1.4.3-SNAPSHOT + + com.zsmartsystems.zigbee + com.zsmartsystems.zigbee.console.zstack + 1.4.3-SNAPSHOT + + + + commons-lang + commons-lang + 2.6 + + + + commons-io + commons-io + 2.4 + + commons-cli commons-cli diff --git a/com.zsmartsystems.zigbee.console.main/src/main/java/com/zsmartsystems/zigbee/console/main/ZigBeeConsoleMain.java b/com.zsmartsystems.zigbee.console.main/src/main/java/com/zsmartsystems/zigbee/console/main/ZigBeeConsoleMain.java index 7c8c138640..5fe70d6f4c 100644 --- a/com.zsmartsystems.zigbee.console.main/src/main/java/com/zsmartsystems/zigbee/console/main/ZigBeeConsoleMain.java +++ b/com.zsmartsystems.zigbee.console.main/src/main/java/com/zsmartsystems/zigbee/console/main/ZigBeeConsoleMain.java @@ -51,6 +51,9 @@ 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; @@ -58,6 +61,7 @@ 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; @@ -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") @@ -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; @@ -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."); diff --git a/com.zsmartsystems.zigbee.console.zstack/.project b/com.zsmartsystems.zigbee.console.zstack/.project new file mode 100644 index 0000000000..5d70aa078c --- /dev/null +++ b/com.zsmartsystems.zigbee.console.zstack/.project @@ -0,0 +1,23 @@ + + + com.zsmartsystems.zigbee.console.zstack + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/com.zsmartsystems.zigbee.console.zstack/build.gradle b/com.zsmartsystems.zigbee.console.zstack/build.gradle new file mode 100644 index 0000000000..230a086c44 --- /dev/null +++ b/com.zsmartsystems.zigbee.console.zstack/build.gradle @@ -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’) +} \ No newline at end of file diff --git a/com.zsmartsystems.zigbee.console.zstack/pom.xml b/com.zsmartsystems.zigbee.console.zstack/pom.xml new file mode 100644 index 0000000000..63accd1916 --- /dev/null +++ b/com.zsmartsystems.zigbee.console.zstack/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + + com.zsmartsystems.zigbee + com.zsmartsystems.zigbee.console.zstack + jar + + + com.zsmartsystems + zigbee + 1.4.3-SNAPSHOT + + + + + + com.zsmartsystems.zigbee + com.zsmartsystems.zigbee + 1.4.3-SNAPSHOT + + + + com.zsmartsystems.zigbee + com.zsmartsystems.zigbee.console + 1.4.3-SNAPSHOT + + + + com.zsmartsystems.zigbee + com.zsmartsystems.zigbee.dongle.zstack + 1.4.3-SNAPSHOT + + + + + + diff --git a/com.zsmartsystems.zigbee.console.zstack/src/main/java/com/zsmartsystems/zigbee/console/zstack/ZstackConsoleAbstractCommand.java b/com.zsmartsystems.zigbee.console.zstack/src/main/java/com/zsmartsystems/zigbee/console/zstack/ZstackConsoleAbstractCommand.java new file mode 100644 index 0000000000..0b0b980635 --- /dev/null +++ b/com.zsmartsystems.zigbee.console.zstack/src/main/java/com/zsmartsystems/zigbee/console/zstack/ZstackConsoleAbstractCommand.java @@ -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(); + } +} diff --git a/com.zsmartsystems.zigbee.console.zstack/src/main/java/com/zsmartsystems/zigbee/console/zstack/ZstackConsoleNcpDiagnosticsCommand.java b/com.zsmartsystems.zigbee.console.zstack/src/main/java/com/zsmartsystems/zigbee/console/zstack/ZstackConsoleNcpDiagnosticsCommand.java new file mode 100644 index 0000000000..884132c289 --- /dev/null +++ b/com.zsmartsystems.zigbee.console.zstack/src/main/java/com/zsmartsystems/zigbee/console/zstack/ZstackConsoleNcpDiagnosticsCommand.java @@ -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 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 diagnosticsEntry : diagnostics.entrySet()) { + out.println(String.format("%-40s %d", diagnosticsEntry.getKey(), diagnosticsEntry.getValue())); + } + } + +} diff --git a/com.zsmartsystems.zigbee.console.zstack/src/main/java/com/zsmartsystems/zigbee/console/zstack/ZstackConsoleNcpSecurityCommand.java b/com.zsmartsystems.zigbee.console.zstack/src/main/java/com/zsmartsystems/zigbee/console/zstack/ZstackConsoleNcpSecurityCommand.java new file mode 100644 index 0000000000..080854fccf --- /dev/null +++ b/com.zsmartsystems.zigbee.console.zstack/src/main/java/com/zsmartsystems/zigbee/console/zstack/ZstackConsoleNcpSecurityCommand.java @@ -0,0 +1,102 @@ +/** + * 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 com.zsmartsystems.zigbee.ZigBeeNetworkManager; +import com.zsmartsystems.zigbee.dongle.zstack.ZstackNcp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackConfigId; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackNwkKeyDesc; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSecMgrEntry; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilGetNvInfoSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.internal.serializer.ZstackDeserializer; + +/** + * + * @author Chris Jackson + * + */ +public class ZstackConsoleNcpSecurityCommand extends ZstackConsoleAbstractCommand { + private static int INVALID_NODE_ADDR = 0xFFFE; + + @Override + public String getCommand() { + return "ncpsecurity"; + } + + @Override + public String getDescription() { + return "Gets the NCP security information."; + } + + @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); + + ZstackUtilGetNvInfoSrsp nvInfo = ncp.getNvDeviceInfo(); + int[] nwkKeyConfig = ncp.readConfiguration(ZstackConfigId.ZCD_NV_NWKKEY); + int[] altKeyInfo = ncp.readConfiguration(ZstackConfigId.ZCD_NV_NWK_ALTERN_KEY_INFO); + int[] nwkActiveKeyInfo = ncp.readConfiguration(ZstackConfigId.ZCD_NV_NWK_ACTIVE_KEY_INFO); + + int[] apsKeyTable = ncp.readConfiguration(ZstackConfigId.ZCD_NV_APS_LINK_KEY_TABLE); + // apsKeyTable contains a 2 byte header which is an integer defining the number of entries + ZstackDeserializer deserializer = new ZstackDeserializer(apsKeyTable); + int apsKeyTableLen = deserializer.deserializeUInt16(); + for (int cnt = 0; cnt < apsKeyTableLen; cnt++) { + ZstackSecMgrEntry secMgrEntry = new ZstackSecMgrEntry(); + secMgrEntry.deserialize(deserializer); + } + + if (nvInfo == null) { + out.println("NV Device info : ERROR"); + } else { + out.println("Preconfigured Network Key : " + nvInfo.getPreConfigKey()); + } + + if (nwkKeyConfig == null) { + out.println("NWK Key Info : Not Supported"); + } else { + out.println("NWK Key Info : TODO: " + hexDump(nwkKeyConfig)); + } + + if (altKeyInfo != null) { + deserializer = new ZstackDeserializer(nwkActiveKeyInfo); + ZstackNwkKeyDesc nwkActiveKey = new ZstackNwkKeyDesc(); + nwkActiveKey.deserialize(deserializer); + out.println("Active NWK Key Info : Sequence=" + nwkActiveKey.getKeySeqNum() + ", Key=" + + nwkActiveKey.getKey()); + } + + if (altKeyInfo != null) { + deserializer = new ZstackDeserializer(nwkActiveKeyInfo); + ZstackNwkKeyDesc altKeyDesc = new ZstackNwkKeyDesc(); + altKeyDesc.deserialize(deserializer); + out.println("Alt NWK Key Info : Sequence=" + altKeyDesc.getKeySeqNum() + ", Key=" + + altKeyDesc.getKey()); + } + + if (apsKeyTable == null) { + out.println("APS Key Info : Not Supported"); + } else { + out.println("APS Key Info : TODO: " + hexDump(apsKeyTable)); + } + } + +} diff --git a/com.zsmartsystems.zigbee.console.zstack/src/main/java/com/zsmartsystems/zigbee/console/zstack/ZstackConsoleNcpStateCommand.java b/com.zsmartsystems.zigbee.console.zstack/src/main/java/com/zsmartsystems/zigbee/console/zstack/ZstackConsoleNcpStateCommand.java new file mode 100644 index 0000000000..99e672986d --- /dev/null +++ b/com.zsmartsystems.zigbee.console.zstack/src/main/java/com/zsmartsystems/zigbee/console/zstack/ZstackConsoleNcpStateCommand.java @@ -0,0 +1,118 @@ +/** + * 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.Set; + +import com.zsmartsystems.zigbee.ZigBeeChannelMask; +import com.zsmartsystems.zigbee.ZigBeeNetworkManager; +import com.zsmartsystems.zigbee.dongle.zstack.ZstackNcp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackConfigId; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysVersionSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSystemCapabilities; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilGetDeviceInfoSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilGetNvInfoSrsp; + +/** + * + * @author Chris Jackson + * + */ +public class ZstackConsoleNcpStateCommand extends ZstackConsoleAbstractCommand { + @Override + public String getCommand() { + return "ncpstate"; + } + + @Override + public String getDescription() { + return "Gets the NCP network state."; + } + + @Override + public String getSyntax() { + return ""; + } + + @Override + public String getHelp() { + return ""; + } + + @Override + public void process(ZigBeeNetworkManager networkManager, String[] args, PrintStream out) + throws IllegalArgumentException { + ncpState(networkManager, out); + } + + private void ncpState(ZigBeeNetworkManager networkManager, PrintStream out) { + ZstackNcp ncp = getZstackNcp(networkManager); + + ZstackUtilGetNvInfoSrsp nvInfo = ncp.getNvDeviceInfo(); + ZstackUtilGetDeviceInfoSrsp deviceInfo = ncp.getDeviceInfo(); + ZstackSysVersionSrsp ncpVersion = ncp.getVersion(); + Set ncpCapabilities = ncp.pingNcp(); + + int[] userDesc = ncp.readConfiguration(ZstackConfigId.ZCD_NV_USERDESC); + int[] bdbDeviceOnNwk = ncp.readConfiguration(ZstackConfigId.ZCD_NV_BDBNODEISONANETWORK); + int[] concentratorRadius = ncp.readConfiguration(ZstackConfigId.ZCD_NV_CONCENTRATOR_RADIUS); + int[] concentratorEnable = ncp.readConfiguration(ZstackConfigId.ZCD_NV_CONCENTRATOR_ENABLE); + int[] concentratorRc = ncp.readConfiguration(ZstackConfigId.ZCD_NV_CONCENTRATOR_RC); + int[] concentratorDiscovery = ncp.readConfiguration(ZstackConfigId.ZCD_NV_CONCENTRATOR_DISCOVERY); + int[] routeExpiry = ncp.readConfiguration(ZstackConfigId.ZCD_NV_ROUTE_EXPIRY_TIME); + int[] stackProfile = ncp.readConfiguration(ZstackConfigId.ZCD_NV_STACK_PROFILE); + int[] tcAddress = ncp.readConfiguration(ZstackConfigId.ZCD_NV_TRUSTCENTER_ADDR); + + out.println("BDB Device On Network : " + hex2Boolean(bdbDeviceOnNwk)); + out.println("Stack Profile : " + hex2Uint8(stackProfile)); + out.println("Trust Centre Address : " + hex2Uint8(routeExpiry)); + + out.println("Route Expiry : " + hex2Uint16(tcAddress)); + + out.println("Concentrator Enabled : " + hex2Boolean(concentratorEnable)); + out.println("Concentrator Radius : " + hex2Uint8(concentratorRadius)); + out.println("Concentrator Discovery Enabled : " + hex2Boolean(concentratorDiscovery)); + out.println("Concentrator Route Cache Enabled : " + hex2Boolean(concentratorRc)); + + if (deviceInfo == null) { + out.println("Device info : ERROR"); + } else { + out.println("Device State : " + deviceInfo.getDeviceState()); + out.println("NWK Address : " + deviceInfo.getShortAddr()); + out.println("IEEE Address : " + deviceInfo.getIeeeAddress()); + } + + if (nvInfo == null) { + out.println("NV Device info : ERROR"); + } else { + ZigBeeChannelMask channels = new ZigBeeChannelMask(nvInfo.getScanChannels()); + out.println("PAN ID : " + nvInfo.getPanId()); + out.println("Scan Channel : " + channels); + out.println("Preconfigured Key : " + nvInfo.getPreConfigKey()); + out.println("NV IEEE Address : " + nvInfo.getIeeeAddress()); + } + + if (ncpVersion == null) { + out.println("NCP Version : ERROR"); + } else { + out.println("Firmware version : " + ncpVersion.getMajorRel() + "." + + ncpVersion.getMinorRel() + "." + ncpVersion.getMaintRel()); + out.println("Product version : " + ncpVersion.getProduct()); + out.println("Transport version : " + ncpVersion.getTransportRev()); + } + + if (ncpCapabilities == null) { + out.println("NCP API Capabilities : ERROR"); + } else { + out.println("NCP API Capabilities : " + ncpCapabilities); + } + out.println("User Description : " + hex2String(userDesc)); + } + +} diff --git a/com.zsmartsystems.zigbee.dongle.cc2531/src/main/java/com/zsmartsystems/zigbee/dongle/cc2531/network/impl/CommandInterfaceImpl.java b/com.zsmartsystems.zigbee.dongle.cc2531/src/main/java/com/zsmartsystems/zigbee/dongle/cc2531/network/impl/CommandInterfaceImpl.java index 46284e453e..7ed96008b9 100644 --- a/com.zsmartsystems.zigbee.dongle.cc2531/src/main/java/com/zsmartsystems/zigbee/dongle/cc2531/network/impl/CommandInterfaceImpl.java +++ b/com.zsmartsystems.zigbee.dongle.cc2531/src/main/java/com/zsmartsystems/zigbee/dongle/cc2531/network/impl/CommandInterfaceImpl.java @@ -173,6 +173,17 @@ public void handlePacket(final ZToolPacket packet) { } } + private String frameToString(int[] inputBuffer) { + if (inputBuffer == null) { + return ""; + } + StringBuilder result = new StringBuilder(); + for (int data : inputBuffer) { + result.append(String.format("%02X ", data)); + } + return result.toString(); + } + /** * Send packet to dongle. * @@ -183,6 +194,7 @@ public void handlePacket(final ZToolPacket packet) { public void sendPacket(final ZToolPacket packet) throws IOException { logger.debug("-> {} ({}) ", packet.getClass().getSimpleName(), packet); final int[] pck = packet.getPacket(); + logger.debug("Sending frame {}", frameToString(pck)); sendRaw(pck); } diff --git a/com.zsmartsystems.zigbee.dongle.cc2531/src/test/java/com/zsmartsystems/zigbee/dongle/cc2531/Cc2351TestPacket.java b/com.zsmartsystems.zigbee.dongle.cc2531/src/test/java/com/zsmartsystems/zigbee/dongle/cc2531/Cc2351TestPacket.java index 04b12e575e..8bff37ec7b 100644 --- a/com.zsmartsystems.zigbee.dongle.cc2531/src/test/java/com/zsmartsystems/zigbee/dongle/cc2531/Cc2351TestPacket.java +++ b/com.zsmartsystems.zigbee.dongle.cc2531/src/test/java/com/zsmartsystems/zigbee/dongle/cc2531/Cc2351TestPacket.java @@ -111,5 +111,13 @@ public boolean open(int baudRate, FlowControl flowControl) { @Override public void purgeRxBuffer() { } + + @Override + public void setDtr(boolean state) { + } + + @Override + public void setRts(boolean state) { + } } } diff --git a/com.zsmartsystems.zigbee.dongle.ember.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/ember/autocode/CommandGenerator.java b/com.zsmartsystems.zigbee.dongle.ember.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/ember/autocode/CommandGenerator.java index fda8ba0a46..c95e886336 100644 --- a/com.zsmartsystems.zigbee.dongle.ember.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/ember/autocode/CommandGenerator.java +++ b/com.zsmartsystems.zigbee.dongle.ember.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/ember/autocode/CommandGenerator.java @@ -470,7 +470,7 @@ private void createStructureClass(Structure structure) throws FileNotFoundExcept continue; } if (autoSizers.get(parameter.name) != null) { - out.println(" " + parameter.name + "= deserializer.deserialize" + out.println(" " + parameter.name + " = deserializer.deserialize" + getTypeSerializer(parameter.data_type) + "(" + autoSizers.get(parameter.name) + ");"); continue; } diff --git a/com.zsmartsystems.zigbee.dongle.ember/src/test/java/com/zsmartsystems/zigbee/dongle/ember/internal/EmberFirmwareUpdateHandlerTest.java b/com.zsmartsystems.zigbee.dongle.ember/src/test/java/com/zsmartsystems/zigbee/dongle/ember/internal/EmberFirmwareUpdateHandlerTest.java index aeebbb23d6..bce4616009 100644 --- a/com.zsmartsystems.zigbee.dongle.ember/src/test/java/com/zsmartsystems/zigbee/dongle/ember/internal/EmberFirmwareUpdateHandlerTest.java +++ b/com.zsmartsystems.zigbee.dongle.ember/src/test/java/com/zsmartsystems/zigbee/dongle/ember/internal/EmberFirmwareUpdateHandlerTest.java @@ -202,6 +202,14 @@ public boolean open(int baudRate, FlowControl flowControl) { public void purgeRxBuffer() { } + @Override + public void setDtr(boolean state) { + } + + @Override + public void setRts(boolean state) { + } + public byte[] getOutput() { return Arrays.copyOfRange(output, 0, cnt); } diff --git a/com.zsmartsystems.zigbee.dongle.ember/src/test/java/com/zsmartsystems/zigbee/dongle/ember/internal/ash/AshFrameHandlerTest.java b/com.zsmartsystems.zigbee.dongle.ember/src/test/java/com/zsmartsystems/zigbee/dongle/ember/internal/ash/AshFrameHandlerTest.java index b7008d8a20..26c3a55d65 100644 --- a/com.zsmartsystems.zigbee.dongle.ember/src/test/java/com/zsmartsystems/zigbee/dongle/ember/internal/ash/AshFrameHandlerTest.java +++ b/com.zsmartsystems.zigbee.dongle.ember/src/test/java/com/zsmartsystems/zigbee/dongle/ember/internal/ash/AshFrameHandlerTest.java @@ -206,6 +206,14 @@ public boolean open(int baudRate, FlowControl flowControl) { public void purgeRxBuffer() { } + @Override + public void setDtr(boolean state) { + } + + @Override + public void setRts(boolean state) { + } + public List getOutputData() { return outputData; } diff --git a/com.zsmartsystems.zigbee.dongle.ember/src/test/java/com/zsmartsystems/zigbee/dongle/ember/internal/spi/SpiFrameHandlerTest.java b/com.zsmartsystems.zigbee.dongle.ember/src/test/java/com/zsmartsystems/zigbee/dongle/ember/internal/spi/SpiFrameHandlerTest.java index 3570d237a4..c48d586fb9 100644 --- a/com.zsmartsystems.zigbee.dongle.ember/src/test/java/com/zsmartsystems/zigbee/dongle/ember/internal/spi/SpiFrameHandlerTest.java +++ b/com.zsmartsystems.zigbee.dongle.ember/src/test/java/com/zsmartsystems/zigbee/dongle/ember/internal/spi/SpiFrameHandlerTest.java @@ -354,5 +354,13 @@ public boolean open(int baudRate, FlowControl flowControl) { @Override public void purgeRxBuffer() { } + + @Override + public void setDtr(boolean state) { + } + + @Override + public void setRts(boolean state) { + } } } diff --git a/com.zsmartsystems.zigbee.dongle.telegesis/src/test/java/com/zsmartsystems/zigbee/dongle/telegesis/internal/TelegesisFirmwareUpdateHandlerTest.java b/com.zsmartsystems.zigbee.dongle.telegesis/src/test/java/com/zsmartsystems/zigbee/dongle/telegesis/internal/TelegesisFirmwareUpdateHandlerTest.java index b88e073a95..1fd848aa91 100644 --- a/com.zsmartsystems.zigbee.dongle.telegesis/src/test/java/com/zsmartsystems/zigbee/dongle/telegesis/internal/TelegesisFirmwareUpdateHandlerTest.java +++ b/com.zsmartsystems.zigbee.dongle.telegesis/src/test/java/com/zsmartsystems/zigbee/dongle/telegesis/internal/TelegesisFirmwareUpdateHandlerTest.java @@ -203,6 +203,14 @@ public boolean open(int baudRate, FlowControl flowControl) { public void purgeRxBuffer() { } + @Override + public void setDtr(boolean state) { + } + + @Override + public void setRts(boolean state) { + } + public byte[] getOutput() { return Arrays.copyOfRange(output, 0, cnt); } diff --git a/com.zsmartsystems.zigbee.dongle.telegesis/src/test/java/com/zsmartsystems/zigbee/dongle/telegesis/internal/TelegesisFrameHandlerTest.java b/com.zsmartsystems.zigbee.dongle.telegesis/src/test/java/com/zsmartsystems/zigbee/dongle/telegesis/internal/TelegesisFrameHandlerTest.java index ec42a6593a..7903006d07 100644 --- a/com.zsmartsystems.zigbee.dongle.telegesis/src/test/java/com/zsmartsystems/zigbee/dongle/telegesis/internal/TelegesisFrameHandlerTest.java +++ b/com.zsmartsystems.zigbee.dongle.telegesis/src/test/java/com/zsmartsystems/zigbee/dongle/telegesis/internal/TelegesisFrameHandlerTest.java @@ -328,5 +328,13 @@ public boolean open(int baudRate, FlowControl flowControl) { @Override public void purgeRxBuffer() { } + + @Override + public void setDtr(boolean state) { + } + + @Override + public void setRts(boolean state) { + } } } diff --git a/com.zsmartsystems.zigbee.dongle.xbee/src/test/java/com/zsmartsystems/zigbee/dongle/xbee/internal/XBeeFrameHandlerTest.java b/com.zsmartsystems.zigbee.dongle.xbee/src/test/java/com/zsmartsystems/zigbee/dongle/xbee/internal/XBeeFrameHandlerTest.java index 3282366338..8b6d21b033 100644 --- a/com.zsmartsystems.zigbee.dongle.xbee/src/test/java/com/zsmartsystems/zigbee/dongle/xbee/internal/XBeeFrameHandlerTest.java +++ b/com.zsmartsystems.zigbee.dongle.xbee/src/test/java/com/zsmartsystems/zigbee/dongle/xbee/internal/XBeeFrameHandlerTest.java @@ -151,5 +151,13 @@ public boolean open(int baudRate, FlowControl flowControl) { @Override public void purgeRxBuffer() { } + + @Override + public void setDtr(boolean state) { + } + + @Override + public void setRts(boolean state) { + } } } diff --git a/com.zsmartsystems.zigbee.dongle.zstack.autocode/.project b/com.zsmartsystems.zigbee.dongle.zstack.autocode/.project new file mode 100644 index 0000000000..eefabd1d51 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack.autocode/.project @@ -0,0 +1,23 @@ + + + com.zsmartsystems.zigbee.dongle.zstack.autocode + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/com.zsmartsystems.zigbee.dongle.zstack.autocode/pom.xml b/com.zsmartsystems.zigbee.dongle.zstack.autocode/pom.xml new file mode 100644 index 0000000000..22f10adff0 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack.autocode/pom.xml @@ -0,0 +1,66 @@ + + + 4.0.0 + + com.zsmartsystems.zigbee + com.zsmartsystems.zigbee.dongle.zstack.autocode + jar + + + UTF-8 + UTF-8 + + + + com.zsmartsystems + zigbee + 1.4.3-SNAPSHOT + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.5 + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + + + + + + + + commons-io + commons-io + 2.4 + + + + commons-lang + commons-lang + 2.6 + + + + commons-codec + commons-codec + 1.8 + + + + + diff --git a/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/ClassGenerator.java b/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/ClassGenerator.java new file mode 100644 index 0000000000..b3a77cac08 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/ClassGenerator.java @@ -0,0 +1,220 @@ +/** + * 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.dongle.zstack.autocode; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import com.zsmartsystems.zigbee.dongle.zstack.autocode.xml.Parameter; + +/** + * + * @author Chris Jackson + * + */ +public abstract class ClassGenerator { + protected int lineLen = 110; + protected String sourceRootPath = "../com.zsmartsystems.zigbee.dongle.zstack/src/main/java/"; + protected List importList = new ArrayList(); + + protected String stringToConstant(String value) { + value = value.replaceAll("\\(.*?\\) ?", ""); + value = value.trim(); + value = value.replace("+", "_Plus"); + value = value.replace(" ", "_"); + value = value.replace("-", "_"); + value = value.replace(".", "_"); + value = value.replace("/", "_"); + value = value.replaceAll("_+", "_"); + return value.toUpperCase(); + } + + private String toProperCase(String str) { + return str.substring(0, 1).toUpperCase() + str.substring(1).toLowerCase(); + } + + private String toCamelCase(String value) { + value = value.replaceAll("\\(.*?\\) ?", ""); + value = value.replace("+", "_Plus"); + value = value.replace(" ", "_"); + value = value.replace("-", "_"); + value = value.replace(".", "_"); + value = value.replace("/", "_"); + value = value.replaceAll("_+", "_"); + String[] parts = value.split("_"); + String camelCaseString = ""; + for (String part : parts) { + camelCaseString = camelCaseString + toProperCase(part); + } + return camelCaseString; + } + + private String splitCamelCase(String str) { + String output = ""; + for (String w : str.split("(?") && line.contains("")) { + year = line.substring(line.indexOf("") + 14, line.indexOf("")); + break; + } + line = br.readLine(); + } + + br.close(); + + br = new BufferedReader(new FileReader("../src/etc/header.txt")); + line = br.readLine(); + + out.println("/**"); + while (line != null) { + out.println(" * " + line.replaceFirst("\\$\\{year\\}", year)); + line = br.readLine(); + } + out.println(" */"); + br.close(); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + protected void outputWithLinebreak(PrintWriter out, String indent, String line) { + String[] words = line.replace("\t", " ").replace("\n", " ").split(" "); + if (words.length == 0) { + return; + } + + out.print(indent + " *"); + + int len = 2; + for (String word : words) { + if (word.trim().isEmpty()) { + continue; + } + if (word.equalsIgnoreCase("note:")) { + if (len > 2) { + out.println(); + } + out.println(indent + " *

"); + out.print(indent + " * Note:"); + len = 15; + continue; + } + if (len + word.length() > lineLen) { + out.println(); + out.print(indent + " *"); + len = 2; + } + out.print(" "); + out.print(word); + len += word.length(); + } + + if (len != 0) { + out.println(); + } + } + + protected String formatParameterString(Parameter parameter) { + if (parameter.displayType != null) { + switch (parameter.displayType.toLowerCase()) { + case "hex": + String size = ""; + if (parameter.displayLength != 0) { + size = "0" + parameter.displayLength; + } + return "String.format(\"%" + size + "X\", " + camelCaseToLowerCamelCase(parameter.name) + ")"; + default: + break; + } + } + return camelCaseToLowerCamelCase(parameter.name); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/CommandGenerator.java b/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/CommandGenerator.java new file mode 100644 index 0000000000..0c30c1ee9d --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/CommandGenerator.java @@ -0,0 +1,1095 @@ +/** + * 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.dongle.zstack.autocode; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +import com.zsmartsystems.zigbee.dongle.zstack.autocode.xml.Command; +import com.zsmartsystems.zigbee.dongle.zstack.autocode.xml.Command.ZstackRequestType; +import com.zsmartsystems.zigbee.dongle.zstack.autocode.xml.Enumeration; +import com.zsmartsystems.zigbee.dongle.zstack.autocode.xml.Parameter; +import com.zsmartsystems.zigbee.dongle.zstack.autocode.xml.Protocol; +import com.zsmartsystems.zigbee.dongle.zstack.autocode.xml.Structure; +import com.zsmartsystems.zigbee.dongle.zstack.autocode.xml.Value; + +/** + * + * @author Chris Jackson + * + */ +public class CommandGenerator extends ClassGenerator { + protected final String zssPackage = "com.zsmartsystems.zigbee"; + protected final String zstackInternalPackage = "com.zsmartsystems.zigbee.dongle.zstack.internal"; + protected final String zstackCommandPackage = "com.zsmartsystems.zigbee.dongle.zstack.api"; + + private List enumerations; + + public void go(Protocol protocol) throws FileNotFoundException { + enumerations = protocol.enumerations; + + String className; + for (Command command : protocol.commands) { + String name = camelCaseToUpperCamelCase(command.name); + if (command.requestType == ZstackRequestType.ASYNC) { + className = "Zstack" + name + "Areq"; + createCommandClass(className, command, command.request_parameters); + } else if (command.requestType == ZstackRequestType.ASYNCMD) { + className = "Zstack" + name + "Acmd"; + createCommandClass(className, command, command.request_parameters); + } else { + if (command.request_parameters != null) { + className = "Zstack" + name + "Sreq"; + createCommandClass(className, command, command.request_parameters); + } + + if (command.response_parameters != null) { + className = "Zstack" + name + "Srsp"; + createCommandClass(className, command, command.response_parameters); + } + } + } + + createZstackFrameFactory(protocol); + + for (Structure structure : protocol.structures) { + createStructureClass(structure); + } + + for (Enumeration enumeration : protocol.enumerations) { + createEnumClass(enumeration); + } + } + + private void createCommandClass(String className, Command command, List parameters) + throws FileNotFoundException { + + System.out.println("Processing command class " + command.name + " [" + className + "()]"); + + StringWriter stringWriter = new StringWriter(); + PrintWriter out = new PrintWriter(stringWriter); + + clearImports(); + + out.println("/**"); + out.println(" * Class to implement the Z-Stack command " + command.name + "."); + out.println(" *

"); + if (command.description != null && !command.description.isEmpty()) { + outputWithLinebreak(out, "", command.description); + out.println(" *

"); + } + out.println(" * Note that this code is autogenerated. Manual changes may be overwritten."); + out.println(" *"); + out.println(" * @author Chris Jackson"); + out.println(" */"); + + if (className.endsWith("Srsp") || className.endsWith("Areq")) { + addImport(zstackCommandPackage + ".ZstackFrameResponse"); + out.println("public class " + className + " extends ZstackFrameResponse {"); + } else { + addImport(zstackCommandPackage + ".ZstackFrameRequest"); + out.println("public class " + className + " extends ZstackFrameRequest {"); + } + + for (Parameter parameter : parameters) { + if (parameter.auto_size != null) { + continue; + } + + out.println(); + out.println(" /**"); + if (parameter.description != null && !parameter.description.isEmpty()) { + outputWithLinebreak(out, " ", parameter.description); + } + if (parameter.multiple) { + out.println(" *

"); + out.println(" * Parameter allows multiple options so implemented as a {@link Set}."); + } + out.println(" */"); + if (parameter.multiple) { + addImport("java.util.Set"); + addImport("java.util.HashSet"); + out.println(" private Set<" + getTypeClass(command.subsystem, parameter.data_type) + "> " + + camelCaseToLowerCamelCase(parameter.name) + " = new HashSet<>();"); + } else { + out.println(" private " + getTypeClass(command.subsystem, parameter.data_type) + " " + + camelCaseToLowerCamelCase(parameter.name) + ";"); + } + + // out.println(" private " + getTypeClass(command.subsystem, parameter.data_type) + " " + // + camelCaseToLowerCamelCase(parameter.name) + ";"); + } + + if (className.endsWith("Srsp") || className.endsWith("Areq")) { + out.println(); + out.println(" /**"); + out.println(" * Response and Handler constructor"); + out.println(" */"); + out.println(" public " + className + "(int[] inputBuffer) {"); + out.println(" // Super creates deserializer and reads header fields"); + out.println(" super(inputBuffer);"); + if (className.endsWith("Srsp")) { + out.println(); + out.println(" synchronousCommand = true;"); + } + out.println(); + out.println(" // Deserialize the fields"); + Map autoSizers = new HashMap(); + for (Parameter parameter : parameters) { + if (parameter.auto_size != null) { + out.println( + " int " + camelCaseToLowerCamelCase(parameter.name) + " = deserializer.deserialize" + + getTypeSerializer(command.subsystem, parameter.data_type) + "();"); + autoSizers.put(parameter.auto_size, camelCaseToLowerCamelCase(parameter.name)); + continue; + } + if (autoSizers.get(parameter.name) != null) { + out.println(" " + camelCaseToLowerCamelCase(parameter.name) + " = deserializer.deserialize" + + getTypeSerializer(command.subsystem, parameter.data_type) + "(" + + autoSizers.get(parameter.name) + ");"); + continue; + } + if (parameter.data_type.contains("[") && parameter.data_type.contains("]") + && !parameter.data_type.contains("[]")) { + int length = Integer.parseInt(parameter.data_type.substring(parameter.data_type.indexOf("[") + 1, + parameter.data_type.indexOf("]"))); + out.println(" " + camelCaseToLowerCamelCase(parameter.name) + " = deserializer.deserialize" + + getTypeSerializer(command.subsystem, parameter.data_type) + "(" + length + ");"); + continue; + } + if (getDataType(parameter.data_type) != parameter.data_type) { + if (parameter.multiple) { + out.println(" " + getTypeClass(command.subsystem, getDataType(parameter.data_type)) + + " tmp" + upperCaseFirstCharacter(parameter.name) + " = deserializer.deserialize" + + getTypeSerializer(command.subsystem, parameter.data_type) + "();"); + out.println(" for (" + getTypeClass(parameter.data_type) + " value : " + + getTypeClass(parameter.data_type) + ".values()) {"); + out.println(" if ((tmp" + upperCaseFirstCharacter(parameter.name) + + " & value.getKey()) != 0) {"); + out.println(" " + camelCaseToLowerCamelCase(parameter.name) + ".add(value);"); + out.println(" }"); + out.println(" }"); + } else { + out.println(" " + camelCaseToLowerCamelCase(parameter.name) + " = " + parameter.data_type + + ".valueOf(deserializer.deserialize" + + getTypeSerializer(command.subsystem, parameter.data_type) + "());"); + } + } else { + out.println(" " + camelCaseToLowerCamelCase(parameter.name) + " = deserializer.deserialize" + + getTypeSerializer(command.subsystem, parameter.data_type) + "();"); + } + } + out.println(" }"); + } else { + out.println(); + out.println(" /**"); + out.println(" * Request constructor"); + out.println(" */"); + out.println(" public " + className + "() {"); + if (className.endsWith("Sreq")) { + out.println(" synchronousCommand = true;"); + } + out.println(" }"); + } + + for (Parameter parameter : parameters) { + if (parameter.auto_size != null) { + continue; + } + + out.println(); + out.println(" /**"); + outputWithLinebreak(out, " ", parameter.description); + out.println(" *"); + if (parameter.multiple) { + out.println(" * @return the current " + camelCaseToLowerCamelCase(parameter.name) + + " as {@link Set} of {@link " + getTypeClass(command.subsystem, parameter.data_type) + "}"); + } else { + out.println(" * @return the current " + camelCaseToLowerCamelCase(parameter.name) + " as {@link " + + getTypeClass(command.subsystem, parameter.data_type) + "}"); + } + out.println(" */"); + if (parameter.multiple) { + out.println(" public Set<" + getTypeClass(command.subsystem, parameter.data_type) + "> get" + + upperCaseFirstCharacter(parameter.name) + "() {"); + } else { + out.println(" public " + getTypeClass(command.subsystem, parameter.data_type) + " get" + + upperCaseFirstCharacter(parameter.name) + "() {"); + } + + out.println(" return " + camelCaseToLowerCamelCase(parameter.name) + ";"); + out.println(" }"); + out.println(); + + if (parameter.multiple) { + out.println(" /**"); + outputWithLinebreak(out, " ", parameter.description); + out.println(" *"); + out.println(" * @param " + camelCaseToLowerCamelCase(parameter.name) + " the " + parameter.name + + " to add to the {@link Set} as {@link " + getTypeClass(command.subsystem, parameter.data_type) + + "}"); + out.println(" */"); + out.println(" public void add" + upperCaseFirstCharacter(parameter.name) + "(" + + getTypeClass(command.subsystem, parameter.data_type) + " " + + camelCaseToLowerCamelCase(parameter.name) + ") {"); + out.println(" this." + camelCaseToLowerCamelCase(parameter.name) + ".add(" + + camelCaseToLowerCamelCase(parameter.name) + ");"); + out.println(" }"); + out.println(); + out.println(" /**"); + outputWithLinebreak(out, " ", parameter.description); + out.println(" *"); + out.println(" * @param " + camelCaseToLowerCamelCase(parameter.name) + " the " + parameter.name + + " to remove to the {@link Set} as {@link " + + getTypeClass(command.subsystem, parameter.data_type) + "}"); + out.println(" */"); + out.println(" public void remove" + upperCaseFirstCharacter(parameter.name) + "(" + + getTypeClass(command.subsystem, parameter.data_type) + " " + + camelCaseToLowerCamelCase(parameter.name) + ") {"); + out.println(" this." + camelCaseToLowerCamelCase(parameter.name) + ".remove(" + + camelCaseToLowerCamelCase(parameter.name) + ");"); + out.println(" }"); + } else { + out.println(" /**"); + outputWithLinebreak(out, " ", parameter.description); + out.println(" *"); + out.println(" * @param " + camelCaseToLowerCamelCase(parameter.name) + " the " + parameter.name + + " to set as {@link " + getTypeClass(command.subsystem, parameter.data_type) + "}"); + out.println(" */"); + out.println(" public void set" + upperCaseFirstCharacter(parameter.name) + "(" + + getTypeClass(command.subsystem, parameter.data_type) + " " + + camelCaseToLowerCamelCase(parameter.name) + ") {"); + out.println(" this." + camelCaseToLowerCamelCase(parameter.name) + " = " + + camelCaseToLowerCamelCase(parameter.name) + ";"); + out.println(" }"); + } + } + + if (className.endsWith("Srsp") || className.endsWith("Areq")) { + } else { + if (className.endsWith("Sreq")) { + addImport(zstackCommandPackage + ".rpc.ZstackRpcSreqErrorSrsp"); + out.println(); + out.println(" @Override"); + out.println(" public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) {"); + out.println(" return (((response.getReqCmd0() & 0x1F) == ZSTACK_" + command.subsystem + + ") && (response.getReqCmd1() == " + String.format("0x%02X", command.id) + "));"); + out.println(" }"); + } + + out.println(); + out.println(" @Override"); + out.println(" public int[] serialize() {"); + out.println(" // Serialize the header"); + out.println(" serializeHeader(ZSTACK_" + className.substring(className.length() - 4).toUpperCase() + + ", ZSTACK_" + command.subsystem + ", " + String.format("0x%02X", command.id) + ");"); + out.println(); + out.println(" // Serialize the fields"); + for (Parameter parameter : parameters) { + String enumModifier = ""; + if (getDataType(parameter.data_type) != parameter.data_type) { + enumModifier = ".getKey()"; + } + if (parameter.auto_size != null) { + out.println( + " serializer.serialize" + getTypeSerializer(command.subsystem, parameter.data_type) + + "(" + camelCaseToLowerCamelCase(parameter.auto_size) + ".length);"); + continue; + } + if (parameter.multiple) { + out.println(" " + getTypeClass(command.subsystem, getDataType(parameter.data_type)) + " tmp" + + upperCaseFirstCharacter(parameter.name) + " = 0;"); + out.println(" for (" + getTypeClass(parameter.data_type) + " value : " + + camelCaseToLowerCamelCase(parameter.name) + ") {"); + out.println(" tmp" + upperCaseFirstCharacter(parameter.name) + " += value.getKey();"); + out.println(" }"); + out.println( + " serializer.serialize" + getTypeSerializer(command.subsystem, parameter.data_type) + + "(" + "tmp" + upperCaseFirstCharacter(parameter.name) + ");"); + } else { + out.println( + " serializer.serialize" + getTypeSerializer(command.subsystem, parameter.data_type) + + "(" + camelCaseToLowerCamelCase(parameter.name) + enumModifier + ");"); + } + } + out.println(" return getPayload();"); + out.println(" }"); + } + + out.println(); + out.println(" @Override"); + out.println(" public String toString() {"); + + if (parameters == null || parameters.size() == 0) { + out.println(" return \"" + className + " []\";"); + } else { + out.println(" final StringBuilder builder = new StringBuilder(" + + (className.length() + 3 + parameters.size() * 25) + ");"); + boolean first = true; + for (Parameter parameter : parameters) { + if (parameter.auto_size != null) { + continue; + } + + if (first) { + out.println(" builder.append(\"" + className + " [" + + camelCaseToLowerCamelCase(parameter.name) + "=\");"); + } else { + out.println(" builder.append(\", " + camelCaseToLowerCamelCase(parameter.name) + "=\");"); + } + first = false; + if (parameter.data_type.contains("[")) { + out.println(" for (int c = 0; c < " + camelCaseToLowerCamelCase(parameter.name) + + ".length; c++) {"); + out.println(" if (c > 0) {"); + out.println(" builder.append(' ');"); + out.println(" }"); + + String format = "%02X"; + if (parameter.displayType != null) { + switch (parameter.displayType.toLowerCase()) { + case "hex": + String size = ""; + if (parameter.displayLength != 0) { + size = "0" + parameter.displayLength; + } + format = "%" + size + "X"; + break; + } + } + + out.println(" builder.append(String.format(\"" + format + "\", " + + camelCaseToLowerCamelCase(parameter.name) + "[c]));"); + + // + // out.println(" builder.append(String.format(\"%02X\", " + formatParameterString(parameter) + // + "[c]));"); + out.println(" }"); + } else { + out.println(" builder.append(" + formatParameterString(parameter) + ");"); + } + } + out.println(" builder.append(']');"); + out.println(" return builder.toString();"); + } + out.println(" }"); + + out.println("}"); + + out.flush(); + + String cmdPackage = zstackCommandPackage + "." + command.subsystem.toLowerCase().replace("_", ""); + File packageFile = new File(sourceRootPath + cmdPackage.replace(".", "/")); + packageFile.mkdirs(); + PrintWriter outFile = getClassOut(packageFile, className); + + outputCopywrite(outFile); + outFile.println("package " + cmdPackage + ";"); + + outFile.println(); + + outputImports(outFile); + + outFile.println(); + outFile.print(stringWriter.toString()); + + outFile.flush(); + outFile.close(); + + out.close(); + } + + private void createStructureClass(Structure structure) throws FileNotFoundException { + String className = upperCaseFirstCharacter(structure.name); + + System.out.println("Processing structure class " + structure.name + " [" + className + "()]"); + + StringWriter stringWriter = new StringWriter(); + PrintWriter out = new PrintWriter(stringWriter); + + clearImports(); + + out.println("/**"); + out.println(" * Class to implement the Z-Stack structure " + structure.name + "."); + out.println(" *

"); + if (structure.description != null && !structure.description.isEmpty()) { + outputWithLinebreak(out, "", structure.description); + out.println(" *

"); + } + out.println(" * Note that this code is autogenerated. Manual changes may be overwritten."); + out.println(" *"); + out.println(" * @author Chris Jackson"); + out.println(" */"); + + addImport(zstackInternalPackage + ".serializer.ZstackSerializer"); + addImport(zstackInternalPackage + ".serializer.ZstackDeserializer"); + out.println("public class " + className + " {"); + + for (Parameter parameter : structure.parameters) { + if (parameter.auto_size != null) { + continue; + } + + out.println(); + out.println(" /**"); + if (parameter.description != null && !parameter.description.isEmpty()) { + outputWithLinebreak(out, " ", parameter.description); + } + if (parameter.multiple) { + out.println(" *

"); + out.println(" * Parameter allows multiple options so implemented as a {@link Set}."); + } + out.println(" */"); + if (parameter.multiple) { + addImport("java.util.Set"); + addImport("java.util.HashSet"); + out.println(" private Set<" + getTypeClass(structure.subsystem, parameter.data_type) + "> " + + camelCaseToLowerCamelCase(parameter.name) + " = new HashSet<>();"); + } else { + out.println(" private " + getTypeClass(structure.subsystem, parameter.data_type) + " " + + camelCaseToLowerCamelCase(parameter.name) + ";"); + } + + // out.println(" private " + getTypeClass(command.subsystem, parameter.data_type) + " " + // + camelCaseToLowerCamelCase(parameter.name) + ";"); + } + + for (Parameter parameter : structure.parameters) { + if (parameter.auto_size != null) { + continue; + } + + out.println(); + out.println(" /**"); + outputWithLinebreak(out, " ", parameter.description); + out.println(" *"); + if (parameter.multiple) { + out.println(" * @return the current " + camelCaseToLowerCamelCase(parameter.name) + + " as {@link Set} of {@link " + getTypeClass(structure.subsystem, parameter.data_type) + "}"); + } else { + out.println(" * @return the current " + camelCaseToLowerCamelCase(parameter.name) + " as {@link " + + getTypeClass(structure.subsystem, parameter.data_type) + "}"); + } + out.println(" */"); + if (parameter.multiple) { + out.println(" public Set<" + getTypeClass(structure.subsystem, parameter.data_type) + "> get" + + upperCaseFirstCharacter(parameter.name) + "() {"); + } else { + out.println(" public " + getTypeClass(structure.subsystem, parameter.data_type) + " get" + + upperCaseFirstCharacter(parameter.name) + "() {"); + } + + out.println(" return " + camelCaseToLowerCamelCase(parameter.name) + ";"); + out.println(" }"); + out.println(); + + if (parameter.multiple) { + out.println(" /**"); + outputWithLinebreak(out, " ", parameter.description); + out.println(" *"); + out.println(" * @param " + camelCaseToLowerCamelCase(parameter.name) + " the " + parameter.name + + " to add to the {@link Set} as {@link " + + getTypeClass(structure.subsystem, parameter.data_type) + "}"); + out.println(" */"); + out.println(" public void add" + upperCaseFirstCharacter(parameter.name) + "(" + + getTypeClass(structure.subsystem, parameter.data_type) + " " + + camelCaseToLowerCamelCase(parameter.name) + ") {"); + out.println(" this." + camelCaseToLowerCamelCase(parameter.name) + ".add(" + + camelCaseToLowerCamelCase(parameter.name) + ");"); + out.println(" }"); + out.println(); + out.println(" /**"); + outputWithLinebreak(out, " ", parameter.description); + out.println(" *"); + out.println(" * @param " + camelCaseToLowerCamelCase(parameter.name) + " the " + parameter.name + + " to remove to the {@link Set} as {@link " + + getTypeClass(structure.subsystem, parameter.data_type) + "}"); + out.println(" */"); + out.println(" public void remove" + upperCaseFirstCharacter(parameter.name) + "(" + + getTypeClass(structure.subsystem, parameter.data_type) + " " + + camelCaseToLowerCamelCase(parameter.name) + ") {"); + out.println(" this." + camelCaseToLowerCamelCase(parameter.name) + ".remove(" + + camelCaseToLowerCamelCase(parameter.name) + ");"); + out.println(" }"); + } else { + out.println(" /**"); + outputWithLinebreak(out, " ", parameter.description); + out.println(" *"); + out.println(" * @param " + camelCaseToLowerCamelCase(parameter.name) + " the " + parameter.name + + " to set as {@link " + getTypeClass(structure.subsystem, parameter.data_type) + "}"); + out.println(" */"); + out.println(" public void set" + upperCaseFirstCharacter(parameter.name) + "(" + + getTypeClass(structure.subsystem, parameter.data_type) + " " + + camelCaseToLowerCamelCase(parameter.name) + ") {"); + out.println(" this." + camelCaseToLowerCamelCase(parameter.name) + " = " + + camelCaseToLowerCamelCase(parameter.name) + ";"); + out.println(" }"); + } + } + + out.println(); + out.println(" /**"); + out.println(" * Serialize the data from this structure class to an integer array"); + out.println(" *"); + out.println(" * @param serializer the {@link ZstackSerializer} to use"); + out.println(" */"); + out.println(" public int[] serialize(ZstackSerializer serializer) {"); + out.println(" // Serialize the fields"); + for (Parameter parameter : structure.parameters) { + String enumModifier = ""; + if (getDataType(parameter.data_type) != parameter.data_type) { + enumModifier = ".getKey()"; + } + if (parameter.auto_size != null) { + out.println(" serializer.serialize" + getTypeSerializer(structure.subsystem, parameter.data_type) + + "(" + camelCaseToLowerCamelCase(parameter.auto_size) + ".length);"); + continue; + } + if (parameter.multiple) { + out.println(" " + getTypeClass(structure.subsystem, getDataType(parameter.data_type)) + " tmp" + + upperCaseFirstCharacter(parameter.name) + " = 0;"); + out.println(" for (" + getTypeClass(parameter.data_type) + " value : " + + camelCaseToLowerCamelCase(parameter.name) + ") {"); + out.println(" tmp" + upperCaseFirstCharacter(parameter.name) + " += value.getKey();"); + out.println(" }"); + out.println(" serializer.serialize" + getTypeSerializer(structure.subsystem, parameter.data_type) + + "(" + "tmp" + upperCaseFirstCharacter(parameter.name) + ");"); + } else { + out.println(" serializer.serialize" + getTypeSerializer(structure.subsystem, parameter.data_type) + + "(" + camelCaseToLowerCamelCase(parameter.name) + enumModifier + ");"); + } + } + out.println(" return serializer.getBuffer();"); + out.println(" }"); + + out.println(); + out.println(" /**"); + out.println(" * Deserialize the data into this structure class"); + out.println(" *"); + out.println(" * @param deserializer the {@link ZstackDeserializer} to use"); + out.println(" */"); + out.println(" public void deserialize (ZstackDeserializer deserializer) {"); + out.println(" // Deserialize the fields"); + Map autoSizers = new HashMap(); + for (Parameter parameter : structure.parameters) { + if (parameter.auto_size != null) { + out.println(" int " + camelCaseToLowerCamelCase(parameter.name) + " = deserializer.deserialize" + + getTypeSerializer(structure.subsystem, parameter.data_type) + "();"); + autoSizers.put(parameter.auto_size, camelCaseToLowerCamelCase(parameter.name)); + continue; + } + if (autoSizers.get(parameter.name) != null) { + out.println(" " + camelCaseToLowerCamelCase(parameter.name) + " = deserializer.deserialize" + + getTypeSerializer(structure.subsystem, parameter.data_type) + "(" + + autoSizers.get(parameter.name) + ");"); + continue; + } + if (parameter.data_type.contains("[") && parameter.data_type.contains("]") + && !parameter.data_type.contains("[]")) { + int length = Integer.parseInt(parameter.data_type.substring(parameter.data_type.indexOf("[") + 1, + parameter.data_type.indexOf("]"))); + out.println(" " + camelCaseToLowerCamelCase(parameter.name) + " = deserializer.deserialize" + + getTypeSerializer(structure.subsystem, parameter.data_type) + "(" + length + ");"); + continue; + } + if (getDataType(parameter.data_type) != parameter.data_type) { + if (parameter.multiple) { + out.println(" " + getTypeClass(structure.subsystem, getDataType(parameter.data_type)) + + " tmp" + upperCaseFirstCharacter(parameter.name) + " = deserializer.deserialize" + + getTypeSerializer(structure.subsystem, parameter.data_type) + "();"); + out.println(" for (" + getTypeClass(parameter.data_type) + " value : " + + getTypeClass(parameter.data_type) + ".values()) {"); + out.println(" if ((tmp" + upperCaseFirstCharacter(parameter.name) + + " & value.getKey()) != 0) {"); + out.println(" " + camelCaseToLowerCamelCase(parameter.name) + ".add(value);"); + out.println(" }"); + out.println(" }"); + } else { + out.println(" " + camelCaseToLowerCamelCase(parameter.name) + " = " + parameter.data_type + + ".valueOf(deserializer.deserialize" + + getTypeSerializer(structure.subsystem, parameter.data_type) + "());"); + } + } else { + out.println(" " + camelCaseToLowerCamelCase(parameter.name) + " = deserializer.deserialize" + + getTypeSerializer(structure.subsystem, parameter.data_type) + "();"); + } + } + out.println(" }"); + + out.println(); + out.println(" @Override"); + out.println(" public String toString() {"); + + if (structure.parameters == null || structure.parameters.size() == 0) { + out.println(" return \"" + className + " []\";"); + } else { + out.println(" final StringBuilder builder = new StringBuilder(" + + (className.length() + 3 + structure.parameters.size() * 25) + ");"); + boolean first = true; + for (Parameter parameter : structure.parameters) { + if (parameter.auto_size != null) { + continue; + } + + if (first) { + out.println(" builder.append(\"" + className + " [" + + camelCaseToLowerCamelCase(parameter.name) + "=\");"); + } else { + out.println(" builder.append(\", " + camelCaseToLowerCamelCase(parameter.name) + "=\");"); + } + first = false; + if (parameter.data_type.contains("[")) { + out.println(" for (int c = 0; c < " + camelCaseToLowerCamelCase(parameter.name) + + ".length; c++) {"); + out.println(" if (c > 0) {"); + out.println(" builder.append(' ');"); + out.println(" }"); + + String format = "%02X"; + switch (parameter.displayType.toLowerCase()) { + case "hex": + String size = ""; + if (parameter.displayLength != 0) { + size = "0" + parameter.displayLength; + } + format = "%" + size; + break; + } + + out.println(" builder.append(String.format(\"" + format + "\", " + parameter + "[c]));"); + out.println(" }"); + } else { + out.println(" builder.append(" + formatParameterString(parameter) + ");"); + } + } + out.println(" builder.append(']');"); + out.println(" return builder.toString();"); + } + out.println(" }"); + + out.println("}"); + + out.flush(); + + String cmdPackage = zstackCommandPackage + "." + structure.subsystem.toLowerCase().replace("_", ""); + File packageFile = new File(sourceRootPath + cmdPackage.replace(".", "/")); + packageFile.mkdirs(); + PrintWriter outFile = getClassOut(packageFile, className); + + outputCopywrite(outFile); + outFile.println("package " + cmdPackage + ";"); + + outFile.println(); + + outputImports(outFile); + + outFile.println(); + outFile.print(stringWriter.toString()); + + outFile.flush(); + outFile.close(); + + out.close(); + } + + private void createEnumClass(Enumeration enumeration) throws FileNotFoundException { + String className = upperCaseFirstCharacter(enumeration.name); + System.out.println("Processing enum class " + enumeration.name + " [" + className + "()]"); + + StringWriter stringWriter = new StringWriter(); + PrintWriter out = new PrintWriter(stringWriter); + + clearImports(); + + addImport("java.util.Map"); + addImport("java.util.HashMap"); + + out.println("/**"); + out.println(" * Class to implement the Z-Stack Enumeration " + enumeration.name + "."); + if (enumeration.description != null && enumeration.description.trim().length() > 0) { + out.println(" *

"); + outputWithLinebreak(out, "", enumeration.description); + } + out.println(" *

"); + out.println(" * Note that this code is autogenerated. Manual changes may be overwritten."); + out.println(" *"); + out.println(" * @author Chris Jackson"); + out.println(" */"); + + out.println("public enum " + className + " {"); + + if (!enumeration.fullyDefined) { + out.println(" /**"); + out.println(" * Default unknown value"); + out.println(" */"); + out.println(" UNKNOWN(-1),"); + } + + boolean first = true; + for (Value value : enumeration.values) { + if (!first) { + out.println(","); + } + first = false; + out.println(); + out.println(" /**"); + outputWithLinebreak(out, " ", value.description); + out.println(" */"); + out.print(" " + super.stringToConstant(value.name) + "(0x" + String.format("%04X", value.enum_value) + + ")"); + } + + out.println(";"); + + out.println(); + out.println(" /**"); + out.println(" * A mapping between the integer code and its corresponding type to"); + out.println(" * facilitate lookup by code."); + out.println(" */"); + out.println(" private static Map codeMapping;"); + out.println(); + + out.println(" private int key;"); + out.println(); + + out.println(" static {"); + out.println(" codeMapping = new HashMap();"); + out.println(" for (" + className + " s : values()) {"); + out.println(" codeMapping.put(s.key, s);"); + out.println(" }"); + out.println(" }"); + out.println(); + + out.println(" private " + className + "(int key) {"); + out.println(" this.key = key;"); + out.println(" }"); + out.println(); + + out.println(" /**"); + out.println(" * Lookup function based on the type code. Returns null if the code does not exist."); + out.println(" *"); + out.println(" * @param code the code to lookup"); + out.println(" * @return enumeration value of the alarm type."); + out.println(" */"); + out.println(" public static " + className + " valueOf(int code) {"); + if (!enumeration.fullyDefined) { + out.println(" if (codeMapping.get(code) == null) {"); + out.println(" return UNKNOWN;"); + out.println(" }"); + } + out.println(); + + out.println(" return codeMapping.get(code);"); + out.println(" }"); + out.println(); + out.println(" /**"); + out.println(" * Returns the Z-Stack protocol defined value for this enumeration."); + out.println(" *"); + out.println(" * @return the Z-Stack protocol key"); + out.println(" */"); + out.println(" public int getKey() {"); + out.println(" return key;"); + out.println(" }"); + + out.println("}"); + + out.flush(); + + String packageName = zstackCommandPackage; + if (!enumeration.subsystem.isEmpty()) { + packageName += "." + enumeration.subsystem.toLowerCase().replace("_", ""); + } + + File packageFile = new File(sourceRootPath + packageName.replace(".", "/")); + PrintWriter outFile = getClassOut(packageFile, className); + + outputCopywrite(outFile); + outFile.println("package " + packageName + ";"); + + outFile.println(); + + outputImports(outFile); + + outFile.println(); + outFile.print(stringWriter.toString()); + + outFile.flush(); + outFile.close(); + + out.close(); + } + + protected String getDataType(String dataType) { + for (Enumeration enumeration : enumerations) { + if (enumeration.name.equals(dataType) && enumeration.data_type != null) { + return enumeration.data_type; + } + } + + return dataType; + } + + protected String getTypeClass(String dataType) { + return getTypeClass("", dataType); + } + + protected String getTypeClass(String subsystem, String dataType) { + if (dataType == null || dataType.isEmpty()) { + throw new IllegalArgumentException("dataType cannot be empty"); + } + String dataTypeLocal = new String(dataType); + if (dataType.contains("[")) { + dataTypeLocal = dataTypeLocal.substring(0, dataTypeLocal.indexOf("[") + 1); + } + + for (Enumeration enumeration : enumerations) { + if (enumeration.name.equals(dataType) && !enumeration.subsystem.equals(subsystem)) { + String packageName = zstackCommandPackage; + if (!enumeration.subsystem.isEmpty()) { + packageName += "." + enumeration.subsystem.toLowerCase().replace("_", ""); + } + + addImport(packageName + "." + dataTypeLocal); + } + } + + switch (dataTypeLocal) { + case "int8": + case "uint8": + case "uint16": + case "uint32": + return "int"; + case "uint8[": + case "uint16[": + return "int[]"; + case "IeeeAddress": + addImport(zssPackage + "." + dataTypeLocal); + return dataTypeLocal; + case "ZigBeeKey": + addImport(zssPackage + ".security." + dataTypeLocal); + return dataTypeLocal; + case "": + addImport(zstackCommandPackage + "." + dataTypeLocal); + return dataTypeLocal; + case "AfDataOptions": + addImport(zstackCommandPackage + ".af." + dataTypeLocal); + return dataTypeLocal; + default: + return dataType; + } + } + + protected String getTypeSerializer(String subsystem, String dataType) { + String dataTypeLocal = new String(dataType); + if (dataType.contains("[")) { + dataTypeLocal = dataTypeLocal.substring(0, dataTypeLocal.indexOf("[") + 1); + } + + for (Enumeration enumeration : enumerations) { + if (enumeration.name.equals(dataType) && enumeration.data_type != null) { + dataTypeLocal = enumeration.data_type; + } + } + + switch (dataTypeLocal) { + case "int8": + case "uint8": + return "UInt8"; + case "uint16": + return "UInt16"; + case "uint32": + return "UInt32"; + case "uint8[": + return "UInt8Array"; + case "uint16[": + return "UInt16Array"; + case "boolean": + return "Boolean"; + case "AF_DISCV_ROUTE": + case "AfDataOptions": + return dataTypeLocal; + default: + return dataType; + } + } + + private void createZstackFrameFactory(Protocol protocol) throws FileNotFoundException { + StringWriter stringWriter = new StringWriter(); + PrintWriter out = new PrintWriter(stringWriter); + + clearImports(); + + addImport("java.lang.reflect.Constructor"); + addImport("java.lang.reflect.InvocationTargetException"); + addImport("java.util.HashMap"); + addImport("java.util.Map"); + addImport("org.slf4j.Logger"); + addImport("org.slf4j.LoggerFactory"); + + Map commandMap = new TreeMap<>(); + for (Command command : protocol.commands) { + commandMap.put(command.name, command); + } + + out.println(); + + out.println("/**"); + out.println( + " * Factory class to create Z-Stack commands from incoming data. This will only create {@link ZstackFrameResponse}s."); + out.println(" *

"); + out.println(" * Note that this code is autogenerated. Manual changes may be overwritten."); + out.println(" *"); + out.println(" * @author Chris Jackson"); + out.println(" */"); + out.println("public class ZstackFrameFactory {"); + out.println(" /**"); + out.println(" * Logger"); + out.println(" */"); + out.println(" private static Logger logger = LoggerFactory.getLogger(ZstackFrameFactory.class);"); + + out.println(); + + out.println(" /*"); + out.println(" * Subsystem definitions"); + out.println(" */"); + out.println(" public static int ZSTACK_RPC = 0x0000;"); + out.println(" public static int ZSTACK_SYS = 0x0100;"); + out.println(" public static int ZSTACK_MAC = 0x0200;"); + out.println(" public static int ZSTACK_AF = 0x0400;"); + out.println(" public static int ZSTACK_ZDO = 0x0500;"); + out.println(" public static int ZSTACK_SAPI = 0x0600;"); + out.println(" public static int ZSTACK_UTIL = 0x0700;"); + out.println(" public static int ZSTACK_APP_CNF = 0x0F00;"); + out.println(" public static int ZSTACK_SBL = 0x0D00;"); + out.println(); + out.println(" /**"); + out.println(" * Subsystem definition mask"); + out.println(" */"); + out.println(" private static int ZSTACK_SUBSYSTEM_MASK = 0x1F;"); + out.println(); + + for (Command command : commandMap.values()) { + if (command.requestType == ZstackRequestType.ASYNCMD) { + continue; + } + + String reference = camelCaseToConstant( + command.name.substring(0, 1).toUpperCase() + command.name.substring(1)); + out.println( + " private static final int " + reference + " = 0x" + String.format("%02X", command.id) + ";"); + } + + out.println(); + out.println(" private static Map> zstackFrameMap = new HashMap>();"); + out.println(); + out.println(" static {"); + for (Command command : commandMap.values()) { + String name = camelCaseToUpperCamelCase(command.name); + String className; + + String cmdPackage = zstackCommandPackage + "." + command.subsystem.toLowerCase().replace("_", ""); + + if (command.requestType == ZstackRequestType.ASYNC) { + className = "Zstack" + name + "Areq"; + addImport(cmdPackage + "." + className); + + String reference = camelCaseToConstant( + command.name.substring(0, 1).toUpperCase() + command.name.substring(1)); + out.println(" zstackFrameMap.put(ZSTACK_" + command.subsystem + " + " + reference + ", " + + className + ".class);"); + } else if (command.requestType == ZstackRequestType.ASYNCMD) { + // className = "Zstack" + name + "Acmd"; + // addImport(cmdPackage + "." + className); + + // String reference = camelCaseToConstant( + // command.name.substring(0, 1).toUpperCase() + command.name.substring(1)); + // out.println(" zstackFrameMap.put(ZSTACK_" + command.subsystem + " + " + reference + ", " + // + className + ".class);"); + } else { + // className = "Zstack" + name + "Sreq"; + // addImport(cmdPackage + "." + className); + + // String reference = camelCaseToConstant( + // command.name.substring(0, 1).toUpperCase() + command.name.substring(1)); + // out.println(" zstackFrameMap.put(ZSTACK_" + command.subsystem + " + " + reference + ", " + // + className + ".class);"); + + className = "Zstack" + name + "Srsp"; + addImport(cmdPackage + "." + className); + + String reference = camelCaseToConstant( + command.name.substring(0, 1).toUpperCase() + command.name.substring(1)); + out.println(" zstackFrameMap.put(ZSTACK_" + command.subsystem + " + " + reference + ", " + + className + ".class);"); + } + } + + out.println(" }"); + out.println(); + + out.println(" /**"); + out.println(" * Creates and {@link ZstackFrameResponse} from the incoming data."); + out.println(" *"); + out.println(" * @param data the int[] containing the ZStack data from which to generate the frame"); + out.println(" * @return the {@link ZstackFrameResponse} or null if the response can't be created."); + out.println(" */"); + out.println(" public static ZstackFrameResponse createFrame(int[] data) {"); + out.println(" if (data.length < 2) {"); + out.println(" return null;"); + out.println(" }"); + out.println(); + out.println(" int cmdId = ((data[0] & ZSTACK_SUBSYSTEM_MASK) << 8) + data[1];"); + out.println(" Class zstackClass = zstackFrameMap.get(cmdId);"); + out.println(); + out.println(" if (zstackClass == null) {"); + out.println(" return null;"); + out.println(" }"); + out.println(); + out.println(" Constructor ctor;"); + out.println(" try {"); + out.println(" ctor = zstackClass.getConstructor(int[].class);"); + out.println(" return (ZstackFrameResponse) ctor.newInstance(data);"); + out.println( + " } catch (SecurityException | NoSuchMethodException | IllegalArgumentException | InstantiationException"); + out.println(" | IllegalAccessException | InvocationTargetException e) {"); + out.println(" logger.debug(\"Error creating instance of ZstackCommand\", e);"); + out.println(" }"); + out.println(); + out.println(" return null;"); + out.println(" }"); + out.println(); + + out.println(); + out.println("}"); + + out.flush(); + + File packageFile = new File(sourceRootPath + zstackCommandPackage.replace(".", "/")); + PrintWriter outFile = getClassOut(packageFile, "ZstackFrameFactory"); + + outputCopywrite(outFile); + + outFile.println("package " + zstackCommandPackage + ";"); + outFile.println(); + outputImports(outFile); + + outFile.println(); + outFile.print(stringWriter.toString()); + + outFile.flush(); + outFile.close(); + + out.close(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/ZstackAutocoder.java b/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/ZstackAutocoder.java new file mode 100644 index 0000000000..3361903edb --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/ZstackAutocoder.java @@ -0,0 +1,256 @@ +/** + * 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.dongle.zstack.autocode; + +import java.io.File; +import java.io.FileNotFoundException; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import com.zsmartsystems.zigbee.dongle.zstack.autocode.xml.Command; +import com.zsmartsystems.zigbee.dongle.zstack.autocode.xml.Command.ZstackRequestType; +import com.zsmartsystems.zigbee.dongle.zstack.autocode.xml.Enumeration; +import com.zsmartsystems.zigbee.dongle.zstack.autocode.xml.Parameter; +import com.zsmartsystems.zigbee.dongle.zstack.autocode.xml.Protocol; +import com.zsmartsystems.zigbee.dongle.zstack.autocode.xml.Structure; +import com.zsmartsystems.zigbee.dongle.zstack.autocode.xml.Value; + +/** + * Autocoder to generate Java class files for Z-Stack dongle + * + * @author Chris Jackson + * + */ +public class ZstackAutocoder { + public static void main(final String[] args) { + + Protocol protocol; + try { + // Load the class definitions + File fXmlFile = new File("src/main/resources/zstack_protocol.xml"); + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + Document doc = dBuilder.parse(fXmlFile); + doc.getDocumentElement().normalize(); + + NodeList nList = doc.getElementsByTagName("protocol"); + protocol = (Protocol) processNode(nList.item(0)); + + } catch (Exception e) { + e.printStackTrace(); + return; + } + + System.out.println("Generating code..."); + + try { + new CommandGenerator().go(protocol); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } + } + + private static Object processNode(Node node) { + System.out.println("\nCurrent Element :" + node.getNodeName()); + + NodeList nodes = node.getChildNodes(); + + switch (node.getNodeName()) { + case "protocol": + Protocol protocol = new Protocol(); + protocol.commands = new ArrayList<>(); + protocol.structures = new ArrayList<>(); + protocol.enumerations = new ArrayList<>(); + + for (int temp = 0; temp < nodes.getLength(); temp++) { + if (nodes.item(temp).getNodeName().equals("command")) { + protocol.commands.add((Command) processNode(nodes.item(temp))); + } + if (nodes.item(temp).getNodeName().equals("structure")) { + protocol.structures.add((Structure) processNode(nodes.item(temp))); + } + if (nodes.item(temp).getNodeName().equals("enum")) { + protocol.enumerations.add((Enumeration) processNode(nodes.item(temp))); + } + } + return protocol; + case "command": + Command command = new Command(); + + for (int temp = 0; temp < nodes.getLength(); temp++) { + if (nodes.item(temp).getNodeName().equals("name")) { + command.name = nodes.item(temp).getTextContent().trim(); + } + if (nodes.item(temp).getNodeName().equals("id")) { + String id = nodes.item(temp).getTextContent(); + if (id.startsWith("0x")) { + command.id = Integer.parseInt(id.substring(2), 16); + } else { + command.id = Integer.parseInt(id.substring(2)); + } + } + if (nodes.item(temp).getNodeName().equals("description")) { + command.description = nodes.item(temp).getTextContent().trim(); + } + if (nodes.item(temp).getNodeName().equals("subsystem")) { + command.subsystem = nodes.item(temp).getTextContent().trim(); + } + if (nodes.item(temp).getNodeName().equals("type")) { + command.requestType = ZstackRequestType.valueOf(nodes.item(temp).getTextContent().trim()); + } + + if (nodes.item(temp).getNodeName().equals("request")) { + if (command.request_parameters == null) { + command.request_parameters = new ArrayList<>(); + } + command.request_parameters = (List) processNode(nodes.item(temp)); + } + if (nodes.item(temp).getNodeName().equals("response")) { + if (command.response_parameters == null) { + command.response_parameters = new ArrayList<>(); + } + command.response_parameters = (List) processNode(nodes.item(temp)); + } + } + System.out.println("Done: Command - " + command.name); + return command; + case "request": + case "response": + case "parameters": + List parameters = new ArrayList<>(); + + for (int temp = 0; temp < nodes.getLength(); temp++) { + if (nodes.item(temp).getNodeName().equals("parameter")) { + parameters.add((Parameter) processNode(nodes.item(temp))); + } + } + return parameters; + case "parameter": + Parameter parameter = new Parameter(); + for (int temp = 0; temp < nodes.getLength(); temp++) { + if (nodes.item(temp).getNodeName().equals("data_type")) { + parameter.data_type = nodes.item(temp).getTextContent(); + Element dataTypeElement = (Element) nodes.item(temp); + parameter.multiple = dataTypeElement.getAttribute("multiple").equalsIgnoreCase("true"); + } + if (nodes.item(temp).getNodeName().equals("name")) { + parameter.name = nodes.item(temp).getTextContent().trim(); + } + if (nodes.item(temp).getNodeName().equals("description")) { + parameter.description = nodes.item(temp).getTextContent().trim(); + } + if (nodes.item(temp).getNodeName().equals("auto_size")) { + parameter.auto_size = nodes.item(temp).getTextContent().trim(); + } + if (nodes.item(temp).getNodeName().equals("display")) { + String display = nodes.item(temp).getTextContent().trim(); + if (display.contains("[") && display.contains("]")) { + parameter.displayType = display.substring(0, display.indexOf('[')); + parameter.displayLength = Integer + .parseInt(display.substring(display.indexOf('[') + 1, display.indexOf(']'))); + } + } + } + System.out.println("Done: Parameter - " + parameter.name); + return parameter; + case "structure": + Structure structure = new Structure(); + structure.parameters = new ArrayList<>(); + + for (int temp = 0; temp < nodes.getLength(); temp++) { + if (nodes.item(temp).getNodeName().equals("name")) { + structure.name = nodes.item(temp).getTextContent().trim(); + } + if (nodes.item(temp).getNodeName().equals("description")) { + structure.description = nodes.item(temp).getTextContent().trim(); + } + if (nodes.item(temp).getNodeName().equals("subsystem")) { + structure.subsystem = nodes.item(temp).getTextContent().trim(); + } + + if (nodes.item(temp).getNodeName().equals("parameters")) { + structure.parameters = (List) processNode(nodes.item(temp)); + } + } + System.out.println("Done: Structure - " + structure.name); + return structure; + case "enum": + Enumeration enumeration = new Enumeration(); + enumeration.values = new ArrayList(); + + for (int temp = 0; temp < nodes.getLength(); temp++) { + if (nodes.item(temp).getNodeName().equals("name")) { + enumeration.name = nodes.item(temp).getTextContent().trim(); + } + if (nodes.item(temp).getNodeName().equals("data_type")) { + enumeration.data_type = nodes.item(temp).getTextContent().trim(); + } + if (nodes.item(temp).getNodeName().equals("description")) { + enumeration.description = nodes.item(temp).getTextContent().trim(); + } + if (nodes.item(temp).getNodeName().equals("values")) { + Element dataTypeElement = (Element) nodes.item(temp); + enumeration.fullyDefined = "true" + .equalsIgnoreCase(dataTypeElement.getAttribute("fully_defined")); + enumeration.values = (List) processNode(nodes.item(temp)); + } + if (nodes.item(temp).getNodeName().equals("format")) { + enumeration.format = nodes.item(temp).getTextContent().trim(); + } + if (nodes.item(temp).getNodeName().equals("subsystem")) { + enumeration.subsystem = nodes.item(temp).getTextContent().trim(); + } + } + System.out.println("Done: Enum - " + enumeration.name); + return enumeration; + case "values": + List values = new ArrayList<>(); + + for (int temp = 0; temp < nodes.getLength(); temp++) { + if (nodes.item(temp).getNodeName().equals("value")) { + values.add((Value) processNode(nodes.item(temp))); + } + } + return values; + case "value": + Value value = new Value(); + for (int temp = 0; temp < nodes.getLength(); temp++) { + if (nodes.item(temp).getNodeName().equals("name")) { + value.name = nodes.item(temp).getTextContent(); + } + if (nodes.item(temp).getNodeName().equals("enum_value")) { + String id = nodes.item(temp).getTextContent().trim(); + if (id.startsWith("0x")) { + value.enum_value = Integer.parseInt(id.substring(2), 16); + } else { + value.enum_value = Integer.parseInt(id); + } + } + if (nodes.item(temp).getNodeName().equals("description")) { + value.description = nodes.item(temp).getTextContent().trim(); + } + } + System.out.println("Done: Value - " + value.name); + return value; + default: + System.out.println("Uknown node " + node.getNodeName()); + break; + } + + return null; + } + +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/xml/Command.java b/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/xml/Command.java new file mode 100644 index 0000000000..cdf11509cb --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/xml/Command.java @@ -0,0 +1,32 @@ +/** + * 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.dongle.zstack.autocode.xml; + +import java.util.List; + +/** + * + * @author Chris Jackson + * + */ +public class Command { + public String name; + public String subsystem; + public Integer id; + public String description; + public ZstackRequestType requestType; + public List request_parameters; + public List response_parameters; + + public enum ZstackRequestType { + SYNC, + ASYNC, + ASYNCMD, + BOOT + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/xml/Enumeration.java b/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/xml/Enumeration.java new file mode 100644 index 0000000000..6ed7e71419 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/xml/Enumeration.java @@ -0,0 +1,25 @@ +/** + * 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.dongle.zstack.autocode.xml; + +import java.util.List; + +/** + * + * @author Chris Jackson + * + */ +public class Enumeration { + public String name; + public String description; + public String subsystem; + public String format; + public List values; + public String data_type; + public boolean fullyDefined; +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/xml/Parameter.java b/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/xml/Parameter.java new file mode 100644 index 0000000000..757f2c68fc --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/xml/Parameter.java @@ -0,0 +1,23 @@ +/** + * 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.dongle.zstack.autocode.xml; + +/** + * + * @author Chris Jackson + * + */ +public class Parameter { + public String data_type; + public String name; + public String description; + public String auto_size; + public Boolean multiple; + public String displayType; + public int displayLength; +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/xml/Protocol.java b/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/xml/Protocol.java new file mode 100644 index 0000000000..6d5384f150 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/xml/Protocol.java @@ -0,0 +1,21 @@ +/** + * 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.dongle.zstack.autocode.xml; + +import java.util.List; + +/** + * + * @author Chris Jackson + * + */ +public class Protocol { + public List commands; + public List structures; + public List enumerations; +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/xml/Structure.java b/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/xml/Structure.java new file mode 100644 index 0000000000..a871fb216d --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/xml/Structure.java @@ -0,0 +1,22 @@ +/** + * 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.dongle.zstack.autocode.xml; + +import java.util.List; + +/** + * + * @author Chris Jackson + * + */ +public class Structure { + public String name; + public String description; + public List parameters; + public String subsystem; +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/xml/Value.java b/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/xml/Value.java new file mode 100644 index 0000000000..5ba82665ee --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/autocode/xml/Value.java @@ -0,0 +1,19 @@ +/** + * 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.dongle.zstack.autocode.xml; + +/** + * + * @author Chris Jackson + * + */ +public class Value { + public String name; + public String description; + public Integer enum_value; +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/resources/zstack_protocol.xml b/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/resources/zstack_protocol.xml new file mode 100644 index 0000000000..72e11368c3 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack.autocode/src/main/resources/zstack_protocol.xml @@ -0,0 +1,3121 @@ + + + + RPC_SREQ_ERROR + RPC + 0x00 + When the ZNP cannot recognize an SREQ command from the host processor, the following SRSP is returned. + + SYNC + + + ZstackSreqErrorCode + ErrorCode + The error code maps to one of the enumerated values. + + + uint8 + ReqCmd0 + hex[2] + The Cmd0 value of the processed SREQ + + + uint8 + ReqCmd1 + hex[2] + The Cmd1 value of the processed SREQ + + + + + + + SYS_RESET_REQ + SYS + 0x00 + This command is issued by the application processor to reset the CC2530 device. The reset is achieved + through an internal watchdog reset on the CC2530. Note that the hardware reset interface is recommended over using + this interface. + + ASYNCMD + + + ZstackResetType + Type + This requests a target device reset (0) or serial bootloader reset (1). If the target device does not + support serial bootloading, bootloader reset commands are ignored and no response is sent from the target. + + + + + + + + + SYS_VERSION + SYS + 0x02 + This command is used to request for the device’s version string. + SYNC + + + + + uint8 + TransportRev + Transport protocol revision + + + uint8 + Product + Product Id + + + uint8 + MajorRel + Software major release number + + + uint8 + MinorRel + Software minor release number + + + uint8 + HwRev + Hardware revision number. + + + + + + SYS_RESET_IND + SYS + 0x80 + This command is generated by the CC2530 device automatically immediately after a reset. + ASYNC + + + ZstackResetReason + Reason + One of the following values indicating the reason for the reset. Power=0x00, External=0x01, + Watchdog=0x02 + + + + uint8 + TransportRev + Transport protocol revision + + + uint8 + Product + Product Id + + + uint8 + MajorRel + Software major release number + + + uint8 + MinorRel + Software minor release number + + + uint8 + HwRev + Hardware revision number. + + + + + + + + SYS_PING + SYS + 0x01 + This command issues PING requests to verify if a device is active and check the capability of the device. + + SYNC + + + + + uint16 + Capabilities + This field represents the interfaces that this device can handle (compiled into the device). + + hex[4] + + + + + + SYS_VERSION + SYS + 0x02 + This command issues PING requests to verify if a device is active and check the capability of the device. + + SYNC + + + + + uint8 + TransportRev + Transport protocol revision + + + uint8 + Product + Product Id + + + uint8 + MajorRel + Software major release number + + + uint8 + MinorRel + Software minor release number + + + uint8 + MaintRel + Software maintenance release number + + + + + + SYS_SET_EXT_ADDR + SYS + 0x03 + This command is used to set the extended address of the device. + SYNC + + + IeeeAddress + ExtAddress + The device’s extended address. + + + + + ZstackResponseCode + Status + Status is either Success (1) or Failure (0) + + + + + + SYS_GET_EXT_ADDR + SYS + 0x04 + This command is used to set the extended address of the device. + SYNC + + + + + IeeeAddress + ExtAddress + The device’s extended address. + + + + + + SYS_OSAL_NV_READ + SYS + 0x08 + This command is used to read a single memory item from the target non-volatile memory. The command + accepts an attribute Id value and data offset and returns the memory value present in the target for the specified + attribute Id. + + SYNC + + + ZstackConfigId + id + The Id of the NV item. + + + uint8 + Offset + Number of bytes offset from the beginning or the NV value. + + + + + ZstackResponseCode + status + Status is either Success (0) or Failure (1). + + + uint8 + Len + Value + Length of the NV value. + + + uint8[] + Value + Value of the NV item. + + + + + + SYS_OSAL_NV_WRITE + SYS + 0x09 + This command is used to write to a particular item in non-volatile memory. The command accepts an + attribute Id, data offset, data length, and attribute value. The attribute value is written to the location specified + for the attribute Id in the target. + + SYNC + + + ZstackConfigId + Id + The Id of the NV item. + + + uint8 + Offset + Number of bytes offset from the beginning or the NV value. + + + uint8 + Length + Value + Length of the NV value. + + + uint8[] + Value + Value of the NV item. + + + + + ZstackResponseCode + status + Status is either Success (0) or Failure (1). + + + + + + SYS_SET_TX_POWER + SYS + 0x14 + This command is used by the tester to set the target system radio transmit power. The returned TX power + is the actual setting applied to the radio – nearest characterized value for the specific radio. + + SYNC + + + int8 + TxPower + Requested TX power setting, in dBm. + + + + + int8 + TxPower + Requested TX power setting, in dBm. + + + + + + SYS_ZDIAGS_INIT_STATS + SYS + 0x17 + This command is used to initialize the statistics table in NV memory. + SYNC + + + + + ZstackResponseCode + Status + Status is either Success (0) or Failure (1). + + + + + + SYS_ZDIAGS_CLEAR_STATS + SYS + 0x18 + This command is used to clear the statistics table. To clear data in NV (including the Boot Counter) the + clearNV flag shall be set to TRUE. + + SYNC + + + boolean + clearNV + TRUE – Clears statistics in NV memory including Boot Counter. + FALSE – Clears statistics in RAM only. + Boot Counter is preserved. + + + + + + uint32 + SysClock + Milliseconds since last reset. + + + + + + SYS_ZDIAGS_GET_STATS + SYS + 0x19 + This command is used to read a specific system (attribute) ID statistics and/or metrics value. + + SYNC + + + ZstackDiagnosticAttribute + AttributeID + System Diagnostics (ZDiags) attribute ID, as defined in ZDiags.h module. + + + + + uint32 + AttributeValue + Value of the requested attribute. + + + + + + SYS_ZDIAGS_RESTORE_STATS_NV + SYS + 0x1A + This command is used to restore the statistics table from NV into the RAM table. + SYNC + + + ZstackDiagnosticAttribute + AttributeID + System Diagnostics (ZDiags) attribute ID, as defined in ZDiags.h module. + + + + + ZstackResponseCode + Status + Status is either Success (0) or Failure (1). + + + + + + SYS_ZDIAGS_SAVE_STATS_TO_NV + SYS + 0x1B + This command is used to save the statistics table from RAM to NV. + SYNC + + + + + uint32 + SysClock + Milliseconds since last reset. + + + + + + + + + + + AF_REGISTER + AF + 0x00 + This command enables the host processor to register an application’s endpoint description (and its simple + descriptor). Multiple endpoints may be registered with the AF by making multiple calls to AF_REGISTER. This could be + useful in the case where the device needs to support multiple application profiles, where each AF_REGISTER call would + register a unique endpoint description per application profile. + + SYNC + + + uint8 + EndPoint + hex[2] + Specifies the endpoint of this simple descriptor. + + + uint16 + AppProfId + hex[4] + Specifies the profile id of the application. + + + uint16 + AppDeviceId + Specifies the device description id for this endpoint. + + + uint8 + AppDevVer + Specifies the device version number. + + + uint8 + LatencyReq + Specifies latency. For ZigBee the only applicable value is 0x00. + 0x00-No latency 0x01-fast beacons + 0x02-slow beacons + + + + uint8 + AppNumInClusters + AppInClusterList + the number of Input cluster Ids following in the AppInClusterList + + + uint16[] + AppInClusterList + Specifies the list of Input Cluster Ids (2 bytes each). + hex[4] + + + uint8 + AppNumOutClusters + AppOutClusterList + Specifies the number of Output cluster Ids following in the AppOutClusterList. + + + uint16[] + AppOutClusterList + Specifies the list of Output Cluster Ids (2 bytes each) + hex[4] + + + + + ZstackResponseCode + Status + Status is either Success (0) or Failure (1). + + + + + + AF_DATA_REQUEST + AF + 0x01 + This command is used by the App processor to build and send a message through AF layer. + SYNC + + + uint16 + DstAddr + hex[4] + Short address of the destination device. + + + uint8 + DestEndpoint + hex[2] + Endpoint of the destination device. + + + uint8 + SrcEndpoint + hex[2] + Endpoint of the source device. + + + uint16 + ClusterID + hex[4] + Specifies the cluster ID. + + + uint8 + TransID + hex[2] + Specifies the transaction sequence number of the message. The corresponding AF_DATA_CONFIRM will have + the same TransID. This can be useful if the application wishes to match up AF_DATA_REQUESTs with AF_DATA_CONFIRMs. + + + + AfDataOptions + Options + The transmit options field is organized as a bitmask. The following enumerates the values for the + various supported bitmasks. For example, a value of 0x10 means that bit 4 is set. + + + + uint8 + Radius + Specifies the list of Input Cluster Ids ( 2bytes each ). + + + uint8 + Len + Data + Length of the data. + + + uint8[] + Data + 0-99 bytes data. Without any security (99 bytes), with NWK security (81 bytes), with NWK and APS + security (64 bytes). + + + + + + ZstackResponseCode + Status + Status is either Success (0) or Failure (1). + + + + + + AF_DATA_CONFIRM + AF + 0x80 + This command is sent by the device to the user after it receives an AF_DATA_REQUEST. For each + AF_DATA_REQUEST, a AF_DATA_CONFIRM is always returned. If APS acknowledgement was used for the AF_DATA_REQUEST, the + confirm carries the status of whether the APS acknowledgement was received or not (ZApsNoAck – 0xb7). If APS + acknowledgement was not used, then the confirm carries the status of whether the MAC acknowledgement (“next hop” + acknowledgment) was received or not (ZMacNoACK – 0xe9). This also applies to packets that are sent using + AF_DATA_REQUEST_EXT and AF_DATA_STORE. For APS fragmented packets, the value of the configuration item + ZCD_NV_APSF_WINDOW_SIZE determines when an AF_DATA_CONFIRM that carries the status of the APS acknowledgement is + received. + + ASYNC + + + ZstackResponseCode + Status + Status is either Success (0) or Failure (1). + + + uint8 + Endpoint + hex[2] + Endpoint of the device. + + + uint8 + TransId + hex[2] + Specifies the transaction sequence number of the message. + + + + + + + + AF_INCOMING_MSG + AF + 0x81 + This callback message is in response to incoming data to any of the registered endpoints on this device. + + ASYNC + + + uint16 + GroupId + hex[4] + Specifies the group ID of the device. + + + uint16 + ClusterId + hex[4] + Specifies the cluster ID. + + + uint16 + SrcAddr + hex[4] + Specifies the ZigBee network address of the source device sending the message. + + + uint8 + SrcEndpoint + hex[2] + Specifies the source endpoint of the message. + + + uint8 + DestEndpoint + hex[2] + Specifies the destination endpoint of the message. + + + boolean + WasBroadcast + Specifies if the message was a broadcast or not. + + + uint8 + LinkQuality + Indicates the link quality measured during reception. + + + boolean + SecurityUse + Specifies if the security is used or not. + + + uint32 + TimeStamp + hex[8] + Specifies the timestamp of the message. + + + uint8 + SeqNumber + hex[2] + Specifies transaction sequence number of the message. + + + uint8 + Len + Data + Specifies the length of the data. + + + uint8[] + Data + Contains 0 to 99 bytes of data. Without any security (99 bytes), with NWK security (81 bytes), with NWK + and APS security (64 bytes). + + + + + + + + + + ZDO_SET_LINK_KEY + ZDO + 0x23 + This command sets the application link key for a given device. + SYNC + + + uint16 + ShortAddr + hex[4] + Specifies the short address of the pair device of the link key. + + + IeeeAddress + IeeeAddr + Specifies the IEEE address of the pair device of the link key + + + ZigBeeKey + LinkKeyData + 128 bit link key data of the device. + + + + + ZstackResponseCode + Status + 0x00 – Success. 0x01 – Fail to add to address manager. 0x11 – Security manager key table full + + + + + + + ZDO_REMOVE_LINK_KEY + ZDO + 0x24 + This command removes the application link key of a given device. + SYNC + + + IeeeAddress + IeeeAddr + Specifies the IEEE address of the pair device of the link key + + + + + ZstackResponseCode + Status + 0x00 – Success. 0xC8 – Unknown device. + + + + + + ZDO_GET_LINK_KEY + ZDO + 0x25 + This command retrieves the application link key of a given device. + SYNC + + + IeeeAddress + IeeeAddr + Specifies the IEEE address of the pair device of the link key + + + + + ZstackResponseCode + Status + 0x00 – Success. 0xC8 – Unknown device. + + + IeeeAddress + IeeeAddr + Specifies the IEEE address of the pair device of the link key + + + ZigBeeKey + LinkKeyData + Link key data of the device + + + + + + ZDO_NWK_DISCOVERY_REQ + ZDO + 0x26 + This command is used to initiate a network discovery (active scan). + SYNC + + + uint32 + ScanChannels + Bit mask for channels to scan. + + + uint8 + ScanDuration + A value used to calculate the length of time to spend scanning each channel + + + + + ZstackResponseCode + Status + Success (0) + Invalid_Parameter (0x02). + ZNwkInvalidRequest (0xC2) if the device is already on a network. + User ZDO_MGMT_NWK_DISC_REQ instead. Or leave the network first, then + initiate the request. + MAC_SCAN_IN_PROGRESS + (0xFC) if a channel change is in progress. + MAC_NO_RESOURCE (0x1A) if the operation could not complete because no + memory resource were available. + + + + + + + ZDO_MSG_CB_REGISTER + ZDO + 0x3E + This command registers for a ZDO callback. + SYNC + + + uint16 + ClusterId + hex[4] + Specifies the ZDO Cluster Id for which to receive a ZDO callback. + + + + + ZstackResponseCode + Status + 0x00 – Success. + + + + + + ZDO_STARTUP_FROM_APP + ZDO + 0x40 + This command starts the device in the network. + SYNC + + + uint16 + StartDelay + Specifies the time delay before the device starts in milliseconds. + + + + + ZstackResponseCode + Status + This field indicates either SUCCESS (0) or FAILURE (1). + + + + + + ZDO_STATE_CHANGE_IND + ZDO + 0xC0 + This callback message indicates the ZDO state change. + ASYNC + + + ZstackZdoState + State + Specifies the changed ZDO state. An enumerated list starting from 0. + + + + + + + + ZDO_LEAVE_IND + ZDO + 0xC9 + This message is an indication to inform the host of a device leaving the network. + ASYNC + + + uint16 + SrcAddr + hex[4] + Short address (LSB-MSB) of the source of the leave indication. + + + IeeeAddress + ExtAddr + Extended address (LSB-MSB) of the source of the leave indication. + + + boolean + Request + Boolean, TRUE = request, FALSE = indication. + + + boolean + Remove + Boolean, TRUE = remove children. + + + boolean + Rejoin + Boolean, TRUE = rejoin. + + + + + + + + ZDO_TC_DEV_IND + ZDO + 0xCA + This message is a ZDO callback for TC Device Indication. This is an indication that the TC has delivered + the key to a recently joined device. + + ASYNC + + + uint16 + SrcAddr + hex[4] + Source network Address + + + IeeeAddress + ExtAddr + IEEE Address of the source + + + uint16 + ParentAddr + hex[4] + Network address of the parent + + + + + + + + ZDO_MSG_CB_INCOMING + ZDO + 0xFF + This message is a ZDO callback for a Cluster Id that the host requested to receive with a ZDO_ + MSG_CB_REGISTER request. + + ASYNC + + + uint16 + SrcAddr + hex[4] + Short address (LSB-MSB) of the source of the ZDO message. + + + boolean + WasBroadcast + This field indicates whether or not this ZDO message was broadcast. + + + uint16 + ClusterId + hex[4] + The ZDO Cluster Id of this message. + + + boolean + SecurityUse + N/A – not used. + + + uint8 + SeqNumber + hex[2] + The sequence number of this ZDO message. + + + uint16 + DstAddr + hex[4] + The MAC destination short address (LSB-MSB) of the ZDO message. + + + uint8[] + Data + The data that corresponds to the Cluster Id of the message + + + + + + + + + + + ZB_READ_CONFIGURATION + SAPI + 0x04 + This command is used to get a configuration property from non-volatile memory. + SYNC + + + ZstackConfigId + ConfigId + Specifies the Identifier for the configuration property. + + + + + ZstackResponseCode + Status + This field indicates either SUCCESS (0) or FAILURE (1). + + + ZstackConfigId + ConfigId + Specifies the Identifier for the configuration property. + + + uint8 + Len + Value + Specifies the size of the Value buffer in bytes. + + + uint8[] + Value + Buffer to hold the configuration property. + + + + + + ZB_WRITE_CONFIGURATION + SAPI + 0x05 + This command is used to write a configuration property to nonvolatile memory. + SYNC + + + ZstackConfigId + ConfigId + Specifies the Identifier for the configuration property. + + + uint8 + Len + Specifies the size of the Value buffer in bytes. + Value + + + uint8[] + Value + Buffer to hold the configuration property. + + + + + ZstackResponseCode + Status + This field indicates either SUCCESS (0) or FAILURE (1). + + + + + + ZB_GET_DEVICE_INFO + SAPI + 0x06 + This command retrieves a Device Information Property. + SYNC + + + uint8 + Param + The Identifier for the device information. + + + + + uint8 + Param + The Identifier for the device information. + + + uint16 + Value + A buffer to hold the device information + + + + + + + + + UTIL_GET_DEVICE_INFO + UTIL + 0x00 + This command is used to retrieve the device info. + SYNC + + + + + ZstackResponseCode + Status + Status is a one byte field and is either success(0) or fail(1). The fail status is returned if the + address value in the command message was not within the valid range. + + + + IeeeAddress + IeeeAddress + IEEE address of the device. + + + uint16 + ShortAddr + hex[4] + Short address of the device. + + + uint8 + DeviceType + Indicates device type, where bits 0 to 2 indicate the capability for the device to operate as a + coordinator, router, or end device, respectively. + + + + ZstackZdoState + DeviceState + Indicates the state of the device. + + + uint8 + NumAssocDevices + Specifies the number of devices being associated to the target device. + AssocDevicesList + + + uint16[] + AssocDevicesList + Array of 16-bits specifies the network address associated with the device. + + + + + + UTIL_GET_NV_INFO + UTIL + 0x01 + This command is used to read a block of parameters from non-volatile storage of the target device. + + SYNC + + + + + uint8 + Status + A value of zero indicates success. Failure is indicated by a non-zero value, representing a bit mask of + each item that failed to be retrieved from NV memory. Bit0 is used for the first item (IEEEAddress), bit1 for the + second item (ScanChannels), and so forth. Data values for failed items are returned as one or more bytes of 0xFF, + the typical value read from erased NV memory. + + + + IeeeAddress + IeeeAddress + IEEE address of the device. + + + uint32 + ScanChannels + This represents a bit-mask of channels to be scanned when starting the device. + + + uint16 + PanId + hex[4] + Specifies the Pan Id to start or join. Set to 0xFFFF to select a PAN after scanning. + + + uint8 + SecurityLevel + This specifies the network messaging security level, zero disables security. + + + ZigBeeKey + PreConfigKey + This specifies the pre-configured security key. + + + + + + UTIL_SET_PANID + UTIL + 0x02 + Store a PanId value into Non-Volatile memory to be used the next time the target device resets. + + SYNC + + + uint16 + PanId + hex[4] + PanId that will be set. + + + + + ZstackResponseCode + Status + Status is either Success (0) or Failure (1). + + + + + + UTIL_SET_CHANNELS + UTIL + 0x03 + This command is used to store a channel select bit-mask into Non-Volatile memory to be used the next time + the target device resets. + + SYNC + + + uint32 + Channels + A bit-mask representing the channel(s) to scan the next time the target device resets. + + + + + ZstackResponseCode + Status + Status is either Success (0) or Failure (1). + + + + + + UTIL_SET_SECLEVEL + UTIL + 0x04 + This command is used to store a channel select bit-mask into Non-Volatile memory to be used the next time + the target device resets. + + SYNC + + + uint8 + SecLevel + Security level to use the next time the target device resets. Zero is used to disable security. + + + + + + ZstackResponseCode + Status + Status is either Success (0) or Failure (1). + + + + + + UTIL_SET_PRECFGKEY + UTIL + 0x05 + This command is used to store a pre-configured key array into Non-Volatile memory to be used the next + time the target device resets. + + SYNC + + + ZigBeeKey + PreCfgKey + An array representing the pre-configured key to use the next time the target device resets. + + + + + + ZstackResponseCode + Status + Status is either Success (0) or Failure (1). + + + + + + UTIL_LED_CONTROL + UTIL + 0x09 + This command is used by the tester to control the LEDs on the board. + SYNC + + + uint8 + LedId + The LED number. + + + boolean + Mode + 0: OFF, 1: ON. + + + + + ZstackResponseCode + Status + Status is either Success (0) or Failure (1). + + + + + + UTIL_APSME_LINK_KEY_DATA_GET + UTIL + 0x44 + This command retrieves APS link key data, Tx and Rx frame counters. + SYNC + + + IeeeAddress + ExtAddr + The extended address for which to get the link key data. + + + + + ZstackResponseCode + Status + The ZStatus_t returned by the proxy call to APSME_LinkKeyNVIdGet(). + + + ZigBeeKey + SecKey + On success, the security key looked up; otherwise N/A. + + + uint32 + TxFrmCntr + hex[8] + On success, the TX frame counter; otherwise N/A. + + + uint32 + RxFrmCntr + hex[8] + On success, the RX frame counter; otherwise N/A. + + + + + + UTIL_APSME_LINK_KEY_NV_ID_GET + UTIL + 0x45 + This command is a proxy call to the APSME_LinkKeyNvIdGet() function. + SYNC + + + IeeeAddress + ExtAddr + The extended address for which to get the link key NV Id. + + + + + ZstackResponseCode + Status + The ZStatus_t returned by the proxy call to APSME_LinkKeyNVIdGet(). + + + uint16 + LinkKeyNvId + On success, link key NV ID. Otherwise 0xFFFF + + + + + + + MAC_SCAN_REQ + MAC + 0x0C + This command is used to send a request to the device to perform a network scan. + SYNC + + + uint32 + ScanChannels + This represents a bit-mask of channels to be scanned when starting the device: + NONE = 0x00000000, + ALL_CHANNELS = 0x07FFF800, + CHANNEL 11 = 0x00000800, + CHANNEL 12 = 0x00001000, + CHANNEL 13 = 0x00002000, + CHANNEL 14 = + 0x00004000, + CHANNEL 15 = 0x00008000, + CHANNEL 16 = 0x00010000, + CHANNEL 17 = 0x00020000, + CHANNEL 18 = 0x00040000, + CHANNEL_19 = 0x00080000, + CHANNEL 20 = 0x00100000, + CHANNEL 21 = 0x00200000, + CHANNEL 22 = 0x00400000, + CHANNEL 23 = + 0x00800000, + CHANNEL 24 = 0x01000000 + CHANNEL 25 = 0x02000000, + CHANNEL 26 = 0x04000000 + + + + uint8 + ScanType + Specifies the scan type: + + + uint8 + ScanDuration + Duration of the scan - The exponent used in the scan duration calculation. + + + uint8 + ChannelPage + The channel page on which to perform the scan. + + + uint8 + KeySource + Key Source of this data frame. + + + uint8 + SecurityLevel + Security Level of this data frame: + + + uint8 + KeyIdMode + Key Id Mode of this data frame: + + + uint8 + KeyIndex + Key Index of this data frame. + + + + + + + + + + + + + + APP_CNF_SET_ALLOWREJOIN_TC_POLICY + APP_CNF + 0x03 + Sets the AllowRejoin TC policy. + SYNC + + + boolean + AllowRejoin + This value specifies whether or not the Trust Center allows devices to rejoin. + + + + + ZstackResponseCode + Status + Status is either Success (0) or Failure (1). + + + + + + APP_CNF_BDB_ADD_INSTALLCODE + APP_CNF + 0x04 + Add a preconfigured key (plain key or IC) to Trust Center device. + SYNC + + + ZstackInstallCodeFormat + InstallCodeFormat + This value specifies the format in which the install code is being added. The following list contains the values corresponding to the supported formats: +0x01 Install Code + CRC +0x02 Key derived from Install Code + + + IeeeAddress + IeeeAddress + Full IEEE address for the device joining the network + + + ZigBeeKey + InstallCode + 16 Bytes for the Key derived from the IC. +18 Bytes for the Install Code +CRC + + + + + ZstackResponseCode + Status + Status values: +0x00 Success. +0x01 Failure (IC not supported) 0x02 Invalid parameter (bad CRC). + + + + + + APP_CNF_BDB_SET_JOINUSESINSTALLCODEKEY + APP_CNF + 0x06 + Sets the policy to mandate or not the usage of an Install Code upon joining. + SYNC + + + boolean + JoinUsesInstallCodeKey + If it is equal to TRUE and the installation code derived link key is not stored, the Trust Center SHALL + terminate the procedure for adding a new node into the network. If bdbJoinUsesInstall- CodeKey is equal to TRUE and + the installation code derived link key is stored, the Trust Center SHALL first find the entry in + apsDeviceKeyPairSet that corresponds to the joining node and then overwrite the LinkKey entry with the installation + code derived link key and set the KeyAttributes field to PROVISIONAL_KEY. The Trust Center MAY then set + OutgoingFrame- Counter to 0 and SHALL set IncomingFrameCounter to 0. If bdbJoinUsesInstallCodeKey is equal to + FALSE, the Trust Center SHALL first find the entry in apsDeviceKeyPairSet that corresponds to the joining node and + then overwrite the LinkKey entry with the default global Trust Center link key and set the KeyAttributes field to + PROVISIONAL_KEY. The Trust Center MAY then set OutgoingFrameCounter to 0 and SHALL set IncomingFrameCounter to 0. + + + + + + ZstackResponseCode + Status + Status is either Success (0) or Failure (1). + + + + + + APP_CNF_BDB_SET_ACTIVE_DEFAULT_CENTRALIZED_KEY + APP_CNF + 0x07 + Sets the policy to mandate or not the usage of an Install Code upon joining. + SYNC + + + ZstackCentralizedLinkKeyMode + CentralizedLinkKeyMode + This parameter controls which key will be used when performing association to a centralized network. + + + + uint8[] + InstallCode + Buffer with the key in any of its formats. + + + + + ZstackResponseCode + Status + 0x00 Success 0x01 Failure (IC not supported) 0x02 Invalid Parameters (bad CRC). + + + + + + APP_CNF_BDB_SET_TC_REQUIRE_KEY_EXCHANGE + APP_CNF + 0x09 + Sets the policy flag on Trust Center device to mandate or not the TCLK exchange procedure. + SYNC + + + boolean + TrustCenterRequireKeyExchange + The bdbTrustCenterRequireKeyExchange attribute specifies whether the Trust Center requires a joining + device to exchange its initial link key with a new link key generated by the Trust Center. If + bdbTrustCenterRequireKeyExchange is equal to TRUE, the joining node must undergo the link key exchange procedure; + failure to exchange the link key will result in the node being removed from the network. If + bdbTrustCenterRequireKeyExchange is equal to FALSE, the Trust Center will permit the joining node to remain on the + network without exchanging its initial link key. This attribute is used by ZigBee coordinator nodes. + + + + + + ZstackResponseCode + Status + Status is either Success (0) or Failure (1). + + + + + + APP_CNF_BDB_COMMISSIONING_NOTIFICATION + APP_CNF + 0x80 + Callback to receive notifications from BDB process. + ASYNC + + + ZstackBdbStatus + Status + Status of the commissioning mode being notified + + + ZstackBdbCommissioningMode + CommissioningMode + Commissioning mode for which the notification is done and to which the status is related + + + ZstackBdbRemainingCommissioningModes + RemainingCommissioningModes + Bitmask of the remaining commissioning modes after this notification. + + + + + + + + + SB_WRITE_CMD + SBL + 0x00 + + + BOOT + + + uint32 + Length32 + Payload + Payload length. + + + uint8[] + Payload + Payload data. + + + + + ZstackResponseCode + Status + 0x00 - SUCCESS 0x01 - FAILURE + + + + + + SB_HANDSHAKE_CMD + SBL + 0x04 + + + BOOT + + + + + ZstackResponseCode + Status + 0x00 - SUCCESS 0x01 - FAILURE + + + uint32 + BootloaderRevision + + + + uint8 + DeviceType + + + + uint32 + BufferLength + The maximum data size to use with Read / Write command + + + uint32 + PageSize + 0x800 – CC2538 flash page size + + + + + + + + AfDataOptions + uint8 + Options applied when sending frames + AF + + + AF_ACK_REQUEST + 0x10 + Set this bit to request APS acknowledgement for this packet + + + AF_DISCV_ROUTE + 0x20 + Set this bit to force route discovery if a routing table entry doesn’t exist + + + AF_EN_SECURITY + 0x40 + Set this bit to enable APS security for this packet. + + + AF_NO_ROUTING + 0x80 + Skip routing. + + + + + + ZstackConfigId + uint8 + Device specific configuration parameters. + SYS + + + ZCD_NV_EXTADDR + 0x0000 + + + + ZCD_NV_BOOTCOUNTER + 0x0001 + + + + ZCD_NV_STARTUP_OPTION + 0x0003 + This parameter controls the device startup options. Size: 1 byte; Default value: 0 + + + ZCD_NV_START_DELAY + 0x0004 + + + + ZCD_NV_POLL_RATE_OLD16 + 0x0035 + If this parameter is set to a non-zero value, a CC2530-ZNP device that is configured as an end- device + will wake up periodically with this duration to check for data with its parent device. This value is specified in + milliseconds and can range from 1 to 65000. + If this parameter is set to zero, the device will not automatically wake + up to poll for data. Instead, an external + trigger or an internal event (for example, via a software timer event) can + be used to wake up the device. + Size: 4 bytes; Default value: 2000 + + + + ZCD_NV_QUEUED_POLL_RATE + 0x0025 + When an end-device polls for data with its parent and finds that it does have data, it can poll again + with a shorter duration in case there is more data queued for it at its parent device. This value is specified in + milliseconds. This feature can be turned off by setting this value to zero. + Size: 2 bytes; Default value: 100 + + + + ZCD_NV_RESPONSE_POLL_RATE + 0x0026 + When an end-device sends a data packet, it can poll again with a shorter duration, specified by this + parameter, if the application is expecting to receive an application level packet in response. This value is + specified in milliseconds. This feature can be turned off by setting the value to zero. + Note: The setting of the + queued and response poll rates has to be done with caution if the device is sending and + receiving at the same time + or if the device is sending data too fast. + If the device is sending data too fast, setting a queued poll rate with a + higher duration than the sending rate will + cause the poll event to be continuously rescheduled to the future. Then + the device will never poll for data with + its parent and consequently it may miss any packets destined for it. + Size: 2 + bytes; Default value: 100 + + + + ZCD_NV_REJOIN_POLL_RATE + 0x0027 + + + + ZCD_NV_DATA_RETRIES + 0x0028 + + + + ZCD_NV_POLL_FAILURE_RETRIES + 0x0029 + The number of times an end-device will fail when communicating with its parent before invoking the + rejoin mechanism to find and join a new parent. + Size: 1 byte; Default value: 2. + + + + ZCD_NV_STACK_PROFILE + 0x002A + + + + ZCD_NV_INDIRECT_MSG_TIMEOUT + 0x002B + The amount of time (in seconds) that a router or coordinator device will buffer messages destined to + their end-device child nodes. It is recommended that this is at least greater than the poll rate (ZCD_NV_POLL_RATE) + to ensure that end-device will have a chance to wakeup and poll for the data. + Size: 1 byte; Default value: 7 + + + + ZCD_NV_ROUTE_EXPIRY_TIME + 0x002C + The amount of time (in seconds) for which a route must be idle (i.e. no packets are transmitted on that + route) before that routing entry is marked as expired. An expired entry may be deleted if the table is full and the + space is needed for another new routing entry. + This can be set to a special value of 0 to turn off route expiry. In + this case, route entries are not expired. + Size: 1 byte; Default value: 60. + + + + ZCD_NV_EXTPANID + 0x002D + This parameter configures the EXTENDED PAN ID in Z-Stack. The extended pan id is used to further + segregate the sub network(s) among a bigger PAN network. + + + + ZCD_NV_BCAST_RETRIES + 0x002E + The maximum number of retransmissions that a device will attempt when trying to transmit a broadcast + packet. The typical range is from 1 through 3. + Size: 1 byte; Default value: 2. + + + + ZCD_NV_PASSIVE_ACK_TIMEOUT + 0x002F + The amount of time (in units of 100milliseconds) a device will wait before retransmitting a broadcast + packet. The retransmission will not happen if the node hears that each of its neighbor nodes have all transmitted + that packet. + Size: 1 byte; Default value: 5 + + + + ZCD_NV_BCAST_DELIVERY_TIME + 0x0030 + The maximum amount of time (in units of 100ms) that it can take for a broadcast packet to propagate + through the entire network. This includes time for all retransmissions. + Note: This parameter must be set with + caution. It must be set to a value of at least + (ZCD_NV_BCAST_RETRIES + 1) * ZCD_NV_PASSIVE_ACK_TIMEOUT + To be safe, + the actual value should be higher than the above minimum by about 500ms or more. + Size: 1 byte; Default value: 30. + + + + ZCD_NV_NWK_MODE + 0x0031 + Holds the value of the network operational mode. The default value is NWK_MODE_MESH and must not be modified. + + + ZCD_NV_CONCENTRATOR_ENABLE + 0x0032 + + + + ZCD_NV_CONCENTRATOR_DISCOVERY + 0x0033 + + + + + ZCD_NV_CONCENTRATOR_RADIUS + 0x0034 + + + + + ZCD_NV_POLL_RATE + 0x0035 + If this parameter is set to a non-zero value, a CC2530-ZNP device that is configured as an end- device + will wake up periodically with this duration to check for data with its parent device. This value is specified in + milliseconds and can range from 1 to 65000. + If this parameter is set to zero, the device will not automatically wake + up to poll for data. Instead, an external + trigger or an internal event (for example, via a software timer event) can + be used to wake up the device. + Size: 4 bytes; Default value: 2000 + + + + ZCD_NV_CONCENTRATOR_RC + 0x0036 + Holds the value of route cache flag. This enables or disables the route cache for coordinator and is FALSE by default. + + + + ZCD_NV_NWK_MGR_MODE + 0x0037 + + + + ZCD_NV_SRC_RTG_EXPIRY_TIME + 0x0038 + + + + ZCD_NV_ROUTE_DISCOVERY_TIME + 0x0039 + + + + ZCD_NV_NWK_ACTIVE_KEY_INFO + 0x003A + + + + ZCD_NV_NWK_ALTERN_KEY_INFO + 0x003B + + + + ZCD_NV_ROUTER_OFF_ASSOC_CLEANUP + 0x003C + + + + ZCD_NV_NWK_LEAVE_REQ_ALLOWED + 0x003D + + + + ZCD_NV_NWK_CHILD_AGE_ENABLE + 0x003E + Holds the value of Child Aging capability flag. This enables or disables child aging and must be set to TRUE for Zigbee 3.0 compliance. + + + ZCD_NV_DEVICE_LIST_KA_TIMEOUT + 0x003F + + + + ZCD_NV_BINDING_TABLE + 0x0041 + + + + ZCD_NV_GROUP_TABLE + 0x0042 + + + + ZCD_NV_APS_FRAME_RETRIES + 0x0043 + The number of retransmissions performed on a data packet at the application layer if the packet was + transmitted with the end-to-end acknowledgement option enabled. + Size: 1 byte; Default value: 3 + + + + ZCD_NV_APS_ACK_WAIT_DURATION + 0x0044 + The amount of time (in milliseconds) a device will wait before re-transmitting a packet that used the + APS acknowledgement option. If the APS acknowledgement is not received by this time, the sending device will assume + a failure and attempt a re-transmission. + Note: This is recommended to be set to approximately the expected round + trip time for the packet. Note that if the + destination (or source) device is an end-device, the round trip time for + the packet will include an additional + delay up to the poll duration. This is in addition to the delay normally + caused by the network. + Size: 2 bytes; Default value: 3000 + + + + ZCD_NV_APS_ACK_WAIT_MULTIPLIER + 0x0045 + + + + ZCD_NV_BINDING_TIME + 0x0046 + The amount of time (in milliseconds) a device will wait for a response to a binding request. + Size: 2 + bytes; Default value: 8000 + + + + ZCD_NV_APS_USE_EXT_PANID + 0x0047 + + + + ZCD_NV_COMMISSIONED_NWK_ADDR + 0x0049 + + + + ZCD_NV_APS_NONMEMBER_RADIUS + 0x004B + + + + ZCD_NV_APS_LINK_KEY_TABLE + 0x004C + Holds the security manager entries of type ZDSecMgrEntry_t to store the TCKL used to talk with devices in the network that require APS security. The number of entries is controled by ZDSECMGR_DEVICE_MAX=3 by default. + + + ZCD_NV_APS_DUPREJ_TIMEOUT_INC + 0x004D + + + + ZCD_NV_APS_DUPREJ_TIMEOUT_COUNT + 0x004E + + + + ZCD_NV_APS_DUPREJ_TABLE_SIZE + 0x004F + + + + ZCD_NV_DIAGNOSTIC_STATS + 0x0050 + + + + ZCD_NV_NWK_PARENT_INFO + 0x0051 + + + + ZCD_NV_NWK_ENDDEV_TIMEOUT_DEF + 0x0052 + + + + ZCD_NV_END_DEV_TIMEOUT_VALUE + 0x0053 + Holds the value of Child Aging Timeout. This is the time in seconds used by END DEVICE when sending End Device Timeout Request that tells a COORDINATOR the timeout to remove this END DEVICE after no data poll is received. + + + ZCD_NV_END_DEV_CONFIGURATION + 0x0054 + Holds the value of End Device Configuration field when END DEVICE when sending End Device Timeout Request. Is set to 0x00 by default which is the only valid value accourding to Zigbee Core spec R21. + + + ZCD_NV_BDBNODEISONANETWORK + 0x0055 + + + + ZCD_NV_BDBREPORTINGCONFIG + 0x0056 + + + + ZCD_NV_PRECFGKEY + 0x0062 + holds the value of network key that is generated by default. The key can be set to a fixed value by setting DEFAULT_KEY macro. This is used for securing and un-securing packets in the network, if security is enabled for the + network. + NOTE: Use of this configuration item requires the ZNP code to be built with the SECURE=1 compile option. + Size: 16 bytes; Default value: [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, + 0x0E, 0x0F] + + + + ZCD_NV_PRECFGKEYS_ENABLE + 0x0063 + If security functionality is enabled, there are two options to distribute the security key to all + devices in the network. If this parameter is true, the same security key is assumed to be pre-configured in all + devices in the network.If it is set to false, then the key only needs to be configured on the coordinator device. + In this case, the key is distributed to each device upon joining by the coordinator. This key distribution will + happen in the “clear” on the last hop of the packet transmission and this constitutes a brief “period of + vulnerability” during which a malicious device can capture the key. Hence it is not recommended unless it can be + ensured that there are no malicious devices in the vicinity at the time of network formation. + NOTE: Use of this + configuration item requires the ZNP code to be built with the SECURE=1 compile option. + Size: 1 byte; Default value: + TRUE + + + + ZCD_NV_SECURITY_MODE + 0x0064 + This parameter determines if security is used or not in this network. It can be set to 0 (to turn off + NWK security) or 1 (to turn on NWK security). Size: 1 byte; Default value: 0. + + + + ZCD_NV_SECURE_PERMIT_JOIN + 0x0065 + This value tells if only secure joins are allowed. Set to TRUE by default which is the only valid value according to Zigbee Core spec R21. + + + ZCD_NV_APS_LINK_KEY_TYPE + 0x0066 + Is equal to ZG_GLOBAL_LINK_KEY=1 and must not be modified according to Zigbee Core spec R21. + + + ZCD_NV_APS_ALLOW_R19_SECURITY + 0x0067 + + + + ZCD_NV_DISTRIBUTED_KEY + 0x0068 + Default distributed nwk key Id. Nv ID not in use + + + ZCD_NV_IMPLICIT_CERTIFICATE + 0x0069 + + + + ZCD_NV_DEVICE_PRIVATE_KEY + 0x006A + + + + ZCD_NV_CA_PUBLIC_KEY + 0x006B + + + + ZCD_NV_KE_MAX_DEVICES + 0x006C + + + + ZCD_NV_USE_DEFAULT_TCLK + 0x006D + Controls whether a single pre-configured trust center link key is used or whether multiple pre- + configured trust center link keys are used, hereby referred to as Single Key Mode and Multiple Key Mode, + respectively. + In multiple key mode, unique pre-configured trust center link keys are used between the trust center + and each individual device joining the network. Multiple key mode is required by the recommended secure procedure + in ZigBeeSE profile Specification. In single key mode, all devices are using the same pre-configured trust center + link key to join the network. The single key mode provides a simplified alternative procedure to set up the + network. + It can be used for testing and debugging purpose. + Size: 1 byte; Default value: TRUE + + + + ZCD_NV_RNG_COUNTER + 0x006F + + + + ZCD_NV_RANDOM_SEED + 0x0070 + + + + ZCD_NV_TRUSTCENTER_ADDR + 0x0071 + + + + ZCD_NV_CERT_283 + 0x0072 + + + + ZCD_NV_PRIVATE_KEY_283 + 0x0073 + + + + ZCD_NV_PUBLIC_KEY_283 + 0x0074 + + + + ZCD_NV_NWK_SEC_MATERIAL_TABLE_START + 0x0075 + + + + ZCD_NV_NWK_SEC_MATERIAL_TABLE_END + 0x0080 + + + + ZCD_NV_USERDESC + 0x0081 + An optional user-defined data (up to 16bytes) that can be configured in a CC2530-ZNP device so that it + can easily identified or described later. The first byte is the length of the user descriptor data and must not be + greater than 16. + Size: 17 bytes; Default value: “CC2530-ZNP x......” (dots represent the device IEEE address) + + + + ZCD_NV_NWKKEY + 0x0082 + This holds the value of nwkActiveKeyItems structure and restores the NWK key counter after power cycles. + + + ZCD_NV_PANID + 0x0083 + This parameter identifies the ZigBee network. This should be set to a value between 0 and 0x3FFF. + Networks that exist in the same vicinity must have different values for this parameter. It can be set to a special + value of 0xFFFF to indicate “don’t care”. + Size: 2 bytes; Default value: 0xFFFF + + + + ZCD_NV_CHANLIST + 0x0084 + This parameter is a bit mask of the channels on which this network can operate (note that multiple + channels can be selected). See section 4.5.16 for a table of the bitmap representation that maps to each channel. + Multiple networks that exist in the same vicinity are encouraged to have different values. + If multiple channels are + selected, the coordinator will pick one of the channels for network operation. First, an + energy scan is performed on + each channel and those channels with a high energy level are discarded. Then, the + coordinator determines the number + of existing ZigBee networks on each of the remaining channels and picks the one + with the fewest networks. For + routers and end-devices, the device will simply scan all the selected channels until + it finds the ZigBee network. + Size: 4 bytes; Default value: 0x00000800 + + + + ZCD_NV_SCAN_DURATION + 0x0086 + + + + ZCD_NV_LOGICAL_TYPE + 0x0087 + This is the logical type of the device in the ZigBee network. This can be set to a COORDINATOR + (0x00), + ROUTER (0x01) or ENDDEVICE (0x02). + Note: + This parameter is read by the CC2530-ZNP device immediately when it powers + up after a reset. + Size: 1 byte; Default value: 0x00 + + + + ZCD_NV_NWKMGR_MIN_TX + 0x0088 + + + + ZCD_NV_NWKMGR_ADDR + 0x0089 + + + + ZCD_NV_ZDO_DIRECT_CB + 0x008F + This configures the manner in which ZDO responses (hereby referred to as callbacks) are issued to the + host processor. By default, this item is set to FALSE, which means that the host processor must use the + ZDO_MSG_CB_REGISTER command to subscribe to a specific ZDO callback in order to receive it. The ZDO callback is + then conveyed as part of the ZDO_MSG_CB_INCOMING command. If ZCD_NV_ZDO_DIRECT_CB is set TRUE, then the host + processor will receive the “verbose” response. For example, the host processor would receive the ZDO_IEEE_ADDR_RSP + command in response to ZDO_IEEE_ADDR_REQ. + Size: 1 byte; Default value: FALSE + + + + ZCD_NV_SAS_SHORT_ADDR + 0x00B1 + + + + ZCD_NV_SAS_EXT_PANID + 0x00B2 + + + + ZCD_NV_SAS_PANID + 0x00B3 + + + + ZCD_NV_SAS_CHANNEL_MASK + 0x00B4 + + + + ZCD_NV_SAS_PROTOCOL_VER + 0x00B5 + + + + ZCD_NV_SAS_STACK_PROFILE + 0x00B6 + + + + ZCD_NV_SAS_STARTUP_CTRL + 0x00B7 + + + + ZCD_NV_SAS_TC_ADDR + 0x00C1 + + + + ZCD_NV_SAS_TC_MASTER_KEY + 0x00C2 + + + + ZCD_NV_SAS_NWK_KEY + 0x00C3 + + + + ZCD_NV_SAS_USE_INSEC_JOIN + 0x00C4 + + + + ZCD_NV_SAS_PRECFG_LINK_KEY + 0x00C5 + + + + ZCD_NV_SAS_NWK_KEY_SEQ_NUM + 0x00C6 + + + + ZCD_NV_SAS_NWK_KEY_TYPE + 0x00C7 + + + + ZCD_NV_SAS_NWK_MGR_ADDR + 0x00C8 + + + + ZCD_NV_SAS_CURR_TC_MASTER_KEY + 0x00D1 + + + + ZCD_NV_SAS_CURR_NWK_KEY + 0x00D2 + + + + ZCD_NV_TCLK_TABLE_START + 0x0101 + + + + ZCD_NV_TCLK_TABLE_END + 0x01FF + + + + ZCD_NV_APS_LINK_KEY_DATA_START + 0x0201 + + + + ZCD_NV_APS_LINK_KEY_DATA_END + 0x02FF + + + + + + + ZstackDiagnosticAttribute + uint16 + Diagnostics attribute IDs. + SYS + + + ZDIAGS_SYSTEM_CLOCK + 0x0000 + System Clock when stats were saved/cleared + + + ZDIAGS_NUMBER_OF_RESETS + 0x0001 + Increments every time the system resets + + + ZDIAGS_MAC_RX_CRC_PASS + 0x0064 + MAC diagnostic CRC success counter + + + ZDIAGS_MAC_RX_CRC_FAIL + 0x0065 + MAC diagnostic CRC failure counter + + + ZDIAGS_MAC_TX_UCAST_RETRY + 0x006A + MAC layer retries a unicast + + + ZDIAGS_MAC_TX_UCAST_FAIL + 0x006B + Mac layer fails to send a unicast + + + ZDIAGS_NWK_DECRYPT_FAILURES + 0x00CF + NWK packet decryption failed + + + ZDIAGS_PACKET_VALIDATE_DROP_COUNT + 0x00D3 + NWK packet drop because of validation error + + + ZDIAGS_APS_TX_BCAST + 0x012D + APS layer transmits broadcast + + + ZDIAGS_APS_TX_UCAST_SUCCESS + 0x012F + APS layer successfully transmits a unicast + + + ZDIAGS_APS_TX_UCAST_RETRY + 0x0130 + APS layer retries the sending of a unicast + + + ZDIAGS_APS_TX_UCAST_FAIL + 0x0131 + APS layer fails to send a unicast + + + ZDIAGS_APS_DECRYPT_FAILURES + 0x0134 + APS packet decryption failed + + + ZDIAGS_APS_INVALID_PACKETS + 0x0135 + APS invalid packet dropped + + + ZDIAGS_MAC_RETRIES_PER_APS_TX_SUCCESS + 0x0136 + Number of MAC retries per APS message + + + + + + ZstackZdoState + uint8 + + SYS + + + DEV_HOLD + 0x0000 + Initialized - not started automatically + + + DEV_INIT + 0x0001 + Initialized - not connected to anything + + + DEV_NWK_DISC + 0x0002 + Discovering PAN's to join + + + DEV_NWK_JOINING + 0x0003 + Joining a PAN + + + DEV_NWK_REJOIN + 0x0004 + ReJoining a PAN, only for end devices + + + DEV_END_DEVICE_UNAUTH + 0x0005 + Joined but not yet authenticated by trust center + + + DEV_END_DEVICE + 0x0006 + Started as device after authentication + + + DEV_ROUTER + 0x0007 + Device joined, authenticated and is a router + + + DEV_COORD_STARTING + 0x0008 + Starting as Zigbee Coordinator + + + DEV_ZB_COORD + 0x0009 + Started as Zigbee Coordinator + + + DEV_NWK_ORPHAN + 0x0000A + Device has lost information about its parent + + + + + + ZstackSystemCapabilities + uint16 + Subsystem capabilities bitmap + SYS + + + MT_CAP_SYS + 0x0001 + + + + MT_CAP_MAC + 0x0002 + + + + MT_CAP_NWK + 0x0004 + + + + MT_CAP_AF + 0x0008 + + + + MT_CAP_ZDO + 0x0010 + + + + MT_CAP_SAPI + 0x0020 + + + + MT_CAP_UTIL + 0x0040 + + + + MT_CAP_DEBUG + 0x0080 + + + + MT_CAP_APP + 0x0100 + + + + MT_CAP_ZOAD + 0x1000 + + + + + + + ZstackDeviceInformation + uint16 + Device Info Constants + SAPI + + + ZB_INFO_DEV_STATE + 0x0000 + + + + ZB_INFO_IEEE_ADDR + 0x0001 + + + + ZB_INFO_SHORT_ADDR + 0x0002 + + + + ZB_INFO_PARENT_SHORT_ADDR + 0x0003 + + + + ZB_INFO_PARENT_IEEE_ADDR + 0x0004 + + + + ZB_INFO_CHANNEL + 0x0005 + + + + ZB_INFO_PAN_ID + 0x0006 + + + + ZB_INFO_EXT_PAN_ID + 0x0007 + + + + + + + ZstackResetType + uint8 + Reset Command Type + SYS + + + target device + 0x0000 + + + + serial bootloader + 0x0001 + + + + + + + ZstackResetReason + uint8 + Reasons for reset + SYS + + + Power-up + 0x0000 + + + + External + 0x0001 + + + + Watch-dog + 0x0002 + + + + + + + ZstackSreqErrorCode + uint8 + SREQ RPC Error code + RPC + + + Invalid subsystem + 0x0001 + + + + Invalid command ID + 0x0002 + + + + Invalid parameter + 0x0003 + + + + Invalid length + 0x0003 + + + + + + + ZstackResponseCode + uint8 + Global response codes + + + + Success + 0x0000 + + + + Failure + 0x0001 + + + + AF_INVALID_PARAMETER + 0x0002 + + + + AF_MEM_FAIL + 0x0010 + Security manager key table full + + + Key table full + 0x0011 + Security manager key table full + + + MAC_NO_RESOURCES + 0x001A + The operation could not be completed because no memory resources were available + + + Invalid Request + 0x00C2 + Invalid Request + + + Not Permitted + 0x00C3 + Not Permitted + + + Unknown Device + 0x00C8 + Unknown Device + + + AF_NO_ROUTE + 0x00CD + + + + MAC_SCAN_IN_PROGRESS + 0x00FC + The scan request failed because a scan is already in progress + + + + + + ZstackCentralizedLinkKeyMode + uint8 + Central link key policies + APP_CNF + + + Default Global Key + 0x0000 + Instruct joining node to use Default Global Trust Center link key. No key buffer required + + + Provided Install Code + 0x0001 + Instruct the joining node to use the provided install code (16 bytes + 2 CRC bytes) to derive APS Link + key to be used during joining + + + + Provided Install Code then default global key + 0x0002 + Instruct the joining node to use the provided install code (16 bytes + 2 CRC bytes) to derive APS Link + key to be used during joining. If it fails to decrypt Transport Key, it will automatically try Default Global Trust + Center Link Key + + + + Provided APS Key + 0x0003 + Instruct the joining node to use the provided APS Link key to be used during joining (key size is 16 + bytes) + + + + Provided APS Code then default global key + 0x0004 + Instruct the joining node to use the provided APS Link key to be used during joining (key size is 16 + bytes). If it fails to decrypt Transport Key, it will automatically try Default Global Trust Center Link Key + + + + + + + ZstackBdbStatus + uint8 + + APP_CNF + + + BDB_COMMISSIONING_SUCCESS + 0x0000 + + + + BDB_COMMISSIONING_IN_PROGRESS + 0x0001 + + + + BDB_COMMISSIONING_NO_NETWORK + 0x0002 + + + + BDB_COMMISSIONING_TL_TARGET_FAILURE + 0x0003 + + + + BDB_COMMISSIONING_TL_NOT_AA_CAPABLE + 0x0004 + + + + BDB_COMMISSIONING_TL_NO_SCAN_RESPONSE + 0x0005 + + + + BDB_COMMISSIONING_TL_NOT_PERMITTED + 0x0006 + + + + BDB_COMMISSIONING_TCLK_EX_FAILURE + 0x0007 + + + + BDB_COMMISSIONING_FORMATION_FAILURE + 0x0008 + + + + BDB_COMMISSIONING_FB_TARGET_IN_PROGRESS + 0x0009 + + + + BDB_COMMISSIONING_FB_INITIATOR_IN_PROGRESS + 0x000A + + + + BDB_COMMISSIONING_FB_NO_IDENTIFY_QUERY_RESPONSE + 0x000B + + + + BDB_COMMISSIONING_FB_BINDING_TABLE_FULL + 0x000C + + + + BDB_COMMISSIONING_NETWORK_RESTORED + 0x000D + + + + BDB_COMMISSIONING_FAILURE + 0x000E + + + + + + + ZstackBdbCommissioningMode + uint8 + + APP_CNF + + + BDB_COMMISSIONING_INITIALIZATION + 0x0000 + + + + BDB_COMMISSIONING_NWK_STEERING + 0x0001 + + + + BDB_COMMISSIONING_FORMATION + 0x0002 + + + + BDB_COMMISSIONING_FINDING_BINDING + 0x0003 + + + + BDB_COMMISSIONING_TOUCHLINK + 0x0004 + + + + BDB_COMMISSIONING_PARENT_LOST + 0x0005 + + + + + + + ZstackBdbRemainingCommissioningModes + uint8 + + APP_CNF + + + BDB_COMMISSIONING_MODE_INITIATOR_TL + 0x0001 + + + + BDB_COMMISSIONING_MODE_NWK_STEERING + 0x0002 + + + + BDB_COMMISSIONING_MODE_NWK_FORMATION + 0x0004 + + + + BDB_COMMISSIONING_MODE_FINDING_BINDING + 0x0008 + + + + BDB_COMMISSIONING_MODE_INITIALIZATION + 0x0010 + + + + BDB_COMMISSIONING_MODE_PARENT_LOST + 0x0020 + + + + + + + ZstackInstallCodeFormat + uint8 + + APP_CNF + + + INSTALL_CODE + 0x0001 + + + + DERIVED_KEY + 0x0002 + + + + + + + ZstackAuthenticationOption + uint8 + + APP_CNF + + + Not_Authenticated + 0x0000 + The device has not been authenticated + + + Authenticated_CBCK + 0x0001 + The device has been authenticated using CBKE + + + Authenticated_EA + 0x0002 + The device has been authenticated using EA + + + + + + ZstackNwkKeyDesc + SYS + + + + uint8 + keySeqNum + + + + ZigBeeKey + key + + + + + + + ZstackSecMgrEntry + SYS + + + + uint16 + ami + Address manager index that holds the IEEE address of destination device. INVALID_NODE_ADDR = 0xFFFE + + + uint16 + keyNvId + Index to the Link Key table in NV + + + ZstackAuthenticationOption + authenticateOption + + + + + + diff --git a/com.zsmartsystems.zigbee.dongle.zstack/.gitignore b/com.zsmartsystems.zigbee.dongle.zstack/.gitignore new file mode 100644 index 0000000000..ae3c172604 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/com.zsmartsystems.zigbee.dongle.zstack/.project b/com.zsmartsystems.zigbee.dongle.zstack/.project new file mode 100644 index 0000000000..b5a16713fc --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/.project @@ -0,0 +1,23 @@ + + + com.zsmartsystems.zigbee.dongle.zstack + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.m2e.core.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/com.zsmartsystems.zigbee.dongle.zstack/build.gradle b/com.zsmartsystems.zigbee.dongle.zstack/build.gradle new file mode 100644 index 0000000000..e612c6c044 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/build.gradle @@ -0,0 +1,7 @@ +group = 'com.zsmartsystems.zigbee' +description = '' +dependencies { + compile project(':com.zsmartsystems.zigbee') + + testCompile project(':com.zsmartsystems.zigbee').sourceSets.test.output +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/pom.xml b/com.zsmartsystems.zigbee.dongle.zstack/pom.xml new file mode 100644 index 0000000000..5ebc2deab7 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/pom.xml @@ -0,0 +1,34 @@ + + + 4.0.0 + + com.zsmartsystems.zigbee + com.zsmartsystems.zigbee.dongle.zstack + jar + + + com.zsmartsystems + zigbee + 1.4.3-SNAPSHOT + + + + + + com.zsmartsystems.zigbee + com.zsmartsystems.zigbee + 1.4.3-SNAPSHOT + + + + com.zsmartsystems.zigbee + com.zsmartsystems.zigbee + 1.4.3-SNAPSHOT + tests + test + + + + + + diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/ZigBeeDongleZstack.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/ZigBeeDongleZstack.java new file mode 100644 index 0000000000..c8445741ec --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/ZigBeeDongleZstack.java @@ -0,0 +1,834 @@ +/** + * 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.dongle.zstack; + +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.zsmartsystems.zigbee.ExtendedPanId; +import com.zsmartsystems.zigbee.IeeeAddress; +import com.zsmartsystems.zigbee.ZigBeeChannel; +import com.zsmartsystems.zigbee.ZigBeeChannelMask; +import com.zsmartsystems.zigbee.ZigBeeDeviceType; +import com.zsmartsystems.zigbee.ZigBeeNetworkManager; +import com.zsmartsystems.zigbee.ZigBeeNodeStatus; +import com.zsmartsystems.zigbee.ZigBeeProfileType; +import com.zsmartsystems.zigbee.ZigBeeStatus; +import com.zsmartsystems.zigbee.aps.ZigBeeApsFrame; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackCommand; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; +import com.zsmartsystems.zigbee.dongle.zstack.api.af.AfDataOptions; +import com.zsmartsystems.zigbee.dongle.zstack.api.af.ZstackAfDataConfirmAreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.af.ZstackAfDataRequestSreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.af.ZstackAfDataRequestSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.af.ZstackAfIncomingMsgAreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.appcnf.ZstackCentralizedLinkKeyMode; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackConfigId; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackResetType; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysVersionSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSystemCapabilities; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilGetDeviceInfoSreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilGetDeviceInfoSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilGetNvInfoSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.zdo.ZstackZdoMsgCbIncomingAreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.zdo.ZstackZdoStateChangeIndAreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.zdo.ZstackZdoTcDevIndAreq; +import com.zsmartsystems.zigbee.dongle.zstack.internal.ZstackFrameHandler; +import com.zsmartsystems.zigbee.dongle.zstack.internal.ZstackNetworkInitialisation; +import com.zsmartsystems.zigbee.dongle.zstack.internal.ZstackProtocolHandler; +import com.zsmartsystems.zigbee.dongle.zstack.internal.ZstackStackConfiguration; +import com.zsmartsystems.zigbee.dongle.zstack.internal.transaction.ZstackSingleResponseTransaction; +import com.zsmartsystems.zigbee.dongle.zstack.internal.transaction.ZstackTransaction; +import com.zsmartsystems.zigbee.security.ZigBeeKey; +import com.zsmartsystems.zigbee.transport.DeviceType; +import com.zsmartsystems.zigbee.transport.TransportConfig; +import com.zsmartsystems.zigbee.transport.TransportConfigOption; +import com.zsmartsystems.zigbee.transport.ZigBeePort; +import com.zsmartsystems.zigbee.transport.ZigBeeTransportProgressState; +import com.zsmartsystems.zigbee.transport.ZigBeeTransportReceive; +import com.zsmartsystems.zigbee.transport.ZigBeeTransportState; +import com.zsmartsystems.zigbee.transport.ZigBeeTransportTransmit; + +/** + * Implementation of the Texas instruments Z-Stack dongle implementation. + *

+ * Usage notes... + *

    + *
  • To be compatible with older devices (ie pre-ZigBee 3.0), MT_APP_CNF_BDB_SET_TC_REQUIRE_KEY_EXCHANGE should be set + * to FALSE. Failing to set this to FALSE will require the R21 join procedure to exchange keys following the initial + * association, which older devices will not perform, and the coordinator will then remove them from the network. This + * can be achieved with the {@link ZigBeeDongleZstack#requireKeyExchange(boolean)} method. + *
  • There is a bug in the TI ZStack 3.0.2 which always return 00 as the SeqNum in the ZstackZdoMsgCbIncomingAreq + *
+ * + * @author Chris Jackson + * + */ +public class ZigBeeDongleZstack implements ZigBeeTransportTransmit, ZstackFrameHandler { + /** + * The {@link Logger}. + */ + private final Logger logger = LoggerFactory.getLogger(ZigBeeDongleZstack.class); + + /** + * The serial port used to connect to the dongle + */ + private ZigBeePort serialPort; + + /** + * The magic number used to make the dongle exit the bootloader + */ + private int magicNumber = ZstackNetworkInitialisation.MAGIC_NUMBER_DEFAULT; + + /** + * The protocol handler used to send and receive ZStack packets + */ + private ZstackProtocolHandler frameHandler; + + /** + * The stack configuration we need for the NCP + */ + private Map stackConfiguration; + + /** + * The reference to the receive interface + */ + private ZigBeeTransportReceive zigbeeTransportReceive; + + /** + * The current link key as {@link ZigBeeKey} + */ + private ZigBeeKey linkKey = new ZigBeeKey(); + + /** + * The current network key as {@link ZigBeeKey} + */ + private ZigBeeKey networkKey = new ZigBeeKey(); + + /** + * The IeeeAddress of the NCP + */ + private IeeeAddress ieeeAddress; + + /** + * The network address of the NCP + */ + private Integer nwkAddress; + + /** + * The PAN ID + */ + private Integer panId; + + /** + * Requested TX power + */ + private int txPower = 0; + + /** + * The extended PAN ID + */ + private ExtendedPanId extendedPanId; + + /** + * Defines the type of device we want to be - normally this should be COORDINATOR + */ + private DeviceType deviceType = DeviceType.COORDINATOR; + + /** + * The ZStack version used in this system. Set during initialisation and saved in case the client is interested. + */ + private String versionString = "Unknown"; + + /** + * Boolean that is true when the network is UP + */ + private boolean networkStateUp = false; + + /** + * Boolean to hold initialisation state. Set to true after {@link #startup()} completes. + */ + private boolean initialised = false; + + private ScheduledExecutorService executorService; + private ScheduledFuture pollingTimer = null; + + /** + * The rate at which we will do a status poll if we've not sent any other messages within this period + */ + private int pollRate = 1000; + + /** + * The time the last command was sent from the {@link ZigBeeNetworkManager}. This is used by the dongle polling task + * to not poll if commands are otherwise being sent so as to reduce unnecessary communications with the dongle. + */ + private long lastSendCommandTime; + + private final HashMap sender2Endpoint = new HashMap(); + private final HashMap endpoint2Profile = new HashMap(); + + /** + * Create a {@link ZigBeeDongleZstack} + * + * @param serialPort the {@link ZigBeePort} to use for the connection + */ + public ZigBeeDongleZstack(final ZigBeePort serialPort) { + this.serialPort = serialPort; + + // Define the default configuration + stackConfiguration = new LinkedHashMap<>(); + + networkKey = new ZigBeeKey(); + } + + /** + * Update the ZStack configuration that will be sent to the dongle during the initialisation. + *

+ * Note that this must be called prior to {@link #initialize()} for the configuration to be effective. + * + * @param configId the {@link ZstackConfigId} to be updated. + * @param value the value to set (as int[]). Setting this to null will remove the configuration Id from + * the list of configuration to be sent during NCP initialisation. + * @return the previously configured value, or null if no value was set for the {@link ZstackConfigId} + */ + public int[] updateDefaultConfiguration(ZstackConfigId configId, int[] value) { + if (value == null) { + return stackConfiguration.remove(configId); + } + return stackConfiguration.put(configId, value); + } + + /** + * Different hardware may use a different "Magic Number" to skip waiting in the bootloader. Otherwise + * the dongle may wait in the bootloader for 60 seconds after it's powered on or reset. + *

+ * This method allows the user to change the magic number which may be required when using different + * sticks. + * + * @param magicNumber the byte to send to the dongle to exit the bootloader + */ + public void setMagicNumber(int magicNumber) { + this.magicNumber = magicNumber; + } + + @Override + public ZigBeeStatus initialize() { + logger.debug("ZStack dongle initialize: Starting"); + + if (!serialPort.open()) { + logger.error("Unable to open ZStack serial port"); + return ZigBeeStatus.COMMUNICATION_ERROR; + } + + frameHandler = new ZstackProtocolHandler(this); + frameHandler.start(serialPort); + + ZstackNetworkInitialisation netInitialiser = new ZstackNetworkInitialisation(frameHandler); + netInitialiser.setMagicNumber(magicNumber); + + netInitialiser.initializeNcp(false, serialPort); + + ZstackNcp ncp = getZstackNcp(); + + Set capabilities = ncp.pingNcp(); + logger.debug("ZStack subsystem capabilities: {}", capabilities); + + ZstackSysVersionSrsp version = ncp.getVersion(); + if (version == null) { + return ZigBeeStatus.COMMUNICATION_ERROR; + } + StringBuilder builder = new StringBuilder(); + builder.append("Software="); + builder.append(version.getMajorRel()); + builder.append("."); + builder.append(version.getMinorRel()); + builder.append("."); + builder.append(version.getMaintRel()); + builder.append(" Product="); + builder.append(version.getProduct()); + builder.append(" Transport="); + builder.append(version.getTransportRev()); + versionString = builder.toString(); + + ieeeAddress = ncp.getIeeeAddress(); + logger.debug("ZStack local IeeeAddress: {}", ieeeAddress); + + /* + * Create the scheduler with a single thread. This ensures that commands sent to the dongle, and the processing + * of responses is performed in order + */ + executorService = Executors.newScheduledThreadPool(1); + + logger.debug("ZStack dongle initialize: Done"); + + return ZigBeeStatus.SUCCESS; + } + + @Override + public ZigBeeStatus startup(boolean reinitialize) { + logger.debug("ZStack dongle startup: Starting"); + + // If frameHandler is null then the serial port didn't initialise + if (frameHandler == null) { + logger.error("Initialising ZStack Dongle but low level handler is not initialised."); + return ZigBeeStatus.INVALID_STATE; + } + + ZstackNcp ncp = getZstackNcp(); + + // If we want to reinitialize the network, then go... + ZstackNetworkInitialisation netInitialiser = new ZstackNetworkInitialisation(frameHandler); + netInitialiser.setMagicNumber(magicNumber); + if (reinitialize) { + logger.debug("Reinitialising ZStack NCP network."); + netInitialiser.initializeNcp(true, serialPort); + + if (deviceType == DeviceType.COORDINATOR) { + netInitialiser.formNetwork(); + } else { + netInitialiser.joinNetwork(); + } + + ncp.resetNcp(ZstackResetType.SERIAL_BOOTLOADER); + + ZstackResponseCode ncpResponse = ncp.setNetworkKey(networkKey); + if (ncpResponse != ZstackResponseCode.SUCCESS) { + logger.debug("ZStack error setting network key: {}", ncpResponse); + return ZigBeeStatus.COMMUNICATION_ERROR; + } + + ncpResponse = ncp.setCentralisedKey(ZstackCentralizedLinkKeyMode.PROVIDED_APS_KEY, linkKey.getValue()); + if (ncpResponse != ZstackResponseCode.SUCCESS) { + logger.debug("ZStack error setting link key: {}", ncpResponse); + // return ZigBeeStatus.COMMUNICATION_ERROR; + } + + if (panId == null) { + // Allow the NCP to create a random PAN ID + panId = 0xFFFF; + } + ncpResponse = ncp.setPanId(panId); + if (ncpResponse != ZstackResponseCode.SUCCESS) { + logger.debug("ZStack error setting PAN ID: {}", ncpResponse); + return ZigBeeStatus.COMMUNICATION_ERROR; + } + + if (extendedPanId == null) { + // Allow the NCP to create a random extended PAN ID + extendedPanId = new ExtendedPanId("FFFFFFFFFFFFFFFF"); + } + ncpResponse = ncp.setExtendedPanId(extendedPanId); + if (ncpResponse != ZstackResponseCode.SUCCESS) { + logger.debug("ZStack error setting extended PAN ID: {}", ncpResponse); + return ZigBeeStatus.COMMUNICATION_ERROR; + } + } + + // Perform any stack configuration + ZstackStackConfiguration stackConfigurer = new ZstackStackConfiguration(ncp); + + Map configuration = stackConfigurer.getConfiguration(stackConfiguration.keySet()); + for (Entry config : configuration.entrySet()) { + logger.debug("Configuration state {} = {}", config.getKey(), config.getValue()); + } + + stackConfigurer.setConfiguration(stackConfiguration); + configuration = stackConfigurer.getConfiguration(stackConfiguration.keySet()); + for (Entry config : configuration.entrySet()) { + logger.debug("Configuration state {} = {}", config.getKey(), config.getValue()); + } + + // Add the endpoint + ncp.addEndpoint(1, ZigBeeDeviceType.HOME_GATEWAY.getKey(), ZigBeeProfileType.ZIGBEE_HOME_AUTOMATION.getKey(), + new int[] { 0 }, new int[] { 0 }); + sender2Endpoint.put(ZigBeeProfileType.ZIGBEE_HOME_AUTOMATION.getKey(), 1); + endpoint2Profile.put(1, ZigBeeProfileType.ZIGBEE_HOME_AUTOMATION.getKey()); + + if (setTxPower(txPower) != ZigBeeStatus.SUCCESS) { + logger.debug("ZStack error setting transmit power"); + return ZigBeeStatus.COMMUNICATION_ERROR; + } + + netInitialiser.startNetwork(); + + ZstackUtilGetDeviceInfoSrsp deviceInfo = ncp.getDeviceInfo(); + if (deviceInfo == null) { + logger.debug("Error getting device info"); + + return ZigBeeStatus.COMMUNICATION_ERROR; + } + nwkAddress = deviceInfo.getShortAddr(); + + ZstackUtilGetNvInfoSrsp nvDeviceInfo = ncp.getNvDeviceInfo(); + if (nvDeviceInfo == null) { + logger.debug("Error getting NV device info"); + + return ZigBeeStatus.COMMUNICATION_ERROR; + } + + logger.debug("ZStack dongle startup: Waiting"); + + if (!netInitialiser.waitForNcpOnline(ncp)) { + logger.debug("ZStack dongle startup: Failed waiting for NCP to come online"); + return ZigBeeStatus.COMMUNICATION_ERROR; + } + + logger.debug("ZStack dongle startup: Done"); + initialised = true; + handleLinkStateChange(true); + scheduleNetworkStatePolling(); + + return ZigBeeStatus.SUCCESS; + } + + /** + * This method schedules sending a status request frame on the interval specified by pollRate. If the frameHandler + * does not receive a response after a certain amount of retries, the state will be set to OFFLINE. + * The poll will not be sent if other commands have been sent to the dongle within the pollRate period so as to + * eliminate any unnecessary traffic with the dongle. + */ + private void scheduleNetworkStatePolling() { + if (pollingTimer != null) { + pollingTimer.cancel(true); + } + + pollingTimer = executorService.scheduleWithFixedDelay(new Runnable() { + @Override + public void run() { + // Don't poll the state if the network is down + // or we've sent a command to the dongle within the pollRate + if (!networkStateUp || (lastSendCommandTime + pollRate > System.currentTimeMillis())) { + return; + } + // Don't wait for the response. This is running in a single thread scheduler + frameHandler.queueFrame(new ZstackUtilGetDeviceInfoSreq()); + } + }, pollRate, pollRate, TimeUnit.MILLISECONDS); + } + + @Override + public void shutdown() { + if (frameHandler == null) { + return; + } + + if (pollingTimer != null) { + pollingTimer.cancel(true); + } + + if (executorService != null) { + executorService.shutdown(); + } + + frameHandler.setClosing(); + serialPort.close(); + frameHandler.close(); + frameHandler = null; + } + + /** + * Returns an instance of the {@link ZstackNcp} + * + * @return an instance of the {@link ZstackNcp} + */ + public ZstackNcp getZstackNcp() { + return new ZstackNcp(frameHandler); + } + + @Override + public IeeeAddress getIeeeAddress() { + return ieeeAddress; + } + + @Override + public Integer getNwkAddress() { + return nwkAddress; + } + + @Override + public void sendCommand(final int msgTag, final ZigBeeApsFrame apsFrame) { + if (frameHandler == null) { + return; + } + + // Remember the time to reduce unnecessary polling + lastSendCommandTime = System.currentTimeMillis(); + + final int srcEndpoint; + if (apsFrame.getProfile() == 0) { + srcEndpoint = 0; + } else { + srcEndpoint = (short) getSendingEndpoint(apsFrame.getProfile()); + } + + // TODO: How to differentiate group and device addressing????? + + ZstackAfDataRequestSreq request = new ZstackAfDataRequestSreq(); + request.setClusterID(apsFrame.getCluster()); + request.setDstAddr(apsFrame.getDestinationAddress()); + request.setDestEndpoint(apsFrame.getDestinationEndpoint()); + request.setSrcEndpoint(srcEndpoint); + request.setTransID(apsFrame.getApsCounter()); + request.setRadius(apsFrame.getRadius()); + request.setData(apsFrame.getPayload()); + + request.addOptions(AfDataOptions.AF_ACK_REQUEST); + request.addOptions(AfDataOptions.AF_DISCV_ROUTE); + if (apsFrame.getSecurityEnabled()) { + request.addOptions(AfDataOptions.AF_EN_SECURITY); + } + + ZstackTransaction transaction = new ZstackSingleResponseTransaction(request, ZstackAfDataRequestSrsp.class); + + // We need to correlate with the messageTag + executorService.execute(new Runnable() { + @Override + public void run() { + frameHandler.sendTransaction(transaction); + + ZstackAfDataRequestSrsp response = (ZstackAfDataRequestSrsp) transaction.getResponse(); + + ZigBeeTransportProgressState sentHandlerState; + if (response == null || response.getStatus() != ZstackResponseCode.SUCCESS) { + sentHandlerState = ZigBeeTransportProgressState.RX_NAK; + } else { + sentHandlerState = ZigBeeTransportProgressState.RX_ACK; + } + + zigbeeTransportReceive.receiveCommandState(msgTag, sentHandlerState); + } + }); + } + + @Override + public void setZigBeeTransportReceive(ZigBeeTransportReceive zigbeeTransportReceive) { + this.zigbeeTransportReceive = zigbeeTransportReceive; + } + + @Override + public void handlePacket(ZstackCommand response) { + if (response instanceof ZstackAfIncomingMsgAreq) { + ZstackAfIncomingMsgAreq incomingMsg = (ZstackAfIncomingMsgAreq) response; + ZigBeeApsFrame apsFrame = new ZigBeeApsFrame(); + apsFrame.setCluster(incomingMsg.getClusterId()); + apsFrame.setDestinationAddress(nwkAddress); + apsFrame.setDestinationEndpoint(incomingMsg.getDestEndpoint()); + apsFrame.setSourceEndpoint(incomingMsg.getSrcEndpoint()); + apsFrame.setSourceAddress(incomingMsg.getSrcAddr()); + apsFrame.setProfile(getEndpointProfile(incomingMsg.getDestEndpoint())); + apsFrame.setSecurityEnabled(incomingMsg.getSecurityUse()); + apsFrame.setPayload(incomingMsg.getData()); + + zigbeeTransportReceive.receiveCommand(apsFrame); + return; + } + + if (response instanceof ZstackZdoMsgCbIncomingAreq) { + // Ignore frames before we're initialised + if (nwkAddress == null) { + return; + } + + ZstackZdoMsgCbIncomingAreq incomingMsg = (ZstackZdoMsgCbIncomingAreq) response; + ZigBeeApsFrame apsFrame = new ZigBeeApsFrame(); + apsFrame.setCluster(incomingMsg.getClusterId()); + apsFrame.setDestinationAddress(nwkAddress); + apsFrame.setDestinationEndpoint(0); + apsFrame.setSourceEndpoint(0); + apsFrame.setSourceAddress(incomingMsg.getSrcAddr()); + apsFrame.setProfile(0); + apsFrame.setSecurityEnabled(incomingMsg.getSecurityUse()); + + int[] payload = new int[incomingMsg.getData().length + 1]; + System.arraycopy(incomingMsg.getData(), 0, payload, 1, incomingMsg.getData().length); + apsFrame.setPayload(payload); + + zigbeeTransportReceive.receiveCommand(apsFrame); + return; + } + + if (response instanceof ZstackAfDataConfirmAreq) { + // Message has been completed by the NCP + executorService.execute(new Runnable() { + @Override + public void run() { + ZstackAfDataConfirmAreq dataConfirm = (ZstackAfDataConfirmAreq) response; + + ZigBeeTransportProgressState sentHandlerState; + if (dataConfirm.getStatus() == ZstackResponseCode.SUCCESS) { + sentHandlerState = ZigBeeTransportProgressState.RX_ACK; + } else { + sentHandlerState = ZigBeeTransportProgressState.RX_NAK; + } + zigbeeTransportReceive.receiveCommandState(dataConfirm.getTransId(), sentHandlerState); + } + }); + return; + } + + if (response instanceof ZstackZdoStateChangeIndAreq) { + switch (((ZstackZdoStateChangeIndAreq) response).getState()) { + case DEV_NWK_ORPHAN: + case DEV_ROUTER: + case DEV_ZB_COORD: + case DEV_END_DEVICE: + handleLinkStateChange(true); + break; + default: + handleLinkStateChange(false); + break; + } + + return; + } + + if (response instanceof ZstackZdoTcDevIndAreq) { + ZstackZdoTcDevIndAreq tcDeviceInd = (ZstackZdoTcDevIndAreq) response; + + zigbeeTransportReceive.nodeStatusUpdate(ZigBeeNodeStatus.UNSECURED_JOIN, tcDeviceInd.getSrcAddr(), + tcDeviceInd.getExtAddr()); + return; + } + } + + @Override + public void handleLinkStateChange(final boolean linkState) { + // Only act on changes to OFFLINE once we have completed initialisation + // changes to ONLINE have to work during init because they mark the end of the initialisation + if (!initialised || linkState == networkStateUp) { + logger.debug("ZStack dongle state change to {} ignored. initialised={}, networkStateUp={}", linkState, + initialised, networkStateUp); + return; + } + logger.debug("ZStack dongle state change to {}", linkState); + + networkStateUp = linkState; + + new Thread() { + @Override + public void run() { + if (linkState) { + ZstackNcp ncp = getZstackNcp(); + nwkAddress = ncp.getNwkAddress(); + } + // Handle link changes and notify framework + zigbeeTransportReceive + .setTransportState(linkState ? ZigBeeTransportState.ONLINE : ZigBeeTransportState.OFFLINE); + } + }.start(); + } + + @Override + public ZigBeeChannel getZigBeeChannel() { + return ZigBeeChannel.create(0); + } + + @Override + public ZigBeeStatus setZigBeeChannel(ZigBeeChannel channel) { + if ((ZigBeeChannelMask.CHANNEL_MASK_2GHZ & channel.getMask()) == 0) { + logger.debug("Unable to set channel outside of 2.4GHz channels: {}", channel); + return ZigBeeStatus.INVALID_ARGUMENTS; + } + // networkParameters.setRadioChannel(channel.getChannel()); + return ZigBeeStatus.SUCCESS; + } + + @Override + public int getZigBeePanId() { + return 0; + } + + @Override + public ZigBeeStatus setZigBeePanId(int panId) { + // Can't change this when the network is up + if (networkStateUp) { + return ZigBeeStatus.INVALID_STATE; + } + this.panId = panId; + return ZigBeeStatus.SUCCESS; + } + + @Override + public ExtendedPanId getZigBeeExtendedPanId() { + return extendedPanId; + } + + @Override + public ZigBeeStatus setZigBeeExtendedPanId(ExtendedPanId extendedPanId) { + // Can't change this when the network is up + if (networkStateUp) { + return ZigBeeStatus.INVALID_STATE; + } + this.extendedPanId = extendedPanId; + return ZigBeeStatus.SUCCESS; + } + + @Override + public ZigBeeStatus setZigBeeNetworkKey(final ZigBeeKey key) { + if (networkStateUp) { + return ZigBeeStatus.INVALID_STATE; + } + networkKey = key; + return ZigBeeStatus.SUCCESS; + } + + @Override + public ZigBeeKey getZigBeeNetworkKey() { + ZstackNcp ncp = getZstackNcp(); + return ncp.getNetworkKey(); + } + + @Override + public ZigBeeStatus setTcLinkKey(ZigBeeKey key) { + linkKey = key; + ZstackNcp ncp = getZstackNcp(); + + return ncp.setCentralisedKey(ZstackCentralizedLinkKeyMode.PROVIDED_APS_KEY, + key.getValue()) == ZstackResponseCode.SUCCESS ? ZigBeeStatus.SUCCESS : ZigBeeStatus.FAILURE; + } + + @Override + public ZigBeeKey getTcLinkKey() { + return null; + } + + /** + * Sets the policy flag on Trust Center device to mandate or not the TCLK exchange procedure. + *

+ * Note that for ZB3, this should be set to true, however for backward compatability with HA1.2, this needs to be + * set to false or devices will not be able to join the network. + * + * @param required true if the TCLK exchange procedure is required. + * @return {@link ZigBeeStatus} + */ + public ZigBeeStatus requireKeyExchange(boolean required) { + ZstackNcp ncp = getZstackNcp(); + + return ncp.requireKeyExchange(required) == ZstackResponseCode.SUCCESS ? ZigBeeStatus.SUCCESS + : ZigBeeStatus.FAILURE; + } + + @Override + public void updateTransportConfig(TransportConfig configuration) { + for (TransportConfigOption option : configuration.getOptions()) { + try { + switch (option) { + case CONCENTRATOR_CONFIG: + break; + + case INSTALL_KEY: + ZstackNcp ncp = getZstackNcp(); + ZigBeeKey nodeKey = (ZigBeeKey) configuration.getValue(option); + if (!nodeKey.hasAddress()) { + logger.debug("Attempt to set INSTALL_KEY without setting address"); + configuration.setResult(option, ZigBeeStatus.FAILURE); + break; + } + ZstackResponseCode result = ncp.addInstallCode(nodeKey.getAddress(), nodeKey); + + configuration.setResult(option, + result == ZstackResponseCode.SUCCESS ? ZigBeeStatus.SUCCESS : ZigBeeStatus.FAILURE); + break; + + case RADIO_TX_POWER: + txPower = (int) configuration.getValue(option); + configuration.setResult(option, setTxPower(txPower)); + break; + + case DEVICE_TYPE: + deviceType = (DeviceType) configuration.getValue(option); + configuration.setResult(option, ZigBeeStatus.SUCCESS); + break; + + case TRUST_CENTRE_LINK_KEY: + setTcLinkKey((ZigBeeKey) configuration.getValue(option)); + configuration.setResult(option, ZigBeeStatus.SUCCESS); + break; + + case TRUST_CENTRE_JOIN_MODE: + // configuration.setResult(option, + // setTcJoinMode((TrustCentreJoinMode) configuration.getValue(option))); + break; + + default: + configuration.setResult(option, ZigBeeStatus.UNSUPPORTED); + logger.debug("Unsupported configuration option \"{}\" in ZStack dongle", option); + break; + } + } catch (ClassCastException e) { + configuration.setResult(option, ZigBeeStatus.INVALID_ARGUMENTS); + } + } + } + + private ZigBeeStatus setTxPower(int txPower) { + ZstackNcp ncp = getZstackNcp(); + Integer powerResponse = ncp.setTxPower(txPower); + if (powerResponse == null) { + logger.debug("ZStack error setting transmit power"); + return ZigBeeStatus.COMMUNICATION_ERROR; + } + + if (txPower != powerResponse) { + logger.debug("ZStack error setting transmit power. Requested {}dBm, but set to {}dBm", txPower, + powerResponse); + } + + return ZigBeeStatus.SUCCESS; + } + + @Override + public String getVersionString() { + return versionString; + } + + /** + * Gets the endpoint given the profile - for sending + * + * @param profileId the profile ID + * @return the endpoint used for this profile + */ + private int getSendingEndpoint(int profileId) { + synchronized (sender2Endpoint) { + if (sender2Endpoint.containsKey(profileId)) { + return sender2Endpoint.get(profileId); + } else { + logger.info("No endpoint registered for profileId={}", profileId); + return -1; + } + } + } + + /** + * Gets the profile used in an endpoint. + * + * @param endpointId the endpoint + * @return the profile used in the endpoint + */ + private int getEndpointProfile(int endpointId) { + synchronized (endpoint2Profile) { + if (endpoint2Profile.containsKey(endpointId)) { + return endpoint2Profile.get(endpointId); + } else { + logger.info("No endpoint {} registered", endpointId); + // final byte ep = createEndPoint( profileId); + return -1; + } + } + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/ZstackNcp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/ZstackNcp.java new file mode 100644 index 0000000000..710f9bb833 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/ZstackNcp.java @@ -0,0 +1,677 @@ +/** + * 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.dongle.zstack; + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.zsmartsystems.zigbee.ExtendedPanId; +import com.zsmartsystems.zigbee.IeeeAddress; +import com.zsmartsystems.zigbee.ZigBeeChannelMask; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; +import com.zsmartsystems.zigbee.dongle.zstack.api.af.ZstackAfRegisterSreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.af.ZstackAfRegisterSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.appcnf.ZstackAppCnfBdbAddInstallcodeSreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.appcnf.ZstackAppCnfBdbAddInstallcodeSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.appcnf.ZstackAppCnfBdbSetActiveDefaultCentralizedKeySreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.appcnf.ZstackAppCnfBdbSetActiveDefaultCentralizedKeySrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.appcnf.ZstackAppCnfBdbSetTcRequireKeyExchangeSreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.appcnf.ZstackAppCnfBdbSetTcRequireKeyExchangeSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.appcnf.ZstackAppCnfSetAllowrejoinTcPolicySreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.appcnf.ZstackAppCnfSetAllowrejoinTcPolicySrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.appcnf.ZstackCentralizedLinkKeyMode; +import com.zsmartsystems.zigbee.dongle.zstack.api.appcnf.ZstackInstallCodeFormat; +import com.zsmartsystems.zigbee.dongle.zstack.api.sapi.ZstackZbReadConfigurationSreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.sapi.ZstackZbReadConfigurationSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sapi.ZstackZbWriteConfigurationSreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.sapi.ZstackZbWriteConfigurationSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackConfigId; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackDiagnosticAttribute; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackResetType; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysOsalNvReadSreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysOsalNvReadSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysOsalNvWriteSreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysOsalNvWriteSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysPingSreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysPingSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysResetIndAreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysResetReqAcmd; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysSetTxPowerSreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysSetTxPowerSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysVersionSreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysVersionSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysZdiagsGetStatsSreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysZdiagsGetStatsSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSystemCapabilities; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilGetDeviceInfoSreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilGetDeviceInfoSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilGetNvInfoSreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilGetNvInfoSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilSetChannelsSreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilSetChannelsSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.zdo.ZstackZdoMsgCbRegisterSreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.zdo.ZstackZdoMsgCbRegisterSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.zdo.ZstackZdoStartupFromAppSreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.zdo.ZstackZdoStartupFromAppSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.internal.ZstackFrameHandler; +import com.zsmartsystems.zigbee.dongle.zstack.internal.ZstackProtocolHandler; +import com.zsmartsystems.zigbee.dongle.zstack.internal.transaction.ZstackSingleResponseTransaction; +import com.zsmartsystems.zigbee.dongle.zstack.internal.transaction.ZstackTransaction; +import com.zsmartsystems.zigbee.security.ZigBeeKey; +import com.zsmartsystems.zigbee.transport.DeviceType; + +/** + * This class provides utility methods for accessing the ZStack NCP and returning specific data for use in the + * application. It ensures the correct correlation of the requests and responses, and checks for errors. + * + * @author Chris Jackson - Initial contribution + * + */ +public class ZstackNcp { + /** + * The {@link Logger}. + */ + private final Logger logger = LoggerFactory.getLogger(ZstackNcp.class); + + /** + * Flag to use the old (deprecated) config functions + */ + private boolean useOldCfgCalls = true; + + /* + * Startup options bitmap + */ + private final int STARTOPT_CLEAR_CONFIG = 0x0001; + private final int STARTOPT_CLEAR_STATE = 0x0002; + + /** + * The protocol handler used to send and receive ZStack packets + */ + private ZstackProtocolHandler protocolHandler; + + /** + * Create the NCP instance + * + * @param protocolHandler the {@link ZstackFrameHandler} used for communicating with the NCP + */ + public ZstackNcp(ZstackProtocolHandler protocolHandler) { + this.protocolHandler = protocolHandler; + } + + /** + * Resets the NCP + * + * @param resetType the {@link ZstackResetType} to request + * @return the {@link ZstackSysResetIndAreq} from the NCP or null if there was an error + */ + public ZstackSysResetIndAreq resetNcp(ZstackResetType resetType) { + ZstackSysResetReqAcmd request = new ZstackSysResetReqAcmd(); + request.setType(resetType); + ZstackTransaction transaction = protocolHandler + .sendTransaction(new ZstackSingleResponseTransaction(request, ZstackSysResetIndAreq.class)); + ZstackSysResetIndAreq response = (ZstackSysResetIndAreq) transaction.getResponse(); + if (response == null) { + logger.debug("No response from Reset command"); + return null; + } + logger.debug(response.toString()); + + return response; + } + + /** + * Ping the NCP and return the set of subsystem capabilities compiled into the NCP firmware + * + * @return the list of subsystem {@link ZstackSystemCapabilities} from the NCP, or an empty set if there was an + * error + */ + public Set pingNcp() { + ZstackSysPingSreq request = new ZstackSysPingSreq(); + ZstackTransaction transaction = protocolHandler + .sendTransaction(new ZstackSingleResponseTransaction(request, ZstackSysPingSrsp.class)); + ZstackSysPingSrsp response = (ZstackSysPingSrsp) transaction.getResponse(); + if (response == null) { + logger.debug("No response from Ping command"); + return Collections.emptySet(); + } + logger.debug(response.toString()); + + Set capabilities = new HashSet<>(); + for (ZstackSystemCapabilities capability : ZstackSystemCapabilities.values()) { + if (capability == ZstackSystemCapabilities.UNKNOWN) { + continue; + } + if ((capability.getKey() & response.getCapabilities()) != 0) { + capabilities.add(capability); + } + } + + return capabilities; + } + + /** + * The command reads the version information from the stack + * + * @return the {@link ZstackSysVersionSrsp} + */ + public ZstackSysVersionSrsp getVersion() { + ZstackSysVersionSreq request = new ZstackSysVersionSreq(); + ZstackTransaction transaction = protocolHandler + .sendTransaction(new ZstackSingleResponseTransaction(request, ZstackSysVersionSrsp.class)); + ZstackSysVersionSrsp response = (ZstackSysVersionSrsp) transaction.getResponse(); + if (response == null) { + logger.debug("No response from Version command"); + return null; + } + logger.debug(response.toString()); + + return response; + } + + /** + * The command reads the device information from the NCP + * + * @return the {@link ZstackUtilGetDeviceInfoSrsp} + */ + public ZstackUtilGetDeviceInfoSrsp getDeviceInfo() { + ZstackUtilGetDeviceInfoSreq request = new ZstackUtilGetDeviceInfoSreq(); + ZstackTransaction transaction = protocolHandler + .sendTransaction(new ZstackSingleResponseTransaction(request, ZstackUtilGetDeviceInfoSrsp.class)); + ZstackUtilGetDeviceInfoSrsp response = (ZstackUtilGetDeviceInfoSrsp) transaction.getResponse(); + if (response == null) { + logger.debug("No response from DeviceInfo command"); + return null; + } + logger.debug(response.toString()); + + return response; + } + + /** + * The command reads the non-volatile device information from the NCP + * + * @return the {@link ZstackUtilGetDeviceInfoSrsp} + */ + public ZstackUtilGetNvInfoSrsp getNvDeviceInfo() { + ZstackUtilGetNvInfoSreq request = new ZstackUtilGetNvInfoSreq(); + ZstackTransaction transaction = protocolHandler + .sendTransaction(new ZstackSingleResponseTransaction(request, ZstackUtilGetNvInfoSrsp.class)); + ZstackUtilGetNvInfoSrsp response = (ZstackUtilGetNvInfoSrsp) transaction.getResponse(); + if (response == null) { + logger.debug("No response from NvInfo command"); + return null; + } + logger.debug(response.toString()); + + return response; + } + + /** + * Gets the {@link IeeeAddress} from the NCP + * + * @return the {@link IeeeAddress} local address of the NCP + */ + public IeeeAddress getIeeeAddress() { + ZstackUtilGetDeviceInfoSrsp info = getDeviceInfo(); + if (info == null) { + return null; + } + return info.getIeeeAddress(); + } + + /** + * Gets the current network address of the NCP + * + * @return the 16 bit local network address of the NCP or -1 if there was an error + */ + public int getNwkAddress() { + ZstackUtilGetDeviceInfoSrsp info = getDeviceInfo(); + if (info == null) { + return -1; + } + return info.getShortAddr(); + } + + /** + * Gets a diagnostics counter from the NCP + * + * @param attributeId {@ link ZstackDiagnosticAttribute} to request + * @return the 32 bit counter, or null on error + */ + public Long getDiagnosticsAttribute(ZstackDiagnosticAttribute attributeId) { + ZstackSysZdiagsGetStatsSreq request = new ZstackSysZdiagsGetStatsSreq(); + request.setAttributeID(attributeId); + ZstackTransaction transaction = protocolHandler + .sendTransaction(new ZstackSingleResponseTransaction(request, ZstackSysZdiagsGetStatsSrsp.class)); + ZstackSysZdiagsGetStatsSrsp response = (ZstackSysZdiagsGetStatsSrsp) transaction.getResponse(); + if (response == null) { + logger.debug("No response from GetDiagnostics command"); + return null; + } + logger.debug(response.toString()); + + return (long) response.getAttributeValue(); + } + + /** + * Sets the startup options when the NCP starts. + *

+ * The CC2530-ZNP device has two kinds of information stored in non-volatile memory. The configuration parameters + * and network state information. + *

+ * The configuration parameters are configured by the user before start of ZigBee operation. The + * STARTOPT_CLEAR_CONFIG bit is read by the CC2530-ZNP device immediately when it powers up after a reset. + * When the configuration parameters are restored to defaults, the ZCD_NV_STARTUP_OPTION itself is not restored + * except for clearing the STARTOPT_CLEAR_CONFIG bit. + *

+ * The network state information is collected by the device after it joins a network and creates bindings etc. (at + * runtime). This is not set by the application processor. This information is stored so that if the device were to + * reset accidentally, it can restore itself without going through all the network joining and binding process + * again. + *

+ * If the application processor does not wish to continue operating in the previous ZigBee network, it needs to + * instruct the CC2530-ZNP device to clear the network state information and start again based on the configuration + * parameters. This is done by setting the STARTOPT_CLEAR_STATE bit in the startup option. + * + * @param clearConfig STARTOPT_CLEAR_CONFIG – If this option is set, the device will overwrite all the configuration + * parameters (except this one) with the “default” values that it is programmed with. This is used to + * erase the existing configuration and bring the device into a known state. + * @param clearState STARTOPT_CLEAR_STATE – If this option is set, the device will clear its previous network state + * (which would exist if the device had been operating on a network prior to the reset). This is + * typically used during application development. During regular device operation, this flag is typically + * not set, so that an accidental device reset will not cause loss of network state. + * @return {@link ZstackResponseCode} returned from the NCP + */ + public ZstackResponseCode setStartupOptions(boolean clearConfig, boolean clearState) { + int optionVal = (clearConfig ? STARTOPT_CLEAR_CONFIG : 0) + (clearState ? STARTOPT_CLEAR_STATE : 0); + return writeConfiguration(ZstackConfigId.ZCD_NV_STARTUP_OPTION, valueFromUInt8(optionVal)); + } + + /** + * Reads a configuration parameter from the NCP + * + * @param configId the {@link ZstackConfigId} to read + * @return a int[] with the value of the configuration data or null on error + */ + public int[] readConfiguration(ZstackConfigId configId) { + if (useOldCfgCalls) { + ZstackZbReadConfigurationSreq request = new ZstackZbReadConfigurationSreq(); + request.setConfigId(configId); + ZstackTransaction transaction = protocolHandler + .sendTransaction(new ZstackSingleResponseTransaction(request, ZstackZbReadConfigurationSrsp.class)); + ZstackZbReadConfigurationSrsp response = (ZstackZbReadConfigurationSrsp) transaction.getResponse(); + if (response == null) { + logger.debug("No response from ReadConfiguration command"); + return null; + } + logger.debug(response.toString()); + if (response.getStatus() != ZstackResponseCode.SUCCESS) { + logger.debug("No response from ReadConfiguration command: {}", response.getStatus()); + return null; + } + return response.getValue(); + } else { + ZstackSysOsalNvReadSreq request = new ZstackSysOsalNvReadSreq(); + request.setId(configId); + ZstackTransaction transaction = protocolHandler + .sendTransaction(new ZstackSingleResponseTransaction(request, ZstackSysOsalNvReadSrsp.class)); + ZstackSysOsalNvReadSrsp response = (ZstackSysOsalNvReadSrsp) transaction.getResponse(); + if (response == null) { + logger.debug("No response from ReadConfiguration command"); + return null; + } + if (response.getStatus() != ZstackResponseCode.SUCCESS) { + logger.debug("No response from ReadConfiguration command: {}", response.getStatus()); + return null; + } + logger.debug(response.toString()); + return response.getValue(); + } + } + + /** + * Writes a configuration parameter to the NCP + * + * @param configId the {@link ZstackConfigId} to read + * @param value an int array containing the value to be written + * @return {@link ZstackResponseCode} returned from the NCP + */ + public ZstackResponseCode writeConfiguration(ZstackConfigId configId, int[] value) { + if (useOldCfgCalls) { + ZstackZbWriteConfigurationSreq request = new ZstackZbWriteConfigurationSreq(); + request.setConfigId(configId); + request.setValue(value); + ZstackTransaction transaction = protocolHandler.sendTransaction( + new ZstackSingleResponseTransaction(request, ZstackZbWriteConfigurationSrsp.class)); + ZstackZbWriteConfigurationSrsp response = (ZstackZbWriteConfigurationSrsp) transaction.getResponse(); + if (response == null) { + logger.debug("No response from WriteConfiguration command"); + return ZstackResponseCode.FAILURE; + } + logger.debug(response.toString()); + return response.getStatus(); + } else { + ZstackSysOsalNvWriteSreq request = new ZstackSysOsalNvWriteSreq(); + request.setId(configId); + request.setValue(value); + ZstackTransaction transaction = protocolHandler + .sendTransaction(new ZstackSingleResponseTransaction(request, ZstackSysOsalNvWriteSrsp.class)); + ZstackSysOsalNvWriteSrsp response = (ZstackSysOsalNvWriteSrsp) transaction.getResponse(); + if (response == null) { + logger.debug("No response from WriteConfiguration command"); + return ZstackResponseCode.FAILURE; + } + logger.debug(response.toString()); + return response.getStatus(); + } + } + + /** + * Sets the ZStack device type + * + * @param deviceType the {@link DeviceType} to use + * @return {@link ZstackResponseCode} returned from the NCP + */ + public ZstackResponseCode setDeviceType(DeviceType deviceType) { + int value; + switch (deviceType) { + case COORDINATOR: + value = 0; + break; + case ROUTER: + value = 1; + break; + default: + logger.debug("Unknown device type {}", deviceType); + return ZstackResponseCode.FAILURE; + } + return writeConfiguration(ZstackConfigId.ZCD_NV_LOGICAL_TYPE, valueFromUInt8(value)); + } + + /** + * Sets the PAN ID + * + * @param panId the 16 bit PAN ID + * @return {@link ZstackResponseCode} returned from the NCP + */ + public ZstackResponseCode setPanId(int panId) { + return writeConfiguration(ZstackConfigId.ZCD_NV_PANID, valueFromUInt16(panId)); + } + + /** + * Sets the extended PAN ID + * + * @param panId the {@link ExtendedPanId} extended PAN ID + * @return {@link ZstackResponseCode} returned from the NCP + */ + public ZstackResponseCode setExtendedPanId(ExtendedPanId epanId) { + return writeConfiguration(ZstackConfigId.ZCD_NV_EXTPANID, epanId.getValue()); + } + + /** + * Sets the network key, and enables its use. + * + * @param key the {@link ZigBeeKey} to use for the network key + * @return {@link ZstackResponseCode} returned from the NCP + */ + public ZstackResponseCode setNetworkKey(ZigBeeKey key) { + ZstackResponseCode responseCode = writeConfiguration(ZstackConfigId.ZCD_NV_PRECFGKEY, key.getValue()); + if (responseCode != ZstackResponseCode.SUCCESS) { + return responseCode; + } + // Enable the network key + return writeConfiguration(ZstackConfigId.ZCD_NV_PRECFGKEYS_ENABLE, valueFromUInt8(1)); + } + + /** + * Gets the network key. + * + * @return the {@link ZigBeeKey} returned from the NCP or null on error + */ + public ZigBeeKey getNetworkKey() { + int[] response = readConfiguration(ZstackConfigId.ZCD_NV_PRECFGKEY); + if (response == null) { + return null; + } + + return new ZigBeeKey(response); + } + + /** + * Enables network security + * + * @param enableSecurity true to enable network security + * @return {@link ZstackResponseCode} returned from the NCP + */ + public ZstackResponseCode setNetworkSecurity(boolean enableSecurity) { + return writeConfiguration(ZstackConfigId.ZCD_NV_SECURITY_MODE, valueFromBoolean(enableSecurity)); + } + + /** + * Sets the transmit power to be used in the NCP + * + * @param txPower the TX power in dBm + * @return the power returned from the NCP on success or null on error + */ + public Integer setTxPower(int txPower) { + ZstackSysSetTxPowerSreq request = new ZstackSysSetTxPowerSreq(); + request.setTxPower(txPower); + ZstackTransaction transaction = protocolHandler + .sendTransaction(new ZstackSingleResponseTransaction(request, ZstackSysSetTxPowerSrsp.class)); + ZstackSysSetTxPowerSrsp response = (ZstackSysSetTxPowerSrsp) transaction.getResponse(); + if (response == null) { + logger.debug("No response from SetTxPower command"); + return null; + } + logger.debug(response.toString()); + return response.getTxPower(); + } + + /** + * Sets the channels that can be used in the NCP + * + * @param channelMask the {@link ZigBeeChannelMask} to set + * @return {@link ZstackResponseCode} returned from the NCP + */ + public ZstackResponseCode setChannelMask(ZigBeeChannelMask channelMask) { + // TODO: ZCD_NV_CHANLIST + ZstackUtilSetChannelsSreq request = new ZstackUtilSetChannelsSreq(); + request.setChannels(channelMask.getChannelMask()); + ZstackTransaction transaction = protocolHandler + .sendTransaction(new ZstackSingleResponseTransaction(request, ZstackUtilSetChannelsSrsp.class)); + ZstackUtilSetChannelsSrsp response = (ZstackUtilSetChannelsSrsp) transaction.getResponse(); + if (response == null) { + logger.debug("No response from SetChannels command"); + return ZstackResponseCode.FAILURE; + } + logger.debug(response.toString()); + return response.getStatus(); + } + + /** + * Starts the application on the NCP. This will put the NCP onto the network. + * + * @return {@link ZstackResponseCode} returned from the NCP + */ + public ZstackResponseCode startupApplication() { + ZstackZdoStartupFromAppSreq request = new ZstackZdoStartupFromAppSreq(); + request.setStartDelay(100); + ZstackTransaction transaction = protocolHandler + .sendTransaction(new ZstackSingleResponseTransaction(request, ZstackZdoStartupFromAppSrsp.class)); + ZstackZdoStartupFromAppSrsp response = (ZstackZdoStartupFromAppSrsp) transaction.getResponse(); + if (response == null) { + logger.debug("No response from startupApplication command"); + return ZstackResponseCode.FAILURE; + } + logger.debug(response.toString()); + return response.getStatus(); + } + + /** + * Sets the policy flag on Trust Center device to mandate or not the TCLK exchange procedure. + *

+ * APP_CNF_BDB_SET_TC_REQUIRE_KEY_EXCHANGE + * + * @param required true if the TCLK exchange procedure is required. + * @return {@link ZstackResponseCode} returned from the NCP + */ + public ZstackResponseCode requireKeyExchange(boolean required) { + ZstackAppCnfBdbSetTcRequireKeyExchangeSreq request = new ZstackAppCnfBdbSetTcRequireKeyExchangeSreq(); + request.setTrustCenterRequireKeyExchange(required); + ZstackTransaction transaction = protocolHandler.sendTransaction( + new ZstackSingleResponseTransaction(request, ZstackAppCnfBdbSetTcRequireKeyExchangeSrsp.class)); + ZstackAppCnfBdbSetTcRequireKeyExchangeSrsp response = (ZstackAppCnfBdbSetTcRequireKeyExchangeSrsp) transaction + .getResponse(); + if (response == null) { + logger.debug("No response from requireKeyExchange command"); + return ZstackResponseCode.FAILURE; + } + logger.debug(response.toString()); + return response.getStatus(); + } + + /** + * Sets the policy to mandate or not the usage of an Install Code upon joining. + *

+ * APP_CNF_BDB_SET_ACTIVE_DEFAULT_CENTRALIZED_KEY + * + * @param mode the {@link ZstackCentralizedLinkKeyMode} + * @param installCode array with the code in the required format + * @return {@link ZstackResponseCode} returned from the NCP + */ + public ZstackResponseCode setCentralisedKey(ZstackCentralizedLinkKeyMode mode, int[] installCode) { + ZstackAppCnfBdbSetActiveDefaultCentralizedKeySreq request = new ZstackAppCnfBdbSetActiveDefaultCentralizedKeySreq(); + request.setCentralizedLinkKeyMode(mode); + request.setInstallCode(installCode); + ZstackTransaction transaction = protocolHandler.sendTransaction( + new ZstackSingleResponseTransaction(request, ZstackAppCnfBdbSetActiveDefaultCentralizedKeySrsp.class)); + ZstackAppCnfBdbSetActiveDefaultCentralizedKeySrsp response = (ZstackAppCnfBdbSetActiveDefaultCentralizedKeySrsp) transaction + .getResponse(); + if (response == null) { + logger.debug("No response from setCentralisedKey command"); + return ZstackResponseCode.FAILURE; + } + logger.debug(response.toString()); + return response.getStatus(); + } + + /** + * Sets the AllowRejoin TC policy. + *

+ * APP_CNF_SET_ALLOWREJOIN_TC_POLICY + * + * @param allow true to allow rejoins + * @return {@link ZstackResponseCode} returned from the NCP + */ + public ZstackResponseCode allowRejoin(boolean allow) { + ZstackAppCnfSetAllowrejoinTcPolicySreq request = new ZstackAppCnfSetAllowrejoinTcPolicySreq(); + request.setAllowRejoin(allow); + ZstackTransaction transaction = protocolHandler.sendTransaction( + new ZstackSingleResponseTransaction(request, ZstackAppCnfSetAllowrejoinTcPolicySrsp.class)); + ZstackAppCnfSetAllowrejoinTcPolicySrsp response = (ZstackAppCnfSetAllowrejoinTcPolicySrsp) transaction + .getResponse(); + if (response == null) { + logger.debug("No response from allowRejoin command"); + return ZstackResponseCode.FAILURE; + } + logger.debug(response.toString()); + return response.getStatus(); + } + + /** + * Registers for a ZDO callback + * + * @return {@link ZstackResponseCode} returned from the NCP + */ + public ZstackResponseCode zdoRegisterCallback(int clusterId) { + ZstackZdoMsgCbRegisterSreq request = new ZstackZdoMsgCbRegisterSreq(); + request.setClusterId(clusterId); + ZstackTransaction transaction = protocolHandler + .sendTransaction(new ZstackSingleResponseTransaction(request, ZstackZdoMsgCbRegisterSrsp.class)); + ZstackZdoMsgCbRegisterSrsp response = (ZstackZdoMsgCbRegisterSrsp) transaction.getResponse(); + if (response == null) { + logger.debug("No response from RegisterZdoCallback command"); + return ZstackResponseCode.FAILURE; + } + logger.debug(response.toString()); + return response.getStatus(); + } + + /** + * Registers an AF Endpoint in the NCP + * + * @param endpointId the endpoint number to add + * @param deviceId the device id for the endpoint + * @param profileId the profile id + * @param inputClusters an array of input clusters supported by the endpoint + * @param outputClusters an array of output clusters supported by the endpoint + * @return {@link ZstackResponseCode} returned from the NCP + */ + public ZstackResponseCode addEndpoint(int endpointId, int deviceId, int profileId, int[] inputClusters, + int[] outputClusters) { + ZstackAfRegisterSreq request = new ZstackAfRegisterSreq(); + request.setEndPoint(endpointId); + request.setAppDeviceId(deviceId); + request.setAppProfId(profileId); + request.setAppInClusterList(inputClusters); + request.setAppOutClusterList(outputClusters); + request.setLatencyReq(0); + request.setAppDevVer(0); + + ZstackTransaction transaction = protocolHandler + .sendTransaction(new ZstackSingleResponseTransaction(request, ZstackAfRegisterSrsp.class)); + ZstackAfRegisterSrsp response = (ZstackAfRegisterSrsp) transaction.getResponse(); + if (response == null) { + logger.debug("No response from RegisterEndpoint command"); + return ZstackResponseCode.FAILURE; + } + logger.debug(response.toString()); + return response.getStatus(); + } + + /** + * Adds an install code to the NCP. The code must be a ZigBee key - ie not the install code itself. + * + * @param ieeeAddress the {@link IeeeAddress} associated with the key + * @param key the {@link ZigBeeKey} to set + * @return {@link ZstackResponseCode} returned from the NCP + */ + public ZstackResponseCode addInstallCode(IeeeAddress ieeeAddress, ZigBeeKey key) { + ZstackAppCnfBdbAddInstallcodeSreq request = new ZstackAppCnfBdbAddInstallcodeSreq(); + request.setInstallCodeFormat(ZstackInstallCodeFormat.DERIVED_KEY); + request.setIeeeAddress(ieeeAddress); + request.setInstallCode(key); + + ZstackTransaction transaction = protocolHandler + .sendTransaction(new ZstackSingleResponseTransaction(request, ZstackAppCnfBdbAddInstallcodeSrsp.class)); + ZstackAppCnfBdbAddInstallcodeSrsp response = (ZstackAppCnfBdbAddInstallcodeSrsp) transaction.getResponse(); + if (response == null) { + logger.debug("No response from AddInstallCode command"); + return ZstackResponseCode.FAILURE; + } + logger.debug(response.toString()); + return response.getStatus(); + } + + private int[] valueFromBoolean(boolean value) { + return new int[] { value ? 1 : 0 }; + } + + private int[] valueFromUInt8(int value) { + return new int[] { value }; + } + + private int[] valueFromUInt16(int value) { + return new int[] { value & 0xFF, (value >> 8) & 0xFF }; + } + +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/ZstackCommand.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/ZstackCommand.java new file mode 100644 index 0000000000..fa0dfe6a0d --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/ZstackCommand.java @@ -0,0 +1,44 @@ +/** + * 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.dongle.zstack.api; + +/** + * Base class for all ZStack commands + * + * @author Chris Jackson + * + */ +public abstract class ZstackCommand { + /** + * Definitions of API subsystems + */ + protected static int ZSTACK_RPC = 0x00; + protected static int ZSTACK_SYS = 0x01; + protected static int ZSTACK_MAC = 0x02; + protected static int ZSTACK_AF = 0x04; + protected static int ZSTACK_ZDO = 0x05; + protected static int ZSTACK_SAPI = 0x06; + protected static int ZSTACK_UTIL = 0x07; + protected static int ZSTACK_APP = 0x09; + protected static int ZSTACK_SBL = 0x0D; + protected static int ZSTACK_APP_CNF = 0x0F; + + /** + * Flag denoting if this command/request is done synchronously + */ + protected boolean synchronousCommand = false; + + /** + * Returns true if this request/response is performed synchronously + * + * @return true if the request requires asynchronous response + */ + public boolean isSynchronous() { + return synchronousCommand; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/ZstackFrameFactory.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/ZstackFrameFactory.java new file mode 100644 index 0000000000..8a45c3e40e --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/ZstackFrameFactory.java @@ -0,0 +1,233 @@ +/** + * 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.dongle.zstack.api; + +import com.zsmartsystems.zigbee.dongle.zstack.api.af.ZstackAfDataConfirmAreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.af.ZstackAfDataRequestSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.af.ZstackAfIncomingMsgAreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.af.ZstackAfRegisterSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.appcnf.ZstackAppCnfBdbAddInstallcodeSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.appcnf.ZstackAppCnfBdbCommissioningNotificationAreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.appcnf.ZstackAppCnfBdbSetActiveDefaultCentralizedKeySrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.appcnf.ZstackAppCnfBdbSetJoinusesinstallcodekeySrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.appcnf.ZstackAppCnfBdbSetTcRequireKeyExchangeSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.appcnf.ZstackAppCnfSetAllowrejoinTcPolicySrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.mac.ZstackMacScanReqSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sapi.ZstackZbGetDeviceInfoSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sapi.ZstackZbReadConfigurationSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sapi.ZstackZbWriteConfigurationSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sbl.ZstackSbHandshakeCmdSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sbl.ZstackSbWriteCmdSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysGetExtAddrSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysOsalNvReadSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysOsalNvWriteSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysPingSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysResetIndAreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysSetExtAddrSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysSetTxPowerSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysVersionSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysZdiagsClearStatsSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysZdiagsGetStatsSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysZdiagsInitStatsSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysZdiagsRestoreStatsNvSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysZdiagsSaveStatsToNvSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilApsmeLinkKeyDataGetSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilApsmeLinkKeyNvIdGetSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilGetDeviceInfoSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilGetNvInfoSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilLedControlSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilSetChannelsSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilSetPanidSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilSetPrecfgkeySrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilSetSeclevelSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.zdo.ZstackZdoGetLinkKeySrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.zdo.ZstackZdoLeaveIndAreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.zdo.ZstackZdoMsgCbIncomingAreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.zdo.ZstackZdoMsgCbRegisterSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.zdo.ZstackZdoNwkDiscoveryReqSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.zdo.ZstackZdoRemoveLinkKeySrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.zdo.ZstackZdoSetLinkKeySrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.zdo.ZstackZdoStartupFromAppSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.zdo.ZstackZdoStateChangeIndAreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.zdo.ZstackZdoTcDevIndAreq; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Factory class to create Z-Stack commands from incoming data. This will only create {@link ZstackFrameResponse}s. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackFrameFactory { + /** + * Logger + */ + private static Logger logger = LoggerFactory.getLogger(ZstackFrameFactory.class); + + /* + * Subsystem definitions + */ + public static int ZSTACK_RPC = 0x0000; + public static int ZSTACK_SYS = 0x0100; + public static int ZSTACK_MAC = 0x0200; + public static int ZSTACK_AF = 0x0400; + public static int ZSTACK_ZDO = 0x0500; + public static int ZSTACK_SAPI = 0x0600; + public static int ZSTACK_UTIL = 0x0700; + public static int ZSTACK_APP_CNF = 0x0F00; + public static int ZSTACK_SBL = 0x0D00; + + /** + * Subsystem definition mask + */ + private static int ZSTACK_SUBSYSTEM_MASK = 0x1F; + + private static final int AF_DATA_CONFIRM = 0x80; + private static final int AF_DATA_REQUEST = 0x01; + private static final int AF_INCOMING_MSG = 0x81; + private static final int AF_REGISTER = 0x00; + private static final int APP_CNF_BDB_ADD_INSTALLCODE = 0x04; + private static final int APP_CNF_BDB_COMMISSIONING_NOTIFICATION = 0x80; + private static final int APP_CNF_BDB_SET_ACTIVE_DEFAULT_CENTRALIZED_KEY = 0x07; + private static final int APP_CNF_BDB_SET_JOINUSESINSTALLCODEKEY = 0x06; + private static final int APP_CNF_BDB_SET_TC_REQUIRE_KEY_EXCHANGE = 0x09; + private static final int APP_CNF_SET_ALLOWREJOIN_TC_POLICY = 0x03; + private static final int MAC_SCAN_REQ = 0x0C; + private static final int RPC_SREQ_ERROR = 0x00; + private static final int SB_HANDSHAKE_CMD = 0x04; + private static final int SB_WRITE_CMD = 0x00; + private static final int SYS_GET_EXT_ADDR = 0x04; + private static final int SYS_OSAL_NV_READ = 0x08; + private static final int SYS_OSAL_NV_WRITE = 0x09; + private static final int SYS_PING = 0x01; + private static final int SYS_RESET_IND = 0x80; + private static final int SYS_SET_EXT_ADDR = 0x03; + private static final int SYS_SET_TX_POWER = 0x14; + private static final int SYS_VERSION = 0x02; + private static final int SYS_ZDIAGS_CLEAR_STATS = 0x18; + private static final int SYS_ZDIAGS_GET_STATS = 0x19; + private static final int SYS_ZDIAGS_INIT_STATS = 0x17; + private static final int SYS_ZDIAGS_RESTORE_STATS_NV = 0x1A; + private static final int SYS_ZDIAGS_SAVE_STATS_TO_NV = 0x1B; + private static final int UTIL_APSME_LINK_KEY_DATA_GET = 0x44; + private static final int UTIL_APSME_LINK_KEY_NV_ID_GET = 0x45; + private static final int UTIL_GET_DEVICE_INFO = 0x00; + private static final int UTIL_GET_NV_INFO = 0x01; + private static final int UTIL_LED_CONTROL = 0x09; + private static final int UTIL_SET_CHANNELS = 0x03; + private static final int UTIL_SET_PANID = 0x02; + private static final int UTIL_SET_PRECFGKEY = 0x05; + private static final int UTIL_SET_SECLEVEL = 0x04; + private static final int ZB_GET_DEVICE_INFO = 0x06; + private static final int ZB_READ_CONFIGURATION = 0x04; + private static final int ZB_WRITE_CONFIGURATION = 0x05; + private static final int ZDO_GET_LINK_KEY = 0x25; + private static final int ZDO_LEAVE_IND = 0xC9; + private static final int ZDO_MSG_CB_INCOMING = 0xFF; + private static final int ZDO_MSG_CB_REGISTER = 0x3E; + private static final int ZDO_NWK_DISCOVERY_REQ = 0x26; + private static final int ZDO_REMOVE_LINK_KEY = 0x24; + private static final int ZDO_SET_LINK_KEY = 0x23; + private static final int ZDO_STARTUP_FROM_APP = 0x40; + private static final int ZDO_STATE_CHANGE_IND = 0xC0; + private static final int ZDO_TC_DEV_IND = 0xCA; + + private static Map> zstackFrameMap = new HashMap>(); + + static { + zstackFrameMap.put(ZSTACK_AF + AF_DATA_CONFIRM, ZstackAfDataConfirmAreq.class); + zstackFrameMap.put(ZSTACK_AF + AF_DATA_REQUEST, ZstackAfDataRequestSrsp.class); + zstackFrameMap.put(ZSTACK_AF + AF_INCOMING_MSG, ZstackAfIncomingMsgAreq.class); + zstackFrameMap.put(ZSTACK_AF + AF_REGISTER, ZstackAfRegisterSrsp.class); + zstackFrameMap.put(ZSTACK_APP_CNF + APP_CNF_BDB_ADD_INSTALLCODE, ZstackAppCnfBdbAddInstallcodeSrsp.class); + zstackFrameMap.put(ZSTACK_APP_CNF + APP_CNF_BDB_COMMISSIONING_NOTIFICATION, ZstackAppCnfBdbCommissioningNotificationAreq.class); + zstackFrameMap.put(ZSTACK_APP_CNF + APP_CNF_BDB_SET_ACTIVE_DEFAULT_CENTRALIZED_KEY, ZstackAppCnfBdbSetActiveDefaultCentralizedKeySrsp.class); + zstackFrameMap.put(ZSTACK_APP_CNF + APP_CNF_BDB_SET_JOINUSESINSTALLCODEKEY, ZstackAppCnfBdbSetJoinusesinstallcodekeySrsp.class); + zstackFrameMap.put(ZSTACK_APP_CNF + APP_CNF_BDB_SET_TC_REQUIRE_KEY_EXCHANGE, ZstackAppCnfBdbSetTcRequireKeyExchangeSrsp.class); + zstackFrameMap.put(ZSTACK_APP_CNF + APP_CNF_SET_ALLOWREJOIN_TC_POLICY, ZstackAppCnfSetAllowrejoinTcPolicySrsp.class); + zstackFrameMap.put(ZSTACK_MAC + MAC_SCAN_REQ, ZstackMacScanReqSrsp.class); + zstackFrameMap.put(ZSTACK_RPC + RPC_SREQ_ERROR, ZstackRpcSreqErrorSrsp.class); + zstackFrameMap.put(ZSTACK_SBL + SB_HANDSHAKE_CMD, ZstackSbHandshakeCmdSrsp.class); + zstackFrameMap.put(ZSTACK_SBL + SB_WRITE_CMD, ZstackSbWriteCmdSrsp.class); + zstackFrameMap.put(ZSTACK_SYS + SYS_GET_EXT_ADDR, ZstackSysGetExtAddrSrsp.class); + zstackFrameMap.put(ZSTACK_SYS + SYS_OSAL_NV_READ, ZstackSysOsalNvReadSrsp.class); + zstackFrameMap.put(ZSTACK_SYS + SYS_OSAL_NV_WRITE, ZstackSysOsalNvWriteSrsp.class); + zstackFrameMap.put(ZSTACK_SYS + SYS_PING, ZstackSysPingSrsp.class); + zstackFrameMap.put(ZSTACK_SYS + SYS_RESET_IND, ZstackSysResetIndAreq.class); + zstackFrameMap.put(ZSTACK_SYS + SYS_SET_EXT_ADDR, ZstackSysSetExtAddrSrsp.class); + zstackFrameMap.put(ZSTACK_SYS + SYS_SET_TX_POWER, ZstackSysSetTxPowerSrsp.class); + zstackFrameMap.put(ZSTACK_SYS + SYS_VERSION, ZstackSysVersionSrsp.class); + zstackFrameMap.put(ZSTACK_SYS + SYS_ZDIAGS_CLEAR_STATS, ZstackSysZdiagsClearStatsSrsp.class); + zstackFrameMap.put(ZSTACK_SYS + SYS_ZDIAGS_GET_STATS, ZstackSysZdiagsGetStatsSrsp.class); + zstackFrameMap.put(ZSTACK_SYS + SYS_ZDIAGS_INIT_STATS, ZstackSysZdiagsInitStatsSrsp.class); + zstackFrameMap.put(ZSTACK_SYS + SYS_ZDIAGS_RESTORE_STATS_NV, ZstackSysZdiagsRestoreStatsNvSrsp.class); + zstackFrameMap.put(ZSTACK_SYS + SYS_ZDIAGS_SAVE_STATS_TO_NV, ZstackSysZdiagsSaveStatsToNvSrsp.class); + zstackFrameMap.put(ZSTACK_UTIL + UTIL_APSME_LINK_KEY_DATA_GET, ZstackUtilApsmeLinkKeyDataGetSrsp.class); + zstackFrameMap.put(ZSTACK_UTIL + UTIL_APSME_LINK_KEY_NV_ID_GET, ZstackUtilApsmeLinkKeyNvIdGetSrsp.class); + zstackFrameMap.put(ZSTACK_UTIL + UTIL_GET_DEVICE_INFO, ZstackUtilGetDeviceInfoSrsp.class); + zstackFrameMap.put(ZSTACK_UTIL + UTIL_GET_NV_INFO, ZstackUtilGetNvInfoSrsp.class); + zstackFrameMap.put(ZSTACK_UTIL + UTIL_LED_CONTROL, ZstackUtilLedControlSrsp.class); + zstackFrameMap.put(ZSTACK_UTIL + UTIL_SET_CHANNELS, ZstackUtilSetChannelsSrsp.class); + zstackFrameMap.put(ZSTACK_UTIL + UTIL_SET_PANID, ZstackUtilSetPanidSrsp.class); + zstackFrameMap.put(ZSTACK_UTIL + UTIL_SET_PRECFGKEY, ZstackUtilSetPrecfgkeySrsp.class); + zstackFrameMap.put(ZSTACK_UTIL + UTIL_SET_SECLEVEL, ZstackUtilSetSeclevelSrsp.class); + zstackFrameMap.put(ZSTACK_SAPI + ZB_GET_DEVICE_INFO, ZstackZbGetDeviceInfoSrsp.class); + zstackFrameMap.put(ZSTACK_SAPI + ZB_READ_CONFIGURATION, ZstackZbReadConfigurationSrsp.class); + zstackFrameMap.put(ZSTACK_SAPI + ZB_WRITE_CONFIGURATION, ZstackZbWriteConfigurationSrsp.class); + zstackFrameMap.put(ZSTACK_ZDO + ZDO_GET_LINK_KEY, ZstackZdoGetLinkKeySrsp.class); + zstackFrameMap.put(ZSTACK_ZDO + ZDO_LEAVE_IND, ZstackZdoLeaveIndAreq.class); + zstackFrameMap.put(ZSTACK_ZDO + ZDO_MSG_CB_INCOMING, ZstackZdoMsgCbIncomingAreq.class); + zstackFrameMap.put(ZSTACK_ZDO + ZDO_MSG_CB_REGISTER, ZstackZdoMsgCbRegisterSrsp.class); + zstackFrameMap.put(ZSTACK_ZDO + ZDO_NWK_DISCOVERY_REQ, ZstackZdoNwkDiscoveryReqSrsp.class); + zstackFrameMap.put(ZSTACK_ZDO + ZDO_REMOVE_LINK_KEY, ZstackZdoRemoveLinkKeySrsp.class); + zstackFrameMap.put(ZSTACK_ZDO + ZDO_SET_LINK_KEY, ZstackZdoSetLinkKeySrsp.class); + zstackFrameMap.put(ZSTACK_ZDO + ZDO_STARTUP_FROM_APP, ZstackZdoStartupFromAppSrsp.class); + zstackFrameMap.put(ZSTACK_ZDO + ZDO_STATE_CHANGE_IND, ZstackZdoStateChangeIndAreq.class); + zstackFrameMap.put(ZSTACK_ZDO + ZDO_TC_DEV_IND, ZstackZdoTcDevIndAreq.class); + } + + /** + * Creates and {@link ZstackFrameResponse} from the incoming data. + * + * @param data the int[] containing the ZStack data from which to generate the frame + * @return the {@link ZstackFrameResponse} or null if the response can't be created. + */ + public static ZstackFrameResponse createFrame(int[] data) { + if (data.length < 2) { + return null; + } + + int cmdId = ((data[0] & ZSTACK_SUBSYSTEM_MASK) << 8) + data[1]; + Class zstackClass = zstackFrameMap.get(cmdId); + + if (zstackClass == null) { + return null; + } + + Constructor ctor; + try { + ctor = zstackClass.getConstructor(int[].class); + return (ZstackFrameResponse) ctor.newInstance(data); + } catch (SecurityException | NoSuchMethodException | IllegalArgumentException | InstantiationException + | IllegalAccessException | InvocationTargetException e) { + logger.debug("Error creating instance of ZstackCommand", e); + } + + return null; + } + + +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/ZstackFrameRequest.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/ZstackFrameRequest.java new file mode 100644 index 0000000000..85c8e89fec --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/ZstackFrameRequest.java @@ -0,0 +1,62 @@ +/** + * 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.dongle.zstack.api; + +import java.util.Arrays; + +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.internal.serializer.ZstackSerializer; + +/** + * + * @author Chris Jackson + * + */ +public abstract class ZstackFrameRequest extends ZstackCommand { + protected ZstackSerializer serializer = new ZstackSerializer(); + + private static final int ZSTACK_SOF = 0xFE; + + protected int ZSTACK_SREQ = 0x20; + protected int ZSTACK_AREQ = 0x40; + protected int ZSTACK_ACMD = 0x40; + + public abstract int[] serialize(); + + protected void serializeHeader(int type, int subsystem, int id) { + serializer.serializeUInt8(ZSTACK_SOF); + serializer.serializeUInt8(0); // Length will be updated later + serializer.serializeUInt8(type + subsystem); + serializer.serializeUInt8(id); + } + + protected int[] getPayload() { + serializer.serializeUInt8(0); // Checksum will be updated later + int buffer[] = serializer.getBuffer(); + buffer[1] = buffer.length - 5; + + int checksum = 0; + for (int cnt = 1; cnt < buffer.length; cnt++) { + checksum ^= buffer[cnt]; + } + buffer[buffer.length - 1] = checksum & 0xFF; + + return Arrays.copyOfRange(buffer, 0, buffer.length); + } + + /** + * Processes the {@link ZstackRpcSreqErrorSrsp} response which is an error return from the NCP and checks if it is + * related to this request. + * + * @param response the received {@link ZstackRpcSreqErrorSrsp} + * @return true if this request matches the command codes in the {@link ZstackRpcSreqErrorSrsp} + */ + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return false; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/ZstackFrameResponse.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/ZstackFrameResponse.java new file mode 100644 index 0000000000..59a456da69 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/ZstackFrameResponse.java @@ -0,0 +1,27 @@ +/** + * 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.dongle.zstack.api; + +import com.zsmartsystems.zigbee.dongle.zstack.internal.serializer.ZstackDeserializer; + +/** + * + * @author Chris Jackson + * + */ +public abstract class ZstackFrameResponse extends ZstackCommand { + protected ZstackDeserializer deserializer; + + public ZstackFrameResponse(int[] inputBuffer) { + deserializer = new ZstackDeserializer(inputBuffer); + + // Skip the command ID + deserializer.deserializeUInt16(); + } + +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/ZstackResponseCode.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/ZstackResponseCode.java new file mode 100644 index 0000000000..370a17daf5 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/ZstackResponseCode.java @@ -0,0 +1,124 @@ +/** + * 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.dongle.zstack.api; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the Z-Stack Enumeration ZstackResponseCode. + *

+ * Global response codes + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public enum ZstackResponseCode { + /** + * Default unknown value + */ + UNKNOWN(-1), + + /** + * + */ + SUCCESS(0x0000), + + /** + * + */ + FAILURE(0x0001), + + /** + * + */ + AF_INVALID_PARAMETER(0x0002), + + /** + * Security manager key table full + */ + AF_MEM_FAIL(0x0010), + + /** + * Security manager key table full + */ + KEY_TABLE_FULL(0x0011), + + /** + * The operation could not be completed because no memory resources were available + */ + MAC_NO_RESOURCES(0x001A), + + /** + * Invalid Request + */ + INVALID_REQUEST(0x00C2), + + /** + * Not Permitted + */ + NOT_PERMITTED(0x00C3), + + /** + * Unknown Device + */ + UNKNOWN_DEVICE(0x00C8), + + /** + * + */ + AF_NO_ROUTE(0x00CD), + + /** + * The scan request failed because a scan is already in progress + */ + MAC_SCAN_IN_PROGRESS(0x00FC); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + static { + codeMapping = new HashMap(); + for (ZstackResponseCode s : values()) { + codeMapping.put(s.key, s); + } + } + + private ZstackResponseCode(int key) { + this.key = key; + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param code the code to lookup + * @return enumeration value of the alarm type. + */ + public static ZstackResponseCode valueOf(int code) { + if (codeMapping.get(code) == null) { + return UNKNOWN; + } + + return codeMapping.get(code); + } + + /** + * Returns the Z-Stack protocol defined value for this enumeration. + * + * @return the Z-Stack protocol key + */ + public int getKey() { + return key; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/af/AfDataOptions.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/af/AfDataOptions.java new file mode 100644 index 0000000000..3b6d4b8a96 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/af/AfDataOptions.java @@ -0,0 +1,82 @@ +/** + * 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.dongle.zstack.api.af; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the Z-Stack Enumeration AfDataOptions. + *

+ * Options applied when sending frames + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public enum AfDataOptions { + + /** + * Set this bit to request APS acknowledgement for this packet + */ + AF_ACK_REQUEST(0x0010), + + /** + * Set this bit to force route discovery if a routing table entry doesn’t exist + */ + AF_DISCV_ROUTE(0x0020), + + /** + * Set this bit to enable APS security for this packet. + */ + AF_EN_SECURITY(0x0040), + + /** + * Skip routing. + */ + AF_NO_ROUTING(0x0080); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + static { + codeMapping = new HashMap(); + for (AfDataOptions s : values()) { + codeMapping.put(s.key, s); + } + } + + private AfDataOptions(int key) { + this.key = key; + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param code the code to lookup + * @return enumeration value of the alarm type. + */ + public static AfDataOptions valueOf(int code) { + + return codeMapping.get(code); + } + + /** + * Returns the Z-Stack protocol defined value for this enumeration. + * + * @return the Z-Stack protocol key + */ + public int getKey() { + return key; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/af/ZstackAfDataConfirmAreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/af/ZstackAfDataConfirmAreq.java new file mode 100644 index 0000000000..e517917b4d --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/af/ZstackAfDataConfirmAreq.java @@ -0,0 +1,124 @@ +/** + * 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.dongle.zstack.api.af; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command AF_DATA_CONFIRM. + *

+ * This command is sent by the device to the user after it receives an AF_DATA_REQUEST. For each AF_DATA_REQUEST, a + * AF_DATA_CONFIRM is always returned. If APS acknowledgement was used for the AF_DATA_REQUEST, the confirm carries the status + * of whether the APS acknowledgement was received or not (ZApsNoAck – 0xb7). If APS acknowledgement was not used, then the confirm + * carries the status of whether the MAC acknowledgement (“next hop” acknowledgment) was received or not (ZMacNoACK – 0xe9). This + * also applies to packets that are sent using AF_DATA_REQUEST_EXT and AF_DATA_STORE. For APS fragmented packets, the value of + * the configuration item ZCD_NV_APSF_WINDOW_SIZE determines when an AF_DATA_CONFIRM that carries the status of the APS + * acknowledgement is received. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackAfDataConfirmAreq extends ZstackFrameResponse { + + /** + * Status is either Success (0) or Failure (1). + */ + private ZstackResponseCode status; + + /** + * Endpoint of the device. + */ + private int endpoint; + + /** + * Specifies the transaction sequence number of the message. + */ + private int transId; + + /** + * Response and Handler constructor + */ + public ZstackAfDataConfirmAreq(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + endpoint = deserializer.deserializeUInt8(); + transId = deserializer.deserializeUInt8(); + } + + /** + * Status is either Success (0) or Failure (1). + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * Status is either Success (0) or Failure (1). + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + /** + * Endpoint of the device. + * + * @return the current endpoint as {@link int} + */ + public int getEndpoint() { + return endpoint; + } + + /** + * Endpoint of the device. + * + * @param endpoint the Endpoint to set as {@link int} + */ + public void setEndpoint(int endpoint) { + this.endpoint = endpoint; + } + + /** + * Specifies the transaction sequence number of the message. + * + * @return the current transId as {@link int} + */ + public int getTransId() { + return transId; + } + + /** + * Specifies the transaction sequence number of the message. + * + * @param transId the TransId to set as {@link int} + */ + public void setTransId(int transId) { + this.transId = transId; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(101); + builder.append("ZstackAfDataConfirmAreq [status="); + builder.append(status); + builder.append(", endpoint="); + builder.append(String.format("%02X", endpoint)); + builder.append(", transId="); + builder.append(String.format("%02X", transId)); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/af/ZstackAfDataRequestSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/af/ZstackAfDataRequestSreq.java new file mode 100644 index 0000000000..10d94543c6 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/af/ZstackAfDataRequestSreq.java @@ -0,0 +1,290 @@ +/** + * 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.dongle.zstack.api.af; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.af.AfDataOptions; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; +import java.util.HashSet; +import java.util.Set; + +/** + * Class to implement the Z-Stack command AF_DATA_REQUEST. + *

+ * This command is used by the App processor to build and send a message through AF layer. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackAfDataRequestSreq extends ZstackFrameRequest { + + /** + * Short address of the destination device. + */ + private int dstAddr; + + /** + * Endpoint of the destination device. + */ + private int destEndpoint; + + /** + * Endpoint of the source device. + */ + private int srcEndpoint; + + /** + * Specifies the cluster ID. + */ + private int clusterId; + + /** + * Specifies the transaction sequence number of the message. The corresponding AF_DATA_CONFIRM will have the same TransID. This + * can be useful if the application wishes to match up AF_DATA_REQUESTs with AF_DATA_CONFIRMs. + */ + private int transId; + + /** + * The transmit options field is organized as a bitmask. The following enumerates the values for the various supported bitmasks. + * For example, a value of 0x10 means that bit 4 is set. + *

+ * Parameter allows multiple options so implemented as a {@link Set}. + */ + private Set options = new HashSet<>(); + + /** + * Specifies the list of Input Cluster Ids ( 2bytes each ). + */ + private int radius; + + /** + * 0-99 bytes data. Without any security (99 bytes), with NWK security (81 bytes), with NWK and APS security (64 bytes). + */ + private int[] data; + + /** + * Request constructor + */ + public ZstackAfDataRequestSreq() { + synchronousCommand = true; + } + + /** + * Short address of the destination device. + * + * @return the current dstAddr as {@link int} + */ + public int getDstAddr() { + return dstAddr; + } + + /** + * Short address of the destination device. + * + * @param dstAddr the DstAddr to set as {@link int} + */ + public void setDstAddr(int dstAddr) { + this.dstAddr = dstAddr; + } + + /** + * Endpoint of the destination device. + * + * @return the current destEndpoint as {@link int} + */ + public int getDestEndpoint() { + return destEndpoint; + } + + /** + * Endpoint of the destination device. + * + * @param destEndpoint the DestEndpoint to set as {@link int} + */ + public void setDestEndpoint(int destEndpoint) { + this.destEndpoint = destEndpoint; + } + + /** + * Endpoint of the source device. + * + * @return the current srcEndpoint as {@link int} + */ + public int getSrcEndpoint() { + return srcEndpoint; + } + + /** + * Endpoint of the source device. + * + * @param srcEndpoint the SrcEndpoint to set as {@link int} + */ + public void setSrcEndpoint(int srcEndpoint) { + this.srcEndpoint = srcEndpoint; + } + + /** + * Specifies the cluster ID. + * + * @return the current clusterId as {@link int} + */ + public int getClusterID() { + return clusterId; + } + + /** + * Specifies the cluster ID. + * + * @param clusterId the ClusterID to set as {@link int} + */ + public void setClusterID(int clusterId) { + this.clusterId = clusterId; + } + + /** + * Specifies the transaction sequence number of the message. The corresponding AF_DATA_CONFIRM will have the same TransID. This + * can be useful if the application wishes to match up AF_DATA_REQUESTs with AF_DATA_CONFIRMs. + * + * @return the current transId as {@link int} + */ + public int getTransID() { + return transId; + } + + /** + * Specifies the transaction sequence number of the message. The corresponding AF_DATA_CONFIRM will have the same TransID. This + * can be useful if the application wishes to match up AF_DATA_REQUESTs with AF_DATA_CONFIRMs. + * + * @param transId the TransID to set as {@link int} + */ + public void setTransID(int transId) { + this.transId = transId; + } + + /** + * The transmit options field is organized as a bitmask. The following enumerates the values for the various supported bitmasks. + * For example, a value of 0x10 means that bit 4 is set. + * + * @return the current options as {@link Set} of {@link AfDataOptions} + */ + public Set getOptions() { + return options; + } + + /** + * The transmit options field is organized as a bitmask. The following enumerates the values for the various supported bitmasks. + * For example, a value of 0x10 means that bit 4 is set. + * + * @param options the Options to add to the {@link Set} as {@link AfDataOptions} + */ + public void addOptions(AfDataOptions options) { + this.options.add(options); + } + + /** + * The transmit options field is organized as a bitmask. The following enumerates the values for the various supported bitmasks. + * For example, a value of 0x10 means that bit 4 is set. + * + * @param options the Options to remove to the {@link Set} as {@link AfDataOptions} + */ + public void removeOptions(AfDataOptions options) { + this.options.remove(options); + } + + /** + * Specifies the list of Input Cluster Ids ( 2bytes each ). + * + * @return the current radius as {@link int} + */ + public int getRadius() { + return radius; + } + + /** + * Specifies the list of Input Cluster Ids ( 2bytes each ). + * + * @param radius the Radius to set as {@link int} + */ + public void setRadius(int radius) { + this.radius = radius; + } + + /** + * 0-99 bytes data. Without any security (99 bytes), with NWK security (81 bytes), with NWK and APS security (64 bytes). + * + * @return the current data as {@link int[]} + */ + public int[] getData() { + return data; + } + + /** + * 0-99 bytes data. Without any security (99 bytes), with NWK security (81 bytes), with NWK and APS security (64 bytes). + * + * @param data the Data to set as {@link int[]} + */ + public void setData(int[] data) { + this.data = data; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_AF) && (response.getReqCmd1() == 0x01)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_AF, 0x01); + + // Serialize the fields + serializer.serializeUInt16(dstAddr); + serializer.serializeUInt8(destEndpoint); + serializer.serializeUInt8(srcEndpoint); + serializer.serializeUInt16(clusterId); + serializer.serializeUInt8(transId); + int tmpOptions = 0; + for (AfDataOptions value : options) { + tmpOptions += value.getKey(); + } + serializer.serializeUInt8(tmpOptions); + serializer.serializeUInt8(radius); + serializer.serializeUInt8(data.length); + serializer.serializeUInt8Array(data); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(251); + builder.append("ZstackAfDataRequestSreq [dstAddr="); + builder.append(String.format("%04X", dstAddr)); + builder.append(", destEndpoint="); + builder.append(String.format("%02X", destEndpoint)); + builder.append(", srcEndpoint="); + builder.append(String.format("%02X", srcEndpoint)); + builder.append(", clusterId="); + builder.append(String.format("%04X", clusterId)); + builder.append(", transId="); + builder.append(String.format("%02X", transId)); + builder.append(", options="); + builder.append(options); + builder.append(", radius="); + builder.append(radius); + builder.append(", data="); + for (int c = 0; c < data.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", data[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/af/ZstackAfDataRequestSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/af/ZstackAfDataRequestSrsp.java new file mode 100644 index 0000000000..79d4f89cb3 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/af/ZstackAfDataRequestSrsp.java @@ -0,0 +1,68 @@ +/** + * 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.dongle.zstack.api.af; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command AF_DATA_REQUEST. + *

+ * This command is used by the App processor to build and send a message through AF layer. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackAfDataRequestSrsp extends ZstackFrameResponse { + + /** + * Status is either Success (0) or Failure (1). + */ + private ZstackResponseCode status; + + /** + * Response and Handler constructor + */ + public ZstackAfDataRequestSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + } + + /** + * Status is either Success (0) or Failure (1). + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * Status is either Success (0) or Failure (1). + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(51); + builder.append("ZstackAfDataRequestSrsp [status="); + builder.append(status); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/af/ZstackAfIncomingMsgAreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/af/ZstackAfIncomingMsgAreq.java new file mode 100644 index 0000000000..107102f28e --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/af/ZstackAfIncomingMsgAreq.java @@ -0,0 +1,334 @@ +/** + * 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.dongle.zstack.api.af; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; + +/** + * Class to implement the Z-Stack command AF_INCOMING_MSG. + *

+ * This callback message is in response to incoming data to any of the registered endpoints on this device. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackAfIncomingMsgAreq extends ZstackFrameResponse { + + /** + * Specifies the group ID of the device. + */ + private int groupId; + + /** + * Specifies the cluster ID. + */ + private int clusterId; + + /** + * Specifies the ZigBee network address of the source device sending the message. + */ + private int srcAddr; + + /** + * Specifies the source endpoint of the message. + */ + private int srcEndpoint; + + /** + * Specifies the destination endpoint of the message. + */ + private int destEndpoint; + + /** + * Specifies if the message was a broadcast or not. + */ + private boolean wasBroadcast; + + /** + * Indicates the link quality measured during reception. + */ + private int linkQuality; + + /** + * Specifies if the security is used or not. + */ + private boolean securityUse; + + /** + * Specifies the timestamp of the message. + */ + private int timeStamp; + + /** + * Specifies transaction sequence number of the message. + */ + private int seqNumber; + + /** + * Contains 0 to 99 bytes of data. Without any security (99 bytes), with NWK security (81 bytes), with NWK and APS security (64 + * bytes). + */ + private int[] data; + + /** + * Response and Handler constructor + */ + public ZstackAfIncomingMsgAreq(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + // Deserialize the fields + groupId = deserializer.deserializeUInt16(); + clusterId = deserializer.deserializeUInt16(); + srcAddr = deserializer.deserializeUInt16(); + srcEndpoint = deserializer.deserializeUInt8(); + destEndpoint = deserializer.deserializeUInt8(); + wasBroadcast = deserializer.deserializeBoolean(); + linkQuality = deserializer.deserializeUInt8(); + securityUse = deserializer.deserializeBoolean(); + timeStamp = deserializer.deserializeUInt32(); + seqNumber = deserializer.deserializeUInt8(); + int len = deserializer.deserializeUInt8(); + data = deserializer.deserializeUInt8Array(len); + } + + /** + * Specifies the group ID of the device. + * + * @return the current groupId as {@link int} + */ + public int getGroupId() { + return groupId; + } + + /** + * Specifies the group ID of the device. + * + * @param groupId the GroupId to set as {@link int} + */ + public void setGroupId(int groupId) { + this.groupId = groupId; + } + + /** + * Specifies the cluster ID. + * + * @return the current clusterId as {@link int} + */ + public int getClusterId() { + return clusterId; + } + + /** + * Specifies the cluster ID. + * + * @param clusterId the ClusterId to set as {@link int} + */ + public void setClusterId(int clusterId) { + this.clusterId = clusterId; + } + + /** + * Specifies the ZigBee network address of the source device sending the message. + * + * @return the current srcAddr as {@link int} + */ + public int getSrcAddr() { + return srcAddr; + } + + /** + * Specifies the ZigBee network address of the source device sending the message. + * + * @param srcAddr the SrcAddr to set as {@link int} + */ + public void setSrcAddr(int srcAddr) { + this.srcAddr = srcAddr; + } + + /** + * Specifies the source endpoint of the message. + * + * @return the current srcEndpoint as {@link int} + */ + public int getSrcEndpoint() { + return srcEndpoint; + } + + /** + * Specifies the source endpoint of the message. + * + * @param srcEndpoint the SrcEndpoint to set as {@link int} + */ + public void setSrcEndpoint(int srcEndpoint) { + this.srcEndpoint = srcEndpoint; + } + + /** + * Specifies the destination endpoint of the message. + * + * @return the current destEndpoint as {@link int} + */ + public int getDestEndpoint() { + return destEndpoint; + } + + /** + * Specifies the destination endpoint of the message. + * + * @param destEndpoint the DestEndpoint to set as {@link int} + */ + public void setDestEndpoint(int destEndpoint) { + this.destEndpoint = destEndpoint; + } + + /** + * Specifies if the message was a broadcast or not. + * + * @return the current wasBroadcast as {@link boolean} + */ + public boolean getWasBroadcast() { + return wasBroadcast; + } + + /** + * Specifies if the message was a broadcast or not. + * + * @param wasBroadcast the WasBroadcast to set as {@link boolean} + */ + public void setWasBroadcast(boolean wasBroadcast) { + this.wasBroadcast = wasBroadcast; + } + + /** + * Indicates the link quality measured during reception. + * + * @return the current linkQuality as {@link int} + */ + public int getLinkQuality() { + return linkQuality; + } + + /** + * Indicates the link quality measured during reception. + * + * @param linkQuality the LinkQuality to set as {@link int} + */ + public void setLinkQuality(int linkQuality) { + this.linkQuality = linkQuality; + } + + /** + * Specifies if the security is used or not. + * + * @return the current securityUse as {@link boolean} + */ + public boolean getSecurityUse() { + return securityUse; + } + + /** + * Specifies if the security is used or not. + * + * @param securityUse the SecurityUse to set as {@link boolean} + */ + public void setSecurityUse(boolean securityUse) { + this.securityUse = securityUse; + } + + /** + * Specifies the timestamp of the message. + * + * @return the current timeStamp as {@link int} + */ + public int getTimeStamp() { + return timeStamp; + } + + /** + * Specifies the timestamp of the message. + * + * @param timeStamp the TimeStamp to set as {@link int} + */ + public void setTimeStamp(int timeStamp) { + this.timeStamp = timeStamp; + } + + /** + * Specifies transaction sequence number of the message. + * + * @return the current seqNumber as {@link int} + */ + public int getSeqNumber() { + return seqNumber; + } + + /** + * Specifies transaction sequence number of the message. + * + * @param seqNumber the SeqNumber to set as {@link int} + */ + public void setSeqNumber(int seqNumber) { + this.seqNumber = seqNumber; + } + + /** + * Contains 0 to 99 bytes of data. Without any security (99 bytes), with NWK security (81 bytes), with NWK and APS security (64 + * bytes). + * + * @return the current data as {@link int[]} + */ + public int[] getData() { + return data; + } + + /** + * Contains 0 to 99 bytes of data. Without any security (99 bytes), with NWK security (81 bytes), with NWK and APS security (64 + * bytes). + * + * @param data the Data to set as {@link int[]} + */ + public void setData(int[] data) { + this.data = data; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(326); + builder.append("ZstackAfIncomingMsgAreq [groupId="); + builder.append(String.format("%04X", groupId)); + builder.append(", clusterId="); + builder.append(String.format("%04X", clusterId)); + builder.append(", srcAddr="); + builder.append(String.format("%04X", srcAddr)); + builder.append(", srcEndpoint="); + builder.append(String.format("%02X", srcEndpoint)); + builder.append(", destEndpoint="); + builder.append(String.format("%02X", destEndpoint)); + builder.append(", wasBroadcast="); + builder.append(wasBroadcast); + builder.append(", linkQuality="); + builder.append(linkQuality); + builder.append(", securityUse="); + builder.append(securityUse); + builder.append(", timeStamp="); + builder.append(String.format("%08X", timeStamp)); + builder.append(", seqNumber="); + builder.append(String.format("%02X", seqNumber)); + builder.append(", data="); + for (int c = 0; c < data.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", data[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/af/ZstackAfRegisterSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/af/ZstackAfRegisterSreq.java new file mode 100644 index 0000000000..ec1f160a31 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/af/ZstackAfRegisterSreq.java @@ -0,0 +1,248 @@ +/** + * 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.dongle.zstack.api.af; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command AF_REGISTER. + *

+ * This command enables the host processor to register an application’s endpoint description (and its simple descriptor). + * Multiple endpoints may be registered with the AF by making multiple calls to AF_REGISTER. This could be useful in the case where + * the device needs to support multiple application profiles, where each AF_REGISTER call would register a unique endpoint + * description per application profile. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackAfRegisterSreq extends ZstackFrameRequest { + + /** + * Specifies the endpoint of this simple descriptor. + */ + private int endPoint; + + /** + * Specifies the profile id of the application. + */ + private int appProfId; + + /** + * Specifies the device description id for this endpoint. + */ + private int appDeviceId; + + /** + * Specifies the device version number. + */ + private int appDevVer; + + /** + * Specifies latency. For ZigBee the only applicable value is 0x00. 0x00-No latency 0x01-fast beacons 0x02-slow beacons + */ + private int latencyReq; + + /** + * Specifies the list of Input Cluster Ids (2 bytes each). + */ + private int[] appInClusterList; + + /** + * Specifies the list of Output Cluster Ids (2 bytes each) + */ + private int[] appOutClusterList; + + /** + * Request constructor + */ + public ZstackAfRegisterSreq() { + synchronousCommand = true; + } + + /** + * Specifies the endpoint of this simple descriptor. + * + * @return the current endPoint as {@link int} + */ + public int getEndPoint() { + return endPoint; + } + + /** + * Specifies the endpoint of this simple descriptor. + * + * @param endPoint the EndPoint to set as {@link int} + */ + public void setEndPoint(int endPoint) { + this.endPoint = endPoint; + } + + /** + * Specifies the profile id of the application. + * + * @return the current appProfId as {@link int} + */ + public int getAppProfId() { + return appProfId; + } + + /** + * Specifies the profile id of the application. + * + * @param appProfId the AppProfId to set as {@link int} + */ + public void setAppProfId(int appProfId) { + this.appProfId = appProfId; + } + + /** + * Specifies the device description id for this endpoint. + * + * @return the current appDeviceId as {@link int} + */ + public int getAppDeviceId() { + return appDeviceId; + } + + /** + * Specifies the device description id for this endpoint. + * + * @param appDeviceId the AppDeviceId to set as {@link int} + */ + public void setAppDeviceId(int appDeviceId) { + this.appDeviceId = appDeviceId; + } + + /** + * Specifies the device version number. + * + * @return the current appDevVer as {@link int} + */ + public int getAppDevVer() { + return appDevVer; + } + + /** + * Specifies the device version number. + * + * @param appDevVer the AppDevVer to set as {@link int} + */ + public void setAppDevVer(int appDevVer) { + this.appDevVer = appDevVer; + } + + /** + * Specifies latency. For ZigBee the only applicable value is 0x00. 0x00-No latency 0x01-fast beacons 0x02-slow beacons + * + * @return the current latencyReq as {@link int} + */ + public int getLatencyReq() { + return latencyReq; + } + + /** + * Specifies latency. For ZigBee the only applicable value is 0x00. 0x00-No latency 0x01-fast beacons 0x02-slow beacons + * + * @param latencyReq the LatencyReq to set as {@link int} + */ + public void setLatencyReq(int latencyReq) { + this.latencyReq = latencyReq; + } + + /** + * Specifies the list of Input Cluster Ids (2 bytes each). + * + * @return the current appInClusterList as {@link int[]} + */ + public int[] getAppInClusterList() { + return appInClusterList; + } + + /** + * Specifies the list of Input Cluster Ids (2 bytes each). + * + * @param appInClusterList the AppInClusterList to set as {@link int[]} + */ + public void setAppInClusterList(int[] appInClusterList) { + this.appInClusterList = appInClusterList; + } + + /** + * Specifies the list of Output Cluster Ids (2 bytes each) + * + * @return the current appOutClusterList as {@link int[]} + */ + public int[] getAppOutClusterList() { + return appOutClusterList; + } + + /** + * Specifies the list of Output Cluster Ids (2 bytes each) + * + * @param appOutClusterList the AppOutClusterList to set as {@link int[]} + */ + public void setAppOutClusterList(int[] appOutClusterList) { + this.appOutClusterList = appOutClusterList; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_AF) && (response.getReqCmd1() == 0x00)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_AF, 0x00); + + // Serialize the fields + serializer.serializeUInt8(endPoint); + serializer.serializeUInt16(appProfId); + serializer.serializeUInt16(appDeviceId); + serializer.serializeUInt8(appDevVer); + serializer.serializeUInt8(latencyReq); + serializer.serializeUInt8(appInClusterList.length); + serializer.serializeUInt16Array(appInClusterList); + serializer.serializeUInt8(appOutClusterList.length); + serializer.serializeUInt16Array(appOutClusterList); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(248); + builder.append("ZstackAfRegisterSreq [endPoint="); + builder.append(String.format("%02X", endPoint)); + builder.append(", appProfId="); + builder.append(String.format("%04X", appProfId)); + builder.append(", appDeviceId="); + builder.append(appDeviceId); + builder.append(", appDevVer="); + builder.append(appDevVer); + builder.append(", latencyReq="); + builder.append(latencyReq); + builder.append(", appInClusterList="); + for (int c = 0; c < appInClusterList.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%04X", appInClusterList[c])); + } + builder.append(", appOutClusterList="); + for (int c = 0; c < appOutClusterList.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%04X", appOutClusterList[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/af/ZstackAfRegisterSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/af/ZstackAfRegisterSrsp.java new file mode 100644 index 0000000000..2073db3578 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/af/ZstackAfRegisterSrsp.java @@ -0,0 +1,71 @@ +/** + * 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.dongle.zstack.api.af; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command AF_REGISTER. + *

+ * This command enables the host processor to register an application’s endpoint description (and its simple descriptor). + * Multiple endpoints may be registered with the AF by making multiple calls to AF_REGISTER. This could be useful in the case where + * the device needs to support multiple application profiles, where each AF_REGISTER call would register a unique endpoint + * description per application profile. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackAfRegisterSrsp extends ZstackFrameResponse { + + /** + * Status is either Success (0) or Failure (1). + */ + private ZstackResponseCode status; + + /** + * Response and Handler constructor + */ + public ZstackAfRegisterSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + } + + /** + * Status is either Success (0) or Failure (1). + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * Status is either Success (0) or Failure (1). + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(48); + builder.append("ZstackAfRegisterSrsp [status="); + builder.append(status); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbAddInstallcodeSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbAddInstallcodeSreq.java new file mode 100644 index 0000000000..1e70d27aad --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbAddInstallcodeSreq.java @@ -0,0 +1,134 @@ +/** + * 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.dongle.zstack.api.appcnf; + +import com.zsmartsystems.zigbee.IeeeAddress; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; +import com.zsmartsystems.zigbee.security.ZigBeeKey; + +/** + * Class to implement the Z-Stack command APP_CNF_BDB_ADD_INSTALLCODE. + *

+ * Add a preconfigured key (plain key or IC) to Trust Center device. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackAppCnfBdbAddInstallcodeSreq extends ZstackFrameRequest { + + /** + * This value specifies the format in which the install code is being added. The following list contains the values corresponding + * to the supported formats: 0x01 Install Code + CRC 0x02 Key derived from Install Code + */ + private ZstackInstallCodeFormat installCodeFormat; + + /** + * Full IEEE address for the device joining the network + */ + private IeeeAddress ieeeAddress; + + /** + * 16 Bytes for the Key derived from the IC. 18 Bytes for the Install Code +CRC + */ + private ZigBeeKey installCode; + + /** + * Request constructor + */ + public ZstackAppCnfBdbAddInstallcodeSreq() { + synchronousCommand = true; + } + + /** + * This value specifies the format in which the install code is being added. The following list contains the values corresponding + * to the supported formats: 0x01 Install Code + CRC 0x02 Key derived from Install Code + * + * @return the current installCodeFormat as {@link ZstackInstallCodeFormat} + */ + public ZstackInstallCodeFormat getInstallCodeFormat() { + return installCodeFormat; + } + + /** + * This value specifies the format in which the install code is being added. The following list contains the values corresponding + * to the supported formats: 0x01 Install Code + CRC 0x02 Key derived from Install Code + * + * @param installCodeFormat the InstallCodeFormat to set as {@link ZstackInstallCodeFormat} + */ + public void setInstallCodeFormat(ZstackInstallCodeFormat installCodeFormat) { + this.installCodeFormat = installCodeFormat; + } + + /** + * Full IEEE address for the device joining the network + * + * @return the current ieeeAddress as {@link IeeeAddress} + */ + public IeeeAddress getIeeeAddress() { + return ieeeAddress; + } + + /** + * Full IEEE address for the device joining the network + * + * @param ieeeAddress the IeeeAddress to set as {@link IeeeAddress} + */ + public void setIeeeAddress(IeeeAddress ieeeAddress) { + this.ieeeAddress = ieeeAddress; + } + + /** + * 16 Bytes for the Key derived from the IC. 18 Bytes for the Install Code +CRC + * + * @return the current installCode as {@link ZigBeeKey} + */ + public ZigBeeKey getInstallCode() { + return installCode; + } + + /** + * 16 Bytes for the Key derived from the IC. 18 Bytes for the Install Code +CRC + * + * @param installCode the InstallCode to set as {@link ZigBeeKey} + */ + public void setInstallCode(ZigBeeKey installCode) { + this.installCode = installCode; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_APP_CNF) && (response.getReqCmd1() == 0x04)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_APP_CNF, 0x04); + + // Serialize the fields + serializer.serializeUInt8(installCodeFormat.getKey()); + serializer.serializeIeeeAddress(ieeeAddress); + serializer.serializeZigBeeKey(installCode); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(111); + builder.append("ZstackAppCnfBdbAddInstallcodeSreq [installCodeFormat="); + builder.append(installCodeFormat); + builder.append(", ieeeAddress="); + builder.append(ieeeAddress); + builder.append(", installCode="); + builder.append(installCode); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbAddInstallcodeSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbAddInstallcodeSrsp.java new file mode 100644 index 0000000000..4ba8025790 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbAddInstallcodeSrsp.java @@ -0,0 +1,68 @@ +/** + * 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.dongle.zstack.api.appcnf; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command APP_CNF_BDB_ADD_INSTALLCODE. + *

+ * Add a preconfigured key (plain key or IC) to Trust Center device. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackAppCnfBdbAddInstallcodeSrsp extends ZstackFrameResponse { + + /** + * Status values: 0x00 Success. 0x01 Failure (IC not supported) 0x02 Invalid parameter (bad CRC). + */ + private ZstackResponseCode status; + + /** + * Response and Handler constructor + */ + public ZstackAppCnfBdbAddInstallcodeSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + } + + /** + * Status values: 0x00 Success. 0x01 Failure (IC not supported) 0x02 Invalid parameter (bad CRC). + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * Status values: 0x00 Success. 0x01 Failure (IC not supported) 0x02 Invalid parameter (bad CRC). + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(61); + builder.append("ZstackAppCnfBdbAddInstallcodeSrsp [status="); + builder.append(status); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbCommissioningNotificationAreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbCommissioningNotificationAreq.java new file mode 100644 index 0000000000..c0a4c337c0 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbCommissioningNotificationAreq.java @@ -0,0 +1,136 @@ +/** + * 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.dongle.zstack.api.appcnf; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.appcnf.ZstackBdbRemainingCommissioningModes; +import java.util.HashSet; +import java.util.Set; + +/** + * Class to implement the Z-Stack command APP_CNF_BDB_COMMISSIONING_NOTIFICATION. + *

+ * Callback to receive notifications from BDB process. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackAppCnfBdbCommissioningNotificationAreq extends ZstackFrameResponse { + + /** + * Status of the commissioning mode being notified + */ + private ZstackBdbStatus status; + + /** + * Commissioning mode for which the notification is done and to which the status is related + */ + private ZstackBdbCommissioningMode commissioningMode; + + /** + * Bitmask of the remaining commissioning modes after this notification. + *

+ * Parameter allows multiple options so implemented as a {@link Set}. + */ + private Set remainingCommissioningModes = new HashSet<>(); + + /** + * Response and Handler constructor + */ + public ZstackAppCnfBdbCommissioningNotificationAreq(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + // Deserialize the fields + status = ZstackBdbStatus.valueOf(deserializer.deserializeUInt8()); + commissioningMode = ZstackBdbCommissioningMode.valueOf(deserializer.deserializeUInt8()); + int tmpRemainingCommissioningModes = deserializer.deserializeUInt8(); + for (ZstackBdbRemainingCommissioningModes value : ZstackBdbRemainingCommissioningModes.values()) { + if ((tmpRemainingCommissioningModes & value.getKey()) != 0) { + remainingCommissioningModes.add(value); + } + } + } + + /** + * Status of the commissioning mode being notified + * + * @return the current status as {@link ZstackBdbStatus} + */ + public ZstackBdbStatus getStatus() { + return status; + } + + /** + * Status of the commissioning mode being notified + * + * @param status the Status to set as {@link ZstackBdbStatus} + */ + public void setStatus(ZstackBdbStatus status) { + this.status = status; + } + + /** + * Commissioning mode for which the notification is done and to which the status is related + * + * @return the current commissioningMode as {@link ZstackBdbCommissioningMode} + */ + public ZstackBdbCommissioningMode getCommissioningMode() { + return commissioningMode; + } + + /** + * Commissioning mode for which the notification is done and to which the status is related + * + * @param commissioningMode the CommissioningMode to set as {@link ZstackBdbCommissioningMode} + */ + public void setCommissioningMode(ZstackBdbCommissioningMode commissioningMode) { + this.commissioningMode = commissioningMode; + } + + /** + * Bitmask of the remaining commissioning modes after this notification. + * + * @return the current remainingCommissioningModes as {@link Set} of {@link ZstackBdbRemainingCommissioningModes} + */ + public Set getRemainingCommissioningModes() { + return remainingCommissioningModes; + } + + /** + * Bitmask of the remaining commissioning modes after this notification. + * + * @param remainingCommissioningModes the RemainingCommissioningModes to add to the {@link Set} as {@link ZstackBdbRemainingCommissioningModes} + */ + public void addRemainingCommissioningModes(ZstackBdbRemainingCommissioningModes remainingCommissioningModes) { + this.remainingCommissioningModes.add(remainingCommissioningModes); + } + + /** + * Bitmask of the remaining commissioning modes after this notification. + * + * @param remainingCommissioningModes the RemainingCommissioningModes to remove to the {@link Set} as {@link ZstackBdbRemainingCommissioningModes} + */ + public void removeRemainingCommissioningModes(ZstackBdbRemainingCommissioningModes remainingCommissioningModes) { + this.remainingCommissioningModes.remove(remainingCommissioningModes); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(122); + builder.append("ZstackAppCnfBdbCommissioningNotificationAreq [status="); + builder.append(status); + builder.append(", commissioningMode="); + builder.append(commissioningMode); + builder.append(", remainingCommissioningModes="); + builder.append(remainingCommissioningModes); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbSetActiveDefaultCentralizedKeySreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbSetActiveDefaultCentralizedKeySreq.java new file mode 100644 index 0000000000..2da9a33f5f --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbSetActiveDefaultCentralizedKeySreq.java @@ -0,0 +1,108 @@ +/** + * 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.dongle.zstack.api.appcnf; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command APP_CNF_BDB_SET_ACTIVE_DEFAULT_CENTRALIZED_KEY. + *

+ * Sets the policy to mandate or not the usage of an Install Code upon joining. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackAppCnfBdbSetActiveDefaultCentralizedKeySreq extends ZstackFrameRequest { + + /** + * This parameter controls which key will be used when performing association to a centralized network. + */ + private ZstackCentralizedLinkKeyMode centralizedLinkKeyMode; + + /** + * Buffer with the key in any of its formats. + */ + private int[] installCode; + + /** + * Request constructor + */ + public ZstackAppCnfBdbSetActiveDefaultCentralizedKeySreq() { + synchronousCommand = true; + } + + /** + * This parameter controls which key will be used when performing association to a centralized network. + * + * @return the current centralizedLinkKeyMode as {@link ZstackCentralizedLinkKeyMode} + */ + public ZstackCentralizedLinkKeyMode getCentralizedLinkKeyMode() { + return centralizedLinkKeyMode; + } + + /** + * This parameter controls which key will be used when performing association to a centralized network. + * + * @param centralizedLinkKeyMode the CentralizedLinkKeyMode to set as {@link ZstackCentralizedLinkKeyMode} + */ + public void setCentralizedLinkKeyMode(ZstackCentralizedLinkKeyMode centralizedLinkKeyMode) { + this.centralizedLinkKeyMode = centralizedLinkKeyMode; + } + + /** + * Buffer with the key in any of its formats. + * + * @return the current installCode as {@link int[]} + */ + public int[] getInstallCode() { + return installCode; + } + + /** + * Buffer with the key in any of its formats. + * + * @param installCode the InstallCode to set as {@link int[]} + */ + public void setInstallCode(int[] installCode) { + this.installCode = installCode; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_APP_CNF) && (response.getReqCmd1() == 0x07)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_APP_CNF, 0x07); + + // Serialize the fields + serializer.serializeUInt8(centralizedLinkKeyMode.getKey()); + serializer.serializeUInt8Array(installCode); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(102); + builder.append("ZstackAppCnfBdbSetActiveDefaultCentralizedKeySreq [centralizedLinkKeyMode="); + builder.append(centralizedLinkKeyMode); + builder.append(", installCode="); + for (int c = 0; c < installCode.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", installCode[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbSetActiveDefaultCentralizedKeySrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbSetActiveDefaultCentralizedKeySrsp.java new file mode 100644 index 0000000000..9200b66c75 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbSetActiveDefaultCentralizedKeySrsp.java @@ -0,0 +1,68 @@ +/** + * 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.dongle.zstack.api.appcnf; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command APP_CNF_BDB_SET_ACTIVE_DEFAULT_CENTRALIZED_KEY. + *

+ * Sets the policy to mandate or not the usage of an Install Code upon joining. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackAppCnfBdbSetActiveDefaultCentralizedKeySrsp extends ZstackFrameResponse { + + /** + * 0x00 Success 0x01 Failure (IC not supported) 0x02 Invalid Parameters (bad CRC). + */ + private ZstackResponseCode status; + + /** + * Response and Handler constructor + */ + public ZstackAppCnfBdbSetActiveDefaultCentralizedKeySrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + } + + /** + * 0x00 Success 0x01 Failure (IC not supported) 0x02 Invalid Parameters (bad CRC). + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * 0x00 Success 0x01 Failure (IC not supported) 0x02 Invalid Parameters (bad CRC). + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(77); + builder.append("ZstackAppCnfBdbSetActiveDefaultCentralizedKeySrsp [status="); + builder.append(status); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbSetJoinusesinstallcodekeySreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbSetJoinusesinstallcodekeySreq.java new file mode 100644 index 0000000000..4e871c2ebc --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbSetJoinusesinstallcodekeySreq.java @@ -0,0 +1,101 @@ +/** + * 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.dongle.zstack.api.appcnf; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command APP_CNF_BDB_SET_JOINUSESINSTALLCODEKEY. + *

+ * Sets the policy to mandate or not the usage of an Install Code upon joining. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackAppCnfBdbSetJoinusesinstallcodekeySreq extends ZstackFrameRequest { + + /** + * If it is equal to TRUE and the installation code derived link key is not stored, the Trust Center SHALL terminate the procedure for + * adding a new node into the network. If bdbJoinUsesInstall- CodeKey is equal to TRUE and the installation code derived link key is + * stored, the Trust Center SHALL first find the entry in apsDeviceKeyPairSet that corresponds to the joining node and then + * overwrite the LinkKey entry with the installation code derived link key and set the KeyAttributes field to PROVISIONAL_KEY. + * The Trust Center MAY then set OutgoingFrame- Counter to 0 and SHALL set IncomingFrameCounter to 0. If + * bdbJoinUsesInstallCodeKey is equal to FALSE, the Trust Center SHALL first find the entry in apsDeviceKeyPairSet that + * corresponds to the joining node and then overwrite the LinkKey entry with the default global Trust Center link key and set the + * KeyAttributes field to PROVISIONAL_KEY. The Trust Center MAY then set OutgoingFrameCounter to 0 and SHALL set + * IncomingFrameCounter to 0. + */ + private boolean joinUsesInstallCodeKey; + + /** + * Request constructor + */ + public ZstackAppCnfBdbSetJoinusesinstallcodekeySreq() { + synchronousCommand = true; + } + + /** + * If it is equal to TRUE and the installation code derived link key is not stored, the Trust Center SHALL terminate the procedure for + * adding a new node into the network. If bdbJoinUsesInstall- CodeKey is equal to TRUE and the installation code derived link key is + * stored, the Trust Center SHALL first find the entry in apsDeviceKeyPairSet that corresponds to the joining node and then + * overwrite the LinkKey entry with the installation code derived link key and set the KeyAttributes field to PROVISIONAL_KEY. + * The Trust Center MAY then set OutgoingFrame- Counter to 0 and SHALL set IncomingFrameCounter to 0. If + * bdbJoinUsesInstallCodeKey is equal to FALSE, the Trust Center SHALL first find the entry in apsDeviceKeyPairSet that + * corresponds to the joining node and then overwrite the LinkKey entry with the default global Trust Center link key and set the + * KeyAttributes field to PROVISIONAL_KEY. The Trust Center MAY then set OutgoingFrameCounter to 0 and SHALL set + * IncomingFrameCounter to 0. + * + * @return the current joinUsesInstallCodeKey as {@link boolean} + */ + public boolean getJoinUsesInstallCodeKey() { + return joinUsesInstallCodeKey; + } + + /** + * If it is equal to TRUE and the installation code derived link key is not stored, the Trust Center SHALL terminate the procedure for + * adding a new node into the network. If bdbJoinUsesInstall- CodeKey is equal to TRUE and the installation code derived link key is + * stored, the Trust Center SHALL first find the entry in apsDeviceKeyPairSet that corresponds to the joining node and then + * overwrite the LinkKey entry with the installation code derived link key and set the KeyAttributes field to PROVISIONAL_KEY. + * The Trust Center MAY then set OutgoingFrame- Counter to 0 and SHALL set IncomingFrameCounter to 0. If + * bdbJoinUsesInstallCodeKey is equal to FALSE, the Trust Center SHALL first find the entry in apsDeviceKeyPairSet that + * corresponds to the joining node and then overwrite the LinkKey entry with the default global Trust Center link key and set the + * KeyAttributes field to PROVISIONAL_KEY. The Trust Center MAY then set OutgoingFrameCounter to 0 and SHALL set + * IncomingFrameCounter to 0. + * + * @param joinUsesInstallCodeKey the JoinUsesInstallCodeKey to set as {@link boolean} + */ + public void setJoinUsesInstallCodeKey(boolean joinUsesInstallCodeKey) { + this.joinUsesInstallCodeKey = joinUsesInstallCodeKey; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_APP_CNF) && (response.getReqCmd1() == 0x06)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_APP_CNF, 0x06); + + // Serialize the fields + serializer.serializeBoolean(joinUsesInstallCodeKey); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(72); + builder.append("ZstackAppCnfBdbSetJoinusesinstallcodekeySreq [joinUsesInstallCodeKey="); + builder.append(joinUsesInstallCodeKey); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbSetJoinusesinstallcodekeySrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbSetJoinusesinstallcodekeySrsp.java new file mode 100644 index 0000000000..8547b421b6 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbSetJoinusesinstallcodekeySrsp.java @@ -0,0 +1,68 @@ +/** + * 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.dongle.zstack.api.appcnf; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command APP_CNF_BDB_SET_JOINUSESINSTALLCODEKEY. + *

+ * Sets the policy to mandate or not the usage of an Install Code upon joining. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackAppCnfBdbSetJoinusesinstallcodekeySrsp extends ZstackFrameResponse { + + /** + * Status is either Success (0) or Failure (1). + */ + private ZstackResponseCode status; + + /** + * Response and Handler constructor + */ + public ZstackAppCnfBdbSetJoinusesinstallcodekeySrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + } + + /** + * Status is either Success (0) or Failure (1). + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * Status is either Success (0) or Failure (1). + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(72); + builder.append("ZstackAppCnfBdbSetJoinusesinstallcodekeySrsp [status="); + builder.append(status); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbSetTcRequireKeyExchangeSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbSetTcRequireKeyExchangeSreq.java new file mode 100644 index 0000000000..0afe323c69 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbSetTcRequireKeyExchangeSreq.java @@ -0,0 +1,89 @@ +/** + * 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.dongle.zstack.api.appcnf; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command APP_CNF_BDB_SET_TC_REQUIRE_KEY_EXCHANGE. + *

+ * Sets the policy flag on Trust Center device to mandate or not the TCLK exchange procedure. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackAppCnfBdbSetTcRequireKeyExchangeSreq extends ZstackFrameRequest { + + /** + * The bdbTrustCenterRequireKeyExchange attribute specifies whether the Trust Center requires a joining device to exchange + * its initial link key with a new link key generated by the Trust Center. If bdbTrustCenterRequireKeyExchange is equal to TRUE, + * the joining node must undergo the link key exchange procedure; failure to exchange the link key will result in the node being + * removed from the network. If bdbTrustCenterRequireKeyExchange is equal to FALSE, the Trust Center will permit the joining + * node to remain on the network without exchanging its initial link key. This attribute is used by ZigBee coordinator nodes. + */ + private boolean trustCenterRequireKeyExchange; + + /** + * Request constructor + */ + public ZstackAppCnfBdbSetTcRequireKeyExchangeSreq() { + synchronousCommand = true; + } + + /** + * The bdbTrustCenterRequireKeyExchange attribute specifies whether the Trust Center requires a joining device to exchange + * its initial link key with a new link key generated by the Trust Center. If bdbTrustCenterRequireKeyExchange is equal to TRUE, + * the joining node must undergo the link key exchange procedure; failure to exchange the link key will result in the node being + * removed from the network. If bdbTrustCenterRequireKeyExchange is equal to FALSE, the Trust Center will permit the joining + * node to remain on the network without exchanging its initial link key. This attribute is used by ZigBee coordinator nodes. + * + * @return the current trustCenterRequireKeyExchange as {@link boolean} + */ + public boolean getTrustCenterRequireKeyExchange() { + return trustCenterRequireKeyExchange; + } + + /** + * The bdbTrustCenterRequireKeyExchange attribute specifies whether the Trust Center requires a joining device to exchange + * its initial link key with a new link key generated by the Trust Center. If bdbTrustCenterRequireKeyExchange is equal to TRUE, + * the joining node must undergo the link key exchange procedure; failure to exchange the link key will result in the node being + * removed from the network. If bdbTrustCenterRequireKeyExchange is equal to FALSE, the Trust Center will permit the joining + * node to remain on the network without exchanging its initial link key. This attribute is used by ZigBee coordinator nodes. + * + * @param trustCenterRequireKeyExchange the TrustCenterRequireKeyExchange to set as {@link boolean} + */ + public void setTrustCenterRequireKeyExchange(boolean trustCenterRequireKeyExchange) { + this.trustCenterRequireKeyExchange = trustCenterRequireKeyExchange; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_APP_CNF) && (response.getReqCmd1() == 0x09)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_APP_CNF, 0x09); + + // Serialize the fields + serializer.serializeBoolean(trustCenterRequireKeyExchange); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(70); + builder.append("ZstackAppCnfBdbSetTcRequireKeyExchangeSreq [trustCenterRequireKeyExchange="); + builder.append(trustCenterRequireKeyExchange); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbSetTcRequireKeyExchangeSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbSetTcRequireKeyExchangeSrsp.java new file mode 100644 index 0000000000..56c1eea507 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfBdbSetTcRequireKeyExchangeSrsp.java @@ -0,0 +1,68 @@ +/** + * 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.dongle.zstack.api.appcnf; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command APP_CNF_BDB_SET_TC_REQUIRE_KEY_EXCHANGE. + *

+ * Sets the policy flag on Trust Center device to mandate or not the TCLK exchange procedure. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackAppCnfBdbSetTcRequireKeyExchangeSrsp extends ZstackFrameResponse { + + /** + * Status is either Success (0) or Failure (1). + */ + private ZstackResponseCode status; + + /** + * Response and Handler constructor + */ + public ZstackAppCnfBdbSetTcRequireKeyExchangeSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + } + + /** + * Status is either Success (0) or Failure (1). + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * Status is either Success (0) or Failure (1). + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(70); + builder.append("ZstackAppCnfBdbSetTcRequireKeyExchangeSrsp [status="); + builder.append(status); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfSetAllowrejoinTcPolicySreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfSetAllowrejoinTcPolicySreq.java new file mode 100644 index 0000000000..6206c9c111 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfSetAllowrejoinTcPolicySreq.java @@ -0,0 +1,77 @@ +/** + * 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.dongle.zstack.api.appcnf; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command APP_CNF_SET_ALLOWREJOIN_TC_POLICY. + *

+ * Sets the AllowRejoin TC policy. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackAppCnfSetAllowrejoinTcPolicySreq extends ZstackFrameRequest { + + /** + * This value specifies whether or not the Trust Center allows devices to rejoin. + */ + private boolean allowRejoin; + + /** + * Request constructor + */ + public ZstackAppCnfSetAllowrejoinTcPolicySreq() { + synchronousCommand = true; + } + + /** + * This value specifies whether or not the Trust Center allows devices to rejoin. + * + * @return the current allowRejoin as {@link boolean} + */ + public boolean getAllowRejoin() { + return allowRejoin; + } + + /** + * This value specifies whether or not the Trust Center allows devices to rejoin. + * + * @param allowRejoin the AllowRejoin to set as {@link boolean} + */ + public void setAllowRejoin(boolean allowRejoin) { + this.allowRejoin = allowRejoin; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_APP_CNF) && (response.getReqCmd1() == 0x03)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_APP_CNF, 0x03); + + // Serialize the fields + serializer.serializeBoolean(allowRejoin); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(66); + builder.append("ZstackAppCnfSetAllowrejoinTcPolicySreq [allowRejoin="); + builder.append(allowRejoin); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfSetAllowrejoinTcPolicySrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfSetAllowrejoinTcPolicySrsp.java new file mode 100644 index 0000000000..95d9a19585 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAppCnfSetAllowrejoinTcPolicySrsp.java @@ -0,0 +1,68 @@ +/** + * 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.dongle.zstack.api.appcnf; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command APP_CNF_SET_ALLOWREJOIN_TC_POLICY. + *

+ * Sets the AllowRejoin TC policy. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackAppCnfSetAllowrejoinTcPolicySrsp extends ZstackFrameResponse { + + /** + * Status is either Success (0) or Failure (1). + */ + private ZstackResponseCode status; + + /** + * Response and Handler constructor + */ + public ZstackAppCnfSetAllowrejoinTcPolicySrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + } + + /** + * Status is either Success (0) or Failure (1). + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * Status is either Success (0) or Failure (1). + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(66); + builder.append("ZstackAppCnfSetAllowrejoinTcPolicySrsp [status="); + builder.append(status); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAuthenticationOption.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAuthenticationOption.java new file mode 100644 index 0000000000..423ed85050 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackAuthenticationOption.java @@ -0,0 +1,75 @@ +/** + * 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.dongle.zstack.api.appcnf; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the Z-Stack Enumeration ZstackAuthenticationOption. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public enum ZstackAuthenticationOption { + + /** + * The device has not been authenticated + */ + NOT_AUTHENTICATED(0x0000), + + /** + * The device has been authenticated using CBKE + */ + AUTHENTICATED_CBCK(0x0001), + + /** + * The device has been authenticated using EA + */ + AUTHENTICATED_EA(0x0002); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + static { + codeMapping = new HashMap(); + for (ZstackAuthenticationOption s : values()) { + codeMapping.put(s.key, s); + } + } + + private ZstackAuthenticationOption(int key) { + this.key = key; + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param code the code to lookup + * @return enumeration value of the alarm type. + */ + public static ZstackAuthenticationOption valueOf(int code) { + + return codeMapping.get(code); + } + + /** + * Returns the Z-Stack protocol defined value for this enumeration. + * + * @return the Z-Stack protocol key + */ + public int getKey() { + return key; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackBdbCommissioningMode.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackBdbCommissioningMode.java new file mode 100644 index 0000000000..8f919300e4 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackBdbCommissioningMode.java @@ -0,0 +1,90 @@ +/** + * 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.dongle.zstack.api.appcnf; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the Z-Stack Enumeration ZstackBdbCommissioningMode. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public enum ZstackBdbCommissioningMode { + + /** + * + */ + BDB_COMMISSIONING_INITIALIZATION(0x0000), + + /** + * + */ + BDB_COMMISSIONING_NWK_STEERING(0x0001), + + /** + * + */ + BDB_COMMISSIONING_FORMATION(0x0002), + + /** + * + */ + BDB_COMMISSIONING_FINDING_BINDING(0x0003), + + /** + * + */ + BDB_COMMISSIONING_TOUCHLINK(0x0004), + + /** + * + */ + BDB_COMMISSIONING_PARENT_LOST(0x0005); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + static { + codeMapping = new HashMap(); + for (ZstackBdbCommissioningMode s : values()) { + codeMapping.put(s.key, s); + } + } + + private ZstackBdbCommissioningMode(int key) { + this.key = key; + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param code the code to lookup + * @return enumeration value of the alarm type. + */ + public static ZstackBdbCommissioningMode valueOf(int code) { + + return codeMapping.get(code); + } + + /** + * Returns the Z-Stack protocol defined value for this enumeration. + * + * @return the Z-Stack protocol key + */ + public int getKey() { + return key; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackBdbRemainingCommissioningModes.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackBdbRemainingCommissioningModes.java new file mode 100644 index 0000000000..7c062f9a9f --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackBdbRemainingCommissioningModes.java @@ -0,0 +1,90 @@ +/** + * 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.dongle.zstack.api.appcnf; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the Z-Stack Enumeration ZstackBdbRemainingCommissioningModes. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public enum ZstackBdbRemainingCommissioningModes { + + /** + * + */ + BDB_COMMISSIONING_MODE_INITIATOR_TL(0x0001), + + /** + * + */ + BDB_COMMISSIONING_MODE_NWK_STEERING(0x0002), + + /** + * + */ + BDB_COMMISSIONING_MODE_NWK_FORMATION(0x0004), + + /** + * + */ + BDB_COMMISSIONING_MODE_FINDING_BINDING(0x0008), + + /** + * + */ + BDB_COMMISSIONING_MODE_INITIALIZATION(0x0010), + + /** + * + */ + BDB_COMMISSIONING_MODE_PARENT_LOST(0x0020); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + static { + codeMapping = new HashMap(); + for (ZstackBdbRemainingCommissioningModes s : values()) { + codeMapping.put(s.key, s); + } + } + + private ZstackBdbRemainingCommissioningModes(int key) { + this.key = key; + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param code the code to lookup + * @return enumeration value of the alarm type. + */ + public static ZstackBdbRemainingCommissioningModes valueOf(int code) { + + return codeMapping.get(code); + } + + /** + * Returns the Z-Stack protocol defined value for this enumeration. + * + * @return the Z-Stack protocol key + */ + public int getKey() { + return key; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackBdbStatus.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackBdbStatus.java new file mode 100644 index 0000000000..00f05c1047 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackBdbStatus.java @@ -0,0 +1,135 @@ +/** + * 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.dongle.zstack.api.appcnf; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the Z-Stack Enumeration ZstackBdbStatus. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public enum ZstackBdbStatus { + + /** + * + */ + BDB_COMMISSIONING_SUCCESS(0x0000), + + /** + * + */ + BDB_COMMISSIONING_IN_PROGRESS(0x0001), + + /** + * + */ + BDB_COMMISSIONING_NO_NETWORK(0x0002), + + /** + * + */ + BDB_COMMISSIONING_TL_TARGET_FAILURE(0x0003), + + /** + * + */ + BDB_COMMISSIONING_TL_NOT_AA_CAPABLE(0x0004), + + /** + * + */ + BDB_COMMISSIONING_TL_NO_SCAN_RESPONSE(0x0005), + + /** + * + */ + BDB_COMMISSIONING_TL_NOT_PERMITTED(0x0006), + + /** + * + */ + BDB_COMMISSIONING_TCLK_EX_FAILURE(0x0007), + + /** + * + */ + BDB_COMMISSIONING_FORMATION_FAILURE(0x0008), + + /** + * + */ + BDB_COMMISSIONING_FB_TARGET_IN_PROGRESS(0x0009), + + /** + * + */ + BDB_COMMISSIONING_FB_INITIATOR_IN_PROGRESS(0x000A), + + /** + * + */ + BDB_COMMISSIONING_FB_NO_IDENTIFY_QUERY_RESPONSE(0x000B), + + /** + * + */ + BDB_COMMISSIONING_FB_BINDING_TABLE_FULL(0x000C), + + /** + * + */ + BDB_COMMISSIONING_NETWORK_RESTORED(0x000D), + + /** + * + */ + BDB_COMMISSIONING_FAILURE(0x000E); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + static { + codeMapping = new HashMap(); + for (ZstackBdbStatus s : values()) { + codeMapping.put(s.key, s); + } + } + + private ZstackBdbStatus(int key) { + this.key = key; + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param code the code to lookup + * @return enumeration value of the alarm type. + */ + public static ZstackBdbStatus valueOf(int code) { + + return codeMapping.get(code); + } + + /** + * Returns the Z-Stack protocol defined value for this enumeration. + * + * @return the Z-Stack protocol key + */ + public int getKey() { + return key; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackCentralizedLinkKeyMode.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackCentralizedLinkKeyMode.java new file mode 100644 index 0000000000..bff6527453 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackCentralizedLinkKeyMode.java @@ -0,0 +1,96 @@ +/** + * 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.dongle.zstack.api.appcnf; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the Z-Stack Enumeration ZstackCentralizedLinkKeyMode. + *

+ * Central link key policies + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public enum ZstackCentralizedLinkKeyMode { + /** + * Default unknown value + */ + UNKNOWN(-1), + + /** + * Instruct joining node to use Default Global Trust Center link key. No key buffer required + */ + DEFAULT_GLOBAL_KEY(0x0000), + + /** + * Instruct the joining node to use the provided install code (16 bytes + 2 CRC bytes) to derive APS Link key to be used during joining + */ + PROVIDED_INSTALL_CODE(0x0001), + + /** + * Instruct the joining node to use the provided install code (16 bytes + 2 CRC bytes) to derive APS Link key to be used during joining. + * If it fails to decrypt Transport Key, it will automatically try Default Global Trust Center Link Key + */ + PROVIDED_INSTALL_CODE_THEN_DEFAULT_GLOBAL_KEY(0x0002), + + /** + * Instruct the joining node to use the provided APS Link key to be used during joining (key size is 16 bytes) + */ + PROVIDED_APS_KEY(0x0003), + + /** + * Instruct the joining node to use the provided APS Link key to be used during joining (key size is 16 bytes). If it fails to decrypt + * Transport Key, it will automatically try Default Global Trust Center Link Key + */ + PROVIDED_APS_CODE_THEN_DEFAULT_GLOBAL_KEY(0x0004); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + static { + codeMapping = new HashMap(); + for (ZstackCentralizedLinkKeyMode s : values()) { + codeMapping.put(s.key, s); + } + } + + private ZstackCentralizedLinkKeyMode(int key) { + this.key = key; + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param code the code to lookup + * @return enumeration value of the alarm type. + */ + public static ZstackCentralizedLinkKeyMode valueOf(int code) { + if (codeMapping.get(code) == null) { + return UNKNOWN; + } + + return codeMapping.get(code); + } + + /** + * Returns the Z-Stack protocol defined value for this enumeration. + * + * @return the Z-Stack protocol key + */ + public int getKey() { + return key; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackInstallCodeFormat.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackInstallCodeFormat.java new file mode 100644 index 0000000000..bf8a343962 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/appcnf/ZstackInstallCodeFormat.java @@ -0,0 +1,70 @@ +/** + * 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.dongle.zstack.api.appcnf; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the Z-Stack Enumeration ZstackInstallCodeFormat. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public enum ZstackInstallCodeFormat { + + /** + * + */ + INSTALL_CODE(0x0001), + + /** + * + */ + DERIVED_KEY(0x0002); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + static { + codeMapping = new HashMap(); + for (ZstackInstallCodeFormat s : values()) { + codeMapping.put(s.key, s); + } + } + + private ZstackInstallCodeFormat(int key) { + this.key = key; + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param code the code to lookup + * @return enumeration value of the alarm type. + */ + public static ZstackInstallCodeFormat valueOf(int code) { + + return codeMapping.get(code); + } + + /** + * Returns the Z-Stack protocol defined value for this enumeration. + * + * @return the Z-Stack protocol key + */ + public int getKey() { + return key; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/mac/ZstackMacScanReqSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/mac/ZstackMacScanReqSreq.java new file mode 100644 index 0000000000..586620e1df --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/mac/ZstackMacScanReqSreq.java @@ -0,0 +1,271 @@ +/** + * 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.dongle.zstack.api.mac; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command MAC_SCAN_REQ. + *

+ * This command is used to send a request to the device to perform a network scan. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackMacScanReqSreq extends ZstackFrameRequest { + + /** + * This represents a bit-mask of channels to be scanned when starting the device: NONE = 0x00000000, ALL_CHANNELS = 0x07FFF800, + * CHANNEL 11 = 0x00000800, CHANNEL 12 = 0x00001000, CHANNEL 13 = 0x00002000, CHANNEL 14 = 0x00004000, CHANNEL 15 = 0x00008000, + * CHANNEL 16 = 0x00010000, CHANNEL 17 = 0x00020000, CHANNEL 18 = 0x00040000, CHANNEL_19 = 0x00080000, CHANNEL 20 = 0x00100000, + * CHANNEL 21 = 0x00200000, CHANNEL 22 = 0x00400000, CHANNEL 23 = 0x00800000, CHANNEL 24 = 0x01000000 CHANNEL 25 = 0x02000000, + * CHANNEL 26 = 0x04000000 + */ + private int scanChannels; + + /** + * Specifies the scan type: + */ + private int scanType; + + /** + * Duration of the scan - The exponent used in the scan duration calculation. + */ + private int scanDuration; + + /** + * The channel page on which to perform the scan. + */ + private int channelPage; + + /** + * Key Source of this data frame. + */ + private int keySource; + + /** + * Security Level of this data frame: + */ + private int securityLevel; + + /** + * Key Id Mode of this data frame: + */ + private int keyIdMode; + + /** + * Key Index of this data frame. + */ + private int keyIndex; + + /** + * Request constructor + */ + public ZstackMacScanReqSreq() { + synchronousCommand = true; + } + + /** + * This represents a bit-mask of channels to be scanned when starting the device: NONE = 0x00000000, ALL_CHANNELS = 0x07FFF800, + * CHANNEL 11 = 0x00000800, CHANNEL 12 = 0x00001000, CHANNEL 13 = 0x00002000, CHANNEL 14 = 0x00004000, CHANNEL 15 = 0x00008000, + * CHANNEL 16 = 0x00010000, CHANNEL 17 = 0x00020000, CHANNEL 18 = 0x00040000, CHANNEL_19 = 0x00080000, CHANNEL 20 = 0x00100000, + * CHANNEL 21 = 0x00200000, CHANNEL 22 = 0x00400000, CHANNEL 23 = 0x00800000, CHANNEL 24 = 0x01000000 CHANNEL 25 = 0x02000000, + * CHANNEL 26 = 0x04000000 + * + * @return the current scanChannels as {@link int} + */ + public int getScanChannels() { + return scanChannels; + } + + /** + * This represents a bit-mask of channels to be scanned when starting the device: NONE = 0x00000000, ALL_CHANNELS = 0x07FFF800, + * CHANNEL 11 = 0x00000800, CHANNEL 12 = 0x00001000, CHANNEL 13 = 0x00002000, CHANNEL 14 = 0x00004000, CHANNEL 15 = 0x00008000, + * CHANNEL 16 = 0x00010000, CHANNEL 17 = 0x00020000, CHANNEL 18 = 0x00040000, CHANNEL_19 = 0x00080000, CHANNEL 20 = 0x00100000, + * CHANNEL 21 = 0x00200000, CHANNEL 22 = 0x00400000, CHANNEL 23 = 0x00800000, CHANNEL 24 = 0x01000000 CHANNEL 25 = 0x02000000, + * CHANNEL 26 = 0x04000000 + * + * @param scanChannels the ScanChannels to set as {@link int} + */ + public void setScanChannels(int scanChannels) { + this.scanChannels = scanChannels; + } + + /** + * Specifies the scan type: + * + * @return the current scanType as {@link int} + */ + public int getScanType() { + return scanType; + } + + /** + * Specifies the scan type: + * + * @param scanType the ScanType to set as {@link int} + */ + public void setScanType(int scanType) { + this.scanType = scanType; + } + + /** + * Duration of the scan - The exponent used in the scan duration calculation. + * + * @return the current scanDuration as {@link int} + */ + public int getScanDuration() { + return scanDuration; + } + + /** + * Duration of the scan - The exponent used in the scan duration calculation. + * + * @param scanDuration the ScanDuration to set as {@link int} + */ + public void setScanDuration(int scanDuration) { + this.scanDuration = scanDuration; + } + + /** + * The channel page on which to perform the scan. + * + * @return the current channelPage as {@link int} + */ + public int getChannelPage() { + return channelPage; + } + + /** + * The channel page on which to perform the scan. + * + * @param channelPage the ChannelPage to set as {@link int} + */ + public void setChannelPage(int channelPage) { + this.channelPage = channelPage; + } + + /** + * Key Source of this data frame. + * + * @return the current keySource as {@link int} + */ + public int getKeySource() { + return keySource; + } + + /** + * Key Source of this data frame. + * + * @param keySource the KeySource to set as {@link int} + */ + public void setKeySource(int keySource) { + this.keySource = keySource; + } + + /** + * Security Level of this data frame: + * + * @return the current securityLevel as {@link int} + */ + public int getSecurityLevel() { + return securityLevel; + } + + /** + * Security Level of this data frame: + * + * @param securityLevel the SecurityLevel to set as {@link int} + */ + public void setSecurityLevel(int securityLevel) { + this.securityLevel = securityLevel; + } + + /** + * Key Id Mode of this data frame: + * + * @return the current keyIdMode as {@link int} + */ + public int getKeyIdMode() { + return keyIdMode; + } + + /** + * Key Id Mode of this data frame: + * + * @param keyIdMode the KeyIdMode to set as {@link int} + */ + public void setKeyIdMode(int keyIdMode) { + this.keyIdMode = keyIdMode; + } + + /** + * Key Index of this data frame. + * + * @return the current keyIndex as {@link int} + */ + public int getKeyIndex() { + return keyIndex; + } + + /** + * Key Index of this data frame. + * + * @param keyIndex the KeyIndex to set as {@link int} + */ + public void setKeyIndex(int keyIndex) { + this.keyIndex = keyIndex; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_MAC) && (response.getReqCmd1() == 0x0C)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_MAC, 0x0C); + + // Serialize the fields + serializer.serializeUInt32(scanChannels); + serializer.serializeUInt8(scanType); + serializer.serializeUInt8(scanDuration); + serializer.serializeUInt8(channelPage); + serializer.serializeUInt8(keySource); + serializer.serializeUInt8(securityLevel); + serializer.serializeUInt8(keyIdMode); + serializer.serializeUInt8(keyIndex); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(223); + builder.append("ZstackMacScanReqSreq [scanChannels="); + builder.append(scanChannels); + builder.append(", scanType="); + builder.append(scanType); + builder.append(", scanDuration="); + builder.append(scanDuration); + builder.append(", channelPage="); + builder.append(channelPage); + builder.append(", keySource="); + builder.append(keySource); + builder.append(", securityLevel="); + builder.append(securityLevel); + builder.append(", keyIdMode="); + builder.append(keyIdMode); + builder.append(", keyIndex="); + builder.append(keyIndex); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/mac/ZstackMacScanReqSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/mac/ZstackMacScanReqSrsp.java new file mode 100644 index 0000000000..ed1b6a51b9 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/mac/ZstackMacScanReqSrsp.java @@ -0,0 +1,39 @@ +/** + * 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.dongle.zstack.api.mac; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; + +/** + * Class to implement the Z-Stack command MAC_SCAN_REQ. + *

+ * This command is used to send a request to the device to perform a network scan. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackMacScanReqSrsp extends ZstackFrameResponse { + + /** + * Response and Handler constructor + */ + public ZstackMacScanReqSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + } + + @Override + public String toString() { + return "ZstackMacScanReqSrsp []"; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/rpc/ZstackRpcSreqErrorSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/rpc/ZstackRpcSreqErrorSrsp.java new file mode 100644 index 0000000000..2965de8dd1 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/rpc/ZstackRpcSreqErrorSrsp.java @@ -0,0 +1,119 @@ +/** + * 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.dongle.zstack.api.rpc; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; + +/** + * Class to implement the Z-Stack command RPC_SREQ_ERROR. + *

+ * When the ZNP cannot recognize an SREQ command from the host processor, the following SRSP is returned. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackRpcSreqErrorSrsp extends ZstackFrameResponse { + + /** + * The error code maps to one of the enumerated values. + */ + private ZstackSreqErrorCode errorCode; + + /** + * The Cmd0 value of the processed SREQ + */ + private int reqCmd0; + + /** + * The Cmd1 value of the processed SREQ + */ + private int reqCmd1; + + /** + * Response and Handler constructor + */ + public ZstackRpcSreqErrorSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + errorCode = ZstackSreqErrorCode.valueOf(deserializer.deserializeUInt8()); + reqCmd0 = deserializer.deserializeUInt8(); + reqCmd1 = deserializer.deserializeUInt8(); + } + + /** + * The error code maps to one of the enumerated values. + * + * @return the current errorCode as {@link ZstackSreqErrorCode} + */ + public ZstackSreqErrorCode getErrorCode() { + return errorCode; + } + + /** + * The error code maps to one of the enumerated values. + * + * @param errorCode the ErrorCode to set as {@link ZstackSreqErrorCode} + */ + public void setErrorCode(ZstackSreqErrorCode errorCode) { + this.errorCode = errorCode; + } + + /** + * The Cmd0 value of the processed SREQ + * + * @return the current reqCmd0 as {@link int} + */ + public int getReqCmd0() { + return reqCmd0; + } + + /** + * The Cmd0 value of the processed SREQ + * + * @param reqCmd0 the ReqCmd0 to set as {@link int} + */ + public void setReqCmd0(int reqCmd0) { + this.reqCmd0 = reqCmd0; + } + + /** + * The Cmd1 value of the processed SREQ + * + * @return the current reqCmd1 as {@link int} + */ + public int getReqCmd1() { + return reqCmd1; + } + + /** + * The Cmd1 value of the processed SREQ + * + * @param reqCmd1 the ReqCmd1 to set as {@link int} + */ + public void setReqCmd1(int reqCmd1) { + this.reqCmd1 = reqCmd1; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(100); + builder.append("ZstackRpcSreqErrorSrsp [errorCode="); + builder.append(errorCode); + builder.append(", reqCmd0="); + builder.append(String.format("%02X", reqCmd0)); + builder.append(", reqCmd1="); + builder.append(String.format("%02X", reqCmd1)); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/rpc/ZstackSreqErrorCode.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/rpc/ZstackSreqErrorCode.java new file mode 100644 index 0000000000..1913654f82 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/rpc/ZstackSreqErrorCode.java @@ -0,0 +1,89 @@ +/** + * 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.dongle.zstack.api.rpc; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the Z-Stack Enumeration ZstackSreqErrorCode. + *

+ * SREQ RPC Error code + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public enum ZstackSreqErrorCode { + /** + * Default unknown value + */ + UNKNOWN(-1), + + /** + * + */ + INVALID_SUBSYSTEM(0x0001), + + /** + * + */ + INVALID_COMMAND_ID(0x0002), + + /** + * + */ + INVALID_PARAMETER(0x0003), + + /** + * + */ + INVALID_LENGTH(0x0003); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + static { + codeMapping = new HashMap(); + for (ZstackSreqErrorCode s : values()) { + codeMapping.put(s.key, s); + } + } + + private ZstackSreqErrorCode(int key) { + this.key = key; + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param code the code to lookup + * @return enumeration value of the alarm type. + */ + public static ZstackSreqErrorCode valueOf(int code) { + if (codeMapping.get(code) == null) { + return UNKNOWN; + } + + return codeMapping.get(code); + } + + /** + * Returns the Z-Stack protocol defined value for this enumeration. + * + * @return the Z-Stack protocol key + */ + public int getKey() { + return key; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sapi/ZstackDeviceInformation.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sapi/ZstackDeviceInformation.java new file mode 100644 index 0000000000..1548e284f7 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sapi/ZstackDeviceInformation.java @@ -0,0 +1,109 @@ +/** + * 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.dongle.zstack.api.sapi; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the Z-Stack Enumeration ZstackDeviceInformation. + *

+ * Device Info Constants + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public enum ZstackDeviceInformation { + /** + * Default unknown value + */ + UNKNOWN(-1), + + /** + * + */ + ZB_INFO_DEV_STATE(0x0000), + + /** + * + */ + ZB_INFO_IEEE_ADDR(0x0001), + + /** + * + */ + ZB_INFO_SHORT_ADDR(0x0002), + + /** + * + */ + ZB_INFO_PARENT_SHORT_ADDR(0x0003), + + /** + * + */ + ZB_INFO_PARENT_IEEE_ADDR(0x0004), + + /** + * + */ + ZB_INFO_CHANNEL(0x0005), + + /** + * + */ + ZB_INFO_PAN_ID(0x0006), + + /** + * + */ + ZB_INFO_EXT_PAN_ID(0x0007); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + static { + codeMapping = new HashMap(); + for (ZstackDeviceInformation s : values()) { + codeMapping.put(s.key, s); + } + } + + private ZstackDeviceInformation(int key) { + this.key = key; + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param code the code to lookup + * @return enumeration value of the alarm type. + */ + public static ZstackDeviceInformation valueOf(int code) { + if (codeMapping.get(code) == null) { + return UNKNOWN; + } + + return codeMapping.get(code); + } + + /** + * Returns the Z-Stack protocol defined value for this enumeration. + * + * @return the Z-Stack protocol key + */ + public int getKey() { + return key; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sapi/ZstackZbGetDeviceInfoSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sapi/ZstackZbGetDeviceInfoSreq.java new file mode 100644 index 0000000000..44094589c8 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sapi/ZstackZbGetDeviceInfoSreq.java @@ -0,0 +1,77 @@ +/** + * 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.dongle.zstack.api.sapi; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command ZB_GET_DEVICE_INFO. + *

+ * This command retrieves a Device Information Property. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackZbGetDeviceInfoSreq extends ZstackFrameRequest { + + /** + * The Identifier for the device information. + */ + private int param; + + /** + * Request constructor + */ + public ZstackZbGetDeviceInfoSreq() { + synchronousCommand = true; + } + + /** + * The Identifier for the device information. + * + * @return the current param as {@link int} + */ + public int getParam() { + return param; + } + + /** + * The Identifier for the device information. + * + * @param param the Param to set as {@link int} + */ + public void setParam(int param) { + this.param = param; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_SAPI) && (response.getReqCmd1() == 0x06)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_SAPI, 0x06); + + // Serialize the fields + serializer.serializeUInt8(param); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(53); + builder.append("ZstackZbGetDeviceInfoSreq [param="); + builder.append(param); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sapi/ZstackZbGetDeviceInfoSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sapi/ZstackZbGetDeviceInfoSrsp.java new file mode 100644 index 0000000000..754f0781c4 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sapi/ZstackZbGetDeviceInfoSrsp.java @@ -0,0 +1,93 @@ +/** + * 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.dongle.zstack.api.sapi; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; + +/** + * Class to implement the Z-Stack command ZB_GET_DEVICE_INFO. + *

+ * This command retrieves a Device Information Property. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackZbGetDeviceInfoSrsp extends ZstackFrameResponse { + + /** + * The Identifier for the device information. + */ + private int param; + + /** + * A buffer to hold the device information + */ + private int value; + + /** + * Response and Handler constructor + */ + public ZstackZbGetDeviceInfoSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + param = deserializer.deserializeUInt8(); + value = deserializer.deserializeUInt16(); + } + + /** + * The Identifier for the device information. + * + * @return the current param as {@link int} + */ + public int getParam() { + return param; + } + + /** + * The Identifier for the device information. + * + * @param param the Param to set as {@link int} + */ + public void setParam(int param) { + this.param = param; + } + + /** + * A buffer to hold the device information + * + * @return the current value as {@link int} + */ + public int getValue() { + return value; + } + + /** + * A buffer to hold the device information + * + * @param value the Value to set as {@link int} + */ + public void setValue(int value) { + this.value = value; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(78); + builder.append("ZstackZbGetDeviceInfoSrsp [param="); + builder.append(param); + builder.append(", value="); + builder.append(value); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sapi/ZstackZbReadConfigurationSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sapi/ZstackZbReadConfigurationSreq.java new file mode 100644 index 0000000000..5f634a02f6 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sapi/ZstackZbReadConfigurationSreq.java @@ -0,0 +1,78 @@ +/** + * 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.dongle.zstack.api.sapi; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackConfigId; + +/** + * Class to implement the Z-Stack command ZB_READ_CONFIGURATION. + *

+ * This command is used to get a configuration property from non-volatile memory. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackZbReadConfigurationSreq extends ZstackFrameRequest { + + /** + * Specifies the Identifier for the configuration property. + */ + private ZstackConfigId configId; + + /** + * Request constructor + */ + public ZstackZbReadConfigurationSreq() { + synchronousCommand = true; + } + + /** + * Specifies the Identifier for the configuration property. + * + * @return the current configId as {@link ZstackConfigId} + */ + public ZstackConfigId getConfigId() { + return configId; + } + + /** + * Specifies the Identifier for the configuration property. + * + * @param configId the ConfigId to set as {@link ZstackConfigId} + */ + public void setConfigId(ZstackConfigId configId) { + this.configId = configId; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_SAPI) && (response.getReqCmd1() == 0x04)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_SAPI, 0x04); + + // Serialize the fields + serializer.serializeUInt8(configId.getKey()); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(57); + builder.append("ZstackZbReadConfigurationSreq [configId="); + builder.append(configId); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sapi/ZstackZbReadConfigurationSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sapi/ZstackZbReadConfigurationSrsp.java new file mode 100644 index 0000000000..e17fa2c3c4 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sapi/ZstackZbReadConfigurationSrsp.java @@ -0,0 +1,127 @@ +/** + * 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.dongle.zstack.api.sapi; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackConfigId; + +/** + * Class to implement the Z-Stack command ZB_READ_CONFIGURATION. + *

+ * This command is used to get a configuration property from non-volatile memory. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackZbReadConfigurationSrsp extends ZstackFrameResponse { + + /** + * This field indicates either SUCCESS (0) or FAILURE (1). + */ + private ZstackResponseCode status; + + /** + * Specifies the Identifier for the configuration property. + */ + private ZstackConfigId configId; + + /** + * Buffer to hold the configuration property. + */ + private int[] value; + + /** + * Response and Handler constructor + */ + public ZstackZbReadConfigurationSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + configId = ZstackConfigId.valueOf(deserializer.deserializeUInt8()); + int len = deserializer.deserializeUInt8(); + value = deserializer.deserializeUInt8Array(len); + } + + /** + * This field indicates either SUCCESS (0) or FAILURE (1). + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * This field indicates either SUCCESS (0) or FAILURE (1). + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + /** + * Specifies the Identifier for the configuration property. + * + * @return the current configId as {@link ZstackConfigId} + */ + public ZstackConfigId getConfigId() { + return configId; + } + + /** + * Specifies the Identifier for the configuration property. + * + * @param configId the ConfigId to set as {@link ZstackConfigId} + */ + public void setConfigId(ZstackConfigId configId) { + this.configId = configId; + } + + /** + * Buffer to hold the configuration property. + * + * @return the current value as {@link int[]} + */ + public int[] getValue() { + return value; + } + + /** + * Buffer to hold the configuration property. + * + * @param value the Value to set as {@link int[]} + */ + public void setValue(int[] value) { + this.value = value; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(132); + builder.append("ZstackZbReadConfigurationSrsp [status="); + builder.append(status); + builder.append(", configId="); + builder.append(configId); + builder.append(", value="); + for (int c = 0; c < value.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", value[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sapi/ZstackZbWriteConfigurationSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sapi/ZstackZbWriteConfigurationSreq.java new file mode 100644 index 0000000000..c46a281e6d --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sapi/ZstackZbWriteConfigurationSreq.java @@ -0,0 +1,110 @@ +/** + * 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.dongle.zstack.api.sapi; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackConfigId; + +/** + * Class to implement the Z-Stack command ZB_WRITE_CONFIGURATION. + *

+ * This command is used to write a configuration property to nonvolatile memory. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackZbWriteConfigurationSreq extends ZstackFrameRequest { + + /** + * Specifies the Identifier for the configuration property. + */ + private ZstackConfigId configId; + + /** + * Buffer to hold the configuration property. + */ + private int[] value; + + /** + * Request constructor + */ + public ZstackZbWriteConfigurationSreq() { + synchronousCommand = true; + } + + /** + * Specifies the Identifier for the configuration property. + * + * @return the current configId as {@link ZstackConfigId} + */ + public ZstackConfigId getConfigId() { + return configId; + } + + /** + * Specifies the Identifier for the configuration property. + * + * @param configId the ConfigId to set as {@link ZstackConfigId} + */ + public void setConfigId(ZstackConfigId configId) { + this.configId = configId; + } + + /** + * Buffer to hold the configuration property. + * + * @return the current value as {@link int[]} + */ + public int[] getValue() { + return value; + } + + /** + * Buffer to hold the configuration property. + * + * @param value the Value to set as {@link int[]} + */ + public void setValue(int[] value) { + this.value = value; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_SAPI) && (response.getReqCmd1() == 0x05)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_SAPI, 0x05); + + // Serialize the fields + serializer.serializeUInt8(configId.getKey()); + serializer.serializeUInt8(value.length); + serializer.serializeUInt8Array(value); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(108); + builder.append("ZstackZbWriteConfigurationSreq [configId="); + builder.append(configId); + builder.append(", value="); + for (int c = 0; c < value.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", value[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sapi/ZstackZbWriteConfigurationSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sapi/ZstackZbWriteConfigurationSrsp.java new file mode 100644 index 0000000000..65055010ad --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sapi/ZstackZbWriteConfigurationSrsp.java @@ -0,0 +1,68 @@ +/** + * 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.dongle.zstack.api.sapi; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command ZB_WRITE_CONFIGURATION. + *

+ * This command is used to write a configuration property to nonvolatile memory. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackZbWriteConfigurationSrsp extends ZstackFrameResponse { + + /** + * This field indicates either SUCCESS (0) or FAILURE (1). + */ + private ZstackResponseCode status; + + /** + * Response and Handler constructor + */ + public ZstackZbWriteConfigurationSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + } + + /** + * This field indicates either SUCCESS (0) or FAILURE (1). + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * This field indicates either SUCCESS (0) or FAILURE (1). + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(58); + builder.append("ZstackZbWriteConfigurationSrsp [status="); + builder.append(status); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sbl/ZstackSbHandshakeCmdSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sbl/ZstackSbHandshakeCmdSreq.java new file mode 100644 index 0000000000..a4dff033a6 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sbl/ZstackSbHandshakeCmdSreq.java @@ -0,0 +1,47 @@ +/** + * 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.dongle.zstack.api.sbl; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command SB_HANDSHAKE_CMD. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSbHandshakeCmdSreq extends ZstackFrameRequest { + + /** + * Request constructor + */ + public ZstackSbHandshakeCmdSreq() { + synchronousCommand = true; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_SBL) && (response.getReqCmd1() == 0x04)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_SBL, 0x04); + + // Serialize the fields + return getPayload(); + } + + @Override + public String toString() { + return "ZstackSbHandshakeCmdSreq []"; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sbl/ZstackSbHandshakeCmdSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sbl/ZstackSbHandshakeCmdSrsp.java new file mode 100644 index 0000000000..f10c485932 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sbl/ZstackSbHandshakeCmdSrsp.java @@ -0,0 +1,168 @@ +/** + * 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.dongle.zstack.api.sbl; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command SB_HANDSHAKE_CMD. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSbHandshakeCmdSrsp extends ZstackFrameResponse { + + /** + * 0x00 - SUCCESS 0x01 - FAILURE + */ + private ZstackResponseCode status; + + /** + */ + private int bootloaderRevision; + + /** + */ + private int deviceType; + + /** + * The maximum data size to use with Read / Write command + */ + private int bufferLength; + + /** + * 0x800 – CC2538 flash page size + */ + private int pageSize; + + /** + * Response and Handler constructor + */ + public ZstackSbHandshakeCmdSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + bootloaderRevision = deserializer.deserializeUInt32(); + deviceType = deserializer.deserializeUInt8(); + bufferLength = deserializer.deserializeUInt32(); + pageSize = deserializer.deserializeUInt32(); + } + + /** + * 0x00 - SUCCESS 0x01 - FAILURE + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * 0x00 - SUCCESS 0x01 - FAILURE + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + /** + * + * + * @return the current bootloaderRevision as {@link int} + */ + public int getBootloaderRevision() { + return bootloaderRevision; + } + + /** + * + * + * @param bootloaderRevision the BootloaderRevision to set as {@link int} + */ + public void setBootloaderRevision(int bootloaderRevision) { + this.bootloaderRevision = bootloaderRevision; + } + + /** + * + * + * @return the current deviceType as {@link int} + */ + public int getDeviceType() { + return deviceType; + } + + /** + * + * + * @param deviceType the DeviceType to set as {@link int} + */ + public void setDeviceType(int deviceType) { + this.deviceType = deviceType; + } + + /** + * The maximum data size to use with Read / Write command + * + * @return the current bufferLength as {@link int} + */ + public int getBufferLength() { + return bufferLength; + } + + /** + * The maximum data size to use with Read / Write command + * + * @param bufferLength the BufferLength to set as {@link int} + */ + public void setBufferLength(int bufferLength) { + this.bufferLength = bufferLength; + } + + /** + * 0x800 – CC2538 flash page size + * + * @return the current pageSize as {@link int} + */ + public int getPageSize() { + return pageSize; + } + + /** + * 0x800 – CC2538 flash page size + * + * @param pageSize the PageSize to set as {@link int} + */ + public void setPageSize(int pageSize) { + this.pageSize = pageSize; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(152); + builder.append("ZstackSbHandshakeCmdSrsp [status="); + builder.append(status); + builder.append(", bootloaderRevision="); + builder.append(bootloaderRevision); + builder.append(", deviceType="); + builder.append(deviceType); + builder.append(", bufferLength="); + builder.append(bufferLength); + builder.append(", pageSize="); + builder.append(pageSize); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sbl/ZstackSbWriteCmdSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sbl/ZstackSbWriteCmdSreq.java new file mode 100644 index 0000000000..4ac9970054 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sbl/ZstackSbWriteCmdSreq.java @@ -0,0 +1,81 @@ +/** + * 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.dongle.zstack.api.sbl; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command SB_WRITE_CMD. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSbWriteCmdSreq extends ZstackFrameRequest { + + /** + * Payload data. + */ + private int[] payload; + + /** + * Request constructor + */ + public ZstackSbWriteCmdSreq() { + synchronousCommand = true; + } + + /** + * Payload data. + * + * @return the current payload as {@link int[]} + */ + public int[] getPayload() { + return payload; + } + + /** + * Payload data. + * + * @param payload the Payload to set as {@link int[]} + */ + public void setPayload(int[] payload) { + this.payload = payload; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_SBL) && (response.getReqCmd1() == 0x00)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_SBL, 0x00); + + // Serialize the fields + serializer.serializeUInt32(payload.length); + serializer.serializeUInt8Array(payload); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(73); + builder.append("ZstackSbWriteCmdSreq [payload="); + for (int c = 0; c < payload.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", payload[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sbl/ZstackSbWriteCmdSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sbl/ZstackSbWriteCmdSrsp.java new file mode 100644 index 0000000000..13e9e6bca6 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sbl/ZstackSbWriteCmdSrsp.java @@ -0,0 +1,66 @@ +/** + * 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.dongle.zstack.api.sbl; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command SB_WRITE_CMD. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSbWriteCmdSrsp extends ZstackFrameResponse { + + /** + * 0x00 - SUCCESS 0x01 - FAILURE + */ + private ZstackResponseCode status; + + /** + * Response and Handler constructor + */ + public ZstackSbWriteCmdSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + } + + /** + * 0x00 - SUCCESS 0x01 - FAILURE + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * 0x00 - SUCCESS 0x01 - FAILURE + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(48); + builder.append("ZstackSbWriteCmdSrsp [status="); + builder.append(status); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackConfigId.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackConfigId.java new file mode 100644 index 0000000000..fe5bdf8393 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackConfigId.java @@ -0,0 +1,658 @@ +/** + * 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.dongle.zstack.api.sys; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the Z-Stack Enumeration ZstackConfigId. + *

+ * Device specific configuration parameters. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public enum ZstackConfigId { + /** + * Default unknown value + */ + UNKNOWN(-1), + + /** + * + */ + ZCD_NV_EXTADDR(0x0000), + + /** + * + */ + ZCD_NV_BOOTCOUNTER(0x0001), + + /** + * This parameter controls the device startup options. Size: 1 byte; Default value: 0 + */ + ZCD_NV_STARTUP_OPTION(0x0003), + + /** + * + */ + ZCD_NV_START_DELAY(0x0004), + + /** + * If this parameter is set to a non-zero value, a CC2530-ZNP device that is configured as an end- device will wake up periodically + * with this duration to check for data with its parent device. This value is specified in milliseconds and can range from 1 to 65000. + * If this parameter is set to zero, the device will not automatically wake up to poll for data. Instead, an external trigger or an + * internal event (for example, via a software timer event) can be used to wake up the device. Size: 4 bytes; Default value: 2000 + */ + ZCD_NV_POLL_RATE_OLD16(0x0035), + + /** + * When an end-device polls for data with its parent and finds that it does have data, it can poll again with a shorter duration in case + * there is more data queued for it at its parent device. This value is specified in milliseconds. This feature can be turned off by + * setting this value to zero. Size: 2 bytes; Default value: 100 + */ + ZCD_NV_QUEUED_POLL_RATE(0x0025), + + /** + * When an end-device sends a data packet, it can poll again with a shorter duration, specified by this parameter, if the + * application is expecting to receive an application level packet in response. This value is specified in milliseconds. This + * feature can be turned off by setting the value to zero. + *

+ * Note: The setting of the queued and response poll rates has to be done with caution if the device is sending and receiving + * at the same time or if the device is sending data too fast. If the device is sending data too fast, setting a queued poll rate with a + * higher duration than the sending rate will cause the poll event to be continuously rescheduled to the future. Then the device + * will never poll for data with its parent and consequently it may miss any packets destined for it. Size: 2 bytes; Default value: + * 100 + */ + ZCD_NV_RESPONSE_POLL_RATE(0x0026), + + /** + * + */ + ZCD_NV_REJOIN_POLL_RATE(0x0027), + + /** + * + */ + ZCD_NV_DATA_RETRIES(0x0028), + + /** + * The number of times an end-device will fail when communicating with its parent before invoking the rejoin mechanism to find and + * join a new parent. Size: 1 byte; Default value: 2. + */ + ZCD_NV_POLL_FAILURE_RETRIES(0x0029), + + /** + * + */ + ZCD_NV_STACK_PROFILE(0x002A), + + /** + * The amount of time (in seconds) that a router or coordinator device will buffer messages destined to their end-device child + * nodes. It is recommended that this is at least greater than the poll rate (ZCD_NV_POLL_RATE) to ensure that end-device will have + * a chance to wakeup and poll for the data. Size: 1 byte; Default value: 7 + */ + ZCD_NV_INDIRECT_MSG_TIMEOUT(0x002B), + + /** + * The amount of time (in seconds) for which a route must be idle (i.e. no packets are transmitted on that route) before that routing + * entry is marked as expired. An expired entry may be deleted if the table is full and the space is needed for another new routing + * entry. This can be set to a special value of 0 to turn off route expiry. In this case, route entries are not expired. Size: 1 byte; + * Default value: 60. + */ + ZCD_NV_ROUTE_EXPIRY_TIME(0x002C), + + /** + * This parameter configures the EXTENDED PAN ID in Z-Stack. The extended pan id is used to further segregate the sub network(s) + * among a bigger PAN network. + */ + ZCD_NV_EXTPANID(0x002D), + + /** + * The maximum number of retransmissions that a device will attempt when trying to transmit a broadcast packet. The typical range + * is from 1 through 3. Size: 1 byte; Default value: 2. + */ + ZCD_NV_BCAST_RETRIES(0x002E), + + /** + * The amount of time (in units of 100milliseconds) a device will wait before retransmitting a broadcast packet. The + * retransmission will not happen if the node hears that each of its neighbor nodes have all transmitted that packet. Size: 1 byte; + * Default value: 5 + */ + ZCD_NV_PASSIVE_ACK_TIMEOUT(0x002F), + + /** + * The maximum amount of time (in units of 100ms) that it can take for a broadcast packet to propagate through the entire network. + * This includes time for all retransmissions. + *

+ * Note: This parameter must be set with caution. It must be set to a value of at least (ZCD_NV_BCAST_RETRIES + 1) * + * ZCD_NV_PASSIVE_ACK_TIMEOUT To be safe, the actual value should be higher than the above minimum by about 500ms or more. Size: 1 + * byte; Default value: 30. + */ + ZCD_NV_BCAST_DELIVERY_TIME(0x0030), + + /** + * Holds the value of the network operational mode. The default value is NWK_MODE_MESH and must not be modified. + */ + ZCD_NV_NWK_MODE(0x0031), + + /** + * + */ + ZCD_NV_CONCENTRATOR_ENABLE(0x0032), + + /** + * + */ + ZCD_NV_CONCENTRATOR_DISCOVERY(0x0033), + + /** + * + */ + ZCD_NV_CONCENTRATOR_RADIUS(0x0034), + + /** + * If this parameter is set to a non-zero value, a CC2530-ZNP device that is configured as an end- device will wake up periodically + * with this duration to check for data with its parent device. This value is specified in milliseconds and can range from 1 to 65000. + * If this parameter is set to zero, the device will not automatically wake up to poll for data. Instead, an external trigger or an + * internal event (for example, via a software timer event) can be used to wake up the device. Size: 4 bytes; Default value: 2000 + */ + ZCD_NV_POLL_RATE(0x0035), + + /** + * Holds the value of route cache flag. This enables or disables the route cache for coordinator and is FALSE by default. + */ + ZCD_NV_CONCENTRATOR_RC(0x0036), + + /** + * + */ + ZCD_NV_NWK_MGR_MODE(0x0037), + + /** + * + */ + ZCD_NV_SRC_RTG_EXPIRY_TIME(0x0038), + + /** + * + */ + ZCD_NV_ROUTE_DISCOVERY_TIME(0x0039), + + /** + * + */ + ZCD_NV_NWK_ACTIVE_KEY_INFO(0x003A), + + /** + * + */ + ZCD_NV_NWK_ALTERN_KEY_INFO(0x003B), + + /** + * + */ + ZCD_NV_ROUTER_OFF_ASSOC_CLEANUP(0x003C), + + /** + * + */ + ZCD_NV_NWK_LEAVE_REQ_ALLOWED(0x003D), + + /** + * Holds the value of Child Aging capability flag. This enables or disables child aging and must be set to TRUE for Zigbee 3.0 + * compliance. + */ + ZCD_NV_NWK_CHILD_AGE_ENABLE(0x003E), + + /** + * + */ + ZCD_NV_DEVICE_LIST_KA_TIMEOUT(0x003F), + + /** + * + */ + ZCD_NV_BINDING_TABLE(0x0041), + + /** + * + */ + ZCD_NV_GROUP_TABLE(0x0042), + + /** + * The number of retransmissions performed on a data packet at the application layer if the packet was transmitted with the + * end-to-end acknowledgement option enabled. Size: 1 byte; Default value: 3 + */ + ZCD_NV_APS_FRAME_RETRIES(0x0043), + + /** + * The amount of time (in milliseconds) a device will wait before re-transmitting a packet that used the APS acknowledgement + * option. If the APS acknowledgement is not received by this time, the sending device will assume a failure and attempt a + * re-transmission. + *

+ * Note: This is recommended to be set to approximately the expected round trip time for the packet. Note that if the + * destination (or source) device is an end-device, the round trip time for the packet will include an additional delay up to the + * poll duration. This is in addition to the delay normally caused by the network. Size: 2 bytes; Default value: 3000 + */ + ZCD_NV_APS_ACK_WAIT_DURATION(0x0044), + + /** + * + */ + ZCD_NV_APS_ACK_WAIT_MULTIPLIER(0x0045), + + /** + * The amount of time (in milliseconds) a device will wait for a response to a binding request. Size: 2 bytes; Default value: 8000 + */ + ZCD_NV_BINDING_TIME(0x0046), + + /** + * + */ + ZCD_NV_APS_USE_EXT_PANID(0x0047), + + /** + * + */ + ZCD_NV_COMMISSIONED_NWK_ADDR(0x0049), + + /** + * + */ + ZCD_NV_APS_NONMEMBER_RADIUS(0x004B), + + /** + * Holds the security manager entries of type ZDSecMgrEntry_t to store the TCKL used to talk with devices in the network that + * require APS security. The number of entries is controled by ZDSECMGR_DEVICE_MAX=3 by default. + */ + ZCD_NV_APS_LINK_KEY_TABLE(0x004C), + + /** + * + */ + ZCD_NV_APS_DUPREJ_TIMEOUT_INC(0x004D), + + /** + * + */ + ZCD_NV_APS_DUPREJ_TIMEOUT_COUNT(0x004E), + + /** + * + */ + ZCD_NV_APS_DUPREJ_TABLE_SIZE(0x004F), + + /** + * + */ + ZCD_NV_DIAGNOSTIC_STATS(0x0050), + + /** + * + */ + ZCD_NV_NWK_PARENT_INFO(0x0051), + + /** + * + */ + ZCD_NV_NWK_ENDDEV_TIMEOUT_DEF(0x0052), + + /** + * Holds the value of Child Aging Timeout. This is the time in seconds used by END DEVICE when sending End Device Timeout Request that + * tells a COORDINATOR the timeout to remove this END DEVICE after no data poll is received. + */ + ZCD_NV_END_DEV_TIMEOUT_VALUE(0x0053), + + /** + * Holds the value of End Device Configuration field when END DEVICE when sending End Device Timeout Request. Is set to 0x00 by + * default which is the only valid value accourding to Zigbee Core spec R21. + */ + ZCD_NV_END_DEV_CONFIGURATION(0x0054), + + /** + * + */ + ZCD_NV_BDBNODEISONANETWORK(0x0055), + + /** + * + */ + ZCD_NV_BDBREPORTINGCONFIG(0x0056), + + /** + * holds the value of network key that is generated by default. The key can be set to a fixed value by setting DEFAULT_KEY macro. This + * is used for securing and un-securing packets in the network, if security is enabled for the network. + *

+ * Note: Use of this configuration item requires the ZNP code to be built with the SECURE=1 compile option. Size: 16 bytes; + * Default value: [0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F] + */ + ZCD_NV_PRECFGKEY(0x0062), + + /** + * If security functionality is enabled, there are two options to distribute the security key to all devices in the network. If this + * parameter is true, the same security key is assumed to be pre-configured in all devices in the network.If it is set to false, then + * the key only needs to be configured on the coordinator device. In this case, the key is distributed to each device upon joining by + * the coordinator. This key distribution will happen in the “clear” on the last hop of the packet transmission and this + * constitutes a brief “period of vulnerability” during which a malicious device can capture the key. Hence it is not recommended + * unless it can be ensured that there are no malicious devices in the vicinity at the time of network formation. + *

+ * Note: Use of this configuration item requires the ZNP code to be built with the SECURE=1 compile option. Size: 1 byte; + * Default value: TRUE + */ + ZCD_NV_PRECFGKEYS_ENABLE(0x0063), + + /** + * This parameter determines if security is used or not in this network. It can be set to 0 (to turn off NWK security) or 1 (to turn on NWK + * security). Size: 1 byte; Default value: 0. + */ + ZCD_NV_SECURITY_MODE(0x0064), + + /** + * This value tells if only secure joins are allowed. Set to TRUE by default which is the only valid value according to Zigbee Core + * spec R21. + */ + ZCD_NV_SECURE_PERMIT_JOIN(0x0065), + + /** + * Is equal to ZG_GLOBAL_LINK_KEY=1 and must not be modified according to Zigbee Core spec R21. + */ + ZCD_NV_APS_LINK_KEY_TYPE(0x0066), + + /** + * + */ + ZCD_NV_APS_ALLOW_R19_SECURITY(0x0067), + + /** + * Default distributed nwk key Id. Nv ID not in use + */ + ZCD_NV_DISTRIBUTED_KEY(0x0068), + + /** + * + */ + ZCD_NV_IMPLICIT_CERTIFICATE(0x0069), + + /** + * + */ + ZCD_NV_DEVICE_PRIVATE_KEY(0x006A), + + /** + * + */ + ZCD_NV_CA_PUBLIC_KEY(0x006B), + + /** + * + */ + ZCD_NV_KE_MAX_DEVICES(0x006C), + + /** + * Controls whether a single pre-configured trust center link key is used or whether multiple pre- configured trust center link + * keys are used, hereby referred to as Single Key Mode and Multiple Key Mode, respectively. In multiple key mode, unique + * pre-configured trust center link keys are used between the trust center and each individual device joining the network. + * Multiple key mode is required by the recommended secure procedure in ZigBeeSE profile Specification. In single key mode, all + * devices are using the same pre-configured trust center link key to join the network. The single key mode provides a simplified + * alternative procedure to set up the network. It can be used for testing and debugging purpose. Size: 1 byte; Default value: TRUE + */ + ZCD_NV_USE_DEFAULT_TCLK(0x006D), + + /** + * + */ + ZCD_NV_RNG_COUNTER(0x006F), + + /** + * + */ + ZCD_NV_RANDOM_SEED(0x0070), + + /** + * + */ + ZCD_NV_TRUSTCENTER_ADDR(0x0071), + + /** + * + */ + ZCD_NV_CERT_283(0x0072), + + /** + * + */ + ZCD_NV_PRIVATE_KEY_283(0x0073), + + /** + * + */ + ZCD_NV_PUBLIC_KEY_283(0x0074), + + /** + * + */ + ZCD_NV_NWK_SEC_MATERIAL_TABLE_START(0x0075), + + /** + * + */ + ZCD_NV_NWK_SEC_MATERIAL_TABLE_END(0x0080), + + /** + * An optional user-defined data (up to 16bytes) that can be configured in a CC2530-ZNP device so that it can easily identified or + * described later. The first byte is the length of the user descriptor data and must not be greater than 16. Size: 17 bytes; Default + * value: “CC2530-ZNP x......” (dots represent the device IEEE address) + */ + ZCD_NV_USERDESC(0x0081), + + /** + * This holds the value of nwkActiveKeyItems structure and restores the NWK key counter after power cycles. + */ + ZCD_NV_NWKKEY(0x0082), + + /** + * This parameter identifies the ZigBee network. This should be set to a value between 0 and 0x3FFF. Networks that exist in the same + * vicinity must have different values for this parameter. It can be set to a special value of 0xFFFF to indicate “don’t care”. Size: + * 2 bytes; Default value: 0xFFFF + */ + ZCD_NV_PANID(0x0083), + + /** + * This parameter is a bit mask of the channels on which this network can operate (note that multiple channels can be selected). See + * section 4.5.16 for a table of the bitmap representation that maps to each channel. Multiple networks that exist in the same + * vicinity are encouraged to have different values. If multiple channels are selected, the coordinator will pick one of the + * channels for network operation. First, an energy scan is performed on each channel and those channels with a high energy level + * are discarded. Then, the coordinator determines the number of existing ZigBee networks on each of the remaining channels and + * picks the one with the fewest networks. For routers and end-devices, the device will simply scan all the selected channels until + * it finds the ZigBee network. Size: 4 bytes; Default value: 0x00000800 + */ + ZCD_NV_CHANLIST(0x0084), + + /** + * + */ + ZCD_NV_SCAN_DURATION(0x0086), + + /** + * This is the logical type of the device in the ZigBee network. This can be set to a COORDINATOR (0x00), ROUTER (0x01) or ENDDEVICE + * (0x02). + *

+ * Note: This parameter is read by the CC2530-ZNP device immediately when it powers up after a reset. Size: 1 byte; Default + * value: 0x00 + */ + ZCD_NV_LOGICAL_TYPE(0x0087), + + /** + * + */ + ZCD_NV_NWKMGR_MIN_TX(0x0088), + + /** + * + */ + ZCD_NV_NWKMGR_ADDR(0x0089), + + /** + * This configures the manner in which ZDO responses (hereby referred to as callbacks) are issued to the host processor. By + * default, this item is set to FALSE, which means that the host processor must use the ZDO_MSG_CB_REGISTER command to subscribe to + * a specific ZDO callback in order to receive it. The ZDO callback is then conveyed as part of the ZDO_MSG_CB_INCOMING command. If + * ZCD_NV_ZDO_DIRECT_CB is set TRUE, then the host processor will receive the “verbose” response. For example, the host + * processor would receive the ZDO_IEEE_ADDR_RSP command in response to ZDO_IEEE_ADDR_REQ. Size: 1 byte; Default value: FALSE + */ + ZCD_NV_ZDO_DIRECT_CB(0x008F), + + /** + * + */ + ZCD_NV_SAS_SHORT_ADDR(0x00B1), + + /** + * + */ + ZCD_NV_SAS_EXT_PANID(0x00B2), + + /** + * + */ + ZCD_NV_SAS_PANID(0x00B3), + + /** + * + */ + ZCD_NV_SAS_CHANNEL_MASK(0x00B4), + + /** + * + */ + ZCD_NV_SAS_PROTOCOL_VER(0x00B5), + + /** + * + */ + ZCD_NV_SAS_STACK_PROFILE(0x00B6), + + /** + * + */ + ZCD_NV_SAS_STARTUP_CTRL(0x00B7), + + /** + * + */ + ZCD_NV_SAS_TC_ADDR(0x00C1), + + /** + * + */ + ZCD_NV_SAS_TC_MASTER_KEY(0x00C2), + + /** + * + */ + ZCD_NV_SAS_NWK_KEY(0x00C3), + + /** + * + */ + ZCD_NV_SAS_USE_INSEC_JOIN(0x00C4), + + /** + * + */ + ZCD_NV_SAS_PRECFG_LINK_KEY(0x00C5), + + /** + * + */ + ZCD_NV_SAS_NWK_KEY_SEQ_NUM(0x00C6), + + /** + * + */ + ZCD_NV_SAS_NWK_KEY_TYPE(0x00C7), + + /** + * + */ + ZCD_NV_SAS_NWK_MGR_ADDR(0x00C8), + + /** + * + */ + ZCD_NV_SAS_CURR_TC_MASTER_KEY(0x00D1), + + /** + * + */ + ZCD_NV_SAS_CURR_NWK_KEY(0x00D2), + + /** + * + */ + ZCD_NV_TCLK_TABLE_START(0x0101), + + /** + * + */ + ZCD_NV_TCLK_TABLE_END(0x01FF), + + /** + * + */ + ZCD_NV_APS_LINK_KEY_DATA_START(0x0201), + + /** + * + */ + ZCD_NV_APS_LINK_KEY_DATA_END(0x02FF); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + static { + codeMapping = new HashMap(); + for (ZstackConfigId s : values()) { + codeMapping.put(s.key, s); + } + } + + private ZstackConfigId(int key) { + this.key = key; + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param code the code to lookup + * @return enumeration value of the alarm type. + */ + public static ZstackConfigId valueOf(int code) { + if (codeMapping.get(code) == null) { + return UNKNOWN; + } + + return codeMapping.get(code); + } + + /** + * Returns the Z-Stack protocol defined value for this enumeration. + * + * @return the Z-Stack protocol key + */ + public int getKey() { + return key; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackDiagnosticAttribute.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackDiagnosticAttribute.java new file mode 100644 index 0000000000..f18c1e7e38 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackDiagnosticAttribute.java @@ -0,0 +1,144 @@ +/** + * 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.dongle.zstack.api.sys; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the Z-Stack Enumeration ZstackDiagnosticAttribute. + *

+ * Diagnostics attribute IDs. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public enum ZstackDiagnosticAttribute { + /** + * Default unknown value + */ + UNKNOWN(-1), + + /** + * System Clock when stats were saved/cleared + */ + ZDIAGS_SYSTEM_CLOCK(0x0000), + + /** + * Increments every time the system resets + */ + ZDIAGS_NUMBER_OF_RESETS(0x0001), + + /** + * MAC diagnostic CRC success counter + */ + ZDIAGS_MAC_RX_CRC_PASS(0x0064), + + /** + * MAC diagnostic CRC failure counter + */ + ZDIAGS_MAC_RX_CRC_FAIL(0x0065), + + /** + * MAC layer retries a unicast + */ + ZDIAGS_MAC_TX_UCAST_RETRY(0x006A), + + /** + * Mac layer fails to send a unicast + */ + ZDIAGS_MAC_TX_UCAST_FAIL(0x006B), + + /** + * NWK packet decryption failed + */ + ZDIAGS_NWK_DECRYPT_FAILURES(0x00CF), + + /** + * NWK packet drop because of validation error + */ + ZDIAGS_PACKET_VALIDATE_DROP_COUNT(0x00D3), + + /** + * APS layer transmits broadcast + */ + ZDIAGS_APS_TX_BCAST(0x012D), + + /** + * APS layer successfully transmits a unicast + */ + ZDIAGS_APS_TX_UCAST_SUCCESS(0x012F), + + /** + * APS layer retries the sending of a unicast + */ + ZDIAGS_APS_TX_UCAST_RETRY(0x0130), + + /** + * APS layer fails to send a unicast + */ + ZDIAGS_APS_TX_UCAST_FAIL(0x0131), + + /** + * APS packet decryption failed + */ + ZDIAGS_APS_DECRYPT_FAILURES(0x0134), + + /** + * APS invalid packet dropped + */ + ZDIAGS_APS_INVALID_PACKETS(0x0135), + + /** + * Number of MAC retries per APS message + */ + ZDIAGS_MAC_RETRIES_PER_APS_TX_SUCCESS(0x0136); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + static { + codeMapping = new HashMap(); + for (ZstackDiagnosticAttribute s : values()) { + codeMapping.put(s.key, s); + } + } + + private ZstackDiagnosticAttribute(int key) { + this.key = key; + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param code the code to lookup + * @return enumeration value of the alarm type. + */ + public static ZstackDiagnosticAttribute valueOf(int code) { + if (codeMapping.get(code) == null) { + return UNKNOWN; + } + + return codeMapping.get(code); + } + + /** + * Returns the Z-Stack protocol defined value for this enumeration. + * + * @return the Z-Stack protocol key + */ + public int getKey() { + return key; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackNwkKeyDesc.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackNwkKeyDesc.java new file mode 100644 index 0000000000..e0e3072bda --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackNwkKeyDesc.java @@ -0,0 +1,100 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.internal.serializer.ZstackDeserializer; +import com.zsmartsystems.zigbee.dongle.zstack.internal.serializer.ZstackSerializer; +import com.zsmartsystems.zigbee.security.ZigBeeKey; + +/** + * Class to implement the Z-Stack structure ZstackNwkKeyDesc. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackNwkKeyDesc { + + /** + */ + private int keySeqNum; + + /** + */ + private ZigBeeKey key; + + /** + * + * + * @return the current keySeqNum as {@link int} + */ + public int getKeySeqNum() { + return keySeqNum; + } + + /** + * + * + * @param keySeqNum the keySeqNum to set as {@link int} + */ + public void setKeySeqNum(int keySeqNum) { + this.keySeqNum = keySeqNum; + } + + /** + * + * + * @return the current key as {@link ZigBeeKey} + */ + public ZigBeeKey getKey() { + return key; + } + + /** + * + * + * @param key the key to set as {@link ZigBeeKey} + */ + public void setKey(ZigBeeKey key) { + this.key = key; + } + + /** + * Serialize the data from this structure class to an integer array + * + * @param serializer the {@link ZstackSerializer} to use + */ + public int[] serialize(ZstackSerializer serializer) { + // Serialize the fields + serializer.serializeUInt8(keySeqNum); + serializer.serializeZigBeeKey(key); + return serializer.getBuffer(); + } + + /** + * Deserialize the data into this structure class + * + * @param deserializer the {@link ZstackDeserializer} to use + */ + public void deserialize (ZstackDeserializer deserializer) { + // Deserialize the fields + keySeqNum = deserializer.deserializeUInt8(); + key = deserializer.deserializeZigBeeKey(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(69); + builder.append("ZstackNwkKeyDesc [keySeqNum="); + builder.append(keySeqNum); + builder.append(", key="); + builder.append(key); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackResetReason.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackResetReason.java new file mode 100644 index 0000000000..6487a20ced --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackResetReason.java @@ -0,0 +1,84 @@ +/** + * 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.dongle.zstack.api.sys; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the Z-Stack Enumeration ZstackResetReason. + *

+ * Reasons for reset + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public enum ZstackResetReason { + /** + * Default unknown value + */ + UNKNOWN(-1), + + /** + * + */ + POWER_UP(0x0000), + + /** + * + */ + EXTERNAL(0x0001), + + /** + * + */ + WATCH_DOG(0x0002); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + static { + codeMapping = new HashMap(); + for (ZstackResetReason s : values()) { + codeMapping.put(s.key, s); + } + } + + private ZstackResetReason(int key) { + this.key = key; + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param code the code to lookup + * @return enumeration value of the alarm type. + */ + public static ZstackResetReason valueOf(int code) { + if (codeMapping.get(code) == null) { + return UNKNOWN; + } + + return codeMapping.get(code); + } + + /** + * Returns the Z-Stack protocol defined value for this enumeration. + * + * @return the Z-Stack protocol key + */ + public int getKey() { + return key; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackResetType.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackResetType.java new file mode 100644 index 0000000000..754fb01b8e --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackResetType.java @@ -0,0 +1,79 @@ +/** + * 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.dongle.zstack.api.sys; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the Z-Stack Enumeration ZstackResetType. + *

+ * Reset Command Type + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public enum ZstackResetType { + /** + * Default unknown value + */ + UNKNOWN(-1), + + /** + * + */ + TARGET_DEVICE(0x0000), + + /** + * + */ + SERIAL_BOOTLOADER(0x0001); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + static { + codeMapping = new HashMap(); + for (ZstackResetType s : values()) { + codeMapping.put(s.key, s); + } + } + + private ZstackResetType(int key) { + this.key = key; + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param code the code to lookup + * @return enumeration value of the alarm type. + */ + public static ZstackResetType valueOf(int code) { + if (codeMapping.get(code) == null) { + return UNKNOWN; + } + + return codeMapping.get(code); + } + + /** + * Returns the Z-Stack protocol defined value for this enumeration. + * + * @return the Z-Stack protocol key + */ + public int getKey() { + return key; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSecMgrEntry.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSecMgrEntry.java new file mode 100644 index 0000000000..40fa997450 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSecMgrEntry.java @@ -0,0 +1,128 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.api.appcnf.ZstackAuthenticationOption; +import com.zsmartsystems.zigbee.dongle.zstack.internal.serializer.ZstackDeserializer; +import com.zsmartsystems.zigbee.dongle.zstack.internal.serializer.ZstackSerializer; + +/** + * Class to implement the Z-Stack structure ZstackSecMgrEntry. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSecMgrEntry { + + /** + * Address manager index that holds the IEEE address of destination device. INVALID_NODE_ADDR = 0xFFFE + */ + private int ami; + + /** + * Index to the Link Key table in NV + */ + private int keyNvId; + + /** + */ + private ZstackAuthenticationOption authenticateOption; + + /** + * Address manager index that holds the IEEE address of destination device. INVALID_NODE_ADDR = 0xFFFE + * + * @return the current ami as {@link int} + */ + public int getAmi() { + return ami; + } + + /** + * Address manager index that holds the IEEE address of destination device. INVALID_NODE_ADDR = 0xFFFE + * + * @param ami the ami to set as {@link int} + */ + public void setAmi(int ami) { + this.ami = ami; + } + + /** + * Index to the Link Key table in NV + * + * @return the current keyNvId as {@link int} + */ + public int getKeyNvId() { + return keyNvId; + } + + /** + * Index to the Link Key table in NV + * + * @param keyNvId the keyNvId to set as {@link int} + */ + public void setKeyNvId(int keyNvId) { + this.keyNvId = keyNvId; + } + + /** + * + * + * @return the current authenticateOption as {@link ZstackAuthenticationOption} + */ + public ZstackAuthenticationOption getAuthenticateOption() { + return authenticateOption; + } + + /** + * + * + * @param authenticateOption the authenticateOption to set as {@link ZstackAuthenticationOption} + */ + public void setAuthenticateOption(ZstackAuthenticationOption authenticateOption) { + this.authenticateOption = authenticateOption; + } + + /** + * Serialize the data from this structure class to an integer array + * + * @param serializer the {@link ZstackSerializer} to use + */ + public int[] serialize(ZstackSerializer serializer) { + // Serialize the fields + serializer.serializeUInt16(ami); + serializer.serializeUInt16(keyNvId); + serializer.serializeUInt8(authenticateOption.getKey()); + return serializer.getBuffer(); + } + + /** + * Deserialize the data into this structure class + * + * @param deserializer the {@link ZstackDeserializer} to use + */ + public void deserialize (ZstackDeserializer deserializer) { + // Deserialize the fields + ami = deserializer.deserializeUInt16(); + keyNvId = deserializer.deserializeUInt16(); + authenticateOption = ZstackAuthenticationOption.valueOf(deserializer.deserializeUInt8()); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(95); + builder.append("ZstackSecMgrEntry [ami="); + builder.append(ami); + builder.append(", keyNvId="); + builder.append(keyNvId); + builder.append(", authenticateOption="); + builder.append(authenticateOption); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysGetExtAddrSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysGetExtAddrSreq.java new file mode 100644 index 0000000000..27c76cd145 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysGetExtAddrSreq.java @@ -0,0 +1,49 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command SYS_GET_EXT_ADDR. + *

+ * This command is used to set the extended address of the device. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysGetExtAddrSreq extends ZstackFrameRequest { + + /** + * Request constructor + */ + public ZstackSysGetExtAddrSreq() { + synchronousCommand = true; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_SYS) && (response.getReqCmd1() == 0x04)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_SYS, 0x04); + + // Serialize the fields + return getPayload(); + } + + @Override + public String toString() { + return "ZstackSysGetExtAddrSreq []"; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysGetExtAddrSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysGetExtAddrSrsp.java new file mode 100644 index 0000000000..2c8e335ccd --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysGetExtAddrSrsp.java @@ -0,0 +1,68 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.IeeeAddress; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; + +/** + * Class to implement the Z-Stack command SYS_GET_EXT_ADDR. + *

+ * This command is used to set the extended address of the device. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysGetExtAddrSrsp extends ZstackFrameResponse { + + /** + * The device’s extended address. + */ + private IeeeAddress extAddress; + + /** + * Response and Handler constructor + */ + public ZstackSysGetExtAddrSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + extAddress = deserializer.deserializeIeeeAddress(); + } + + /** + * The device’s extended address. + * + * @return the current extAddress as {@link IeeeAddress} + */ + public IeeeAddress getExtAddress() { + return extAddress; + } + + /** + * The device’s extended address. + * + * @param extAddress the ExtAddress to set as {@link IeeeAddress} + */ + public void setExtAddress(IeeeAddress extAddress) { + this.extAddress = extAddress; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(51); + builder.append("ZstackSysGetExtAddrSrsp [extAddress="); + builder.append(extAddress); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysOsalNvReadSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysOsalNvReadSreq.java new file mode 100644 index 0000000000..bbb4b17728 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysOsalNvReadSreq.java @@ -0,0 +1,104 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command SYS_OSAL_NV_READ. + *

+ * This command is used to read a single memory item from the target non-volatile memory. The command accepts an attribute Id value + * and data offset and returns the memory value present in the target for the specified attribute Id. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysOsalNvReadSreq extends ZstackFrameRequest { + + /** + * The Id of the NV item. + */ + private ZstackConfigId id; + + /** + * Number of bytes offset from the beginning or the NV value. + */ + private int offset; + + /** + * Request constructor + */ + public ZstackSysOsalNvReadSreq() { + synchronousCommand = true; + } + + /** + * The Id of the NV item. + * + * @return the current id as {@link ZstackConfigId} + */ + public ZstackConfigId getId() { + return id; + } + + /** + * The Id of the NV item. + * + * @param id the id to set as {@link ZstackConfigId} + */ + public void setId(ZstackConfigId id) { + this.id = id; + } + + /** + * Number of bytes offset from the beginning or the NV value. + * + * @return the current offset as {@link int} + */ + public int getOffset() { + return offset; + } + + /** + * Number of bytes offset from the beginning or the NV value. + * + * @param offset the Offset to set as {@link int} + */ + public void setOffset(int offset) { + this.offset = offset; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_SYS) && (response.getReqCmd1() == 0x08)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_SYS, 0x08); + + // Serialize the fields + serializer.serializeUInt8(id.getKey()); + serializer.serializeUInt8(offset); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(76); + builder.append("ZstackSysOsalNvReadSreq [id="); + builder.append(id); + builder.append(", offset="); + builder.append(offset); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysOsalNvReadSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysOsalNvReadSrsp.java new file mode 100644 index 0000000000..77b667f89a --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysOsalNvReadSrsp.java @@ -0,0 +1,101 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command SYS_OSAL_NV_READ. + *

+ * This command is used to read a single memory item from the target non-volatile memory. The command accepts an attribute Id value + * and data offset and returns the memory value present in the target for the specified attribute Id. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysOsalNvReadSrsp extends ZstackFrameResponse { + + /** + * Status is either Success (0) or Failure (1). + */ + private ZstackResponseCode status; + + /** + * Value of the NV item. + */ + private int[] value; + + /** + * Response and Handler constructor + */ + public ZstackSysOsalNvReadSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + int len = deserializer.deserializeUInt8(); + value = deserializer.deserializeUInt8Array(len); + } + + /** + * Status is either Success (0) or Failure (1). + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * Status is either Success (0) or Failure (1). + * + * @param status the status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + /** + * Value of the NV item. + * + * @return the current value as {@link int[]} + */ + public int[] getValue() { + return value; + } + + /** + * Value of the NV item. + * + * @param value the Value to set as {@link int[]} + */ + public void setValue(int[] value) { + this.value = value; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(101); + builder.append("ZstackSysOsalNvReadSrsp [status="); + builder.append(status); + builder.append(", value="); + for (int c = 0; c < value.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", value[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysOsalNvWriteSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysOsalNvWriteSreq.java new file mode 100644 index 0000000000..090a4421f6 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysOsalNvWriteSreq.java @@ -0,0 +1,136 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command SYS_OSAL_NV_WRITE. + *

+ * This command is used to write to a particular item in non-volatile memory. The command accepts an attribute Id, data offset, data + * length, and attribute value. The attribute value is written to the location specified for the attribute Id in the target. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysOsalNvWriteSreq extends ZstackFrameRequest { + + /** + * The Id of the NV item. + */ + private ZstackConfigId id; + + /** + * Number of bytes offset from the beginning or the NV value. + */ + private int offset; + + /** + * Value of the NV item. + */ + private int[] value; + + /** + * Request constructor + */ + public ZstackSysOsalNvWriteSreq() { + synchronousCommand = true; + } + + /** + * The Id of the NV item. + * + * @return the current id as {@link ZstackConfigId} + */ + public ZstackConfigId getId() { + return id; + } + + /** + * The Id of the NV item. + * + * @param id the Id to set as {@link ZstackConfigId} + */ + public void setId(ZstackConfigId id) { + this.id = id; + } + + /** + * Number of bytes offset from the beginning or the NV value. + * + * @return the current offset as {@link int} + */ + public int getOffset() { + return offset; + } + + /** + * Number of bytes offset from the beginning or the NV value. + * + * @param offset the Offset to set as {@link int} + */ + public void setOffset(int offset) { + this.offset = offset; + } + + /** + * Value of the NV item. + * + * @return the current value as {@link int[]} + */ + public int[] getValue() { + return value; + } + + /** + * Value of the NV item. + * + * @param value the Value to set as {@link int[]} + */ + public void setValue(int[] value) { + this.value = value; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_SYS) && (response.getReqCmd1() == 0x09)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_SYS, 0x09); + + // Serialize the fields + serializer.serializeUInt8(id.getKey()); + serializer.serializeUInt8(offset); + serializer.serializeUInt8(value.length); + serializer.serializeUInt8Array(value); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(127); + builder.append("ZstackSysOsalNvWriteSreq [id="); + builder.append(id); + builder.append(", offset="); + builder.append(offset); + builder.append(", value="); + for (int c = 0; c < value.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", value[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysOsalNvWriteSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysOsalNvWriteSrsp.java new file mode 100644 index 0000000000..b06ba01548 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysOsalNvWriteSrsp.java @@ -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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command SYS_OSAL_NV_WRITE. + *

+ * This command is used to write to a particular item in non-volatile memory. The command accepts an attribute Id, data offset, data + * length, and attribute value. The attribute value is written to the location specified for the attribute Id in the target. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysOsalNvWriteSrsp extends ZstackFrameResponse { + + /** + * Status is either Success (0) or Failure (1). + */ + private ZstackResponseCode status; + + /** + * Response and Handler constructor + */ + public ZstackSysOsalNvWriteSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + } + + /** + * Status is either Success (0) or Failure (1). + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * Status is either Success (0) or Failure (1). + * + * @param status the status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(52); + builder.append("ZstackSysOsalNvWriteSrsp [status="); + builder.append(status); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysPingSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysPingSreq.java new file mode 100644 index 0000000000..8f953acd39 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysPingSreq.java @@ -0,0 +1,49 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command SYS_PING. + *

+ * This command issues PING requests to verify if a device is active and check the capability of the device. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysPingSreq extends ZstackFrameRequest { + + /** + * Request constructor + */ + public ZstackSysPingSreq() { + synchronousCommand = true; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_SYS) && (response.getReqCmd1() == 0x01)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_SYS, 0x01); + + // Serialize the fields + return getPayload(); + } + + @Override + public String toString() { + return "ZstackSysPingSreq []"; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysPingSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysPingSrsp.java new file mode 100644 index 0000000000..23041e9586 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysPingSrsp.java @@ -0,0 +1,67 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; + +/** + * Class to implement the Z-Stack command SYS_PING. + *

+ * This command issues PING requests to verify if a device is active and check the capability of the device. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysPingSrsp extends ZstackFrameResponse { + + /** + * This field represents the interfaces that this device can handle (compiled into the device). + */ + private int capabilities; + + /** + * Response and Handler constructor + */ + public ZstackSysPingSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + capabilities = deserializer.deserializeUInt16(); + } + + /** + * This field represents the interfaces that this device can handle (compiled into the device). + * + * @return the current capabilities as {@link int} + */ + public int getCapabilities() { + return capabilities; + } + + /** + * This field represents the interfaces that this device can handle (compiled into the device). + * + * @param capabilities the Capabilities to set as {@link int} + */ + public void setCapabilities(int capabilities) { + this.capabilities = capabilities; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(45); + builder.append("ZstackSysPingSrsp [capabilities="); + builder.append(String.format("%04X", capabilities)); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysResetIndAreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysResetIndAreq.java new file mode 100644 index 0000000000..8d9840c5e7 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysResetIndAreq.java @@ -0,0 +1,195 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; + +/** + * Class to implement the Z-Stack command SYS_RESET_IND. + *

+ * This command is generated by the CC2530 device automatically immediately after a reset. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysResetIndAreq extends ZstackFrameResponse { + + /** + * One of the following values indicating the reason for the reset. Power=0x00, External=0x01, Watchdog=0x02 + */ + private ZstackResetReason reason; + + /** + * Transport protocol revision + */ + private int transportRev; + + /** + * Product Id + */ + private int product; + + /** + * Software major release number + */ + private int majorRel; + + /** + * Software minor release number + */ + private int minorRel; + + /** + * Hardware revision number. + */ + private int hwRev; + + /** + * Response and Handler constructor + */ + public ZstackSysResetIndAreq(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + // Deserialize the fields + reason = ZstackResetReason.valueOf(deserializer.deserializeUInt8()); + transportRev = deserializer.deserializeUInt8(); + product = deserializer.deserializeUInt8(); + majorRel = deserializer.deserializeUInt8(); + minorRel = deserializer.deserializeUInt8(); + hwRev = deserializer.deserializeUInt8(); + } + + /** + * One of the following values indicating the reason for the reset. Power=0x00, External=0x01, Watchdog=0x02 + * + * @return the current reason as {@link ZstackResetReason} + */ + public ZstackResetReason getReason() { + return reason; + } + + /** + * One of the following values indicating the reason for the reset. Power=0x00, External=0x01, Watchdog=0x02 + * + * @param reason the Reason to set as {@link ZstackResetReason} + */ + public void setReason(ZstackResetReason reason) { + this.reason = reason; + } + + /** + * Transport protocol revision + * + * @return the current transportRev as {@link int} + */ + public int getTransportRev() { + return transportRev; + } + + /** + * Transport protocol revision + * + * @param transportRev the TransportRev to set as {@link int} + */ + public void setTransportRev(int transportRev) { + this.transportRev = transportRev; + } + + /** + * Product Id + * + * @return the current product as {@link int} + */ + public int getProduct() { + return product; + } + + /** + * Product Id + * + * @param product the Product to set as {@link int} + */ + public void setProduct(int product) { + this.product = product; + } + + /** + * Software major release number + * + * @return the current majorRel as {@link int} + */ + public int getMajorRel() { + return majorRel; + } + + /** + * Software major release number + * + * @param majorRel the MajorRel to set as {@link int} + */ + public void setMajorRel(int majorRel) { + this.majorRel = majorRel; + } + + /** + * Software minor release number + * + * @return the current minorRel as {@link int} + */ + public int getMinorRel() { + return minorRel; + } + + /** + * Software minor release number + * + * @param minorRel the MinorRel to set as {@link int} + */ + public void setMinorRel(int minorRel) { + this.minorRel = minorRel; + } + + /** + * Hardware revision number. + * + * @return the current hwRev as {@link int} + */ + public int getHwRev() { + return hwRev; + } + + /** + * Hardware revision number. + * + * @param hwRev the HwRev to set as {@link int} + */ + public void setHwRev(int hwRev) { + this.hwRev = hwRev; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(174); + builder.append("ZstackSysResetIndAreq [reason="); + builder.append(reason); + builder.append(", transportRev="); + builder.append(transportRev); + builder.append(", product="); + builder.append(product); + builder.append(", majorRel="); + builder.append(majorRel); + builder.append(", minorRel="); + builder.append(minorRel); + builder.append(", hwRev="); + builder.append(hwRev); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysResetReqAcmd.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysResetReqAcmd.java new file mode 100644 index 0000000000..5b3e747a42 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysResetReqAcmd.java @@ -0,0 +1,74 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; + +/** + * Class to implement the Z-Stack command SYS_RESET_REQ. + *

+ * This command is issued by the application processor to reset the CC2530 device. The reset is achieved through an internal + * watchdog reset on the CC2530. Note that the hardware reset interface is recommended over using this interface. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysResetReqAcmd extends ZstackFrameRequest { + + /** + * This requests a target device reset (0) or serial bootloader reset (1). If the target device does not support serial + * bootloading, bootloader reset commands are ignored and no response is sent from the target. + */ + private ZstackResetType type; + + /** + * Request constructor + */ + public ZstackSysResetReqAcmd() { + } + + /** + * This requests a target device reset (0) or serial bootloader reset (1). If the target device does not support serial + * bootloading, bootloader reset commands are ignored and no response is sent from the target. + * + * @return the current type as {@link ZstackResetType} + */ + public ZstackResetType getType() { + return type; + } + + /** + * This requests a target device reset (0) or serial bootloader reset (1). If the target device does not support serial + * bootloading, bootloader reset commands are ignored and no response is sent from the target. + * + * @param type the Type to set as {@link ZstackResetType} + */ + public void setType(ZstackResetType type) { + this.type = type; + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_ACMD, ZSTACK_SYS, 0x00); + + // Serialize the fields + serializer.serializeUInt8(type.getKey()); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(49); + builder.append("ZstackSysResetReqAcmd [type="); + builder.append(type); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysSetExtAddrSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysSetExtAddrSreq.java new file mode 100644 index 0000000000..39cfed944f --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysSetExtAddrSreq.java @@ -0,0 +1,78 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.IeeeAddress; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command SYS_SET_EXT_ADDR. + *

+ * This command is used to set the extended address of the device. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysSetExtAddrSreq extends ZstackFrameRequest { + + /** + * The device’s extended address. + */ + private IeeeAddress extAddress; + + /** + * Request constructor + */ + public ZstackSysSetExtAddrSreq() { + synchronousCommand = true; + } + + /** + * The device’s extended address. + * + * @return the current extAddress as {@link IeeeAddress} + */ + public IeeeAddress getExtAddress() { + return extAddress; + } + + /** + * The device’s extended address. + * + * @param extAddress the ExtAddress to set as {@link IeeeAddress} + */ + public void setExtAddress(IeeeAddress extAddress) { + this.extAddress = extAddress; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_SYS) && (response.getReqCmd1() == 0x03)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_SYS, 0x03); + + // Serialize the fields + serializer.serializeIeeeAddress(extAddress); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(51); + builder.append("ZstackSysSetExtAddrSreq [extAddress="); + builder.append(extAddress); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysSetExtAddrSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysSetExtAddrSrsp.java new file mode 100644 index 0000000000..fadf08c210 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysSetExtAddrSrsp.java @@ -0,0 +1,68 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command SYS_SET_EXT_ADDR. + *

+ * This command is used to set the extended address of the device. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysSetExtAddrSrsp extends ZstackFrameResponse { + + /** + * Status is either Success (1) or Failure (0) + */ + private ZstackResponseCode status; + + /** + * Response and Handler constructor + */ + public ZstackSysSetExtAddrSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + } + + /** + * Status is either Success (1) or Failure (0) + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * Status is either Success (1) or Failure (0) + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(51); + builder.append("ZstackSysSetExtAddrSrsp [status="); + builder.append(status); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysSetTxPowerSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysSetTxPowerSreq.java new file mode 100644 index 0000000000..4f821e9732 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysSetTxPowerSreq.java @@ -0,0 +1,78 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command SYS_SET_TX_POWER. + *

+ * This command is used by the tester to set the target system radio transmit power. The returned TX power is the actual setting + * applied to the radio – nearest characterized value for the specific radio. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysSetTxPowerSreq extends ZstackFrameRequest { + + /** + * Requested TX power setting, in dBm. + */ + private int txPower; + + /** + * Request constructor + */ + public ZstackSysSetTxPowerSreq() { + synchronousCommand = true; + } + + /** + * Requested TX power setting, in dBm. + * + * @return the current txPower as {@link int} + */ + public int getTxPower() { + return txPower; + } + + /** + * Requested TX power setting, in dBm. + * + * @param txPower the TxPower to set as {@link int} + */ + public void setTxPower(int txPower) { + this.txPower = txPower; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_SYS) && (response.getReqCmd1() == 0x14)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_SYS, 0x14); + + // Serialize the fields + serializer.serializeUInt8(txPower); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(51); + builder.append("ZstackSysSetTxPowerSreq [txPower="); + builder.append(txPower); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysSetTxPowerSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysSetTxPowerSrsp.java new file mode 100644 index 0000000000..bc5e473525 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysSetTxPowerSrsp.java @@ -0,0 +1,68 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; + +/** + * Class to implement the Z-Stack command SYS_SET_TX_POWER. + *

+ * This command is used by the tester to set the target system radio transmit power. The returned TX power is the actual setting + * applied to the radio – nearest characterized value for the specific radio. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysSetTxPowerSrsp extends ZstackFrameResponse { + + /** + * Requested TX power setting, in dBm. + */ + private int txPower; + + /** + * Response and Handler constructor + */ + public ZstackSysSetTxPowerSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + txPower = deserializer.deserializeUInt8(); + } + + /** + * Requested TX power setting, in dBm. + * + * @return the current txPower as {@link int} + */ + public int getTxPower() { + return txPower; + } + + /** + * Requested TX power setting, in dBm. + * + * @param txPower the TxPower to set as {@link int} + */ + public void setTxPower(int txPower) { + this.txPower = txPower; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(51); + builder.append("ZstackSysSetTxPowerSrsp [txPower="); + builder.append(txPower); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysVersionSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysVersionSreq.java new file mode 100644 index 0000000000..3b0810af13 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysVersionSreq.java @@ -0,0 +1,49 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command SYS_VERSION. + *

+ * This command issues PING requests to verify if a device is active and check the capability of the device. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysVersionSreq extends ZstackFrameRequest { + + /** + * Request constructor + */ + public ZstackSysVersionSreq() { + synchronousCommand = true; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_SYS) && (response.getReqCmd1() == 0x02)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_SYS, 0x02); + + // Serialize the fields + return getPayload(); + } + + @Override + public String toString() { + return "ZstackSysVersionSreq []"; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysVersionSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysVersionSrsp.java new file mode 100644 index 0000000000..69728fbd41 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysVersionSrsp.java @@ -0,0 +1,171 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; + +/** + * Class to implement the Z-Stack command SYS_VERSION. + *

+ * This command issues PING requests to verify if a device is active and check the capability of the device. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysVersionSrsp extends ZstackFrameResponse { + + /** + * Transport protocol revision + */ + private int transportRev; + + /** + * Product Id + */ + private int product; + + /** + * Software major release number + */ + private int majorRel; + + /** + * Software minor release number + */ + private int minorRel; + + /** + * Software maintenance release number + */ + private int maintRel; + + /** + * Response and Handler constructor + */ + public ZstackSysVersionSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + transportRev = deserializer.deserializeUInt8(); + product = deserializer.deserializeUInt8(); + majorRel = deserializer.deserializeUInt8(); + minorRel = deserializer.deserializeUInt8(); + maintRel = deserializer.deserializeUInt8(); + } + + /** + * Transport protocol revision + * + * @return the current transportRev as {@link int} + */ + public int getTransportRev() { + return transportRev; + } + + /** + * Transport protocol revision + * + * @param transportRev the TransportRev to set as {@link int} + */ + public void setTransportRev(int transportRev) { + this.transportRev = transportRev; + } + + /** + * Product Id + * + * @return the current product as {@link int} + */ + public int getProduct() { + return product; + } + + /** + * Product Id + * + * @param product the Product to set as {@link int} + */ + public void setProduct(int product) { + this.product = product; + } + + /** + * Software major release number + * + * @return the current majorRel as {@link int} + */ + public int getMajorRel() { + return majorRel; + } + + /** + * Software major release number + * + * @param majorRel the MajorRel to set as {@link int} + */ + public void setMajorRel(int majorRel) { + this.majorRel = majorRel; + } + + /** + * Software minor release number + * + * @return the current minorRel as {@link int} + */ + public int getMinorRel() { + return minorRel; + } + + /** + * Software minor release number + * + * @param minorRel the MinorRel to set as {@link int} + */ + public void setMinorRel(int minorRel) { + this.minorRel = minorRel; + } + + /** + * Software maintenance release number + * + * @return the current maintRel as {@link int} + */ + public int getMaintRel() { + return maintRel; + } + + /** + * Software maintenance release number + * + * @param maintRel the MaintRel to set as {@link int} + */ + public void setMaintRel(int maintRel) { + this.maintRel = maintRel; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(148); + builder.append("ZstackSysVersionSrsp [transportRev="); + builder.append(transportRev); + builder.append(", product="); + builder.append(product); + builder.append(", majorRel="); + builder.append(majorRel); + builder.append(", minorRel="); + builder.append(minorRel); + builder.append(", maintRel="); + builder.append(maintRel); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsClearStatsSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsClearStatsSreq.java new file mode 100644 index 0000000000..3f51f6d98e --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsClearStatsSreq.java @@ -0,0 +1,78 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command SYS_ZDIAGS_CLEAR_STATS. + *

+ * This command is used to clear the statistics table. To clear data in NV (including the Boot Counter) the clearNV flag shall be set + * to TRUE. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysZdiagsClearStatsSreq extends ZstackFrameRequest { + + /** + * TRUE – Clears statistics in NV memory including Boot Counter. FALSE – Clears statistics in RAM only. Boot Counter is preserved. + */ + private boolean clearNv; + + /** + * Request constructor + */ + public ZstackSysZdiagsClearStatsSreq() { + synchronousCommand = true; + } + + /** + * TRUE – Clears statistics in NV memory including Boot Counter. FALSE – Clears statistics in RAM only. Boot Counter is preserved. + * + * @return the current clearNv as {@link boolean} + */ + public boolean getClearNV() { + return clearNv; + } + + /** + * TRUE – Clears statistics in NV memory including Boot Counter. FALSE – Clears statistics in RAM only. Boot Counter is preserved. + * + * @param clearNv the clearNV to set as {@link boolean} + */ + public void setClearNV(boolean clearNv) { + this.clearNv = clearNv; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_SYS) && (response.getReqCmd1() == 0x18)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_SYS, 0x18); + + // Serialize the fields + serializer.serializeBoolean(clearNv); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(57); + builder.append("ZstackSysZdiagsClearStatsSreq [clearNv="); + builder.append(clearNv); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsClearStatsSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsClearStatsSrsp.java new file mode 100644 index 0000000000..eeea7e39c7 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsClearStatsSrsp.java @@ -0,0 +1,68 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; + +/** + * Class to implement the Z-Stack command SYS_ZDIAGS_CLEAR_STATS. + *

+ * This command is used to clear the statistics table. To clear data in NV (including the Boot Counter) the clearNV flag shall be set + * to TRUE. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysZdiagsClearStatsSrsp extends ZstackFrameResponse { + + /** + * Milliseconds since last reset. + */ + private int sysClock; + + /** + * Response and Handler constructor + */ + public ZstackSysZdiagsClearStatsSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + sysClock = deserializer.deserializeUInt32(); + } + + /** + * Milliseconds since last reset. + * + * @return the current sysClock as {@link int} + */ + public int getSysClock() { + return sysClock; + } + + /** + * Milliseconds since last reset. + * + * @param sysClock the SysClock to set as {@link int} + */ + public void setSysClock(int sysClock) { + this.sysClock = sysClock; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(57); + builder.append("ZstackSysZdiagsClearStatsSrsp [sysClock="); + builder.append(sysClock); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsGetStatsSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsGetStatsSreq.java new file mode 100644 index 0000000000..91e27c8598 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsGetStatsSreq.java @@ -0,0 +1,77 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command SYS_ZDIAGS_GET_STATS. + *

+ * This command is used to read a specific system (attribute) ID statistics and/or metrics value. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysZdiagsGetStatsSreq extends ZstackFrameRequest { + + /** + * System Diagnostics (ZDiags) attribute ID, as defined in ZDiags.h module. + */ + private ZstackDiagnosticAttribute attributeId; + + /** + * Request constructor + */ + public ZstackSysZdiagsGetStatsSreq() { + synchronousCommand = true; + } + + /** + * System Diagnostics (ZDiags) attribute ID, as defined in ZDiags.h module. + * + * @return the current attributeId as {@link ZstackDiagnosticAttribute} + */ + public ZstackDiagnosticAttribute getAttributeID() { + return attributeId; + } + + /** + * System Diagnostics (ZDiags) attribute ID, as defined in ZDiags.h module. + * + * @param attributeId the AttributeID to set as {@link ZstackDiagnosticAttribute} + */ + public void setAttributeID(ZstackDiagnosticAttribute attributeId) { + this.attributeId = attributeId; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_SYS) && (response.getReqCmd1() == 0x19)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_SYS, 0x19); + + // Serialize the fields + serializer.serializeUInt16(attributeId.getKey()); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(55); + builder.append("ZstackSysZdiagsGetStatsSreq [attributeId="); + builder.append(attributeId); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsGetStatsSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsGetStatsSrsp.java new file mode 100644 index 0000000000..8354040f0b --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsGetStatsSrsp.java @@ -0,0 +1,67 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; + +/** + * Class to implement the Z-Stack command SYS_ZDIAGS_GET_STATS. + *

+ * This command is used to read a specific system (attribute) ID statistics and/or metrics value. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysZdiagsGetStatsSrsp extends ZstackFrameResponse { + + /** + * Value of the requested attribute. + */ + private int attributeValue; + + /** + * Response and Handler constructor + */ + public ZstackSysZdiagsGetStatsSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + attributeValue = deserializer.deserializeUInt32(); + } + + /** + * Value of the requested attribute. + * + * @return the current attributeValue as {@link int} + */ + public int getAttributeValue() { + return attributeValue; + } + + /** + * Value of the requested attribute. + * + * @param attributeValue the AttributeValue to set as {@link int} + */ + public void setAttributeValue(int attributeValue) { + this.attributeValue = attributeValue; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(55); + builder.append("ZstackSysZdiagsGetStatsSrsp [attributeValue="); + builder.append(attributeValue); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsInitStatsSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsInitStatsSreq.java new file mode 100644 index 0000000000..e75ddd3bce --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsInitStatsSreq.java @@ -0,0 +1,49 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command SYS_ZDIAGS_INIT_STATS. + *

+ * This command is used to initialize the statistics table in NV memory. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysZdiagsInitStatsSreq extends ZstackFrameRequest { + + /** + * Request constructor + */ + public ZstackSysZdiagsInitStatsSreq() { + synchronousCommand = true; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_SYS) && (response.getReqCmd1() == 0x17)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_SYS, 0x17); + + // Serialize the fields + return getPayload(); + } + + @Override + public String toString() { + return "ZstackSysZdiagsInitStatsSreq []"; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsInitStatsSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsInitStatsSrsp.java new file mode 100644 index 0000000000..5b0e84bd56 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsInitStatsSrsp.java @@ -0,0 +1,68 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command SYS_ZDIAGS_INIT_STATS. + *

+ * This command is used to initialize the statistics table in NV memory. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysZdiagsInitStatsSrsp extends ZstackFrameResponse { + + /** + * Status is either Success (0) or Failure (1). + */ + private ZstackResponseCode status; + + /** + * Response and Handler constructor + */ + public ZstackSysZdiagsInitStatsSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + } + + /** + * Status is either Success (0) or Failure (1). + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * Status is either Success (0) or Failure (1). + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(56); + builder.append("ZstackSysZdiagsInitStatsSrsp [status="); + builder.append(status); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsRestoreStatsNvSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsRestoreStatsNvSreq.java new file mode 100644 index 0000000000..c60a2f76b3 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsRestoreStatsNvSreq.java @@ -0,0 +1,77 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command SYS_ZDIAGS_RESTORE_STATS_NV. + *

+ * This command is used to restore the statistics table from NV into the RAM table. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysZdiagsRestoreStatsNvSreq extends ZstackFrameRequest { + + /** + * System Diagnostics (ZDiags) attribute ID, as defined in ZDiags.h module. + */ + private ZstackDiagnosticAttribute attributeId; + + /** + * Request constructor + */ + public ZstackSysZdiagsRestoreStatsNvSreq() { + synchronousCommand = true; + } + + /** + * System Diagnostics (ZDiags) attribute ID, as defined in ZDiags.h module. + * + * @return the current attributeId as {@link ZstackDiagnosticAttribute} + */ + public ZstackDiagnosticAttribute getAttributeID() { + return attributeId; + } + + /** + * System Diagnostics (ZDiags) attribute ID, as defined in ZDiags.h module. + * + * @param attributeId the AttributeID to set as {@link ZstackDiagnosticAttribute} + */ + public void setAttributeID(ZstackDiagnosticAttribute attributeId) { + this.attributeId = attributeId; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_SYS) && (response.getReqCmd1() == 0x1A)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_SYS, 0x1A); + + // Serialize the fields + serializer.serializeUInt16(attributeId.getKey()); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(61); + builder.append("ZstackSysZdiagsRestoreStatsNvSreq [attributeId="); + builder.append(attributeId); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsRestoreStatsNvSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsRestoreStatsNvSrsp.java new file mode 100644 index 0000000000..ca1ebdf4ae --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsRestoreStatsNvSrsp.java @@ -0,0 +1,68 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command SYS_ZDIAGS_RESTORE_STATS_NV. + *

+ * This command is used to restore the statistics table from NV into the RAM table. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysZdiagsRestoreStatsNvSrsp extends ZstackFrameResponse { + + /** + * Status is either Success (0) or Failure (1). + */ + private ZstackResponseCode status; + + /** + * Response and Handler constructor + */ + public ZstackSysZdiagsRestoreStatsNvSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + } + + /** + * Status is either Success (0) or Failure (1). + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * Status is either Success (0) or Failure (1). + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(61); + builder.append("ZstackSysZdiagsRestoreStatsNvSrsp [status="); + builder.append(status); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsSaveStatsToNvSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsSaveStatsToNvSreq.java new file mode 100644 index 0000000000..ca8a96c788 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsSaveStatsToNvSreq.java @@ -0,0 +1,49 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command SYS_ZDIAGS_SAVE_STATS_TO_NV. + *

+ * This command is used to save the statistics table from RAM to NV. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysZdiagsSaveStatsToNvSreq extends ZstackFrameRequest { + + /** + * Request constructor + */ + public ZstackSysZdiagsSaveStatsToNvSreq() { + synchronousCommand = true; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_SYS) && (response.getReqCmd1() == 0x1B)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_SYS, 0x1B); + + // Serialize the fields + return getPayload(); + } + + @Override + public String toString() { + return "ZstackSysZdiagsSaveStatsToNvSreq []"; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsSaveStatsToNvSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsSaveStatsToNvSrsp.java new file mode 100644 index 0000000000..4a9bd13404 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysZdiagsSaveStatsToNvSrsp.java @@ -0,0 +1,67 @@ +/** + * 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.dongle.zstack.api.sys; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; + +/** + * Class to implement the Z-Stack command SYS_ZDIAGS_SAVE_STATS_TO_NV. + *

+ * This command is used to save the statistics table from RAM to NV. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackSysZdiagsSaveStatsToNvSrsp extends ZstackFrameResponse { + + /** + * Milliseconds since last reset. + */ + private int sysClock; + + /** + * Response and Handler constructor + */ + public ZstackSysZdiagsSaveStatsToNvSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + sysClock = deserializer.deserializeUInt32(); + } + + /** + * Milliseconds since last reset. + * + * @return the current sysClock as {@link int} + */ + public int getSysClock() { + return sysClock; + } + + /** + * Milliseconds since last reset. + * + * @param sysClock the SysClock to set as {@link int} + */ + public void setSysClock(int sysClock) { + this.sysClock = sysClock; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(60); + builder.append("ZstackSysZdiagsSaveStatsToNvSrsp [sysClock="); + builder.append(sysClock); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSystemCapabilities.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSystemCapabilities.java new file mode 100644 index 0000000000..fdb0c686b1 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSystemCapabilities.java @@ -0,0 +1,119 @@ +/** + * 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.dongle.zstack.api.sys; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the Z-Stack Enumeration ZstackSystemCapabilities. + *

+ * Subsystem capabilities bitmap + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public enum ZstackSystemCapabilities { + /** + * Default unknown value + */ + UNKNOWN(-1), + + /** + * + */ + MT_CAP_SYS(0x0001), + + /** + * + */ + MT_CAP_MAC(0x0002), + + /** + * + */ + MT_CAP_NWK(0x0004), + + /** + * + */ + MT_CAP_AF(0x0008), + + /** + * + */ + MT_CAP_ZDO(0x0010), + + /** + * + */ + MT_CAP_SAPI(0x0020), + + /** + * + */ + MT_CAP_UTIL(0x0040), + + /** + * + */ + MT_CAP_DEBUG(0x0080), + + /** + * + */ + MT_CAP_APP(0x0100), + + /** + * + */ + MT_CAP_ZOAD(0x1000); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + static { + codeMapping = new HashMap(); + for (ZstackSystemCapabilities s : values()) { + codeMapping.put(s.key, s); + } + } + + private ZstackSystemCapabilities(int key) { + this.key = key; + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param code the code to lookup + * @return enumeration value of the alarm type. + */ + public static ZstackSystemCapabilities valueOf(int code) { + if (codeMapping.get(code) == null) { + return UNKNOWN; + } + + return codeMapping.get(code); + } + + /** + * Returns the Z-Stack protocol defined value for this enumeration. + * + * @return the Z-Stack protocol key + */ + public int getKey() { + return key; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackZdoState.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackZdoState.java new file mode 100644 index 0000000000..0197882bbd --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackZdoState.java @@ -0,0 +1,122 @@ +/** + * 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.dongle.zstack.api.sys; + +import java.util.HashMap; +import java.util.Map; + +/** + * Class to implement the Z-Stack Enumeration ZstackZdoState. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public enum ZstackZdoState { + /** + * Default unknown value + */ + UNKNOWN(-1), + + /** + * Initialized - not started automatically + */ + DEV_HOLD(0x0000), + + /** + * Initialized - not connected to anything + */ + DEV_INIT(0x0001), + + /** + * Discovering PAN's to join + */ + DEV_NWK_DISC(0x0002), + + /** + * Joining a PAN + */ + DEV_NWK_JOINING(0x0003), + + /** + * ReJoining a PAN, only for end devices + */ + DEV_NWK_REJOIN(0x0004), + + /** + * Joined but not yet authenticated by trust center + */ + DEV_END_DEVICE_UNAUTH(0x0005), + + /** + * Started as device after authentication + */ + DEV_END_DEVICE(0x0006), + + /** + * Device joined, authenticated and is a router + */ + DEV_ROUTER(0x0007), + + /** + * Starting as Zigbee Coordinator + */ + DEV_COORD_STARTING(0x0008), + + /** + * Started as Zigbee Coordinator + */ + DEV_ZB_COORD(0x0009), + + /** + * Device has lost information about its parent + */ + DEV_NWK_ORPHAN(0x000A); + + /** + * A mapping between the integer code and its corresponding type to + * facilitate lookup by code. + */ + private static Map codeMapping; + + private int key; + + static { + codeMapping = new HashMap(); + for (ZstackZdoState s : values()) { + codeMapping.put(s.key, s); + } + } + + private ZstackZdoState(int key) { + this.key = key; + } + + /** + * Lookup function based on the type code. Returns null if the code does not exist. + * + * @param code the code to lookup + * @return enumeration value of the alarm type. + */ + public static ZstackZdoState valueOf(int code) { + if (codeMapping.get(code) == null) { + return UNKNOWN; + } + + return codeMapping.get(code); + } + + /** + * Returns the Z-Stack protocol defined value for this enumeration. + * + * @return the Z-Stack protocol key + */ + public int getKey() { + return key; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilApsmeLinkKeyDataGetSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilApsmeLinkKeyDataGetSreq.java new file mode 100644 index 0000000000..ffc14c095c --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilApsmeLinkKeyDataGetSreq.java @@ -0,0 +1,78 @@ +/** + * 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.dongle.zstack.api.util; + +import com.zsmartsystems.zigbee.IeeeAddress; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command UTIL_APSME_LINK_KEY_DATA_GET. + *

+ * This command retrieves APS link key data, Tx and Rx frame counters. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackUtilApsmeLinkKeyDataGetSreq extends ZstackFrameRequest { + + /** + * The extended address for which to get the link key data. + */ + private IeeeAddress extAddr; + + /** + * Request constructor + */ + public ZstackUtilApsmeLinkKeyDataGetSreq() { + synchronousCommand = true; + } + + /** + * The extended address for which to get the link key data. + * + * @return the current extAddr as {@link IeeeAddress} + */ + public IeeeAddress getExtAddr() { + return extAddr; + } + + /** + * The extended address for which to get the link key data. + * + * @param extAddr the ExtAddr to set as {@link IeeeAddress} + */ + public void setExtAddr(IeeeAddress extAddr) { + this.extAddr = extAddr; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_UTIL) && (response.getReqCmd1() == 0x44)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_UTIL, 0x44); + + // Serialize the fields + serializer.serializeIeeeAddress(extAddr); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(61); + builder.append("ZstackUtilApsmeLinkKeyDataGetSreq [extAddr="); + builder.append(extAddr); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilApsmeLinkKeyDataGetSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilApsmeLinkKeyDataGetSrsp.java new file mode 100644 index 0000000000..8bd2c98126 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilApsmeLinkKeyDataGetSrsp.java @@ -0,0 +1,147 @@ +/** + * 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.dongle.zstack.api.util; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; +import com.zsmartsystems.zigbee.security.ZigBeeKey; + +/** + * Class to implement the Z-Stack command UTIL_APSME_LINK_KEY_DATA_GET. + *

+ * This command retrieves APS link key data, Tx and Rx frame counters. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackUtilApsmeLinkKeyDataGetSrsp extends ZstackFrameResponse { + + /** + * The ZStatus_t returned by the proxy call to APSME_LinkKeyNVIdGet(). + */ + private ZstackResponseCode status; + + /** + * On success, the security key looked up; otherwise N/A. + */ + private ZigBeeKey secKey; + + /** + * On success, the TX frame counter; otherwise N/A. + */ + private int txFrmCntr; + + /** + * On success, the RX frame counter; otherwise N/A. + */ + private int rxFrmCntr; + + /** + * Response and Handler constructor + */ + public ZstackUtilApsmeLinkKeyDataGetSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + secKey = deserializer.deserializeZigBeeKey(); + txFrmCntr = deserializer.deserializeUInt32(); + rxFrmCntr = deserializer.deserializeUInt32(); + } + + /** + * The ZStatus_t returned by the proxy call to APSME_LinkKeyNVIdGet(). + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * The ZStatus_t returned by the proxy call to APSME_LinkKeyNVIdGet(). + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + /** + * On success, the security key looked up; otherwise N/A. + * + * @return the current secKey as {@link ZigBeeKey} + */ + public ZigBeeKey getSecKey() { + return secKey; + } + + /** + * On success, the security key looked up; otherwise N/A. + * + * @param secKey the SecKey to set as {@link ZigBeeKey} + */ + public void setSecKey(ZigBeeKey secKey) { + this.secKey = secKey; + } + + /** + * On success, the TX frame counter; otherwise N/A. + * + * @return the current txFrmCntr as {@link int} + */ + public int getTxFrmCntr() { + return txFrmCntr; + } + + /** + * On success, the TX frame counter; otherwise N/A. + * + * @param txFrmCntr the TxFrmCntr to set as {@link int} + */ + public void setTxFrmCntr(int txFrmCntr) { + this.txFrmCntr = txFrmCntr; + } + + /** + * On success, the RX frame counter; otherwise N/A. + * + * @return the current rxFrmCntr as {@link int} + */ + public int getRxFrmCntr() { + return rxFrmCntr; + } + + /** + * On success, the RX frame counter; otherwise N/A. + * + * @param rxFrmCntr the RxFrmCntr to set as {@link int} + */ + public void setRxFrmCntr(int rxFrmCntr) { + this.rxFrmCntr = rxFrmCntr; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(136); + builder.append("ZstackUtilApsmeLinkKeyDataGetSrsp [status="); + builder.append(status); + builder.append(", secKey="); + builder.append(secKey); + builder.append(", txFrmCntr="); + builder.append(String.format("%08X", txFrmCntr)); + builder.append(", rxFrmCntr="); + builder.append(String.format("%08X", rxFrmCntr)); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilApsmeLinkKeyNvIdGetSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilApsmeLinkKeyNvIdGetSreq.java new file mode 100644 index 0000000000..27c9b68e24 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilApsmeLinkKeyNvIdGetSreq.java @@ -0,0 +1,78 @@ +/** + * 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.dongle.zstack.api.util; + +import com.zsmartsystems.zigbee.IeeeAddress; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command UTIL_APSME_LINK_KEY_NV_ID_GET. + *

+ * This command is a proxy call to the APSME_LinkKeyNvIdGet() function. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackUtilApsmeLinkKeyNvIdGetSreq extends ZstackFrameRequest { + + /** + * The extended address for which to get the link key NV Id. + */ + private IeeeAddress extAddr; + + /** + * Request constructor + */ + public ZstackUtilApsmeLinkKeyNvIdGetSreq() { + synchronousCommand = true; + } + + /** + * The extended address for which to get the link key NV Id. + * + * @return the current extAddr as {@link IeeeAddress} + */ + public IeeeAddress getExtAddr() { + return extAddr; + } + + /** + * The extended address for which to get the link key NV Id. + * + * @param extAddr the ExtAddr to set as {@link IeeeAddress} + */ + public void setExtAddr(IeeeAddress extAddr) { + this.extAddr = extAddr; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_UTIL) && (response.getReqCmd1() == 0x45)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_UTIL, 0x45); + + // Serialize the fields + serializer.serializeIeeeAddress(extAddr); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(61); + builder.append("ZstackUtilApsmeLinkKeyNvIdGetSreq [extAddr="); + builder.append(extAddr); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilApsmeLinkKeyNvIdGetSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilApsmeLinkKeyNvIdGetSrsp.java new file mode 100644 index 0000000000..e0f51b8f78 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilApsmeLinkKeyNvIdGetSrsp.java @@ -0,0 +1,94 @@ +/** + * 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.dongle.zstack.api.util; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command UTIL_APSME_LINK_KEY_NV_ID_GET. + *

+ * This command is a proxy call to the APSME_LinkKeyNvIdGet() function. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackUtilApsmeLinkKeyNvIdGetSrsp extends ZstackFrameResponse { + + /** + * The ZStatus_t returned by the proxy call to APSME_LinkKeyNVIdGet(). + */ + private ZstackResponseCode status; + + /** + * On success, link key NV ID. Otherwise 0xFFFF + */ + private int linkKeyNvId; + + /** + * Response and Handler constructor + */ + public ZstackUtilApsmeLinkKeyNvIdGetSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + linkKeyNvId = deserializer.deserializeUInt16(); + } + + /** + * The ZStatus_t returned by the proxy call to APSME_LinkKeyNVIdGet(). + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * The ZStatus_t returned by the proxy call to APSME_LinkKeyNVIdGet(). + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + /** + * On success, link key NV ID. Otherwise 0xFFFF + * + * @return the current linkKeyNvId as {@link int} + */ + public int getLinkKeyNvId() { + return linkKeyNvId; + } + + /** + * On success, link key NV ID. Otherwise 0xFFFF + * + * @param linkKeyNvId the LinkKeyNvId to set as {@link int} + */ + public void setLinkKeyNvId(int linkKeyNvId) { + this.linkKeyNvId = linkKeyNvId; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(86); + builder.append("ZstackUtilApsmeLinkKeyNvIdGetSrsp [status="); + builder.append(status); + builder.append(", linkKeyNvId="); + builder.append(linkKeyNvId); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilGetDeviceInfoSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilGetDeviceInfoSreq.java new file mode 100644 index 0000000000..90e2eac0b9 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilGetDeviceInfoSreq.java @@ -0,0 +1,49 @@ +/** + * 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.dongle.zstack.api.util; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command UTIL_GET_DEVICE_INFO. + *

+ * This command is used to retrieve the device info. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackUtilGetDeviceInfoSreq extends ZstackFrameRequest { + + /** + * Request constructor + */ + public ZstackUtilGetDeviceInfoSreq() { + synchronousCommand = true; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_UTIL) && (response.getReqCmd1() == 0x00)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_UTIL, 0x00); + + // Serialize the fields + return getPayload(); + } + + @Override + public String toString() { + return "ZstackUtilGetDeviceInfoSreq []"; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilGetDeviceInfoSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilGetDeviceInfoSrsp.java new file mode 100644 index 0000000000..8353cf4609 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilGetDeviceInfoSrsp.java @@ -0,0 +1,212 @@ +/** + * 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.dongle.zstack.api.util; + +import com.zsmartsystems.zigbee.IeeeAddress; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackZdoState; + +/** + * Class to implement the Z-Stack command UTIL_GET_DEVICE_INFO. + *

+ * This command is used to retrieve the device info. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackUtilGetDeviceInfoSrsp extends ZstackFrameResponse { + + /** + * Status is a one byte field and is either success(0) or fail(1). The fail status is returned if the address value in the command + * message was not within the valid range. + */ + private ZstackResponseCode status; + + /** + * IEEE address of the device. + */ + private IeeeAddress ieeeAddress; + + /** + * Short address of the device. + */ + private int shortAddr; + + /** + * Indicates device type, where bits 0 to 2 indicate the capability for the device to operate as a coordinator, router, or end + * device, respectively. + */ + private int deviceType; + + /** + * Indicates the state of the device. + */ + private ZstackZdoState deviceState; + + /** + * Array of 16-bits specifies the network address associated with the device. + */ + private int[] assocDevicesList; + + /** + * Response and Handler constructor + */ + public ZstackUtilGetDeviceInfoSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + ieeeAddress = deserializer.deserializeIeeeAddress(); + shortAddr = deserializer.deserializeUInt16(); + deviceType = deserializer.deserializeUInt8(); + deviceState = ZstackZdoState.valueOf(deserializer.deserializeUInt8()); + int numAssocDevices = deserializer.deserializeUInt8(); + assocDevicesList = deserializer.deserializeUInt16Array(numAssocDevices); + } + + /** + * Status is a one byte field and is either success(0) or fail(1). The fail status is returned if the address value in the command + * message was not within the valid range. + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * Status is a one byte field and is either success(0) or fail(1). The fail status is returned if the address value in the command + * message was not within the valid range. + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + /** + * IEEE address of the device. + * + * @return the current ieeeAddress as {@link IeeeAddress} + */ + public IeeeAddress getIeeeAddress() { + return ieeeAddress; + } + + /** + * IEEE address of the device. + * + * @param ieeeAddress the IeeeAddress to set as {@link IeeeAddress} + */ + public void setIeeeAddress(IeeeAddress ieeeAddress) { + this.ieeeAddress = ieeeAddress; + } + + /** + * Short address of the device. + * + * @return the current shortAddr as {@link int} + */ + public int getShortAddr() { + return shortAddr; + } + + /** + * Short address of the device. + * + * @param shortAddr the ShortAddr to set as {@link int} + */ + public void setShortAddr(int shortAddr) { + this.shortAddr = shortAddr; + } + + /** + * Indicates device type, where bits 0 to 2 indicate the capability for the device to operate as a coordinator, router, or end + * device, respectively. + * + * @return the current deviceType as {@link int} + */ + public int getDeviceType() { + return deviceType; + } + + /** + * Indicates device type, where bits 0 to 2 indicate the capability for the device to operate as a coordinator, router, or end + * device, respectively. + * + * @param deviceType the DeviceType to set as {@link int} + */ + public void setDeviceType(int deviceType) { + this.deviceType = deviceType; + } + + /** + * Indicates the state of the device. + * + * @return the current deviceState as {@link ZstackZdoState} + */ + public ZstackZdoState getDeviceState() { + return deviceState; + } + + /** + * Indicates the state of the device. + * + * @param deviceState the DeviceState to set as {@link ZstackZdoState} + */ + public void setDeviceState(ZstackZdoState deviceState) { + this.deviceState = deviceState; + } + + /** + * Array of 16-bits specifies the network address associated with the device. + * + * @return the current assocDevicesList as {@link int[]} + */ + public int[] getAssocDevicesList() { + return assocDevicesList; + } + + /** + * Array of 16-bits specifies the network address associated with the device. + * + * @param assocDevicesList the AssocDevicesList to set as {@link int[]} + */ + public void setAssocDevicesList(int[] assocDevicesList) { + this.assocDevicesList = assocDevicesList; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(205); + builder.append("ZstackUtilGetDeviceInfoSrsp [status="); + builder.append(status); + builder.append(", ieeeAddress="); + builder.append(ieeeAddress); + builder.append(", shortAddr="); + builder.append(String.format("%04X", shortAddr)); + builder.append(", deviceType="); + builder.append(deviceType); + builder.append(", deviceState="); + builder.append(deviceState); + builder.append(", assocDevicesList="); + for (int c = 0; c < assocDevicesList.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", assocDevicesList[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilGetNvInfoSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilGetNvInfoSreq.java new file mode 100644 index 0000000000..492250e6f9 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilGetNvInfoSreq.java @@ -0,0 +1,49 @@ +/** + * 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.dongle.zstack.api.util; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command UTIL_GET_NV_INFO. + *

+ * This command is used to read a block of parameters from non-volatile storage of the target device. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackUtilGetNvInfoSreq extends ZstackFrameRequest { + + /** + * Request constructor + */ + public ZstackUtilGetNvInfoSreq() { + synchronousCommand = true; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_UTIL) && (response.getReqCmd1() == 0x01)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_UTIL, 0x01); + + // Serialize the fields + return getPayload(); + } + + @Override + public String toString() { + return "ZstackUtilGetNvInfoSreq []"; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilGetNvInfoSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilGetNvInfoSrsp.java new file mode 100644 index 0000000000..d20e973c5b --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilGetNvInfoSrsp.java @@ -0,0 +1,205 @@ +/** + * 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.dongle.zstack.api.util; + +import com.zsmartsystems.zigbee.IeeeAddress; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.security.ZigBeeKey; + +/** + * Class to implement the Z-Stack command UTIL_GET_NV_INFO. + *

+ * This command is used to read a block of parameters from non-volatile storage of the target device. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackUtilGetNvInfoSrsp extends ZstackFrameResponse { + + /** + * A value of zero indicates success. Failure is indicated by a non-zero value, representing a bit mask of each item that failed to be + * retrieved from NV memory. Bit0 is used for the first item (IEEEAddress), bit1 for the second item (ScanChannels), and so forth. + * Data values for failed items are returned as one or more bytes of 0xFF, the typical value read from erased NV memory. + */ + private int status; + + /** + * IEEE address of the device. + */ + private IeeeAddress ieeeAddress; + + /** + * This represents a bit-mask of channels to be scanned when starting the device. + */ + private int scanChannels; + + /** + * Specifies the Pan Id to start or join. Set to 0xFFFF to select a PAN after scanning. + */ + private int panId; + + /** + * This specifies the network messaging security level, zero disables security. + */ + private int securityLevel; + + /** + * This specifies the pre-configured security key. + */ + private ZigBeeKey preConfigKey; + + /** + * Response and Handler constructor + */ + public ZstackUtilGetNvInfoSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = deserializer.deserializeUInt8(); + ieeeAddress = deserializer.deserializeIeeeAddress(); + scanChannels = deserializer.deserializeUInt32(); + panId = deserializer.deserializeUInt16(); + securityLevel = deserializer.deserializeUInt8(); + preConfigKey = deserializer.deserializeZigBeeKey(); + } + + /** + * A value of zero indicates success. Failure is indicated by a non-zero value, representing a bit mask of each item that failed to be + * retrieved from NV memory. Bit0 is used for the first item (IEEEAddress), bit1 for the second item (ScanChannels), and so forth. + * Data values for failed items are returned as one or more bytes of 0xFF, the typical value read from erased NV memory. + * + * @return the current status as {@link int} + */ + public int getStatus() { + return status; + } + + /** + * A value of zero indicates success. Failure is indicated by a non-zero value, representing a bit mask of each item that failed to be + * retrieved from NV memory. Bit0 is used for the first item (IEEEAddress), bit1 for the second item (ScanChannels), and so forth. + * Data values for failed items are returned as one or more bytes of 0xFF, the typical value read from erased NV memory. + * + * @param status the Status to set as {@link int} + */ + public void setStatus(int status) { + this.status = status; + } + + /** + * IEEE address of the device. + * + * @return the current ieeeAddress as {@link IeeeAddress} + */ + public IeeeAddress getIeeeAddress() { + return ieeeAddress; + } + + /** + * IEEE address of the device. + * + * @param ieeeAddress the IeeeAddress to set as {@link IeeeAddress} + */ + public void setIeeeAddress(IeeeAddress ieeeAddress) { + this.ieeeAddress = ieeeAddress; + } + + /** + * This represents a bit-mask of channels to be scanned when starting the device. + * + * @return the current scanChannels as {@link int} + */ + public int getScanChannels() { + return scanChannels; + } + + /** + * This represents a bit-mask of channels to be scanned when starting the device. + * + * @param scanChannels the ScanChannels to set as {@link int} + */ + public void setScanChannels(int scanChannels) { + this.scanChannels = scanChannels; + } + + /** + * Specifies the Pan Id to start or join. Set to 0xFFFF to select a PAN after scanning. + * + * @return the current panId as {@link int} + */ + public int getPanId() { + return panId; + } + + /** + * Specifies the Pan Id to start or join. Set to 0xFFFF to select a PAN after scanning. + * + * @param panId the PanId to set as {@link int} + */ + public void setPanId(int panId) { + this.panId = panId; + } + + /** + * This specifies the network messaging security level, zero disables security. + * + * @return the current securityLevel as {@link int} + */ + public int getSecurityLevel() { + return securityLevel; + } + + /** + * This specifies the network messaging security level, zero disables security. + * + * @param securityLevel the SecurityLevel to set as {@link int} + */ + public void setSecurityLevel(int securityLevel) { + this.securityLevel = securityLevel; + } + + /** + * This specifies the pre-configured security key. + * + * @return the current preConfigKey as {@link ZigBeeKey} + */ + public ZigBeeKey getPreConfigKey() { + return preConfigKey; + } + + /** + * This specifies the pre-configured security key. + * + * @param preConfigKey the PreConfigKey to set as {@link ZigBeeKey} + */ + public void setPreConfigKey(ZigBeeKey preConfigKey) { + this.preConfigKey = preConfigKey; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(176); + builder.append("ZstackUtilGetNvInfoSrsp [status="); + builder.append(status); + builder.append(", ieeeAddress="); + builder.append(ieeeAddress); + builder.append(", scanChannels="); + builder.append(scanChannels); + builder.append(", panId="); + builder.append(String.format("%04X", panId)); + builder.append(", securityLevel="); + builder.append(securityLevel); + builder.append(", preConfigKey="); + builder.append(preConfigKey); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilLedControlSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilLedControlSreq.java new file mode 100644 index 0000000000..214582fc99 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilLedControlSreq.java @@ -0,0 +1,103 @@ +/** + * 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.dongle.zstack.api.util; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command UTIL_LED_CONTROL. + *

+ * This command is used by the tester to control the LEDs on the board. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackUtilLedControlSreq extends ZstackFrameRequest { + + /** + * The LED number. + */ + private int ledId; + + /** + * 0: OFF, 1: ON. + */ + private boolean mode; + + /** + * Request constructor + */ + public ZstackUtilLedControlSreq() { + synchronousCommand = true; + } + + /** + * The LED number. + * + * @return the current ledId as {@link int} + */ + public int getLedId() { + return ledId; + } + + /** + * The LED number. + * + * @param ledId the LedId to set as {@link int} + */ + public void setLedId(int ledId) { + this.ledId = ledId; + } + + /** + * 0: OFF, 1: ON. + * + * @return the current mode as {@link boolean} + */ + public boolean getMode() { + return mode; + } + + /** + * 0: OFF, 1: ON. + * + * @param mode the Mode to set as {@link boolean} + */ + public void setMode(boolean mode) { + this.mode = mode; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_UTIL) && (response.getReqCmd1() == 0x09)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_UTIL, 0x09); + + // Serialize the fields + serializer.serializeUInt8(ledId); + serializer.serializeBoolean(mode); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(77); + builder.append("ZstackUtilLedControlSreq [ledId="); + builder.append(ledId); + builder.append(", mode="); + builder.append(mode); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilLedControlSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilLedControlSrsp.java new file mode 100644 index 0000000000..17c511ab1c --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilLedControlSrsp.java @@ -0,0 +1,68 @@ +/** + * 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.dongle.zstack.api.util; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command UTIL_LED_CONTROL. + *

+ * This command is used by the tester to control the LEDs on the board. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackUtilLedControlSrsp extends ZstackFrameResponse { + + /** + * Status is either Success (0) or Failure (1). + */ + private ZstackResponseCode status; + + /** + * Response and Handler constructor + */ + public ZstackUtilLedControlSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + } + + /** + * Status is either Success (0) or Failure (1). + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * Status is either Success (0) or Failure (1). + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(52); + builder.append("ZstackUtilLedControlSrsp [status="); + builder.append(status); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilSetChannelsSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilSetChannelsSreq.java new file mode 100644 index 0000000000..eb25e1dfb7 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilSetChannelsSreq.java @@ -0,0 +1,78 @@ +/** + * 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.dongle.zstack.api.util; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command UTIL_SET_CHANNELS. + *

+ * This command is used to store a channel select bit-mask into Non-Volatile memory to be used the next time the target device + * resets. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackUtilSetChannelsSreq extends ZstackFrameRequest { + + /** + * A bit-mask representing the channel(s) to scan the next time the target device resets. + */ + private int channels; + + /** + * Request constructor + */ + public ZstackUtilSetChannelsSreq() { + synchronousCommand = true; + } + + /** + * A bit-mask representing the channel(s) to scan the next time the target device resets. + * + * @return the current channels as {@link int} + */ + public int getChannels() { + return channels; + } + + /** + * A bit-mask representing the channel(s) to scan the next time the target device resets. + * + * @param channels the Channels to set as {@link int} + */ + public void setChannels(int channels) { + this.channels = channels; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_UTIL) && (response.getReqCmd1() == 0x03)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_UTIL, 0x03); + + // Serialize the fields + serializer.serializeUInt32(channels); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(53); + builder.append("ZstackUtilSetChannelsSreq [channels="); + builder.append(channels); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilSetChannelsSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilSetChannelsSrsp.java new file mode 100644 index 0000000000..0655c5176e --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilSetChannelsSrsp.java @@ -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.dongle.zstack.api.util; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command UTIL_SET_CHANNELS. + *

+ * This command is used to store a channel select bit-mask into Non-Volatile memory to be used the next time the target device + * resets. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackUtilSetChannelsSrsp extends ZstackFrameResponse { + + /** + * Status is either Success (0) or Failure (1). + */ + private ZstackResponseCode status; + + /** + * Response and Handler constructor + */ + public ZstackUtilSetChannelsSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + } + + /** + * Status is either Success (0) or Failure (1). + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * Status is either Success (0) or Failure (1). + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(53); + builder.append("ZstackUtilSetChannelsSrsp [status="); + builder.append(status); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilSetPanidSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilSetPanidSreq.java new file mode 100644 index 0000000000..608fde1050 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilSetPanidSreq.java @@ -0,0 +1,77 @@ +/** + * 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.dongle.zstack.api.util; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command UTIL_SET_PANID. + *

+ * Store a PanId value into Non-Volatile memory to be used the next time the target device resets. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackUtilSetPanidSreq extends ZstackFrameRequest { + + /** + * PanId that will be set. + */ + private int panId; + + /** + * Request constructor + */ + public ZstackUtilSetPanidSreq() { + synchronousCommand = true; + } + + /** + * PanId that will be set. + * + * @return the current panId as {@link int} + */ + public int getPanId() { + return panId; + } + + /** + * PanId that will be set. + * + * @param panId the PanId to set as {@link int} + */ + public void setPanId(int panId) { + this.panId = panId; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_UTIL) && (response.getReqCmd1() == 0x02)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_UTIL, 0x02); + + // Serialize the fields + serializer.serializeUInt16(panId); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(50); + builder.append("ZstackUtilSetPanidSreq [panId="); + builder.append(String.format("%04X", panId)); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilSetPanidSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilSetPanidSrsp.java new file mode 100644 index 0000000000..d8da673aa6 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilSetPanidSrsp.java @@ -0,0 +1,68 @@ +/** + * 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.dongle.zstack.api.util; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command UTIL_SET_PANID. + *

+ * Store a PanId value into Non-Volatile memory to be used the next time the target device resets. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackUtilSetPanidSrsp extends ZstackFrameResponse { + + /** + * Status is either Success (0) or Failure (1). + */ + private ZstackResponseCode status; + + /** + * Response and Handler constructor + */ + public ZstackUtilSetPanidSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + } + + /** + * Status is either Success (0) or Failure (1). + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * Status is either Success (0) or Failure (1). + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(50); + builder.append("ZstackUtilSetPanidSrsp [status="); + builder.append(status); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilSetPrecfgkeySreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilSetPrecfgkeySreq.java new file mode 100644 index 0000000000..2623dcc139 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilSetPrecfgkeySreq.java @@ -0,0 +1,79 @@ +/** + * 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.dongle.zstack.api.util; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; +import com.zsmartsystems.zigbee.security.ZigBeeKey; + +/** + * Class to implement the Z-Stack command UTIL_SET_PRECFGKEY. + *

+ * This command is used to store a pre-configured key array into Non-Volatile memory to be used the next time the target device + * resets. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackUtilSetPrecfgkeySreq extends ZstackFrameRequest { + + /** + * An array representing the pre-configured key to use the next time the target device resets. + */ + private ZigBeeKey preCfgKey; + + /** + * Request constructor + */ + public ZstackUtilSetPrecfgkeySreq() { + synchronousCommand = true; + } + + /** + * An array representing the pre-configured key to use the next time the target device resets. + * + * @return the current preCfgKey as {@link ZigBeeKey} + */ + public ZigBeeKey getPreCfgKey() { + return preCfgKey; + } + + /** + * An array representing the pre-configured key to use the next time the target device resets. + * + * @param preCfgKey the PreCfgKey to set as {@link ZigBeeKey} + */ + public void setPreCfgKey(ZigBeeKey preCfgKey) { + this.preCfgKey = preCfgKey; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_UTIL) && (response.getReqCmd1() == 0x05)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_UTIL, 0x05); + + // Serialize the fields + serializer.serializeZigBeeKey(preCfgKey); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(54); + builder.append("ZstackUtilSetPrecfgkeySreq [preCfgKey="); + builder.append(preCfgKey); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilSetPrecfgkeySrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilSetPrecfgkeySrsp.java new file mode 100644 index 0000000000..50b489517b --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilSetPrecfgkeySrsp.java @@ -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.dongle.zstack.api.util; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command UTIL_SET_PRECFGKEY. + *

+ * This command is used to store a pre-configured key array into Non-Volatile memory to be used the next time the target device + * resets. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackUtilSetPrecfgkeySrsp extends ZstackFrameResponse { + + /** + * Status is either Success (0) or Failure (1). + */ + private ZstackResponseCode status; + + /** + * Response and Handler constructor + */ + public ZstackUtilSetPrecfgkeySrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + } + + /** + * Status is either Success (0) or Failure (1). + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * Status is either Success (0) or Failure (1). + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(54); + builder.append("ZstackUtilSetPrecfgkeySrsp [status="); + builder.append(status); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilSetSeclevelSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilSetSeclevelSreq.java new file mode 100644 index 0000000000..417f4d0cd5 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilSetSeclevelSreq.java @@ -0,0 +1,78 @@ +/** + * 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.dongle.zstack.api.util; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command UTIL_SET_SECLEVEL. + *

+ * This command is used to store a channel select bit-mask into Non-Volatile memory to be used the next time the target device + * resets. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackUtilSetSeclevelSreq extends ZstackFrameRequest { + + /** + * Security level to use the next time the target device resets. Zero is used to disable security. + */ + private int secLevel; + + /** + * Request constructor + */ + public ZstackUtilSetSeclevelSreq() { + synchronousCommand = true; + } + + /** + * Security level to use the next time the target device resets. Zero is used to disable security. + * + * @return the current secLevel as {@link int} + */ + public int getSecLevel() { + return secLevel; + } + + /** + * Security level to use the next time the target device resets. Zero is used to disable security. + * + * @param secLevel the SecLevel to set as {@link int} + */ + public void setSecLevel(int secLevel) { + this.secLevel = secLevel; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_UTIL) && (response.getReqCmd1() == 0x04)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_UTIL, 0x04); + + // Serialize the fields + serializer.serializeUInt8(secLevel); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(53); + builder.append("ZstackUtilSetSeclevelSreq [secLevel="); + builder.append(secLevel); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilSetSeclevelSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilSetSeclevelSrsp.java new file mode 100644 index 0000000000..39e8f10e60 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilSetSeclevelSrsp.java @@ -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.dongle.zstack.api.util; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command UTIL_SET_SECLEVEL. + *

+ * This command is used to store a channel select bit-mask into Non-Volatile memory to be used the next time the target device + * resets. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackUtilSetSeclevelSrsp extends ZstackFrameResponse { + + /** + * Status is either Success (0) or Failure (1). + */ + private ZstackResponseCode status; + + /** + * Response and Handler constructor + */ + public ZstackUtilSetSeclevelSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + } + + /** + * Status is either Success (0) or Failure (1). + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * Status is either Success (0) or Failure (1). + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(53); + builder.append("ZstackUtilSetSeclevelSrsp [status="); + builder.append(status); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoGetLinkKeySreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoGetLinkKeySreq.java new file mode 100644 index 0000000000..830a75229e --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoGetLinkKeySreq.java @@ -0,0 +1,78 @@ +/** + * 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.dongle.zstack.api.zdo; + +import com.zsmartsystems.zigbee.IeeeAddress; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command ZDO_GET_LINK_KEY. + *

+ * This command retrieves the application link key of a given device. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackZdoGetLinkKeySreq extends ZstackFrameRequest { + + /** + * Specifies the IEEE address of the pair device of the link key + */ + private IeeeAddress ieeeAddr; + + /** + * Request constructor + */ + public ZstackZdoGetLinkKeySreq() { + synchronousCommand = true; + } + + /** + * Specifies the IEEE address of the pair device of the link key + * + * @return the current ieeeAddr as {@link IeeeAddress} + */ + public IeeeAddress getIeeeAddr() { + return ieeeAddr; + } + + /** + * Specifies the IEEE address of the pair device of the link key + * + * @param ieeeAddr the IeeeAddr to set as {@link IeeeAddress} + */ + public void setIeeeAddr(IeeeAddress ieeeAddr) { + this.ieeeAddr = ieeeAddr; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_ZDO) && (response.getReqCmd1() == 0x25)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_ZDO, 0x25); + + // Serialize the fields + serializer.serializeIeeeAddress(ieeeAddr); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(51); + builder.append("ZstackZdoGetLinkKeySreq [ieeeAddr="); + builder.append(ieeeAddr); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoGetLinkKeySrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoGetLinkKeySrsp.java new file mode 100644 index 0000000000..3ed21a4b50 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoGetLinkKeySrsp.java @@ -0,0 +1,122 @@ +/** + * 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.dongle.zstack.api.zdo; + +import com.zsmartsystems.zigbee.IeeeAddress; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; +import com.zsmartsystems.zigbee.security.ZigBeeKey; + +/** + * Class to implement the Z-Stack command ZDO_GET_LINK_KEY. + *

+ * This command retrieves the application link key of a given device. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackZdoGetLinkKeySrsp extends ZstackFrameResponse { + + /** + * 0x00 – Success. 0xC8 – Unknown device. + */ + private ZstackResponseCode status; + + /** + * Specifies the IEEE address of the pair device of the link key + */ + private IeeeAddress ieeeAddr; + + /** + * Link key data of the device + */ + private ZigBeeKey linkKeyData; + + /** + * Response and Handler constructor + */ + public ZstackZdoGetLinkKeySrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + ieeeAddr = deserializer.deserializeIeeeAddress(); + linkKeyData = deserializer.deserializeZigBeeKey(); + } + + /** + * 0x00 – Success. 0xC8 – Unknown device. + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * 0x00 – Success. 0xC8 – Unknown device. + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + /** + * Specifies the IEEE address of the pair device of the link key + * + * @return the current ieeeAddr as {@link IeeeAddress} + */ + public IeeeAddress getIeeeAddr() { + return ieeeAddr; + } + + /** + * Specifies the IEEE address of the pair device of the link key + * + * @param ieeeAddr the IeeeAddr to set as {@link IeeeAddress} + */ + public void setIeeeAddr(IeeeAddress ieeeAddr) { + this.ieeeAddr = ieeeAddr; + } + + /** + * Link key data of the device + * + * @return the current linkKeyData as {@link ZigBeeKey} + */ + public ZigBeeKey getLinkKeyData() { + return linkKeyData; + } + + /** + * Link key data of the device + * + * @param linkKeyData the LinkKeyData to set as {@link ZigBeeKey} + */ + public void setLinkKeyData(ZigBeeKey linkKeyData) { + this.linkKeyData = linkKeyData; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(101); + builder.append("ZstackZdoGetLinkKeySrsp [status="); + builder.append(status); + builder.append(", ieeeAddr="); + builder.append(ieeeAddr); + builder.append(", linkKeyData="); + builder.append(linkKeyData); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoLeaveIndAreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoLeaveIndAreq.java new file mode 100644 index 0000000000..d2335174dd --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoLeaveIndAreq.java @@ -0,0 +1,170 @@ +/** + * 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.dongle.zstack.api.zdo; + +import com.zsmartsystems.zigbee.IeeeAddress; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; + +/** + * Class to implement the Z-Stack command ZDO_LEAVE_IND. + *

+ * This message is an indication to inform the host of a device leaving the network. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackZdoLeaveIndAreq extends ZstackFrameResponse { + + /** + * Short address (LSB-MSB) of the source of the leave indication. + */ + private int srcAddr; + + /** + * Extended address (LSB-MSB) of the source of the leave indication. + */ + private IeeeAddress extAddr; + + /** + * Boolean, TRUE = request, FALSE = indication. + */ + private boolean request; + + /** + * Boolean, TRUE = remove children. + */ + private boolean remove; + + /** + * Boolean, TRUE = rejoin. + */ + private boolean rejoin; + + /** + * Response and Handler constructor + */ + public ZstackZdoLeaveIndAreq(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + // Deserialize the fields + srcAddr = deserializer.deserializeUInt16(); + extAddr = deserializer.deserializeIeeeAddress(); + request = deserializer.deserializeBoolean(); + remove = deserializer.deserializeBoolean(); + rejoin = deserializer.deserializeBoolean(); + } + + /** + * Short address (LSB-MSB) of the source of the leave indication. + * + * @return the current srcAddr as {@link int} + */ + public int getSrcAddr() { + return srcAddr; + } + + /** + * Short address (LSB-MSB) of the source of the leave indication. + * + * @param srcAddr the SrcAddr to set as {@link int} + */ + public void setSrcAddr(int srcAddr) { + this.srcAddr = srcAddr; + } + + /** + * Extended address (LSB-MSB) of the source of the leave indication. + * + * @return the current extAddr as {@link IeeeAddress} + */ + public IeeeAddress getExtAddr() { + return extAddr; + } + + /** + * Extended address (LSB-MSB) of the source of the leave indication. + * + * @param extAddr the ExtAddr to set as {@link IeeeAddress} + */ + public void setExtAddr(IeeeAddress extAddr) { + this.extAddr = extAddr; + } + + /** + * Boolean, TRUE = request, FALSE = indication. + * + * @return the current request as {@link boolean} + */ + public boolean getRequest() { + return request; + } + + /** + * Boolean, TRUE = request, FALSE = indication. + * + * @param request the Request to set as {@link boolean} + */ + public void setRequest(boolean request) { + this.request = request; + } + + /** + * Boolean, TRUE = remove children. + * + * @return the current remove as {@link boolean} + */ + public boolean getRemove() { + return remove; + } + + /** + * Boolean, TRUE = remove children. + * + * @param remove the Remove to set as {@link boolean} + */ + public void setRemove(boolean remove) { + this.remove = remove; + } + + /** + * Boolean, TRUE = rejoin. + * + * @return the current rejoin as {@link boolean} + */ + public boolean getRejoin() { + return rejoin; + } + + /** + * Boolean, TRUE = rejoin. + * + * @param rejoin the Rejoin to set as {@link boolean} + */ + public void setRejoin(boolean rejoin) { + this.rejoin = rejoin; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(149); + builder.append("ZstackZdoLeaveIndAreq [srcAddr="); + builder.append(String.format("%04X", srcAddr)); + builder.append(", extAddr="); + builder.append(extAddr); + builder.append(", request="); + builder.append(request); + builder.append(", remove="); + builder.append(remove); + builder.append(", rejoin="); + builder.append(rejoin); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoMsgCbIncomingAreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoMsgCbIncomingAreq.java new file mode 100644 index 0000000000..bcf9fc7bd1 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoMsgCbIncomingAreq.java @@ -0,0 +1,226 @@ +/** + * 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.dongle.zstack.api.zdo; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; + +/** + * Class to implement the Z-Stack command ZDO_MSG_CB_INCOMING. + *

+ * This message is a ZDO callback for a Cluster Id that the host requested to receive with a ZDO_ MSG_CB_REGISTER request. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackZdoMsgCbIncomingAreq extends ZstackFrameResponse { + + /** + * Short address (LSB-MSB) of the source of the ZDO message. + */ + private int srcAddr; + + /** + * This field indicates whether or not this ZDO message was broadcast. + */ + private boolean wasBroadcast; + + /** + * The ZDO Cluster Id of this message. + */ + private int clusterId; + + /** + * N/A – not used. + */ + private boolean securityUse; + + /** + * The sequence number of this ZDO message. + */ + private int seqNumber; + + /** + * The MAC destination short address (LSB-MSB) of the ZDO message. + */ + private int dstAddr; + + /** + * The data that corresponds to the Cluster Id of the message + */ + private int[] data; + + /** + * Response and Handler constructor + */ + public ZstackZdoMsgCbIncomingAreq(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + // Deserialize the fields + srcAddr = deserializer.deserializeUInt16(); + wasBroadcast = deserializer.deserializeBoolean(); + clusterId = deserializer.deserializeUInt16(); + securityUse = deserializer.deserializeBoolean(); + seqNumber = deserializer.deserializeUInt8(); + dstAddr = deserializer.deserializeUInt16(); + data = deserializer.deserializeUInt8Array(); + } + + /** + * Short address (LSB-MSB) of the source of the ZDO message. + * + * @return the current srcAddr as {@link int} + */ + public int getSrcAddr() { + return srcAddr; + } + + /** + * Short address (LSB-MSB) of the source of the ZDO message. + * + * @param srcAddr the SrcAddr to set as {@link int} + */ + public void setSrcAddr(int srcAddr) { + this.srcAddr = srcAddr; + } + + /** + * This field indicates whether or not this ZDO message was broadcast. + * + * @return the current wasBroadcast as {@link boolean} + */ + public boolean getWasBroadcast() { + return wasBroadcast; + } + + /** + * This field indicates whether or not this ZDO message was broadcast. + * + * @param wasBroadcast the WasBroadcast to set as {@link boolean} + */ + public void setWasBroadcast(boolean wasBroadcast) { + this.wasBroadcast = wasBroadcast; + } + + /** + * The ZDO Cluster Id of this message. + * + * @return the current clusterId as {@link int} + */ + public int getClusterId() { + return clusterId; + } + + /** + * The ZDO Cluster Id of this message. + * + * @param clusterId the ClusterId to set as {@link int} + */ + public void setClusterId(int clusterId) { + this.clusterId = clusterId; + } + + /** + * N/A – not used. + * + * @return the current securityUse as {@link boolean} + */ + public boolean getSecurityUse() { + return securityUse; + } + + /** + * N/A – not used. + * + * @param securityUse the SecurityUse to set as {@link boolean} + */ + public void setSecurityUse(boolean securityUse) { + this.securityUse = securityUse; + } + + /** + * The sequence number of this ZDO message. + * + * @return the current seqNumber as {@link int} + */ + public int getSeqNumber() { + return seqNumber; + } + + /** + * The sequence number of this ZDO message. + * + * @param seqNumber the SeqNumber to set as {@link int} + */ + public void setSeqNumber(int seqNumber) { + this.seqNumber = seqNumber; + } + + /** + * The MAC destination short address (LSB-MSB) of the ZDO message. + * + * @return the current dstAddr as {@link int} + */ + public int getDstAddr() { + return dstAddr; + } + + /** + * The MAC destination short address (LSB-MSB) of the ZDO message. + * + * @param dstAddr the DstAddr to set as {@link int} + */ + public void setDstAddr(int dstAddr) { + this.dstAddr = dstAddr; + } + + /** + * The data that corresponds to the Cluster Id of the message + * + * @return the current data as {@link int[]} + */ + public int[] getData() { + return data; + } + + /** + * The data that corresponds to the Cluster Id of the message + * + * @param data the Data to set as {@link int[]} + */ + public void setData(int[] data) { + this.data = data; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(204); + builder.append("ZstackZdoMsgCbIncomingAreq [srcAddr="); + builder.append(String.format("%04X", srcAddr)); + builder.append(", wasBroadcast="); + builder.append(wasBroadcast); + builder.append(", clusterId="); + builder.append(String.format("%04X", clusterId)); + builder.append(", securityUse="); + builder.append(securityUse); + builder.append(", seqNumber="); + builder.append(String.format("%02X", seqNumber)); + builder.append(", dstAddr="); + builder.append(String.format("%04X", dstAddr)); + builder.append(", data="); + for (int c = 0; c < data.length; c++) { + if (c > 0) { + builder.append(' '); + } + builder.append(String.format("%02X", data[c])); + } + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoMsgCbRegisterSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoMsgCbRegisterSreq.java new file mode 100644 index 0000000000..0807e2662c --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoMsgCbRegisterSreq.java @@ -0,0 +1,77 @@ +/** + * 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.dongle.zstack.api.zdo; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command ZDO_MSG_CB_REGISTER. + *

+ * This command registers for a ZDO callback. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackZdoMsgCbRegisterSreq extends ZstackFrameRequest { + + /** + * Specifies the ZDO Cluster Id for which to receive a ZDO callback. + */ + private int clusterId; + + /** + * Request constructor + */ + public ZstackZdoMsgCbRegisterSreq() { + synchronousCommand = true; + } + + /** + * Specifies the ZDO Cluster Id for which to receive a ZDO callback. + * + * @return the current clusterId as {@link int} + */ + public int getClusterId() { + return clusterId; + } + + /** + * Specifies the ZDO Cluster Id for which to receive a ZDO callback. + * + * @param clusterId the ClusterId to set as {@link int} + */ + public void setClusterId(int clusterId) { + this.clusterId = clusterId; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_ZDO) && (response.getReqCmd1() == 0x3E)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_ZDO, 0x3E); + + // Serialize the fields + serializer.serializeUInt16(clusterId); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(54); + builder.append("ZstackZdoMsgCbRegisterSreq [clusterId="); + builder.append(String.format("%04X", clusterId)); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoMsgCbRegisterSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoMsgCbRegisterSrsp.java new file mode 100644 index 0000000000..a092446b13 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoMsgCbRegisterSrsp.java @@ -0,0 +1,68 @@ +/** + * 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.dongle.zstack.api.zdo; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command ZDO_MSG_CB_REGISTER. + *

+ * This command registers for a ZDO callback. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackZdoMsgCbRegisterSrsp extends ZstackFrameResponse { + + /** + * 0x00 – Success. + */ + private ZstackResponseCode status; + + /** + * Response and Handler constructor + */ + public ZstackZdoMsgCbRegisterSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + } + + /** + * 0x00 – Success. + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * 0x00 – Success. + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(54); + builder.append("ZstackZdoMsgCbRegisterSrsp [status="); + builder.append(status); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoNwkDiscoveryReqSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoNwkDiscoveryReqSreq.java new file mode 100644 index 0000000000..5a2106eb18 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoNwkDiscoveryReqSreq.java @@ -0,0 +1,103 @@ +/** + * 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.dongle.zstack.api.zdo; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command ZDO_NWK_DISCOVERY_REQ. + *

+ * This command is used to initiate a network discovery (active scan). + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackZdoNwkDiscoveryReqSreq extends ZstackFrameRequest { + + /** + * Bit mask for channels to scan. + */ + private int scanChannels; + + /** + * A value used to calculate the length of time to spend scanning each channel + */ + private int scanDuration; + + /** + * Request constructor + */ + public ZstackZdoNwkDiscoveryReqSreq() { + synchronousCommand = true; + } + + /** + * Bit mask for channels to scan. + * + * @return the current scanChannels as {@link int} + */ + public int getScanChannels() { + return scanChannels; + } + + /** + * Bit mask for channels to scan. + * + * @param scanChannels the ScanChannels to set as {@link int} + */ + public void setScanChannels(int scanChannels) { + this.scanChannels = scanChannels; + } + + /** + * A value used to calculate the length of time to spend scanning each channel + * + * @return the current scanDuration as {@link int} + */ + public int getScanDuration() { + return scanDuration; + } + + /** + * A value used to calculate the length of time to spend scanning each channel + * + * @param scanDuration the ScanDuration to set as {@link int} + */ + public void setScanDuration(int scanDuration) { + this.scanDuration = scanDuration; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_ZDO) && (response.getReqCmd1() == 0x26)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_ZDO, 0x26); + + // Serialize the fields + serializer.serializeUInt32(scanChannels); + serializer.serializeUInt8(scanDuration); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(81); + builder.append("ZstackZdoNwkDiscoveryReqSreq [scanChannels="); + builder.append(scanChannels); + builder.append(", scanDuration="); + builder.append(scanDuration); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoNwkDiscoveryReqSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoNwkDiscoveryReqSrsp.java new file mode 100644 index 0000000000..0375e74602 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoNwkDiscoveryReqSrsp.java @@ -0,0 +1,77 @@ +/** + * 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.dongle.zstack.api.zdo; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command ZDO_NWK_DISCOVERY_REQ. + *

+ * This command is used to initiate a network discovery (active scan). + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackZdoNwkDiscoveryReqSrsp extends ZstackFrameResponse { + + /** + * Success (0) Invalid_Parameter (0x02). ZNwkInvalidRequest (0xC2) if the device is already on a network. User + * ZDO_MGMT_NWK_DISC_REQ instead. Or leave the network first, then initiate the request. MAC_SCAN_IN_PROGRESS (0xFC) if a + * channel change is in progress. MAC_NO_RESOURCE (0x1A) if the operation could not complete because no memory resource were + * available. + */ + private ZstackResponseCode status; + + /** + * Response and Handler constructor + */ + public ZstackZdoNwkDiscoveryReqSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + } + + /** + * Success (0) Invalid_Parameter (0x02). ZNwkInvalidRequest (0xC2) if the device is already on a network. User + * ZDO_MGMT_NWK_DISC_REQ instead. Or leave the network first, then initiate the request. MAC_SCAN_IN_PROGRESS (0xFC) if a + * channel change is in progress. MAC_NO_RESOURCE (0x1A) if the operation could not complete because no memory resource were + * available. + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * Success (0) Invalid_Parameter (0x02). ZNwkInvalidRequest (0xC2) if the device is already on a network. User + * ZDO_MGMT_NWK_DISC_REQ instead. Or leave the network first, then initiate the request. MAC_SCAN_IN_PROGRESS (0xFC) if a + * channel change is in progress. MAC_NO_RESOURCE (0x1A) if the operation could not complete because no memory resource were + * available. + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(56); + builder.append("ZstackZdoNwkDiscoveryReqSrsp [status="); + builder.append(status); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoRemoveLinkKeySreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoRemoveLinkKeySreq.java new file mode 100644 index 0000000000..34e5da8b74 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoRemoveLinkKeySreq.java @@ -0,0 +1,78 @@ +/** + * 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.dongle.zstack.api.zdo; + +import com.zsmartsystems.zigbee.IeeeAddress; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command ZDO_REMOVE_LINK_KEY. + *

+ * This command removes the application link key of a given device. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackZdoRemoveLinkKeySreq extends ZstackFrameRequest { + + /** + * Specifies the IEEE address of the pair device of the link key + */ + private IeeeAddress ieeeAddr; + + /** + * Request constructor + */ + public ZstackZdoRemoveLinkKeySreq() { + synchronousCommand = true; + } + + /** + * Specifies the IEEE address of the pair device of the link key + * + * @return the current ieeeAddr as {@link IeeeAddress} + */ + public IeeeAddress getIeeeAddr() { + return ieeeAddr; + } + + /** + * Specifies the IEEE address of the pair device of the link key + * + * @param ieeeAddr the IeeeAddr to set as {@link IeeeAddress} + */ + public void setIeeeAddr(IeeeAddress ieeeAddr) { + this.ieeeAddr = ieeeAddr; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_ZDO) && (response.getReqCmd1() == 0x24)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_ZDO, 0x24); + + // Serialize the fields + serializer.serializeIeeeAddress(ieeeAddr); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(54); + builder.append("ZstackZdoRemoveLinkKeySreq [ieeeAddr="); + builder.append(ieeeAddr); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoRemoveLinkKeySrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoRemoveLinkKeySrsp.java new file mode 100644 index 0000000000..e99f6c0d6b --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoRemoveLinkKeySrsp.java @@ -0,0 +1,68 @@ +/** + * 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.dongle.zstack.api.zdo; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command ZDO_REMOVE_LINK_KEY. + *

+ * This command removes the application link key of a given device. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackZdoRemoveLinkKeySrsp extends ZstackFrameResponse { + + /** + * 0x00 – Success. 0xC8 – Unknown device. + */ + private ZstackResponseCode status; + + /** + * Response and Handler constructor + */ + public ZstackZdoRemoveLinkKeySrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + } + + /** + * 0x00 – Success. 0xC8 – Unknown device. + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * 0x00 – Success. 0xC8 – Unknown device. + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(54); + builder.append("ZstackZdoRemoveLinkKeySrsp [status="); + builder.append(status); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoSetLinkKeySreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoSetLinkKeySreq.java new file mode 100644 index 0000000000..0bbc3018fc --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoSetLinkKeySreq.java @@ -0,0 +1,131 @@ +/** + * 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.dongle.zstack.api.zdo; + +import com.zsmartsystems.zigbee.IeeeAddress; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; +import com.zsmartsystems.zigbee.security.ZigBeeKey; + +/** + * Class to implement the Z-Stack command ZDO_SET_LINK_KEY. + *

+ * This command sets the application link key for a given device. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackZdoSetLinkKeySreq extends ZstackFrameRequest { + + /** + * Specifies the short address of the pair device of the link key. + */ + private int shortAddr; + + /** + * Specifies the IEEE address of the pair device of the link key + */ + private IeeeAddress ieeeAddr; + + /** + * 128 bit link key data of the device. + */ + private ZigBeeKey linkKeyData; + + /** + * Request constructor + */ + public ZstackZdoSetLinkKeySreq() { + synchronousCommand = true; + } + + /** + * Specifies the short address of the pair device of the link key. + * + * @return the current shortAddr as {@link int} + */ + public int getShortAddr() { + return shortAddr; + } + + /** + * Specifies the short address of the pair device of the link key. + * + * @param shortAddr the ShortAddr to set as {@link int} + */ + public void setShortAddr(int shortAddr) { + this.shortAddr = shortAddr; + } + + /** + * Specifies the IEEE address of the pair device of the link key + * + * @return the current ieeeAddr as {@link IeeeAddress} + */ + public IeeeAddress getIeeeAddr() { + return ieeeAddr; + } + + /** + * Specifies the IEEE address of the pair device of the link key + * + * @param ieeeAddr the IeeeAddr to set as {@link IeeeAddress} + */ + public void setIeeeAddr(IeeeAddress ieeeAddr) { + this.ieeeAddr = ieeeAddr; + } + + /** + * 128 bit link key data of the device. + * + * @return the current linkKeyData as {@link ZigBeeKey} + */ + public ZigBeeKey getLinkKeyData() { + return linkKeyData; + } + + /** + * 128 bit link key data of the device. + * + * @param linkKeyData the LinkKeyData to set as {@link ZigBeeKey} + */ + public void setLinkKeyData(ZigBeeKey linkKeyData) { + this.linkKeyData = linkKeyData; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_ZDO) && (response.getReqCmd1() == 0x23)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_ZDO, 0x23); + + // Serialize the fields + serializer.serializeUInt16(shortAddr); + serializer.serializeIeeeAddress(ieeeAddr); + serializer.serializeZigBeeKey(linkKeyData); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(101); + builder.append("ZstackZdoSetLinkKeySreq [shortAddr="); + builder.append(String.format("%04X", shortAddr)); + builder.append(", ieeeAddr="); + builder.append(ieeeAddr); + builder.append(", linkKeyData="); + builder.append(linkKeyData); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoSetLinkKeySrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoSetLinkKeySrsp.java new file mode 100644 index 0000000000..919773d731 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoSetLinkKeySrsp.java @@ -0,0 +1,68 @@ +/** + * 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.dongle.zstack.api.zdo; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command ZDO_SET_LINK_KEY. + *

+ * This command sets the application link key for a given device. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackZdoSetLinkKeySrsp extends ZstackFrameResponse { + + /** + * 0x00 – Success. 0x01 – Fail to add to address manager. 0x11 – Security manager key table full + */ + private ZstackResponseCode status; + + /** + * Response and Handler constructor + */ + public ZstackZdoSetLinkKeySrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + } + + /** + * 0x00 – Success. 0x01 – Fail to add to address manager. 0x11 – Security manager key table full + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * 0x00 – Success. 0x01 – Fail to add to address manager. 0x11 – Security manager key table full + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(51); + builder.append("ZstackZdoSetLinkKeySrsp [status="); + builder.append(status); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoStartupFromAppSreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoStartupFromAppSreq.java new file mode 100644 index 0000000000..9cb6d76a37 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoStartupFromAppSreq.java @@ -0,0 +1,77 @@ +/** + * 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.dongle.zstack.api.zdo; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Class to implement the Z-Stack command ZDO_STARTUP_FROM_APP. + *

+ * This command starts the device in the network. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackZdoStartupFromAppSreq extends ZstackFrameRequest { + + /** + * Specifies the time delay before the device starts in milliseconds. + */ + private int startDelay; + + /** + * Request constructor + */ + public ZstackZdoStartupFromAppSreq() { + synchronousCommand = true; + } + + /** + * Specifies the time delay before the device starts in milliseconds. + * + * @return the current startDelay as {@link int} + */ + public int getStartDelay() { + return startDelay; + } + + /** + * Specifies the time delay before the device starts in milliseconds. + * + * @param startDelay the StartDelay to set as {@link int} + */ + public void setStartDelay(int startDelay) { + this.startDelay = startDelay; + } + + @Override + public boolean matchSreqError(ZstackRpcSreqErrorSrsp response) { + return (((response.getReqCmd0() & 0x1F) == ZSTACK_ZDO) && (response.getReqCmd1() == 0x40)); + } + + @Override + public int[] serialize() { + // Serialize the header + serializeHeader(ZSTACK_SREQ, ZSTACK_ZDO, 0x40); + + // Serialize the fields + serializer.serializeUInt16(startDelay); + return getPayload(); + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(55); + builder.append("ZstackZdoStartupFromAppSreq [startDelay="); + builder.append(startDelay); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoStartupFromAppSrsp.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoStartupFromAppSrsp.java new file mode 100644 index 0000000000..7dc08b9a08 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoStartupFromAppSrsp.java @@ -0,0 +1,68 @@ +/** + * 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.dongle.zstack.api.zdo; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; + +/** + * Class to implement the Z-Stack command ZDO_STARTUP_FROM_APP. + *

+ * This command starts the device in the network. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackZdoStartupFromAppSrsp extends ZstackFrameResponse { + + /** + * This field indicates either SUCCESS (0) or FAILURE (1). + */ + private ZstackResponseCode status; + + /** + * Response and Handler constructor + */ + public ZstackZdoStartupFromAppSrsp(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + synchronousCommand = true; + + // Deserialize the fields + status = ZstackResponseCode.valueOf(deserializer.deserializeUInt8()); + } + + /** + * This field indicates either SUCCESS (0) or FAILURE (1). + * + * @return the current status as {@link ZstackResponseCode} + */ + public ZstackResponseCode getStatus() { + return status; + } + + /** + * This field indicates either SUCCESS (0) or FAILURE (1). + * + * @param status the Status to set as {@link ZstackResponseCode} + */ + public void setStatus(ZstackResponseCode status) { + this.status = status; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(55); + builder.append("ZstackZdoStartupFromAppSrsp [status="); + builder.append(status); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoStateChangeIndAreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoStateChangeIndAreq.java new file mode 100644 index 0000000000..789c9af0c2 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoStateChangeIndAreq.java @@ -0,0 +1,66 @@ +/** + * 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.dongle.zstack.api.zdo; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackZdoState; + +/** + * Class to implement the Z-Stack command ZDO_STATE_CHANGE_IND. + *

+ * This callback message indicates the ZDO state change. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackZdoStateChangeIndAreq extends ZstackFrameResponse { + + /** + * Specifies the changed ZDO state. An enumerated list starting from 0. + */ + private ZstackZdoState state; + + /** + * Response and Handler constructor + */ + public ZstackZdoStateChangeIndAreq(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + // Deserialize the fields + state = ZstackZdoState.valueOf(deserializer.deserializeUInt8()); + } + + /** + * Specifies the changed ZDO state. An enumerated list starting from 0. + * + * @return the current state as {@link ZstackZdoState} + */ + public ZstackZdoState getState() { + return state; + } + + /** + * Specifies the changed ZDO state. An enumerated list starting from 0. + * + * @param state the State to set as {@link ZstackZdoState} + */ + public void setState(ZstackZdoState state) { + this.state = state; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(55); + builder.append("ZstackZdoStateChangeIndAreq [state="); + builder.append(state); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoTcDevIndAreq.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoTcDevIndAreq.java new file mode 100644 index 0000000000..9dd6cd5cf0 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/api/zdo/ZstackZdoTcDevIndAreq.java @@ -0,0 +1,119 @@ +/** + * 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.dongle.zstack.api.zdo; + +import com.zsmartsystems.zigbee.IeeeAddress; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; + +/** + * Class to implement the Z-Stack command ZDO_TC_DEV_IND. + *

+ * This message is a ZDO callback for TC Device Indication. This is an indication that the TC has delivered the key to a recently + * joined device. + *

+ * Note that this code is autogenerated. Manual changes may be overwritten. + * + * @author Chris Jackson + */ +public class ZstackZdoTcDevIndAreq extends ZstackFrameResponse { + + /** + * Source network Address + */ + private int srcAddr; + + /** + * IEEE Address of the source + */ + private IeeeAddress extAddr; + + /** + * Network address of the parent + */ + private int parentAddr; + + /** + * Response and Handler constructor + */ + public ZstackZdoTcDevIndAreq(int[] inputBuffer) { + // Super creates deserializer and reads header fields + super(inputBuffer); + + // Deserialize the fields + srcAddr = deserializer.deserializeUInt16(); + extAddr = deserializer.deserializeIeeeAddress(); + parentAddr = deserializer.deserializeUInt16(); + } + + /** + * Source network Address + * + * @return the current srcAddr as {@link int} + */ + public int getSrcAddr() { + return srcAddr; + } + + /** + * Source network Address + * + * @param srcAddr the SrcAddr to set as {@link int} + */ + public void setSrcAddr(int srcAddr) { + this.srcAddr = srcAddr; + } + + /** + * IEEE Address of the source + * + * @return the current extAddr as {@link IeeeAddress} + */ + public IeeeAddress getExtAddr() { + return extAddr; + } + + /** + * IEEE Address of the source + * + * @param extAddr the ExtAddr to set as {@link IeeeAddress} + */ + public void setExtAddr(IeeeAddress extAddr) { + this.extAddr = extAddr; + } + + /** + * Network address of the parent + * + * @return the current parentAddr as {@link int} + */ + public int getParentAddr() { + return parentAddr; + } + + /** + * Network address of the parent + * + * @param parentAddr the ParentAddr to set as {@link int} + */ + public void setParentAddr(int parentAddr) { + this.parentAddr = parentAddr; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(99); + builder.append("ZstackZdoTcDevIndAreq [srcAddr="); + builder.append(String.format("%04X", srcAddr)); + builder.append(", extAddr="); + builder.append(extAddr); + builder.append(", parentAddr="); + builder.append(String.format("%04X", parentAddr)); + builder.append(']'); + return builder.toString(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/internal/ZstackFrameHandler.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/internal/ZstackFrameHandler.java new file mode 100644 index 0000000000..413953b129 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/internal/ZstackFrameHandler.java @@ -0,0 +1,33 @@ +/** + * 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.dongle.zstack.internal; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackCommand; + +/** + * Interface to exchange asynchronous packets and link state changes from the low level protocol handlers + * to the dongle layer. + * + * @author Chris Jackson + * + */ +public interface ZstackFrameHandler { + /** + * Passes received asynchronous frames from the ZStack protocol handler to the dongle layer + * + * @param response incoming {@link ZstackCommand} response frame + */ + public void handlePacket(ZstackCommand response); + + /** + * Called when the ZStack handler link state changes + * + * @param state true if the link is UP, false if the link is DOWN + */ + public void handleLinkStateChange(boolean state); +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/internal/ZstackNetworkInitialisation.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/internal/ZstackNetworkInitialisation.java new file mode 100644 index 0000000000..a8792bad13 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/internal/ZstackNetworkInitialisation.java @@ -0,0 +1,286 @@ +/** + * 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.dongle.zstack.internal; + +import com.zsmartsystems.zigbee.ZigBeeStatus; +import com.zsmartsystems.zigbee.dongle.zstack.ZstackNcp; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysResetIndAreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackZdoState; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilGetDeviceInfoSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.zdo.ZstackZdoStateChangeIndAreq; +import com.zsmartsystems.zigbee.transport.DeviceType; +import com.zsmartsystems.zigbee.transport.ZigBeePort; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +/** + * This class provides utility functions to establish a ZStack ZigBee network + * + * @author Chris Jackson + * + */ +public class ZstackNetworkInitialisation { + /** + * The {@link Logger}. + */ + private final Logger logger = LoggerFactory.getLogger(ZstackNetworkInitialisation.class); + + /** + * Number of milliseconds to wait for the bootloader to exit + */ + public static final int BOOTLOAD_TIMEOUT = 3000; + + /** + * Number of milliseconds to wait for the NCP to come online + */ + public static final int ONLINE_TIMEOUT = 5000; + + /** + * The default magic number used to make the dongle exit the bootloader + */ + public static final int MAGIC_NUMBER_DEFAULT = 0xEF; + + /** + * The frame handler used to send the ZStack frames to the NCP + */ + private ZstackProtocolHandler protocolHandler; + + /** + * The magic number used to make the dongle exit the bootloader + */ + private int magicNumber = MAGIC_NUMBER_DEFAULT; + + /** + * @param protocolHandler the {@link ZstackProtocolHandler} used to communicate with the NCP + */ + public ZstackNetworkInitialisation(ZstackProtocolHandler protocolHandler) { + this.protocolHandler = protocolHandler; + } + + /** + * Different hardware may use a different "Magic Number" to skip waiting in the bootloader. Otherwise + * the dongle may wait in the bootloader for 60 seconds after it's powered on or reset. + *

+ * This method allows the user to change the magic number which may be required when using different + * sticks. + * + * @param magicNumber + */ + public void setMagicNumber(int magicNumber) { + this.magicNumber = magicNumber; + } + + /** + * This method performs the initial initialisation of the dongle application firmware. This simply starts the + * dongle, ensuring that it enters the application (ie exiting the bootloader) and sets the configuration to use the + * defaults. From here we have a known configuration on which to start our session. + *

+ * The dongle is not reset completely, thus allowing it to be placed back into the previous network. + * + * @param initialize set to true to reset the dongle and erase all current network settings + * @param serialPort + */ + public ZigBeeStatus initializeNcp(boolean initialize, ZigBeePort serialPort) { + logger.debug("ZStack Initialisation: Initialise"); + ZstackNcp ncp = new ZstackNcp(protocolHandler); + + // The reset failed - assume we're in the bootloader and try and exit + if (exitBootloader(serialPort) == false) { + logger.debug("ZStack Initialisation: Failed to exit bootloader"); + return ZigBeeStatus.COMMUNICATION_ERROR; + } + + if (initialize) { + return resetNcp(ncp, true); + } + return ZigBeeStatus.SUCCESS; + } + + /** + * Form a new network as the coordinator. + *

+ * This assumes that the network configuration parameters have been set prior to calling + * + * @return {@link ZigBeeStatus} defining the result + */ + public ZigBeeStatus formNetwork() { + logger.debug("ZStack forming new network"); + ZstackNcp ncp = new ZstackNcp(protocolHandler); + + if (ncp.setDeviceType(DeviceType.COORDINATOR) != ZstackResponseCode.SUCCESS) { + logger.debug("ZStack forming network: Error setting NCP to coordinator"); + return ZigBeeStatus.COMMUNICATION_ERROR; + } + + return ZigBeeStatus.SUCCESS; + } + + /** + * Join an existing network as a Router + *

+ * This assumes that the network configuration parameters have been set prior to calling + * + * @return {@link ZigBeeStatus} defining the result + */ + public ZigBeeStatus joinNetwork() { + logger.debug("ZStack joining new network"); + ZstackNcp ncp = new ZstackNcp(protocolHandler); + + if (ncp.setDeviceType(DeviceType.ROUTER) != ZstackResponseCode.SUCCESS) { + logger.debug("ZStack forming network: Error setting NCP to router"); + return ZigBeeStatus.COMMUNICATION_ERROR; + } + + return ZigBeeStatus.SUCCESS; + } + + /** + * Starts the NCP application, placing it on the network as previously configured. + * + * @return {@link ZigBeeStatus} defining the result + */ + public ZigBeeStatus startNetwork() { + logger.debug("ZStack starting network"); + ZstackNcp ncp = new ZstackNcp(protocolHandler); + + ncp.setNetworkSecurity(true); + + ncp.zdoRegisterCallback(0x0006);// MatchDescriptorRequest + ncp.zdoRegisterCallback(0x0013);// DeviceAnnounce + ncp.zdoRegisterCallback(0x0036);// ManagementPermitJoiningRequest + ncp.zdoRegisterCallback(0x8000);// NetworkAddressResponse() { + ncp.zdoRegisterCallback(0x8001);// IeeeAddressResponse() { + ncp.zdoRegisterCallback(0x8002);// NodeDescriptorResponse.); + ncp.zdoRegisterCallback(0x8003);// PowerDescriptorResponse + ncp.zdoRegisterCallback(0x8004);// SimpleDescriptorResponse + ncp.zdoRegisterCallback(0x8005);// ActiveEndpointsResponse + ncp.zdoRegisterCallback(0x8006);// MatchDescriptorResponse + ncp.zdoRegisterCallback(0x8011);// UserDescriptorResponse + ncp.zdoRegisterCallback(0x8020);// EndDeviceBindResponse + ncp.zdoRegisterCallback(0x8021);// BindResponse + ncp.zdoRegisterCallback(0x8022);// UnbindResponse + ncp.zdoRegisterCallback(0x8031);// ManagementLqiResponse + ncp.zdoRegisterCallback(0x8032);// ManagementRoutingResponse + ncp.zdoRegisterCallback(0x8033);// ManagementBindResponse + ncp.zdoRegisterCallback(0x8034);// ManagementLeaveResponse + ncp.zdoRegisterCallback(0x8036);// ManagementPermitJoiningResponse + + // Now start the NCP + if (ncp.startupApplication() != ZstackResponseCode.SUCCESS) { + return ZigBeeStatus.COMMUNICATION_ERROR; + } + + return ZigBeeStatus.SUCCESS; + } + + /** + * Attempts to exit the bootloader by sending the "magic number" and waiting for the {@link ZstackSysResetIndAreq} + * to be received to confirm that the NCP application firmware has started. + * + * https://www.ti.com/lit/an/swra466d/swra466d.pdf + * https://www.ti.com/lit/ug/swcu185d/swcu185d.pdf + * + * @return true if the {@link ZstackSysResetIndAreq} was received, otherwise false + * @param serialPort Serial port + */ + private boolean exitBootloader(ZigBeePort serialPort) { + // FIXME this does not work in the OpenHAB binding, as it seems their write() implementation blocks + /* + protocolHandler.sendRaw(magicNumber); + if (waitForBoot("Magicnumber")) { + return true; + } + */ + + serialPort.setDtr(false); + + serialPort.setRts(false); + serialPort.setRts(true); + serialPort.setRts(false); + + return waitForBoot("Hardware reset"); + } + + private boolean waitForBoot(String resetMode) { + Future waiter = protocolHandler.waitForEvent(ZstackSysResetIndAreq.class); + try { + ZstackFrameResponse response = waiter.get(BOOTLOAD_TIMEOUT, TimeUnit.MILLISECONDS); + logger.debug("ZStack Initialisation: Bootloader reset via {} response {}", resetMode, response); + return true; + } catch (InterruptedException | ExecutionException | TimeoutException e) { + logger.debug("ZStack Initialisation: Bootloader reset via {} failed", resetMode, e); + return false; + } + } + + /** + * Resets the NCP and optionally clears the existing network information. + * + * @param ncp the {@link ZstackNcp} + * @param initialise true to remove all current network information + * @return a {@link ZigBeeStatus} defining the success of reason for failure + */ + private ZigBeeStatus resetNcp(ZstackNcp ncp, boolean initialise) { + // Ensure the start options are set to reset the configuration to defaults so we start in a known config + if (ncp.setStartupOptions(true, initialise) != ZstackResponseCode.SUCCESS) { + logger.debug("ZStack Initialisation: Failed to set startup options"); + return ZigBeeStatus.COMMUNICATION_ERROR; + } + + return ZigBeeStatus.SUCCESS; + } + + /** + * Waits for the NCP to come online. + * + * @param ncp the {@link ZstackNcp} + * @return true if the NCP is online, false if the method times out while waiting + */ + public boolean waitForNcpOnline(ZstackNcp ncp) { + long waitTime = System.currentTimeMillis() + ONLINE_TIMEOUT; + while (waitTime > System.currentTimeMillis()) { + logger.debug("ZStack dongle waiting for NCP to come online"); + Future stateChangeFuture = protocolHandler + .waitForEvent(ZstackZdoStateChangeIndAreq.class); + try { + ZstackZdoStateChangeIndAreq stateChange = (ZstackZdoStateChangeIndAreq) stateChangeFuture.get(500, + TimeUnit.MILLISECONDS); + if (isStackOnline(stateChange.getState())) { + return true; + } + } catch (InterruptedException | ExecutionException | TimeoutException e) { + // Eat this exception + } + } + + // It's possible to get here with the NCP being online if we miss the event while we weren't listening + // Do one last check + ZstackUtilGetDeviceInfoSrsp deviceInfo = ncp.getDeviceInfo(); + return isStackOnline(deviceInfo.getDeviceState()); + } + + private boolean isStackOnline(ZstackZdoState state) { + switch (state) { + case DEV_NWK_ORPHAN: + case DEV_ROUTER: + case DEV_ZB_COORD: + case DEV_END_DEVICE: + // NCP is now on the network + return true; + default: + return false; + } + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/internal/ZstackProtocolHandler.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/internal/ZstackProtocolHandler.java new file mode 100644 index 0000000000..7ad1b59176 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/internal/ZstackProtocolHandler.java @@ -0,0 +1,544 @@ +/** + * 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.dongle.zstack.internal; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Queue; +import java.util.concurrent.Callable; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackCommand; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameFactory; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.internal.transaction.ZstackTransaction; +import com.zsmartsystems.zigbee.transport.ZigBeePort; + +/** + * Class for the ZStack protocol handler. The protocol handler manages the low level data transfer of ZStack frames. + * + * @author Chris Jackson + * + */ +public class ZstackProtocolHandler { + private static int ZSTACK_MIN_LENGTH = 3; + private static int ZSTACK_MAX_LENGTH = 100; + + /** + * Time to wait for a SRSP response to an SREQ before moving on + */ + private static int TIMEOUT = 3500; + + private static int ZSTACK_SOF = 0xFE; + + private enum ZstackState { + SOF, + LENGTH, + DATA, + FCS + } + + /** + * Flag to note if we are waiting for a SRSP to ensure that only one synchronous request is outstanding at any time + */ + private AtomicBoolean waitingSrsp = new AtomicBoolean(); + + /** + * The logger. + */ + private final Logger logger = LoggerFactory.getLogger(ZstackProtocolHandler.class); + + /** + * The packet handler. + */ + private final ZstackFrameHandler frameHandler; + + /** + * The port. + */ + private ZigBeePort port; + + /** + * The parser parserThread. + */ + private Thread parserThread = null; + + /** + * Flag reflecting that parser has been closed and parser parserThread should exit. + */ + private boolean closeHandler = false; + + /** + * The queue of {@link ZstackFrameRequest} frames waiting to be sent + */ + private final Queue sendQueue = new ConcurrentLinkedQueue<>(); + + private ExecutorService executor = Executors.newCachedThreadPool(); + private final List transactionListeners = new ArrayList<>(); + + /** + * Construct the handler and provides the {@link ZstackFrameHandler} + * + * @param frameHandler the {@link ZstackFrameHandler} to receive incoming frames + */ + public ZstackProtocolHandler(final ZstackFrameHandler frameHandler) { + this.frameHandler = frameHandler; + } + + /** + * Starts the handler. Sets input stream where the packet is read from the and + * handler which further processes the received packet. + * + * @param port the {@link ZigBeePort} + */ + public void start(final ZigBeePort port) { + this.port = port; + + parserThread = new Thread("ZstackFrameHandler") { + @Override + public void run() { + logger.debug("ZstackFrameHandler thread started"); + + int exceptionCnt = 0; + + while (!closeHandler) { + try { + final int[] frameData = getPacket(); + logger.debug("ZSTACK RX: FrameData [ data={}]", frameToString(frameData)); + + if (waitingSrsp.compareAndSet(isSynchronous(frameData[0]), false)) { + logger.debug("ZSTACK synchronous frame received. waitingSrsp={}, isSynchronous={}", + waitingSrsp, isSynchronous(frameData[0])); + } + + ZstackFrameResponse response = ZstackFrameFactory.createFrame(frameData); + if (response == null) { + logger.debug("RX ZSTACK: ZstackUnknownFrame [ data={}]", frameToString(frameData)); + continue; + } else { + logger.debug("RX ZSTACK: {}", response); + } + + // Send this into the stack + frameHandler.handlePacket(response); + + // Also handle any ZStack level transactions (SREQ transactions or waiting events) + notifyResponseReceived(response); + + sendNextFrame(); + } catch (final IOException e) { + logger.error("ZstackFrameHandler IOException: ", e); + + if (exceptionCnt++ > 10) { + logger.error("ZstackFrameHandler exception count exceeded"); + closeHandler = true; + } + } catch (final Exception e) { + logger.error("ZstackFrameHandler Exception: ", e); + } + } + logger.debug("ZstackFrameHandler exited."); + } + }; + + parserThread.setDaemon(true); + parserThread.start(); + } + + public int[] getPacket() throws IOException { + int length = 0; + int bytesRead = 0; + int[] frameData = null; + + ZstackState state = ZstackState.SOF; + + while (!closeHandler) { + int val = port.read(); + logger.trace("ZSTACK RX Byte: {} [{}/{}]", String.format("%02X", val), bytesRead, length); + if (val == -1) { + continue; + } + + switch (state) { + case SOF: + if (val == ZSTACK_SOF) { + state = ZstackState.LENGTH; + } + break; + case LENGTH: + if (val > ZSTACK_MAX_LENGTH) { + logger.debug("ZSTACK Length greater than allowed: {}", val); + state = ZstackState.SOF; + continue; + } + length = val + 2; + frameData = new int[length]; + state = ZstackState.DATA; + bytesRead = 0; + break; + case DATA: + frameData[bytesRead++] = val; + if (bytesRead >= length) { + state = ZstackState.FCS; + } + break; + case FCS: + int checksum = getChecksum(frameData); + if (val != checksum) { + logger.debug("ZSTACK Checksum error: {} <> {}", val, checksum); + state = ZstackState.SOF; + continue; + } + return frameData; + default: + logger.debug("ZSTACK Unknown decoder state: {}", state); + break; + } + } + + return null; + } + + private int getChecksum(int[] data) { + int checksum = (data.length - 2); + for (int value : data) { + checksum ^= value; + } + return checksum & 0xFF; + } + + /** + * Checks the frame type to see if it is a synchronous request or response. + * + * @param cmd0 the first command byte of the request or response frame + * @return true if this is a synchronous frame + */ + private boolean isSynchronous(int cmd0) { + int frameType = cmd0 & 0xE0; + return (frameType == 0x20 || frameType == 0x60); + } + + public void setClosing() { + executor.shutdown(); + closeHandler = true; + } + + public void close() { + logger.debug("ZstackFrameHandler close."); + setClosing(); + + clearTransactionQueue(); + + sendQueue.clear(); + + frameHandler.handleLinkStateChange(false); + + executor.shutdownNow(); + + try { + parserThread.interrupt(); + parserThread.join(); + logger.debug("ZstackFrameHandler close complete."); + } catch (InterruptedException e) { + logger.debug("ZstackFrameHandler interrupted in packet parser thread shutdown join."); + } + } + + public boolean isAlive() { + return parserThread != null && parserThread.isAlive(); + } + + /** + * Add a ZStack frame to the send queue. The sendQueue is a FIFO queue. + * This method queues a {@link ZstackFrameRequest} frame without waiting for a response and + * no transaction management is performed. + * + * @param request {@link ZstackFrameRequest} + */ + public void queueFrame(ZstackFrameRequest request) { + if (closeHandler) { + logger.debug("ZSTACK: Handler is closed"); + return; + } + sendQueue.add(request); + + logger.debug("ZSTACK TX Queue length={}, waitingSync={}", sendQueue.size(), waitingSrsp); + + sendNextFrame(); + } + + /** + * Notify any transaction listeners when we receive a response. + * + * @param response the response {@link ZstackFrameResponse} received + * @return true if the response was processed + */ + private boolean notifyResponseReceived(final ZstackFrameResponse response) { + boolean processed = false; + + synchronized (transactionListeners) { + for (ZstackListener listener : transactionListeners) { + if (listener.transactionEvent(response)) { + processed = true; + } + } + } + + return processed; + } + + private void addTransactionListener(ZstackListener listener) { + synchronized (transactionListeners) { + if (transactionListeners.contains(listener)) { + return; + } + + transactionListeners.add(listener); + } + } + + private void removeTransactionListener(ZstackListener listener) { + synchronized (transactionListeners) { + transactionListeners.remove(listener); + } + } + + /** + * Aborts all waiting transactions + */ + private void clearTransactionQueue() { + synchronized (transactionListeners) { + for (ZstackListener listener : transactionListeners) { + listener.transactionComplete(); + } + } + } + + private synchronized boolean sendNextFrame() { + if (sendQueue.isEmpty()) { + return false; + } + + if (waitingSrsp.get() && sendQueue.peek().isSynchronous()) { + // We are waiting for an SRSP and the next frame is an SREQ, so we need to wait + return false; + } + + ZstackFrameRequest nextFrame = sendQueue.poll(); + if (waitingSrsp.compareAndSet(false, nextFrame.isSynchronous())) { + logger.debug("ZSTACK synchronous frame sent. waitingSrsp={}", waitingSrsp); + } + + sendFrame(nextFrame); + return true; + } + + private synchronized void sendFrame(ZstackFrameRequest request) { + logger.debug("TX ZSTACK: {}", request); + + StringBuilder builder = new StringBuilder(100); + builder.append("ZSTACK TX: FrameData [ data="); + + for (int outByte : request.serialize()) { + port.write(outByte); + builder.append(String.format("%02X ", outByte)); + } + builder.append(']'); + logger.debug(builder.toString()); + } + + public void sendRaw(int rawByte) { + logger.trace("ZSTACK TX Byte: {}", String.format("%02X", rawByte)); + port.write(rawByte); + } + + /** + * Sends a ZStack request to the NCP without waiting for the response. + * + * @param transaction Request {@link ZstackTransaction} + * @return response {@link Future} {@link ZstackFrameResponse} + */ + public Future sendZstackRequestAsync(final ZstackTransaction transaction) { + if (closeHandler) { + logger.debug("ZSTACK: Handler is closed"); + return null; + } + + class TransactionWaiter implements Callable, ZstackListener { + private boolean complete = false; + + @Override + public ZstackFrameResponse call() { + // Register a listener + addTransactionListener(this); + + // Send the transaction + queueFrame(transaction.getRequest()); + + // Wait for the transaction to complete + synchronized (this) { + while (!complete) { + try { + wait(); + } catch (InterruptedException e) { + complete = true; + } + } + } + + // Remove the listener + removeTransactionListener(this); + + return null;// response; + } + + @Override + public boolean transactionEvent(ZstackFrameResponse response) { + // Check if this response completes our transaction + if (!transaction.isMatch(response)) { + return false; + } + + transactionComplete(); + // response = request; + + return true; + } + + @Override + public void transactionComplete() { + synchronized (this) { + complete = true; + notify(); + } + } + } + + Callable worker = new TransactionWaiter(); + return executor.submit(worker); + } + + /** + * Waiting for a specific response from the NCP. + * + * @param transaction Request {@link ZstackTransaction} + * @return response {@link Future} {@link ZstackFrameResponse} + */ + public Future waitForEvent(final Class requiredResponse) { + if (closeHandler) { + logger.debug("ZSTACK: Handler is closed"); + return null; + } + + class TransactionWaiter implements Callable, ZstackListener { + private boolean complete = false; + private ZstackFrameResponse response; + + @Override + public ZstackFrameResponse call() { + // Register a listener + addTransactionListener(this); + + // Wait for the event to be received + synchronized (this) { + while (!complete) { + try { + wait(); + } catch (InterruptedException e) { + complete = true; + } + } + } + + // Remove the listener + removeTransactionListener(this); + + return response; + } + + @Override + public boolean transactionEvent(ZstackFrameResponse response) { + // Check if this response completes our transaction + if (response.getClass() != requiredResponse) { + return true; + } + + transactionComplete(); + this.response = response; + + return true; + } + + @Override + public void transactionComplete() { + synchronized (this) { + complete = true; + notify(); + } + } + } + + Callable worker = new TransactionWaiter(); + return executor.submit(worker); + } + + /** + * Sends a ZStack request to the NCP and waits for the response. The response is correlated with the request and the + * returned {@link ZstackTransaction} contains the request and response data. + * + * @param transaction Request {@link ZstackTransaction} + * @return response {@link ZstackCommand} + */ + public ZstackTransaction sendTransaction(ZstackTransaction transaction) { + logger.debug("QUEUE ZSTACK: {}", transaction.getRequest()); + + Future futureResponse = sendZstackRequestAsync(transaction); + if (futureResponse == null) { + logger.debug("ZSTACK: Error sending transaction: Future is null"); + return null; + } + + try { + futureResponse.get(TIMEOUT, TimeUnit.MILLISECONDS); + } catch (InterruptedException | TimeoutException | ExecutionException e) { + futureResponse.cancel(true); + logger.debug("ZSTACK interrupted in sendTransaction for {}", transaction, e); + } + + return transaction; + } + + private String frameToString(int[] inputBuffer) { + if (inputBuffer == null) { + return ""; + } + StringBuilder result = new StringBuilder(); + for (int data : inputBuffer) { + result.append(String.format("%02X ", data)); + } + return result.toString(); + } + + interface ZstackListener { + boolean transactionEvent(ZstackFrameResponse response); + + void transactionComplete(); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/internal/ZstackStackConfiguration.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/internal/ZstackStackConfiguration.java new file mode 100644 index 0000000000..92eb98f0dd --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/internal/ZstackStackConfiguration.java @@ -0,0 +1,76 @@ +/** + * 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.dongle.zstack.internal; + +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import com.zsmartsystems.zigbee.dongle.zstack.ZstackNcp; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackConfigId; +import com.zsmartsystems.zigbee.zcl.field.ByteArray; + +/** + * This class provides utility functions to configure, and read the configuration from the Ember stack. + * + * @author Chris Jackson + * + */ +public class ZstackStackConfiguration { + /** + * The {@link ZstackNcp} used to send the EZSP frames to the NCP + */ + private ZstackNcp ncp; + + /** + * Constructor to set the {@link ZstackNcp} + * + * @param ncp the {@link ZstackNcp} used to communicate with the NCP + */ + public ZstackStackConfiguration(ZstackNcp ncp) { + this.ncp = ncp; + } + + /** + * Configuration utility. Takes a {@link Map} of {@link ConfigId} to {@link ByteArray} and will work through + * setting them before returning. + * + * @param configuration {@link Map} of {@link ConfigId} to {@link Integer} with configuration to set + * @return true if all configuration were set successfully + */ + public boolean setConfiguration(Map configuration) { + boolean success = true; + + for (Entry config : configuration.entrySet()) { + if (ncp.writeConfiguration(config.getKey(), config.getValue()) != ZstackResponseCode.SUCCESS) { + success = false; + } + } + return success; + } + + /** + * Configuration utility. Takes a {@link Set} of {@link EzspConfigId} and will work through + * requesting them before returning. + * + * @param configuration {@link Set} of {@link ConfigId} to request + * @return map of configuration data mapping {@link ConfigId} to int[]. Value will be null if error + * occurred. + */ + public Map getConfiguration(Set configuration) { + Map response = new HashMap<>(); + + for (ZstackConfigId configId : configuration) { + response.put(configId, ncp.readConfiguration(configId)); + } + + return response; + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/internal/serializer/ZstackDeserializer.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/internal/serializer/ZstackDeserializer.java new file mode 100644 index 0000000000..ead692a8a6 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/internal/serializer/ZstackDeserializer.java @@ -0,0 +1,78 @@ +/** + * 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.dongle.zstack.internal.serializer; + +import com.zsmartsystems.zigbee.IeeeAddress; +import com.zsmartsystems.zigbee.security.ZigBeeKey; + +/** + * + * @author Chris Jackson + * + */ +public class ZstackDeserializer { + private int[] buffer; + private int position; + + public ZstackDeserializer(int[] inputBuffer) { + buffer = inputBuffer; + position = 0; + } + + public int deserializeUInt8() { + return buffer[position++]; + } + + public int deserializeUInt16() { + return buffer[position++] + (buffer[position++] << 8); + } + + public int deserializeUInt32() { + return buffer[position++] + (buffer[position++] << 8) + (buffer[position++] << 16) + (buffer[position++] << 24); + } + + public boolean deserializeBoolean() { + return buffer[position++] != 0; + } + + public IeeeAddress deserializeIeeeAddress() { + int address[] = new int[8]; + for (int cnt = 0; cnt < 8; cnt++) { + address[cnt] = buffer[position++]; + } + return new IeeeAddress(address); + } + + public int[] deserializeUInt8Array() { + return deserializeUInt8Array(buffer.length - position); + } + + public int[] deserializeUInt8Array(int len) { + int[] array = new int[len]; + + for (int cnt = 0; cnt < len; cnt++) { + array[cnt] = deserializeUInt8(); + } + + return array; + } + + public int[] deserializeUInt16Array(int len) { + int[] array = new int[len]; + + for (int cnt = 0; cnt < len; cnt++) { + array[cnt] = deserializeUInt16(); + } + + return array; + } + + public ZigBeeKey deserializeZigBeeKey() { + return new ZigBeeKey(deserializeUInt8Array(16)); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/internal/serializer/ZstackSerializer.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/internal/serializer/ZstackSerializer.java new file mode 100644 index 0000000000..14f5f1a253 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/internal/serializer/ZstackSerializer.java @@ -0,0 +1,75 @@ +/** + * 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.dongle.zstack.internal.serializer; + +import java.util.Arrays; + +import com.zsmartsystems.zigbee.IeeeAddress; +import com.zsmartsystems.zigbee.security.ZigBeeKey; + +/** + * + * @author Chris Jackson + * + */ +public class ZstackSerializer { + private int[] buffer = new int[250]; + private int length = 0; + + public void serializeUInt8(int uint8) { + buffer[length++] = uint8 & 0xFF; + } + + public void serializeUInt16(int uint16) { + buffer[length++] = uint16 & 0xFF; + buffer[length++] = (uint16 >> 8) & 0xFF; + } + + public void serializeUInt32(int uint32) { + buffer[length++] = uint32 & 0xFF; + buffer[length++] = (uint32 >> 8) & 0xFF; + buffer[length++] = (uint32 >> 16) & 0xFF; + buffer[length++] = (uint32 >> 24) & 0xFF; + } + + public void serializeBoolean(boolean bool) { + buffer[length++] = bool ? 1 : 0; + } + + public void serializeUInt8Array(int[] uint8Array) { + for (int val : uint8Array) { + serializeUInt8(val); + } + } + + public void serializeUInt16Array(int[] uint16Array) { + for (int val : uint16Array) { + serializeUInt16(val); + } + } + + public void serializeIeeeAddress(IeeeAddress address) { + buffer[length++] = address.getValue()[0]; + buffer[length++] = address.getValue()[1]; + buffer[length++] = address.getValue()[2]; + buffer[length++] = address.getValue()[3]; + buffer[length++] = address.getValue()[4]; + buffer[length++] = address.getValue()[5]; + buffer[length++] = address.getValue()[6]; + buffer[length++] = address.getValue()[7]; + } + + public void serializeZigBeeKey(ZigBeeKey keyData) { + serializeUInt8Array(keyData.getValue()); + } + + public int[] getBuffer() { + return Arrays.copyOfRange(buffer, 0, length); + } + +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/internal/transaction/ZstackSingleResponseTransaction.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/internal/transaction/ZstackSingleResponseTransaction.java new file mode 100644 index 0000000000..6c843e7efc --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/internal/transaction/ZstackSingleResponseTransaction.java @@ -0,0 +1,76 @@ +/** + * 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.dongle.zstack.internal.transaction; + +import java.util.Arrays; +import java.util.List; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * Single ZStack transaction response handling. This matches a {@link ZstackFrameRequest} with a single + * {@link ZstackFrameResponse}. + * + * @author Chris Jackson + * + */ +public class ZstackSingleResponseTransaction implements ZstackTransaction { + private ZstackFrameRequest request; + private ZstackFrameResponse response; + private Class requiredResponse; + + public ZstackSingleResponseTransaction(ZstackFrameRequest request, Class requiredResponse) { + this.request = request; + this.requiredResponse = requiredResponse; + } + + @Override + public boolean isMatch(ZstackFrameResponse response) { + if (response.getClass() == requiredResponse) { + this.response = response; + return true; + } + + // If this is an RPC Error Response, then it might be telling us that the command we tried to send is + // unsupported. + // We need to terminate the transaction if this is true. + if (response instanceof ZstackRpcSreqErrorSrsp) { + return request.matchSreqError((ZstackRpcSreqErrorSrsp) response); + } + return false; + } + + @Override + public ZstackFrameRequest getRequest() { + return request; + } + + @Override + public ZstackFrameResponse getResponse() { + return response; + } + + @Override + public List getResponses() { + if (response == null) { + return null; + } + + // This transaction only allows a single response + return Arrays.asList(response); + } + + @Override + public String toString() { + return "ZstackSingleResponseTransaction [request=" + request + ", requiredResponse=" + + requiredResponse.getSimpleName() + ", response=" + response + "]"; + } + +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/internal/transaction/ZstackTransaction.java b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/internal/transaction/ZstackTransaction.java new file mode 100644 index 0000000000..1d519794da --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/main/java/com/zsmartsystems/zigbee/dongle/zstack/internal/transaction/ZstackTransaction.java @@ -0,0 +1,58 @@ +/** + * 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.dongle.zstack.internal.transaction; + +import java.util.List; + +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; + +/** + * Interface for ZStack protocol transaction. + *

+ * The transaction looks for a received {@link ZstackFrameResponse} that matches the sent {@link ZstackFrameRequest}. + * Generally, this is matching the Srsp matching the Sreq. + * The {@link ZstackFrameRequest} and {@link ZstackFrameResponse} classes are provided when the transaction is created. + * + * @author Chris Jackson + * + */ +public interface ZstackTransaction { + /** + * Matches request and response. + * + * @param response the response {@link ZstackFrameResponse} + * @return true if response matches the request + */ + boolean isMatch(ZstackFrameResponse response); + + /** + * Gets the {@link ZstackFrameRequest} associated with this transaction + * + * @return the {@link ZstackFrameRequest} + */ + ZstackFrameRequest getRequest(); + + /** + * Gets the {@link ZstackFrameResponse} for the transaction. If multiple responses are returned, this will return + * the + * last response, indicating the final response used to complete the transaction. + * + * @return {@link ZstackFrameResponse} to complete the transaction or null if no response received + */ + ZstackFrameResponse getResponse(); + + /** + * Gets a {@link List} of the {@link ZstackFrameResponse}s received for the transaction. This is used for + * transactions + * returning multiple responses - for single response transactions, use {@link #getResponse}. + * + * @return {@link ZstackFrameResponse} to complete the transaction or null if no response received + */ + List getResponses(); +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/ZStackNcpTest.java b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/ZStackNcpTest.java new file mode 100644 index 0000000000..5a0aa9624e --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/ZStackNcpTest.java @@ -0,0 +1,145 @@ +/** + * 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.dongle.zstack; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.Set; + +import org.junit.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.ArgumentMatchers; +import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; + +import com.zsmartsystems.zigbee.IeeeAddress; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameResponse; +import com.zsmartsystems.zigbee.dongle.zstack.api.sapi.ZstackZbWriteConfigurationSreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.sapi.ZstackZbWriteConfigurationSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackResetType; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysPingSreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysPingSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysResetIndAreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSysResetReqAcmd; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackSystemCapabilities; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackZdoState; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilGetDeviceInfoSreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilGetDeviceInfoSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.internal.ZstackProtocolHandler; +import com.zsmartsystems.zigbee.dongle.zstack.internal.transaction.ZstackTransaction; + +/** + * + * @author Chris Jackson + * + */ +public class ZStackNcpTest { + private ArgumentCaptor transactionCapture = ArgumentCaptor.forClass(ZstackTransaction.class); + private ZstackProtocolHandler handler; + + private ZstackNcp getZstackNcp(ZstackFrameResponse response) { + handler = Mockito.mock(ZstackProtocolHandler.class); + ZstackNcp ncp = new ZstackNcp(handler); + + ZstackTransaction transaction = Mockito.mock(ZstackTransaction.class); + Mockito.when(transaction.getResponse()).thenReturn(response); + Mockito.doAnswer(new Answer() { + @Override + public ZstackTransaction answer(InvocationOnMock invocation) { + return transaction; + } + }).when(handler).sendTransaction(ArgumentMatchers.any(ZstackTransaction.class)); + + return ncp; + } + + @Test + public void resetNcp() { + ZstackNcp ncp = getZstackNcp(Mockito.mock(ZstackSysResetIndAreq.class)); + + ncp.resetNcp(ZstackResetType.SERIAL_BOOTLOADER); + Mockito.verify(handler, Mockito.times(1)).sendTransaction(transactionCapture.capture()); + + ZstackFrameRequest request = transactionCapture.getValue().getRequest(); + System.out.println(request); + assertTrue(request instanceof ZstackSysResetReqAcmd); + assertEquals(ZstackResetType.SERIAL_BOOTLOADER, ((ZstackSysResetReqAcmd) request).getType()); + + ncp.resetNcp(ZstackResetType.TARGET_DEVICE); + Mockito.verify(handler, Mockito.times(2)).sendTransaction(transactionCapture.capture()); + + request = transactionCapture.getValue().getRequest(); + System.out.println(request); + assertTrue(request instanceof ZstackSysResetReqAcmd); + assertEquals(ZstackResetType.TARGET_DEVICE, ((ZstackSysResetReqAcmd) request).getType()); + } + + @Test + public void pingNcp() { + ZstackSysPingSrsp response = Mockito.mock(ZstackSysPingSrsp.class); + Mockito.when(response.getCapabilities()).thenReturn(0x17D); + ZstackNcp ncp = getZstackNcp(response); + + Set capabilities = ncp.pingNcp(); + System.out.println("Capabilities returned " + capabilities); + + Mockito.verify(handler, Mockito.times(1)).sendTransaction(transactionCapture.capture()); + + ZstackFrameRequest request = transactionCapture.getValue().getRequest(); + System.out.println(request); + assertTrue(request instanceof ZstackSysPingSreq); + assertEquals(7, capabilities.size()); + } + + @Test + public void getDeviceInfo() { + ZstackUtilGetDeviceInfoSrsp response = Mockito.mock(ZstackUtilGetDeviceInfoSrsp.class); + Mockito.when(response.getDeviceState()).thenReturn(ZstackZdoState.DEV_INIT); + Mockito.when(response.getIeeeAddress()).thenReturn(new IeeeAddress("1234567890ABCDEF")); + Mockito.when(response.getShortAddr()).thenReturn(0x1234); + ZstackNcp ncp = getZstackNcp(response); + + ZstackUtilGetDeviceInfoSrsp deviceInfo = ncp.getDeviceInfo(); + System.out.println("Device info returned " + deviceInfo); + + Mockito.verify(handler, Mockito.times(1)).sendTransaction(transactionCapture.capture()); + assertEquals(0x1234, deviceInfo.getShortAddr()); + assertEquals(new IeeeAddress("1234567890ABCDEF"), deviceInfo.getIeeeAddress()); + + ZstackFrameRequest request = transactionCapture.getValue().getRequest(); + System.out.println(request); + assertTrue(request instanceof ZstackUtilGetDeviceInfoSreq); + + assertEquals(0x1234, ncp.getNwkAddress()); + assertEquals(new IeeeAddress("1234567890ABCDEF"), ncp.getIeeeAddress()); + } + + @Test + public void setStartupOptions() { + ZstackNcp ncp = getZstackNcp(Mockito.mock(ZstackZbWriteConfigurationSrsp.class)); + + ncp.setStartupOptions(false, false); + Mockito.verify(handler, Mockito.times(1)).sendTransaction(transactionCapture.capture()); + assertEquals(0, ((ZstackZbWriteConfigurationSreq) transactionCapture.getValue().getRequest()).getValue()[0]); + + ncp.setStartupOptions(true, false); + Mockito.verify(handler, Mockito.times(2)).sendTransaction(transactionCapture.capture()); + assertEquals(1, ((ZstackZbWriteConfigurationSreq) transactionCapture.getValue().getRequest()).getValue()[0]); + + ncp.setStartupOptions(false, true); + Mockito.verify(handler, Mockito.times(3)).sendTransaction(transactionCapture.capture()); + assertEquals(2, ((ZstackZbWriteConfigurationSreq) transactionCapture.getValue().getRequest()).getValue()[0]); + + ncp.setStartupOptions(true, true); + Mockito.verify(handler, Mockito.times(4)).sendTransaction(transactionCapture.capture()); + assertEquals(3, ((ZstackZbWriteConfigurationSreq) transactionCapture.getValue().getRequest()).getValue()[0]); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/ZigBeeDongleZstackTest.java b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/ZigBeeDongleZstackTest.java new file mode 100644 index 0000000000..9bc7ac0899 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/ZigBeeDongleZstackTest.java @@ -0,0 +1,218 @@ +/** + * 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.dongle.zstack; + +import static org.junit.Assert.assertEquals; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; + +import org.junit.Test; +import org.mockito.ArgumentMatchers; +import org.mockito.Mockito; + +import com.zsmartsystems.zigbee.ExtendedPanId; +import com.zsmartsystems.zigbee.TestUtilities; +import com.zsmartsystems.zigbee.ZigBeeChannel; +import com.zsmartsystems.zigbee.ZigBeeNwkAddressMode; +import com.zsmartsystems.zigbee.ZigBeeProfileType; +import com.zsmartsystems.zigbee.ZigBeeStatus; +import com.zsmartsystems.zigbee.aps.ZigBeeApsFrame; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackFrameRequest; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; +import com.zsmartsystems.zigbee.dongle.zstack.api.af.ZstackAfDataConfirmAreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackZdoState; +import com.zsmartsystems.zigbee.dongle.zstack.api.zdo.ZstackZdoStateChangeIndAreq; +import com.zsmartsystems.zigbee.dongle.zstack.internal.ZstackProtocolHandler; +import com.zsmartsystems.zigbee.dongle.zstack.internal.transaction.ZstackTransaction; +import com.zsmartsystems.zigbee.transport.ZigBeePort; +import com.zsmartsystems.zigbee.transport.ZigBeeTransportProgressState; +import com.zsmartsystems.zigbee.transport.ZigBeeTransportReceive; +import com.zsmartsystems.zigbee.transport.ZigBeeTransportState; + +/** + * Tests for {@link ZigBeeDongleZstack} + * + * @author Chris Jackson + * + */ +public class ZigBeeDongleZstackTest { + private static int TIMEOUT = 5000; + + @Test + public void setZigBeeExtendedPanId() { + ZigBeeDongleZstack dongle = new ZigBeeDongleZstack(null); + + dongle.setZigBeeExtendedPanId(new ExtendedPanId("123456789abcdef")); + } + + @Test + public void setZigBeePanId() { + ZigBeeDongleZstack dongle = new ZigBeeDongleZstack(null); + + dongle.setZigBeePanId(0x1234); + } + + @Test + public void testEzspStackStatusHandler() throws Exception { + ZigBeeTransportReceive transport = Mockito.mock(ZigBeeTransportReceive.class); + + final ZstackNcp ncp = Mockito.mock(ZstackNcp.class); + Mockito.when(ncp.getNwkAddress()).thenReturn(1243); + ZigBeeDongleZstack dongle = new ZigBeeDongleZstack(null) { + @Override + public ZstackNcp getZstackNcp() { + return ncp; + } + }; + dongle.setZigBeeTransportReceive(transport); + + TestUtilities.setField(ZigBeeDongleZstack.class, dongle, "initialised", true); + + ZstackZdoStateChangeIndAreq response = Mockito.mock(ZstackZdoStateChangeIndAreq.class); + Mockito.when(response.getState()).thenReturn(ZstackZdoState.DEV_ZB_COORD); + Mockito.verify(transport, Mockito.timeout(TIMEOUT).times(0)).setTransportState(ZigBeeTransportState.ONLINE); + + response = Mockito.mock(ZstackZdoStateChangeIndAreq.class); + Mockito.when(response.getState()).thenReturn(ZstackZdoState.DEV_ROUTER); + dongle.handlePacket(response); + Mockito.verify(transport, Mockito.timeout(TIMEOUT)).setTransportState(ZigBeeTransportState.ONLINE); + assertEquals(Integer.valueOf(1243), dongle.getNwkAddress()); + + response = Mockito.mock(ZstackZdoStateChangeIndAreq.class); + Mockito.when(response.getState()).thenReturn(ZstackZdoState.DEV_INIT); + dongle.handlePacket(response); + Mockito.verify(transport, Mockito.timeout(TIMEOUT)).setTransportState(ZigBeeTransportState.OFFLINE); + } + + @Test + public void setZigBeeChannel() { + ZigBeeDongleZstack dongle = new ZigBeeDongleZstack(null); + + assertEquals(ZigBeeStatus.INVALID_ARGUMENTS, dongle.setZigBeeChannel(ZigBeeChannel.CHANNEL_03)); + + assertEquals(ZigBeeStatus.SUCCESS, dongle.setZigBeeChannel(ZigBeeChannel.CHANNEL_11)); + + assertEquals(ZigBeeStatus.SUCCESS, dongle.setZigBeeChannel(ZigBeeChannel.CHANNEL_24)); + } + + @Test + public void testEzspMessageSentHandler() throws Exception { + ZigBeeTransportReceive transport = Mockito.mock(ZigBeeTransportReceive.class); + + final ZstackNcp ncp = Mockito.mock(ZstackNcp.class); + Mockito.when(ncp.getNwkAddress()).thenReturn(1243); + ZigBeeDongleZstack dongle = new ZigBeeDongleZstack(null); + dongle.setZigBeeTransportReceive(transport); + + TestUtilities.setField(ZigBeeDongleZstack.class, dongle, "initialised", true); + TestUtilities.setField(ZigBeeDongleZstack.class, dongle, "executorService", + Executors.newScheduledThreadPool(1)); + + ZstackAfDataConfirmAreq response = Mockito.mock(ZstackAfDataConfirmAreq.class); + Mockito.when(response.getTransId()).thenReturn(231); + Mockito.when(response.getStatus()).thenReturn(ZstackResponseCode.SUCCESS); + dongle.handlePacket(response); + Mockito.verify(transport, Mockito.timeout(TIMEOUT)).receiveCommandState(231, + ZigBeeTransportProgressState.RX_ACK); + + response = Mockito.mock(ZstackAfDataConfirmAreq.class); + Mockito.when(response.getTransId()).thenReturn(231); + Mockito.when(response.getStatus()).thenReturn(ZstackResponseCode.FAILURE); + dongle.handlePacket(response); + Mockito.verify(transport, Mockito.timeout(TIMEOUT)).receiveCommandState(231, + ZigBeeTransportProgressState.RX_NAK); + } + + @Test + public void sendCommandUnicast() throws Exception { + ZigBeeDongleZstack dongle = new ZigBeeDongleZstack(null); + + ZstackProtocolHandler handler = Mockito.mock(ZstackProtocolHandler.class); + TestUtilities.setField(ZigBeeDongleZstack.class, dongle, "frameHandler", handler); + + ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1); + TestUtilities.setField(ZigBeeDongleZstack.class, dongle, "executorService", executorService); + + ZigBeeApsFrame apsFrame = new ZigBeeApsFrame(); + apsFrame.setCluster(0); + apsFrame.setProfile(ZigBeeProfileType.ZIGBEE_HOME_AUTOMATION.getKey()); + apsFrame.setAddressMode(ZigBeeNwkAddressMode.DEVICE); + apsFrame.setDestinationAddress(1234); + apsFrame.setApsCounter(1); + apsFrame.setRadius(30); + apsFrame.setPayload(new int[] {}); + + dongle.sendCommand(1, apsFrame); + Mockito.verify(handler, Mockito.timeout(TIMEOUT).times(1)) + .sendTransaction(ArgumentMatchers.any(ZstackTransaction.class)); + } + + @Test + public void sendCommandBroadcast() throws Exception { + ZigBeeDongleZstack dongle = new ZigBeeDongleZstack(null); + + ZstackProtocolHandler handler = Mockito.mock(ZstackProtocolHandler.class); + TestUtilities.setField(ZigBeeDongleZstack.class, dongle, "frameHandler", handler); + + ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1); + TestUtilities.setField(ZigBeeDongleZstack.class, dongle, "executorService", executorService); + + ZigBeeApsFrame apsFrame = new ZigBeeApsFrame(); + apsFrame.setCluster(0); + apsFrame.setProfile(ZigBeeProfileType.ZIGBEE_HOME_AUTOMATION.getKey()); + apsFrame.setAddressMode(ZigBeeNwkAddressMode.DEVICE); + apsFrame.setDestinationAddress(0xfff9); + apsFrame.setApsCounter(1); + apsFrame.setRadius(30); + apsFrame.setPayload(new int[] {}); + + dongle.sendCommand(1, apsFrame); + Mockito.verify(handler, Mockito.timeout(TIMEOUT).times(1)) + .sendTransaction(ArgumentMatchers.any(ZstackTransaction.class)); + } + + @Test + public void shutdown() throws Exception { + ZigBeeDongleZstack dongle = new ZigBeeDongleZstack(null); + TestUtilities.setField(ZigBeeDongleZstack.class, dongle, "serialPort", Mockito.mock(ZigBeePort.class)); + TestUtilities.setField(ZigBeeDongleZstack.class, dongle, "frameHandler", + Mockito.mock(ZstackProtocolHandler.class)); + + dongle.shutdown(); + } + + @Test + public void scheduleNetworkStatePolling() throws Exception { + ZigBeeDongleZstack dongle = new ZigBeeDongleZstack(null); + + ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1); + + ZstackProtocolHandler frameHandler = Mockito.mock(ZstackProtocolHandler.class); + + TestUtilities.setField(ZigBeeDongleZstack.class, dongle, "pollRate", 1); + TestUtilities.setField(ZigBeeDongleZstack.class, dongle, "frameHandler", frameHandler); + TestUtilities.setField(ZigBeeDongleZstack.class, dongle, "executorService", executorService); + + TestUtilities.invokeMethod(ZigBeeDongleZstack.class, dongle, "scheduleNetworkStatePolling"); + Mockito.verify(frameHandler, Mockito.timeout(TIMEOUT).times(0)) + .queueFrame(ArgumentMatchers.any(ZstackFrameRequest.class)); + + TestUtilities.setField(ZigBeeDongleZstack.class, dongle, "lastSendCommandTime", Long.MAX_VALUE - 1); + TestUtilities.setField(ZigBeeDongleZstack.class, dongle, "networkStateUp", true); + TestUtilities.invokeMethod(ZigBeeDongleZstack.class, dongle, "scheduleNetworkStatePolling"); + Mockito.verify(frameHandler, Mockito.timeout(TIMEOUT).times(0)) + .queueFrame(ArgumentMatchers.any(ZstackFrameRequest.class)); + + TestUtilities.setField(ZigBeeDongleZstack.class, dongle, "lastSendCommandTime", 0); + TestUtilities.invokeMethod(ZigBeeDongleZstack.class, dongle, "scheduleNetworkStatePolling"); + Mockito.verify(frameHandler, Mockito.timeout(TIMEOUT).atLeast(1)) + .queueFrame(ArgumentMatchers.any(ZstackFrameRequest.class)); + } + +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/api/ZstackFrameRequestTest.java b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/api/ZstackFrameRequestTest.java new file mode 100644 index 0000000000..59c5bab7ab --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/api/ZstackFrameRequestTest.java @@ -0,0 +1,73 @@ +/** + * 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.dongle.zstack.api; + +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; + +import org.junit.Test; + +import com.zsmartsystems.zigbee.IeeeAddress; + +/** + * + * @author Chris Jackson + * + */ +public class ZstackFrameRequestTest { + + @Test + public void deserializeUInt16() { + Request request = new Request(); + request.serializeHeader(0, 0, 0); + request.serializer.serializeUInt16(0x1234); + + assertTrue(Arrays.equals(new int[] { 0xFE, 0x02, 0x00, 0x00, 0x34, 0x12, 0x24 }, request.getPayload())); + } + + @Test + public void serializeUInt32() { + Request request = new Request(); + request.serializeHeader(0, 0, 0); + request.serializer.serializeUInt32(0x12345678); + + assertTrue(Arrays.equals(new int[] { 0xFE, 0x04, 0x00, 0x00, 0x78, 0x56, 0x34, 0x12, 0x0C }, + request.getPayload())); + } + + @Test + public void serializeIeeeAddress() { + Request request = new Request(); + IeeeAddress address = new IeeeAddress("1234567890ABCDEF"); + request.serializeHeader(0, 0, 0); + request.serializer.serializeIeeeAddress(address); + + assertTrue(Arrays.equals( + new int[] { 0xFE, 0x08, 0x00, 0x00, 0xEF, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12, 0x19 }, + request.getPayload())); + } + + @Test + public void serializeBoolean() { + Request request = new Request(); + request.serializeHeader(0, 0, 0); + request.serializer.serializeBoolean(false); + request.serializer.serializeBoolean(true); + + assertTrue(Arrays.equals(new int[] { 0xFE, 0x02, 0x00, 0x00, 0x00, 0x01, 0x03 }, request.getPayload())); + } + + class Request extends ZstackFrameRequest { + @Override + public int[] serialize() { + // TODO Auto-generated method stub + return null; + } + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/api/ZstackFrameResponseTest.java b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/api/ZstackFrameResponseTest.java new file mode 100644 index 0000000000..3dc0f68f17 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/api/ZstackFrameResponseTest.java @@ -0,0 +1,57 @@ +/** + * 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.dongle.zstack.api; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import com.zsmartsystems.zigbee.IeeeAddress; + +/** + * + * @author Chris Jackson + * + */ +public class ZstackFrameResponseTest { + + @Test + public void deserializeUInt16() { + Response response = new Response(new int[] { 0x00, 0x00, 0x34, 0x12 }); + + assertEquals(0x1234, response.deserializer.deserializeUInt16()); + } + + @Test + public void deserializeUInt32() { + Response response = new Response(new int[] { 0x00, 0x00, 0x78, 0x56, 0x34, 0x12 }); + + assertEquals(0x12345678, response.deserializer.deserializeUInt32()); + } + + @Test + public void deserializeBoolean() { + Response response = new Response(new int[] { 0x00, 0x00, 0x00, 0x01 }); + + assertEquals(false, response.deserializer.deserializeBoolean()); + assertEquals(true, response.deserializer.deserializeBoolean()); + } + + @Test + public void deserializeIeeeAddress() { + Response response = new Response(new int[] { 0x00, 0x00, 0xEF, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12 }); + + assertEquals(new IeeeAddress("1234567890ABCDEF"), response.deserializer.deserializeIeeeAddress()); + } + + class Response extends ZstackFrameResponse { + public Response(int[] inputBuffer) { + super(inputBuffer); + } + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/api/af/ZstackAfRegisterSreqTest.java b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/api/af/ZstackAfRegisterSreqTest.java new file mode 100644 index 0000000000..510d73efff --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/api/af/ZstackAfRegisterSreqTest.java @@ -0,0 +1,41 @@ +/** + * 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.dongle.zstack.api.af; + +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; + +import org.junit.Test; + +/** + * + * @author Chris Jackson + * + */ +public class ZstackAfRegisterSreqTest { + @Test + public void test() { + ZstackAfRegisterSreq request = new ZstackAfRegisterSreq(); + + request.setEndPoint(1); + request.setAppDeviceId(2); + request.setAppProfId(0x1122); + request.setAppInClusterList(new int[] { 1, 2, 3 }); + request.setAppOutClusterList(new int[] { 0x1234 }); + request.setLatencyReq(0x21); + request.setAppDevVer(0x12); + + System.out.println(request); + + int[] x = request.serialize(); + + assertTrue(Arrays.equals(new int[] { 0xFE, 0x11, 0x24, 0x00, 0x01, 0x22, 0x11, 0x02, 0x00, 0x12, 0x21, 0x03, + 0x01, 0x00, 0x02, 0x00, 0x03, 0x00, 0x01, 0x34, 0x12, 0x12 }, x)); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/api/rpc/ZstackRpcSreqErrorSrspTest.java b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/api/rpc/ZstackRpcSreqErrorSrspTest.java new file mode 100644 index 0000000000..252d3a5564 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/api/rpc/ZstackRpcSreqErrorSrspTest.java @@ -0,0 +1,30 @@ +/** + * 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.dongle.zstack.api.rpc; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +/** + * + * @author Chris Jackson + * + */ +public class ZstackRpcSreqErrorSrspTest { + @Test + public void test() { + ZstackRpcSreqErrorSrsp res = new ZstackRpcSreqErrorSrsp(new int[] { 0x60, 0x00, 0x02, 0x21, 0x19, 0x59 }); + + System.out.println(res); + + assertEquals(0x21, res.getReqCmd0()); + assertEquals(0x19, res.getReqCmd1()); + assertEquals(ZstackSreqErrorCode.INVALID_COMMAND_ID, res.getErrorCode()); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysResetReqAcmdTest.java b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysResetReqAcmdTest.java new file mode 100644 index 0000000000..3c38d5c643 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysResetReqAcmdTest.java @@ -0,0 +1,38 @@ +/** + * 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.dongle.zstack.api.sys; + +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; + +import org.junit.Test; + +/** + * + * @author Chris Jackson + * + */ +public class ZstackSysResetReqAcmdTest { + @Test + public void test() { + ZstackSysResetReqAcmd req = new ZstackSysResetReqAcmd(); + req.setType(ZstackResetType.TARGET_DEVICE); + + System.out.println(req); + int[] data = req.serialize(); + assertTrue(Arrays.equals(data, new int[] { 0xFE, 0x01, 0x41, 0x00, 0x00, 0x40 })); + + req = new ZstackSysResetReqAcmd(); + req.setType(ZstackResetType.SERIAL_BOOTLOADER); + + System.out.println(req); + data = req.serialize(); + assertTrue(Arrays.equals(data, new int[] { 0xFE, 0x01, 0x41, 0x00, 0x01, 0x41 })); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysVersionSreqTest.java b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysVersionSreqTest.java new file mode 100644 index 0000000000..f3d5313aef --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/api/sys/ZstackSysVersionSreqTest.java @@ -0,0 +1,51 @@ +/** + * 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.dongle.zstack.api.sys; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; + +import org.junit.Test; +import org.mockito.Mockito; + +import com.zsmartsystems.zigbee.dongle.zstack.api.rpc.ZstackRpcSreqErrorSrsp; + +/** + * + * @author Chris Jackson + * + */ +public class ZstackSysVersionSreqTest { + @Test + public void test() { + ZstackSysVersionSreq req = new ZstackSysVersionSreq(); + + System.out.println(req); + int[] data = req.serialize(); + assertTrue(Arrays.equals(data, new int[] { 0xFE, 0x00, 0x21, 0x02, 0x23 })); + + ZstackRpcSreqErrorSrsp err = Mockito.mock(ZstackRpcSreqErrorSrsp.class); + Mockito.when(err.getReqCmd0()).thenReturn(0x21); + Mockito.when(err.getReqCmd1()).thenReturn(0x02); + assertTrue(req.matchSreqError(err)); + + Mockito.when(err.getReqCmd0()).thenReturn(0x21); + Mockito.when(err.getReqCmd1()).thenReturn(0x03); + assertFalse(req.matchSreqError(err)); + + Mockito.when(err.getReqCmd0()).thenReturn(0x22); + Mockito.when(err.getReqCmd1()).thenReturn(0x02); + assertFalse(req.matchSreqError(err)); + + Mockito.when(err.getReqCmd0()).thenReturn(0x41); + Mockito.when(err.getReqCmd1()).thenReturn(0x02); + assertTrue(req.matchSreqError(err)); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilGetDeviceInfoSrspTest.java b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilGetDeviceInfoSrspTest.java new file mode 100644 index 0000000000..afdae47191 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/api/util/ZstackUtilGetDeviceInfoSrspTest.java @@ -0,0 +1,40 @@ +/** + * 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.dongle.zstack.api.util; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import com.zsmartsystems.zigbee.IeeeAddress; +import com.zsmartsystems.zigbee.dongle.zstack.api.ZstackResponseCode; +import com.zsmartsystems.zigbee.dongle.zstack.api.sys.ZstackZdoState; + +/** + * + * @author Chris Jackson + * + */ +public class ZstackUtilGetDeviceInfoSrspTest { + @Test + public void test() { + ZstackUtilGetDeviceInfoSrsp res = new ZstackUtilGetDeviceInfoSrsp( + new int[] { 0x67, 0x00, 0x00, 0x14, 0xD4, 0xF1, 0x02, 0x00, 0x4B, 0x12, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x04, 0xFC, 0x35, 0x7E, 0xC4, 0xAF, 0x29, 0xE3, 0xF6 }); + + System.out.println(res); + + assertEquals(ZstackResponseCode.SUCCESS, res.getStatus()); + assertEquals(1, res.getDeviceType()); + assertEquals(0, res.getShortAddr()); + assertEquals(new IeeeAddress("00124B0002F1D414"), res.getIeeeAddress()); + assertEquals(ZstackZdoState.DEV_HOLD, res.getDeviceState()); + assertEquals(4, res.getAssocDevicesList().length); + assertEquals(0x35FC, res.getAssocDevicesList()[0]); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/internal/ZstackProtocolHandlerTest.java b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/internal/ZstackProtocolHandlerTest.java new file mode 100644 index 0000000000..1998d7d20e --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/internal/ZstackProtocolHandlerTest.java @@ -0,0 +1,166 @@ +/** + * 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.dongle.zstack.internal; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; + +import com.zsmartsystems.zigbee.TestUtilities; +import com.zsmartsystems.zigbee.transport.ZigBeePort; + +/** + * Tests for {@link ZstackProtocolHandler} + * + * @author Chris Jackson + * + */ +public class ZstackProtocolHandlerTest { + private static int TIMEOUT = 5000; + + private int[] getPacket(int[] data) { + ZstackProtocolHandler handler = new ZstackProtocolHandler(null); + byte[] bytedata = new byte[data.length]; + int cnt = 0; + for (int value : data) { + bytedata[cnt++] = (byte) value; + } + ByteArrayInputStream stream = new ByteArrayInputStream(bytedata); + ZigBeePort port = new TestPort(stream, null); + + Method privateMethod; + try { + Field field = handler.getClass().getDeclaredField("port"); + field.setAccessible(true); + field.set(handler, port); + + privateMethod = ZstackProtocolHandler.class.getDeclaredMethod("getPacket"); + privateMethod.setAccessible(true); + + return (int[]) privateMethod.invoke(handler); + } catch (NoSuchMethodException | SecurityException | IllegalArgumentException | IllegalAccessException + | InvocationTargetException | NoSuchFieldException e) { + e.printStackTrace(); + } + + return null; + } + + @Test + public void testReceivePacket() { + int[] response = getPacket(new int[] { 0xFE, 0x02, 0x61, 0x01, 0x12, 0x34, 0x44 }); + assertTrue(Arrays.equals(response, new int[] { 0x61, 0x01, 0x12, 0x34 })); + } + + @Test + public void testReceivePacketLeadingRubbish() { + int[] response = getPacket(new int[] { 0x00, 0x12, 0xFE, 0x02, 0x61, 0x01, 0x12, 0x34, 0x44 }); + assertTrue(Arrays.equals(response, new int[] { 0x61, 0x01, 0x12, 0x34 })); + } + + @Test + public void isSynchronous() throws NoSuchMethodException, SecurityException, IllegalAccessException, + IllegalArgumentException, InvocationTargetException { + ZstackProtocolHandler handler = new ZstackProtocolHandler(null); + + assertTrue((boolean) TestUtilities.invokeMethod(ZstackProtocolHandler.class, handler, "isSynchronous", + int.class, 0x61)); + assertTrue((boolean) TestUtilities.invokeMethod(ZstackProtocolHandler.class, handler, "isSynchronous", + int.class, 0x22)); + assertFalse((boolean) TestUtilities.invokeMethod(ZstackProtocolHandler.class, handler, "isSynchronous", + int.class, 0x01)); + assertFalse((boolean) TestUtilities.invokeMethod(ZstackProtocolHandler.class, handler, "isSynchronous", + int.class, 0x42)); + } + + class TestPort implements ZigBeePort { + InputStream input; + List outputData = new ArrayList<>(); + + TestPort(InputStream input, OutputStream output) { + this.input = input; + } + + @Override + public boolean open() { + return true; + } + + @Override + public void close() { + } + + @Override + public void write(int value) { + outputData.add(value); + } + + @Override + public void write(int[] bytes) { + for (int b: bytes) { + outputData.add(b); + } + } + + @Override + public int read(int timeout) { + return read(); + } + + @Override + public int read() { + if (input == null) { + return -1; + } + try { + return input.read(); + } catch (IOException e) { + return -1; + } + } + + @Override + public boolean open(int baudRate) { + return false; + } + + @Override + public boolean open(int baudRate, FlowControl flowControl) { + return false; + } + + @Override + public void purgeRxBuffer() { + } + + @Override + public void setDtr(boolean state) { + } + + @Override + public void setRts(boolean state) { + } + + public List getOutputData() { + return outputData; + } + } + +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/internal/serializer/ZstackDeserializerTest.java b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/internal/serializer/ZstackDeserializerTest.java new file mode 100644 index 0000000000..d5d37e7d42 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/internal/serializer/ZstackDeserializerTest.java @@ -0,0 +1,53 @@ +/** + * 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.dongle.zstack.internal.serializer; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import com.zsmartsystems.zigbee.IeeeAddress; + +/** + * + * @author Chris Jackson + * + */ +public class ZstackDeserializerTest { + + @Test + public void deserializeUInt16() { + ZstackDeserializer response = new ZstackDeserializer(new int[] { 0x34, 0x12 }); + + assertEquals(0x1234, response.deserializeUInt16()); + } + + @Test + public void deserializeUInt32() { + ZstackDeserializer response = new ZstackDeserializer(new int[] { 0x78, 0x56, 0x34, 0x12 }); + + assertEquals(0x12345678, response.deserializeUInt32()); + } + + @Test + public void deserializeBoolean() { + ZstackDeserializer response = new ZstackDeserializer(new int[] { 0x00, 0x01 }); + + assertEquals(false, response.deserializeBoolean()); + assertEquals(true, response.deserializeBoolean()); + } + + @Test + public void deserializeIeeeAddress() { + ZstackDeserializer response = new ZstackDeserializer( + new int[] { 0xEF, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12 }); + + assertEquals(new IeeeAddress("1234567890ABCDEF"), response.deserializeIeeeAddress()); + } + +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/internal/serializer/ZstackSerializerTest.java b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/internal/serializer/ZstackSerializerTest.java new file mode 100644 index 0000000000..b4c82c6325 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/internal/serializer/ZstackSerializerTest.java @@ -0,0 +1,58 @@ +/** + * 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.dongle.zstack.internal.serializer; + +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; + +import org.junit.Test; + +import com.zsmartsystems.zigbee.IeeeAddress; + +/** + * + * @author Chris Jackson + * + */ +public class ZstackSerializerTest { + + @Test + public void deserializeUInt16() { + ZstackSerializer request = new ZstackSerializer(); + request.serializeUInt16(0x1234); + + assertTrue(Arrays.equals(new int[] { 0x34, 0x12 }, request.getBuffer())); + } + + @Test + public void serializeUInt32() { + ZstackSerializer request = new ZstackSerializer(); + request.serializeUInt32(0x12345678); + + assertTrue(Arrays.equals(new int[] { 0x78, 0x56, 0x34, 0x12 }, request.getBuffer())); + } + + @Test + public void serializeIeeeAddress() { + ZstackSerializer request = new ZstackSerializer(); + IeeeAddress address = new IeeeAddress("1234567890ABCDEF"); + request.serializeIeeeAddress(address); + + assertTrue(Arrays.equals(new int[] { 0xEF, 0xCD, 0xAB, 0x90, 0x78, 0x56, 0x34, 0x12 }, request.getBuffer())); + } + + @Test + public void serializeBoolean() { + ZstackSerializer request = new ZstackSerializer(); + request.serializeBoolean(false); + request.serializeBoolean(true); + + assertTrue(Arrays.equals(new int[] { 0x00, 0x01 }, request.getBuffer())); + } +} diff --git a/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/internal/transaction/ZstackSingleResponseTransactionTest.java b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/internal/transaction/ZstackSingleResponseTransactionTest.java new file mode 100644 index 0000000000..5d31ea4234 --- /dev/null +++ b/com.zsmartsystems.zigbee.dongle.zstack/src/test/java/com/zsmartsystems/zigbee/dongle/zstack/internal/transaction/ZstackSingleResponseTransactionTest.java @@ -0,0 +1,64 @@ +/** + * 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.dongle.zstack.internal.transaction; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilLedControlSreq; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilLedControlSrsp; +import com.zsmartsystems.zigbee.dongle.zstack.api.util.ZstackUtilSetChannelsSrsp; + +/** + * + * @author Chris Jackson + * + */ +public class ZstackSingleResponseTransactionTest { + @Test + public void testResponseMatches() { + ZstackUtilLedControlSreq request = new ZstackUtilLedControlSreq(); + request.setLedId(1); + request.setMode(false); + System.out.println(request); + + ZstackTransaction transaction = new ZstackSingleResponseTransaction(request, ZstackUtilLedControlSrsp.class); + + ZstackUtilLedControlSrsp response = new ZstackUtilLedControlSrsp(new int[] { 0x00, 0x00, 0x34, 0x12 }); + System.out.println(response); + + assertTrue(transaction.isMatch(response)); + + assertEquals(request, transaction.getRequest()); + assertNotNull(transaction.getResponse()); + assertEquals(response, transaction.getResponse()); + } + + @Test + public void testResponseMatchFails() { + ZstackUtilLedControlSreq request = new ZstackUtilLedControlSreq(); + request.setLedId(1); + request.setMode(false); + System.out.println(request); + + ZstackTransaction transaction = new ZstackSingleResponseTransaction(request, ZstackUtilLedControlSrsp.class); + + ZstackUtilSetChannelsSrsp response = new ZstackUtilSetChannelsSrsp(new int[] { 0x00, 0x00, 0x34, 0x12 }); + System.out.println(response); + + assertFalse(transaction.isMatch(response)); + + assertEquals(request, transaction.getRequest()); + assertNull(transaction.getResponse()); + } +} diff --git a/com.zsmartsystems.zigbee.serial/src/main/java/com/zsmartsystems/zigbee/serial/ZigBeeSerialPort.java b/com.zsmartsystems.zigbee.serial/src/main/java/com/zsmartsystems/zigbee/serial/ZigBeeSerialPort.java index 3a2b61ad77..5bb98901b6 100644 --- a/com.zsmartsystems.zigbee.serial/src/main/java/com/zsmartsystems/zigbee/serial/ZigBeeSerialPort.java +++ b/com.zsmartsystems.zigbee.serial/src/main/java/com/zsmartsystems/zigbee/serial/ZigBeeSerialPort.java @@ -273,19 +273,21 @@ public void purgeRxBuffer() { } } - public boolean setDtr(boolean state) { + @Override + public void setDtr(boolean state) { try { - return serialPort.setDTR(state); + serialPort.setDTR(state); } catch (SerialPortException e) { - return false; + logger.warn("Could not set DTR to {} on {}", state, this.portName, e); } } - public boolean setRts(boolean state) { + @Override + public void setRts(boolean state) { try { - return serialPort.setRTS(state); + serialPort.setRTS(state); } catch (SerialPortException e) { - return false; + logger.warn("Could not set RTS to {} on {}", state, this.portName, e); } } } \ No newline at end of file diff --git a/com.zsmartsystems.zigbee/src/main/java/com/zsmartsystems/zigbee/transport/ZigBeePort.java b/com.zsmartsystems.zigbee/src/main/java/com/zsmartsystems/zigbee/transport/ZigBeePort.java index f7cc20cac0..b25fe2a3f1 100644 --- a/com.zsmartsystems.zigbee/src/main/java/com/zsmartsystems/zigbee/transport/ZigBeePort.java +++ b/com.zsmartsystems.zigbee/src/main/java/com/zsmartsystems/zigbee/transport/ZigBeePort.java @@ -85,6 +85,16 @@ public interface ZigBeePort { */ void purgeRxBuffer(); + /** + * Set DTR on Port + */ + void setDtr(boolean state); + + /** + * Set DTS on Port + */ + void setRts(boolean state); + /** * Enumeration of flow control options */ diff --git a/pom.xml b/pom.xml index e6287a77d1..ca769cc84f 100644 --- a/pom.xml +++ b/pom.xml @@ -76,10 +76,13 @@ com.zsmartsystems.zigbee.dongle.conbee com.zsmartsystems.zigbee.dongle.telegesis com.zsmartsystems.zigbee.dongle.telegesis.autocode + com.zsmartsystems.zigbee.dongle.zstack + com.zsmartsystems.zigbee.dongle.zstack.autocode com.zsmartsystems.zigbee.console com.zsmartsystems.zigbee.console.ember com.zsmartsystems.zigbee.console.main com.zsmartsystems.zigbee.console.telegesis + com.zsmartsystems.zigbee.console.zstack com.zsmartsystems.zigbee.serial com.zsmartsystems.zigbee.test releng/p2repo