Perfecting 4th benchmark; adding needed MySQL config files; maturing Zigbee drivers
authorrtrimana <rtrimana@uci.edu>
Sat, 7 Jan 2017 00:09:52 +0000 (16:09 -0800)
committerrtrimana <rtrimana@uci.edu>
Sat, 7 Jan 2017 00:09:52 +0000 (16:09 -0800)
18 files changed:
benchmarks/HomeSecurityController/HomeSecurityController.java
benchmarks/drivers/Makefile
benchmarks/drivers/MotionSensor/MotionSensor.java
benchmarks/drivers/MultipurposeSensor/MultipurposeSensor.java
benchmarks/drivers/WaterLeakSensor/WaterLeakSensor.java
benchmarks/other/ZigbeeTest/IoTZigbee.java
iotjava/iotrmi/Java/IoTSocket.java
iotjava/iotruntime/master/IoTMaster.java
iotjava/iotruntime/zigbee/IoTZigbee.java
localconfig/iotruntime/IoTMaster.config
localconfig/mysql/alm_Addresses.config [new file with mode: 0644]
localconfig/mysql/camSet.config
localconfig/mysql/motionSensorUdpAddress.config [new file with mode: 0644]
localconfig/mysql/motionSensorZigbeeAddress.config [new file with mode: 0644]
localconfig/mysql/multipurposeSensorUdpAddress.config [new file with mode: 0644]
localconfig/mysql/multipurposeSensorZigbeeAddress.config [new file with mode: 0644]
localconfig/mysql/waterleakSensorUdpAddress.config [new file with mode: 0644]
localconfig/mysql/waterleakSensorZigbeeAddress.config [new file with mode: 0644]

index 5129e4ad40d2af9ffe54243cc2cc029063842e45..bab46cd50c61d3d7ce72ef1eca066f2bfb13c848 100644 (file)
@@ -131,8 +131,12 @@ public class HomeSecurityController implements SmartthingsSensorCallback {
                        try {
                                // Initialize sensors
                                sen.init();
+                               System.out.println("DEBUG: Initialized smartthings sensor! ID: " + sensorId + " Room ID: " + rm.getRoomID());
+                               senDetectStatus.put(sensorId, false);
+                               System.out.println("DEBUG: Initialized sensor detection to false!");
                                sen.setId(sensorId++);
-                               System.out.println("DEBUG: Initialized smartthings sensor!");
+                               sen.registerCallback(this);
+                               System.out.println("DEBUG: Registered sensor callback!");
                        } catch (Exception e) {
                                e.printStackTrace();
                        }
@@ -146,10 +150,10 @@ public class HomeSecurityController implements SmartthingsSensorCallback {
         */
        private void initCameras(RoomSmart rm) {
 
-               // Get and init the cameras for this specific room
+               // Get and init the IAS sensors for this specific room
                HashSet<CameraSmart> cameras = roomCameraRelation.get(rm);
                // Setup the cameras, start them all and assign each one a motion detector
-               for (CameraSmart cam : camSet.values()) {
+               for (CameraSmart cam : cameras) {
 
                        // Each camera will have a motion detector unique to it since the motion detection has state
                        MotionDetection mo = new MotionDetection(12, 0.5f, 10, 10);
@@ -170,6 +174,9 @@ public class HomeSecurityController implements SmartthingsSensorCallback {
 
                        // Remember which motion detector is for what camera
                        camMotionDetect.put(cam, mo);
+
+                       // Initialize detection to false
+                       camDetectStatus.put(cam, false);
                }
        }
 
@@ -242,9 +249,9 @@ public class HomeSecurityController implements SmartthingsSensorCallback {
         *   @param _numberOfSeconds [int]  , Number of seconds in the past that we consider recent.
         *   @param _upperThreshold  [int]  , Number of seconds as an upper bound before we turn off.
         *
-        *   @return [void] None.
+        *   @return [boolean] None.
         */
-       private void updateCameraStatus(RoomSmart _room, int _numberOfSeconds) {
+       private boolean roomDidHaveMotionRecently(RoomSmart _room, int _numberOfSeconds) {
                long currentTimeSeconds = (new Date()).getTime() / 1000;
 
                // Loop through all the cameras in the room
@@ -259,14 +266,16 @@ public class HomeSecurityController implements SmartthingsSensorCallback {
                        } else {
                                // motionTime == null means this is the initialization phase
                                // so we put false
-                               camDetectStatus.put(cam, false);
+                               return false;
                        }
 
                        // Did detect motion recently
                        if (Math.abs(currentTimeSeconds - lastDetectedMotionSeconds) < _numberOfSeconds) {
-                               camDetectStatus.put(cam, true);
+                               return true;
                        }
                }
+
+               return false;
        }
 
 
@@ -278,11 +287,11 @@ public class HomeSecurityController implements SmartthingsSensorCallback {
 
                System.out.println("DEBUG: Sensor reading value: " + _value);
                if(_activeValue) {
-
+                       System.out.println("DEBUG: Sensor is detecting something: " + _activeValue);
                        senDetectStatus.put(_sensorId, true);
 
                } else {
-
+                       //System.out.println("DEBUG: Sensor is not detecting something: " + _activeValue);
                        senDetectStatus.put(_sensorId, false);
                } 
        }
@@ -342,7 +351,7 @@ public class HomeSecurityController implements SmartthingsSensorCallback {
                for (RoomSmart room : roomSet.values()) {
 
                        // Update status of camera
-                       updateCameraStatus(room, MOTION_TIME_THRESHOLD);
+                       updateCameraStatus(room);
 
                        // Update status of doorlocks
                        //updateDoorLockStatus(room);
@@ -353,6 +362,28 @@ public class HomeSecurityController implements SmartthingsSensorCallback {
        }
 
 
+       /** Update the status of all devices
+        *
+        *   @return [void] None.
+        */
+       private void updateCameraStatus(RoomSmart room) {
+
+               HashSet<CameraSmart> cameras = roomCameraRelation.get(room);
+               if (roomDidHaveMotionRecently(room, MOTION_TIME_THRESHOLD)) {
+
+                       // Motion was detected
+                       System.out.println("DEBUG: Camera detected something!");
+                       for(CameraSmart cam : cameras)
+                               camDetectStatus.put(cam, true);
+               } else {
+
+                       // No motion was detected
+                       //System.out.println("DEBUG: Camera didn't detect anything!");
+                       for(CameraSmart cam : cameras)
+                               camDetectStatus.put(cam, false);
+               }
+       }
+
        /** Method to turn on alarms
         *
         *   @return [void] None.
@@ -410,10 +441,12 @@ public class HomeSecurityController implements SmartthingsSensorCallback {
                        for (SmartthingsSensorSmart sensor : roomSensorRelation.get(room)) {
 
                                // Get the right sensor and the right detection status (true or false)
+                               //System.out.println("ABOUT TO DETECT: Reading sensor: " + sensor.getId());
                                if (senDetectStatus.get(sensor.getId())) {
                                        zoneId = room.getRoomID();
                                        turnOnAlarms(zoneId);
                                        System.out.println("DETECTION: Sensor active in room: " + zoneId);
+                                       System.out.println("DETECTION: Detection by sensor: " + sensor.getId());
                                }
                        }
                }
@@ -494,15 +527,17 @@ public class HomeSecurityController implements SmartthingsSensorCallback {
                        initCameras(rm);
 
                        // Init all doorlocks
-                       //initDoorLocks(rm);
+                       //initDoorLocks();
 
                        // Init all outlets
-                       //initOutlets(rm);
+                       //initOutlets();
                }
 
                // Init all alarms
                initAlarms();
 
+               System.out.println("DEBUG: Initialized all devices! Now starting detection loop!");
+
                // Run the main loop that will keep checking the sensors and cameras periodically
                while (true) {
 
index 46e189daf8794b925516ff0c902533aff6702ab4..b842e028298d7be894831b2114b827c0ab4abf9a 100644 (file)
@@ -101,7 +101,7 @@ multipurpose:
 PHONY += waterleak
 waterleak:
        $(JAVAC) $(JFLAGS) WaterLeakSensor/*.java
-       cp MotionSensor/WaterLeakSensor.config $(BIN_DIR)/iotcode/WaterLeakSensor
+       cp WaterLeakSensor/WaterLeakSensor.config $(BIN_DIR)/iotcode/WaterLeakSensor
        cd $(BIN_DIR)/iotcode/WaterLeakSensor; $(JAR) $(JARFLAGS) WaterLeakSensor.jar ../../iotcode/WaterLeakSensor/*.class ../../iotcode/interfaces/SmartthingsSensor*.class ../../iotcode/interfaces/Camera*.class ../../IrrigationController/MotionDetection*.class
 
 .PHONY: $(PHONY)
index 6520de0ffaa7311366fa2dcdb0be6dc01db8492c..23e31b59ca8d8a3d4a94a24d5220a7d92e82b3ab 100644 (file)
@@ -42,12 +42,14 @@ public class MotionSensor implements IoTZigbeeCallback, SmartthingsSensor {
 
        private int sensorId = 0;
 
-       @config private IoTSet<IoTDeviceAddress> devUdpAddress;
-       @config private IoTSet<IoTZigbeeAddress> devZigbeeAddress;
-
-       public MotionSensor(IoTSet<IoTDeviceAddress> dSet, IoTSet<IoTZigbeeAddress> zigSet) {
-               //devUdpAddress = dSet;
-               //devZigbeeAddress = zigSet;
+       @config private IoTSet<IoTDeviceAddress> motionSensorUdpAddress;
+       @config private IoTSet<IoTZigbeeAddress> motionSensorZigbeeAddress;
+
+       //public MotionSensor(IoTSet<IoTDeviceAddress> dSet, IoTSet<IoTZigbeeAddress> zigSet) {
+               //motionSensorUdpAddress = dSet;
+               //motionSensorZigbeeAddress = zigSet;
+       //}
+       public MotionSensor() {
        }
 
        public void init() {
@@ -59,20 +61,20 @@ public class MotionSensor implements IoTZigbeeCallback, SmartthingsSensor {
                didAlreadyClose.set(false);
 
                try {
-                       Iterator itrUdp = devUdpAddress.iterator();
-                       Iterator itrZig = devZigbeeAddress.iterator();
+                       Iterator itrUdp = motionSensorUdpAddress.iterator();
+                       Iterator itrZig = motionSensorZigbeeAddress.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();
+                       Iterator itrDebugUdp = motionSensorUdpAddress.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();
+                       Iterator itrDebugZig = motionSensorZigbeeAddress.iterator();
                        IoTZigbeeAddress iotzbaddDebug = (IoTZigbeeAddress)itrDebugZig.next();
                        System.out.println("Zigbee address: " + iotzbaddDebug.getAddress());
 
index d2123e3fda6eaaa26ef471e288eef1b7e97b6f14..ae1aaf371759ec0ee1b654394778da93a017bbae 100644 (file)
@@ -42,12 +42,14 @@ public class MultipurposeSensor implements IoTZigbeeCallback, SmartthingsSensor
 
        private int sensorId = 0;
 
-       @config private IoTSet<IoTDeviceAddress> devUdpAddress;
-       @config private IoTSet<IoTZigbeeAddress> devZigbeeAddress;
-
-       public MultipurposeSensor(IoTSet<IoTDeviceAddress> dSet, IoTSet<IoTZigbeeAddress> zigSet) {
-               //devUdpAddress = dSet;
-               //devZigbeeAddress = zigSet;
+       @config private IoTSet<IoTDeviceAddress> multipurposeSensorUdpAddress;
+       @config private IoTSet<IoTZigbeeAddress> multipurposeSensorZigbeeAddress;
+
+       //public MultipurposeSensor(IoTSet<IoTDeviceAddress> dSet, IoTSet<IoTZigbeeAddress> zigSet) {
+               //multipurposeSensorUdpAddress = dSet;
+               //multipurposeSensorZigbeeAddress = zigSet;
+       //}
+       public MultipurposeSensor() {
        }
 
        public void init() {
@@ -59,20 +61,20 @@ public class MultipurposeSensor implements IoTZigbeeCallback, SmartthingsSensor
                didAlreadyClose.set(false);
 
                try {
-                       Iterator itrUdp = devUdpAddress.iterator();
-                       Iterator itrZig = devZigbeeAddress.iterator();
+                       Iterator itrUdp = multipurposeSensorUdpAddress.iterator();
+                       Iterator itrZig = multipurposeSensorZigbeeAddress.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();
+                       Iterator itrDebugUdp = multipurposeSensorUdpAddress.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();
+                       Iterator itrDebugZig = multipurposeSensorZigbeeAddress.iterator();
                        IoTZigbeeAddress iotzbaddDebug = (IoTZigbeeAddress)itrDebugZig.next();
                        System.out.println("Zigbee address: " + iotzbaddDebug.getAddress());
 
index ca8585645d65ebd7006156a9fae8f5b50aaa910c..7a28cbe8c6a6df49de5a4d7dfc644e93d1cdf0bf 100644 (file)
@@ -42,12 +42,14 @@ public class WaterLeakSensor implements IoTZigbeeCallback, SmartthingsSensor {
 
        private int sensorId = 0;
 
-       @config private IoTSet<IoTDeviceAddress> devUdpAddress;
-       @config private IoTSet<IoTZigbeeAddress> devZigbeeAddress;
-
-       public WaterLeakSensor(IoTSet<IoTDeviceAddress> dSet, IoTSet<IoTZigbeeAddress> zigSet) {
-               //devUdpAddress = dSet;
-               //devZigbeeAddress = zigSet;
+       @config private IoTSet<IoTDeviceAddress> waterleakSensorUdpAddress;
+       @config private IoTSet<IoTZigbeeAddress> waterleakSensorZigbeeAddress;
+
+       //public WaterLeakSensor(IoTSet<IoTDeviceAddress> dSet, IoTSet<IoTZigbeeAddress> zigSet) {
+               //waterleakSensorUdpAddress = dSet;
+               //waterleakSensorZigbeeAddress = zigSet;
+       //}
+       public WaterLeakSensor() {
        }
 
        public void init() {
@@ -59,20 +61,20 @@ public class WaterLeakSensor implements IoTZigbeeCallback, SmartthingsSensor {
                didAlreadyClose.set(false);
 
                try {
-                       Iterator itrUdp = devUdpAddress.iterator();
-                       Iterator itrZig = devZigbeeAddress.iterator();
+                       Iterator itrUdp = waterleakSensorUdpAddress.iterator();
+                       Iterator itrZig = waterleakSensorZigbeeAddress.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();
+                       Iterator itrDebugUdp = waterleakSensorUdpAddress.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();
+                       Iterator itrDebugZig = waterleakSensorZigbeeAddress.iterator();
                        IoTZigbeeAddress iotzbaddDebug = (IoTZigbeeAddress)itrDebugZig.next();
                        System.out.println("Zigbee address: " + iotzbaddDebug.getAddress());
 
index 31c1d8aa3f39db6d82506235ef710bc177979976..4a931d0727ee549afc042c4a81ce502735b8c9d1 100644 (file)
@@ -300,6 +300,7 @@ public class IoTZigbee {
 
                                        }
 */
+
                                        // made by changwoo
                                        if (packetData.get("type").equals("zcl_zone_status_change_notification")){
                                                int packetId = Integer.parseInt(packetData.get("packet_id"), 16);
index 8db9a9114503bd397c1b13ef25207fcaabadd50c..ba8af4a43fbe689eff8afcf160d892801cd450cb 100644 (file)
@@ -34,8 +34,8 @@ public abstract class IoTSocket {
        /**
         * Class Constant
         */
-       //protected static int BUFFSIZE = 128000;       // how many bytes our incoming buffer can hold (original)
-       protected static int BUFFSIZE = 8388608;        // 8388608 = 2^23 bytes of memory (8MB) - this is required by our IHome speaker driver
+       protected static int BUFFSIZE = 128000; // how many bytes our incoming buffer can hold (original)
+       //protected static int BUFFSIZE = 8388608;      // 8388608 = 2^23 bytes of memory (8MB) - this is required by our IHome speaker driver
        protected static int MSG_LEN_SIZE = 4;  // send length in the size of integer (4 bytes)
 
        /**
index 31f82e91793c8fc401e6992eaf4364b8c90e73e5..1f7e697e43bc418ce97ff9cbf5956def9a94e14f 100644 (file)
@@ -84,6 +84,8 @@ public class IoTMaster {
        private static String STR_ZB_GATEWAY_PORT;
        private static String STR_ZB_IOTMASTER_PORT;
        private static String STR_NUM_CALLBACK_PORTS;
+       private static String STR_JVM_INIT_HEAP_SIZE;
+       private static String STR_JVM_MAX_HEAP_SIZE;
        private static boolean BOOL_VERBOSE;
 
        /**
@@ -156,6 +158,8 @@ public class IoTMaster {
                STR_ZB_GATEWAY_PORT = null;
                STR_ZB_IOTMASTER_PORT = null;
                STR_NUM_CALLBACK_PORTS = null;
+               STR_JVM_INIT_HEAP_SIZE = null;
+               STR_JVM_MAX_HEAP_SIZE = null;
                BOOL_VERBOSE = false;
        }
 
@@ -211,6 +215,8 @@ public class IoTMaster {
                STR_ZB_GATEWAY_PORT = prop.getProperty("ZIGBEE_GATEWAY_PORT");
                STR_ZB_IOTMASTER_PORT = prop.getProperty("ZIGBEE_IOTMASTER_PORT");
                STR_NUM_CALLBACK_PORTS = prop.getProperty("NUMBER_CALLBACK_PORTS");
+               STR_JVM_INIT_HEAP_SIZE = prop.getProperty("JVM_INIT_HEAP_SIZE");
+               STR_JVM_MAX_HEAP_SIZE = prop.getProperty("JVM_MAX_HEAP_SIZE");
                if(prop.getProperty("VERBOSE").equals(STR_YES)) {
                        BOOL_VERBOSE = true;
                }
@@ -231,6 +237,8 @@ public class IoTMaster {
                RuntimeOutput.print("STR_ZB_GATEWAY_PORT=" + STR_ZB_GATEWAY_PORT, BOOL_VERBOSE);
                RuntimeOutput.print("STR_ZB_IOTMASTER_PORT=" + STR_ZB_IOTMASTER_PORT, BOOL_VERBOSE);
                RuntimeOutput.print("STR_NUM_CALLBACK_PORTS=" + STR_NUM_CALLBACK_PORTS, BOOL_VERBOSE);
+               RuntimeOutput.print("STR_JVM_INIT_HEAP_SIZE=" + STR_JVM_INIT_HEAP_SIZE, BOOL_VERBOSE);
+               RuntimeOutput.print("STR_JVM_MAX_HEAP_SIZE=" + STR_JVM_MAX_HEAP_SIZE, BOOL_VERBOSE);
                RuntimeOutput.print("BOOL_VERBOSE=" + BOOL_VERBOSE, BOOL_VERBOSE);
                RuntimeOutput.print("IoTMaster: Information extracted successfully!", BOOL_VERBOSE);
        }
@@ -333,7 +341,7 @@ public class IoTMaster {
         * @params  inStream                  ObjectOutputStream communication
         * @return  void
         */
-       private void instrumentIoTSetDevice(String strFieldIdentifier, String strFieldName, String strIoTSlaveObjectHostAdd,
+       private void instrumentIoTSetDevice(String strFieldIdentifier, String strObjName, String strFieldName, String strIoTSlaveObjectHostAdd,
                ObjectInputStream inStream, ObjectOutputStream outStream) 
                        throws IOException, ClassNotFoundException, InterruptedException {
 
@@ -349,10 +357,13 @@ public class IoTMaster {
                        arrFieldValues = listObject.get(iRow);
                        // Get device address - if 00:00:00:00:00:00 that means it needs the driver object address (self)
                        String strDeviceAddress = null;
+                       String strDeviceAddressKey = null;
                        if (arrFieldValues[0].equals(STR_SELF_MAC_ADD)) {
                                strDeviceAddress = strIoTSlaveObjectHostAdd;
+                               strDeviceAddressKey = strObjName + "-" + strIoTSlaveObjectHostAdd;
                        } else {
                                strDeviceAddress = routerConfig.getIPFromMACAddress((String) arrFieldValues[0]);
+                               strDeviceAddressKey = strObjName + "-" + strDeviceAddress;
                        }
                        int iDestDeviceDriverPort = (int) arrFieldValues[1];
                        String strProtocol = (String) arrFieldValues[2];
@@ -364,18 +375,24 @@ public class IoTMaster {
                                bDstPortWildCard = (boolean) arrFieldValues[4];
                        }
                        // Add the port connection into communication handler - if it's not assigned yet
-                       if (commHan.getComPort(strDeviceAddress) == null) {
-                               commHan.addPortConnection(strIoTSlaveObjectHostAdd, strDeviceAddress);
+                       if (commHan.getComPort(strDeviceAddressKey) == null) {
+                               commHan.addPortConnection(strIoTSlaveObjectHostAdd, strDeviceAddressKey);
                        }
+
+                       // TODO: DEBUG!!!
+                       System.out.println("\n\n DEBUG: InstrumentSetDevice: Object Name: " + strObjName);
+                       System.out.println("DEBUG: InstrumentSetDevice: Port number: " + commHan.getComPort(strDeviceAddressKey));
+                       System.out.println("DEBUG: InstrumentSetDevice: Device address: " + strDeviceAddressKey + "\n\n");
+
                        // Send address one by one
                        Message msgGetIoTSetObj = null;
                        if (bDstPortWildCard) {
-                               String strUniqueDev = strDeviceAddress + ":" + iRow;
+                               String strUniqueDev = strDeviceAddressKey + ":" + iRow;
                                msgGetIoTSetObj = new MessageGetDeviceObject(IoTCommCode.GET_DEVICE_IOTSET_OBJECT,
                                        strDeviceAddress, commHan.getAdditionalPort(strUniqueDev), iDestDeviceDriverPort, bSrcPortWildCard, bDstPortWildCard);
                        } else
                                msgGetIoTSetObj = new MessageGetDeviceObject(IoTCommCode.GET_DEVICE_IOTSET_OBJECT,
-                                       strDeviceAddress, commHan.getComPort(strDeviceAddress), iDestDeviceDriverPort, bSrcPortWildCard, bDstPortWildCard);
+                                       strDeviceAddress, commHan.getComPort(strDeviceAddressKey), iDestDeviceDriverPort, bSrcPortWildCard, bDstPortWildCard);
                        commMasterToSlave(msgGetIoTSetObj, "Get IoTSet objects!", inStream, outStream);
                }
                // Reinitialize IoTSet on device object
@@ -394,7 +411,7 @@ public class IoTMaster {
         * @params  inStream                  ObjectOutputStream communication
         * @return  void
         */
-       private void instrumentIoTSetZBDevice(Map.Entry<String,Object> map, String strFieldName, String strIoTSlaveObjectHostAdd,
+       private void instrumentIoTSetZBDevice(Map.Entry<String,Object> map, String strObjName, String strFieldName, String strIoTSlaveObjectHostAdd,
                ObjectInputStream inStream, ObjectOutputStream outStream) 
                        throws IOException, ClassNotFoundException, InterruptedException {
 
@@ -405,24 +422,31 @@ public class IoTMaster {
                commMasterToSlave(msgCrtIoTSet, "Create new IoTSet for IoTZigbeeAddress!", inStream, outStream);
                // Prepare ZigbeeConfig
                String strZigbeeGWAddress = routerConfig.getIPFromMACAddress(STR_ZB_GATEWAY_ADDRESS);
+               String strZigbeeGWAddressKey = strObjName + "-" + strZigbeeGWAddress;
                int iZigbeeGWPort = Integer.parseInt(STR_ZB_GATEWAY_PORT);
                int iZigbeeIoTMasterPort = Integer.parseInt(STR_ZB_IOTMASTER_PORT);
                commHan.addDevicePort(iZigbeeIoTMasterPort);
                ZigbeeConfig zbConfig = new ZigbeeConfig(strZigbeeGWAddress, iZigbeeGWPort, iZigbeeIoTMasterPort, 
                        BOOL_VERBOSE);
                // Add the port connection into communication handler - if it's not assigned yet
-               if (commHan.getComPort(strZigbeeGWAddress) == null) {
-                       commHan.addPortConnection(strIoTSlaveObjectHostAdd, strZigbeeGWAddress);
+               if (commHan.getComPort(strZigbeeGWAddressKey) == null) {
+                       commHan.addPortConnection(strIoTSlaveObjectHostAdd, strZigbeeGWAddressKey);
                }               
                int iRows = setInstrumenter.numberOfRows();
                RuntimeOutput.print("IoTMaster: Number of rows for IoTZigbeeAddress: " + iRows, BOOL_VERBOSE);
+
+               // TODO: DEBUG!!!
+               System.out.println("\n\n DEBUG: InstrumentZigbeeDevice: Object Name: " + strObjName);
+               System.out.println("DEBUG: InstrumentZigbeeDevice: Port number: " + commHan.getComPort(strZigbeeGWAddressKey));
+               System.out.println("DEBUG: InstrumentZigbeeDevice: Device address: " + strZigbeeGWAddress + "\n\n");
+
                // Transfer the address
                for(int iRow=0; iRow<iRows; iRow++) {
                        arrFieldValues = setInstrumenter.fieldValues(iRow);
                        // Get device address
                        String strZBDevAddress = (String) arrFieldValues[0];
                        // Send policy to Zigbee gateway - TODO: Need to clear policy first?
-                       zbConfig.setPolicy(strIoTSlaveObjectHostAdd, commHan.getComPort(strZigbeeGWAddress), strZBDevAddress);
+                       zbConfig.setPolicy(strIoTSlaveObjectHostAdd, commHan.getComPort(strZigbeeGWAddressKey), strZBDevAddress);
                        // Send address one by one
                        Message msgGetIoTSetZBObj = new MessageGetSimpleDeviceObject(IoTCommCode.GET_ZB_DEV_IOTSET_OBJECT,
                                strZBDevAddress);
@@ -430,8 +454,7 @@ public class IoTMaster {
                }
                zbConfig.closeConnection();
                // Reinitialize IoTSet on device object
-               commMasterToSlave(new MessageSimple(IoTCommCode.REINITIALIZE_IOTSET_FIELD),
-                                                                                       "Reinitialize IoTSet fields!", inStream, outStream);
+               commMasterToSlave(new MessageSimple(IoTCommCode.REINITIALIZE_IOTSET_FIELD), "Reinitialize IoTSet fields!", inStream, outStream);
        }
 
        
@@ -591,37 +614,44 @@ public class IoTMaster {
                        objAddInitHand.addField(strFieldIdentifier, arrFieldValues);    // Save this for object instantiation
                        // Get device address - if 00:00:00:00:00:00 that means it needs the driver object address (self)
                        String strDeviceAddress = null;
+                       String strDeviceAddressKey = null;
                        if (arrFieldValues[0].equals(STR_SELF_MAC_ADD)) {
                                strDeviceAddress = strIoTSlaveObjectHostAdd;
-                       } else {
+                               strDeviceAddressKey = strObjName + "-" + strIoTSlaveObjectHostAdd;
+                       } else {        // Concatenate object name and IP address to give unique key - for a case where there is one device for multiple drivers
                                strDeviceAddress = routerConfig.getIPFromMACAddress((String) arrFieldValues[0]);
+                               strDeviceAddressKey = strObjName + "-" + strDeviceAddress;
                        }
                        int iDestDeviceDriverPort = (int) arrFieldValues[1];
                        String strProtocol = (String) arrFieldValues[2];
                        // Add the port connection into communication handler - if it's not assigned yet
-                       if (commHan.getComPort(strDeviceAddress) == null) {
-                               commHan.addPortConnection(strIoTSlaveObjectHostAdd, strDeviceAddress);
-                       }
+                       if (commHan.getComPort(strDeviceAddressKey) == null)
+                               commHan.addPortConnection(strIoTSlaveObjectHostAdd, strDeviceAddressKey);
                        boolean bDstPortWildCard = false;
                        // Recognize this and allocate different ports for it
                        if (arrFieldValues.length > 3) {
                                bDstPortWildCard = (boolean) arrFieldValues[4];
                                if (bDstPortWildCard) { // This needs a unique source port
-                                       String strUniqueDev = strDeviceAddress + ":" + iRow;
+                                       String strUniqueDev = strDeviceAddressKey + ":" + iRow; 
                                        commHan.addAdditionalPort(strUniqueDev);
                                }
                        }
+
+                       // TODO: DEBUG!!!
+                       System.out.println("\n\n DEBUG: InstrumentPolicySetDevice: Object Name: " + strObjName);
+                       System.out.println("DEBUG: InstrumentPolicySetDevice: Port number: " + commHan.getComPort(strDeviceAddressKey));
+                       System.out.println("DEBUG: InstrumentPolicySetDevice: Device address: " + strDeviceAddressKey + "\n\n");
+
+
                        // Send routing policy to router for device drivers and devices
                        // ROUTING POLICY: RMI communication - RMI registry and stub ports
                        if((iDestDeviceDriverPort == -1) && (!strProtocol.equals(STR_NO_PROTOCOL))) {
                                // Port number -1 means that we don't set the policy strictly to port number level
                                // "nopro" = no protocol specified for just TCP or just UDP (can be both used as well)
                                // ROUTING POLICY: Device driver and device
-                               routerConfig.configureRouterMainPolicies(STR_ROUTER_ADD, strIoTSlaveObjectHostAdd, strDeviceAddress,
-                                       strProtocol);
+                               routerConfig.configureRouterMainPolicies(STR_ROUTER_ADD, strIoTSlaveObjectHostAdd, strDeviceAddress, strProtocol);
                                // ROUTING POLICY: Send to the compute node where the device driver is
-                               routerConfig.configureHostMainPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd,
-                                       strDeviceAddress, strProtocol);
+                               routerConfig.configureHostMainPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd, strDeviceAddress, strProtocol);
                        } else if((iDestDeviceDriverPort == -1) && (strProtocol.equals(STR_NO_PROTOCOL))) {
                                routerConfig.configureRouterMainPolicies(STR_ROUTER_ADD, strIoTSlaveObjectHostAdd, strDeviceAddress);
                                routerConfig.configureHostMainPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd, strDeviceAddress);
@@ -629,19 +659,17 @@ public class IoTMaster {
                                // This is a TCP protocol that connects, e.g. a phone to our runtime system
                                // that provides a gateway access (accessed through destination port number)
                                commHan.addDevicePort(iDestDeviceDriverPort);
-                               routerConfig.configureRouterMainPolicies(STR_ROUTER_ADD, strIoTSlaveObjectHostAdd, strDeviceAddress,
-                                       STR_TCP_PROTOCOL, iDestDeviceDriverPort);
-                               routerConfig.configureHostMainPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd, strDeviceAddress,
-                                       STR_TCP_PROTOCOL, iDestDeviceDriverPort);
+                               routerConfig.configureRouterMainPolicies(STR_ROUTER_ADD, strIoTSlaveObjectHostAdd, strDeviceAddress, STR_TCP_PROTOCOL, iDestDeviceDriverPort);
+                               routerConfig.configureHostMainPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd, strDeviceAddress, STR_TCP_PROTOCOL, iDestDeviceDriverPort);
                                routerConfig.configureRouterHTTPPolicies(STR_ROUTER_ADD, strIoTSlaveObjectHostAdd, strDeviceAddress);
                                routerConfig.configureHostHTTPPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd, strDeviceAddress);
                        } else {
                                // Other port numbers...
                                commHan.addDevicePort(iDestDeviceDriverPort);
-                               routerConfig.configureRouterMainPolicies(STR_ROUTER_ADD, strIoTSlaveObjectHostAdd, strDeviceAddress,
-                                       strProtocol, commHan.getComPort(strDeviceAddress), iDestDeviceDriverPort);
-                               routerConfig.configureHostMainPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd, strDeviceAddress,
-                                       strProtocol, commHan.getComPort(strDeviceAddress), iDestDeviceDriverPort);
+                               routerConfig.configureRouterMainPolicies(STR_ROUTER_ADD, strIoTSlaveObjectHostAdd, strDeviceAddress, strProtocol, commHan.getComPort(strDeviceAddressKey), 
+                                       iDestDeviceDriverPort);
+                               routerConfig.configureHostMainPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd, strDeviceAddress, strProtocol, commHan.getComPort(strDeviceAddressKey), 
+                                       iDestDeviceDriverPort);
                        }
                }
        }
@@ -824,12 +852,12 @@ public class IoTMaster {
                                if(setInstrumenter.getObjTableName().equals(STR_IOT_DEV_ADD_CLS)) { 
                                // Instrument the normal IoTDeviceAddress
                                        synchronized(this) {
-                                               instrumentIoTSetDevice(strFieldIdentifier, strFieldName, strIoTSlaveObjectHostAdd, inStream, outStream);
+                                               instrumentIoTSetDevice(strFieldIdentifier, strObjName, strFieldName, strIoTSlaveObjectHostAdd, inStream, outStream);
                                        }
                                } else if(setInstrumenter.getObjTableName().equals(STR_IOT_ZB_ADD_CLS)) { 
                                // Instrument the IoTZigbeeAddress - special feature for Zigbee device support
                                        synchronized(this) {
-                                               instrumentIoTSetZBDevice(map, strFieldName, strIoTSlaveObjectHostAdd, inStream, outStream);
+                                               instrumentIoTSetZBDevice(map, strObjName, strFieldName, strIoTSlaveObjectHostAdd, inStream, outStream);
                                        }
                                } else if(setInstrumenter.getObjTableName().equals(STR_IOT_ADD_CLS)) { 
                                // Instrument the IoTAddress
@@ -1185,7 +1213,8 @@ public class IoTMaster {
 
                                // Construct ssh command line and create a controller thread for e.g. AcmeProximity
                                String strSSHCommand = STR_SSH_USERNAME + strIoTSlaveControllerHostAdd + " cd " +
-                                       STR_RUNTIME_DIR + " sudo java " + STR_CLS_PATH + " " +
+                                       STR_RUNTIME_DIR + " sudo java " + STR_JVM_INIT_HEAP_SIZE + " " + 
+                                       STR_JVM_MAX_HEAP_SIZE + " " + STR_CLS_PATH + " " +
                                        STR_RMI_PATH + " " + STR_IOT_SLAVE_CLS + " " + strIoTMasterHostAdd + " " +
                                        commHan.getComPort(strObjControllerName) + " " +
                                        commHan.getRMIRegPort(strObjControllerName) + " " +
index a7729188d89fc7c685581e9b774e257278e8bfde..b4f2a3fcd50bc7f84a7cfd971b767c4b4b9ff36b 100644 (file)
@@ -287,7 +287,28 @@ public class IoTZigbee {
                                } else {
                                        IoTZigbeeMessage callbackMessage = null;
 
-                                       if (packetData.get("type").equals("zcl_read_attributes_response")) {
+                                       //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);
index d98aa4d016d219dd320221a9c8a9c349534bbbb2..79e16e8e7364eb7a095416b0a2e29d23a6357122 100644 (file)
@@ -30,3 +30,9 @@ VERBOSE=Yes
 #Number of callback ports
 NUMBER_CALLBACK_PORTS=1
 
+#JVM heap size - can go out of memory if a IoTSlave needs to handle a lot of objects
+#E.g. JVM_INIT_HEAP_SIZE=-Xms64m, JVM_MAX_HEAP_SIZE=-Xmx64m (64 MB of heap)
+#Made empty for now as it needs fine-tuning
+JVM_INIT_HEAP_SIZE=
+JVM_MAX_HEAP_SIZE=
+
diff --git a/localconfig/mysql/alm_Addresses.config b/localconfig/mysql/alm_Addresses.config
new file mode 100644 (file)
index 0000000..2564492
--- /dev/null
@@ -0,0 +1,5 @@
+SELECT * FROM
+IoTDeviceAddress
+WHERE
+TYPE='EspAlarmAdd'
+;
index 5798c171313152480bc35c4628c6ee76e3206fbd..083ca82d508383ba422b92ece18f86dac7b2b193 100644 (file)
@@ -1,5 +1,3 @@
 SELECT * FROM
 CameraSmart
-WHERE
-ID='CM1'
 ;
diff --git a/localconfig/mysql/motionSensorUdpAddress.config b/localconfig/mysql/motionSensorUdpAddress.config
new file mode 100644 (file)
index 0000000..31f215b
--- /dev/null
@@ -0,0 +1,5 @@
+SELECT * FROM
+IoTDeviceAddress
+WHERE
+TYPE='MotionSensorAdd'
+;
diff --git a/localconfig/mysql/motionSensorZigbeeAddress.config b/localconfig/mysql/motionSensorZigbeeAddress.config
new file mode 100644 (file)
index 0000000..8b66bb2
--- /dev/null
@@ -0,0 +1,5 @@
+SELECT * FROM
+IoTZigbeeAddress
+WHERE
+TYPE='MotionSensorZBAdd'
+;
diff --git a/localconfig/mysql/multipurposeSensorUdpAddress.config b/localconfig/mysql/multipurposeSensorUdpAddress.config
new file mode 100644 (file)
index 0000000..5e97f18
--- /dev/null
@@ -0,0 +1,5 @@
+SELECT * FROM
+IoTDeviceAddress
+WHERE
+TYPE='MultipurposeSensorAdd'
+;
diff --git a/localconfig/mysql/multipurposeSensorZigbeeAddress.config b/localconfig/mysql/multipurposeSensorZigbeeAddress.config
new file mode 100644 (file)
index 0000000..212b248
--- /dev/null
@@ -0,0 +1,5 @@
+SELECT * FROM
+IoTZigbeeAddress
+WHERE
+TYPE='MultipurposeSensorZBAdd'
+;
diff --git a/localconfig/mysql/waterleakSensorUdpAddress.config b/localconfig/mysql/waterleakSensorUdpAddress.config
new file mode 100644 (file)
index 0000000..95437ce
--- /dev/null
@@ -0,0 +1,5 @@
+SELECT * FROM
+IoTDeviceAddress
+WHERE
+TYPE='WaterLeakSensorAdd'
+;
diff --git a/localconfig/mysql/waterleakSensorZigbeeAddress.config b/localconfig/mysql/waterleakSensorZigbeeAddress.config
new file mode 100644 (file)
index 0000000..70d216c
--- /dev/null
@@ -0,0 +1,5 @@
+SELECT * FROM
+IoTZigbeeAddress
+WHERE
+TYPE='WaterLeakSensorZBAdd'
+;