Lab3_Surveillance

Dependencies:   GPS mbed

Files at this revision

API Documentation at this revision

Comitter:
gtg846r
Date:
Thu Oct 13 16:44:37 2011 +0000
Parent:
0:2af1e48a285d
Child:
2:ba06c987a111
Commit message:
Revision #2
More user status info

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Oct 13 05:48:32 2011 +0000
+++ b/main.cpp	Thu Oct 13 16:44:37 2011 +0000
@@ -61,8 +61,8 @@
     if (cam->takePicture() != 0) {
         return -1;
     }
-    DEBMSG("Captured.");
-    NEWLINE();
+    //DEBMSG("Captured.");
+    //NEWLINE();
 
     /*
      * Open file.
@@ -75,8 +75,8 @@
     /*
      * Read the content.
      */
-    DEBMSG("%s", filename);
-    NEWLINE();
+    //DEBMSG("%s", filename);
+    //NEWLINE();
     if (cam->readJpegFileContent(callback_func) != 0) 
     {
         fclose(work.fp);
@@ -94,28 +94,20 @@
 
 void print_pics()
 {
-    if (cam1.reset() == 0) 
-    {
-        DEBMSG("Reset OK.");
-        NEWLINE();
-    } 
-    else 
-    {
-        DEBMSG("Reset fail.");
-        NEWLINE();
-        error("Reset fail.");
-    }
-    
+        
     int cnt = 0;
+    int c = 0;
     while (cnt < 4) 
     {
+       
         char fname[64];
         snprintf(fname, sizeof(fname) - 1, FILENAME, alert_num, cnt);
         int r = capture(&cam1, fname);
         if (r == 0) 
         {
-            DEBMSG("[%04d]:OK.", cnt);
-            NEWLINE();
+            ++c;
+           // DEBMSG("[%04d]:OK.", cnt);
+            //NEWLINE();
         } 
         else 
         {
@@ -125,6 +117,10 @@
         }
         cnt++;
     }
+    if(c==4)
+    {
+        printf("All pictures taken \n");
+    }
     
     return;
   }
@@ -135,36 +131,37 @@
     char buf2= 0x1A;
     
     gsm.printf("AT\r\n");  //Should return OK
-    gsm.scanf("%s",buf);
-    pc.printf("%s\n",buf);
+   // gsm.scanf("%s",buf);
+   // pc.printf("%s\n",buf);
+    
     //gsm.scanf("%s",buf1);
     //pc.printf("%s\n",buf1);
-
+    wait(.5);
     gsm.printf("AT+CSMP=17,167,0,0\r\n");  //Set text mode parameters =<fo>,<vp>,<pid>,<dcs>
-    gsm.scanf("%s",buf);                   // Should return OK
+    //gsm.scanf("%s",buf);                   // Should return OK
     //gsm.scanf("%s",buf1);
-    pc.printf("%s\n",buf);
+    //pc.printf("%s\n",buf);
     //pc.printf("%s\n",buf1);
-
+    wait(.5);
     gsm.printf("AT+CMGF=1\r\n");      //1 - text mode, indicates the format of messages used with send, list, read and write commands
-    gsm.scanf("%s",buf);               
+    //gsm.scanf("%s",buf);               
    // gsm.scanf("%s",buf1);
-    pc.printf("%s\n",buf);
+    //pc.printf("%s\n",buf);
     //pc.printf("%s\n",buf1);
-
+    wait(.5);
     while (1) 
     {
             //pc.printf("message sent");
             gsm.printf("AT+CMGS=\"16784370074\"\r\n");   //AT+CMGS=”<da>"...da - destination address
-            gsm.scanf("%s",buf);  //Response OK
+          //  gsm.scanf("%s",buf);  //Response OK
            // gsm.scanf("%s",buf1);
-            pc.printf("%s\n",buf);
+            //pc.printf("%s\n",buf);
             //pc.printf("%s\n",buf1);
-           
-            gsm.printf("Alert message %c \r\n", buf2);  //Actual message following CMGS command followed by ctrl+z (buf2)
-            gsm.scanf("%s",buf);  //Response OK
+           wait(.5);
+            gsm.printf("Alert message #%d %c \r\n", alert_num, buf2);  //Actual message following CMGS command followed by ctrl+z (buf2)
+            //gsm.scanf("%s",buf);  //Response OK
            // gsm.scanf("%s",buf1);
-            pc.printf("%s\n",buf);
+            //pc.printf("%s\n",buf);
             //pc.printf("%s\n",buf1);
             pc.printf("Message sent \n");
 
@@ -175,22 +172,45 @@
 void sound_alarm()
 {
     ++alert_num;
-    pc.printf("The value was: %f", reading);
-    pc.printf("Sound alarm...alert alert\n");
-    pc.printf("4 Pictures being taken \n");
+    pc.printf("\nSound alarm...alert alert\n");
+    pc.printf("The value was: %f \n", reading);
+    pc.printf("4 Pictures being taken... \n");
     print_pics();
+    pc.printf("Pictures have been taken!\n");
+    pc.printf("Sending text alert...\n");
     send_text();
-    pc.printf("Done \n");
+    
+    
+    
+    pc.printf("Re-engaging in 10 seconds... \n");
+    wait(10);
     return;
 }
 
-
+void init_cam()
+{
+    if (cam1.reset() == 0) 
+    {
+        DEBMSG("Reset OK.");
+        NEWLINE();
+    } 
+    else 
+    {
+        DEBMSG("Reset fail.");
+        NEWLINE();
+        error("Reset fail.");
+    }
+    return;
+}
   
 
 int main() 
 {
     gsm.baud(115200);
     pc.baud(115200);
+    //pc.printf("Testing...");
+    //send_text();
+   
     char user_input[5] = "";
    // user_input = "";
    
@@ -203,6 +223,9 @@
         pc.printf("Initialize Security System (y/n) \n");
         pc.scanf("%s", user_input);
      }
+     pc.printf("Initializing...\n");
+     init_cam();
+     
     int i = 0;
     while(1)
     {