From 3ce0924a2451b4f2573c390f99cadf8d307977bd Mon Sep 17 00:00:00 2001 From: rtrimana Date: Thu, 5 Jan 2017 13:12:00 -0800 Subject: [PATCH] Testing Smartthings sensors with some adjustments for 4th benchmark --- benchmarks/other/ZigbeeTest/IoTAddress.java | 77 +++ .../other/ZigbeeTest/IoTDeviceAddress.java | 138 +++++ benchmarks/other/ZigbeeTest/IoTRelation.java | 105 ++++ benchmarks/other/ZigbeeTest/IoTSet.java | 80 +++ benchmarks/other/ZigbeeTest/IoTZigbee.java | 497 ++++++++++++++++++ .../other/ZigbeeTest/IoTZigbeeAddress.java | 49 ++ .../other/ZigbeeTest/IoTZigbeeCallback.java | 17 + .../other/ZigbeeTest/IoTZigbeeMessage.java | 30 ++ .../IoTZigbeeMessageSendAddressResponse.java | 31 ++ ...IoTZigbeeMessageZclConfigureReporting.java | 41 ++ ...eMessageZclConfigureReportingResponse.java | 109 ++++ .../IoTZigbeeMessageZclReadAttributes.java | 40 ++ ...igbeeMessageZclReadAttributesResponse.java | 113 ++++ .../IoTZigbeeMessageZclReportAttributes.java | 101 ++++ ...gbeeMessageZclWriteAttributesResponse.java | 31 ++ ...essageZclZoneStatusChangeNotification.java | 37 ++ .../IoTZigbeeMessageZdoBindResponse.java | 40 ++ .../IoTZigbeeMessageZdoUnBindResponse.java | 40 ++ .../other/ZigbeeTest/MoistureSensor.java | 11 + .../ZigbeeTest/MoistureSensorCallback.java | 6 + .../other/ZigbeeTest/MoistureSensorSmart.java | 12 + .../MoistureSensorSmartCallback.java | 7 + benchmarks/other/ZigbeeTest/MotionSensor.java | 224 ++++++++ .../other/ZigbeeTest/MultipurposeSensor.java | 221 ++++++++ .../other/ZigbeeTest/SmartthingsSensor.java | 71 +++ .../ZigbeeTest/SmartthingsSensorCallback.java | 16 + benchmarks/other/ZigbeeTest/SpruceSensor.java | 216 ++++++++ .../other/ZigbeeTest/WaterLeakSensor.java | 222 ++++++++ benchmarks/other/ZigbeeTest/ZigbeeTest.java | 79 +++ .../other/ZigbeeTest/ZigbeeTest_motion.java | 61 +++ .../ZigbeeTest/ZigbeeTest_multipurpose.java | 59 +++ .../ZigbeeTest/ZigbeeTest_waterleak.java | 60 +++ benchmarks/other/ZigbeeTest/build.bash | 3 + benchmarks/other/ZigbeeTest/buildall.bash | 11 + benchmarks/other/ZigbeeTest/clean.bash | 1 + benchmarks/other/ZigbeeTest/config.java | 15 + benchmarks/other/ZigbeeTest/run.bash | 2 + benchmarks/other/ZigbeeTest/run_motion.bash | 1 + .../other/ZigbeeTest/run_multipurpose.bash | 2 + .../other/ZigbeeTest/run_waterleak.bash | 1 + iotjava/iotruntime/zigbee/IoTZigbee.java | 56 ++ ...gbeeMessageZclWriteAttributesResponse.java | 33 ++ ...essageZclZoneStatusChangeNotification.java | 39 ++ 43 files changed, 3005 insertions(+) create mode 100644 benchmarks/other/ZigbeeTest/IoTAddress.java create mode 100644 benchmarks/other/ZigbeeTest/IoTDeviceAddress.java create mode 100644 benchmarks/other/ZigbeeTest/IoTRelation.java create mode 100644 benchmarks/other/ZigbeeTest/IoTSet.java create mode 100644 benchmarks/other/ZigbeeTest/IoTZigbee.java create mode 100644 benchmarks/other/ZigbeeTest/IoTZigbeeAddress.java create mode 100644 benchmarks/other/ZigbeeTest/IoTZigbeeCallback.java create mode 100644 benchmarks/other/ZigbeeTest/IoTZigbeeMessage.java create mode 100644 benchmarks/other/ZigbeeTest/IoTZigbeeMessageSendAddressResponse.java create mode 100644 benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclConfigureReporting.java create mode 100644 benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclConfigureReportingResponse.java create mode 100644 benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclReadAttributes.java create mode 100644 benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclReadAttributesResponse.java create mode 100644 benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclReportAttributes.java create mode 100644 benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclWriteAttributesResponse.java create mode 100644 benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclZoneStatusChangeNotification.java create mode 100644 benchmarks/other/ZigbeeTest/IoTZigbeeMessageZdoBindResponse.java create mode 100644 benchmarks/other/ZigbeeTest/IoTZigbeeMessageZdoUnBindResponse.java create mode 100644 benchmarks/other/ZigbeeTest/MoistureSensor.java create mode 100644 benchmarks/other/ZigbeeTest/MoistureSensorCallback.java create mode 100644 benchmarks/other/ZigbeeTest/MoistureSensorSmart.java create mode 100644 benchmarks/other/ZigbeeTest/MoistureSensorSmartCallback.java create mode 100644 benchmarks/other/ZigbeeTest/MotionSensor.java create mode 100644 benchmarks/other/ZigbeeTest/MultipurposeSensor.java create mode 100644 benchmarks/other/ZigbeeTest/SmartthingsSensor.java create mode 100644 benchmarks/other/ZigbeeTest/SmartthingsSensorCallback.java create mode 100644 benchmarks/other/ZigbeeTest/SpruceSensor.java create mode 100644 benchmarks/other/ZigbeeTest/WaterLeakSensor.java create mode 100644 benchmarks/other/ZigbeeTest/ZigbeeTest.java create mode 100644 benchmarks/other/ZigbeeTest/ZigbeeTest_motion.java create mode 100644 benchmarks/other/ZigbeeTest/ZigbeeTest_multipurpose.java create mode 100644 benchmarks/other/ZigbeeTest/ZigbeeTest_waterleak.java create mode 100755 benchmarks/other/ZigbeeTest/build.bash create mode 100755 benchmarks/other/ZigbeeTest/buildall.bash create mode 100755 benchmarks/other/ZigbeeTest/clean.bash create mode 100644 benchmarks/other/ZigbeeTest/config.java create mode 100755 benchmarks/other/ZigbeeTest/run.bash create mode 100755 benchmarks/other/ZigbeeTest/run_motion.bash create mode 100755 benchmarks/other/ZigbeeTest/run_multipurpose.bash create mode 100755 benchmarks/other/ZigbeeTest/run_waterleak.bash create mode 100644 iotjava/iotruntime/zigbee/IoTZigbeeMessageZclWriteAttributesResponse.java create mode 100644 iotjava/iotruntime/zigbee/IoTZigbeeMessageZclZoneStatusChangeNotification.java diff --git a/benchmarks/other/ZigbeeTest/IoTAddress.java b/benchmarks/other/ZigbeeTest/IoTAddress.java new file mode 100644 index 0000000..8e82847 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/IoTAddress.java @@ -0,0 +1,77 @@ + +// Java packages +import java.net.Socket; +import java.net.ServerSocket; +import java.net.InetAddress; +import java.net.UnknownHostException; + +/** Class IoTAddress is a wrapper class to pass + * IoTSet of any addresses from master to slave + * + * @author Rahmadi Trimananda + * @version 1.0 + * @since 2016-04-22 + */ +public class IoTAddress { + + /** + * IoTDeviceAddress class properties + */ + protected final InetAddress inetAddress; + + /** + * Class constructor + * + * @param sAddress String address + */ + public IoTAddress(String sAddress) throws UnknownHostException { + + inetAddress = InetAddress.getByName(sAddress); + } + + /** + * getHostAddress() method + * + * @return String + */ + public String getHostAddress() { + + return inetAddress.getHostAddress(); + + } + + /** + * getHostName() method + * + * @return String + */ + public String getHostName() { + + return inetAddress.getHostName(); + + } + + /** + * getUrl() method + * + * @return String + */ + public String getURL(String strURLComplete) { + + //e.g. http:// + inetAddress.getHostAddress() + strURLComplete + // http://192.168.2.254/cgi-bin/mjpg/video.cgi? + return "http://" + inetAddress.getHostAddress() + strURLComplete; + + } + + /** + * getCompleteAddress() method + * + * @return String + */ + public String getCompleteAddress() { + + return inetAddress.toString(); + + } +} diff --git a/benchmarks/other/ZigbeeTest/IoTDeviceAddress.java b/benchmarks/other/ZigbeeTest/IoTDeviceAddress.java new file mode 100644 index 0000000..1dff865 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/IoTDeviceAddress.java @@ -0,0 +1,138 @@ + +// Java packages +import java.net.Socket; +import java.net.ServerSocket; +import java.net.InetAddress; +import java.net.UnknownHostException; + +/** Class IoTDeviceAddress is a wrapper class to pass + * IoTSet of device addresses from master to slave + * + * @author Rahmadi Trimananda + * @version 1.0 + * @since 2016-02-18 + */ +public class IoTDeviceAddress extends IoTAddress { + + /** + * IoTDeviceAddress class properties + */ + private int iSrcPort; + private int iDstPort; + private final String sAddress; + + // the wildcard status of this address + private final boolean isSrcPortWildCard; + private final boolean isDstPortWildCard; + + + /** + * Class constructor + * + * @param sAddress String address + * @param _iSrcPort Source port number + * @param _iDstPort Destination port number + * @param _isSrcPortWildCard Is this source port a wild card (=can change port number)? + * @param _isDstPortWildCard Is this destination port a wild card (=can change port number)? + */ + public IoTDeviceAddress(String _sAddress, int _iSrcPort, int _iDstPort, boolean _isSrcPortWildCard, + boolean _isDstPortWildCard) throws UnknownHostException { + + super(_sAddress); + sAddress = _sAddress; + iSrcPort = _iSrcPort; + iDstPort = _iDstPort; + + isSrcPortWildCard = _isSrcPortWildCard; + isDstPortWildCard = _isDstPortWildCard; + } + + /** + * getSourcePortNumber() method + * + * @return int + */ + public int getSourcePortNumber() { + + return iSrcPort; + + } + + /** + * getDestinationPortNumber() method + * + * @return int + */ + public int getDestinationPortNumber() { + + return iDstPort; + + } + + /** + * setSrcPort() method + * + * @param port Port number + * @return void + */ + public void setSrcPort(int port) { + if (isSrcPortWildCard) { + iSrcPort = port; + } + } + + /** + * setDstPort() method + * + * @param port Port number + * @return void + */ + public void setDstPort(int port) { + if (isDstPortWildCard) { + iDstPort = port; + } + } + + /** + * getAddress() method + * + * @return String + */ + public String getAddress() { + return sAddress; + } + + /** + * getHostAddress() method + * + * @return String + */ + public static String getLocalHostAddress() { + + String strLocalHostAddress = null; + try { + strLocalHostAddress = InetAddress.getLocalHost().getHostAddress(); + } catch (UnknownHostException ex) { + ex.printStackTrace(); + } + return strLocalHostAddress; + } + + /** + * getIsSrcPortWildcard() method + * + * @return boolean + */ + public boolean getIsSrcPortWildcard() { + return isSrcPortWildCard; + } + + /** + * getIsDstPortWildcard() method + * + * @return boolean + */ + public boolean getIsDstPortWildcard() { + return isDstPortWildCard; + } +} diff --git a/benchmarks/other/ZigbeeTest/IoTRelation.java b/benchmarks/other/ZigbeeTest/IoTRelation.java new file mode 100644 index 0000000..438b3d3 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/IoTRelation.java @@ -0,0 +1,105 @@ + +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 + * @version 1.0 + * @since 2015-12-01 + */ +public final class IoTRelation { + + /** + * Reference to an object Map + */ + private Map > mapRelation; + private int iSize; + + /** + * Class constructor (pass the reference to this immutable wrapper) + */ + protected IoTRelation(Map> 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>> + */ + public Set>> entrySet() { + + return new HashSet>>(mapRelation.entrySet()); + + } + + /** + * Method keySet() inherited from Map interface + * + * @return Set + */ + public Set keySet() { + + return new HashSet(mapRelation.keySet()); + + } + + /** + * Method get() inherited from Map interface + * + * @param key The first Object that is usually a key in a Map + * @return HashSet + */ + public HashSet get(K key) { + + return new HashSet(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; + + } +} diff --git a/benchmarks/other/ZigbeeTest/IoTSet.java b/benchmarks/other/ZigbeeTest/IoTSet.java new file mode 100644 index 0000000..0f316cd --- /dev/null +++ b/benchmarks/other/ZigbeeTest/IoTSet.java @@ -0,0 +1,80 @@ + +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 to implement; we don't provide interfaces to modify + * the contents, but we do provide means to read them out + * + * @author Rahmadi Trimananda + * @version 1.0 + * @since 2015-12-01 + */ +public final class IoTSet { + + /** + * Reference to an object Set + */ + private Set set; + + /** + * Class constructor (pass the reference to this immutable wrapper) + */ + public IoTSet(Set 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 iterator() { + + return new HashSet(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 values() { + + return new HashSet(set); + + } +} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbee.java b/benchmarks/other/ZigbeeTest/IoTZigbee.java new file mode 100644 index 0000000..31c1d8a --- /dev/null +++ b/benchmarks/other/ZigbeeTest/IoTZigbee.java @@ -0,0 +1,497 @@ + +// 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 , Changwoo Lee + * @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 callbackList = new ArrayList(); + + /** + * 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 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 packetData = new HashMap(); + 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 attrList = new ArrayList(); + + 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 attrList = new ArrayList(); + + 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 attrList = new ArrayList(); + + 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 pairedValues = new ArrayList(); + 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; + } + +} + + + + + + + + + + + + + + + + diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeAddress.java b/benchmarks/other/ZigbeeTest/IoTZigbeeAddress.java new file mode 100644 index 0000000..e15c518 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/IoTZigbeeAddress.java @@ -0,0 +1,49 @@ + +/** Class IoTZigbeeAddress is a wrapper class to pass + * IoTSet of device addresses from master to slave + * + * @author Ali Younis + * @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; + } +} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeCallback.java b/benchmarks/other/ZigbeeTest/IoTZigbeeCallback.java new file mode 100644 index 0000000..94d75db --- /dev/null +++ b/benchmarks/other/ZigbeeTest/IoTZigbeeCallback.java @@ -0,0 +1,17 @@ + +/** Zigbee Callback for when a zigbee message is received. + * + * @author Ali Younis + * @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); +} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeMessage.java b/benchmarks/other/ZigbeeTest/IoTZigbeeMessage.java new file mode 100644 index 0000000..c1df838 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/IoTZigbeeMessage.java @@ -0,0 +1,30 @@ + +/** Zigbee Message generic class. + * + * @author Ali Younis + * @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; + } + +} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageSendAddressResponse.java b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageSendAddressResponse.java new file mode 100644 index 0000000..cfb31c1 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageSendAddressResponse.java @@ -0,0 +1,31 @@ + + +/** Zigbee Message Send Address Response. + * + * @author Ali Younis + * @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; + } +} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclConfigureReporting.java b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclConfigureReporting.java new file mode 100644 index 0000000..60a98cb --- /dev/null +++ b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclConfigureReporting.java @@ -0,0 +1,41 @@ + +/** Zigbee Message Zcl Configure Reporting. + * + * @author Ali Younis + * @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; + } +} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclConfigureReportingResponse.java b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclConfigureReportingResponse.java new file mode 100644 index 0000000..05fda4b --- /dev/null +++ b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclConfigureReportingResponse.java @@ -0,0 +1,109 @@ + +import java.util.List; + +/** Zigbee Message Zcl Configure Reporting Response. + * + * @author Ali Younis + * @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 attributes; + + /** + * Constructor + */ + public IoTZigbeeMessageZclConfigureReportingResponse(int _packetId, int _clusterId, int _profileId, boolean _allSuccess, List _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 + */ + public List getAttributes() { + return attributes; + } +} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclReadAttributes.java b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclReadAttributes.java new file mode 100644 index 0000000..bb20d9d --- /dev/null +++ b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclReadAttributes.java @@ -0,0 +1,40 @@ + +/** Zigbee Message Zcl Read Attributes. + * + * @author Ali Younis + * @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; + } +} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclReadAttributesResponse.java b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclReadAttributesResponse.java new file mode 100644 index 0000000..bd6f75a --- /dev/null +++ b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclReadAttributesResponse.java @@ -0,0 +1,113 @@ + +import java.util.List; + +/** Zigbee Message Zcl Read Attributes Response. + * + * @author Ali Younis + * @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 attributes; + + /** + * Constructor + */ + public IoTZigbeeMessageZclReadAttributesResponse(int _packetId, int _clusterId, int _profileId, List _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 + */ + public List getAttributes() { + return attributes; + } +} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclReportAttributes.java b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclReportAttributes.java new file mode 100644 index 0000000..de1bfd0 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclReportAttributes.java @@ -0,0 +1,101 @@ + +import java.util.List; + +/** Zigbee Message Zcl Report Attributes. + * + * @author Ali Younis + * @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 attributes; + + /** + * Constructor + */ + public IoTZigbeeMessageZclReportAttributes(int _packetId, int _clusterId, int _profileId, List _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 + */ + public List getAttributes() { + return attributes; + } +} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclWriteAttributesResponse.java b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclWriteAttributesResponse.java new file mode 100644 index 0000000..ac045c8 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclWriteAttributesResponse.java @@ -0,0 +1,31 @@ +/** Zigbee Message Zcl Write Attributes Response. + * + * @author changwoo Lee + * @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; + } +} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclZoneStatusChangeNotification.java b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclZoneStatusChangeNotification.java new file mode 100644 index 0000000..fd633fe --- /dev/null +++ b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclZoneStatusChangeNotification.java @@ -0,0 +1,37 @@ +/** Zigbee Message Zcl Zone Status Change Notification. + * + * @author changwoo Lee + * @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; + } +} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZdoBindResponse.java b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZdoBindResponse.java new file mode 100644 index 0000000..f1d27d4 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZdoBindResponse.java @@ -0,0 +1,40 @@ + +/** Zigbee Message Zdo Bind Response. + * + * @author Ali Younis + * @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; + } +} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZdoUnBindResponse.java b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZdoUnBindResponse.java new file mode 100644 index 0000000..edb5534 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZdoUnBindResponse.java @@ -0,0 +1,40 @@ + +/** Zigbee Message Zdo UnBind Response. + * + * @author Ali Younis + * @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; + } +} diff --git a/benchmarks/other/ZigbeeTest/MoistureSensor.java b/benchmarks/other/ZigbeeTest/MoistureSensor.java new file mode 100644 index 0000000..573bd70 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/MoistureSensor.java @@ -0,0 +1,11 @@ +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); +} diff --git a/benchmarks/other/ZigbeeTest/MoistureSensorCallback.java b/benchmarks/other/ZigbeeTest/MoistureSensorCallback.java new file mode 100644 index 0000000..d45e698 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/MoistureSensorCallback.java @@ -0,0 +1,6 @@ +import java.util.List; +import java.util.ArrayList; + +public interface MoistureSensorCallback { + public void newReadingAvailable(int sensorId, float moisture, long timeStampOfLastReading); +} diff --git a/benchmarks/other/ZigbeeTest/MoistureSensorSmart.java b/benchmarks/other/ZigbeeTest/MoistureSensorSmart.java new file mode 100644 index 0000000..1496146 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/MoistureSensorSmart.java @@ -0,0 +1,12 @@ +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(); +} diff --git a/benchmarks/other/ZigbeeTest/MoistureSensorSmartCallback.java b/benchmarks/other/ZigbeeTest/MoistureSensorSmartCallback.java new file mode 100644 index 0000000..c69e9cc --- /dev/null +++ b/benchmarks/other/ZigbeeTest/MoistureSensorSmartCallback.java @@ -0,0 +1,7 @@ +import java.util.List; +import java.util.ArrayList; + +public interface MoistureSensorSmartCallback { + + public void newReadingAvailable(int sensorId, float moisture, long timeStampOfLastReading); +} diff --git a/benchmarks/other/ZigbeeTest/MotionSensor.java b/benchmarks/other/ZigbeeTest/MotionSensor.java new file mode 100644 index 0000000..2ad5490 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/MotionSensor.java @@ -0,0 +1,224 @@ +// 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 + * @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 devUdpAddress; + @config private IoTSet devZigbeeAddress; + + public MotionSensor(IoTSet dSet, IoTSet 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); + } +} diff --git a/benchmarks/other/ZigbeeTest/MultipurposeSensor.java b/benchmarks/other/ZigbeeTest/MultipurposeSensor.java new file mode 100644 index 0000000..a21155f --- /dev/null +++ b/benchmarks/other/ZigbeeTest/MultipurposeSensor.java @@ -0,0 +1,221 @@ +// 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 + * @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 devUdpAddress; + @config private IoTSet devZigbeeAddress; + + public MultipurposeSensor(IoTSet dSet, IoTSet 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); + } +} diff --git a/benchmarks/other/ZigbeeTest/SmartthingsSensor.java b/benchmarks/other/ZigbeeTest/SmartthingsSensor.java new file mode 100644 index 0000000..d739f19 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/SmartthingsSensor.java @@ -0,0 +1,71 @@ +// 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 , 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; +} + + + + + + + + + + + + + + diff --git a/benchmarks/other/ZigbeeTest/SmartthingsSensorCallback.java b/benchmarks/other/ZigbeeTest/SmartthingsSensorCallback.java new file mode 100644 index 0000000..2367da1 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/SmartthingsSensorCallback.java @@ -0,0 +1,16 @@ +// Checker annotations +//import iotchecker.qual.*; + + +/** Smartthings Sensor Callback for when a camera changes state (new frame available). + * + * @author Rahmadi Trimananda , 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); +} diff --git a/benchmarks/other/ZigbeeTest/SpruceSensor.java b/benchmarks/other/ZigbeeTest/SpruceSensor.java new file mode 100644 index 0000000..2992130 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/SpruceSensor.java @@ -0,0 +1,216 @@ +// 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 devUdpAddress; + @config private IoTSet devZigbeeAddress; + + public SpruceSensor(IoTSet _devUdpAddress, IoTSet _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 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); + } +} diff --git a/benchmarks/other/ZigbeeTest/WaterLeakSensor.java b/benchmarks/other/ZigbeeTest/WaterLeakSensor.java new file mode 100644 index 0000000..75923a4 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/WaterLeakSensor.java @@ -0,0 +1,222 @@ +// 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 + * @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 devUdpAddress; + @config private IoTSet devZigbeeAddress; + + public WaterLeakSensor(IoTSet dSet, IoTSet 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); + } +} diff --git a/benchmarks/other/ZigbeeTest/ZigbeeTest.java b/benchmarks/other/ZigbeeTest/ZigbeeTest.java new file mode 100644 index 0000000..a90b7b3 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/ZigbeeTest.java @@ -0,0 +1,79 @@ +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 zigSet = new HashSet(); + zigSet.add(zigAddrLong); + IoTSet zigIotSet = new IoTSet(zigSet); + + Set devSet = new HashSet(); + devSet.add(zigUdpAddr); + IoTSet devIotSet = new IoTSet(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) { + + } + } +} diff --git a/benchmarks/other/ZigbeeTest/ZigbeeTest_motion.java b/benchmarks/other/ZigbeeTest/ZigbeeTest_motion.java new file mode 100644 index 0000000..e62301f --- /dev/null +++ b/benchmarks/other/ZigbeeTest/ZigbeeTest_motion.java @@ -0,0 +1,61 @@ +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 zigSet = new HashSet(); + zigSet.add(zigAddrLong); + IoTSet zigIotSet = new IoTSet(zigSet); + + Set devSet = new HashSet(); + devSet.add(zigUdpAddr); + IoTSet devIotSet = new IoTSet(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) { + + } + } +} diff --git a/benchmarks/other/ZigbeeTest/ZigbeeTest_multipurpose.java b/benchmarks/other/ZigbeeTest/ZigbeeTest_multipurpose.java new file mode 100644 index 0000000..a9298cd --- /dev/null +++ b/benchmarks/other/ZigbeeTest/ZigbeeTest_multipurpose.java @@ -0,0 +1,59 @@ +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 zigSet = new HashSet(); + zigSet.add(zigAddrLong); + IoTSet zigIotSet = new IoTSet(zigSet); + + Set devSet = new HashSet(); + devSet.add(zigUdpAddr); + IoTSet devIotSet = new IoTSet(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) { + + } + } +} diff --git a/benchmarks/other/ZigbeeTest/ZigbeeTest_waterleak.java b/benchmarks/other/ZigbeeTest/ZigbeeTest_waterleak.java new file mode 100644 index 0000000..1bd5524 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/ZigbeeTest_waterleak.java @@ -0,0 +1,60 @@ +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 zigSet = new HashSet(); + zigSet.add(zigAddrLong); + IoTSet zigIotSet = new IoTSet(zigSet); + + Set devSet = new HashSet(); + devSet.add(zigUdpAddr); + IoTSet devIotSet = new IoTSet(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) { + + } + } +} diff --git a/benchmarks/other/ZigbeeTest/build.bash b/benchmarks/other/ZigbeeTest/build.bash new file mode 100755 index 0000000..b74dfc1 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/build.bash @@ -0,0 +1,3 @@ +cwd=$(pwd) +cd $cwd +javac -cp ./../iotjava:./../../../bin:.:../../packages/build *.java diff --git a/benchmarks/other/ZigbeeTest/buildall.bash b/benchmarks/other/ZigbeeTest/buildall.bash new file mode 100755 index 0000000..8dc832d --- /dev/null +++ b/benchmarks/other/ZigbeeTest/buildall.bash @@ -0,0 +1,11 @@ +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 diff --git a/benchmarks/other/ZigbeeTest/clean.bash b/benchmarks/other/ZigbeeTest/clean.bash new file mode 100755 index 0000000..73c03ab --- /dev/null +++ b/benchmarks/other/ZigbeeTest/clean.bash @@ -0,0 +1 @@ +rm -rf *.class diff --git a/benchmarks/other/ZigbeeTest/config.java b/benchmarks/other/ZigbeeTest/config.java new file mode 100644 index 0000000..9a7fde7 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/config.java @@ -0,0 +1,15 @@ +//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 + * @version 1.0 + * @since 2016-12-12 + */ +@Retention(RetentionPolicy.RUNTIME) +public @interface config { +} diff --git a/benchmarks/other/ZigbeeTest/run.bash b/benchmarks/other/ZigbeeTest/run.bash new file mode 100755 index 0000000..35f58eb --- /dev/null +++ b/benchmarks/other/ZigbeeTest/run.bash @@ -0,0 +1,2 @@ +#java -cp ./../../../bin:.:../../packages/build ZigbeeTest +java -cp ./../iotjava:./../../../bin:. ZigbeeTest diff --git a/benchmarks/other/ZigbeeTest/run_motion.bash b/benchmarks/other/ZigbeeTest/run_motion.bash new file mode 100755 index 0000000..e5baba1 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/run_motion.bash @@ -0,0 +1 @@ +java -cp ./../iotjava:./../../../bin:. ZigbeeTest_motion diff --git a/benchmarks/other/ZigbeeTest/run_multipurpose.bash b/benchmarks/other/ZigbeeTest/run_multipurpose.bash new file mode 100755 index 0000000..653b0a2 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/run_multipurpose.bash @@ -0,0 +1,2 @@ +#java -cp ./../../../bin:.:../../packages/build ZigbeeTest +java -cp ./../iotjava:./../../../bin:. ZigbeeTest_multipurpose diff --git a/benchmarks/other/ZigbeeTest/run_waterleak.bash b/benchmarks/other/ZigbeeTest/run_waterleak.bash new file mode 100755 index 0000000..76ae633 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/run_waterleak.bash @@ -0,0 +1 @@ +java -cp ./../iotjava:./../../../bin:. ZigbeeTest_waterleak diff --git a/iotjava/iotruntime/zigbee/IoTZigbee.java b/iotjava/iotruntime/zigbee/IoTZigbee.java index bc58c47..a772918 100644 --- a/iotjava/iotruntime/zigbee/IoTZigbee.java +++ b/iotjava/iotruntime/zigbee/IoTZigbee.java @@ -95,6 +95,62 @@ public class IoTZigbee { } } + //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"; diff --git a/iotjava/iotruntime/zigbee/IoTZigbeeMessageZclWriteAttributesResponse.java b/iotjava/iotruntime/zigbee/IoTZigbeeMessageZclWriteAttributesResponse.java new file mode 100644 index 0000000..b19a6ae --- /dev/null +++ b/iotjava/iotruntime/zigbee/IoTZigbeeMessageZclWriteAttributesResponse.java @@ -0,0 +1,33 @@ +package iotruntime.zigbee; + +/** Zigbee Message Zcl Write Attributes Response. + * + * @author changwoo Lee + * @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; + } +} diff --git a/iotjava/iotruntime/zigbee/IoTZigbeeMessageZclZoneStatusChangeNotification.java b/iotjava/iotruntime/zigbee/IoTZigbeeMessageZclZoneStatusChangeNotification.java new file mode 100644 index 0000000..3b9eb0b --- /dev/null +++ b/iotjava/iotruntime/zigbee/IoTZigbeeMessageZclZoneStatusChangeNotification.java @@ -0,0 +1,39 @@ +package iotruntime.zigbee; + +/** Zigbee Message Zcl Zone Status Change Notification. + * + * @author changwoo Lee + * @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; + } +} -- 2.34.1