QC Control software

Dependencies:   mbed

Fork of dgps by Colin Stearns

Revision:
49:06721139d298
Parent:
46:f89fc45811a1
Child:
51:d6b64ac3c30d
--- a/packet.h	Fri Apr 25 23:50:51 2014 +0000
+++ b/packet.h	Sat Apr 26 04:14:18 2014 +0000
@@ -72,6 +72,7 @@
         EvTimer t;
         t.set_s_period(30);
         t.start_timer();
+        char con_status_steady;
         char timed_out = 0;
         do{
             USB::getSerial().printf("trying to connect...\r\n");
@@ -81,18 +82,28 @@
                 wait_us(200000);
             }
             setTCPConStatus = 1;
+            con_status_steady = 1;
             wait_us(200000);
+            for(int i=0;i<10;i++){
+                if(!getTCPConStatus){
+                    con_status_steady = 0;
+                    break;
+                }
+                wait_us(1000);
+            }
             timed_out = t.get_num_trips();
-        }while(!getTCPConStatus && !timed_out);
+        }while(!con_status_steady && !timed_out);
         t.stop_timer();
         if(timed_out>0){
             if(hover_attempt){
                 //emergency landing goes here
                 USB::getSerial().printf("Second Attempt Connection failure. Emergency Landing.\r\n");
+                wait_us(10000000);
             }else{
                 //hover and give it another shot
                 USB::getSerial().printf("First Attempt Connection failure. Hover and retry.\r\n");
                 //hover code goes here
+                wait_us(10000000);
                 openConnection(close_conn, 1);
             }
         }
@@ -117,13 +128,13 @@
         if(serialDevice == NULL){
             serialDevice = &outputDevice;
         }
-        if(seconds==0 && u_seconds==0){
-            seconds = 3.0;
-        }
         if(serialDevice->readable()){
             return 1;
         }else{
             EvTimer t;
+             if(seconds==0 && u_seconds==0){
+                seconds = 3.0;
+            }
             if(seconds>0){
                 t.set_s_period(seconds);
             }else{
@@ -132,6 +143,7 @@
             t.start_timer();
             while(t.get_num_trips() == 0){
                 if(serialDevice->readable()){
+                    t.stop_timer();
                     return 1;
                 }
             }