Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MBed_Adafruit-GPS-Library SDFileSystem mbed GSM_Library
Fork of DCS by
Diff: gsmqueue.cpp
- Revision:
- 8:6b4a6bcd7694
- Parent:
- 1:8614e190908b
- Child:
- 9:c79e856c36e2
diff -r 8614e190908b -r 6b4a6bcd7694 gsmqueue.cpp
--- a/gsmqueue.cpp Fri Mar 06 22:36:44 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,135 +0,0 @@
-#include "gsmqueue.h"
-#include "mbed.h"
-/* queue.cpp
- * Contains functions to read from the DMA buffer in a queue fashion
- */
-extern Serial pc;
-
-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.
-//The given string terminates in NULL (\0)
-bool findInQueue(char* str)
-{
- //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;
- char* qPos = 0;
- for (qPos = queueHead; qPos != QUEUETAIL; qPos = incrementIndex(qPos)){
- //Compare the next char
- if (*qPos == *sPos)
- {
- ++sPos; //Increment index (prefix incrementation).
- if (*sPos == NULL) //If finished, update queueHead, return true.
- {
- queueHead = incrementIndex(qPos);
- 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;
-}
-
-//$debug - print queue elements
-void printQueue()
-{
- char* qPos = queueHead;
- pc.printf("Queue:");
- while (qPos != QUEUETAIL)
- {
- //Print the current character
- if (*qPos == '\n')
- pc.printf("\\n");
- else if (*qPos == '\r')
- pc.printf("\\r");
- else
- pc.printf("%C",*qPos);
-
-
- //Increment index
- qPos = incrementIndex(qPos);
- }
- pc.printf("\n\r");
-}
-
-//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()
-{
- //Check if queue is empty first
- if (queueHead == QUEUETAIL) return -1;
-
- //Advance to first numeric character
- while (!isNumeric(queueHead))
- {
- queueHead = incrementIndex(queueHead);
- if (queueHead == QUEUETAIL) return -1;
- }
-
- //Continue until first non-numeric character
- int val = 0;
- while (queueHead != QUEUETAIL && isNumeric(queueHead))
- {
- val *= 10;
- val += (int)(*queueHead - '0');
- queueHead = incrementIndex(queueHead);
- }
- 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()
-{
- UART_S1_REG(UART3) &= ~UART_S1_IDLE_MASK;
-}
-
-//Get the GSM DMA idle bit (if 1, indicates we already received a response)
-bool getGSMIdleBit()
-{
- return (UART_S1_IDLE_MASK & UART_S1_REG(UART3)) >> UART_S1_IDLE_SHIFT;
-}
\ No newline at end of file
