From: rtrimana Date: Wed, 21 Jun 2017 16:49:55 +0000 (-0700) Subject: Completing ZigbeeTest with doorlock test X-Git-Url: http://plrg.eecs.uci.edu/git/?p=iot2.git;a=commitdiff_plain;h=29139245e9e467770431976dae4bab726f08ccd1;hp=903f2886824222a912502db3fdf432e4351141e6 Completing ZigbeeTest with doorlock test --- diff --git a/benchmarks/other/DoorlockAndOutlet/DoorlockSensor.java b/benchmarks/other/DoorlockAndOutlet/DoorlockSensor.java index a1d6d95..c069949 100644 --- a/benchmarks/other/DoorlockAndOutlet/DoorlockSensor.java +++ b/benchmarks/other/DoorlockAndOutlet/DoorlockSensor.java @@ -26,18 +26,16 @@ public class DoorlockSensor implements IoTZigbeeCallback, SmartthingsSensor { private final int TIMEOUT_FOR_RESEND_MSEC = 900; private IoTZigbee zigConnection = null; - - private int status = 0; private boolean didClose; // make sure that the clean up was done correctly - //private boolean detectStatus = false; + private boolean detectStatus = false; - //private int detectedValue = 0; + 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); + private AtomicBoolean didMatchDscr = new AtomicBoolean(false); private AtomicBoolean didBind = new AtomicBoolean(false); private AtomicBoolean didDoorLockConfigureReporting = new AtomicBoolean(false); //made by Jiawei static Semaphore gettingLatestDataMutex = new Semaphore(1); @@ -156,12 +154,13 @@ public class DoorlockSensor implements IoTZigbeeCallback, SmartthingsSensor { } // made by Jiawei - public int getStatus() { + //public int getStatus() { + public int getValue() { int tmp = 0; try { gettingLatestDataMutex.acquire(); - tmp = status; + tmp = detectedValue; } catch (Exception e) { e.printStackTrace(); @@ -171,6 +170,16 @@ public class DoorlockSensor implements IoTZigbeeCallback, SmartthingsSensor { return tmp; } + public boolean isActiveValue() { + + int tmp = getValue(); + if (tmp == 1) + detectStatus = true; // Door is locked + else + detectStatus = false; // Door is not locked/not fully locked + return detectStatus; + } + public void close() { if (didAlreadyClose.compareAndSet(false, true) == false) { @@ -248,7 +257,7 @@ public class DoorlockSensor implements IoTZigbeeCallback, SmartthingsSensor { try { gettingLatestDataMutex.acquire(); - status = value; + detectedValue = value; timestampOfLastDetecting = new Date(); } catch (Exception e) { e.printStackTrace(); @@ -257,7 +266,7 @@ public class DoorlockSensor implements IoTZigbeeCallback, SmartthingsSensor { try { for (SmartthingsSensorCallback cb : callbackList) { - cb.newReadingAvailable(this); + cb.newReadingAvailable(this.getValue(), this.isActiveValue()); } } catch (Exception e) { e.printStackTrace(); diff --git a/benchmarks/other/DoorlockAndOutlet/ZigbeeTest_doorlock.java b/benchmarks/other/DoorlockAndOutlet/ZigbeeTest_doorlock.java index 20ff4f2..a27b954 100644 --- a/benchmarks/other/DoorlockAndOutlet/ZigbeeTest_doorlock.java +++ b/benchmarks/other/DoorlockAndOutlet/ZigbeeTest_doorlock.java @@ -13,28 +13,30 @@ import java.rmi.RemoteException; public class ZigbeeTest_doorlock 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 = "127.0.0.1"; + private static final String MY_IP_ADDRESS = "192.168.1.198"; public static final String DEVIDE_MAC_ADDRESS = "002446fffd00b0ba"; //doorlock sensor - public void newReadingAvailable(SmartthingsSensor _sensor) { - //public void newReadingAvailable(SmartthingsSensor _sensor) throws RemoteException { - System.out.println("New Message!!!!"); - int status = ((DoorlockSensor)_sensor).getStatus(); - switch (status) { - case 0: - System.out.println("Not fully locked"); - break; - case 1: - System.out.println("Locked"); - break; - case 2: - System.out.println("Unlocked"); - break; - default: - System.out.println("Unknown value: " + status); - break; - } - } + //public void newReadingAvailable(SmartthingsSensor _sensor) { + public void newReadingAvailable(int _value, boolean _activeValue) { + + System.out.println("New Message!!!!"); + //int status = ((DoorlockSensor)_sensor).getStatus(); + int status = _value; + switch (status) { + case 0: + System.out.println("Not fully locked"); + break; + case 1: + System.out.println("Locked"); + break; + case 2: + System.out.println("Unlocked"); + break; + default: + System.out.println("Unknown value: " + status); + break; + } + } public static void main(String[] args) throws UnknownHostException, SocketException, InterruptedException, IOException, IOException, RemoteException{ @@ -50,7 +52,7 @@ public class ZigbeeTest_doorlock implements SmartthingsSensorCallback { socket.setReuseAddress(true); socket.close(); - IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("127.0.0.1", 5959, 5005,false,false); + IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.1.192", 5959, 5005,false,false); IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVIDE_MAC_ADDRESS); Set zigSet = new HashSet(); diff --git a/benchmarks/other/ZigbeeTest/DoorlockSensor.java b/benchmarks/other/ZigbeeTest/DoorlockSensor.java new file mode 100644 index 0000000..c069949 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/DoorlockSensor.java @@ -0,0 +1,283 @@ +//package iotcode.DoorlockSensor; + +// 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 DoorlockSensor 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); + private AtomicBoolean didBind = new AtomicBoolean(false); + private AtomicBoolean didDoorLockConfigureReporting = new AtomicBoolean(false); //made by Jiawei + static Semaphore gettingLatestDataMutex = new Semaphore(1); + + private List < SmartthingsSensorCallback > callbackList = new CopyOnWriteArrayList < SmartthingsSensorCallback > (); + + private int sensorId = 0; + + @config private IoTSet DoorlockSensorUdpAddress; // + @config private IoTSet DoorlockSensorZigbeeAddress;// + + public DoorlockSensor(IoTSet dSet, IoTSet zigSet) { + DoorlockSensorUdpAddress = dSet; + DoorlockSensorZigbeeAddress = zigSet; + } + + public DoorlockSensor() { + } + + public void init() { + + if (didAlreadyInit.compareAndSet(false, true) == false) { + return; // already init + } + + didAlreadyClose.set(false); + + try { + Iterator itrUdp = DoorlockSensorUdpAddress.iterator(); + Iterator itrZig = DoorlockSensorZigbeeAddress.iterator(); + + zigConnection = new IoTZigbee((IoTDeviceAddress)itrUdp.next(), (IoTZigbeeAddress)itrZig.next()); + + // DEBUG + System.out.println("DEBUG: Allocate iterators to print out addresses!"); + Iterator itrDebugUdp = DoorlockSensorUdpAddress.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 = DoorlockSensorZigbeeAddress.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("BroadcastingRouteRecordRequest "); + // zigConnection.sendBroadcastingRouteRecordRequest(0x0001); + // sleep(6); + + System.out.println("Sending Management Permit Joining Request"); + // for(int z=0; z<3; z++){ + zigConnection.sendManagementPermitJoiningRequest(0x0002, 0x0036, 0x00); + sleep(0); + // } + + + while(!didBind.get()){ + System.out.println("Sending Bind Request"); + zigConnection.sendBindRequest(0x0003, 0x0101, 0x02); + sleep(0); + } + + while(!didDoorLockConfigureReporting.get()){ + System.out.println("Sending Door Lock: Configure Reporting"); + zigConnection.sendConfigureReportingCommand(0x0004, 0x0101, 0x0104, 0x01, 0x02, 0x0000, 0x30, 0x0000, 0x100E, null); + sleep(0); + } + + while(true){ + Scanner in = new Scanner(System.in); + System.out.println("\nUnlock door: 0"); + System.out.println("Lock door: 1"); + System.out.println("Read status: 2 (or anything else)"); + String str = in.next(); + if(str.equals("1")) { + System.out.println("the doorlock sensor is locking"); + zigConnection.sendLockOrUnlockDoorRequest(0x0005, 0x0101, 0x0104, 0x02, 0); + sleep(0); + }else if(str.equals("0")){ + System.out.println("the doorlock sensor is unlocking"); + zigConnection.sendLockOrUnlockDoorRequest(0x0005, 0x0101, 0x0104, 0x02, 1); + sleep(0); + }else{ + System.out.println("Let's see the doorlock sensor's status currently"); + zigConnection.sendReadDoorStatusRequest(0x0005, 0x0101, 0x0104, 0x02, 0x10, 0x00, 0x0000); + 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(); + } + } + + // made by Jiawei + //public int getStatus() { + public int getValue() { + int tmp = 0; + + try { + gettingLatestDataMutex.acquire(); + tmp = detectedValue; + + } catch (Exception e) { + e.printStackTrace(); + } + gettingLatestDataMutex.release(); + + return tmp; + } + + public boolean isActiveValue() { + + int tmp = getValue(); + if (tmp == 1) + detectStatus = true; // Door is locked + else + detectStatus = false; // Door is not locked/not fully locked + return detectStatus; + } + + 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 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 yuting + 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()) { + didDoorLockConfigureReporting.set(true); + } + } + else if (_zm instanceof IoTZigbeeMessageZclReadAttributesResponse) { + IoTZigbeeMessageZclReadAttributesResponse message = (IoTZigbeeMessageZclReadAttributesResponse)_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]; + + try { + gettingLatestDataMutex.acquire(); + detectedValue = value; + 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(); + } + } + } + } + } + + //public void registerCallback(SmartthingsSensorSmartCallback _callbackTo) { + public void registerCallback(SmartthingsSensorCallback _callbackTo) { + callbackList.add(_callbackTo); + } +} diff --git a/benchmarks/other/ZigbeeTest/IoTZigbee.java b/benchmarks/other/ZigbeeTest/IoTZigbee.java index 4a931d0..6f0ad69 100644 --- a/benchmarks/other/ZigbeeTest/IoTZigbee.java +++ b/benchmarks/other/ZigbeeTest/IoTZigbee.java @@ -104,6 +104,34 @@ public class IoTZigbee { socket.send(sendPacket); } + //made by Jiawei + public void sendLockOrUnlockDoorRequest(int packetId, int clusterId, int profileId, int deviceEndpoint, int value) throws IOException { + String message = "type: zcl_lock_or_unlock_door_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 Jiawei + public void sendReadDoorStatusRequest(int packetId, int clusterId, int profileId, int deviceEndpoint, int framecontrol, int commandframe, int attribute_id) throws IOException { + String message = "type: zcl_read_door_status_request\n"; + message += "packet_id: " + String.format("%04x", packetId) + "\n"; + message += "framecontrol: " + String.format("%02x", framecontrol) + "\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"; + message += "commandframe: " + String.format("%02x", commandframe) + "\n"; + message += "attribute_id: " + String.format("%04x", attribute_id) + "\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"; @@ -189,13 +217,14 @@ public class IoTZigbee { 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 { + public void sendConfigureReportingCommand(int packetId, int clusterId, int profileId, int src_endpoint, int dest_endpoint, 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 += "src_endpoint: " + String.format("%02x", src_endpoint) + "\n"; + message += "device_endpoint: " + String.format("%02x", dest_endpoint) + "\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"; @@ -213,6 +242,10 @@ public class IoTZigbee { socket.send(sendPacket); } + public void sendConfigureReportingCommand(int packetId, int clusterId, int profileId, int dest_endpoint, int attributeId, int dataType, int minReportingInterval, int maxReportingInterval, byte[] reportableChange) throws IOException { + sendConfigureReportingCommand(packetId, clusterId, profileId, 0x00, dest_endpoint, attributeId, dataType, minReportingInterval, maxReportingInterval, reportableChange); + } + public void registerCallback(IoTZigbeeCallback callbackTo) { callbackList.add(callbackTo); @@ -244,6 +277,7 @@ public class IoTZigbee { String message = "type: send_address\n"; message += "packet_id: 00\n"; message += "device_address_long: " + zigbeeAddress.getAddress() + "\n"; + System.out.println(message); DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName(strHostAddress), iDstPort); socket.send(sendPacket); } @@ -311,6 +345,16 @@ public class IoTZigbee { if(packetData.get("attributes").equals("success")) successOrFail=true; callbackMessage = new IoTZigbeeMessageZclZoneStatusChangeNotification(packetId, clusterId, profileId, status, successOrFail); + // made by yuting + }else if (packetData.get("type").equals("zcl_change_switch_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); + int status = Integer.parseInt(packetData.get("status"), 10); + boolean successOrFail = false; + if(packetData.get("attributes").equals("success")) successOrFail=true; + callbackMessage = new IoTZigbeeMessageZclChangeSwitchResponse(packetId, clusterId, profileId, status, successOrFail); + //made by changwoo } else if (packetData.get("type").equals("zcl_write_attributes_response")) { diff --git a/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclChangeSwitchResponse.java b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclChangeSwitchResponse.java new file mode 100644 index 0000000..0071d22 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/IoTZigbeeMessageZclChangeSwitchResponse.java @@ -0,0 +1,37 @@ +/** Zigbee Message Zcl Change Switch Response + * + * @author Yuting Tan + * @version 1.0 + * @since 2017-2-28 + */ +public class IoTZigbeeMessageZclChangeSwitchResponse extends IoTZigbeeMessage { + + private boolean SuccessOrFail=false; + private int clusterId; + private int profileId; + private int status; + + public IoTZigbeeMessageZclChangeSwitchResponse(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/MotionSensor.java b/benchmarks/other/ZigbeeTest/MotionSensor.java index 68dfe29..5fe888a 100644 --- a/benchmarks/other/ZigbeeTest/MotionSensor.java +++ b/benchmarks/other/ZigbeeTest/MotionSensor.java @@ -38,8 +38,6 @@ public class MotionSensor implements IoTZigbeeCallback, SmartthingsSensor { private List < SmartthingsSensorCallback > callbackList = new CopyOnWriteArrayList < SmartthingsSensorCallback > (); - private int sensorId = 0; - @config private IoTSet devUdpAddress; @config private IoTSet devZigbeeAddress; @@ -82,9 +80,10 @@ public class MotionSensor implements IoTZigbeeCallback, SmartthingsSensor { //made by changwoo sleep(10); - System.out.println("Sending Management Permit Joining Request"); + //System.out.println("Sending Management Permit Joining Request"); for(int z=0; z<3; z++){ zigConnection.sendManagementPermitJoiningRequest(0x0001, 0x0036, 0x00); + System.out.println("Sending Management Permit Joining Request"); sleep(0); } @@ -140,18 +139,6 @@ public class MotionSensor implements IoTZigbeeCallback, SmartthingsSensor { } } - public void setId(int id) { - - sensorId = id; - - } - - public int getId() { - - return sensorId; - - } - public int getValue() { int tmp = 0; @@ -216,7 +203,7 @@ public class MotionSensor implements IoTZigbeeCallback, SmartthingsSensor { gettingLatestDataMutex.release(); try { for (SmartthingsSensorCallback cb : callbackList) { - cb.newReadingAvailable(this.getId(), this.getValue(), this.isActiveValue()); + cb.newReadingAvailable(this.getValue(), this.isActiveValue()); } } catch (Exception e) { e.printStackTrace(); diff --git a/benchmarks/other/ZigbeeTest/MultipurposeSensor.java b/benchmarks/other/ZigbeeTest/MultipurposeSensor.java index 0243091..a21155f 100644 --- a/benchmarks/other/ZigbeeTest/MultipurposeSensor.java +++ b/benchmarks/other/ZigbeeTest/MultipurposeSensor.java @@ -38,8 +38,6 @@ public class MultipurposeSensor implements IoTZigbeeCallback, SmartthingsSensor private List < SmartthingsSensorCallback > callbackList = new CopyOnWriteArrayList < SmartthingsSensorCallback > (); - private int sensorId = 0; - @config private IoTSet devUdpAddress; @config private IoTSet devZigbeeAddress; @@ -138,18 +136,6 @@ public class MultipurposeSensor implements IoTZigbeeCallback, SmartthingsSensor } } - public void setId(int id) { - - sensorId = id; - - } - - public int getId() { - - return sensorId; - - } - public int getValue() { int tmp = 0; @@ -212,7 +198,7 @@ public class MultipurposeSensor implements IoTZigbeeCallback, SmartthingsSensor gettingLatestDataMutex.release(); try { for (SmartthingsSensorCallback cb : callbackList) { - cb.newReadingAvailable(this.getId(), this.getValue(), this.isActiveValue()); + cb.newReadingAvailable(this.getValue(), this.isActiveValue()); } } catch (Exception e) { e.printStackTrace(); diff --git a/benchmarks/other/ZigbeeTest/SmartthingsSensor.java b/benchmarks/other/ZigbeeTest/SmartthingsSensor.java index aba8819..d739f19 100644 --- a/benchmarks/other/ZigbeeTest/SmartthingsSensor.java +++ b/benchmarks/other/ZigbeeTest/SmartthingsSensor.java @@ -46,9 +46,6 @@ public interface SmartthingsSensor extends Remote { */ public void init() throws RemoteException; - public void setId(int id); - - public int getId(); /** Register an object to retrieve callbacks when new sensor reading is available * diff --git a/benchmarks/other/ZigbeeTest/SmartthingsSensorCallback.java b/benchmarks/other/ZigbeeTest/SmartthingsSensorCallback.java index 5342538..2367da1 100644 --- a/benchmarks/other/ZigbeeTest/SmartthingsSensorCallback.java +++ b/benchmarks/other/ZigbeeTest/SmartthingsSensorCallback.java @@ -11,5 +11,6 @@ public interface SmartthingsSensorCallback { - public void newReadingAvailable(int _sensorId, int _value, boolean _activeValue); + //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 index 2992130..7dccc1f 100644 --- a/benchmarks/other/ZigbeeTest/SpruceSensor.java +++ b/benchmarks/other/ZigbeeTest/SpruceSensor.java @@ -79,6 +79,7 @@ public class SpruceSensor implements IoTZigbeeCallback, MoistureSensor { while (!didBind.get()) { zigConnection.sendBindRequest(0x0001, 0x0405, 0x01); + System.out.println("Sending bind request!"); try { Thread.sleep(TIMEOUT_FOR_RESEND_MSEC); } catch (Exception e) { diff --git a/benchmarks/other/ZigbeeTest/WaterLeakSensor.java b/benchmarks/other/ZigbeeTest/WaterLeakSensor.java index 8a56aab..75923a4 100644 --- a/benchmarks/other/ZigbeeTest/WaterLeakSensor.java +++ b/benchmarks/other/ZigbeeTest/WaterLeakSensor.java @@ -41,8 +41,6 @@ public class WaterLeakSensor implements IoTZigbeeCallback, SmartthingsSensor { @config private IoTSet devUdpAddress; @config private IoTSet devZigbeeAddress; - private int sensorId = 0; - public WaterLeakSensor(IoTSet dSet, IoTSet zigSet) { devUdpAddress = dSet; devZigbeeAddress = zigSet; @@ -138,18 +136,6 @@ public class WaterLeakSensor implements IoTZigbeeCallback, SmartthingsSensor { } } - public void setId(int id) { - - sensorId = id; - - } - - public int getId() { - - return sensorId; - - } - public int getValue() { int tmp = 0; @@ -213,7 +199,7 @@ public class WaterLeakSensor implements IoTZigbeeCallback, SmartthingsSensor { gettingLatestDataMutex.release(); try { for (SmartthingsSensorCallback cb : callbackList) { - cb.newReadingAvailable(this.getId(), this.getValue(), this.isActiveValue()); + cb.newReadingAvailable(this.getValue(), this.isActiveValue()); } } catch (Exception e) { e.printStackTrace(); diff --git a/benchmarks/other/ZigbeeTest/ZigbeeTest.java b/benchmarks/other/ZigbeeTest/ZigbeeTest.java index a90b7b3..9fe8cbe 100644 --- a/benchmarks/other/ZigbeeTest/ZigbeeTest.java +++ b/benchmarks/other/ZigbeeTest/ZigbeeTest.java @@ -33,13 +33,12 @@ public class ZigbeeTest implements MoistureSensorSmartCallback { 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 += "ip_address: " + "192.168.2.108\n"; // local ip address //message += "port: " + "5959\n"; // port number - message += "port: " + "5557\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 + DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("192.168.2.192"), 5005); // address and port of the gateway DatagramSocket socket = new DatagramSocket(); socket.setSendBufferSize(4096); @@ -51,7 +50,7 @@ public class ZigbeeTest implements MoistureSensorSmartCallback { //IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("128.195.204.110", 5557, 5005,false,false); - IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.227", 5557, 5005,false,false); + IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.192", 5557, 5005,false,false); IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress("000d6f0003ebf2ee"); Set zigSet = new HashSet(); @@ -65,9 +64,9 @@ public class ZigbeeTest implements MoistureSensorSmartCallback { System.out.println("About to init"); sen.init(); - + System.out.println("Passed init!"); ZigbeeTest zTest = new ZigbeeTest(); - + System.out.println("ZigbeeTest created!"); sen.registerCallback(zTest); diff --git a/benchmarks/other/ZigbeeTest/ZigbeeTest_doorlock.java b/benchmarks/other/ZigbeeTest/ZigbeeTest_doorlock.java new file mode 100644 index 0000000..5582191 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/ZigbeeTest_doorlock.java @@ -0,0 +1,83 @@ +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_doorlock implements IoTZigbeeCallback { +public class ZigbeeTest_doorlock 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.1.198"; + public static final String DEVIDE_MAC_ADDRESS = "002446fffd00b0ba"; //doorlock sensor + + //public void newReadingAvailable(SmartthingsSensor _sensor) { + public void newReadingAvailable(int _value, boolean _activeValue) { + + System.out.println("New Message!!!!"); + //int status = ((DoorlockSensor)_sensor).getStatus(); + int status = _value; + switch (status) { + case 0: + System.out.println("Not fully locked"); + break; + case 1: + System.out.println("Locked"); + break; + case 2: + System.out.println("Unlocked"); + break; + default: + System.out.println("Unknown value: " + status); + break; + } + } + + 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: " + "5959\n"; // port number + message += "device_address_long: " + DEVIDE_MAC_ADDRESS + "\n"; + DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("192.168.1.192"), 5005); // address and port of the gateway which means Raspberry PI's IP address + DatagramSocket socket = new DatagramSocket(12345/*test number*/); + socket.setSendBufferSize(4096); + socket.setReceiveBufferSize(4096); + socket.send(sendPacket); + socket.setReuseAddress(true); + socket.close(); + + IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.1.192", 5959, 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); + DoorlockSensor sen = new DoorlockSensor(devIotSet, zigIotSet); + + ZigbeeTest_doorlock zTest = new ZigbeeTest_doorlock(); + sen.registerCallback(zTest); + + System.out.println("About to init"); + sen.init(); + + // ZigbeeTest_doorlock zTest = new ZigbeeTest_doorlock(); + // 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 index 7dde4b1..b19eca9 100644 --- a/benchmarks/other/ZigbeeTest/ZigbeeTest_motion.java +++ b/benchmarks/other/ZigbeeTest/ZigbeeTest_motion.java @@ -12,12 +12,12 @@ 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 + private static final String MY_IP_ADDRESS = "192.168.1.198"; + public static final String DEVIDE_MAC_ADDRESS = "000d6f000bbd5398"; //motion //000d6f000bbd5398 //000d6f00057c92a7 - public void newReadingAvailable(int _sensorId, int _value, boolean _activeValue) { + public void newReadingAvailable(int _value, boolean _activeValue) { System.out.println("New Message!!!!"); System.out.println("motion : "+ _value); System.out.println("active? : "+ _activeValue); @@ -29,16 +29,17 @@ public class ZigbeeTest_motion implements SmartthingsSensorCallback { 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 + DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("192.168.1.192"), 5005); // address and port of the gateway which means Raspberry PI's IP address //DatagramSocket socket = new DatagramSocket(11222); - DatagramSocket socket = new DatagramSocket(12345); + DatagramSocket socket = new DatagramSocket(12345); socket.setSendBufferSize(4096); socket.setReceiveBufferSize(4096); socket.send(sendPacket); - socket.setReuseAddress(true); - socket.close(); + socket.setReuseAddress(true); + socket.close(); - IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.227", 5956, 5005,false,false); + //IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.227", 5956, 5005,false,false); + IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.1.192", 5956, 5005,false,false); IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVIDE_MAC_ADDRESS); Set zigSet = new HashSet(); diff --git a/benchmarks/other/ZigbeeTest/ZigbeeTest_multipurpose.java b/benchmarks/other/ZigbeeTest/ZigbeeTest_multipurpose.java index bec2d37..bb5c836 100644 --- a/benchmarks/other/ZigbeeTest/ZigbeeTest_multipurpose.java +++ b/benchmarks/other/ZigbeeTest/ZigbeeTest_multipurpose.java @@ -12,10 +12,10 @@ 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"; + private static final String MY_IP_ADDRESS = "192.168.1.198"; public static final String DEVIDE_MAC_ADDRESS = "000d6f000bbd3413"; //Multipurpose sensor - public void newReadingAvailable(int _sensorId, int _value, boolean _activeValue) { + public void newReadingAvailable(int _value, boolean _activeValue) { System.out.println("New Message!!!!"); System.out.println("multipurpose : "+ _value); System.out.println("active? : "+ _activeValue); @@ -26,17 +26,19 @@ public class ZigbeeTest_multipurpose implements SmartthingsSensorCallback { String message = "type: policy_set\n"; message += "ip_address: " + MY_IP_ADDRESS + "\n"; // local ip address message += "port: " + "5957\n"; // port number + //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); + DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("192.168.1.192"), 5005); //DatagramSocket socket = new DatagramSocket(11111); - DatagramSocket socket = new DatagramSocket(12345); + DatagramSocket socket = new DatagramSocket(12345); socket.setSendBufferSize(4096); socket.setReceiveBufferSize(4096); socket.send(sendPacket); - socket.setReuseAddress(true); - socket.close(); + socket.setReuseAddress(true); + socket.close(); - IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.227", 5957, 5005,false,false); + IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.1.192", 5957, 5005,false,false); + //IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.227", 5956, 5005,false,false); IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVIDE_MAC_ADDRESS); Set zigSet = new HashSet(); diff --git a/benchmarks/other/ZigbeeTest/ZigbeeTest_waterleak.java b/benchmarks/other/ZigbeeTest/ZigbeeTest_waterleak.java index 5064290..11dbb30 100644 --- a/benchmarks/other/ZigbeeTest/ZigbeeTest_waterleak.java +++ b/benchmarks/other/ZigbeeTest/ZigbeeTest_waterleak.java @@ -12,11 +12,11 @@ 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 String MY_IP_ADDRESS = "192.168.1.198"; private static final int PORT_NUMBER = 5959; public static final String DEVIDE_MAC_ADDRESS = "000d6f000ada75e3"; //water leak - public void newReadingAvailable(int _sensorId, int _value, boolean _activeValue) { + public void newReadingAvailable(int _value, boolean _activeValue) { System.out.println("New Message!!!!"); System.out.println("water leak : "+ _value); System.out.println("active? : "+ _activeValue); @@ -28,16 +28,17 @@ public class ZigbeeTest_waterleak implements SmartthingsSensorCallback { 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 + DatagramPacket sendPacket = new DatagramPacket(message.getBytes(), message.getBytes().length, InetAddress.getByName("192.168.1.192"), 5005); // address and port of the gateway which means Raspberry PI's IP address //DatagramSocket socket = new DatagramSocket(22222); - DatagramSocket socket = new DatagramSocket(12345); + DatagramSocket socket = new DatagramSocket(12345); socket.setSendBufferSize(4096); socket.setReceiveBufferSize(4096); socket.send(sendPacket); - socket.setReuseAddress(true); - socket.close(); + socket.setReuseAddress(true); + socket.close(); - IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.227", PORT_NUMBER, 5005,false,false); + //IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.2.227", PORT_NUMBER, 5005,false,false); + IoTDeviceAddress zigUdpAddr = new IoTDeviceAddress("192.168.1.192", PORT_NUMBER, 5005,false,false); IoTZigbeeAddress zigAddrLong = new IoTZigbeeAddress(DEVIDE_MAC_ADDRESS); Set zigSet = new HashSet(); diff --git a/benchmarks/other/ZigbeeTest/run_doorlock.bash b/benchmarks/other/ZigbeeTest/run_doorlock.bash new file mode 100755 index 0000000..688e338 --- /dev/null +++ b/benchmarks/other/ZigbeeTest/run_doorlock.bash @@ -0,0 +1 @@ +java -cp ./../iotjava:./../../../bin:. ZigbeeTest_doorlock