--- /dev/null
+\r
+// Java packages\r
+import java.net.Socket;\r
+import java.net.ServerSocket;\r
+import java.net.InetAddress;\r
+import java.net.UnknownHostException;\r
+\r
+/** Class IoTAddress is a wrapper class to pass\r
+ * IoTSet of any addresses from master to slave\r
+ *\r
+ * @author Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>\r
+ * @version 1.0\r
+ * @since 2016-04-22\r
+ */\r
+public class IoTAddress {\r
+\r
+ /**\r
+ * IoTDeviceAddress class properties\r
+ */\r
+ protected final InetAddress inetAddress;\r
+\r
+ /**\r
+ * Class constructor\r
+ *\r
+ * @param sAddress String address\r
+ */\r
+ public IoTAddress(String sAddress) throws UnknownHostException {\r
+\r
+ inetAddress = InetAddress.getByName(sAddress);\r
+ }\r
+\r
+ /**\r
+ * getHostAddress() method\r
+ *\r
+ * @return String\r
+ */\r
+ public String getHostAddress() {\r
+\r
+ return inetAddress.getHostAddress();\r
+\r
+ }\r
+\r
+ /**\r
+ * getHostName() method\r
+ *\r
+ * @return String\r
+ */\r
+ public String getHostName() {\r
+\r
+ return inetAddress.getHostName();\r
+\r
+ }\r
+\r
+ /**\r
+ * getUrl() method\r
+ *\r
+ * @return String\r
+ */\r
+ public String getURL(String strURLComplete) {\r
+\r
+ //e.g. http:// + inetAddress.getHostAddress() + strURLComplete\r
+ // http://192.168.2.254/cgi-bin/mjpg/video.cgi?\r
+ return "http://" + inetAddress.getHostAddress() + strURLComplete;\r
+\r
+ }\r
+\r
+ /**\r
+ * getCompleteAddress() method\r
+ *\r
+ * @return String\r
+ */\r
+ public String getCompleteAddress() {\r
+\r
+ return inetAddress.toString();\r
+\r
+ }\r
+}\r
--- /dev/null
+\r
+// Java packages\r
+import java.net.Socket;\r
+import java.net.ServerSocket;\r
+import java.net.InetAddress;\r
+import java.net.UnknownHostException;\r
+\r
+/** Class IoTDeviceAddress is a wrapper class to pass\r
+ * IoTSet of device addresses from master to slave\r
+ *\r
+ * @author Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>\r
+ * @version 1.0\r
+ * @since 2016-02-18\r
+ */\r
+public class IoTDeviceAddress extends IoTAddress {\r
+\r
+ /**\r
+ * IoTDeviceAddress class properties\r
+ */\r
+ private int iSrcPort;\r
+ private int iDstPort;\r
+ private final String sAddress;\r
+\r
+ // the wildcard status of this address\r
+ private final boolean isSrcPortWildCard;\r
+ private final boolean isDstPortWildCard;\r
+\r
+\r
+ /**\r
+ * Class constructor\r
+ *\r
+ * @param sAddress String address\r
+ * @param _iSrcPort Source port number\r
+ * @param _iDstPort Destination port number\r
+ * @param _isSrcPortWildCard Is this source port a wild card (=can change port number)?\r
+ * @param _isDstPortWildCard Is this destination port a wild card (=can change port number)?\r
+ */\r
+ public IoTDeviceAddress(String _sAddress, int _iSrcPort, int _iDstPort, boolean _isSrcPortWildCard, \r
+ boolean _isDstPortWildCard) throws UnknownHostException {\r
+\r
+ super(_sAddress);\r
+ sAddress = _sAddress;\r
+ iSrcPort = _iSrcPort;\r
+ iDstPort = _iDstPort;\r
+\r
+ isSrcPortWildCard = _isSrcPortWildCard;\r
+ isDstPortWildCard = _isDstPortWildCard;\r
+ }\r
+\r
+ /**\r
+ * getSourcePortNumber() method\r
+ *\r
+ * @return int\r
+ */\r
+ public int getSourcePortNumber() {\r
+\r
+ return iSrcPort;\r
+\r
+ }\r
+\r
+ /**\r
+ * getDestinationPortNumber() method\r
+ *\r
+ * @return int\r
+ */\r
+ public int getDestinationPortNumber() {\r
+\r
+ return iDstPort;\r
+\r
+ }\r
+\r
+ /**\r
+ * setSrcPort() method\r
+ *\r
+ * @param port Port number\r
+ * @return void\r
+ */\r
+ public void setSrcPort(int port) {\r
+ if (isSrcPortWildCard) {\r
+ iSrcPort = port;\r
+ }\r
+ }\r
+\r
+ /**\r
+ * setDstPort() method\r
+ *\r
+ * @param port Port number\r
+ * @return void\r
+ */\r
+ public void setDstPort(int port) {\r
+ if (isDstPortWildCard) {\r
+ iDstPort = port;\r
+ }\r
+ }\r
+\r
+ /**\r
+ * getAddress() method\r
+ *\r
+ * @return String\r
+ */\r
+ public String getAddress() {\r
+ return sAddress;\r
+ }\r
+\r
+ /**\r
+ * getHostAddress() method\r
+ *\r
+ * @return String\r
+ */\r
+ public static String getLocalHostAddress() {\r
+\r
+ String strLocalHostAddress = null;\r
+ try {\r
+ strLocalHostAddress = InetAddress.getLocalHost().getHostAddress();\r
+ } catch (UnknownHostException ex) {\r
+ ex.printStackTrace();\r
+ } \r
+ return strLocalHostAddress;\r
+ }\r
+\r
+ /**\r
+ * getIsSrcPortWildcard() method\r
+ *\r
+ * @return boolean\r
+ */\r
+ public boolean getIsSrcPortWildcard() {\r
+ return isSrcPortWildCard;\r
+ }\r
+\r
+ /**\r
+ * getIsDstPortWildcard() method\r
+ *\r
+ * @return boolean\r
+ */\r
+ public boolean getIsDstPortWildcard() {\r
+ return isDstPortWildCard;\r
+ }\r
+}\r
--- /dev/null
+
+import java.lang.UnsupportedOperationException;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+
+/** Class IoTRelation is the actual implementation of @config IoTRelation<...>.
+ * Upon extracting DB information, RelationInstrumenter class will use
+ * this class to actually instantiate the Map as IoTRelation uses a
+ * combination between a HashMap and a IoTSet; we don't provide interfaces
+ * to modify the contents, but we do provide means to read them out.
+ * The add method is just used the first time it is needed to add new objects,
+ * then it is going to be made immutable
+ *
+ * @author Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
+ * @version 1.0
+ * @since 2015-12-01
+ */
+public final class IoTRelation<K, V> {
+
+ /**
+ * Reference to an object Map<T>
+ */
+ private Map<K,HashSet<V> > mapRelation;
+ private int iSize;
+
+ /**
+ * Class constructor (pass the reference to this immutable wrapper)
+ */
+ protected IoTRelation(Map<K,HashSet<V>> mapRel, int _iSize) {
+ mapRelation = mapRel;
+ iSize = _iSize;
+ }
+
+ /**
+ * Method containsKey() inherited from Map interface
+ *
+ * @param key The first Object that is usually a key in a Map
+ * @return boolean
+ */
+ public boolean containsKey(K key) {
+
+ return mapRelation.containsKey(key);
+
+ }
+
+ /**
+ * Method entrySet() inherited from Map interface
+ *
+ * @return Set<Map.Entry<K,HashSet<V>>>
+ */
+ public Set<Map.Entry<K,HashSet<V>>> entrySet() {
+
+ return new HashSet<Map.Entry<K,HashSet<V>>>(mapRelation.entrySet());
+
+ }
+
+ /**
+ * Method keySet() inherited from Map interface
+ *
+ * @return Set<K>
+ */
+ public Set<K> keySet() {
+
+ return new HashSet<K>(mapRelation.keySet());
+
+ }
+
+ /**
+ * Method get() inherited from Map interface
+ *
+ * @param key The first Object that is usually a key in a Map
+ * @return HashSet<V>
+ */
+ public HashSet<V> get(K key) {
+
+ return new HashSet<V>(mapRelation.get(key));
+
+ }
+
+ /**
+ * Method isEmpty() inherited from Map interface
+ *
+ * @return boolean
+ */
+ public boolean isEmpty() {
+
+ return mapRelation.isEmpty();
+
+ }
+
+ /**
+ * size() method
+ *
+ * @return int
+ */
+ public int size() {
+
+ return this.iSize;
+
+ }
+}
--- /dev/null
+
+import java.lang.UnsupportedOperationException;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+import java.util.Spliterator;
+
+
+/** Class IoTSet is the actual implementation of @config IoTSet<...>.
+ * Upon extracting DB information, SetInstrumenter class will use
+ * this class to actually instantiate the Set as IoTSet that uses
+ * Java Set<T> to implement; we don't provide interfaces to modify
+ * the contents, but we do provide means to read them out
+ *
+ * @author Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
+ * @version 1.0
+ * @since 2015-12-01
+ */
+public final class IoTSet<T> {
+
+ /**
+ * Reference to an object Set<T>
+ */
+ private Set<T> set;
+
+ /**
+ * Class constructor (pass the reference to this immutable wrapper)
+ */
+ public IoTSet(Set<T> s) {
+
+ set = s;
+ }
+
+ /**
+ * contains() method inherited from Set interface
+ */
+ public boolean contains(T o) {
+
+ return set.contains(o);
+
+ }
+
+ /**
+ * isEmpty() method inherited from Set interface
+ */
+ public boolean isEmpty() {
+
+ return set.isEmpty();
+
+ }
+
+ /**
+ * iterator() method inherited from Set interface
+ */
+ public Iterator<T> iterator() {
+
+ return new HashSet<T>(set).iterator();
+
+ }
+
+ /**
+ * size() method inherited from Set interface
+ */
+ public int size() {
+
+ return set.size();
+
+ }
+
+ /**
+ * values() method to return Set object values for easy iteration
+ */
+ public Set<T> values() {
+
+ return new HashSet<T>(set);
+
+ }
+}
--- /dev/null
+
+// Java packages
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.DatagramSocket;
+import java.net.InetAddress;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.Set;
+import java.util.HashSet;
+import java.nio.charset.StandardCharsets;
+import java.util.concurrent.Semaphore;
+
+
+/** Class IoTZigbee
+ *
+ * @author Ali Younis <ayounis @ uci.edu>, Changwoo Lee <changwl2 @ uci.edu>
+ * @version 1.0
+ * @since 2016-04-12, 2016-10-28
+ */
+public class IoTZigbee {
+
+ public final int SOCKET_SEND_BUFFER_SIZE = 1024;
+ public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024;
+ public final int SHORT_ADDRESS_UPDATE_TIME_MSEC = 10000;
+ public final int SHORT_ADDRESS_UPDATE_TIME_FAST_MSEC = 500;
+ public final int RESEND_WAIT_TIME = 500;
+
+ /**
+ * IoTZigbee class properties
+ */
+
+ // UDP connection stuff
+ private final String strHostAddress;
+ private final int iSrcPort;
+ private final int iDstPort;
+ private DatagramSocket socket; // the socket interface that we are guarding
+ private boolean didClose; // make sure that the clean up was done correctly
+
+ private final IoTZigbeeAddress zigbeeAddress;
+
+ // list that holds the callbacks
+ private List<IoTZigbeeCallback> callbackList = new ArrayList<IoTZigbeeCallback>();
+
+ /**
+ * IoTZigbee class concurrency and concurrency control
+ */
+ private Thread receiveThread = null;
+
+ private AtomicBoolean endTask = new AtomicBoolean(false);
+ private AtomicBoolean didSuccesfullySendAddress = new AtomicBoolean(false);
+
+ /**
+ * Class constructor
+ */
+ public IoTZigbee(IoTDeviceAddress iotDevAdd, IoTZigbeeAddress zigAddress) throws SocketException, IOException, InterruptedException {
+
+ strHostAddress = iotDevAdd.getHostAddress();
+ iSrcPort = iotDevAdd.getSourcePortNumber();
+ iDstPort = iotDevAdd.getDestinationPortNumber();
+ didClose = false;
+ zigbeeAddress = zigAddress;
+
+ socket = new DatagramSocket(iSrcPort);
+ socket.setSendBufferSize(SOCKET_SEND_BUFFER_SIZE);
+ socket.setReceiveBufferSize(SOCKET_RECEIVE_BUFFER_SIZE);
+
+ receiveThread = new Thread(new Runnable() {
+ public void run() {
+ receieveWorker();
+ }
+ });
+ receiveThread.start();
+ }
+
+ public void init() throws IOException {
+ while (!didSuccesfullySendAddress.get()) {
+
+ sendDeviceAddress();
+
+ try {
+ Thread.sleep(RESEND_WAIT_TIME);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ //made by changwoo
+ public void sendChangeSwtichRequest(int packetId, int clusterId, int profileId, int value, int deviceEndpoint) throws IOException {
+ String message = "type: zcl_change_switch_request\n";
+ message += "packet_id: " + String.format("%04x", packetId) + "\n";
+ message += "value: " + String.format("%01x", value) + "\n";
+ message += "cluster_id: " + String.format("%04x", clusterId) + "\n";
+ message += "profile_id: " + String.format("%04x", profileId) + "\n";
+ message += "device_address_long: " + zigbeeAddress.getAddress() + "\n";
+ message += "device_endpoint: " + String.format("%02x", deviceEndpoint) + "\n";
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort);
+ socket.send(sendPacket);
+ }
+
+ //made by changwoo
+ public void sendBroadcastingRouteRecordRequest(int packetId) throws IOException {
+ String message = "type: zdo_broadcast_route_record_request\n";
+ message += "packet_id: " + String.format("%04x", packetId) + "\n";
+ message += "device_address_long: " + zigbeeAddress.getAddress() + "\n";
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort);
+ socket.send(sendPacket);
+ }
+
+ //made by changwoo
+ public void sendEnrollmentResponse(int packetId, int clusterId, int profileId, int deviceEndpoint) throws IOException {
+ String message = "type: zcl_enrollment_response\n";
+ message += "packet_id: " + String.format("%04x", packetId) + "\n";
+ message += "device_address_long: " + zigbeeAddress.getAddress() + "\n";
+ message += "cluster_id: " + String.format("%04x", clusterId) + "\n";
+ message += "profile_id: " + String.format("%04x", profileId) + "\n";
+ message += "device_endpoint: " + String.format("%02x", deviceEndpoint) + "\n";
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort);
+ socket.send(sendPacket);
+ }
+
+ //made by changwoo
+ public void sendWriteAttributesCommand(int packetId, int clusterId, int profileId, int deviceEndpoint) throws IOException {
+ String message = "type: zcl_write_attributes\n";
+ message += "packet_id: " + String.format("%04x", packetId) + "\n";
+ message += "device_address_long: " + zigbeeAddress.getAddress() + "\n";
+ message += "cluster_id: " + String.format("%04x", clusterId) + "\n";
+ message += "profile_id: " + String.format("%04x", profileId) + "\n";
+ message += "device_endpoint: " + String.format("%02x", deviceEndpoint) + "\n";
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort);
+ socket.send(sendPacket);
+ }
+
+ //made by changwoo
+ public void sendManagementPermitJoiningRequest(int packetId, int clusterId, int deviceEndpoint) throws IOException {
+ String message = "type: management_permit_joining_request\n";
+ message += "packet_id: " + String.format("%04x", packetId) + "\n";
+ message += "device_address_long: " + zigbeeAddress.getAddress() + "\n";
+ message += "cluster_id: " + String.format("%04x", clusterId) + "\n";
+ message += "device_endpoint: " + String.format("%02x", deviceEndpoint) + "\n";
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort);
+ socket.send(sendPacket);
+ }
+
+ public void sendBindRequest(int packetId, int clusterId, int deviceEndpoint) throws IOException {
+ String message = "type: zdo_bind_request\n";
+ message += "packet_id: " + String.format("%04x", packetId) + "\n";
+ message += "device_address_long: " + zigbeeAddress.getAddress() + "\n";
+ message += "cluster_id: " + String.format("%04x", clusterId) + "\n";
+ message += "device_endpoint: " + String.format("%02x", deviceEndpoint) + "\n";
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort);
+ socket.send(sendPacket);
+ }
+
+ public void sendUnBindRequest(int packetId, int clusterId, int deviceEndpoint) throws IOException {
+ String message = "type: zdo_unbind_request\n";
+ message += "packet_id: " + String.format("%04x", packetId) + "\n";
+ message += "device_address_long: " + zigbeeAddress.getAddress() + "\n";
+ message += "cluster_id: " + String.format("%04x", clusterId) + "\n";
+ message += "device_endpoint: " + String.format("%02x", deviceEndpoint) + "\n";
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort);
+ socket.send(sendPacket);
+ }
+
+ public void sendReadAttributesCommand(int packetId, int clusterId, int profileId, int deviceEndpoint, List<Integer> attributeIds) throws IOException {
+ String message = "type: zcl_read_attributes\n";
+ message += "packet_id: " + String.format("%04x", packetId) + "\n";
+ message += "device_address_long: " + zigbeeAddress.getAddress() + "\n";
+ message += "cluster_id: " + String.format("%04x", clusterId) + "\n";
+ message += "profile_id: " + String.format("%04x", profileId) + "\n";
+ message += "device_endpoint: " + String.format("%02x", deviceEndpoint) + "\n";
+
+ message += "attribute_ids: ";
+
+ for (Integer i : attributeIds) {
+ message += String.format("%04x", i) + ",";
+ }
+
+ message = message.substring(0, message.length() - 1);
+ message += "\n";
+
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort);
+ socket.send(sendPacket);
+ }
+
+ public void sendConfigureReportingCommand(int packetId, int clusterId, int profileId, int deviceEndpoint, int attributeId, int dataType, int minReportingInterval, int maxReportingInterval, byte[] reportableChange) throws IOException {
+ String message = "type: zcl_configure_reporting\n";
+ message += "packet_id: " + String.format("%04x", packetId) + "\n";
+ message += "device_address_long: " + zigbeeAddress.getAddress() + "\n";
+ message += "cluster_id: " + String.format("%04x", clusterId) + "\n";
+ message += "profile_id: " + String.format("%04x", profileId) + "\n";
+ message += "device_endpoint: " + String.format("%02x", deviceEndpoint) + "\n";
+ message += "attribute_id: " + String.format("%04x", attributeId) + "\n";
+ message += "data_type: " + String.format("%02x", dataType) + "\n";
+ message += "min_reporting_interval: " + String.format("%04x", minReportingInterval) + "\n";
+ message += "max_reporting_interval: " + String.format("%04x", maxReportingInterval) + "\n";
+
+ if (reportableChange != null) {
+ message += "reportable_change: ";
+ for (Byte b : reportableChange) {
+ message += String.format("%02x", (int)b);
+ }
+ message += "\n";
+ }
+
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort);
+ socket.send(sendPacket);
+ }
+
+ public void registerCallback(IoTZigbeeCallback callbackTo) {
+
+ callbackList.add(callbackTo);
+
+ }
+
+ public void close() throws InterruptedException {
+ endTask.set(true);
+
+ // wait for the threads to end
+ receiveThread.join();
+
+ socket.close();
+ didClose = true;
+ }
+
+ /**
+ * close() called by the garbage collector right before trashing object
+ */
+ public void Finalize() throws SocketException, InterruptedException {
+
+ if (!didClose) {
+ close();
+ throw new SocketException("Socket not closed before object destruction, must call close method.");
+ }
+ }
+
+ private void sendDeviceAddress() throws IOException {
+ String message = "type: send_address\n";
+ message += "packet_id: 00\n";
+ message += "device_address_long: " + zigbeeAddress.getAddress() + "\n";
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort);
+ socket.send(sendPacket);
+ }
+
+ private void receieveWorker() {
+ while (!(endTask.get())) {
+
+ byte[] recBuffer = new byte[SOCKET_RECEIVE_BUFFER_SIZE];
+ try {
+ DatagramPacket recPacket = new DatagramPacket(recBuffer, recBuffer.length);
+ socket.receive(recPacket);
+
+ // Convert the UDP data into a string format
+ String dataString = new String(recPacket.getData());
+
+ // split the data by line so we can start procesisng
+ String[] lines = dataString.split("\n");
+
+ Map<String, String> packetData = new HashMap<String, String>();
+ for (String line : lines) {
+
+ // trim the line
+ String trimmedLine = line.trim();
+ // make sure this is a valid data line and not just blank
+ if (trimmedLine.length() == 0) {
+ continue;
+ }
+
+ // Split the data into parts
+ String[] parts = trimmedLine.split(":");
+ parts[0] = parts[0].trim();
+ parts[1] = parts[1].trim();
+ packetData.put(parts[0], parts[1]);
+ }
+
+ if (packetData.get("type").equals("send_address_response")) {
+ didSuccesfullySendAddress.set(true);
+
+ } else {
+ IoTZigbeeMessage callbackMessage = null;
+
+/*
+ // made by changwoo
+ if (packetData.get("type").equals("zcl_match_descriptor_response")) {
+ System.out.println("zcl_match_descriptor_response message arrives");
+
+ int packetId = Integer.parseInt(packetData.get("packet_id"), 16);
+ int clusterId = Integer.parseInt(packetData.get("cluster_id"), 16);
+ int profileId = Integer.parseInt(packetData.get("profile_id"), 16);
+ boolean successOrFail = false;
+ if(packetData.get("attributes").equals("success")) successOrFail=true;
+
+ callbackMessage = new IoTZigbeeMessageMatchDescriptorResponse(packetId, clusterId, profileId, successOrFail);
+
+ }
+*/
+ // made by changwoo
+ if (packetData.get("type").equals("zcl_zone_status_change_notification")){
+ int packetId = Integer.parseInt(packetData.get("packet_id"), 16);
+ int clusterId = Integer.parseInt(packetData.get("cluster_id"), 16);
+ int profileId = Integer.parseInt(packetData.get("profile_id"), 16);
+ int status = Integer.parseInt(packetData.get("status"), 10);
+ boolean successOrFail = false;
+ if(packetData.get("attributes").equals("success")) successOrFail=true;
+ callbackMessage = new IoTZigbeeMessageZclZoneStatusChangeNotification(packetId, clusterId, profileId, status, successOrFail);
+
+ //made by changwoo
+ } else if (packetData.get("type").equals("zcl_write_attributes_response")) {
+
+ int packetId = Integer.parseInt(packetData.get("packet_id"), 16);
+ int clusterId = Integer.parseInt(packetData.get("cluster_id"), 16);
+ int profileId = Integer.parseInt(packetData.get("profile_id"), 16);
+ boolean successOrFail = false;
+ if(packetData.get("attributes").equals("success")) successOrFail=true;
+
+ callbackMessage = new IoTZigbeeMessageZclWriteAttributesResponse(packetId, clusterId, profileId, successOrFail);
+
+ } else if (packetData.get("type").equals("zcl_read_attributes_response")) {
+ int packetId = Integer.parseInt(packetData.get("packet_id"), 16);
+ int clusterId = Integer.parseInt(packetData.get("cluster_id"), 16);
+ int profileId = Integer.parseInt(packetData.get("profile_id"), 16);
+
+ List<IoTZigbeeMessageZclReadAttributesResponse.Attribute> attrList = new ArrayList<IoTZigbeeMessageZclReadAttributesResponse.Attribute>();
+
+ String[] attributes = packetData.get("attributes").split(";");
+ for (String attr : attributes) {
+ attr = attr.trim();
+ String[] parts = attr.split(",");
+
+ if (parts.length == 2) {
+ parts[0] = parts[0].trim();
+ parts[1] = parts[1].trim();
+
+ IoTZigbeeMessageZclReadAttributesResponse.Attribute at = new IoTZigbeeMessageZclReadAttributesResponse.Attribute(Integer.parseInt(parts[0], 16), 0, false, null);
+ attrList.add(at);
+ } else {
+ parts[0] = parts[0].trim();
+ parts[1] = parts[1].trim();
+ parts[2] = parts[2].trim();
+ parts[3] = parts[3].trim();
+ IoTZigbeeMessageZclReadAttributesResponse.Attribute at = new IoTZigbeeMessageZclReadAttributesResponse.Attribute(Integer.parseInt(parts[0], 16), Integer.parseInt(parts[1], 16), true, hexStringToByteArray(parts[3]));
+ attrList.add(at);
+ }
+ }
+
+ callbackMessage = new IoTZigbeeMessageZclReadAttributesResponse(packetId, clusterId, profileId, attrList);
+
+ } else if (packetData.get("type").equals("zcl_configure_reporting_response")) {
+ int packetId = Integer.parseInt(packetData.get("packet_id"), 16);
+ int clusterId = Integer.parseInt(packetData.get("cluster_id"), 16);
+ int profileId = Integer.parseInt(packetData.get("profile_id"), 16);
+
+ if (packetData.get("attributes").equals("all_success")) {
+ callbackMessage = new IoTZigbeeMessageZclConfigureReportingResponse(packetId, clusterId, profileId, true, null);
+ } else {
+ List<IoTZigbeeMessageZclConfigureReportingResponse.Attribute> attrList = new ArrayList<IoTZigbeeMessageZclConfigureReportingResponse.Attribute>();
+
+ String[] attributes = packetData.get("attributes").split(";");
+ for (String attr : attributes) {
+ attr = attr.trim();
+ String[] parts = attr.split(",");
+ parts[0] = parts[0].trim();
+ parts[1] = parts[1].trim();
+ parts[2] = parts[2].trim();
+ IoTZigbeeMessageZclConfigureReportingResponse.Attribute at = new IoTZigbeeMessageZclConfigureReportingResponse.Attribute(Integer.parseInt(parts[0], 16), parts[1].equals("success"), parts[2].equals("reported"));
+ attrList.add(at);
+ }
+ callbackMessage = new IoTZigbeeMessageZclConfigureReportingResponse(packetId, clusterId, profileId, false, attrList);
+ }
+
+ } else if (packetData.get("type").equals("zcl_report_attributes")) {
+ int packetId = Integer.parseInt(packetData.get("packet_id"), 16);
+ int clusterId = Integer.parseInt(packetData.get("cluster_id"), 16);
+ int profileId = Integer.parseInt(packetData.get("profile_id"), 16);
+
+ List<IoTZigbeeMessageZclReportAttributes.Attribute> attrList = new ArrayList<IoTZigbeeMessageZclReportAttributes.Attribute>();
+
+ String[] attributes = packetData.get("attributes").split(";");
+ for (String attr : attributes) {
+ attr = attr.trim();
+ String[] parts = attr.split(",");
+
+ parts[0] = parts[0].trim();
+ parts[1] = parts[1].trim();
+ parts[2] = parts[2].trim();
+ IoTZigbeeMessageZclReportAttributes.Attribute at = new IoTZigbeeMessageZclReportAttributes.Attribute(Integer.parseInt(parts[0], 16), Integer.parseInt(parts[1], 16), hexStringToByteArray(parts[2]));
+ attrList.add(at);
+ }
+
+ callbackMessage = new IoTZigbeeMessageZclReportAttributes(packetId, clusterId, profileId, attrList);
+
+ } else if (packetData.get("type").equals("zcl_read_attributes")) {
+ int packetId = Integer.parseInt(packetData.get("packet_id"), 16);
+ boolean success = packetData.get("response").equals("success");
+
+ if (success) {
+ callbackMessage = new IoTZigbeeMessageZclReadAttributes(packetId, success, "");
+ } else {
+ callbackMessage = new IoTZigbeeMessageZclReadAttributes(packetId, success, packetData.get("reason"));
+ }
+
+ } else if (packetData.get("type").equals("zcl_configure_reporting")) {
+ int packetId = Integer.parseInt(packetData.get("packet_id"), 16);
+ boolean success = packetData.get("response").equals("success");
+
+ if (success) {
+ callbackMessage = new IoTZigbeeMessageZclConfigureReporting(packetId, success, "");
+ } else {
+ callbackMessage = new IoTZigbeeMessageZclConfigureReporting(packetId, success, packetData.get("reason"));
+ }
+
+ } else if (packetData.get("type").equals("zdo_bind_request")) {
+ int packetId = Integer.parseInt(packetData.get("packet_id"), 16);
+ boolean success = packetData.get("response").equals("success");
+
+ if (success) {
+ callbackMessage = new IoTZigbeeMessageZdoBindResponse(packetId, success, "");
+ } else {
+ callbackMessage = new IoTZigbeeMessageZdoBindResponse(packetId, success, packetData.get("reason"));
+ }
+ }
+
+ else if (packetData.get("type").equals("zdo_unbind_request")) {
+ int packetId = Integer.parseInt(packetData.get("packet_id"), 16);
+ boolean success = packetData.get("response").equals("success");
+
+ if (success) {
+ callbackMessage = new IoTZigbeeMessageZdoUnBindResponse(packetId, success, "");
+ } else {
+ callbackMessage = new IoTZigbeeMessageZdoUnBindResponse(packetId, success, packetData.get("reason"));
+ }
+ }
+
+ if (callbackMessage != null) {
+ for (IoTZigbeeCallback c : callbackList) {
+ c.newMessageAvailable(callbackMessage);
+ }
+ }
+ }
+
+
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public static String changeHexEndianness(String hexData) {
+
+ List<String> pairedValues = new ArrayList<String>();
+ for (int i = 0; i < hexData.length(); i += 2) {
+ String part = hexData.substring(i, Math.min(i + 2, hexData.length()));
+ pairedValues.add(part);
+ }
+
+ String retString = "";
+ for (int i = (pairedValues.size() - 1); i >= 0; i--) {
+ retString += pairedValues.get(i);
+ }
+ return retString;
+ }
+
+ // taken from: http://stackoverflow.com/questions/140131/convert-a-string-representation-of-a-hex-dump-to-a-byte-array-using-java
+ public static byte[] hexStringToByteArray(String s) {
+ int len = s.length();
+ byte[] data = new byte[len / 2];
+ for (int i = 0; i < len; i += 2) {
+ data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
+ + Character.digit(s.charAt(i + 1), 16));
+ }
+ return data;
+ }
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
--- /dev/null
+
+/** Class IoTZigbeeAddress is a wrapper class to pass
+ * IoTSet of device addresses from master to slave
+ *
+ * @author Ali Younis <ayounis @ uci.edu>
+ * @version 1.0
+ * @since 2016-04-12
+ */
+public class IoTZigbeeAddress {
+
+ /**
+ * IoTZigbeeAddress class properties
+ */
+ private final String zigbeeAddress;
+ private final byte[] zigbeeAddressByteArray;
+
+ /**
+ * Class constructor
+ *
+ * @param zAddress Zigbee long address
+ */
+ public IoTZigbeeAddress(String zAddress) {
+ zigbeeAddress = zAddress;
+ // convert to byte array
+ zigbeeAddressByteArray = new byte[zAddress.length() / 2];
+ for (int i = 0; i < zAddress.length(); i += 2) {
+ zigbeeAddressByteArray[i / 2] = (byte) ((Character.digit(zAddress.charAt(i), 16) << 4)
+ + Character.digit(zAddress.charAt(i + 1), 16));
+ }
+ }
+
+ /**
+ * getAddress() method that returns the zigbee address as a human readable String
+ *
+ * @return String
+ */
+ public String getAddress() {
+ return zigbeeAddress;
+ }
+
+ /**
+ * getAddressBytes() method that returns the zigbee address as a byte array
+ *
+ * @return byte[]
+ */
+ public byte[] getAddressBytes() {
+ return zigbeeAddressByteArray;
+ }
+}
--- /dev/null
+
+/** Zigbee Callback for when a zigbee message is received.
+ *
+ * @author Ali Younis <ayounis @ uci.edu>
+ * @version 1.0
+ * @since 2016-04-12
+ */
+public interface IoTZigbeeCallback {
+
+ /** Callback method for when data comes from the zigbee object
+ *
+ * @param zigbee message class [IoTZigbeeMessage] .
+ *
+ * @return [void] None.
+ */
+ public void newMessageAvailable(IoTZigbeeMessage _zm);
+}
--- /dev/null
+
+/** Zigbee Message generic class.
+ *
+ * @author Ali Younis <ayounis @ uci.edu>
+ * @version 1.0
+ * @since 2016-04-19
+ */
+public class IoTZigbeeMessage {
+
+ // private variables
+ private int packetId;
+
+ /**
+ * Constructor
+ */
+ public IoTZigbeeMessage(int _packetId) {
+ packetId = _packetId;
+ }
+
+
+ /**
+ * getPacketId() method that returns the packet id of the received message
+ *
+ * @return int
+ */
+ public int getPacketId() {
+ return packetId;
+ }
+
+}
--- /dev/null
+
+
+/** Zigbee Message Send Address Response.
+ *
+ * @author Ali Younis <ayounis @ uci.edu>
+ * @version 1.0
+ * @since 2016-04-19
+ */
+public class IoTZigbeeMessageSendAddressResponse extends IoTZigbeeMessage {
+
+ // private variables
+ private boolean succeeded;
+ private String message;
+
+ /**
+ * Constructor
+ */
+ public IoTZigbeeMessageSendAddressResponse(int _packetId, boolean _succeded) {
+ super(_packetId);
+ succeeded = _succeded;
+ }
+
+ /**
+ * getSucceeded() method that returns the success status
+ *
+ * @return boolean
+ */
+ public boolean getSucceeded() {
+ return succeeded;
+ }
+}
--- /dev/null
+
+/** Zigbee Message Zcl Configure Reporting.
+ *
+ * @author Ali Younis <ayounis @ uci.edu>
+ * @version 1.0
+ * @since 2016-04-19
+ */
+public class IoTZigbeeMessageZclConfigureReporting extends IoTZigbeeMessage {
+
+ // private variables
+ private boolean succeeded;
+ private String message;
+
+ /**
+ * Constructor
+ */
+ public IoTZigbeeMessageZclConfigureReporting(int _packetId, boolean _succeded, String _message) {
+ super(_packetId);
+ message = _message;
+ succeeded = _succeded;
+ }
+
+
+ /**
+ * getSucceeded() method that returns the success status
+ *
+ * @return boolean
+ */
+ public boolean getSucceeded() {
+ return succeeded;
+ }
+
+ /**
+ * getMessage() method that returns the error message
+ *
+ * @return String
+ */
+ public String getMessage() {
+ return message;
+ }
+}
--- /dev/null
+
+import java.util.List;
+
+/** Zigbee Message Zcl Configure Reporting Response.
+ *
+ * @author Ali Younis <ayounis @ uci.edu>
+ * @version 1.0
+ * @since 2016-04-19
+ */
+public class IoTZigbeeMessageZclConfigureReportingResponse extends IoTZigbeeMessage {
+
+ static public class Attribute {
+
+ // private variables
+ private int attributeId;
+ private boolean successOrFail;
+ private boolean isReport;
+
+ /**
+ * Constructor
+ */
+ public Attribute(int _attributeId, boolean _successOrFail, boolean _isReport) {
+ attributeId = _attributeId;
+ successOrFail = _successOrFail;
+ isReport = _isReport;
+ }
+
+ /**
+ * getAttributeId() method that returns attribute id
+ *
+ * @return int
+ */
+ public int getAttributeId() {
+ return attributeId;
+ }
+
+ /**
+ * getIsReport() method that gets if the direction is report of receive
+ *
+ * @return boolean
+ */
+ public boolean getIsReport() {
+ return isReport;
+ }
+
+ /**
+ * getSuccessOrFail() method is if the configure for this attribute failed or succeeded
+ *
+ * @return boolean
+ */
+ public boolean getSuccessOrFail() {
+ return successOrFail;
+ }
+ }
+
+ // private variables
+ private int clusterId;
+ private int profileId;
+ private boolean allSuccess;
+ private List <Attribute> attributes;
+
+ /**
+ * Constructor
+ */
+ public IoTZigbeeMessageZclConfigureReportingResponse(int _packetId, int _clusterId, int _profileId, boolean _allSuccess, List <Attribute> _attributes) {
+ super(_packetId);
+
+ clusterId = _clusterId;
+ profileId = _profileId;
+ allSuccess = _allSuccess;
+ attributes = _attributes;
+ }
+
+ /**
+ * getAllSuccess() method that returns if all the configurations succeeded
+ *
+ * @return boolean
+ */
+ public boolean getAllSuccess() {
+ return allSuccess;
+ }
+
+ /**
+ * getClusterId() method that returns the cluster id
+ *
+ * @return int
+ */
+ public int getClusterId() {
+ return clusterId;
+ }
+
+ /**
+ * getProfileId() method that returns the profile id
+ *
+ * @return int
+ */
+ public int getProfileId() {
+ return profileId;
+ }
+
+ /**
+ * getAttributes() method that returns if all attributes if one of there was a failure to configure
+ *
+ * @return List <Attribute>
+ */
+ public List <Attribute> getAttributes() {
+ return attributes;
+ }
+}
--- /dev/null
+
+/** Zigbee Message Zcl Read Attributes.
+ *
+ * @author Ali Younis <ayounis @ uci.edu>
+ * @version 1.0
+ * @since 2016-04-19
+ */
+public class IoTZigbeeMessageZclReadAttributes extends IoTZigbeeMessage {
+
+ // private variables
+ private boolean succeeded;
+ private String message;
+
+ /**
+ * Constructor
+ */
+ public IoTZigbeeMessageZclReadAttributes(int _packetId, boolean _succeded, String _message) {
+ super(_packetId);
+ message = _message;
+ succeeded = _succeded;
+ }
+
+ /**
+ * getSucceeded() method that returns the success status
+ *
+ * @return boolean
+ */
+ public boolean getSucceeded() {
+ return succeeded;
+ }
+
+ /**
+ * getMessage() method that returns the error message
+ *
+ * @return String
+ */
+ public String getMessage() {
+ return message;
+ }
+}
--- /dev/null
+
+import java.util.List;
+
+/** Zigbee Message Zcl Read Attributes Response.
+ *
+ * @author Ali Younis <ayounis @ uci.edu>
+ * @version 1.0
+ * @since 2016-04-19
+ */
+public class IoTZigbeeMessageZclReadAttributesResponse extends IoTZigbeeMessage {
+
+ static class Attribute {
+
+ // private variables
+ private int attributeId;
+ private int dataType;
+ private boolean successOrFail;
+ private byte[] data;
+
+ /**
+ * Constructor
+ */
+ public Attribute(int _attributeId, int _dataType, boolean _successOrFail, byte[] _data) {
+ attributeId = _attributeId;
+ dataType = _dataType;
+ successOrFail = _successOrFail;
+ data = _data;
+ }
+
+
+ /**
+ * getAttributeId() method that returns attribute id
+ *
+ * @return int
+ */
+ public int getAttributeId() {
+ return attributeId;
+ }
+
+
+ /**
+ * getDataType() method that returns attribute data type
+ *
+ * @return int
+ */
+ public int getDataType() {
+ return dataType;
+ }
+
+
+ /**
+ * getSuccessOrFail() method is if the configure for this attribute failed or succeeded
+ *
+ * @return boolean
+ */
+ public boolean getSuccessOrFail() {
+ return successOrFail;
+ }
+
+
+ /**
+ * getData() method that returns attribute data
+ *
+ * @return byte[]
+ */
+ public byte[] getData() {
+ return data;
+ }
+ }
+
+ // private variables
+ private int clusterId;
+ private int profileId;
+ private List <Attribute> attributes;
+
+ /**
+ * Constructor
+ */
+ public IoTZigbeeMessageZclReadAttributesResponse(int _packetId, int _clusterId, int _profileId, List <Attribute> _attributes) {
+ super(_packetId);
+
+ clusterId = _clusterId;
+ profileId = _profileId;
+ attributes = _attributes;
+ }
+
+ /**
+ * getClusterId() method that returns the cluster id
+ *
+ * @return int
+ */
+ public int getClusterId() {
+ return clusterId;
+ }
+
+ /**
+ * getProfileId() method that returns the profile id
+ *
+ * @return int
+ */
+ public int getProfileId() {
+ return profileId;
+ }
+
+ /**
+ * getAttributes() method that returns all attributes data
+ *
+ * @return List <Attribute>
+ */
+ public List <Attribute> getAttributes() {
+ return attributes;
+ }
+}
--- /dev/null
+
+import java.util.List;
+
+/** Zigbee Message Zcl Report Attributes.
+ *
+ * @author Ali Younis <ayounis @ uci.edu>
+ * @version 1.0
+ * @since 2016-04-19
+ */
+public class IoTZigbeeMessageZclReportAttributes extends IoTZigbeeMessage {
+
+ static public class Attribute {
+
+ // private variables
+ private int attributeId;
+ private int dataType;
+ private byte[] data;
+
+ /**
+ * Constructor
+ */
+ public Attribute(int _attributeId, int _dataType, byte[] _data) {
+ attributeId = _attributeId;
+ dataType = _dataType;
+ data = _data;
+ }
+
+ /**
+ * getAttributeId() method that returns attribute id
+ *
+ * @return int
+ */
+ public int getAttributeId() {
+ return attributeId;
+ }
+
+
+ /**
+ * getDataType() method that returns attribute data type
+ *
+ * @return int
+ */
+ public int getDataType() {
+ return dataType;
+ }
+
+
+ /**
+ * getData() method that returns attribute data
+ *
+ * @return byte[]
+ */
+ public byte[] getData() {
+ return data;
+ }
+
+ }
+
+ // private variables
+ private int clusterId;
+ private int profileId;
+ private List <Attribute> attributes;
+
+ /**
+ * Constructor
+ */
+ public IoTZigbeeMessageZclReportAttributes(int _packetId, int _clusterId, int _profileId, List <Attribute> _attributes) {
+ super(_packetId);
+
+ clusterId = _clusterId;
+ profileId = _profileId;
+ attributes = _attributes;
+ }
+
+ /**
+ * getClusterId() method that returns the cluster id
+ *
+ * @return int
+ */
+ public int getClusterId() {
+ return clusterId;
+ }
+
+ /**
+ * getProfileId() method that returns the profile id
+ *
+ * @return int
+ */
+ public int getProfileId() {
+ return profileId;
+ }
+
+ /**
+ * getAttributes() method that returns all attributes data
+ *
+ * @return List <Attribute>
+ */
+ public List <Attribute> getAttributes() {
+ return attributes;
+ }
+}
--- /dev/null
+/** Zigbee Message Zcl Write Attributes Response.
+ *
+ * @author changwoo Lee <changwl2 @ uci.edu>
+ * @version 1.0
+ * @since 2016-10-18
+ */
+public class IoTZigbeeMessageZclWriteAttributesResponse extends IoTZigbeeMessage {
+
+ private boolean SuccessOrFail=false;
+ private int clusterId;
+ private int profileId;
+
+ public IoTZigbeeMessageZclWriteAttributesResponse(int _packetId, int _clusterId, int _profileId, boolean _SuccessOrFail){
+ super(_packetId);
+
+ clusterId = _clusterId;
+ profileId = _profileId;
+ SuccessOrFail = _SuccessOrFail;
+ }
+ public boolean getSuccessOrFail(){
+ return SuccessOrFail;
+ }
+
+ public int getClusterId() {
+ return clusterId;
+ }
+
+ public int getProfileId() {
+ return profileId;
+ }
+}
--- /dev/null
+/** Zigbee Message Zcl Zone Status Change Notification.
+ *
+ * @author changwoo Lee <changwl2 @ uci.edu>
+ * @version 1.0
+ * @since 2016-10-28
+ */
+public class IoTZigbeeMessageZclZoneStatusChangeNotification extends IoTZigbeeMessage {
+
+ private boolean SuccessOrFail=false;
+ private int clusterId;
+ private int profileId;
+ private int status;
+
+ public IoTZigbeeMessageZclZoneStatusChangeNotification(int _packetId, int _clusterId, int _profileId, int _status, boolean _SuccessOrFail){
+ super(_packetId);
+
+ clusterId = _clusterId;
+ profileId = _profileId;
+ status = _status;
+ SuccessOrFail = _SuccessOrFail;
+ }
+ public boolean getSuccessOrFail(){
+ return SuccessOrFail;
+ }
+
+ public int getClusterId() {
+ return clusterId;
+ }
+
+ public int getProfileId() {
+ return profileId;
+ }
+
+ public int getStatus(){
+ return status;
+ }
+}
--- /dev/null
+
+/** Zigbee Message Zdo Bind Response.
+ *
+ * @author Ali Younis <ayounis @ uci.edu>
+ * @version 1.0
+ * @since 2016-04-19
+ */
+public class IoTZigbeeMessageZdoBindResponse extends IoTZigbeeMessage {
+
+ // private variables
+ private boolean succeeded;
+ private String message;
+
+ /**
+ * Constructor
+ */
+ public IoTZigbeeMessageZdoBindResponse(int _packetId, boolean _succeded, String _message) {
+ super(_packetId);
+ message = _message;
+ succeeded = _succeded;
+ }
+
+ /**
+ * getSucceeded() method that returns the success status
+ *
+ * @return boolean
+ */
+ public boolean getSucceeded() {
+ return succeeded;
+ }
+
+ /**
+ * getMessage() method that returns the error message
+ *
+ * @return String
+ */
+ public String getMessage() {
+ return message;
+ }
+}
--- /dev/null
+
+/** Zigbee Message Zdo UnBind Response.
+ *
+ * @author Ali Younis <ayounis @ uci.edu>
+ * @version 1.0
+ * @since 2016-05-04
+ */
+public class IoTZigbeeMessageZdoUnBindResponse extends IoTZigbeeMessage {
+
+ // private variables
+ private boolean succeeded;
+ private String message;
+
+ /**
+ * Constructor
+ */
+ public IoTZigbeeMessageZdoUnBindResponse(int _packetId, boolean _succeded, String _message) {
+ super(_packetId);
+ message = _message;
+ succeeded = _succeded;
+ }
+
+ /**
+ * getSucceeded() method that returns the success status
+ *
+ * @return boolean
+ */
+ public boolean getSucceeded() {
+ return succeeded;
+ }
+
+ /**
+ * getMessage() method that returns the error message
+ *
+ * @return String
+ */
+ public String getMessage() {
+ return message;
+ }
+}
--- /dev/null
+import java.util.List;
+import java.util.ArrayList;
+
+public interface MoistureSensor {
+ public void init();
+ public float getMoisture();
+ public long getTimestampOfLastReading();
+ public void setId(int id);
+ public int getId();
+ public void registerCallback(MoistureSensorSmartCallback _callbackTo);
+}
--- /dev/null
+import java.util.List;
+import java.util.ArrayList;
+
+public interface MoistureSensorCallback {
+ public void newReadingAvailable(int sensorId, float moisture, long timeStampOfLastReading);
+}
--- /dev/null
+import java.util.List;
+import java.util.ArrayList;
+
+public interface MoistureSensorSmart {
+
+ public long getTimestampOfLastReading();
+ public int getId();
+ public void registerCallback(MoistureSensorCallback _callbackTo);
+ public float getMoisture();
+ public void setId(int id);
+ public void init();
+}
--- /dev/null
+import java.util.List;
+import java.util.ArrayList;
+
+public interface MoistureSensorSmartCallback {
+
+ public void newReadingAvailable(int sensorId, float moisture, long timeStampOfLastReading);
+}
--- /dev/null
+// Standard Java Packages
+import java.util.*;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.Semaphore;
+
+// Checker annotations
+//import iotchecker.qual.*;
+//import iotcode.annotation.*;
+
+// IoT Packages
+import iotruntime.slave.*;
+//import iotcode.interfaces.*;
+import iotruntime.zigbee.*;
+
+/** Class Smartthings sensor driver for Smartthings sensor devices.
+ *
+ * @author Changwoo Lee, Rahmadi Trimananda <rtrimana @ uci.edu>
+ * @version 1.0
+ * @since 2016-12-01
+ */
+public class MotionSensor implements IoTZigbeeCallback, SmartthingsSensor {
+
+ private final int TIMEOUT_FOR_RESEND_MSEC = 900;
+
+ private IoTZigbee zigConnection = null;
+ private boolean didClose; // make sure that the clean up was done correctly
+ private boolean detectStatus = false;
+
+ private int detectedValue = 0;
+ private Date timestampOfLastDetecting = null;
+
+ private AtomicBoolean didAlreadyClose = new AtomicBoolean(true);
+ private AtomicBoolean didAlreadyInit = new AtomicBoolean(false);
+ private AtomicBoolean didWriteAttrb = new AtomicBoolean(false);
+ private AtomicBoolean didMatchDscr = new AtomicBoolean(false);
+ static Semaphore gettingLatestDataMutex = new Semaphore(1);
+
+ private List < SmartthingsSensorCallback > callbackList = new CopyOnWriteArrayList < SmartthingsSensorCallback > ();
+
+ @config private IoTSet<IoTDeviceAddress> devUdpAddress;
+ @config private IoTSet<IoTZigbeeAddress> devZigbeeAddress;
+
+ public MotionSensor(IoTSet<IoTDeviceAddress> dSet, IoTSet<IoTZigbeeAddress> zigSet) {
+ devUdpAddress = dSet;
+ devZigbeeAddress = zigSet;
+ }
+
+ public void init() {
+
+ if (didAlreadyInit.compareAndSet(false, true) == false) {
+ return; // already init
+ }
+
+ didAlreadyClose.set(false);
+
+ try {
+ Iterator itrUdp = devUdpAddress.iterator();
+ Iterator itrZig = devZigbeeAddress.iterator();
+
+ zigConnection = new IoTZigbee((IoTDeviceAddress)itrUdp.next(), (IoTZigbeeAddress)itrZig.next());
+
+ // DEBUG
+ System.out.println("DEBUG: Allocate iterators to print out addresses!");
+ Iterator itrDebugUdp = devUdpAddress.iterator();
+ IoTDeviceAddress iotaddDebug = (IoTDeviceAddress)itrDebugUdp.next();
+ System.out.println("IP address: " + iotaddDebug.getCompleteAddress());
+ System.out.println("Source port: " + iotaddDebug.getSourcePortNumber());
+ System.out.println("Destination port: " + iotaddDebug.getDestinationPortNumber());
+
+ Iterator itrDebugZig = devZigbeeAddress.iterator();
+ IoTZigbeeAddress iotzbaddDebug = (IoTZigbeeAddress)itrDebugZig.next();
+ System.out.println("Zigbee address: " + iotzbaddDebug.getAddress());
+
+ zigConnection.registerCallback(this);
+ System.out.println("Register callback!");
+ zigConnection.init();
+ System.out.println("Initialized!");
+
+ //made by changwoo
+ sleep(10);
+
+ System.out.println("Sending Management Permit Joining Request");
+ for(int z=0; z<3; z++){
+ zigConnection.sendManagementPermitJoiningRequest(0x0001, 0x0036, 0x00);
+ sleep(0);
+ }
+
+ //made by changwoo
+ while (!didWriteAttrb.get()) {
+ System.out.println("Sending Write Attribute Request");
+ zigConnection.sendWriteAttributesCommand(0x0002, 0x0500, 0x0104, 0x01);
+ sleep(0);
+ }
+
+ //made by changwoo
+ System.out.println("Sending Enrollment Reponse");
+ zigConnection.sendEnrollmentResponse(0x0003, 0x0500, 0x0104, 0x01);
+ sleep(0);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ //made by changwoo
+ private void sleep(int multipleTime){
+ if(multipleTime<=0){
+ multipleTime=1;
+ }
+ try{
+ Thread.sleep(TIMEOUT_FOR_RESEND_MSEC*multipleTime);
+ } catch(Exception e){
+ e.printStackTrace();
+ }
+ }
+
+ public void close() {
+
+ if (didAlreadyClose.compareAndSet(false, true) == false) {
+ return; // already init
+ }
+
+ didAlreadyInit.set(false);
+
+
+ try {
+ zigConnection.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ public void Finalize() {
+ if (!didClose) {
+ close();
+ }
+ }
+
+ public int getValue() {
+
+ int tmp = 0;
+ try {
+ gettingLatestDataMutex.acquire();
+ tmp = detectedValue;
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ gettingLatestDataMutex.release();
+
+ return tmp;
+ }
+
+ // MotionSensor:
+ // - 24 = no motion = false
+ // - 26 = motion = true
+ // After getting 26, if there is no motion for ~12 seconds then we get back 24
+ public boolean isActiveValue() {
+
+ int tmp = getValue();
+ if (tmp == 26)
+ detectStatus = true;
+ else // Getting 24 here
+ detectStatus = false;
+
+ return detectStatus;
+ }
+
+ public long getTimestampOfLastReading() {
+
+ Date tmp = null;
+ try {
+ gettingLatestDataMutex.acquire();
+ tmp = (Date)timestampOfLastDetecting.clone();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ gettingLatestDataMutex.release();
+ long retLong = tmp.getTime();
+
+ return retLong;
+ }
+
+ public void newMessageAvailable(IoTZigbeeMessage _zm) {
+
+ //made by changwoo
+ if(_zm instanceof IoTZigbeeMessageZclZoneStatusChangeNotification){
+ IoTZigbeeMessageZclZoneStatusChangeNotification message = (IoTZigbeeMessageZclZoneStatusChangeNotification)_zm;
+ if(message.getSuccessOrFail()){
+ //do something!
+
+ try {
+ gettingLatestDataMutex.acquire();
+ detectedValue = message.getStatus();
+ timestampOfLastDetecting = new Date();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ gettingLatestDataMutex.release();
+ try {
+ for (SmartthingsSensorCallback cb : callbackList) {
+ cb.newReadingAvailable(this.getValue(), this.isActiveValue());
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }//if
+
+ //made by changwoo
+ } else if (_zm instanceof IoTZigbeeMessageZclWriteAttributesResponse) {
+ IoTZigbeeMessageZclWriteAttributesResponse message = (IoTZigbeeMessageZclWriteAttributesResponse)_zm;
+ if (message.getSuccessOrFail()) {
+ didWriteAttrb.set(true);
+ }
+ }
+ }
+
+ public void registerCallback(SmartthingsSensorCallback _callbackTo) {
+ callbackList.add(_callbackTo);
+ }
+}
--- /dev/null
+// Standard Java Packages
+import java.util.*;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.Semaphore;
+
+// Checker annotations
+//import iotchecker.qual.*;
+//import iotcode.annotation.*;
+
+// IoT Packages
+import iotruntime.slave.*;
+import iotcode.interfaces.*;
+import iotruntime.zigbee.*;
+
+/** Class Smartthings sensor driver for Smartthings sensor devices.
+ *
+ * @author Changwoo Lee, Rahmadi Trimananda <rtrimana @ uci.edu>
+ * @version 1.0
+ * @since 2016-12-01
+ */
+public class MultipurposeSensor implements IoTZigbeeCallback, SmartthingsSensor {
+
+ private final int TIMEOUT_FOR_RESEND_MSEC = 900;
+
+ private IoTZigbee zigConnection = null;
+ private boolean didClose; // make sure that the clean up was done correctly
+ private boolean detectStatus = false;
+
+ private int detectedValue = 0;
+ private Date timestampOfLastDetecting = null;
+
+ private AtomicBoolean didAlreadyClose = new AtomicBoolean(true);
+ private AtomicBoolean didAlreadyInit = new AtomicBoolean(false);
+ private AtomicBoolean didWriteAttrb = new AtomicBoolean(false);
+ private AtomicBoolean didMatchDscr = new AtomicBoolean(false);
+ static Semaphore gettingLatestDataMutex = new Semaphore(1);
+
+ private List < SmartthingsSensorCallback > callbackList = new CopyOnWriteArrayList < SmartthingsSensorCallback > ();
+
+ @config private IoTSet<IoTDeviceAddress> devUdpAddress;
+ @config private IoTSet<IoTZigbeeAddress> devZigbeeAddress;
+
+ public MultipurposeSensor(IoTSet<IoTDeviceAddress> dSet, IoTSet<IoTZigbeeAddress> zigSet) {
+ devUdpAddress = dSet;
+ devZigbeeAddress = zigSet;
+ }
+
+ public void init() {
+
+ if (didAlreadyInit.compareAndSet(false, true) == false) {
+ return; // already init
+ }
+
+ didAlreadyClose.set(false);
+
+ try {
+ Iterator itrUdp = devUdpAddress.iterator();
+ Iterator itrZig = devZigbeeAddress.iterator();
+
+ zigConnection = new IoTZigbee((IoTDeviceAddress)itrUdp.next(), (IoTZigbeeAddress)itrZig.next());
+
+ // DEBUG
+ System.out.println("DEBUG: Allocate iterators to print out addresses!");
+ Iterator itrDebugUdp = devUdpAddress.iterator();
+ IoTDeviceAddress iotaddDebug = (IoTDeviceAddress)itrDebugUdp.next();
+ System.out.println("IP address: " + iotaddDebug.getCompleteAddress());
+ System.out.println("Source port: " + iotaddDebug.getSourcePortNumber());
+ System.out.println("Destination port: " + iotaddDebug.getDestinationPortNumber());
+
+ Iterator itrDebugZig = devZigbeeAddress.iterator();
+ IoTZigbeeAddress iotzbaddDebug = (IoTZigbeeAddress)itrDebugZig.next();
+ System.out.println("Zigbee address: " + iotzbaddDebug.getAddress());
+
+ zigConnection.registerCallback(this);
+ System.out.println("Register callback!");
+ zigConnection.init();
+ System.out.println("Initialized!");
+
+ //made by changwoo
+ sleep(10);
+ System.out.println("Sending Management Permit Joining Request");
+ for(int z=0; z<3; z++){
+ zigConnection.sendManagementPermitJoiningRequest(0x0001, 0x0036, 0x00);
+ sleep(0);
+ }
+
+ //made by changwoo
+ while (!didWriteAttrb.get()) {
+ System.out.println("Sending Write Attribute Request");
+ zigConnection.sendWriteAttributesCommand(0x0002, 0x0500, 0x0104, 0x01);
+ sleep(0);
+ }
+
+ //made by changwoo
+ System.out.println("Sending Enrollment Reponse");
+ zigConnection.sendEnrollmentResponse(0x0003, 0x0500, 0x0104, 0x01);
+ sleep(0);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ //made by changwoo
+ private void sleep(int multipleTime){
+ if(multipleTime<=0){
+ multipleTime=1;
+ }
+ try{
+ Thread.sleep(TIMEOUT_FOR_RESEND_MSEC*multipleTime);
+ } catch(Exception e){
+ e.printStackTrace();
+ }
+ }
+
+ public void close() {
+
+ if (didAlreadyClose.compareAndSet(false, true) == false) {
+ return; // already init
+ }
+
+ didAlreadyInit.set(false);
+
+
+ try {
+ zigConnection.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void Finalize() {
+ if (!didClose) {
+ close();
+ }
+ }
+
+ public int getValue() {
+
+ int tmp = 0;
+ try {
+ gettingLatestDataMutex.acquire();
+ tmp = detectedValue;
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ gettingLatestDataMutex.release();
+
+ return tmp;
+ }
+
+ // MultipurposeSensor:
+ // - 24 = close = false
+ // - 25 = open = true
+ public boolean isActiveValue() {
+
+ int tmp = getValue();
+ if (tmp == 25)
+ detectStatus = true;
+ else // Getting 24 here
+ detectStatus = false;
+
+ return detectStatus;
+ }
+
+ public long getTimestampOfLastReading() {
+
+ Date tmp = null;
+ try {
+ gettingLatestDataMutex.acquire();
+ tmp = (Date)timestampOfLastDetecting.clone();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ gettingLatestDataMutex.release();
+ long retLong = tmp.getTime();
+
+ return retLong;
+ }
+
+ public void newMessageAvailable(IoTZigbeeMessage _zm) {
+
+ //made by changwoo
+ if(_zm instanceof IoTZigbeeMessageZclZoneStatusChangeNotification){
+ IoTZigbeeMessageZclZoneStatusChangeNotification message = (IoTZigbeeMessageZclZoneStatusChangeNotification)_zm;
+ if(message.getSuccessOrFail()){
+ //do something!
+ try {
+ gettingLatestDataMutex.acquire();
+ detectedValue = message.getStatus();
+ timestampOfLastDetecting = new Date();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ gettingLatestDataMutex.release();
+ try {
+ for (SmartthingsSensorCallback cb : callbackList) {
+ cb.newReadingAvailable(this.getValue(), this.isActiveValue());
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }//if
+
+ //made by changwoo
+ }//if
+ else if (_zm instanceof IoTZigbeeMessageZclWriteAttributesResponse) {
+ IoTZigbeeMessageZclWriteAttributesResponse message = (IoTZigbeeMessageZclWriteAttributesResponse)_zm;
+ if (message.getSuccessOrFail()) {
+ didWriteAttrb.set(true);
+ }//if
+ }//else if
+ }
+
+ public void registerCallback(SmartthingsSensorCallback _callbackTo) {
+ callbackList.add(_callbackTo);
+ }
+}
--- /dev/null
+// Standard Java Packages
+import java.util.Date;
+
+//RMI packages
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+// Checker annotations
+//import iotchecker.qual.*;
+
+
+/** Class Smartthings sensor interface for Smartthings sensor devices.
+ *
+ * @author Rahmadi Trimananda <rtrimana @ uci.edu>, Changwoo Lee
+ * @version 1.0
+ * @since 2016-12-21
+ */
+public interface SmartthingsSensor extends Remote {
+
+ /** Method to get the latests moisture reading from the sensor
+ *
+ * @return [float] Moisture as a percentage.
+ */
+ public int getValue() throws RemoteException;
+
+
+ /** Method to probe the sensor for active value
+ *
+ * @return [boolean] True means sensor is actively detecting something.
+ */
+ public boolean isActiveValue() throws RemoteException;
+
+
+ /** Method to get the latests moisture reading timestamp from the sensor
+ *
+ * @return [Date] timestamp of latest moisture reading, null if no reading occurred yet.
+ */
+ public long getTimestampOfLastReading() throws RemoteException;
+
+
+ /** Method to initialize the moisture sensor.
+ *
+ * @param None.
+ *
+ * @return [void] None.
+ */
+ public void init() throws RemoteException;
+
+
+ /** Register an object to retrieve callbacks when new sensor reading is available
+ *
+ * @param _callbackTo [MoistureSensorCallback].
+ *
+ * @return [void] None.
+ */
+ public void registerCallback(SmartthingsSensorCallback _callbackTo) throws RemoteException;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
--- /dev/null
+// Checker annotations
+//import iotchecker.qual.*;
+
+
+/** Smartthings Sensor Callback for when a camera changes state (new frame available).
+ *
+ * @author Rahmadi Trimananda <rtrimana @ uci.edu>, Changwoo Lee
+ * @version 1.0
+ * @since 2016-12-21
+ */
+
+public interface SmartthingsSensorCallback {
+
+ //public void newReadingAvailable(@NonLocalRemote SmartthingsSensor _sensor) throws RemoteException;
+ public void newReadingAvailable(int _value, boolean _activeValue);
+}
--- /dev/null
+// Standard Java Packages
+import java.util.Iterator;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.Semaphore;
+
+
+// Checker annotations
+//import iotchecker.qual.*;
+
+// IoT Packages
+import iotruntime.slave.*;
+//import iotcode.interfaces.MoistureSensor;
+//import iotcode.interfaces.MoistureSensorSmartCallback;
+import iotruntime.zigbee.*;
+//import iotcode.annotation.*;
+
+public class SpruceSensor implements IoTZigbeeCallback, MoistureSensor {
+
+ private final int TIMEOUT_FOR_RESEND_MSEC = 1000;
+
+ private IoTZigbee zigConnection = null;
+ private boolean didClose; // make sure that the clean up was done correctly
+
+ private float humidity = 0;
+ private Date timestampOfLastHumidity = null;
+
+ private AtomicBoolean didBind = new AtomicBoolean(false);
+ private AtomicBoolean didConfigureReporting = new AtomicBoolean(false);
+ private AtomicBoolean didAlreadyInit = new AtomicBoolean(false);
+ private AtomicBoolean didAlreadyClose = new AtomicBoolean(true);
+ static Semaphore gettingLatestDataMutex = new Semaphore(1);
+
+ private List < MoistureSensorSmartCallback > callbackList = new CopyOnWriteArrayList < MoistureSensorSmartCallback > ();
+
+ private int sensorId = 0;
+
+ @config private IoTSet<IoTDeviceAddress> devUdpAddress;
+ @config private IoTSet<IoTZigbeeAddress> devZigbeeAddress;
+
+ public SpruceSensor(IoTSet<IoTDeviceAddress> _devUdpAddress, IoTSet<IoTZigbeeAddress> _devZigbeeAddress) {
+ devUdpAddress = _devUdpAddress;
+ devZigbeeAddress = _devZigbeeAddress;
+ }
+
+ public void init() {
+
+ if (didAlreadyInit.compareAndSet(false, true) == false) {
+ return; // already init
+ }
+
+ didAlreadyClose.set(false);
+
+ try {
+ Iterator itrUdp = devUdpAddress.iterator();
+ Iterator itrZig = devZigbeeAddress.iterator();
+
+ zigConnection = new IoTZigbee((IoTDeviceAddress)itrUdp.next(), (IoTZigbeeAddress)itrZig.next());
+
+ // DEBUG
+ System.out.println("DEBUG: Allocate iterators to print out addresses!");
+ Iterator itrDebugUdp = devUdpAddress.iterator();
+ IoTDeviceAddress iotaddDebug = (IoTDeviceAddress)itrDebugUdp.next();
+ System.out.println("IP address: " + iotaddDebug.getCompleteAddress());
+ System.out.println("Source port: " + iotaddDebug.getSourcePortNumber());
+ System.out.println("Destination port: " + iotaddDebug.getDestinationPortNumber());
+
+ Iterator itrDebugZig = devZigbeeAddress.iterator();
+ IoTZigbeeAddress iotzbaddDebug = (IoTZigbeeAddress)itrDebugZig.next();
+ System.out.println("Zigbee address: " + iotzbaddDebug.getAddress());
+
+ zigConnection.registerCallback(this);
+ System.out.println("Register callback!");
+ zigConnection.init();
+ System.out.println("Initialized!");
+
+ while (!didBind.get()) {
+ zigConnection.sendBindRequest(0x0001, 0x0405, 0x01);
+ try {
+ Thread.sleep(TIMEOUT_FOR_RESEND_MSEC);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ while (!didConfigureReporting.get()) {
+ zigConnection.sendConfigureReportingCommand(0x0001, 0x0405, 0x0104, 0x01, 0x0000, 0x21, 0x0001, 0x0001, null);
+ try {
+ Thread.sleep(TIMEOUT_FOR_RESEND_MSEC);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void close() {
+
+ if (didAlreadyClose.compareAndSet(false, true) == false) {
+ return; // already init
+ }
+
+ didAlreadyInit.set(false);
+
+
+ try {
+ zigConnection.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void Finalize() {
+ if (!didClose) {
+ close();
+ }
+ }
+
+ public void setId(int id) {
+
+ sensorId = id;
+
+ }
+
+ public int getId() {
+
+ return sensorId;
+
+ }
+
+ public float getMoisture() {
+
+ float tmp = 0;
+ try {
+ gettingLatestDataMutex.acquire();
+ tmp = humidity;
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ gettingLatestDataMutex.release();
+
+ return tmp;
+ }
+
+ public long getTimestampOfLastReading() {
+
+ Date tmp = null;
+ try {
+ gettingLatestDataMutex.acquire();
+ tmp = (Date)timestampOfLastHumidity.clone();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ gettingLatestDataMutex.release();
+ long retLong = tmp.getTime();
+
+ return retLong;
+ }
+
+ public void newMessageAvailable(IoTZigbeeMessage _zm) {
+
+ if (_zm instanceof IoTZigbeeMessageZdoBindResponse) {
+ IoTZigbeeMessageZdoBindResponse message = (IoTZigbeeMessageZdoBindResponse)_zm;
+ if (message.getSucceeded()) {
+ didBind.set(true);
+ }
+
+ } else if (_zm instanceof IoTZigbeeMessageZclConfigureReportingResponse) {
+ IoTZigbeeMessageZclConfigureReportingResponse message = (IoTZigbeeMessageZclConfigureReportingResponse)_zm;
+ if (message.getAllSuccess()) {
+ didConfigureReporting.set(true);
+ }
+
+ } else if (_zm instanceof IoTZigbeeMessageZclReportAttributes) {
+ IoTZigbeeMessageZclReportAttributes message = (IoTZigbeeMessageZclReportAttributes)_zm;
+ List <IoTZigbeeMessageZclReportAttributes.Attribute> attrList = message.getAttributes();
+
+ if (attrList.size() == 1) {
+ if (attrList.get(0).getAttributeId() == 0) {
+ byte[] data = attrList.get(0).getData();
+
+ int value = (data[0] * 256) + data[1];
+
+ try {
+ gettingLatestDataMutex.acquire();
+ humidity = (float)value / (float)100.0;
+ timestampOfLastHumidity = new Date();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ gettingLatestDataMutex.release();
+
+ try {
+ for (MoistureSensorSmartCallback cb : callbackList) {
+ cb.newReadingAvailable(this.getId(), this.getMoisture(), this.getTimestampOfLastReading());
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ }
+ }
+
+ public void registerCallback(MoistureSensorSmartCallback _callbackTo) {
+ callbackList.add(_callbackTo);
+ }
+}
--- /dev/null
+// Standard Java Packages
+import java.util.*;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.Semaphore;
+
+// Checker annotations
+//import iotchecker.qual.*;
+//import iotcode.annotation.*;
+
+// IoT Packages
+import iotruntime.slave.*;
+import iotcode.interfaces.*;
+import iotruntime.zigbee.*;
+
+/** Class Smartthings sensor driver for Smartthings sensor devices.
+ *
+ * @author Changwoo Lee, Rahmadi Trimananda <rtrimana @ uci.edu>
+ * @version 1.0
+ * @since 2016-12-01
+ */
+public class WaterLeakSensor implements IoTZigbeeCallback, SmartthingsSensor {
+
+ private final int TIMEOUT_FOR_RESEND_MSEC = 900;
+
+ private IoTZigbee zigConnection = null;
+ private boolean didClose; // make sure that the clean up was done correctly
+ private boolean detectStatus = false;
+
+ private int detectedValue = 0;
+ private Date timestampOfLastDetecting = null;
+
+ private AtomicBoolean didAlreadyInit = new AtomicBoolean(false);
+ private AtomicBoolean didAlreadyClose = new AtomicBoolean(true);
+ private AtomicBoolean didWriteAttrb = new AtomicBoolean(false);
+ private AtomicBoolean didMatchDscr = new AtomicBoolean(false);
+ static Semaphore gettingLatestDataMutex = new Semaphore(1);
+
+ private List < SmartthingsSensorCallback > callbackList = new CopyOnWriteArrayList < SmartthingsSensorCallback > ();
+
+ @config private IoTSet<IoTDeviceAddress> devUdpAddress;
+ @config private IoTSet<IoTZigbeeAddress> devZigbeeAddress;
+
+ public WaterLeakSensor(IoTSet<IoTDeviceAddress> dSet, IoTSet<IoTZigbeeAddress> zigSet) {
+ devUdpAddress = dSet;
+ devZigbeeAddress = zigSet;
+ }
+
+ public void init() {
+
+ if (didAlreadyInit.compareAndSet(false, true) == false) {
+ return; // already init
+ }
+
+ didAlreadyClose.set(false);
+
+ try {
+ Iterator itrUdp = devUdpAddress.iterator();
+ Iterator itrZig = devZigbeeAddress.iterator();
+
+ zigConnection = new IoTZigbee((IoTDeviceAddress)itrUdp.next(), (IoTZigbeeAddress)itrZig.next());
+
+ // DEBUG
+ System.out.println("DEBUG: Allocate iterators to print out addresses!");
+ Iterator itrDebugUdp = devUdpAddress.iterator();
+ IoTDeviceAddress iotaddDebug = (IoTDeviceAddress)itrDebugUdp.next();
+ System.out.println("IP address: " + iotaddDebug.getCompleteAddress());
+ System.out.println("Source port: " + iotaddDebug.getSourcePortNumber());
+ System.out.println("Destination port: " + iotaddDebug.getDestinationPortNumber());
+
+ Iterator itrDebugZig = devZigbeeAddress.iterator();
+ IoTZigbeeAddress iotzbaddDebug = (IoTZigbeeAddress)itrDebugZig.next();
+ System.out.println("Zigbee address: " + iotzbaddDebug.getAddress());
+
+ zigConnection.registerCallback(this);
+ System.out.println("Register callback!");
+ zigConnection.init();
+ System.out.println("Initialized!");
+
+ //made by changwoo
+ sleep(10);
+ System.out.println("Sending Management Permit Joining Request");
+ for(int z=0; z<3; z++){
+ zigConnection.sendManagementPermitJoiningRequest(0x0001, 0x0036, 0x00);
+ sleep(0);
+ }
+
+ //made by changwoo
+ while (!didWriteAttrb.get()) {
+ System.out.println("Sending Write Attribute Request");
+ zigConnection.sendWriteAttributesCommand(0x0002, 0x0500, 0x0104, 0x01);
+ sleep(0);
+ }
+
+ //made by changwoo
+ System.out.println("Sending Enrollment Reponse");
+ zigConnection.sendEnrollmentResponse(0x0003, 0x0500, 0x0104, 0x01);
+ sleep(0);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ //made by changwoo
+ private void sleep(int multipleTime){
+ if(multipleTime<=0){
+ multipleTime=1;
+ }
+ try{
+ Thread.sleep(TIMEOUT_FOR_RESEND_MSEC*multipleTime);
+ } catch(Exception e){
+ e.printStackTrace();
+ }
+ }
+
+ public void close() {
+
+ if (didAlreadyClose.compareAndSet(false, true) == false) {
+ return; // already init
+ }
+
+ didAlreadyInit.set(false);
+
+
+ try {
+ zigConnection.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void Finalize() {
+ if (!didClose) {
+ close();
+ }
+ }
+
+ public int getValue() {
+
+ int tmp = 0;
+ try {
+ gettingLatestDataMutex.acquire();
+ tmp = detectedValue;
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ gettingLatestDataMutex.release();
+
+ return tmp;
+ }
+
+ // WaterLeakSensor:
+ // - 24 = no leak = false
+ // - 25 = leak = true
+ public boolean isActiveValue() {
+
+ int tmp = getValue();
+ if (tmp == 25)
+ detectStatus = true;
+ else // Getting 24 here
+ detectStatus = false;
+
+ return detectStatus;
+ }
+
+ public long getTimestampOfLastReading() {
+
+ Date tmp = null;
+ try {
+ gettingLatestDataMutex.acquire();
+ tmp = (Date)timestampOfLastDetecting.clone();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ gettingLatestDataMutex.release();
+ long retLong = tmp.getTime();
+
+ return retLong;
+ }
+
+ public void newMessageAvailable(IoTZigbeeMessage _zm) {
+
+ //made by changwoo
+ if(_zm instanceof IoTZigbeeMessageZclZoneStatusChangeNotification){
+ IoTZigbeeMessageZclZoneStatusChangeNotification message = (IoTZigbeeMessageZclZoneStatusChangeNotification)_zm;
+ if(message.getSuccessOrFail()){
+ //do something!
+
+ try {
+ gettingLatestDataMutex.acquire();
+ detectedValue = message.getStatus();
+ timestampOfLastDetecting = new Date();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ gettingLatestDataMutex.release();
+ try {
+ for (SmartthingsSensorCallback cb : callbackList) {
+ cb.newReadingAvailable(this.getValue(), this.isActiveValue());
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }//if
+
+ //made by changwoo
+ }//if
+ else if (_zm instanceof IoTZigbeeMessageZclWriteAttributesResponse) {
+ IoTZigbeeMessageZclWriteAttributesResponse message = (IoTZigbeeMessageZclWriteAttributesResponse)_zm;
+ if (message.getSuccessOrFail()) {
+ didWriteAttrb.set(true);
+ }//if
+ }//else if
+ }
+
+ public void registerCallback(SmartthingsSensorCallback _callbackTo) {
+ callbackList.add(_callbackTo);
+ }
+}
--- /dev/null
+import java.util.Map;
+import java.net.*;
+import java.io.*;
+import java.util.*;
+
+import iotruntime.*;
+import iotruntime.zigbee.*;
+
+//import iotcode.interfaces.*;
+import java.rmi.RemoteException;
+
+public class ZigbeeTest implements MoistureSensorSmartCallback {
+
+ public final int SOCKET_SEND_BUFFER_SIZE = 1024;
+ public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024;
+
+
+ public ZigbeeTest() {
+ }
+
+
+ public void newReadingAvailable(int sensorId, float moisture, long timeStampOfLastReading) {
+ System.out.println("New Message!!!!");
+ System.out.println(moisture);
+ System.out.println("Reading time: " + timeStampOfLastReading);
+ }
+
+
+
+
+
+
+ public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException, IOException, RemoteException{
+
+ String message = "type: policy_set\n";
+ //message += "ip_address: " + "192.168.1.1\n"; // local ip address
+ message += "ip_address: " + "192.168.2.108\n"; // local ip address
+ //message += "port: " + "5959\n"; // port number
+ message += "port: " + "5557\n"; // port number
+ message += "device_address_long: " + "000d6f0003ebf2ee" + "\n";
+ //DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("128.195.204.110"), 5005); // address and port of the gateway
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("192.168.2.227"), 5005); // address and port of the gateway
+
+ DatagramSocket socket = new DatagramSocket();
+ socket.setSendBufferSize(4096);
+ socket.setReceiveBufferSize(4096);
+
+ socket.send(sendPacket);
+
+
+
+
+ //IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("128.195.204.110", 5557, 5005,false,false);
+ IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.227", 5557, 5005,false,false);
+ IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress("000d6f0003ebf2ee");
+
+ Set<IoTZigbeeAddress> zigSet = new HashSet<IoTZigbeeAddress>();
+ zigSet.add(zigAddrLong);
+ IoTSet<IoTZigbeeAddress> zigIotSet = new IoTSet<IoTZigbeeAddress>(zigSet);
+
+ Set<IoTDeviceAddress> devSet = new HashSet<IoTDeviceAddress>();
+ devSet.add(zigUdpAddr);
+ IoTSet<IoTDeviceAddress> devIotSet = new IoTSet<IoTDeviceAddress>(devSet);
+ SpruceSensor sen = new SpruceSensor(devIotSet, zigIotSet);
+
+ System.out.println("About to init");
+ sen.init();
+
+ ZigbeeTest zTest = new ZigbeeTest();
+
+ sen.registerCallback(zTest);
+
+
+ System.out.println("Loop Begin");
+ while (true) {
+
+ }
+ }
+}
--- /dev/null
+import java.util.Map;
+import java.net.*;
+import java.io.*;
+import java.util.*;
+
+import iotruntime.*;
+import iotruntime.zigbee.*;
+
+//import iotcode.interfaces.*;
+import java.rmi.RemoteException;
+
+public class ZigbeeTest_motion implements SmartthingsSensorCallback {
+ public final int SOCKET_SEND_BUFFER_SIZE = 1024;
+ public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024;
+ private static final String MY_IP_ADDRESS = "192.168.2.108";
+ public static final String DEVIDE_MAC_ADDRESS = "000d6f00057c92a7"; //motion
+
+//000d6f000bbd5398
+//000d6f00057c92a7
+ public void newReadingAvailable(int _value, boolean _activeValue) {
+ System.out.println("New Message!!!!");
+ System.out.println("motion : "+ _value);
+ System.out.println("active? : "+ _activeValue);
+ }
+
+ public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException, IOException, RemoteException{
+
+ String message = "type: policy_set\n";
+ message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address
+ message += "port: " + "5956\n"; // port number
+ message += "device_address_long: " + DEVIDE_MAC_ADDRESS + "\n";
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("192.168.2.227"), 5005); // address and port of the gateway which means Raspberry PI's IP address
+ DatagramSocket socket = new DatagramSocket(11222);
+ socket.setSendBufferSize(4096);
+ socket.setReceiveBufferSize(4096);
+ socket.send(sendPacket);
+
+ IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.227", 5956, 5005,false,false);
+ IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVIDE_MAC_ADDRESS);
+
+ Set<IoTZigbeeAddress> zigSet = new HashSet<IoTZigbeeAddress>();
+ zigSet.add(zigAddrLong);
+ IoTSet<IoTZigbeeAddress> zigIotSet = new IoTSet<IoTZigbeeAddress>(zigSet);
+
+ Set<IoTDeviceAddress> devSet = new HashSet<IoTDeviceAddress>();
+ devSet.add(zigUdpAddr);
+ IoTSet<IoTDeviceAddress> devIotSet = new IoTSet<IoTDeviceAddress>(devSet);
+ MotionSensor sen = new MotionSensor(devIotSet, zigIotSet);
+
+ System.out.println("About to init");
+ sen.init();
+
+ ZigbeeTest_motion zTest = new ZigbeeTest_motion();
+ sen.registerCallback(zTest);
+
+ System.out.println("Loop Begin");
+ while (true) {
+
+ }
+ }
+}
--- /dev/null
+import java.util.Map;
+import java.net.*;
+import java.io.*;
+import java.util.*;
+
+import iotruntime.*;
+import iotruntime.zigbee.*;
+
+//import iotcode.interfaces.*;
+import java.rmi.RemoteException;
+
+public class ZigbeeTest_multipurpose implements SmartthingsSensorCallback {
+ public final int SOCKET_SEND_BUFFER_SIZE = 1024;
+ public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024;
+ private static final String MY_IP_ADDRESS = "192.168.2.108";
+ public static final String DEVIDE_MAC_ADDRESS = "000d6f000bbd3413"; //Multipurpose sensor
+
+ public void newReadingAvailable(int _value, boolean _activeValue) {
+ System.out.println("New Message!!!!");
+ System.out.println("multipurpose : "+ _value);
+ System.out.println("active? : "+ _activeValue);
+ }
+
+ public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException, IOException, RemoteException{
+
+ String message = "type: policy_set\n";
+ message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address
+ message += "port: " + "5957\n"; // port number
+ message += "device_address_long: " + DEVIDE_MAC_ADDRESS + "\n";
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("192.168.2.227"), 5005);
+ DatagramSocket socket = new DatagramSocket(11111);
+ socket.setSendBufferSize(4096);
+ socket.setReceiveBufferSize(4096);
+ socket.send(sendPacket);
+
+ IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.227", 5957, 5005,false,false);
+ IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVIDE_MAC_ADDRESS);
+
+ Set<IoTZigbeeAddress> zigSet = new HashSet<IoTZigbeeAddress>();
+ zigSet.add(zigAddrLong);
+ IoTSet<IoTZigbeeAddress> zigIotSet = new IoTSet<IoTZigbeeAddress>(zigSet);
+
+ Set<IoTDeviceAddress> devSet = new HashSet<IoTDeviceAddress>();
+ devSet.add(zigUdpAddr);
+ IoTSet<IoTDeviceAddress> devIotSet = new IoTSet<IoTDeviceAddress>(devSet);
+ MultipurposeSensor sen = new MultipurposeSensor(devIotSet, zigIotSet);
+
+ System.out.println("About to init");
+ sen.init();
+
+ ZigbeeTest_multipurpose zTest = new ZigbeeTest_multipurpose();
+ sen.registerCallback(zTest);
+
+ System.out.println("Loop Begin");
+ while (true) {
+
+ }
+ }
+}
--- /dev/null
+import java.util.Map;
+import java.net.*;
+import java.io.*;
+import java.util.*;
+
+import iotruntime.*;
+import iotruntime.zigbee.*;
+
+//import iotcode.interfaces.*;
+import java.rmi.RemoteException;
+
+public class ZigbeeTest_waterleak implements SmartthingsSensorCallback {
+ public final int SOCKET_SEND_BUFFER_SIZE = 1024;
+ public final int SOCKET_RECEIVE_BUFFER_SIZE = 1024;
+ private static final String MY_IP_ADDRESS = "192.168.2.108";
+ private static final int PORT_NUMBER = 5959;
+ public static final String DEVIDE_MAC_ADDRESS = "000d6f000ada75e3"; //water leak
+
+ public void newReadingAvailable(int _value, boolean _activeValue) {
+ System.out.println("New Message!!!!");
+ System.out.println("water leak : "+ _value);
+ System.out.println("active? : "+ _activeValue);
+ }
+
+ public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException, IOException, RemoteException{
+
+ String message = "type: policy_set\n";
+ message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address
+ message += "port: " + PORT_NUMBER + "\n"; // port number
+ message += "device_address_long: " + DEVIDE_MAC_ADDRESS + "\n";
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("192.168.2.227"), 5005); // address and port of the gateway which means Raspberry PI's IP address
+ DatagramSocket socket = new DatagramSocket(22222);
+ socket.setSendBufferSize(4096);
+ socket.setReceiveBufferSize(4096);
+ socket.send(sendPacket);
+
+ IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.227", PORT_NUMBER, 5005,false,false);
+ IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVIDE_MAC_ADDRESS);
+
+ Set<IoTZigbeeAddress> zigSet = new HashSet<IoTZigbeeAddress>();
+ zigSet.add(zigAddrLong);
+ IoTSet<IoTZigbeeAddress> zigIotSet = new IoTSet<IoTZigbeeAddress>(zigSet);
+
+ Set<IoTDeviceAddress> devSet = new HashSet<IoTDeviceAddress>();
+ devSet.add(zigUdpAddr);
+ IoTSet<IoTDeviceAddress> devIotSet = new IoTSet<IoTDeviceAddress>(devSet);
+ WaterLeakSensor sen = new WaterLeakSensor(devIotSet, zigIotSet);
+
+ System.out.println("About to init");
+ sen.init();
+
+ ZigbeeTest_waterleak zTest = new ZigbeeTest_waterleak();
+ sen.registerCallback(zTest);
+
+ System.out.println("Loop Begin");
+ while (true) {
+
+ }
+ }
+}
--- /dev/null
+cwd=$(pwd)
+cd $cwd
+javac -cp ./../iotjava:./../../../bin:.:../../packages/build *.java
--- /dev/null
+cwd=$(pwd)
+cd ./../../..
+make iotjava
+cd benchmarks
+make nocheck
+cd $cwd
+cd ../../packages/
+# ./clean.bash
+# ./build.bash
+cd $cwd
+javac -cp ./../../../bin:.:../../packages/build *.java
\ No newline at end of file
--- /dev/null
+rm -rf *.class
--- /dev/null
+//package iotcode.annotation;
+
+import java.lang.annotation.*;
+
+/** @config annotation
+ * This annotation is for the runtime system to instrument IoTSet and IoTRelation
+ * Re-instated on 12/12/2016
+ *
+ * @author Rahmadi Trimananda <rahmadi.trimananda @ uci.edu>
+ * @version 1.0
+ * @since 2016-12-12
+ */
+@Retention(RetentionPolicy.RUNTIME)
+public @interface config {
+}
--- /dev/null
+#java -cp ./../../../bin:.:../../packages/build ZigbeeTest
+java -cp ./../iotjava:./../../../bin:. ZigbeeTest
--- /dev/null
+java -cp ./../iotjava:./../../../bin:. ZigbeeTest_motion
--- /dev/null
+#java -cp ./../../../bin:.:../../packages/build ZigbeeTest
+java -cp ./../iotjava:./../../../bin:. ZigbeeTest_multipurpose
--- /dev/null
+java -cp ./../iotjava:./../../../bin:. ZigbeeTest_waterleak
}
}
+ //made by changwoo
+ public void sendChangeSwtichRequest(int packetId, int clusterId, int profileId, int value, int deviceEndpoint) throws IOException {
+ String message = "type: zcl_change_switch_request\n";
+ message += "packet_id: " + String.format("%04x", packetId) + "\n";
+ message += "value: " + String.format("%01x", value) + "\n";
+ message += "cluster_id: " + String.format("%04x", clusterId) + "\n";
+ message += "profile_id: " + String.format("%04x", profileId) + "\n";
+ message += "device_address_long: " + zigbeeAddress.getAddress() + "\n";
+ message += "device_endpoint: " + String.format("%02x", deviceEndpoint) + "\n";
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort);
+ socket.send(sendPacket);
+ }
+
+ //made by changwoo
+ public void sendBroadcastingRouteRecordRequest(int packetId) throws IOException {
+ String message = "type: zdo_broadcast_route_record_request\n";
+ message += "packet_id: " + String.format("%04x", packetId) + "\n";
+ message += "device_address_long: " + zigbeeAddress.getAddress() + "\n";
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort);
+ socket.send(sendPacket);
+ }
+
+ //made by changwoo
+ public void sendEnrollmentResponse(int packetId, int clusterId, int profileId, int deviceEndpoint) throws IOException {
+ String message = "type: zcl_enrollment_response\n";
+ message += "packet_id: " + String.format("%04x", packetId) + "\n";
+ message += "device_address_long: " + zigbeeAddress.getAddress() + "\n";
+ message += "cluster_id: " + String.format("%04x", clusterId) + "\n";
+ message += "profile_id: " + String.format("%04x", profileId) + "\n";
+ message += "device_endpoint: " + String.format("%02x", deviceEndpoint) + "\n";
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort);
+ socket.send(sendPacket);
+ }
+
+ //made by changwoo
+ public void sendWriteAttributesCommand(int packetId, int clusterId, int profileId, int deviceEndpoint) throws IOException {
+ String message = "type: zcl_write_attributes\n";
+ message += "packet_id: " + String.format("%04x", packetId) + "\n";
+ message += "device_address_long: " + zigbeeAddress.getAddress() + "\n";
+ message += "cluster_id: " + String.format("%04x", clusterId) + "\n";
+ message += "profile_id: " + String.format("%04x", profileId) + "\n";
+ message += "device_endpoint: " + String.format("%02x", deviceEndpoint) + "\n";
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort);
+ socket.send(sendPacket);
+ }
+
+ //made by changwoo
+ public void sendManagementPermitJoiningRequest(int packetId, int clusterId, int deviceEndpoint) throws IOException {
+ String message = "type: management_permit_joining_request\n";
+ message += "packet_id: " + String.format("%04x", packetId) + "\n";
+ message += "device_address_long: " + zigbeeAddress.getAddress() + "\n";
+ message += "cluster_id: " + String.format("%04x", clusterId) + "\n";
+ message += "device_endpoint: " + String.format("%02x", deviceEndpoint) + "\n";
+ DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort);
+ socket.send(sendPacket);
+ }
public void sendBindRequest(int packetId, int clusterId, int deviceEndpoint) throws IOException {
String message = "type: zdo_bind_request\n";
--- /dev/null
+package iotruntime.zigbee;
+
+/** Zigbee Message Zcl Write Attributes Response.
+ *
+ * @author changwoo Lee <changwl2 @ uci.edu>
+ * @version 1.0
+ * @since 2016-10-18
+ */
+public class IoTZigbeeMessageZclWriteAttributesResponse extends IoTZigbeeMessage {
+
+ private boolean SuccessOrFail=false;
+ private int clusterId;
+ private int profileId;
+
+ public IoTZigbeeMessageZclWriteAttributesResponse(int _packetId, int _clusterId, int _profileId, boolean _SuccessOrFail){
+ super(_packetId);
+
+ clusterId = _clusterId;
+ profileId = _profileId;
+ SuccessOrFail = _SuccessOrFail;
+ }
+ public boolean getSuccessOrFail(){
+ return SuccessOrFail;
+ }
+
+ public int getClusterId() {
+ return clusterId;
+ }
+
+ public int getProfileId() {
+ return profileId;
+ }
+}
--- /dev/null
+package iotruntime.zigbee;
+
+/** Zigbee Message Zcl Zone Status Change Notification.
+ *
+ * @author changwoo Lee <changwl2 @ uci.edu>
+ * @version 1.0
+ * @since 2016-10-28
+ */
+public class IoTZigbeeMessageZclZoneStatusChangeNotification extends IoTZigbeeMessage {
+
+ private boolean SuccessOrFail=false;
+ private int clusterId;
+ private int profileId;
+ private int status;
+
+ public IoTZigbeeMessageZclZoneStatusChangeNotification(int _packetId, int _clusterId, int _profileId, int _status, boolean _SuccessOrFail){
+ super(_packetId);
+
+ clusterId = _clusterId;
+ profileId = _profileId;
+ status = _status;
+ SuccessOrFail = _SuccessOrFail;
+ }
+ public boolean getSuccessOrFail(){
+ return SuccessOrFail;
+ }
+
+ public int getClusterId() {
+ return clusterId;
+ }
+
+ public int getProfileId() {
+ return profileId;
+ }
+
+ public int getStatus(){
+ return status;
+ }
+}