Quicksand micro-electronics / Mbed 2 deprecated QW-Downlink

Dependencies:   QW_Sensors mbed

Fork of QW-Downlink by Quicksand

Files at this revision

API Documentation at this revision

Comitter:
quicksand
Date:
Tue Mar 14 15:40:25 2017 +0000
Parent:
4:1d707586e24d
Commit message:
Code cleanup and shortening timeouts.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 1d707586e24d -r 225de2b86ed5 main.cpp
--- a/main.cpp	Tue Mar 14 12:45:21 2017 +0000
+++ b/main.cpp	Tue Mar 14 15:40:25 2017 +0000
@@ -4,13 +4,6 @@
 /* The 4 onboard LEDs */
 BusOut leds(PB_6, PA_7, PA_6, PA_5);
 
-/*
-DigitalOut LED_0 (PB_6);
-DigitalOut LED_1 (PA_7);
-DigitalOut LED_2 (PA_6);
-DigitalOut LED_3 (PA_5);
-*/
-
 /* The 2 user buttons */
 InterruptIn SW1(PA_8);
 InterruptIn SW2(PB_10);
@@ -103,13 +96,12 @@
         /* Timeout */
         Timeout tmout;
         ser_timeout = false;
-        tmout.attach(&sertmout, 35.0);
+        tmout.attach(&sertmout, 20.0);
         /* Animation while waiting for downlink */
         int c;
         int animation = 0;
         while(!ser_timeout && !begin_rx) {
-
-            while (modem.readable() && !ser_timeout && !begin_rx) {
+            if(modem.readable()) {
                 c = modem.getc();
                 if ( (char)c == *beginStringPtr ) beginStringPtr++;
                 else beginStringPtr = beginString;
@@ -144,8 +136,9 @@
             int j = 0;
             tmout.attach(&sertmout, 30.0);
             ser_timeout = false;
-            while(modem.readable() && !ser_timeout && !rx_ready)
-                while (((c = modem.getc()) > 0) && !ser_timeout && !rx_ready) {
+            while(!ser_timeout && !rx_ready)
+                if(modem.readable()){
+                    c = modem.getc();
                     rx_buffer[i++] = (char)c;
                     pc.putc((char)c);
                     if ( (char)c == *readyStringPtr ) readyStringPtr++;
@@ -262,20 +255,21 @@
     /* Wait untill serial feedback, max 10 seconds before timeout */
     tmout.attach(&sertmout, 10.0);
     int c;
-    while(!ser_timeout && !ok && !error)
-        if(modem.readable())
-            while (((c = modem.getc()) > 0) && !ser_timeout  && !ok && !error) {
-                if ( (char)c == *readyStringPtr ) readyStringPtr++;
-                else readyStringPtr = readyString;
-                if ( *readyStringPtr == 0 ) {
-                    ok = true;
-                }
-                if ( (char)c == *errorStringPtr ) errorStringPtr++;
-                else errorStringPtr = errorString;
-                if ( *errorStringPtr == 0 ) {
-                    error = true;
-                }
+    while (!ser_timeout  && !ok && !error) {
+        if(modem.readable()) {
+            c = modem.getc();
+            if ( (char)c == *readyStringPtr ) readyStringPtr++;
+            else readyStringPtr = readyString;
+            if ( *readyStringPtr == 0 ) {
+                ok = true;
             }
+            if ( (char)c == *errorStringPtr ) errorStringPtr++;
+            else errorStringPtr = errorString;
+            if ( *errorStringPtr == 0 ) {
+                error = true;
+            }
+        }
+    }
     tmout.detach();
     if(ser_timeout) return false;
     else return ok;