Committing changes in driver files for paper evaluation
authorrtrimana <rtrimana@uci.edu>
Thu, 1 Feb 2018 18:14:21 +0000 (10:14 -0800)
committerrtrimana <rtrimana@uci.edu>
Thu, 1 Feb 2018 18:14:21 +0000 (10:14 -0800)
benchmarks/Java/SmartLightsController/MotionDetection.java
benchmarks/Java/SmartLightsController/SmartLightsController.java
benchmarks/drivers/Java/AmcrestCamera/AmcrestCamera.java
benchmarks/drivers/Java/BlossomSprinkler/BlossomSprinkler.java
benchmarks/drivers/Java/IHome/IHome.java
benchmarks/drivers/Java/LifxLightBulb/LifxLightBulb.java

index 3c9567f..8491318 100644 (file)
@@ -260,7 +260,7 @@ class MotionDetection implements CameraCallback {
        public void newCameraFrameAvailable(byte[] latestFrame, long timeStamp) {
        //public void newCameraFrameAvailable(CameraSmart _camera) {
                BufferedImage img = null;
-
+               
                //byte[] newImg = _camera.getLatestFrame();
                try {
                        //InputStream in = new ByteArrayInputStream(_camera.getLatestFrame());
@@ -286,7 +286,7 @@ class MotionDetection implements CameraCallback {
                // timestamp from camera into timestamp buffer
                long dateLong = timeStamp;
                //long dateLong = _camera.getTimestamp();
-               //System.out.println("dateLong: " + dateLong + " - newImage size: " + newImg.length);
+               //System.out.println("DEBUG: New image at time: " + dateLong);
                possibleDate = new Date(dateLong);
 
                imageWriteLock.unlock();        // Never forget to unlock
index 4f1c915..9a9f805 100644 (file)
@@ -340,30 +340,34 @@ public class SmartLightsController {
                System.out.println("Initialized rooms!");
 
                // Setup the cameras, start them all and assign each one a motion detector
-/*             for (CameraSmart cam : cameras.values()) {
+               for (CameraSmart cam : cameras.values()) {
 
                        // 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);
+                       System.out.println("Motion detection initialized!");
 
                        // initialize the camera, might need to setup some stuff internally
                        cam.init();
+                       System.out.println("Initialized cam!");
 
                        // set the camera parameters.
                        cam.setFPS(CAMERA_FPS);
+                       System.out.println("Set FPS!");
                        cam.setResolution(Resolution.RES_VGA);
+                       System.out.println("Set RES_VGA!");
 
                        // camera will call the motion detector directly with data not this controller
                        cam.registerCallback(mo);
+                       System.out.println("Register callback!");
 
                        // Start the camera (example is start the HTTP stream if it is a network camera)
                        cam.start();
+                       System.out.println("Cam start!");
 
                        // Remember which motion detector is for what camera
                        camMotionDetect.put(cam, mo);
                }
                System.out.println("Initialized cameras!");
-*/
-               System.out.println("Skipped cameras!");
 
                //Initialize the light-bulbs, will turn off the bulb
                for (LightBulbSmart bulb : mainRoomLightBulbs.values()) {
@@ -373,12 +377,9 @@ public class SmartLightsController {
                        Thread.sleep(1000);
                }
                System.out.println("Initialized bulbs!");
-               
-               System.out.println("STOP here until we have 2 more working cameras!");
-               while (true) { }
 
                // Run the main loop that will keep check the bulbs and rooms periodically
-/*             while (true) {
+               while (true) {
 
                        // Run this code every <specified time>
                        long currentTimeSeconds = (new Date()).getTime() / 1000;
@@ -414,8 +415,7 @@ public class SmartLightsController {
 
                                }
                        }
-
-               }*/
+               }
        }
 }
 
index ffa92d0..f186be1 100644 (file)
@@ -26,6 +26,8 @@ import java.util.Arrays;
 import java.util.Date;
 import java.util.List;
 import java.util.ArrayList;
+import java.util.Set;
+import java.util.HashSet;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
@@ -89,6 +91,11 @@ public class AmcrestCamera implements Camera {
        // Will be filled with only 1 address.
        @config private IoTSet<IoTDeviceAddress> cam_addresses;
 
+       public AmcrestCamera(String _credentialUsername, String _credentialPassword, IoTSet<IoTDeviceAddress> _camAddresses) throws RemoteException {
+               credentialUsername = _credentialUsername;
+               credentialPassword = _credentialPassword;
+               cam_addresses = _camAddresses;
+       }
 
        public AmcrestCamera(String _credentialUsername, String _credentialPassword) throws RemoteException {
                credentialUsername = _credentialUsername;
@@ -148,11 +155,11 @@ public class AmcrestCamera implements Camera {
                                httpConnection.setDoInput(true);
                                httpConnection.setRequestProperty("Authorization", httpAuthCredentials);
                                httpConnection.connect();
-
+                               
                                InputStream is = httpConnection.getInputStream();
                                BufferedInputStream bis = new BufferedInputStream(is);
                                DataInputStream din = new DataInputStream(bis);
-
+                               
                                // wait for a response
                                try {
                                        Thread.sleep(1000);
@@ -174,7 +181,7 @@ public class AmcrestCamera implements Camera {
                                        return false;
                                        // e.printStackTrace();
                                }
-
+                               
                                httpConnection.disconnect();
                        } catch (IOException e) {
                                return false;
@@ -227,7 +234,6 @@ public class AmcrestCamera implements Camera {
                                camUrlString += "&Encode[0].MainFormat[0].Video.Height=480&Encode[0].MainFormat[0].Video.Width=640";
                        }
 
-
                        try {
 
                                String credsPreBase64 = credentialUsername + ":" + credentialPassword;
@@ -288,8 +294,6 @@ public class AmcrestCamera implements Camera {
                        return; // already started
                }
 
-
-
                doEnd.set(false);
 
                if (!streamConnect()) {
@@ -425,7 +429,8 @@ public class AmcrestCamera implements Camera {
                        String httpAuthCredentials = "Basic " + credsBase64;
 
                        IoTHTTP httpConnection = new IoTHTTP(deviceAddress);
-                       httpConnection.setURL("/cgi-bin/mjpg/video.cgi?");
+                       httpConnection.setURL("/cgi-bin/mjpg/video.cgi?channel=0&subtype=1");
+                       //httpConnection.setURL("/cgi-bin/mjpg/video.cgi?channel=0&subtype=1", credentialUsername, credentialPassword);
                        httpConnection.openConnection();
                        httpConnection.setDoInput(true);
                        httpConnection.setRequestProperty("Authorization", httpAuthCredentials);
@@ -518,7 +523,28 @@ public class AmcrestCamera implements Camera {
                }
 
        }
+       
+       /* TODO: Uncomment this part to do camera test
+       public static void main(String[] args) throws Exception {
+
+               System.out.println("Running AmcrestCamera!");
+
+               IoTDeviceAddress iotDevAdd = new IoTDeviceAddress(args[0], 12345, 80, false, false);
+               Set<IoTDeviceAddress> set = new HashSet<IoTDeviceAddress>();
+               set.add(iotDevAdd);
+               IoTSet<IoTDeviceAddress> iotset = new IoTSet<IoTDeviceAddress>(set);
+       
+               AmcrestCamera cam = new AmcrestCamera(args[1], args[2], iotset);
+               cam.init();
+               cam.setFPS(15);
+               cam.setResolution(Resolution.RES_VGA);
+               cam.start();
+
+           while (true) {
+
+           }
 
+       }*/
 }
 
 
index f8100e1..dc05c0d 100644 (file)
@@ -437,11 +437,14 @@ public class BlossomSprinkler implements Sprinkler {
         }
     }
        
-       /*public static void main(String[] args) throws Exception {
+       /* TODO: Uncomment this part to do sprinkler test
+       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);
+               //IoTDeviceAddress iotDevAdd1 = new IoTDeviceAddress("192.168.0.129", 10009, 80, false, false);
+               //IoTDeviceAddress iotDevAdd2 = new IoTDeviceAddress("192.168.0.84", 10010, 80, false, false);
+               IoTDeviceAddress iotDevAdd1 = new IoTDeviceAddress(args[0], 10009, 80, false, false);
+               IoTDeviceAddress iotDevAdd2 = new IoTDeviceAddress(args[1], 10010, 80, false, false);           
                Set<IoTDeviceAddress> setBlossom = new HashSet<IoTDeviceAddress>();
                Set<IoTDeviceAddress> setLocal = new HashSet<IoTDeviceAddress>();
                setBlossom.add(iotDevAdd1);
@@ -452,8 +455,7 @@ public class BlossomSprinkler implements Sprinkler {
                BlossomSprinkler bs = new BlossomSprinkler(channelID, iotsetBlossom, iotsetLocal);
                bs.init();
                System.out.println("Finished init()");
-               Thread.sleep(30000);
-               bs.setZone(0, true, 120);
+               bs.setZone(0, true, 60);
                System.out.println("Finished setZone!");
 
        }*/
index a9bcf0d..b7ba3b4 100644 (file)
@@ -31,6 +31,9 @@ import java.util.LinkedList;
 import java.util.concurrent.Semaphore;
 import java.util.concurrent.CopyOnWriteArrayList;
 
+// TODO: REMOVE THIS
+import java.util.Random;
+import java.io.File;
 
 public class IHome implements Speaker {
 
@@ -50,6 +53,8 @@ public class IHome implements Speaker {
     public static final long RTP_TIMESTAMP_INCREMENT_VALUE = 352L;
     public static final long SOURCE_ID = 1326796157;
     public static final long SEQUENCE_ID = 0x86b27741;
+       // TODO: REMOVE THIS
+       public static final String MUSIC_FILE_DIRECTORY = "./music/";   // file that the music files are in
 
     private IoTDeviceAddress tcpAddress = null;
     private IoTDeviceAddress myAddress = null;
@@ -102,6 +107,11 @@ public class IHome implements Speaker {
 
     @config private IoTSet<IoTDeviceAddress> speakerAddresses;
 
+       public IHome(IoTSet<IoTDeviceAddress> devAddresses) {
+        this();
+               speakerAddresses = devAddresses;
+    }
+       
     public IHome() {
         didInit.set(false);
         playbackAboutToStart.set(false);
@@ -311,12 +321,15 @@ public class IHome implements Speaker {
                         if (keyValue.length == 2) {
                             if (keyValue[0].equals("server_port")) {
                                 serverPort = Integer.parseInt(keyValue[1]);
+                                                               System.out.println("DEBUG: Server port: " + serverPort);
 
                             } else if (keyValue[0].equals("control_port")) {
                                 controlPort = Integer.parseInt(keyValue[1]);
+                                                               System.out.println("DEBUG: Control port: " + controlPort);
 
                             } else if (keyValue[0].equals("timing_port")) {
                                 timingPort = Integer.parseInt(keyValue[1]);
+                                                               System.out.println("DEBUG: Timing port: " + timingPort);
                             }
 
                         }
@@ -963,6 +976,110 @@ public class IHome implements Speaker {
         long nanotime = System.nanoTime();
         return nanotime;
     }
+       
+       
+       // TODO: REMOVE THIS
+       /**
+        * Prepare the speakers for a new song to start playing
+        */
+       private void prepareNextSong(IHome ih) {
+               System.out.println("Starting Music Prep");
+
+               System.out.println("Stopping all device playback");
+               // stop all devices that are still playing and clear their buffers
+               // they are about to end playback anyways
+               try {
+
+                       if (ih.getPlaybackState()) {
+                               ih.stopPlayback();
+                       }
+                       ih.clearData();
+               } catch (Exception e) {
+                       e.printStackTrace();
+               }
+
+               // get the music file names that are in the music files directory
+               File musicFolder = new File(MUSIC_FILE_DIRECTORY);
+               File[] audioFiles = musicFolder.listFiles();
+               List<String> audioFileNames = new ArrayList<String>();
+
+               // put all names in a list
+               for (int i = 0; i < audioFiles.length; i++) {
+                       if (audioFiles[i].isFile()) {
+                               try {
+                                       audioFileNames.add(audioFiles[i].getCanonicalPath());
+                               } catch (Exception ex) {
+                                       ex.printStackTrace();
+                               }
+                       }
+               }
+
+               // pick a random file to play
+               Random rand = new Random(System.nanoTime());
+               String audioFilename = audioFileNames.get(rand.nextInt(audioFileNames.size()));
+
+               System.out.println("Going to load audio file");
+               System.out.println(audioFilename);
+
+               // decode the mp3 file
+               System.out.println("Starting Decode");
+               MP3Decoder dec = new MP3Decoder(audioFilename);
+               List<short[]> dat = dec.getDecodedFrames();
+               System.out.println("Ending Decode");
+
+               // count the number of samples
+               int count = 0;
+               for (short[] d : dat) {
+                       count += d.length;
+               }
+
+               // make into a single large buffer for 1 large RMI call
+               short[] compressedArray = new short[count];
+               count = 0;
+               for (short[] d : dat) {
+                       for (short s : d) {
+                               compressedArray[count] = s;
+                               count++;
+                       }
+               }
+
+               System.out.println("Loading Speakers");
+               // send the new data to all the speakers
+               ih.loadData(compressedArray, 0, compressedArray.length);
+               System.out.println("Done loading a single speaker with data");
+               System.out.println("All Speakers done loading");
+               
+               // Attack the speaker
+               System.out.println("Trying to play the song on the speaker");
+               ih.startPlayback();
+               ih.setPosition(0);
+       }
+       
+       /* TODO: Uncomment this part to do speaker test
+       public static void main(String[] args) throws Exception {
+
+               System.out.println("Executing main function!");
+               //IoTDeviceAddress iotDevAdd1 = new IoTDeviceAddress("192.168.0.93", 60000, 1024, false, false);
+               //IoTDeviceAddress iotDevAdd2 = new IoTDeviceAddress("192.168.0.90", 60001, -1, false, false);
+               //IoTDeviceAddress iotDevAdd3 = new IoTDeviceAddress("192.168.0.93", 60010, -1, false, true);
+               //IoTDeviceAddress iotDevAdd4 = new IoTDeviceAddress("192.168.0.93", 60011, -1, false, true);
+               //IoTDeviceAddress iotDevAdd5 = new IoTDeviceAddress("192.168.0.93", 60012, -1, false, true);
+               IoTDeviceAddress iotDevAdd1 = new IoTDeviceAddress(args[0], 60000, 1024, false, false);
+               IoTDeviceAddress iotDevAdd2 = new IoTDeviceAddress(args[1], 60001, -1, false, false);
+               IoTDeviceAddress iotDevAdd3 = new IoTDeviceAddress(args[0], 60010, -1, false, true);
+               IoTDeviceAddress iotDevAdd4 = new IoTDeviceAddress(args[0], 60011, -1, false, true);
+               IoTDeviceAddress iotDevAdd5 = new IoTDeviceAddress(args[0], 60012, -1, false, true);
+               Set<IoTDeviceAddress> set = new HashSet<IoTDeviceAddress>();
+               set.add(iotDevAdd1);
+               set.add(iotDevAdd2);
+               set.add(iotDevAdd3);
+               set.add(iotDevAdd4);
+               set.add(iotDevAdd5);
+               IoTSet<IoTDeviceAddress> iotset = new IoTSet<IoTDeviceAddress>(set);
+               IHome ih = new IHome(iotset);
+               ih.init();
+               ih.prepareNextSong(ih);
+       }*/
 }
 
 
index c131bfa..909a90c 100644 (file)
@@ -102,12 +102,12 @@ public class LifxLightBulb implements LightBulb {
        /*public LifxLightBulb(IoTUDP udp, byte[] macAddress) {
                communicationSockect = udp;
                bulbMacAddress = macAddress;
-       }
+       }*/
 
        public LifxLightBulb(IoTSet<IoTDeviceAddress> _lb_addresses, String macAddress) {
                this(macAddress);
                lb_addresses = _lb_addresses;
-       }*/
+       }
 
        public LifxLightBulb(String macAddress) {
                communicationSockect = null;
@@ -1200,34 +1200,29 @@ public class LifxLightBulb implements LightBulb {
        }
 
 
-       /*public static void main(String[] args) throws Exception {
+       /* TODO: Uncomment this part to do light bulb test
+       public static void main(String[] args) throws Exception {
 
                System.out.println("Executing main function!");
-               IoTDeviceAddress iotDevAdd = new IoTDeviceAddress("192.168.2.126", 12345, 56700, false, false);
+               IoTDeviceAddress iotDevAdd = new IoTDeviceAddress(args[0], 12345, 56700, false, false);
                Set<IoTDeviceAddress> set = new HashSet<IoTDeviceAddress>();
                set.add(iotDevAdd);
                IoTSet<IoTDeviceAddress> iotset = new IoTSet<IoTDeviceAddress>(set);
                LifxLightBulb lb = new LifxLightBulb(iotset, "D073D5128E300000");
-               lb.init();
+               try {
+                       lb.init();
+                       Thread.sleep(1000);
+                       for (int i = 0; i < 2; i++) {
+                               lb.turnOff();
+                               System.out.println("Turning off!");
+                               Thread.sleep(1000);
+                               lb.turnOn();
+                               System.out.println("Turning on!");
+                               Thread.sleep(1000);
+                       }
+                       lb.turnOff();
+               } catch(Exception ex) {
+                       ex.printStackTrace();
+               }
        }*/
 }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-