QC Control software

Dependencies:   mbed

Fork of dgps by Colin Stearns

Revision:
20:81d5655fecc2
Parent:
19:8c1f2a2204fb
Child:
24:e65416d6de22
--- a/main.cpp	Sun Apr 20 22:01:05 2014 +0000
+++ b/main.cpp	Tue Apr 22 04:26:31 2014 +0000
@@ -4,6 +4,7 @@
 #include "adapt/usb.h"
 #include "handle/handleCamera.h"
 #include "handle/handleGPS.h"
+#include "handle/handleCommand.h"
 
 Serial pc(USBTX,USBRX);
 Serial xbee(p9,p10);//tx, rx
@@ -107,95 +108,73 @@
 
 int main()
 {
-    //getPS().sendPacket(0,NULL,0,PT_EMPTY);getPS().sendPacket(55,NULL,0,PT_IMAGE);
-    //char output[256];for(int i=0;i<256;i++){output[i]=i;}getPS().sendPacket(0,NULL,0,PT_IMAGE);getPS().sendPacket(55,output,256);getPS().sendPacket(55,output,5);getPS().sendPacket(55,NULL,0,PT_END);
-    //while(true){}
- /*   PacketStruct* packs[4];
-    for(int i=0;i<4;i){
-        packs[i]=getPS().getNextPacket();
-        if(packs[i]!=NULL)i++;
-    }
-    for(int i=0;i<4;i++){
-        PacketStruct* pack=packs[i];
-        if(pack!=NULL){
-            USB::getSerial().printf("Got Packet!\n");
-            USB::getSerial().printf(" > %d\n",pack->type);
-            for(int i=0;i<sizeof(PacketStruct);i++){
-                USB::getSerial().printf("%d\n",((char*)pack)[i]);
-            }
-            USB::getSerial().printf("\n",pack->type);
-        }else{
-            //USB::getSerial().printf(".");
-        }
-    }
-    while(true){}
-    */
-    //getPS().sendPacket(55,NULL,0,PT_IMAGE);char output[256];for(int i=0;i<256;i++){output[i]=i;}getPS().sendPacket(55,output,256,PT_IMAGE);getPS().sendPacket(55,output,5,PT_IMAGE);getPS().sendPacket(55,NULL,0,PT_END);while(true){}
-    ImageHandle imageHand;
-    GPSHandle gpsHand;
-    /// Main Loop
+    //handlers
+    //ImageHandle imageHand;
+    //GPSHandle gpsHand;
+    //CommandHandle commHand;
+
     USB::getSerial().printf("Starting %d\n",sizeof(PacketStruct));
-    //while(1){
-        //USB::getSerial().printf("Test\n");
-        //XBEE::getSerial().printf("ABC\n");
-    //}
     USB::getSerial().printf("Check GPS\n");
+    USB::getSerial().printf("Connect to the wifly network now!\r\n");
+    //XBEE::getTCPInterrupt().fall(&connection_lost);
     
-    USB::getSerial().printf("Connect to the wifly network now!\r\n");
-    __disable_irq();
-    XBEE::getTCPInterrupt().fall(&connection_lost);
-    
+    //checking connection to egg before continuing
     getPS().openConnection();
     getPS().closeConnection();
-    //for(int a=0;a<1000000000;a++);
-    while(1){
+    
+    //Main Loop
+    //while(1){
         while(1){
-            USB::getSerial().printf("sending 0's\n");
-            //getPS().openConnection();
-            USB::getSerial().printf("connection open!\r\n");
-            imageHand.run();
-            USB::getSerial().printf("sent all data\r\n");
-            //for(int a=0;a<10000000;a++);
-            //getPS().closeConnection();
-            //for(int a=0;a<10000000;a++);
-        }
+            USB::getSerial().printf("Requesting commands from egg...\r\n");
+            wait_us(100000);
+            CommandHandle::getCommandHand().run();
+            wait_us(100000);
+            if(GPSHandle::getGPSHand().if_image_location()){
+                USB::getSerial().printf("Taking picture and sending...\r\n");
+                wait_us(100000);
+                ImageHandle::getImageHand().run();
+                USB::getSerial().printf("sent all data\r\n");
+                wait_us(100000);
+            }
+            wait_us(1000000);
+        //}
 
         // Run image handler
-        USB::getSerial().printf("Check Image\n");
-        imageHand.run();
+        //USB::getSerial().printf("Check Image\n");
+       // imageHand.run();
         // Run GPS handler
-        USB::getSerial().printf("Check GPS\n");
-        gpsHand.run();
-        USB::getSerial().printf("GPS Time: %f\n",DH::Locs().getC().getTime());
+       // USB::getSerial().printf("Check GPS\n");
+        //gpsHand.run();
+        //USB::getSerial().printf("GPS Time: %f\n",DH::Locs().getC().getTime());
         // Read packet
-        USB::getSerial().printf("Read Input\n");
+        //USB::getSerial().printf("Read Input\n");
         //PacketStruct* pack=getPS().lastValid;//getPS().getNextPacket();
         //if(pack!=NULL){
         //    USB::getSerial().printf("Received Type: %d\n",pack->type);
         //    if(pack->type==PT_REQLOC){
-        if(getPS().outputDevice.readable()>0){
-                char input=getPS().outputDevice.getc();
-                //if(getPS().outputDevice.getc()=='A'){
-                // Send location
-                unsigned int sID=getPS().getSuperID();
-                getPS().sendPacket(0,NULL,0,PT_EMPTY);
-                getPS().sendPacket(sID,NULL,0,PT_SENDLOC);
-                getPS().sendPacket(sID,(char*)(&DH::Locs().getC().getLoc()),sizeof(DataLocation));
-                getPS().sendPacket(sID,NULL,0,PT_END);
-                //}
-        }
+        //if(getPS().outputDevice.readable()>0){
+//                char input=getPS().outputDevice.getc();
+//                //if(getPS().outputDevice.getc()=='A'){
+//                // Send location
+//                unsigned int sID=getPS().getSuperID();
+//                getPS().sendPacket(0,NULL,0,PT_EMPTY);
+//                getPS().sendPacket(sID,NULL,0,PT_SENDLOC);
+//                getPS().sendPacket(sID,(char*)(&DH::Locs().getC().getLoc()),sizeof(DataLocation));
+//                getPS().sendPacket(sID,NULL,0,PT_END);
+//                //}
+//        }
     }
     /// Main Loop
-    while(true) {
-        gps.baud(57600);
-        xbee.baud(9600);
-        pc.baud(57600);
-
-        sendGpsCommand("PMTK301,1");
-        while(true) {
-            pc.putc(gps.getc());
-        }
+   // while(true) {
+//        gps.baud(57600);
+//        xbee.baud(9600);
+//        pc.baud(57600);
+//
+//        sendGpsCommand("PMTK301,1");
+//        while(true) {
+//            pc.putc(gps.getc());
+//        }
         //gps.attach(&handleGpsData, Serial::RxIrq);
         //xbee.attach(&handleXbeeGps, Serial::RxIrq)//;
-    }
+    //}
 }