Skip to content

Commit

Permalink
Split client/server attributes and refactor ZCL attribute read/write …
Browse files Browse the repository at this point in the history
…methods

Signed-off-by: Chris Jackson <[email protected]>
  • Loading branch information
cdjackson committed Apr 20, 2019
1 parent f39ef94 commit 37ca2fd
Show file tree
Hide file tree
Showing 458 changed files with 12,741 additions and 7,327 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The following clusters are currently supported -:
| 0202 | FAN_CONTROL | This cluster specifies an interface to control the speed of a fan as part of a heating / cooling system. |
| 0203 | DEHUMIDIFICATION_CONTROL | This cluster provides an interface to dehumidification functionality. |
| 0204 | THERMOSTAT_USER_INTERFACE_CONFIGURATION | This cluster provides an interface to allow configuration of the user interface for a thermostat, or a thermostat controller device, that supports a keypad and LCD screen. |
| 0300 | COLOR_CONTROL | This cluster provides an interface for changing the color of a light. Color is specified according to the Commission Internationale de l'Éclairage (CIE) specification CIE 1931 Color Space, [B4]. Color control is carried out in terms of x,y values, as defined by this specification. |
| 0300 | COLOR_CONTROL | This cluster provides an interface for changing the color of a light. Color is specified according to the Commission Internationale de l'Éclairage (CIE) specification CIE 1931 Color Space. Color control is carried out in terms of x,y values, as defined by this specification. |
| 0400 | ILLUMINANCE_MEASUREMENT | The cluster provides an interface to illuminance measurement functionality, including configuration and provision of notifications of illuminance measurements. |
| 0401 | ILLUMINANCE_LEVEL_SENSING | The cluster provides an interface to illuminance level sensing functionality, including configuration and provision of notifications of whether the illuminance is within, above or below a target band. |
| 0402 | TEMPERATURE_MEASUREMENT | The server cluster provides an interface to temperature measurement functionality, including configuration and provision of notifications of temperature measurements. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public abstract class ZigBeeBaseClassGenerator {
standardTypes.add("Boolean");
standardTypes.add("Object");
standardTypes.add("Long");
standardTypes.add("Double");
standardTypes.add("String");
standardTypes.add("int[]");

Expand Down Expand Up @@ -390,6 +391,24 @@ protected void outputAttributeJavaDoc(PrintWriter out, String type, ZigBeeXmlAtt
} else {
out.println(" * @return the {@link Future<CommandResult>} command result future");
}

String replacedBy;
if ("Set reporting for".equals(type)) {
replacedBy = "setReporting(int attributeId, int minInterval, int maxInterval";
if (zclDataType.analogue) {
replacedBy += ", Object reportableChange";
}
} else if (type.contains("Set")) {
replacedBy = "writeAttribute(int attributeId, Object value";
} else if ("Synchronously get".equals(type)) {
replacedBy = "readAttributeValue(int attributeId, long refreshPeriod";
} else {
replacedBy = "readAttribute(int attributeId";
}
replacedBy += ")";

out.println(" * @deprecated As of release 1.2.0, replaced by {@link #" + replacedBy + "}");

out.println(" */");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -84,19 +85,19 @@ private void generateZclClusterClasses(ZigBeeXmlCluster cluster, String packageR
boolean addAttributeTypes = false;
boolean readAttributes = false;
boolean writeAttributes = false;
int attributesServer = 0;
int attributesClient = 0;
List<ZigBeeXmlAttribute> attributesClient = new ArrayList<>();
List<ZigBeeXmlAttribute> attributesServer = new ArrayList<>();
for (final ZigBeeXmlAttribute attribute : cluster.attributes) {
if (attribute.writable) {
addAttributeTypes = true;
writeAttributes = true;
}
readAttributes = true;
if (attribute.side.equals("server")) {
attributesServer++;
attributesServer.add(attribute);
}
if (attribute.side.equals("client")) {
attributesClient++;
attributesClient.add(attribute);
}

importsAddClass(attribute);
Expand All @@ -107,7 +108,7 @@ private void generateZclClusterClasses(ZigBeeXmlCluster cluster, String packageR
}

importsAdd(packageRoot + packageZcl + ".ZclCluster");
if (attributesServer > 0) {
if (attributesServer.size() > 0) {
importsAdd(packageRoot + packageZclProtocol + ".ZclDataType");
importsAdd(packageRoot + packageZclProtocol + ".ZclClusterType");
}
Expand Down Expand Up @@ -190,35 +191,13 @@ private void generateZclClusterClasses(ZigBeeXmlCluster cluster, String packageR
}

out.println(" @Override");
out.println(" protected Map<Integer, ZclAttribute> initializeAttributes() {");
out.println(
" Map<Integer, ZclAttribute> attributeMap = new ConcurrentHashMap<>(" + attributesServer + ");");

if (attributesServer != 0) {
out.println();
for (final ZigBeeXmlAttribute attribute : cluster.attributes) {
if (!attribute.side.equalsIgnoreCase("server")) {
continue;
}

if (attribute.arrayStart != null && attribute.arrayCount != null && attribute.arrayCount > 0) {
int arrayCount = attribute.arrayStart;
int arrayStep = attribute.arrayStep == null ? 1 : attribute.arrayStep;
for (int count = 0; count < attribute.arrayCount; count++) {
String name = attribute.name.replaceAll("\\{\\{count\\}\\}", Integer.toString(arrayCount));
out.println(" attributeMap.put(" + getEnum(name) + ", "
+ defineAttribute(attribute, cluster.name, name, 0) + ");");
arrayCount += arrayStep;
}
} else {
out.println(" attributeMap.put(" + getEnum(attribute.name) + ", "
+ defineAttribute(attribute, cluster.name, attribute.name, 0) + ");");
}
}
}
out.println(" protected Map<Integer, ZclAttribute> initializeClientAttributes() {");
createInitializeAttributes(out, cluster.name, attributesClient);
out.println();
out.println(" return attributeMap;");
out.println(" }");

out.println(" @Override");
out.println(" protected Map<Integer, ZclAttribute> initializeServerAttributes() {");
createInitializeAttributes(out, cluster.name, attributesServer);
out.println();

// TODO: Add client attributes
Expand Down Expand Up @@ -271,6 +250,10 @@ private void generateZclClusterClasses(ZigBeeXmlCluster cluster, String packageR
out.println(" }");

for (final ZigBeeXmlAttribute attribute : cluster.attributes) {
if (attribute.side.equals("client")) {
continue;
}

DataTypeMap zclDataType = ZclDataType.getDataTypeMapping().get(attribute.type);
if (zclDataType == null) {
throw new IllegalArgumentException(
Expand All @@ -281,15 +264,18 @@ private void generateZclClusterClasses(ZigBeeXmlCluster cluster, String packageR
outputAttributeJavaDoc(out, "Set", attribute, zclDataType);
if (attribute.arrayStart != null && attribute.arrayCount != null && attribute.arrayCount > 0) {
String name = attribute.name.replaceAll("\\{\\{count\\}\\}", "");
out.println(" @Deprecated");
out.println(" public Future<CommandResult> set" + stringToUpperCamelCase(name).replace("_", "")
+ "(final int arrayOffset, final " + getDataTypeClass(attribute) + " value) {");
name = attribute.name.replaceAll("\\{\\{count\\}\\}", Integer.toString(attribute.arrayStart));
out.println(" return write(attributes.get(" + getEnum(name) + " + arrayOffset), value);");
out.println(
" return write(serverAttributes.get(" + getEnum(name) + " + arrayOffset), value);");
} else {
out.println(" @Deprecated");
out.println(" public Future<CommandResult> set"
+ stringToUpperCamelCase(attribute.name).replace("_", "") + "(final "
+ getDataTypeClass(attribute) + " value) {");
out.println(" return write(attributes.get(" + getEnum(attribute.name) + "), value);");
out.println(" return write(serverAttributes.get(" + getEnum(attribute.name) + "), value);");
}
out.println(" }");
}
Expand All @@ -298,6 +284,7 @@ private void generateZclClusterClasses(ZigBeeXmlCluster cluster, String packageR
outputAttributeJavaDoc(out, "Get", attribute, zclDataType);
if (attribute.arrayStart != null && attribute.arrayCount != null && attribute.arrayCount > 0) {
String name = attribute.name.replaceAll("\\{\\{count\\}\\}", "");
out.println(" @Deprecated");
out.println(" public Future<CommandResult> get" + stringToUpperCamelCase(name).replace("_", "")
+ "Async(final int arrayOffset) {");
out.println(" if (arrayOffset < " + attribute.arrayStart + " || arrayOffset > "
Expand All @@ -306,40 +293,43 @@ private void generateZclClusterClasses(ZigBeeXmlCluster cluster, String packageR
out.println(" }");
out.println();
name = attribute.name.replaceAll("\\{\\{count\\}\\}", Integer.toString(attribute.arrayStart));
out.println(" return read(attributes.get(" + getEnum(name) + " + arrayOffset));");
out.println(" return read(serverAttributes.get(" + getEnum(name) + " + arrayOffset));");
} else {
out.println(" @Deprecated");
out.println(" public Future<CommandResult> get"
+ stringToUpperCamelCase(attribute.name).replace("_", "") + "Async() {");
out.println(" return read(attributes.get(" + getEnum(attribute.name) + "));");
out.println(" return read(serverAttributes.get(" + getEnum(attribute.name) + "));");
}
out.println(" }");

// TODO: Needs to document the counter
outputAttributeJavaDoc(out, "Synchronously get", attribute, zclDataType);
if (attribute.arrayStart != null && attribute.arrayCount != null && attribute.arrayCount > 0) {
String name = attribute.name.replaceAll("\\{\\{count\\}\\}", "");
out.println(" @Deprecated");
out.println(" public " + getDataTypeClass(attribute) + " get"
+ stringToUpperCamelCase(name).replace("_", "")
+ "(final int arrayOffset, final long refreshPeriod) {");
name = attribute.name.replaceAll("\\{\\{count\\}\\}", Integer.toString(attribute.arrayStart));
out.println(" if (attributes.get(" + getEnum(name) + " + arrayOffset"
out.println(" if (serverAttributes.get(" + getEnum(name) + " + arrayOffset"
+ ").isLastValueCurrent(refreshPeriod)) {");
out.println(" return (" + getDataTypeClass(attribute) + ") attributes.get(" + getEnum(name)
+ " + arrayOffset).getLastValue();");
out.println(" return (" + getDataTypeClass(attribute) + ") serverAttributes.get("
+ getEnum(name) + " + arrayOffset).getLastValue();");
out.println(" }");
out.println();
out.println(" return (" + getDataTypeClass(attribute) + ") readSync(attributes.get("
out.println(" return (" + getDataTypeClass(attribute) + ") readSync(serverAttributes.get("
+ getEnum(name) + " + arrayOffset));");
} else {
out.println(" @Deprecated");
out.println(" public " + getDataTypeClass(attribute) + " get"
+ stringToUpperCamelCase(attribute.name).replace("_", "") + "(final long refreshPeriod) {");
out.println(" if (attributes.get(" + getEnum(attribute.name)
out.println(" if (serverAttributes.get(" + getEnum(attribute.name)
+ ").isLastValueCurrent(refreshPeriod)) {");
out.println(" return (" + getDataTypeClass(attribute) + ") attributes.get("
out.println(" return (" + getDataTypeClass(attribute) + ") serverAttributes.get("
+ getEnum(attribute.name) + ").getLastValue();");
out.println(" }");
out.println();
out.println(" return (" + getDataTypeClass(attribute) + ") readSync(attributes.get("
out.println(" return (" + getDataTypeClass(attribute) + ") readSync(serverAttributes.get("
+ getEnum(attribute.name) + "));");
}
out.println(" }");
Expand All @@ -358,26 +348,30 @@ private void generateZclClusterClasses(ZigBeeXmlCluster cluster, String packageR
}

if (zclDataType.analogue) {
out.println(" @Deprecated");
out.println(" public Future<CommandResult> set" + stringToUpperCamelCase(name)
+ "Reporting(final int arrayOffset, final int minInterval, final int maxInterval, final Object reportableChange) {");
out.println(" return setReporting(attributes.get(" + getEnum(name) + " + " + offset
out.println(" return setReporting(serverAttributes.get(" + getEnum(name) + " + " + offset
+ "), minInterval, maxInterval, reportableChange);");
} else {
out.println(" @Deprecated");
out.println(" public Future<CommandResult> set" + stringToUpperCamelCase(name)
+ "Reporting(final int arrayOffset, final int minInterval, final int maxInterval) {");
out.println(" return setReporting(attributes.get(" + getEnum(name) + " + " + offset
out.println(" return setReporting(serverAttributes.get(" + getEnum(name) + " + " + offset
+ "), minInterval, maxInterval);");
}
} else {
if (zclDataType.analogue) {
out.println(" @Deprecated");
out.println(" public Future<CommandResult> set" + stringToUpperCamelCase(attribute.name)
+ "Reporting(final int minInterval, final int maxInterval, final Object reportableChange) {");
out.println(" return setReporting(attributes.get(" + getEnum(attribute.name)
out.println(" return setReporting(serverAttributes.get(" + getEnum(attribute.name)
+ "), minInterval, maxInterval, reportableChange);");
} else {
out.println(" @Deprecated");
out.println(" public Future<CommandResult> set" + stringToUpperCamelCase(attribute.name)
+ "Reporting(final int minInterval, final int maxInterval) {");
out.println(" return setReporting(attributes.get(" + getEnum(attribute.name)
out.println(" return setReporting(serverAttributes.get(" + getEnum(attribute.name)
+ "), minInterval, maxInterval);");
}
}
Expand Down Expand Up @@ -439,6 +433,37 @@ private void generateZclClusterClasses(ZigBeeXmlCluster cluster, String packageR
out.close();
}

private void createInitializeAttributes(PrintWriter out, String clusterName, List<ZigBeeXmlAttribute> attributes) {
out.println(" Map<Integer, ZclAttribute> attributeMap = new ConcurrentHashMap<>(" + attributes.size()
+ ");");

if (attributes.size() != 0) {
out.println();
for (final ZigBeeXmlAttribute attribute : attributes) {
if (!attribute.side.equalsIgnoreCase("server")) {
continue;
}

if (attribute.arrayStart != null && attribute.arrayCount != null && attribute.arrayCount > 0) {
int arrayCount = attribute.arrayStart;
int arrayStep = attribute.arrayStep == null ? 1 : attribute.arrayStep;
for (int count = 0; count < attribute.arrayCount; count++) {
String name = attribute.name.replaceAll("\\{\\{count\\}\\}", Integer.toString(arrayCount));
out.println(" attributeMap.put(" + getEnum(name) + ", "
+ defineAttribute(attribute, clusterName, name, 0) + ");");
arrayCount += arrayStep;
}
} else {
out.println(" attributeMap.put(" + getEnum(attribute.name) + ", "
+ defineAttribute(attribute, clusterName, attribute.name, 0) + ");");
}
}
}
out.println();
out.println(" return attributeMap;");
out.println(" }");
}

private String defineAttribute(ZigBeeXmlAttribute attribute, String clusterName, String attributeName, int count) {
return "new ZclAttribute(ZclClusterType." + stringToConstant(clusterName) + ", " + getEnum(attributeName)
+ ", \"" + attributeName + "\", " + "ZclDataType." + attribute.type + ", " + !attribute.optional + ", "
Expand Down
Loading

0 comments on commit 37ca2fd

Please sign in to comment.