From: rtrimana Date: Wed, 27 Sep 2017 22:08:21 +0000 (-0700) Subject: Adding doorlock to the fourth benchmark X-Git-Url: http://plrg.eecs.uci.edu/git/?p=iot2.git;a=commitdiff_plain;h=1bac443ac1ed2689852ef846c6332865374e2b36;hp=00922a5779ecade450c3cabc756f850dbe528095 Adding doorlock to the fourth benchmark --- diff --git a/benchmarks/Java/HomeSecurityController/HomeSecurityController.java b/benchmarks/Java/HomeSecurityController/HomeSecurityController.java index 68cf0fb..c87eece 100644 --- a/benchmarks/Java/HomeSecurityController/HomeSecurityController.java +++ b/benchmarks/Java/HomeSecurityController/HomeSecurityController.java @@ -8,6 +8,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.HashSet; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.ConcurrentHashMap; @@ -33,7 +34,7 @@ import iotcode.interfaces.*; * @version 1.0 * @since 2016-12-14 */ -public class HomeSecurityController implements SmartthingsSensorCallback { +public class HomeSecurityController implements SmartthingsSensorCallback, SmartthingsActuatorCallback { /* * Constants @@ -43,6 +44,8 @@ public class HomeSecurityController implements SmartthingsSensorCallback { private static final int CHECK_TIME_WAIT = 1; // in seconds private static final int SECOND_TO_TURN_ON = 60; // in seconds private static final int SECOND_TO_TURN_OFF = 1; // in seconds + private static final int LOCK_DOOR = 0; + private static final int UNLOCK_DOOR = 1; /** * IoT Sets and Relations @@ -54,24 +57,17 @@ public class HomeSecurityController implements SmartthingsSensorCallback { * 4) Camera (detect motion) * 5) Alarm (using ESP board) - assuming 1 house alarm * 6) Room (object as place of device) - * - * Additionals (for more extensive home management) * 7) Doorlock (detect open/locked) - * 8) Power outlet (detect on/off, monitor watt) */ - // This comprises multipurpose, motion, and water leak sensors - // TODO: Per 01/2017, doorlock and outlet are not ready, ESP board will be used for alarm @config private IoTSet smartSensorsSet; @config private IoTSet camSet; @config private IoTSet alarmSet; @config private IoTSet roomSet; - //@config private IoTSet doorlockSet; - //@config private IoTSet outletSet; + @config private IoTSet doorlockSet; @config private IoTRelation roomSensorRelation; @config private IoTRelation roomCameraRelation; //@config private IoTRelation roomDoorLockRelation; - //@config private IoTRelation roomOutletRelation; /******************************************************************************************************************************************* ** @@ -81,6 +77,7 @@ public class HomeSecurityController implements SmartthingsSensorCallback { long lastTimeChecked = 0; private static int sensorId = 0; + private static int doorlockId = 0; /******************************************************************************************************************************************* ** @@ -96,12 +93,9 @@ public class HomeSecurityController implements SmartthingsSensorCallback { // Camera (true = motion) private Map camDetectStatus = new HashMap(); - // Doorlock (true = open - not locked) - //private Map doorlockStatus = - // new HashMap(); - // Outlet (true = on - outlet is used) - //private Map outletStatus = - // new HashMap(); + // Doorlock (true = locked) + private Map doorlockStatus = + new HashMap(); // Alarm status private Map alarmStatus = @@ -211,41 +205,25 @@ public class HomeSecurityController implements SmartthingsSensorCallback { * * @return [void] None. */ - private void initDoorLocks(RoomSmart rm) { + private void initDoorLocks() { - // Get and init the doorlocks for this specific room - /*HashSet doorlocks = roomDoorLockRelation.get(rm); - for (DoorLock doorlock : doorlocks) { + // Get and init the doorlocks (we only assume 1 main doorlock) + Set doorlocks = doorlockSet.values(); + for (SmartthingsActuatorSmart doorlock : doorlocks) { try { // Initialize doorlocks doorlock.init(); - System.out.println("DEBUG: Initialized doorlock!"); + System.out.println("DEBUG: Initialized doorlock! ID: " + doorlockId); + doorlockStatus.put(doorlockId, false); + System.out.println("DEBUG: Initialized doorlock status to false!"); + doorlock.setId(doorlockId++); + doorlock.registerCallback(this); + System.out.println("DEBUG: Registered doorlock callback!"); } catch (Exception e) { e.printStackTrace(); } - }*/ - } - - - /** Method to initialize power outlets - * - * @return [void] None. - */ - private void initOutlets(RoomSmart rm) { - - // Get and init the outlets for this specific room - /*HashSet outlets = roomOutletRelation.get(rm); - for (Outlet outlet : outlets) { - - try { - // Initialize outlets - outlet.init(); - System.out.println("DEBUG: Initialized outlet!"); - } catch (Exception e) { - e.printStackTrace(); - } - }*/ + } } @@ -303,48 +281,21 @@ public class HomeSecurityController implements SmartthingsSensorCallback { } } - - /** Method to update state data structures for doorlocks - * - * @return [void] None. - */ - private void updateDoorLockStatus(RoomSmart rm) { - - // Get and init the outlets for this specific room - /*HashSet doorlocks = roomDoorLockRelation.get(rm); - for (DoorLock doorlock : doorlocks) { - - // Change is detected! Set to true for report... - if(isChangeDetected()) { - - doorlockStatus.put(doorlock, true); - } else { - - doorlockStatus.put(doorlock, false); - } - }*/ - } - - - /** Method to update state data structures for outlets + /** Method to update state data structures for Smartthings actuators * * @return [void] None. */ - private void updateOutletStatus(RoomSmart rm) { - - // Get and init the outlets for this specific room - /*HashSet outlets = roomOutletRelation.get(rm); - for (Outlet outlet : outlets) { - - // Change is detected! Set to true for report... - if(isChangeDetected()) { + public void newActuatorReadingAvailable(int _sensorId, int _value, boolean _activeValue) { - outletStatus.put(outlet, true); - } else { + System.out.println("DEBUG: Actuator reading value: " + _value); + if(_activeValue) { + System.out.println("DEBUG: Actuator is detecting something: " + _activeValue); + doorlockStatus.put(_sensorId, true); - outletStatus.put(outlet, false); - } - }*/ + } else { + //System.out.println("DEBUG: Sensor is not detecting something: " + _activeValue); + doorlockStatus.put(_sensorId, false); + } } @@ -360,11 +311,8 @@ public class HomeSecurityController implements SmartthingsSensorCallback { // Update status of camera updateCameraStatus(room); - // Update status of doorlocks - //updateDoorLockStatus(room); - - // Update status of outlets - //updateOutletStatus(room); + // Update status of other devices if any + // ... } } @@ -418,6 +366,22 @@ public class HomeSecurityController implements SmartthingsSensorCallback { } + /** Method to lock doors + * + * @return [void] None. + */ + private void lockDoors() { + + // Get and lock the doorlocks (we only assume 1 main doorlock) + Set doorlocks = doorlockSet.values(); + for (SmartthingsActuatorSmart doorlock : doorlocks) { + + doorlock.actuate(LOCK_DOOR); + System.out.println("DEBUG: Lock doorlock! ID: " + doorlock.getId()); + } + } + + /** Check status of devices and turn on alarm accordingly *

* Simple rule is whenever any sensor or camera detect something unusual @@ -441,6 +405,7 @@ public class HomeSecurityController implements SmartthingsSensorCallback { zoneId = room.getRoomID(); turnOnAlarms(zoneId); System.out.println("DETECTION: Camera active in room: " + zoneId); + lockDoors(); } } @@ -454,6 +419,7 @@ public class HomeSecurityController implements SmartthingsSensorCallback { turnOnAlarms(zoneId); System.out.println("DETECTION: Sensor active in room: " + zoneId); System.out.println("DETECTION: Detection by sensor: " + sensor.getId()); + lockDoors(); } } } @@ -534,10 +500,8 @@ public class HomeSecurityController implements SmartthingsSensorCallback { initCameras(rm); // Init all doorlocks - //initDoorLocks(); + initDoorLocks(); - // Init all outlets - //initOutlets(); } // Init all alarms diff --git a/benchmarks/Java/HomeSecurityController/Makefile b/benchmarks/Java/HomeSecurityController/Makefile index 460b10a..7e9a569 100644 --- a/benchmarks/Java/HomeSecurityController/Makefile +++ b/benchmarks/Java/HomeSecurityController/Makefile @@ -22,12 +22,12 @@ PHONY += homesecurity homesecurity: $(JAVAC) $(JFLAGS) *.java cp HomeSecurityController.config $(BIN_DIR)/HomeSecurityController - cd $(BIN_DIR)/HomeSecurityController; $(JAR) $(JARFLAGS) HomeSecurityController.jar ../HomeSecurityController/HomeSecurityController*.class ../HomeSecurityController/*.class ../iotcode/interfaces/SmartthingsSensor*.class ../iotcode/interfaces/Camera*.class ../iotcode/interfaces/Alarm*.class ../iotcode/interfaces/Room*.class ../iotcode/interfaces/ZoneState*.class ../iotcode/interfaces/Resolution*.class + cd $(BIN_DIR)/HomeSecurityController; $(JAR) $(JARFLAGS) HomeSecurityController.jar ../HomeSecurityController/HomeSecurityController*.class ../HomeSecurityController/*.class ../iotcode/interfaces/SmartthingsSensor*.class ../iotcode/interfaces/SmartthingsActuator*.class ../iotcode/interfaces/Camera*.class ../iotcode/interfaces/Alarm*.class ../iotcode/interfaces/Room*.class ../iotcode/interfaces/ZoneState*.class ../iotcode/interfaces/Resolution*.class PHONY += check-homesecurity check-homesecurity: $(JAVAC) $(JFLAGS) $(CHECKER_OPT) $(ASTUBS) *.java cp HomeSecurityController.config $(BIN_DIR)/HomeSecurityController - cd $(BIN_DIR)/HomeSecurityController; $(JAR) $(JARFLAGS) HomeSecurityController.jar ../HomeSecurityController/HomeSecurityController*.class ../HomeSecurityController/*.class ../iotcode/interfaces/SmartthingsSensor*.class ../iotcode/interfaces/Camera*.class ../iotcode/interfaces/Alarm*.class ../iotcode/interfaces/Room*.class ../iotcode/interfaces/ZoneState*.class ../iotcode/interfaces/Resolution*.class + cd $(BIN_DIR)/HomeSecurityController; $(JAR) $(JARFLAGS) HomeSecurityController.jar ../HomeSecurityController/HomeSecurityController*.class ../HomeSecurityController/*.class ../iotcode/interfaces/SmartthingsSensor*.class ../iotcode/interfaces/SmartthingsActuator*.class ../iotcode/interfaces/Camera*.class ../iotcode/interfaces/Alarm*.class ../iotcode/interfaces/Room*.class ../iotcode/interfaces/ZoneState*.class ../iotcode/interfaces/Resolution*.class .PHONY: $(PHONY) diff --git a/benchmarks/Java/HomeSecurityController/SmartthingsActuatorCallback_Skeleton.java b/benchmarks/Java/HomeSecurityController/SmartthingsActuatorCallback_Skeleton.java new file mode 100644 index 0000000..e76e39e --- /dev/null +++ b/benchmarks/Java/HomeSecurityController/SmartthingsActuatorCallback_Skeleton.java @@ -0,0 +1,116 @@ +package HomeSecurityController; + +import java.io.IOException; +import java.util.List; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Map; +import java.util.HashMap; +import java.util.concurrent.atomic.AtomicBoolean; +import iotrmi.Java.IoTRMIComm; +import iotrmi.Java.IoTRMICommClient; +import iotrmi.Java.IoTRMICommServer; +import iotrmi.Java.IoTRMIUtil; + +import iotcode.interfaces.*; + +public class SmartthingsActuatorCallback_Skeleton implements SmartthingsActuatorCallback { + + private SmartthingsActuatorCallback mainObj; + private int objectId = 2; + // Communications and synchronizations + private IoTRMIComm rmiComm; + private AtomicBoolean didAlreadyInitWaitInvoke; + private AtomicBoolean methodReceived; + private byte[] methodBytes = null; + // Permissions + private static Integer[] object2Permission = { 0 }; + private static List set2Allowed; + + + public SmartthingsActuatorCallback_Skeleton(SmartthingsActuatorCallback _mainObj, int _portSend, int _portRecv) throws Exception { + mainObj = _mainObj; + rmiComm = new IoTRMICommServer(_portSend, _portRecv); + set2Allowed = new ArrayList(Arrays.asList(object2Permission)); + IoTRMIUtil.mapSkel.put(_mainObj, this); + IoTRMIUtil.mapSkelId.put(_mainObj, objectId); + didAlreadyInitWaitInvoke = new AtomicBoolean(false); + methodReceived = new AtomicBoolean(false); + rmiComm.registerSkeleton(objectId, methodReceived); + Thread thread1 = new Thread() { + public void run() { + try { + ___waitRequestInvokeMethod(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + }; + thread1.start(); + } + + public SmartthingsActuatorCallback_Skeleton(SmartthingsActuatorCallback _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception { + mainObj = _mainObj; + rmiComm = _rmiComm; + objectId = _objectId; + set2Allowed = new ArrayList(Arrays.asList(object2Permission)); + didAlreadyInitWaitInvoke = new AtomicBoolean(false); + methodReceived = new AtomicBoolean(false); + rmiComm.registerSkeleton(objectId, methodReceived); + } + + public boolean didAlreadyInitWaitInvoke() { + return didAlreadyInitWaitInvoke.get(); + } + + public void newActuatorReadingAvailable(int _sensorId, int _value, boolean _activeValue) { + mainObj.newActuatorReadingAvailable(_sensorId, _value, _activeValue); + } + + public void ___newActuatorReadingAvailable() { + byte[] localMethodBytes = methodBytes; + rmiComm.setGetMethodBytes(); + Object[] paramObj = rmiComm.getMethodParams(new Class[] { int.class, int.class, boolean.class }, new Class[] { null, null, null }, localMethodBytes); + newActuatorReadingAvailable((int) paramObj[0], (int) paramObj[1], (boolean) paramObj[2]); + } + + public void ___waitRequestInvokeMethod() throws IOException { + didAlreadyInitWaitInvoke.compareAndSet(false, true); + while (true) { + if (!methodReceived.get()) { + continue; + } + methodBytes = rmiComm.getMethodBytes(); + methodReceived.set(false); + int _objectId = IoTRMIComm.getObjectId(methodBytes); + int methodId = IoTRMIComm.getMethodId(methodBytes); + if (_objectId == objectId) { + if (!set2Allowed.contains(methodId)) { + throw new Error("Object with object Id: " + _objectId + " is not allowed to access method: " + methodId); + } + } + else { + continue; + } + switch (methodId) { + case 0: + new Thread() { + public void run() { + try { + ___newActuatorReadingAvailable(); + } + catch (Exception ex) { + ex.printStackTrace(); + } + } + }.start(); + break; + default: + throw new Error("Method Id " + methodId + " not recognized!"); + } + } + } + +} diff --git a/benchmarks/Java/HomeSecurityController/SmartthingsActuatorSmart_Stub.java b/benchmarks/Java/HomeSecurityController/SmartthingsActuatorSmart_Stub.java new file mode 100644 index 0000000..db5b85b --- /dev/null +++ b/benchmarks/Java/HomeSecurityController/SmartthingsActuatorSmart_Stub.java @@ -0,0 +1,193 @@ +package HomeSecurityController; + +import java.io.IOException; +import java.util.List; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Map; +import java.util.HashMap; +import java.util.concurrent.atomic.AtomicBoolean; +import iotrmi.Java.IoTRMIComm; +import iotrmi.Java.IoTRMICommClient; +import iotrmi.Java.IoTRMICommServer; +import iotrmi.Java.IoTRMIUtil; + +import iotcode.interfaces.*; + +public class SmartthingsActuatorSmart_Stub implements SmartthingsActuatorSmart { + + private int objectId = 1; + private IoTRMIComm rmiComm; + // Synchronization variables + private AtomicBoolean retValueReceived5 = new AtomicBoolean(false); + private AtomicBoolean retValueReceived7 = new AtomicBoolean(false); + private AtomicBoolean retValueReceived4 = new AtomicBoolean(false); + private AtomicBoolean retValueReceived3 = new AtomicBoolean(false); + private AtomicBoolean retValueReceived1 = new AtomicBoolean(false); + + + public SmartthingsActuatorSmart_Stub(int _localPortSend, int _localPortRecv, int _portSend, int _portRecv, String _skeletonAddress, int _rev) throws Exception { + if (_localPortSend != 0 && _localPortRecv != 0) { + rmiComm = new IoTRMICommClient(_localPortSend, _localPortRecv, _portSend, _portRecv, _skeletonAddress, _rev); + } else + { + rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev); + } + rmiComm.registerStub(objectId, 5, retValueReceived5); + rmiComm.registerStub(objectId, 7, retValueReceived7); + rmiComm.registerStub(objectId, 4, retValueReceived4); + rmiComm.registerStub(objectId, 3, retValueReceived3); + rmiComm.registerStub(objectId, 1, retValueReceived1); + IoTRMIUtil.mapStub.put(objectId, this); + } + + public SmartthingsActuatorSmart_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception { + rmiComm = _rmiComm; + objectId = _objectId; + rmiComm.registerStub(objectId, 5, retValueReceived5); + rmiComm.registerStub(objectId, 7, retValueReceived7); + rmiComm.registerStub(objectId, 4, retValueReceived4); + rmiComm.registerStub(objectId, 3, retValueReceived3); + rmiComm.registerStub(objectId, 1, retValueReceived1); + } + + public long getTimestampOfLastReading() { + int methodId = 5; + Class retType = long.class; + Class[] paramCls = new Class[] { }; + Object[] paramObj = new Object[] { }; + rmiComm.remoteCall(objectId, methodId, paramCls, paramObj); + // Waiting for return value + while (!retValueReceived5.get()); + Object retObj = rmiComm.getReturnValue(retType, null); + retValueReceived5.set(false); + rmiComm.setGetReturnBytes(); + + return (long)retObj; + } + + public int getId() { + int methodId = 7; + Class retType = int.class; + Class[] paramCls = new Class[] { }; + Object[] paramObj = new Object[] { }; + rmiComm.remoteCall(objectId, methodId, paramCls, paramObj); + // Waiting for return value + while (!retValueReceived7.get()); + Object retObj = rmiComm.getReturnValue(retType, null); + retValueReceived7.set(false); + rmiComm.setGetReturnBytes(); + + return (int)retObj; + } + + public void registerCallback(SmartthingsActuatorCallback _callbackTo) { + int[] objIdSent0 = new int[1]; + try { + if (!IoTRMIUtil.mapSkel.containsKey(_callbackTo)) { + int newObjIdSent = rmiComm.getObjectIdCounter(); + objIdSent0[0] = newObjIdSent; + rmiComm.decrementObjectIdCounter(); + SmartthingsActuatorCallback_Skeleton skel0 = new SmartthingsActuatorCallback_Skeleton(_callbackTo, rmiComm, newObjIdSent); + IoTRMIUtil.mapSkel.put(_callbackTo, skel0); + IoTRMIUtil.mapSkelId.put(_callbackTo, newObjIdSent); + Thread thread = new Thread() { + public void run() { + try { + skel0.___waitRequestInvokeMethod(); + } catch (Exception ex) { + ex.printStackTrace(); + throw new Error("Exception when trying to run ___waitRequestInvokeMethod() for SmartthingsActuatorCallback_Skeleton!"); + } + } + }; + thread.start(); + while(!skel0.didAlreadyInitWaitInvoke()); + } + else + { + int newObjIdSent = IoTRMIUtil.mapSkelId.get(_callbackTo); + objIdSent0[0] = newObjIdSent; + } + } catch (Exception ex) { + ex.printStackTrace(); + throw new Error("Exception when generating skeleton objects!"); + } + + int methodId = 8; + Class retType = void.class; + Class[] paramCls = new Class[] { int[].class }; + Object[] paramObj = new Object[] { objIdSent0 }; + rmiComm.remoteCall(objectId, methodId, paramCls, paramObj); + } + + public void requestStatus() { + int methodId = 2; + Class retType = void.class; + Class[] paramCls = new Class[] { }; + Object[] paramObj = new Object[] { }; + rmiComm.remoteCall(objectId, methodId, paramCls, paramObj); + } + + public void setId(int id) { + int methodId = 6; + Class retType = void.class; + Class[] paramCls = new Class[] { int.class }; + Object[] paramObj = new Object[] { id }; + rmiComm.remoteCall(objectId, methodId, paramCls, paramObj); + } + + public boolean isActiveStatus() { + int methodId = 4; + Class retType = boolean.class; + Class[] paramCls = new Class[] { }; + Object[] paramObj = new Object[] { }; + rmiComm.remoteCall(objectId, methodId, paramCls, paramObj); + // Waiting for return value + while (!retValueReceived4.get()); + Object retObj = rmiComm.getReturnValue(retType, null); + retValueReceived4.set(false); + rmiComm.setGetReturnBytes(); + + return (boolean)retObj; + } + + public int getStatus() { + int methodId = 3; + Class retType = int.class; + Class[] paramCls = new Class[] { }; + Object[] paramObj = new Object[] { }; + rmiComm.remoteCall(objectId, methodId, paramCls, paramObj); + // Waiting for return value + while (!retValueReceived3.get()); + Object retObj = rmiComm.getReturnValue(retType, null); + retValueReceived3.set(false); + rmiComm.setGetReturnBytes(); + + return (int)retObj; + } + + public void init() { + int methodId = 0; + Class retType = void.class; + Class[] paramCls = new Class[] { }; + Object[] paramObj = new Object[] { }; + rmiComm.remoteCall(objectId, methodId, paramCls, paramObj); + } + + public boolean actuate(int value) { + int methodId = 1; + Class retType = boolean.class; + Class[] paramCls = new Class[] { int.class }; + Object[] paramObj = new Object[] { value }; + rmiComm.remoteCall(objectId, methodId, paramCls, paramObj); + // Waiting for return value + while (!retValueReceived1.get()); + Object retObj = rmiComm.getReturnValue(retType, null); + retValueReceived1.set(false); + rmiComm.setGetReturnBytes(); + + return (boolean)retObj; + } + +} diff --git a/benchmarks/drivers/Java/DoorlockActuator/DoorlockActuator.config b/benchmarks/drivers/Java/DoorlockActuator/DoorlockActuator.config new file mode 100644 index 0000000..6925867 --- /dev/null +++ b/benchmarks/drivers/Java/DoorlockActuator/DoorlockActuator.config @@ -0,0 +1,7 @@ +# Skeleton/original interface +INTERFACE_CLASS=SmartthingsActuator +# Stub +INTERFACE_STUB_CLASS=SmartthingsActuatorSmart + +# Language +LANGUAGE=Java diff --git a/benchmarks/drivers/Java/DoorlockActuator/DoorlockActuator.java b/benchmarks/drivers/Java/DoorlockActuator/DoorlockActuator.java new file mode 100644 index 0000000..09eb539 --- /dev/null +++ b/benchmarks/drivers/Java/DoorlockActuator/DoorlockActuator.java @@ -0,0 +1,300 @@ +package iotcode.DoorlockActuator; + +// 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 DoorlockActuator implements IoTZigbeeCallback, SmartthingsActuator { + + 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 < SmartthingsActuatorSmartCallback > callbackList = new CopyOnWriteArrayList < SmartthingsActuatorSmartCallback > (); + + private int sensorId = 0; + + @config private IoTSet doorlockActuatorUdpAddress; + @config private IoTSet doorlockActuatorZigbeeAddress; + + public DoorlockActuator(IoTSet dSet, IoTSet zigSet) { + doorlockActuatorUdpAddress = dSet; + doorlockActuatorZigbeeAddress = zigSet; + } + + public DoorlockActuator() { + } + + public void init() { + + if (didAlreadyInit.compareAndSet(false, true) == false) { + return; // already init + } + + didAlreadyClose.set(false); + + try { + Iterator itrUdp = doorlockActuatorUdpAddress.iterator(); + Iterator itrZig = doorlockActuatorZigbeeAddress.iterator(); + + zigConnection = new IoTZigbee((IoTDeviceAddress)itrUdp.next(), (IoTZigbeeAddress)itrZig.next()); + + // DEBUG + System.out.println("DEBUG: Allocate iterators to print out addresses!"); + Iterator itrDebugUdp = doorlockActuatorUdpAddress.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 = doorlockActuatorZigbeeAddress.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); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * actuate() method + * + * @param value Integer value for actuation + * @return boolean Status of sending actuate command + */ + public boolean actuate(int value) { + + // Value check + if (value == 0) + System.out.println("Doorlock: Is locking!"); + else if(value == 1) + System.out.println("Doorlock: Is unlocking!"); + else { // Failed to send command because of invalid value + throw new Error("Doorlock: Actuate value " + value + " is not recognized (only 0 or 1)! Please check your method call..."); + } + try { + zigConnection.sendLockOrUnlockDoorRequest(0x0005, 0x0101, 0x0104, 0x02, value); + sleep(0); + } catch (Exception e) { + e.printStackTrace(); + } + return true; + } + + /** + * requestStatus() method + * + * @return void + */ + public void requestStatus() { + System.out.println("Doorlock: Requesting status... Receiving answer through callback..."); + try { + 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() { + + int tmp = 0; + + try { + gettingLatestDataMutex.acquire(); + tmp = detectedValue; + + } catch (Exception e) { + e.printStackTrace(); + } + gettingLatestDataMutex.release(); + + return tmp; + } + + public boolean isActiveStatus() { + + int tmp = getStatus(); + if (tmp == 1) + detectStatus = true; // ACTIVE == Door is locked + else + detectStatus = false; // NOT ACTIVE == 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 (SmartthingsActuatorSmartCallback cb : callbackList) { + cb.newActuatorReadingAvailable(this.getId(), this.getStatus(), this.isActiveStatus()); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + } + + public void registerCallback(SmartthingsActuatorSmartCallback _callbackTo) { + callbackList.add(_callbackTo); + } +} diff --git a/benchmarks/drivers/Java/DoorlockActuator/SmartthingsActuatorSmartCallback_Stub.java b/benchmarks/drivers/Java/DoorlockActuator/SmartthingsActuatorSmartCallback_Stub.java new file mode 100644 index 0000000..9a2f912 --- /dev/null +++ b/benchmarks/drivers/Java/DoorlockActuator/SmartthingsActuatorSmartCallback_Stub.java @@ -0,0 +1,47 @@ +package iotcode.DoorlockActuator; + +import java.io.IOException; +import java.util.List; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Map; +import java.util.HashMap; +import java.util.concurrent.atomic.AtomicBoolean; +import iotrmi.Java.IoTRMIComm; +import iotrmi.Java.IoTRMICommClient; +import iotrmi.Java.IoTRMICommServer; +import iotrmi.Java.IoTRMIUtil; + +import iotcode.interfaces.*; + +public class SmartthingsActuatorSmartCallback_Stub implements SmartthingsActuatorSmartCallback { + + private int objectId = 2; + private IoTRMIComm rmiComm; + // Synchronization variables + + + public SmartthingsActuatorSmartCallback_Stub(int _localPortSend, int _localPortRecv, int _portSend, int _portRecv, String _skeletonAddress, int _rev) throws Exception { + if (_localPortSend != 0 && _localPortRecv != 0) { + rmiComm = new IoTRMICommClient(_localPortSend, _localPortRecv, _portSend, _portRecv, _skeletonAddress, _rev); + } else + { + rmiComm = new IoTRMICommClient(_portSend, _portRecv, _skeletonAddress, _rev); + } + IoTRMIUtil.mapStub.put(objectId, this); + } + + public SmartthingsActuatorSmartCallback_Stub(IoTRMIComm _rmiComm, int _objectId) throws Exception { + rmiComm = _rmiComm; + objectId = _objectId; + } + + public void newActuatorReadingAvailable(int _sensorId, int _value, boolean _activeValue) { + int methodId = 0; + Class retType = void.class; + Class[] paramCls = new Class[] { int.class, int.class, boolean.class }; + Object[] paramObj = new Object[] { _sensorId, _value, _activeValue }; + rmiComm.remoteCall(objectId, methodId, paramCls, paramObj); + } + +} diff --git a/benchmarks/drivers/Java/DoorlockActuator/SmartthingsActuator_Skeleton.java b/benchmarks/drivers/Java/DoorlockActuator/SmartthingsActuator_Skeleton.java new file mode 100644 index 0000000..41ca279 --- /dev/null +++ b/benchmarks/drivers/Java/DoorlockActuator/SmartthingsActuator_Skeleton.java @@ -0,0 +1,323 @@ +package iotcode.DoorlockActuator; + +import java.io.IOException; +import java.util.List; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Map; +import java.util.HashMap; +import java.util.concurrent.atomic.AtomicBoolean; +import iotrmi.Java.IoTRMIComm; +import iotrmi.Java.IoTRMICommClient; +import iotrmi.Java.IoTRMICommServer; +import iotrmi.Java.IoTRMIUtil; + +import iotcode.interfaces.*; + +public class SmartthingsActuator_Skeleton implements SmartthingsActuator { + + private SmartthingsActuator mainObj; + private int objectId = 1; + // Communications and synchronizations + private IoTRMIComm rmiComm; + private AtomicBoolean didAlreadyInitWaitInvoke; + private AtomicBoolean methodReceived; + private byte[] methodBytes = null; + // Permissions + private static Integer[] object1Permission = { 5, 7, 8, 2, 6, 4, 3, 0, 1 }; + private static List set1Allowed; + + + public SmartthingsActuator_Skeleton(SmartthingsActuator _mainObj, int _portSend, int _portRecv) throws Exception { + mainObj = _mainObj; + rmiComm = new IoTRMICommServer(_portSend, _portRecv); + set1Allowed = new ArrayList(Arrays.asList(object1Permission)); + IoTRMIUtil.mapSkel.put(_mainObj, this); + IoTRMIUtil.mapSkelId.put(_mainObj, objectId); + didAlreadyInitWaitInvoke = new AtomicBoolean(false); + methodReceived = new AtomicBoolean(false); + rmiComm.registerSkeleton(objectId, methodReceived); + Thread thread1 = new Thread() { + public void run() { + try { + ___waitRequestInvokeMethod(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + }; + thread1.start(); + } + + public SmartthingsActuator_Skeleton(SmartthingsActuator _mainObj, IoTRMIComm _rmiComm, int _objectId) throws Exception { + mainObj = _mainObj; + rmiComm = _rmiComm; + objectId = _objectId; + set1Allowed = new ArrayList(Arrays.asList(object1Permission)); + didAlreadyInitWaitInvoke = new AtomicBoolean(false); + methodReceived = new AtomicBoolean(false); + rmiComm.registerSkeleton(objectId, methodReceived); + } + + public boolean didAlreadyInitWaitInvoke() { + return didAlreadyInitWaitInvoke.get(); + } + + public void init() { + mainObj.init(); + } + + public boolean actuate(int value) { + return mainObj.actuate(value); + } + + public void requestStatus() { + mainObj.requestStatus(); + } + + public int getStatus() { + return mainObj.getStatus(); + } + + public boolean isActiveStatus() { + return mainObj.isActiveStatus(); + } + + public long getTimestampOfLastReading() { + return mainObj.getTimestampOfLastReading(); + } + + public void setId(int id) { + mainObj.setId(id); + } + + public int getId() { + return mainObj.getId(); + } + + public void registerCallback(SmartthingsActuatorSmartCallback _callbackTo) { + mainObj.registerCallback(_callbackTo); + } + + public void ___init() { + byte[] localMethodBytes = methodBytes; + rmiComm.setGetMethodBytes(); + Object[] paramObj = rmiComm.getMethodParams(new Class[] { }, new Class[] { }, localMethodBytes); + init(); + } + + public void ___actuate() throws IOException { + byte[] localMethodBytes = methodBytes; + rmiComm.setGetMethodBytes(); + Object[] paramObj = rmiComm.getMethodParams(new Class[] { int.class }, new Class[] { null }, localMethodBytes); + Object retObj = actuate((int) paramObj[0]); + rmiComm.sendReturnObj(retObj, localMethodBytes); + } + + public void ___requestStatus() { + byte[] localMethodBytes = methodBytes; + rmiComm.setGetMethodBytes(); + Object[] paramObj = rmiComm.getMethodParams(new Class[] { }, new Class[] { }, localMethodBytes); + requestStatus(); + } + + public void ___getStatus() throws IOException { + byte[] localMethodBytes = methodBytes; + rmiComm.setGetMethodBytes(); + Object[] paramObj = rmiComm.getMethodParams(new Class[] { }, new Class[] { }, localMethodBytes); + Object retObj = getStatus(); + rmiComm.sendReturnObj(retObj, localMethodBytes); + } + + public void ___isActiveStatus() throws IOException { + byte[] localMethodBytes = methodBytes; + rmiComm.setGetMethodBytes(); + Object[] paramObj = rmiComm.getMethodParams(new Class[] { }, new Class[] { }, localMethodBytes); + Object retObj = isActiveStatus(); + rmiComm.sendReturnObj(retObj, localMethodBytes); + } + + public void ___getTimestampOfLastReading() throws IOException { + byte[] localMethodBytes = methodBytes; + rmiComm.setGetMethodBytes(); + Object[] paramObj = rmiComm.getMethodParams(new Class[] { }, new Class[] { }, localMethodBytes); + Object retObj = getTimestampOfLastReading(); + rmiComm.sendReturnObj(retObj, localMethodBytes); + } + + public void ___setId() { + byte[] localMethodBytes = methodBytes; + rmiComm.setGetMethodBytes(); + Object[] paramObj = rmiComm.getMethodParams(new Class[] { int.class }, new Class[] { null }, localMethodBytes); + setId((int) paramObj[0]); + } + + public void ___getId() throws IOException { + byte[] localMethodBytes = methodBytes; + rmiComm.setGetMethodBytes(); + Object[] paramObj = rmiComm.getMethodParams(new Class[] { }, new Class[] { }, localMethodBytes); + Object retObj = getId(); + rmiComm.sendReturnObj(retObj, localMethodBytes); + } + + public void ___registerCallback() { + byte[] localMethodBytes = methodBytes; + rmiComm.setGetMethodBytes(); + Object[] paramObj = rmiComm.getMethodParams(new Class[] { int[].class }, new Class[] { null }, localMethodBytes); + try { + int[] stubIdArray0 = (int[]) paramObj[0]; + int objIdRecv0 = stubIdArray0[0]; + SmartthingsActuatorSmartCallback newStub0 = null; + if(!IoTRMIUtil.mapStub.containsKey(objIdRecv0)) { + newStub0 = new SmartthingsActuatorSmartCallback_Stub(rmiComm, objIdRecv0); + IoTRMIUtil.mapStub.put(objIdRecv0, newStub0); + rmiComm.setObjectIdCounter(objIdRecv0); + rmiComm.decrementObjectIdCounter(); + } + else { + newStub0 = (SmartthingsActuatorSmartCallback_Stub) IoTRMIUtil.mapStub.get(objIdRecv0); + } + SmartthingsActuatorSmartCallback stub0 = newStub0; + registerCallback(stub0); + } catch(Exception ex) { + ex.printStackTrace(); + throw new Error("Exception from callback object instantiation!"); + } + } + + public void ___waitRequestInvokeMethod() throws IOException { + didAlreadyInitWaitInvoke.compareAndSet(false, true); + while (true) { + if (!methodReceived.get()) { + continue; + } + methodBytes = rmiComm.getMethodBytes(); + methodReceived.set(false); + int _objectId = IoTRMIComm.getObjectId(methodBytes); + int methodId = IoTRMIComm.getMethodId(methodBytes); + if (_objectId == objectId) { + if (!set1Allowed.contains(methodId)) { + throw new Error("Object with object Id: " + _objectId + " is not allowed to access method: " + methodId); + } + } + else { + continue; + } + switch (methodId) { + case 0: + new Thread() { + public void run() { + try { + ___init(); + } + catch (Exception ex) { + ex.printStackTrace(); + } + } + }.start(); + break; + case 1: + new Thread() { + public void run() { + try { + ___actuate(); + } + catch (Exception ex) { + ex.printStackTrace(); + } + } + }.start(); + break; + case 2: + new Thread() { + public void run() { + try { + ___requestStatus(); + } + catch (Exception ex) { + ex.printStackTrace(); + } + } + }.start(); + break; + case 3: + new Thread() { + public void run() { + try { + ___getStatus(); + } + catch (Exception ex) { + ex.printStackTrace(); + } + } + }.start(); + break; + case 4: + new Thread() { + public void run() { + try { + ___isActiveStatus(); + } + catch (Exception ex) { + ex.printStackTrace(); + } + } + }.start(); + break; + case 5: + new Thread() { + public void run() { + try { + ___getTimestampOfLastReading(); + } + catch (Exception ex) { + ex.printStackTrace(); + } + } + }.start(); + break; + case 6: + new Thread() { + public void run() { + try { + ___setId(); + } + catch (Exception ex) { + ex.printStackTrace(); + } + } + }.start(); + break; + case 7: + new Thread() { + public void run() { + try { + ___getId(); + } + catch (Exception ex) { + ex.printStackTrace(); + } + } + }.start(); + break; + case 8: + new Thread() { + public void run() { + try { + ___registerCallback(); + } + catch (Exception ex) { + ex.printStackTrace(); + } + } + }.start(); + break; + default: + throw new Error("Method Id " + methodId + " not recognized!"); + } + } + } + +} diff --git a/benchmarks/drivers/Java/Makefile b/benchmarks/drivers/Java/Makefile index 92ab192..ce21238 100644 --- a/benchmarks/drivers/Java/Makefile +++ b/benchmarks/drivers/Java/Makefile @@ -16,8 +16,8 @@ CHECKER_OPT = -processor iotchecker.IoTJavaChecker -AprintErrorStack ASTUBS = -Astubs=../../../checker/astubs/ -all: light camera labroom greenlawn sprinkler moisture weathergateway audioroom gpsgateway ihome homeroom alarm motion multipurpose waterleak -check-all: check-light check-camera check-labroom check-greenlawn check-sprinkler check-moisture check-weathergateway check-audioroom check-gpsgateway check-ihome check-homeroom check-alarm check-motion check-multipurpose check-waterleak +all: light camera labroom greenlawn sprinkler moisture weathergateway audioroom gpsgateway ihome homeroom alarm motion multipurpose waterleak doorlock doorlockactuator +check-all: check-light check-camera check-labroom check-greenlawn check-sprinkler check-moisture check-weathergateway check-audioroom check-gpsgateway check-ihome check-homeroom check-alarm check-motion check-multipurpose check-waterleak check-doorlock check-doorlockactuator # Compile - without checker # @@ -121,6 +121,12 @@ doorlock: cp DoorlockSensor/DoorlockSensor.config $(BIN_DIR)/iotcode/DoorlockSensor cd $(BIN_DIR)/iotcode/DoorlockSensor; $(JAR) $(JARFLAGS) DoorlockSensor.jar ../../iotcode/DoorlockSensor/*.class ../../iotcode/interfaces/SmartthingsSensor*.class ../../iotcode/interfaces/Camera*.class +PHONY += doorlockactuator +doorlockactuator: + $(JAVAC) $(JFLAGS) DoorlockActuator/*.java + cp DoorlockActuator/DoorlockActuator.config $(BIN_DIR)/iotcode/DoorlockActuator + cd $(BIN_DIR)/iotcode/DoorlockActuator; $(JAR) $(JARFLAGS) DoorlockActuator.jar ../../iotcode/DoorlockActuator/*.class ../../iotcode/interfaces/SmartthingsActuator*.class ../../iotcode/interfaces/Camera*.class + # Compile - with checker # PHONY += check-light @@ -220,4 +226,10 @@ check-doorlock: cp DoorlockSensor/DoorlockSensor.config $(BIN_DIR)/iotcode/DoorlockSensor cd $(BIN_DIR)/iotcode/DoorlockSensor; $(JAR) $(JARFLAGS) DoorlockSensor.jar ../../iotcode/DoorlockSensor/*.class ../../iotcode/interfaces/SmartthingsSensor*.class ../../iotcode/interfaces/Camera*.class +PHONY += check-doorlockactuator +check-doorlockactuator: + $(JAVAC) $(JFLAGS) $(CHECKER_OPT) $(ASTUBS) DoorlockActuator/*.java + cp DoorlockActuator/DoorlockActuator.config $(BIN_DIR)/iotcode/DoorlockActuator + cd $(BIN_DIR)/iotcode/DoorlockActuator; $(JAR) $(JARFLAGS) DoorlockActuator.jar ../../iotcode/DoorlockActuator/*.class ../../iotcode/interfaces/SmartthingsActuator*.class ../../iotcode/interfaces/Camera*.class + .PHONY: $(PHONY) diff --git a/benchmarks/interfaces/SmartthingsActuator.java b/benchmarks/interfaces/SmartthingsActuator.java new file mode 100644 index 0000000..4eda11b --- /dev/null +++ b/benchmarks/interfaces/SmartthingsActuator.java @@ -0,0 +1,16 @@ +package iotcode.interfaces; + +import java.util.List; +import java.util.ArrayList; + +public interface SmartthingsActuator { + public void init(); + public boolean actuate(int value); + public void requestStatus(); + public int getStatus(); + public boolean isActiveStatus(); + public long getTimestampOfLastReading(); + public void setId(int id); + public int getId(); + public void registerCallback(SmartthingsActuatorSmartCallback _callbackTo); +} diff --git a/benchmarks/interfaces/SmartthingsActuatorCallback.java b/benchmarks/interfaces/SmartthingsActuatorCallback.java new file mode 100644 index 0000000..df151de --- /dev/null +++ b/benchmarks/interfaces/SmartthingsActuatorCallback.java @@ -0,0 +1,8 @@ +package iotcode.interfaces; + +import java.util.List; +import java.util.ArrayList; + +public interface SmartthingsActuatorCallback { + public void newActuatorReadingAvailable(int _sensorId, int _value, boolean _activeValue); +} diff --git a/benchmarks/interfaces/SmartthingsActuatorSmart.java b/benchmarks/interfaces/SmartthingsActuatorSmart.java new file mode 100644 index 0000000..6a5f790 --- /dev/null +++ b/benchmarks/interfaces/SmartthingsActuatorSmart.java @@ -0,0 +1,17 @@ +package iotcode.interfaces; + +import java.util.List; +import java.util.ArrayList; + +public interface SmartthingsActuatorSmart { + + public long getTimestampOfLastReading(); + public int getId(); + public void registerCallback(SmartthingsActuatorCallback _callbackTo); + public void requestStatus(); + public void setId(int id); + public boolean isActiveStatus(); + public int getStatus(); + public void init(); + public boolean actuate(int value); +} diff --git a/benchmarks/interfaces/SmartthingsActuatorSmartCallback.java b/benchmarks/interfaces/SmartthingsActuatorSmartCallback.java new file mode 100644 index 0000000..45e9607 --- /dev/null +++ b/benchmarks/interfaces/SmartthingsActuatorSmartCallback.java @@ -0,0 +1,9 @@ +package iotcode.interfaces; + +import java.util.List; +import java.util.ArrayList; + +public interface SmartthingsActuatorSmartCallback { + + public void newActuatorReadingAvailable(int _sensorId, int _value, boolean _activeValue); +} diff --git a/iotjava/Makefile b/iotjava/Makefile index c3d55c4..e1e8f08 100644 --- a/iotjava/Makefile +++ b/iotjava/Makefile @@ -133,6 +133,12 @@ run-compiler-smart: cp ../localconfig/iotpolicy/SmartthingsSensor/*.req $(BIN_DIR)/iotpolicy/ cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler smartthingssensor.pol smartthingssensor.req smartthingssensorcallback.pol smartthingssensorcallback.req -java Java +PHONY += run-compiler-actuate +run-compiler-actuate: + cp ../localconfig/iotpolicy/SmartthingsActuator/*.pol $(BIN_DIR)/iotpolicy/ + cp ../localconfig/iotpolicy/SmartthingsActuator/*.req $(BIN_DIR)/iotpolicy/ + cd $(BIN_DIR)/iotpolicy; $(JAVA) -cp .:..:../$(PARSERJARS):../$(BIN_DIR) iotpolicy.IoTCompiler smartthingsactuator.pol smartthingsactuator.req smartthingsactuatorcallback.pol smartthingsactuatorcallback.req -java Java + # TODO: Can remove this later - just to test-compile the resulted files from the compiler PHONY += compile compile: diff --git a/localconfig/iotpolicy/SmartthingsActuator/smartthingsactuator.pol b/localconfig/iotpolicy/SmartthingsActuator/smartthingsactuator.pol new file mode 100644 index 0000000..a271924 --- /dev/null +++ b/localconfig/iotpolicy/SmartthingsActuator/smartthingsactuator.pol @@ -0,0 +1,39 @@ +public interface SmartthingsActuator { + + public void init(); + public boolean actuate(int value); + public void requestStatus(); + public int getStatus(); + public boolean isActiveStatus(); + public long getTimestampOfLastReading(); + public void setId(int id); + public int getId(); + public void registerCallback(SmartthingsActuatorCallback _callbackTo); + + capability Initialize { + description = "Initialize object"; + method = "init()"; + method = "registerCallback(SmartthingsActuatorCallback _callbackTo)"; + } + + capability Actuate { + description = "Actuate device"; + method = "actuate(int value)"; + } + + capability Status { + description = "Handle status"; + method = "requestStatus()"; + method = "getStatus()"; + method = "isActiveStatus()"; + method = "getTimestampOfLastReading()"; + } + + capability ActuatorId { + description = "Manage actuator Id"; + method = "setId(int id)"; + method = "getId()"; + } +} + + diff --git a/localconfig/iotpolicy/SmartthingsActuator/smartthingsactuator.req b/localconfig/iotpolicy/SmartthingsActuator/smartthingsactuator.req new file mode 100644 index 0000000..ef11b8a --- /dev/null +++ b/localconfig/iotpolicy/SmartthingsActuator/smartthingsactuator.req @@ -0,0 +1,3 @@ + +requires SmartthingsSensor with Initialize, Actuate, Status, ActuatorId as interface SmartthingsActuatorSmart; + diff --git a/localconfig/iotpolicy/SmartthingsActuator/smartthingsactuatorcallback.pol b/localconfig/iotpolicy/SmartthingsActuator/smartthingsactuatorcallback.pol new file mode 100644 index 0000000..67ef033 --- /dev/null +++ b/localconfig/iotpolicy/SmartthingsActuator/smartthingsactuatorcallback.pol @@ -0,0 +1,11 @@ +public interface SmartthingsActuatorCallback { + + public void newActuatorReadingAvailable(int _sensorId, int _value, boolean _activeValue); + + capability Callback { + description = "Callback method"; + method = "newActuatorReadingAvailable(int _sensorId, int _value, boolean _activeValue)"; + } +} + + diff --git a/localconfig/iotpolicy/SmartthingsActuator/smartthingsactuatorcallback.req b/localconfig/iotpolicy/SmartthingsActuator/smartthingsactuatorcallback.req new file mode 100644 index 0000000..65f9f0e --- /dev/null +++ b/localconfig/iotpolicy/SmartthingsActuator/smartthingsactuatorcallback.req @@ -0,0 +1,3 @@ + +requires SmartthingsActuatorCallback with Callback as interface SmartthingsActuatorSmartCallback; + diff --git a/localconfig/mysql/doorlockActuatorUdpAddress.config b/localconfig/mysql/doorlockActuatorUdpAddress.config new file mode 100644 index 0000000..eaec2e4 --- /dev/null +++ b/localconfig/mysql/doorlockActuatorUdpAddress.config @@ -0,0 +1,5 @@ +SELECT * FROM +IoTDeviceAddress +WHERE +TYPE='DoorlockActuatorAdd' +; diff --git a/localconfig/mysql/doorlockActuatorZigbeeAddress.config b/localconfig/mysql/doorlockActuatorZigbeeAddress.config new file mode 100644 index 0000000..e9f2d7e --- /dev/null +++ b/localconfig/mysql/doorlockActuatorZigbeeAddress.config @@ -0,0 +1,5 @@ +SELECT * FROM +IoTZigbeeAddress +WHERE +TYPE='DoorlockActuatorZBAdd' +; diff --git a/localconfig/mysql/doorlockSet.config b/localconfig/mysql/doorlockSet.config new file mode 100644 index 0000000..49b24c1 --- /dev/null +++ b/localconfig/mysql/doorlockSet.config @@ -0,0 +1,3 @@ +SELECT * FROM +SmartthingsActuatorSmart +; diff --git a/others/Mysql/IoTMain.gz b/others/Mysql/IoTMain.gz index a8d18ad..4b9fe78 100644 Binary files a/others/Mysql/IoTMain.gz and b/others/Mysql/IoTMain.gz differ diff --git a/others/lede-gui/.idea/misc.xml b/others/lede-gui/.idea/misc.xml index b0a270f..7e15d9d 100644 --- a/others/lede-gui/.idea/misc.xml +++ b/others/lede-gui/.idea/misc.xml @@ -27,7 +27,7 @@ - + diff --git a/others/lede-gui/.idea/workspace.xml b/others/lede-gui/.idea/workspace.xml index be99b55..d764ed2 100644 --- a/others/lede-gui/.idea/workspace.xml +++ b/others/lede-gui/.idea/workspace.xml @@ -50,12 +50,10 @@ - + - - - + @@ -64,12 +62,9 @@ - + - - - - + @@ -77,54 +72,25 @@ - + - - - - - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1244,11 +1210,6 @@ - - - - - @@ -1416,6 +1377,11 @@ + + + + + @@ -2036,24 +2002,21 @@ - + - - - - - + + @@ -2066,7 +2029,10 @@ + + + @@ -2148,63 +2114,18 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - + + @@ -2230,7 +2151,6 @@ - @@ -2238,7 +2158,6 @@ - @@ -2268,7 +2187,6 @@ - @@ -2282,28 +2200,8 @@ - - - - - - - - - - - - - - - - - - - - - - + + @@ -2315,14 +2213,7 @@ - - - - - - - - + @@ -2367,7 +2258,6 @@ - @@ -2384,61 +2274,29 @@ - + - - - + - + - - - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -2466,5 +2324,26 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/others/lede-gui/lede-gui.iml b/others/lede-gui/lede-gui.iml index 74baa3e..288756d 100644 --- a/others/lede-gui/lede-gui.iml +++ b/others/lede-gui/lede-gui.iml @@ -77,31 +77,13 @@ - - - - - - - - - - - - - - - - - -