QC Control software

Dependencies:   mbed

Fork of dgps by Colin Stearns

Files at this revision

API Documentation at this revision

Comitter:
krobertson
Date:
Thu Apr 24 16:16:57 2014 +0000
Parent:
44:2ae602b89961
Child:
46:f89fc45811a1
Commit message:
connection timeouts added

Changed in this revision

packet.h Show annotated file Show diff for this revision Revisions of this file
--- a/packet.h	Wed Apr 23 04:45:36 2014 +0000
+++ b/packet.h	Thu Apr 24 16:16:57 2014 +0000
@@ -68,7 +68,11 @@
         //wait_ms(100);
     }
     
-    void openConnection(char close_conn = 0){
+    void openConnection(char close_conn = 0, char hover_attempt = 0){
+        EvTimer t;
+        t.set_s_period(30);
+        t.start_timer();
+        char timed_out = 0;
         do{
             USB::getSerial().printf("trying to connect...\r\n");
             if(getTCPConStatus){
@@ -78,7 +82,20 @@
             }
             setTCPConStatus = 1;
             wait_us(100000);
-        }while(!getTCPConStatus);
+            timed_out = t.get_num_trips();
+        }while(!getTCPConStatus && !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");
+            }else{
+                //hover and give it another shot
+                USB::getSerial().printf("First Attempt Connection failure. Hover and retry.\r\n");
+                //hover code goes here
+                openConnection(close_conn, 1);
+            }
+        }
     }
     
     void closeConnection(){