Re-testing Blossom driver and enabling driver with sudo to be able to use system...
authorrtrimana <rtrimana@uci.edu>
Mon, 15 Jan 2018 23:54:59 +0000 (15:54 -0800)
committerrtrimana <rtrimana@uci.edu>
Mon, 15 Jan 2018 23:54:59 +0000 (15:54 -0800)
benchmarks/drivers/Java/BlossomSprinkler/BlossomSprinkler.java
iotjava/iotruntime/master/IoTMaster.java

index cf04828..f8100e1 100644 (file)
@@ -14,9 +14,8 @@ import java.util.Calendar;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.concurrent.atomic.AtomicBoolean;
-
-// import java.util.HashSet;
-// import java.util.Set;
+import java.util.Set;
+import java.util.HashSet;
 
 // IoT Packages
 import iotruntime.IoTTCP;
@@ -40,7 +39,8 @@ public class BlossomSprinkler implements Sprinkler {
     /*******************************************************************************************************************************************
     **  Constants
     *******************************************************************************************************************************************/
-    public static final int NUMBER_OF_ZONES = 12;
+    //public static final int NUMBER_OF_ZONES = 12;
+       public static final int NUMBER_OF_ZONES = 1;
 
     @config IoTSet<IoTDeviceAddress> blossomSprAddressSet;
     @config IoTSet<IoTDeviceAddress> localAddressSet;
@@ -61,6 +61,11 @@ public class BlossomSprinkler implements Sprinkler {
     private Thread workerThread = null;
     private Thread httpMonitorThread = null;
 
+    public BlossomSprinkler(String _channelId, IoTSet<IoTDeviceAddress> _blossomSprAddressSet, IoTSet<IoTDeviceAddress> _localAddressSet) {
+        this(_channelId);
+               blossomSprAddressSet = _blossomSprAddressSet;
+               localAddressSet = _localAddressSet;             
+    }
 
     public BlossomSprinkler(String _channelId) {
         channelId = _channelId;
@@ -195,13 +200,16 @@ public class BlossomSprinkler implements Sprinkler {
     *******************************************************************************************************************************************/
 
     private void workerMethod() {
-        while (didEnd.get() == false) {
-
+               System.out.println("Get into worker!");
+               while (didEnd.get() == false) {
+                       //System.out.println("While not end");
             try {
                 zoneStateMutex.acquire();
                 for (ZoneState z : zoneStates) {
+                                       //System.out.println("Iterating on zone: " + z.zoneNumber);
                     if (z.onOffState) {
-
+                                               //System.out.println("Turning on zone: " + z.zoneNumber);
+                                               //System.out.println("Duration: " + z.duration);
                         // if on and time has expired then turn off
                         if (z.duration == 0) {
 
@@ -252,9 +260,6 @@ public class BlossomSprinkler implements Sprinkler {
                 BufferedReader tcpIn = new BufferedReader(new InputStreamReader(recSock.getInputStream()));
                 PrintWriter tcpOut = new PrintWriter(recSock.getOutputStream());
 
-
-
-
                 System.out.println("Waiting For Data");
                 // wait for data to be ready
                 while (!tcpIn.ready()) {
@@ -270,12 +275,11 @@ public class BlossomSprinkler implements Sprinkler {
                     sList.add(s);
                 }
 
-                // System.out.println("---------------------------------------------------------------------");
-                // System.out.println("---------------------------------------------------------------------");
-                // for (String s : sList) {
-                //     System.out.println(s);
-                // }
-
+                System.out.println("---------------------------------------------------------------------");
+                System.out.println("---------------------------------------------------------------------");
+                for (String s : sList) {
+                    System.out.println(s);
+                }
 
                 // get first line and check that it is a GET request
                 String line = sList.get(0);
@@ -360,6 +364,7 @@ public class BlossomSprinkler implements Sprinkler {
 
             tcpOut.print(postMessage);
             tcpOut.flush();
+                       System.out.println("Sent POST message: " + postMessage);
 
             // wait for data
             while (!tcpIn.ready()) {
@@ -431,6 +436,27 @@ public class BlossomSprinkler implements Sprinkler {
             e.printStackTrace();
         }
     }
+       
+       /*public static void main(String[] args) throws Exception {
+
+               System.out.println("Executing main function!");
+               IoTDeviceAddress iotDevAdd1 = new IoTDeviceAddress("192.168.0.129", 10009, 80, false, false);
+               IoTDeviceAddress iotDevAdd2 = new IoTDeviceAddress("192.168.0.84", 10010, 80, false, false);
+               Set<IoTDeviceAddress> setBlossom = new HashSet<IoTDeviceAddress>();
+               Set<IoTDeviceAddress> setLocal = new HashSet<IoTDeviceAddress>();
+               setBlossom.add(iotDevAdd1);
+               setLocal.add(iotDevAdd2);
+               IoTSet<IoTDeviceAddress> iotsetBlossom = new IoTSet<IoTDeviceAddress>(setBlossom);
+               IoTSet<IoTDeviceAddress> iotsetLocal = new IoTSet<IoTDeviceAddress>(setLocal);
+               String channelID = "1bd60b0c-2a99-4c83-8a7d-f97bd3f77a51";
+               BlossomSprinkler bs = new BlossomSprinkler(channelID, iotsetBlossom, iotsetLocal);
+               bs.init();
+               System.out.println("Finished init()");
+               Thread.sleep(30000);
+               bs.setZone(0, true, 120);
+               System.out.println("Finished setZone!");
+
+       }*/
 }
 
 
index 15948bf..03a3652 100644 (file)
@@ -954,7 +954,7 @@ public final class IoTMaster {
        private String getCmdJavaDriverIoTSlave(String strIoTMasterHostAdd, String strIoTSlaveObjectHostAdd, String strObjName) {
 
                // Create an Shell executable
-               String strJavaCommand = STR_SHELL_HEADER + "\nexec " + STR_JAVA_PATH + " " + STR_CLS_PATH + " " + STR_RMI_PATH + " " + 
+               String strJavaCommand = STR_SHELL_HEADER + "\nexec sudo " + STR_JAVA_PATH + " " + STR_CLS_PATH + " " + STR_RMI_PATH + " " + 
                        STR_RMI_HOSTNAME + strIoTSlaveObjectHostAdd + " " + STR_IOT_SLAVE_CLS + " " + strIoTMasterHostAdd + " " +
                        commHan.getComPort(strObjName) + " " + commHan.getRMIRegPort(strObjName) + " " +
                        commHan.getRMIStubPort(strObjName) + " > " + STR_LOG_FILE_PATH + strObjName + ".log &";