Skip to content

Commit

Permalink
Update ZclAttribute to add new methods and constructor
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Jackson <[email protected]>
  • Loading branch information
cdjackson committed Apr 20, 2019
1 parent 37ca2fd commit 5c4c587
Show file tree
Hide file tree
Showing 49 changed files with 2,731 additions and 2,629 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ protected void outputWithLinebreak(PrintWriter out, String indent, List<ZigBeeXm
len += word.length();
}

if (len != 0) {
if (len != 2 + indent.length()) {
out.println();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ protected void generateFields(PrintWriter out, String parentClass, String classN
+ ") deserializer.deserialize(" + "ZclDataType." + field.type + ");");
out.println(" }");
} else {
if (field.type != null && !field.type.isEmpty()) {
if (!field.type.isEmpty()) {
out.println(" " + stringToLowerCamelCase(field.name) + " = (" + getDataTypeClass(field)
+ ") deserializer.deserialize(" + "ZclDataType." + field.type + ");");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private void generateZclClusterClasses(ZigBeeXmlCluster cluster, String packageR
importsAdd(packageRoot + packageZcl + ".ZclCluster");
if (attributesServer.size() > 0) {
importsAdd(packageRoot + packageZclProtocol + ".ZclDataType");
importsAdd(packageRoot + packageZclProtocol + ".ZclClusterType");
// importsAdd(packageRoot + packageZclProtocol + ".ZclClusterType");
}

if (!cluster.commands.isEmpty()) {
Expand Down Expand Up @@ -465,9 +465,9 @@ private void createInitializeAttributes(PrintWriter out, String clusterName, Lis
}

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 + ", "
+ true + ", " + attribute.writable + ", " + attribute.reportable + ")";
return "new ZclAttribute(this, " + getEnum(attributeName) + ", \"" + attributeName + "\", " + "ZclDataType."
+ attribute.type + ", " + !attribute.optional + ", " + true + ", " + attribute.writable + ", "
+ attribute.reportable + ")";
}

private String getEnum(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
package com.zsmartsystems.zigbee.zcl;

import java.util.Calendar;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

import com.zsmartsystems.zigbee.zcl.clusters.ZclOnOffCluster;
import com.zsmartsystems.zigbee.CommandResult;
import com.zsmartsystems.zigbee.zcl.protocol.ZclClusterType;
import com.zsmartsystems.zigbee.zcl.protocol.ZclDataType;

Expand All @@ -23,7 +25,7 @@ public class ZclAttribute {
/**
*
*/
private final ZclClusterType cluster;
private final ZclCluster cluster;

/**
* The attribute identifier field is 16-bits in length and shall contain the
Expand Down Expand Up @@ -116,15 +118,15 @@ public class ZclAttribute {
/**
* Constructor used to set the static information
*
* @param cluster
* @param id
* @param dataType
* @param mandatory
* @param readable
* @param writeable
* @param reportable
*/
public ZclAttribute(final ZclClusterType cluster, final int id, final String name, final ZclDataType dataType,
* @param cluster the {@link ZclCluster} to which the attribute belongs
* @param id the attribute ID
* @param dataType the {@link ZclDataType} for this attribute
* @param mandatory true if this is defined as mandatory in the ZCL specification
* @param readable true if this is defined as readable in the ZCL specification
* @param writeable true if this is defined as writable in the ZCL specification
* @param reportable true if this is defined as reportable in the ZCL specification
*/
public ZclAttribute(final ZclCluster cluster, final int id, final String name, final ZclDataType dataType,
final boolean mandatory, final boolean readable, final boolean writeable, final boolean reportable) {
this.cluster = cluster;
this.id = id;
Expand All @@ -136,12 +138,24 @@ public ZclAttribute(final ZclClusterType cluster, final int id, final String nam
this.reportable = reportable;
}

/**
* Returns the value of the attribute. If the current value is newer than refreshPeriod (in milliseconds) then the
* current value will be returned, otherwise the value will be requested from the remote device.
*
* @param refreshPeriod the number of milliseconds to consider the value current
* @return an Object with the attribute value, or null on error
*/
public Object readValue(long refreshPeriod) {
// if()
ZclCluster cluster = new ZclOnOffCluster(null);
if (isLastValueCurrent(refreshPeriod)) {
return getLastValue();
}

// TODO!!!!!!!!!!!
return cluster.readAttribute(id);
try {
return cluster.readAttribute(id).get();
} catch (InterruptedException | ExecutionException e) {
// Eat me!
}
return null;
}

/**
Expand All @@ -150,7 +164,7 @@ public Object readValue(long refreshPeriod) {
* @return the {@link ZclClusterType} for this attribute
*/
public ZclClusterType getCluster() {
return cluster;
return ZclClusterType.getValueById(cluster.getClusterId());
}

/**
Expand Down Expand Up @@ -297,6 +311,64 @@ public Calendar getLastReportTime() {
return lastReportTime;
}

/**
* Configures the reporting for the specified attribute ID for analog attributes.
* <p>
* <b>minInterval</b>:
* The minimum reporting interval field is 16 bits in length and shall contain the
* minimum interval, in seconds, between issuing reports of the specified attribute.
* If minInterval is set to 0x0000, then there is no minimum limit, unless one is
* imposed by the specification of the cluster using this reporting mechanism or by
* the applicable profile.
* <p>
* <b>maxInterval</b>:
* The maximum reporting interval field is 16 bits in length and shall contain the
* maximum interval, in seconds, between issuing reports of the specified attribute.
* If maxInterval is set to 0xffff, then the device shall not issue reports for the specified
* attribute, and the configuration information for that attribute need not be
* maintained.
* <p>
* <b>reportableChange</b>:
* The reportable change field shall contain the minimum change to the attribute that
* will result in a report being issued. This field is of variable length. For attributes
* with 'analog' data type the field has the same data type as the attribute. The sign (if any) of the reportable
* change field is ignored.
*
* @param minInterval the minimum reporting interval
* @param maxInterval the maximum reporting interval
* @param reportableChange the minimum change required to report an update
* @return command future {@link CommandResult}
*/
public Future<CommandResult> setReporting(final int minInterval, final int maxInterval,
final Object reportableChange) {
return cluster.setReporting(id, minInterval, maxInterval, reportableChange);
}

/**
* Configures the reporting for the specified attribute ID for discrete attributes.
* <p>
* <b>minInterval</b>:
* The minimum reporting interval field is 16 bits in length and shall contain the
* minimum interval, in seconds, between issuing reports of the specified attribute.
* If minInterval is set to 0x0000, then there is no minimum limit, unless one is
* imposed by the specification of the cluster using this reporting mechanism or by
* the applicable profile.
* <p>
* <b>maxInterval</b>:
* The maximum reporting interval field is 16 bits in length and shall contain the
* maximum interval, in seconds, between issuing reports of the specified attribute.
* If maxInterval is set to 0xffff, then the device shall not issue reports for the specified
* attribute, and the configuration information for that attribute need not be
* maintained.
*
* @param minInterval the minimum reporting interval
* @param maxInterval the maximum reporting interval
* @return command future {@link CommandResult}
*/
public Future<CommandResult> setReporting(final int minInterval, final int maxInterval) {
return cluster.setReporting(id, minInterval, maxInterval);
}

/**
* Checks if the last value received for the attribute is still current.
* If the last update time is more recent than the allowedAge then this will return true. allowedAge is defined in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
*/
package com.zsmartsystems.zigbee.zcl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeSet;
import java.util.concurrent.Callable;
Expand Down Expand Up @@ -293,22 +291,10 @@ public Future<CommandResult> writeAttribute(final int attribute, final ZclDataTy
/**
* Writes a number of attributes in a single command
*
* @param attributes a Map of {@link ZclAttribute}s and their values
* @param attributes a List of {@link WriteAttributeRecord}s with the attribute ID, type and value
* @return command future {@link CommandResult}
*/
public Future<CommandResult> writeAttributes(final Map<ZclAttribute, Object> attributes) {
List<WriteAttributeRecord> attributeRecords = new ArrayList<>();
for (Entry<ZclAttribute, Object> attribute : attributes.entrySet()) {
final WriteAttributeRecord attributeIdentifier = new WriteAttributeRecord();
attributeIdentifier.setAttributeIdentifier(attribute.getKey().getId());
attributeIdentifier.setAttributeDataType(attribute.getKey().getDataType());
attributeIdentifier.setAttributeValue(attribute.getValue());
}

return writeAttributes(attributeRecords);
}

private Future<CommandResult> writeAttributes(List<WriteAttributeRecord> attributes) {
public Future<CommandResult> writeAttributes(List<WriteAttributeRecord> attributes) {
final WriteAttributesCommand command = new WriteAttributesCommand();
command.setClusterId(clusterId);
command.setRecords(attributes);
Expand Down Expand Up @@ -958,9 +944,9 @@ public void handleAttributeReport(List<AttributeReport> reports) {
public void handleAttributeStatus(List<ReadAttributeStatusRecord> records) {
for (ReadAttributeStatusRecord record : records) {
if (record.getStatus() != ZclStatus.SUCCESS) {
logger.debug("{}: Error reading attribute {} in cluster {} - {}", zigbeeEndpoint.getEndpointAddress(),
(isClient ? "Client" : "Server"), record.getAttributeIdentifier(), clusterId,
record.getStatus());
logger.debug("{}: Error reading attribute {} in {} cluster {} - {}",
zigbeeEndpoint.getEndpointAddress(), (isClient ? "Client" : "Server"),
record.getAttributeIdentifier(), clusterId, record.getStatus());
continue;
}

Expand Down Expand Up @@ -1164,7 +1150,7 @@ public Future<CommandResult> read(final int attribute) {
*
* @param attribute the {@link ZclAttribute} to read
* @return command future
* @deprecated from 1.2.0 use {@link #read(ZclAttribute)}. Method will be removed in 1.3.0.
* @deprecated from 1.2.0 use {@link #readAttribute(ZclAttribute)}. Method will be removed in 1.3.0.
*/
@Deprecated
public Future<CommandResult> read(final ZclAttribute attribute) {
Expand Down Expand Up @@ -1212,7 +1198,8 @@ public Future<CommandResult> read(final List<Integer> attributes) {
* @param maxInterval the maximum reporting interval
* @param reportableChange the minimum change required to report an update
* @return command future {@link CommandResult}
* @deprecated from 1.2.0 use {@link ZclAttribute.setReporting} methods. This will be removed in 1.3.0
* @deprecated from 1.2.0 use {@link ZclCluster#setReporting(int, int, int, Object)} or
* {@link ZclAttribute.setReporting} methods. This will be removed in 1.3.0
*/
@Deprecated
public Future<CommandResult> setReporting(final ZclAttribute attribute, final int minInterval,
Expand Down Expand Up @@ -1255,7 +1242,8 @@ public Future<CommandResult> setReporting(final ZclAttribute attribute, final in
* @param minInterval the minimum reporting interval
* @param maxInterval the maximum reporting interval
* @return command future {@link CommandResult}
* @deprecated from 1.2.0 use {@link ZclAttribute.setReporting} methods. This will be removed in 1.3.0
* @deprecated from 1.2.0 use {@link ZclCluster#setReporting(int, int, int)} or {@link ZclAttribute.setReporting}
* methods. This will be removed in 1.3.0
*/
@Deprecated
public Future<CommandResult> setReporting(final ZclAttribute attribute, final int minInterval,
Expand All @@ -1268,7 +1256,7 @@ public Future<CommandResult> setReporting(final ZclAttribute attribute, final in
*
* @param attribute the {@link ZclAttribute} on which to get the reporting configuration
* @return command future {@link CommandResult}
* @deprecated from 1.2.0 use {@link ZclAttribute.getReporting} method. This will be removed in 1.3.0
* @deprecated from 1.2.0 use {@link ZclAttribute.getReporting} methods. This will be removed in 1.3.0
*/
@Deprecated
public Future<CommandResult> getReporting(final ZclAttribute attribute) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.zsmartsystems.zigbee.zcl.clusters.alarms.ResetAlarmCommand;
import com.zsmartsystems.zigbee.zcl.clusters.alarms.ResetAlarmLogCommand;
import com.zsmartsystems.zigbee.zcl.clusters.alarms.ResetAllAlarmsCommand;
import com.zsmartsystems.zigbee.zcl.protocol.ZclClusterType;
import com.zsmartsystems.zigbee.zcl.protocol.ZclDataType;

/**
Expand All @@ -45,7 +44,7 @@
* <p>
* Code is auto-generated. Modifications may be overwritten!
*/
@Generated(value = "com.zsmartsystems.zigbee.autocode.ZigBeeCodeGenerator", date = "2019-04-14T09:37:44Z")
@Generated(value = "com.zsmartsystems.zigbee.autocode.ZigBeeCodeGenerator", date = "2019-04-18T19:39:16Z")
public class ZclAlarmsCluster extends ZclCluster {
/**
* The ZigBee Cluster Library Cluster ID
Expand Down Expand Up @@ -78,7 +77,7 @@ protected Map<Integer, ZclAttribute> initializeClientAttributes() {
protected Map<Integer, ZclAttribute> initializeServerAttributes() {
Map<Integer, ZclAttribute> attributeMap = new ConcurrentHashMap<>(1);

attributeMap.put(ATTR_ALARMCOUNT, new ZclAttribute(ZclClusterType.ALARMS, ATTR_ALARMCOUNT, "Alarm Count", ZclDataType.UNSIGNED_16_BIT_INTEGER, false, true, false, false));
attributeMap.put(ATTR_ALARMCOUNT, new ZclAttribute(this, ATTR_ALARMCOUNT, "Alarm Count", ZclDataType.UNSIGNED_16_BIT_INTEGER, false, true, false, false));

return attributeMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.zsmartsystems.zigbee.ZigBeeEndpoint;
import com.zsmartsystems.zigbee.zcl.ZclAttribute;
import com.zsmartsystems.zigbee.zcl.ZclCluster;
import com.zsmartsystems.zigbee.zcl.protocol.ZclClusterType;
import com.zsmartsystems.zigbee.zcl.protocol.ZclDataType;

/**
Expand All @@ -29,7 +28,7 @@
* <p>
* Code is auto-generated. Modifications may be overwritten!
*/
@Generated(value = "com.zsmartsystems.zigbee.autocode.ZigBeeCodeGenerator", date = "2019-04-14T09:37:44Z")
@Generated(value = "com.zsmartsystems.zigbee.autocode.ZigBeeCodeGenerator", date = "2019-04-18T19:39:16Z")
public class ZclAnalogInputBasicCluster extends ZclCluster {
/**
* The ZigBee Cluster Library Cluster ID
Expand Down Expand Up @@ -168,16 +167,16 @@ protected Map<Integer, ZclAttribute> initializeClientAttributes() {
protected Map<Integer, ZclAttribute> initializeServerAttributes() {
Map<Integer, ZclAttribute> attributeMap = new ConcurrentHashMap<>(10);

attributeMap.put(ATTR_DESCRIPTION, new ZclAttribute(ZclClusterType.ANALOG_INPUT_BASIC, ATTR_DESCRIPTION, "Description", ZclDataType.CHARACTER_STRING, false, true, true, false));
attributeMap.put(ATTR_MAXPRESENTVALUE, new ZclAttribute(ZclClusterType.ANALOG_INPUT_BASIC, ATTR_MAXPRESENTVALUE, "Max Present Value", ZclDataType.FLOAT_32_BIT, false, true, true, false));
attributeMap.put(ATTR_MINPRESENTVALUE, new ZclAttribute(ZclClusterType.ANALOG_INPUT_BASIC, ATTR_MINPRESENTVALUE, "Min Present Value", ZclDataType.FLOAT_32_BIT, false, true, true, false));
attributeMap.put(ATTR_OUTOFSERVICE, new ZclAttribute(ZclClusterType.ANALOG_INPUT_BASIC, ATTR_OUTOFSERVICE, "Out Of Service", ZclDataType.BOOLEAN, false, true, true, false));
attributeMap.put(ATTR_PRESENTVALUE, new ZclAttribute(ZclClusterType.ANALOG_INPUT_BASIC, ATTR_PRESENTVALUE, "Present Value", ZclDataType.FLOAT_32_BIT, false, true, true, false));
attributeMap.put(ATTR_RELIABILITY, new ZclAttribute(ZclClusterType.ANALOG_INPUT_BASIC, ATTR_RELIABILITY, "Reliability", ZclDataType.ENUMERATION_8_BIT, false, true, true, false));
attributeMap.put(ATTR_RESOLUTION, new ZclAttribute(ZclClusterType.ANALOG_INPUT_BASIC, ATTR_RESOLUTION, "Resolution", ZclDataType.FLOAT_32_BIT, false, true, true, false));
attributeMap.put(ATTR_STATUSFLAGS, new ZclAttribute(ZclClusterType.ANALOG_INPUT_BASIC, ATTR_STATUSFLAGS, "Status Flags", ZclDataType.BITMAP_8_BIT, false, true, true, false));
attributeMap.put(ATTR_ENGINEERINGUNITS, new ZclAttribute(ZclClusterType.ANALOG_INPUT_BASIC, ATTR_ENGINEERINGUNITS, "Engineering Units", ZclDataType.ENUMERATION_32_BIT, false, true, true, false));
attributeMap.put(ATTR_APPLICATIONTYPE, new ZclAttribute(ZclClusterType.ANALOG_INPUT_BASIC, ATTR_APPLICATIONTYPE, "Application Type", ZclDataType.SIGNED_32_BIT_INTEGER, false, true, true, false));
attributeMap.put(ATTR_DESCRIPTION, new ZclAttribute(this, ATTR_DESCRIPTION, "Description", ZclDataType.CHARACTER_STRING, false, true, true, false));
attributeMap.put(ATTR_MAXPRESENTVALUE, new ZclAttribute(this, ATTR_MAXPRESENTVALUE, "Max Present Value", ZclDataType.FLOAT_32_BIT, false, true, true, false));
attributeMap.put(ATTR_MINPRESENTVALUE, new ZclAttribute(this, ATTR_MINPRESENTVALUE, "Min Present Value", ZclDataType.FLOAT_32_BIT, false, true, true, false));
attributeMap.put(ATTR_OUTOFSERVICE, new ZclAttribute(this, ATTR_OUTOFSERVICE, "Out Of Service", ZclDataType.BOOLEAN, false, true, true, false));
attributeMap.put(ATTR_PRESENTVALUE, new ZclAttribute(this, ATTR_PRESENTVALUE, "Present Value", ZclDataType.FLOAT_32_BIT, false, true, true, false));
attributeMap.put(ATTR_RELIABILITY, new ZclAttribute(this, ATTR_RELIABILITY, "Reliability", ZclDataType.ENUMERATION_8_BIT, false, true, true, false));
attributeMap.put(ATTR_RESOLUTION, new ZclAttribute(this, ATTR_RESOLUTION, "Resolution", ZclDataType.FLOAT_32_BIT, false, true, true, false));
attributeMap.put(ATTR_STATUSFLAGS, new ZclAttribute(this, ATTR_STATUSFLAGS, "Status Flags", ZclDataType.BITMAP_8_BIT, false, true, true, false));
attributeMap.put(ATTR_ENGINEERINGUNITS, new ZclAttribute(this, ATTR_ENGINEERINGUNITS, "Engineering Units", ZclDataType.ENUMERATION_32_BIT, false, true, true, false));
attributeMap.put(ATTR_APPLICATIONTYPE, new ZclAttribute(this, ATTR_APPLICATIONTYPE, "Application Type", ZclDataType.SIGNED_32_BIT_INTEGER, false, true, true, false));

return attributeMap;
}
Expand Down
Loading

0 comments on commit 5c4c587

Please sign in to comment.