Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Refactor to add cluster API #104

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.bubblecloud.zigbee.tools;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.WordUtils;

Expand All @@ -16,7 +18,19 @@ public static Integer fromHex(String headerIdString) {
}

public static String labelToEnumerationValue(String dataType) {
return dataType.trim().toUpperCase().replace(" ", "_").replace("-", "_").replace("/", "_").replace("(", "_").replace(")", "_");
String val = dataType.trim().toUpperCase().replace(" ", "_").replace("-", "_").replace("/", "_").replace("(", "_").replace(")", "_");
if ("0123456789".indexOf(val.charAt(0)) >= 0) {
// Swap the last word to the beginning
String partsInitial[] = val.split("_");
StringBuilder sb = new StringBuilder();
sb.append(partsInitial[partsInitial.length-1]);
for(int c = 0; c < partsInitial.length-1; c++) {
sb.append("_");
sb.append(partsInitial[c]);
}
return sb.toString();
}
return val;
}

public static String labelToUpperCamelCase(String value) {
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.bubblecloud.zigbee.tools.zcl;

import java.util.List;

public class Attribute {
public String attributeLabel;
public List<String> attributeDescription;
public String attributeType;
public String dataType;
public String dataTypeClass;
public String nameUpperCamelCase;
public String nameLowerCamelCase;
public String attributeAccess;
public String attributeReporting;
public String enumName;
public Integer attributeId;
public String attributeImplementation;
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package org.bubblecloud.zigbee.tools.zcl;

import java.util.List;
import java.util.TreeMap;

/**
* Created by tlaukkan on 4/10/2016.
*/
public class Cluster {
public int clusterId;
public List<String> clusterDescription;
public String clusterName;
public String clusterType;
public String nameUpperCamelCase;
public String nameLowerCamelCase;
public TreeMap<Integer, Command> received = new TreeMap<Integer, Command>();
public TreeMap<Integer, Command> generated = new TreeMap<Integer, Command>();
public TreeMap<Integer, Attribute> attributes = new TreeMap<Integer, Attribute>();
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.bubblecloud.zigbee.tools.zcl;

import java.util.List;
import java.util.TreeMap;

/**
Expand All @@ -8,7 +9,10 @@
public class Command {
public int commandId;
public String commandLabel;
public List<String> commandDescription;
public String commandType;
public String dataType;
public String dataTypeClass;
public String nameUpperCamelCase;
public String nameLowerCamelCase;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class Context {
public Command command;

public boolean received;
public boolean generated;
public boolean attribute;

public TreeMap<String, DataType> dataTypes = new TreeMap<String, DataType>();
public TreeMap<Integer, Profile> profiles = new TreeMap<Integer, Profile>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package org.bubblecloud.zigbee.tools.zcl;

import java.util.HashMap;
import java.util.Map;

public class ZclDataType {

public static class DataTypeMap {
public String dataClass;
public Integer id;
public Integer length;
public Integer invalid;

DataTypeMap(String dataClass, int id, int length) {
this(dataClass, id, length, 0);
}

DataTypeMap(String dataClass, int id, int length, int invalid) {
this.dataClass = dataClass;
this.id = id;
this.length = length;
this.invalid = invalid;
}
};

final static Map<String, DataTypeMap> dataTypeMapping;

static {
dataTypeMapping = new HashMap<String, DataTypeMap>();

dataTypeMapping.put("CHARACTER_STRING", new DataTypeMap("String", 0x42, -1));
dataTypeMapping.put("IEEE_ADDRESS", new DataTypeMap("Long", 0xf0, 8, 0xffffffff));
dataTypeMapping.put("N_X_EXTENSION_FIELD_SET", new DataTypeMap("List<ExtensionFieldSet>", 0, 0));
dataTypeMapping.put("N_X_NEIGHBORS_INFORMATION", new DataTypeMap("List<NeighborInformation>", 0, 0));
dataTypeMapping.put("N_X_UNSIGNED_16_BIT_INTEGER", new DataTypeMap("List<Unsigned16BitInteger>", 0, 0));
dataTypeMapping.put("N_X_UNSIGNED_8_BIT_INTEGER", new DataTypeMap("List<Unsigned8BitInteger>", 0, 0));
dataTypeMapping.put("N_X_ATTRIBUTE_IDENTIFIER", new DataTypeMap("List<AttributeIdentifier>", 0, 0));
dataTypeMapping.put("N_X_READ_ATTRIBUTE_STATUS_RECORD",
new DataTypeMap("List<ReadAttributeStatusRecord>", 0, 0));
dataTypeMapping.put("N_X_WRITE_ATTRIBUTE_RECORD", new DataTypeMap("List<WriteAttributeRecord>", 0, 0));
dataTypeMapping.put("N_X_WRITE_ATTRIBUTE_STATUS_RECORD", new DataTypeMap("List<WriteAttributeStatusRecord>", 0,
0));
dataTypeMapping.put("N_X_ATTRIBUTE_REPORTING_CONFIGURATION_RECORD", new DataTypeMap(
"List<AttributeReportingConfigurationRecord>", 0, 0));
dataTypeMapping.put("N_X_ATTRIBUTE_STATUS_RECORD", new DataTypeMap("List<AttributeStatusRecord>", 0, 0));
dataTypeMapping.put("N_X_ATTRIBUTE_RECORD", new DataTypeMap("List<AttributeRecord>", 0, 0));
dataTypeMapping.put("N_X_ATTRIBUTE_REPORT", new DataTypeMap("List<AttributeReport>", 0, 0));
dataTypeMapping.put("N_X_ATTRIBUTE_INFORMATION", new DataTypeMap("List<AttributeInformation>", 0, 0));
dataTypeMapping.put("N_X_ATTRIBUTE_SELECTOR", new DataTypeMap("Object", 0, 0));
dataTypeMapping.put("BOOLEAN", new DataTypeMap("Boolean", 0x10, 1, 0xff));
dataTypeMapping.put("SIGNED_32_BIT_INTEGER", new DataTypeMap("Integer", 0x2b, 4, 0x80000000));
dataTypeMapping.put("SIGNED_16_BIT_INTEGER", new DataTypeMap("Integer", 0x29, 2, 0x8000));
dataTypeMapping.put("SIGNED_8_BIT_INTEGER", new DataTypeMap("Integer", 0x28, 1, 0x80));
dataTypeMapping.put("UNSIGNED_16_BIT_INTEGER", new DataTypeMap("Integer", 0x21, 2, 0xffff));
dataTypeMapping.put("UNSIGNED_32_BIT_INTEGER", new DataTypeMap("Integer", 0x23, 4, 0xffffffff));
dataTypeMapping.put("UNSIGNED_8_BIT_INTEGER", new DataTypeMap("Integer", 0x20, 1, 0xff));
dataTypeMapping.put("BITMAP_16_BIT", new DataTypeMap("Integer", 0x19, 2));
dataTypeMapping.put("BITMAP_8_BIT", new DataTypeMap("Integer", 0x18, 1));
dataTypeMapping.put("ENUMERATION_16_BIT", new DataTypeMap("Integer", 0x31, 2, 0xffff));
dataTypeMapping.put("ENUMERATION_8_BIT", new DataTypeMap("Integer", 0x30, 1, 0xff));
dataTypeMapping.put("DATA_8_BIT", new DataTypeMap("Integer", 0x08, 1));
dataTypeMapping.put("OCTET_STRING", new DataTypeMap("String", 0x41, -1));
dataTypeMapping.put("UTCTIME", new DataTypeMap("Calendar", 0xe2, 4, 0xffffffff));
};

public static Map<String, DataTypeMap> getDataTypeMapping() {
return dataTypeMapping;
}
}
Loading