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:
- 13:9ac5ff131214
- Parent:
- 10:32d5604accfd
- Child:
- 24:7d2ff444d6d8
diff -r f3ccc43c4d3c -r 9ac5ff131214 gsmqueue.cpp --- a/gsmqueue.cpp Fri Mar 06 00:30:41 2015 +0000 +++ b/gsmqueue.cpp Fri Mar 06 01:11:58 2015 +0000 @@ -29,9 +29,9 @@ //Does the character match the begin char? if (*queueHead == *str){ //Check the remaining characters - char* sPos = str + 1; + char* sPos = str; char* qPos = 0; - for (qPos = incrementIndex(queueHead); qPos != QUEUETAIL; qPos = incrementIndex(qPos)){ + for (qPos = queueHead; qPos != QUEUETAIL; qPos = incrementIndex(qPos)){ //Compare the next char if (*qPos == *sPos) { @@ -95,21 +95,23 @@ //Does not read negative integers; returns -1 if unsuccessful int parseInt() { - char* qPos = queueHead; + //Check if queue is empty first + if (queueHead == QUEUETAIL) return -1; + //Advance to first numeric character - while (!isNumeric(qPos)) + while (!isNumeric(queueHead)) { - qPos = incrementIndex(qPos); - if (qPos == QUEUETAIL) return -1; + queueHead = incrementIndex(queueHead); + if (queueHead == QUEUETAIL) return -1; } //Continue until first non-numeric character int val = 0; - while (qPos != QUEUETAIL && isNumeric(qPos)) + while (queueHead != QUEUETAIL && isNumeric(queueHead)) { val *= 10; - val += (int)(qPos - '0'); - qPos = incrementIndex(qPos); + val += (int)(*queueHead - '0'); + queueHead = incrementIndex(queueHead); } return val; } @@ -117,7 +119,7 @@ //Returns true if the character is numeric bool isNumeric(char* qPos) { - return ('0' < *qPos && *qPos < '9'); + return ('0' <= *qPos && *qPos <= '9'); } //Reset the GSM DMA idle bit to 0