Colin Stearns / Mbed 2 deprecated qcControl

Dependencies:   mbed

Fork of dgps by Colin Stearns

Revision:
19:8c1f2a2204fb
Parent:
18:e72ee7aed088
Child:
20:81d5655fecc2
--- a/packet.h	Sun Apr 20 08:04:37 2014 +0000
+++ b/packet.h	Sun Apr 20 22:01:05 2014 +0000
@@ -17,6 +17,7 @@
     PT_REQLOC,
     PT_SENDLOC,
     PT_WAY,
+    PT_GETCOMMANDS,
     PT_SIZE
 };
 typedef struct PacketStruct{
@@ -77,12 +78,17 @@
     
     void openConnection(char close_conn = 0){
         __disable_irq();
-        while(!getTCPConStatus){
-            setTCPConStatus = 0;
-            wait_us(500000);
+        do{
+            USB::getSerial().printf("trying to connect...\r\n");
+            if(getTCPConStatus){
+                setTCPConStatus = 0;
+                while(getTCPConStatus){}
+                wait_us(50000);
+            }
             setTCPConStatus = 1;
-            wait_us(500000);
-        }
+            while(setTCPConStatus==1 && !getTCPConStatus){}          
+        }while(!getTCPConStatus);
+
         __enable_irq();
         //for(int a=0;a<10000000;a++);
 //        char connected = 0;
@@ -162,12 +168,13 @@
 //        for(int a=0;a<1000000;a++);
     }
     void closeConnection(){
-        wait_us(100000);
         __disable_irq();
-        while(getTCPConStatus){
+        wait_us(50000);
+        do{
+            USB::getSerial().printf("disconnecting...\r\n");
             setTCPConStatus = 0;
             wait_us(50000);
-        }
+        }while(getTCPConStatus);
     }
     unsigned int min(unsigned int a,unsigned int b){
         return a<b ? a : b;
@@ -185,6 +192,7 @@
                 sendPacket(output);
             }
         }else{
+            //openConnection();
             PacketStruct output;
             output.type=type;
             output.size=0;
@@ -195,6 +203,9 @@
             for(int a=0;a<PACKETSIZE;a++){output.data[a]='\0';}
             sendPacket(output);
         }
+        if(type == PT_END){
+            //closeConnection();
+        }
     }
     PacketStruct* lastValid;
     bool found;