uses pushing box to publish to google spreadsheets with a state machine instead of a while loop

Dependents:   DCS_FINAL_CODE

Fork of GSM_PUSHING_BOX_STATE_MACHINE by DCS_TEAM

Revision:
0:41904adca656
Child:
1:c1458b739eb6
diff -r 000000000000 -r 41904adca656 gsmqueue.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gsmqueue.cpp	Thu Mar 05 20:06:41 2015 +0000
@@ -0,0 +1,90 @@
+#include "gsmqueue.h"
+#include "mbed.h"
+/* queue.cpp
+ * Contains functions to read from the DMA buffer in a queue fashion
+ */
+
+char buffer[BUFFER_LENGTH];
+char* queueHead;
+
+
+//Initialize variables 
+void queueInit()
+{
+    //The buffer is initialized in init.cpp
+    queueHead = QUEUETAIL;
+}
+
+//Find an occurrence of the given string in the buffer.
+//Only advance queueHead until a matching string is found.
+bool findInQueue(char* str, int strLen)
+{
+    while (queueHead != QUEUETAIL)
+    {
+        //Does the character match the begin char?
+        if (*queueHead == *str){
+            //Check the remaining characters
+            char* sPos = str + 1;
+            char * qPos = 0;
+            for (qPos = incrementIndex(queueHead); qPos != QUEUETAIL; qPos = incrementIndex(qPos)){
+                //Compare the next char
+                if (*qPos == *sPos)
+                {
+                    //Increment index (prefix incrementation). If finished, return true.
+                    if (++sPos == str + strLen)
+                        return true;
+                }
+                else    //Not equal, so exit for loop and try again at a different location
+                    break;
+            }
+        }
+        //Increment queue index for next iteration
+        queueHead = incrementIndex(queueHead);
+    }
+    //We never finished, so return false
+    return false;
+}
+
+//Increment queue index by 1
+char* incrementIndex(char* pointerToIncrement)
+{
+    if((pointerToIncrement + 1) < (buffer + BUFFER_LENGTH))
+        return (pointerToIncrement + 1);
+    else
+        return buffer;
+}
+
+//clear queue
+void flushQueue()
+{
+    queueHead = QUEUETAIL;   
+}
+
+//print queue elements, (will help debug)
+void printQueue()
+{
+    char* qPos = queueHead;
+    while (qPos != QUEUETAIL)
+    {
+        //Print the current character
+        pc.printf("%C",*qPos);
+        
+        //Increment index
+        qPos = incrementIndex(qPos);
+    }
+}
+
+//Parse through characters until first integer is found
+//
+int parseInt()
+{
+    char* qPos = queueHead;
+    while (qPos != QUEUETAIL)
+    {
+        //Print the current character
+        pc.printf("%C",*qPos);
+        
+        //Increment index
+        qPos = incrementIndex(qPos);
+    }
+}
\ No newline at end of file