uses pushing box to publish to google spreadsheets with a state machine instead of a while loop
Fork of GSM_PUSHING_BOX_STATE_MACHINE by
Diff: gsmqueue.cpp
- Revision:
- 3:dac922a18af6
- Parent:
- 1:c1458b739eb6
- Child:
- 5:320d2babfb41
diff -r c1458b739eb6 -r dac922a18af6 gsmqueue.cpp --- a/gsmqueue.cpp Thu Mar 05 20:51:04 2015 +0000 +++ b/gsmqueue.cpp Thu Mar 05 21:24:56 2015 +0000 @@ -3,6 +3,7 @@ /* queue.cpp * Contains functions to read from the DMA buffer in a queue fashion */ +extern Serial pc; char buffer[BUFFER_LENGTH]; char* queueHead; @@ -17,21 +18,25 @@ //Find an occurrence of the given string in the buffer. //Only advance queueHead until a matching string is found. +//The given string terminates in NULL (\0) bool findInQueue(char* str, int strLen) { + //Check that string to find is not empty + if (*str == NULL) return false; + while (queueHead != QUEUETAIL) { //Does the character match the begin char? if (*queueHead == *str){ //Check the remaining characters char* sPos = str + 1; - char * qPos = 0; + 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) + ++sPos; //Increment index (prefix incrementation). + if (*sPos == NULL) //If finished, return true. return true; } else //Not equal, so exit for loop and try again at a different location @@ -60,7 +65,7 @@ queueHead = QUEUETAIL; } -//print queue elements, (will help debug) +//$debug - print queue elements void printQueue() { char* qPos = queueHead; @@ -76,21 +81,34 @@ //Parse through characters until first integer is found //Advance qHead until you reach the next non-numeric character +//Does not read negative integers; returns -1 if unsuccessful int parseInt() { char* qPos = queueHead; - while (qPos != QUEUETAIL) + //Advance to first numeric character + while (!isNumeric(qPos)) { - //Print the current character - pc.printf("%C",*qPos); - - //Increment index + qPos = incrementIndex(qPos); + if (qPos == QUEUETAIL) return -1; + } + + //Continue until first non-numeric character + int val = 0; + while (qPos != QUEUETAIL && isNumeric(qPos)) + { + val *= 10; + val += (int)(qPos - '0'); qPos = incrementIndex(qPos); } - - + return val; } +//Returns true if the character is numeric +bool isNumeric(char* qPos) +{ + return ('0' < *qPos && *qPos < '9'); +} + //Reset the GSM DMA idle bit to 0 void resetGSMIdleBit() {