Committing changes in driver files for paper evaluation
[iot2.git] / benchmarks / drivers / Java / AmcrestCamera / AmcrestCamera.java
index ffa92d06d8b55439e903a4612eab1473e64e5bd3..f186be19adb53c31cfd3171736dbbff9fce24e16 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) {
+
+           }
 
+       }*/
 }