DCS_TEAM / Mbed 2 deprecated DCS

Dependencies:   MBed_Adafruit-GPS-Library SDFileSystem mbed GSM_Library

Fork of DCS by Brandon Crofts

Files at this revision

API Documentation at this revision

Comitter:
bjcrofts
Date:
Tue Mar 24 17:04:31 2015 +0000
Parent:
1:8614e190908b
Child:
9:c79e856c36e2
Commit message:
GSM Integration;

Changed in this revision

GSMLibrary.cpp Show diff for this revision Revisions of this file
GSMLibrary.h Show diff for this revision Revisions of this file
GSM_Library.lib Show annotated file Show diff for this revision Revisions of this file
QAM.h Show annotated file Show diff for this revision Revisions of this file
Sensor.cpp Show annotated file Show diff for this revision Revisions of this file
gsmqueue.cpp Show diff for this revision Revisions of this file
gsmqueue.h Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
param.h Show annotated file Show diff for this revision Revisions of this file
--- a/GSMLibrary.cpp	Fri Mar 06 22:36:44 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,280 +0,0 @@
-#include "GSMLibrary.h"
-#include "gsmqueue.h"
-#include <string.h>
-
-#define TIME_CONST .3
-#define SECONDS_TIMEOUT 40
-#define TIMEOUTLIMIT SECONDS_TIMEOUT/TIME_CONST //$change check with main code this will set up condition fior timeout.
-
-//definition for AT comands
-#define AT_OK "AT"
-#define AT_CSQ "AT+CSQ" 
-#define AT_CREG "AT+CREG?"
-#define AT_CMGF "AT+CMGF=1"
-#define RECEIVER_PHONE_NUMBER "\"+18014722842\""
-#define AT_CMGS "AT+CMGS=" RECEIVER_PHONE_NUMBER 
-#define MESSAGE_BODY "stress test\32\32"
-
-//Definition for AT repsonses
-//Please notice that after ":" the gsm will usually send aditional information
-#define AT_OK_RESPONSE "OK" //Response after sending "AT" message
-#define AT_CSQ_RESPONSE "+CSQ:" //+CSQ: <arg1>,<arg2> where <arg1> is signal strength arg1 = 0-30 where a number below 10 means low signal strength and 99 is not knwn or detectable signal and arg2 is bit error rate form 0-7, 99 will represent error 
-#define AT_CREG_RESPONSE "+CREG:"//+CREG: <arg1>,<arg2> where <arg1> = 0-2(see AT command descriptions), <arg2> =  0-5, 0 not registered to nework and not looking for one. 1 is conected to network, 2 is not conected but searching
-#define AT_CMGF_RESPONSE "OK"
-#define AT_CMGS_RESPONSE ">"  //Message is written aftersymbol
-#define AT_SENDSMS_RESPONSE ">" // +CMGS: <id> this will include the message id. CMGS ERROR for error and 
-#define AT_SUCCESS_REPSONSE "+CMGS:"
-
-//External variables
-extern Serial pc;
-extern Serial gsm;
-extern uint8_t buffer[BUFFER_LENGTH];//buffer storing char
-
-//Internal variables
-gsm_states gsm_current_state = GSM_INITIALIZE;
-char send = 0;
-int timeout_count = 0;
-
-void gsm_tick()
-{
-    if (getGSMIdleBit() || gsm_timeOut() || (send && gsm_current_state == GSM_INITIALIZE))  //question with send...
-    {
-        resetGSMIdleBit();  //reset GSM idle bit
-        gsm_nextStateLogic();   //Next state
-        gsm_mealyOutputs(); //Mealy outputs
-        flushQueue();       //Flush the queue
-    }
-}
-
-
-
-//Advance timeout counter; if timeout, return true
-bool gsm_timeOut()
-{
-    if(++timeout_count >= TIMEOUTLIMIT){
-        timeout_count=0; 
-        gsm_current_state = GSM_INITIALIZE;
-        return true;
-    }
-    else
-        return false;     
-}
-
-//Next state logic -----------------------------------------------------
-void gsm_nextStateLogic()
-{
-    printQueue(); //$debug
-
-    switch(gsm_current_state)
-    {
-        case GSM_INITIALIZE:
-            pc.printf("gsm_initialize state\r\n");//&debug
-            timeout_count = 0;
-            if (send)
-                gsm_current_state = GSM_AT_OK;   //unconditional (check it)
-            break;
-        case GSM_AT_OK:
-            pc.printf("inside AT_OK state\r\n");//&debug
-            if (findInQueue(AT_OK_RESPONSE))
-                gsm_current_state = GSM_AT_CSQ;
-            break;
-        case GSM_AT_CSQ:
-            pc.printf("inside AT_CSQ state \r\n");//&debug
-            if(findInQueue(AT_CSQ_RESPONSE))
-                gsm_current_state = GSM_AT_CREG;
-            break;
-        case GSM_AT_CREG:
-            pc.printf("gsm_creg state\r\n");//&debug
-            if(findInQueue(AT_CREG_RESPONSE))
-            {
-                pc.printf("creg parse Int1: %d\r\n",parseInt());//&debug
-                int q = parseInt();
-                pc.printf("creg parse Int2: %d\r\n",q);//&debug
-                if(q == 1)
-                    gsm_current_state = GSM_AT_CMGF;
-            } 
-            break;
-        case GSM_AT_CMGF:
-            pc.printf("gsm_cmgf state\r\n");//&debug
-            if(findInQueue(AT_CMGF_RESPONSE))
-                gsm_current_state = GSM_AT_CMGS;
-            break;
-        case GSM_AT_CMGS:
-            pc.printf("gsm_cmgs state\r\n");//&debug
-            if(findInQueue(AT_CMGS_RESPONSE))
-                gsm_current_state = GSM_AT_SENDSMS;
-            break;
-        case GSM_AT_SENDSMS:
-            pc.printf("gsm_send_sms state\r\n");//&debug
-            if(findInQueue(AT_SENDSMS_RESPONSE))
-                gsm_current_state = GSM_SUCCESS;
-            else
-                gsm_current_state = GSM_AT_CMGS;        //The only spot we can go backwards
-            break;
-        case GSM_SUCCESS:
-            pc.printf("gsm_success state\r\n");//&debug
-            if(findInQueue(AT_SENDSMS_RESPONSE))         //This appears to be a bug. It was in Danilo's original code as well.
-                pc.printf("Message SENT! msgID: %iY\r\n",parseInt());//&debug
-            gsm_current_state = GSM_AT_CMGS;                //Confusing part. Do we always go backwards here?
-            break;
-        default:
-            pc.printf("This is a state error");
-    }
-}
-
-//Mealy output logic ------------------------------------------------------
-void gsm_mealyOutputs()
-{
-    switch(gsm_current_state)
-    {
-        case GSM_INITIALIZE:
-            pc.printf("No Mealy initialize state output\r\n");//&debug
-            break;
-        case GSM_AT_OK:
-            pc.printf("sending AT_OK\r\n");//&debug
-            gsm.puts(AT_OK);
-            gsm.puts("\r\n"); 
-            break;
-        case GSM_AT_CSQ:
-            pc.printf("sending AT_CSQ\r\n");//&debug
-            gsm.puts(AT_CSQ);
-            gsm.puts("\r\n"); 
-            break;
-        case GSM_AT_CREG:
-            pc.printf("sending AT_CREG\r\n");//&debug
-            gsm.puts(AT_CREG);
-            gsm.puts("\r\n"); 
-            break;
-        case GSM_AT_CMGF:   
-            pc.printf("sending AT_CMGF\r\n");//&debug
-            gsm.puts(AT_CMGF);
-            gsm.puts("\r\n"); 
-            break;
-        case GSM_AT_CMGS:   
-            pc.printf("sending AT_CMGS\r\n");//&debug
-            gsm.puts(AT_CMGS);
-            gsm.puts("\r\n"); 
-            break;
-        case GSM_AT_SENDSMS:
-            pc.printf("sending MESSAGE_BODY\r\n");//&debug
-            gsm.puts(MESSAGE_BODY); //substitute char included
-            gsm.puts("\r\n"); 
-            break;
-        case GSM_SUCCESS:
-            pc.printf("No Mealy success state output\r\n");//&debug 
-        default:
-            pc.printf("This is a state error");
-    }
-}
-
-//set send falg on
-void gsm_send_sms(){
-    send = 1;
-}
-
-//
-void gsm_reset();
-
-
-//
-void gsm_initialize(){  
-      SIM_SCGC6 |= SIM_SCGC6_DMAMUX_MASK; //enabling dmamux clock
-      SIM_SCGC7 |= SIM_SCGC7_DMA_MASK;  // enebaling dma clock
-      pc.printf("initializing registers...!\r\n");
-     // control register mux, enabling uart3 receive        
-     DMAMUX_CHCFG0 |= DMAMUX_CHCFG_ENBL_MASK|DMAMUX_CHCFG_SOURCE(8); 
-     
-     // Enable request signal for channel 0 
-     DMA_ERQ = DMA_ERQ_ERQ0_MASK;
-     
-      // select round-robin arbitration priority
-     DMA_CR |= DMA_CR_ERCA_MASK;
-     
-     //enabled error interrupt for DMA0
-     //DMA_EEI = DMA_EEI_EEI0_MASK ;
-     //Addres for buffer
-     DMA_TCD0_SADDR = (uint32_t) &UART_D_REG(UART3_BASE_PTR);
-     DMA_TCD0_DADDR = (uint32_t) buffer;
-     // Set an offset for source and destination address
-     DMA_TCD0_SOFF = 0x00; 
-     DMA_TCD0_DOFF = 0x01; // Destination address offset of 1 byte per transaction
-     
-     // Set source and destination data transfer size
-     DMA_TCD0_ATTR = DMA_ATTR_SSIZE(0) | DMA_ATTR_DSIZE(0);
-     
-     // Number of bytes to be transfered in each service request of the channel
-     DMA_TCD0_NBYTES_MLNO = 0x01;
-     // Current major iteration count
-    DMA_TCD0_CITER_ELINKNO = DMA_CITER_ELINKNO_CITER(BUFFER_LENGTH);
-    DMA_TCD0_BITER_ELINKNO = DMA_BITER_ELINKNO_BITER(BUFFER_LENGTH);
-    // Adjustment value used to restore the source and destiny address to the initial value
-    // After reading 'len' number of times, the DMA goes back to the beginning by subtracting len*2 from the address (going back to the original address)
-    DMA_TCD0_SLAST = 0;   // Source address adjustment
-    DMA_TCD0_DLASTSGA = -BUFFER_LENGTH;  // Destination address adjustment   
-    // Setup control and status register
-    DMA_TCD0_CSR = 0;
-       
-    // enable interrupt call at end of major loop
-    DMA_TCD0_CSR |= DMA_CSR_INTMAJOR_MASK;
-    
-    //Activate dma trasnfer rx interrupt
-    UART_C2_REG(UART3) |= UART_C2_RIE_MASK;
-    UART_C5_REG(UART3) |= UART_C5_RDMAS_MASK | UART_C5_ILDMAS_MASK | UART_C5_LBKDDMAS_MASK;
-    //activate p fifo   
-    UART_PFIFO_REG(UART3) |= UART_PFIFO_RXFE_MASK; //RXFE and buffer size of 1 word
-    queueInit();
-    pc.printf("Initialization done...\n\r");
-}
-
-
-
-//initialization debuging purposes
-void print_registers() {
-    
-   
-    pc.printf("\n\rDMA REGISTERS\n\r");
-    pc.printf("DMA_MUX: 0x%08x\r\n",DMAMUX_CHCFG0);
-    pc.printf("SADDR0: 0x%08x\r\n",DMA_TCD0_SADDR);
-    pc.printf("DADDR0: 0x%08x\r\n",DMA_TCD0_DADDR);
-    pc.printf("CITER0: 0x%08x\r\n",DMA_TCD0_CITER_ELINKNO);
-    pc.printf("BITER0: 0x%08x\r\n",DMA_TCD0_BITER_ELINKNO);
-    pc.printf("DMA_CR: %08x\r\n", DMA_CR);
-    pc.printf("DMA_ES: %08x\r\n", DMA_ES);
-    pc.printf("DMA_ERQ: %08x\r\n", DMA_ERQ);
-    pc.printf("DMA_EEI: %08x\r\n", DMA_EEI);
-    pc.printf("DMA_CEEI: %02x\r\n", DMA_CEEI);
-    pc.printf("DMA_SEEI: %02x\r\n", DMA_SEEI);
-    pc.printf("DMA_CERQ: %02x\r\n", DMA_CERQ);
-    pc.printf("DMA_SERQ: %02x\r\n", DMA_SERQ);
-    pc.printf("DMA_CDNE: %02x\r\n", DMA_CDNE);
-    pc.printf("DMA_SSRT: %02x\r\n", DMA_SSRT);
-    pc.printf("DMA_CERR: %02x\r\n", DMA_CERR);
-    pc.printf("DMA_CINT: %02x\r\n", DMA_CINT);
-    pc.printf("DMA_INT: %08x\r\n", DMA_INT);
-    pc.printf("DMA_ERR: %08x\r\n", DMA_ERR);
-    pc.printf("DMA_HRS: %08x\r\n", DMA_HRS);
-    pc.printf("DMA_TCD0_DOFF: %08x\r\n",DMA_TCD0_DOFF);
-    pc.printf("\n\rUART REGISTERS\n\r");
-    pc.printf("UART_BDH_REG: %08x\r\n",UART_BDH_REG(UART3)); 
-    pc.printf("UART_C1_REG: %08x\r\n",UART_C1_REG(UART3));
-    pc.printf("UART_C2_REG: %08x\r\n",UART_C2_REG(UART3));
-    pc.printf("UART_S1_REG: %08x\r\n",UART_S1_REG(UART3));
-    pc.printf("UART_s2_REG: %08x\r\n",UART_S2_REG(UART3));  
-    pc.printf("UART_C3_REG: %08x\r\n",UART_C3_REG(UART3));
-    pc.printf("UART_D_REG: %08x\r\n",UART_D_REG(UART3));
-    pc.printf("UART_MA1_REG: %08x\r\n",UART_MA1_REG(UART3));
-    pc.printf("UART_MA2_REG: %08x\r\n",UART_MA2_REG(UART3));
-    pc.printf("UART_C4_REG: %08x\r\n",UART_C4_REG(UART3));
-    pc.printf("UART_C5_REG: %08x\r\n",UART_C5_REG(UART3));
-    pc.printf("UART_ED_REG: %08x\r\n",UART_ED_REG(UART3));   
-    pc.printf("UART_MODEM_REG: %08x\r\n",UART_MODEM_REG(UART3));
-    pc.printf("UART_IR_REG: %08x\r\n",UART_IR_REG(UART3)); 
-    pc.printf("UART_PFIFO_REG: %08x\r\n",UART_PFIFO_REG(UART3));
-    pc.printf("UART_CFIFO_REG: %08x\r\n",UART_CFIFO_REG(UART3));
-    pc.printf("UART_SFIFO_REG: %08x\r\n",UART_SFIFO_REG(UART3)); 
-    pc.printf("UART_TWFIFO_REG: %08x\r\n",UART_TWFIFO_REG(UART3));
-    pc.printf("UART_TCFIFO_REG: %08x\r\n",UART_TCFIFO_REG(UART3)); 
-    pc.printf("UART_RWFIFO_REG: %08x\r\n",UART_RWFIFO_REG(UART3)); 
-    pc.printf("UART_RCFIFO_REG: %08x\r\n",UART_RCFIFO_REG(UART3));
-  
-}
\ No newline at end of file
--- a/GSMLibrary.h	Fri Mar 06 22:36:44 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,36 +0,0 @@
-#ifndef GSMLIBRARY_H
-#define GSMLIBRARY_H
-
-#include "mbed.h"
-
-enum gsm_states{GSM_INITIALIZE, 
-                    GSM_AT_OK,      //Make sure communication is stablished betheen fdm and gsm
-                    GSM_AT_CSQ,     //Check signal strength if strenght lower than 10 keep trying
-                    GSM_AT_CREG,    //Checking if phone is conected to network
-                    GSM_AT_CMGF,    //prepare phone to send message by CMGF=1
-                    GSM_AT_CMGS,    //input phone number by CMGS= "+phonenumber"
-                    GSM_AT_SENDSMS, //write message, finish with alt+z
-                    GSM_SUCCESS     //check if message was send correctly
-                };
-
-
-//GSM state machine
-void gsm_tick();
-bool gsm_timeOut();
-void gsm_nextStateLogic();
-void gsm_mealyOutputs();
-
-//Initialize DMA data transfer, and UART3.
-void gsm_initialize();
-
-//begin message transmission
-void gsm_send_sms();
-
-//Brings state machine back to initialize state (notice this is different than initialize function)
-//this will set flags to initial values and prepare gsm to work anew.
-void reset();
-
-//used for debuging purposes, it print all main registers from dma0 and uart3
-void print_registers(); 
-
-#endif
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GSM_Library.lib	Tue Mar 24 17:04:31 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/teams/DCS_TEAM/code/GSM_Library/#fbde9d2fc0ed
--- a/QAM.h	Fri Mar 06 22:36:44 2015 +0000
+++ b/QAM.h	Tue Mar 24 17:04:31 2015 +0000
@@ -9,9 +9,9 @@
 {   
     float *taps = firCoeffs;
     int i, j;
-    float out[SAMPLE_LENGTH] = {};
+    float out[2000] = {};
     
-    for( i = NUM_TAPS; i < SAMPLE_LENGTH; i++ )
+    for( i = NUM_TAPS; i < 2000; i++ )
     {
         out[ i ] = 0.0;
         for( j = 0; j < NUM_TAPS; j++ ){
@@ -22,7 +22,7 @@
         }
     }
     
-    for( i = 0; i < SAMPLE_LENGTH; i++ )
+    for( i = 0; i < 2000; i++ )
     {
         in[ i ] = out[i];
     }
@@ -43,6 +43,6 @@
     
     filter(sI, pc);
     filter(sQ, pc);
-    return avg_QAM(sI, sQ, SAMPLE_LENGTH);
+    return avg_QAM(sI, sQ, 2000);
 }
 
--- a/Sensor.cpp	Fri Mar 06 22:36:44 2015 +0000
+++ b/Sensor.cpp	Tue Mar 24 17:04:31 2015 +0000
@@ -5,10 +5,18 @@
 #include "SDFileSystem.h"
 #include "QAM.h"
 #include "param.h"
+#include "GSMLibrary.h"
+#include "stdlib.h"
 
 DigitalOut led_red(LED_RED);
 Serial pc(USBTX, USBRX);
 Timer t;
+Timer z;
+bool run = 0;
+Serial gsm(D1,D0);
+
+char message[5000];
+char num[10];
 
 /**************************************************
  **          SD FILE SYSTEM                       **
@@ -80,10 +88,14 @@
 int main () {
     
     pc.baud(115200);
+    gsm.baud(115200);
     pc.printf("hello\r\n");
     
+    //GSM INITIALIZATION ///////////////////////////////
+    gsm_initialize();
+    
     // GPS INITIALIZATION //////////////////////////////
-    gps_Serial = new Serial(D1,D0);
+    gps_Serial = new Serial(PTC4,PTC3); ////Serial gsm(D1,D0);
     Adafruit_GPS myGPS(gps_Serial);
     char c;
     myGPS.begin(9600);
@@ -100,21 +112,20 @@
     float filteredLongRef = 0;
     float filteredShortRef = 0;
     
+    void gsm_initialize();
+    
     sample_tick.attach(&tick, 0.0001);
     
     t.start();
+    z.start();
+    
+    int buffer = 0;
     
     while(1){
         
-        if(takeSample){ //3.46 us per loop
+        if(takeSample  && z.read_ms()>1000){
             
-            takeSample = false;
             dac0 = sinWave[sinIndex];
-            sinIndex++;
-            if((sinIndex+1) > sinRes){
-                sinIndex = 0;
-            }
-        
             
             lon = AnLong.read();
             lonRef = AnRefLong.read();
@@ -132,17 +143,31 @@
             sRefSI[sampleIndex] = shorRef*I;
             sRefSQ[sampleIndex] = shorRef*Q;
             
+            takeSample = false;
+            
+            sinIndex++;
+            if((sinIndex+1) > sinRes){
+                sinIndex = 0;
+            }
+            
+            
             sampleIndex++;
             if(sampleIndex+1 > SAMPLE_LENGTH){
                 sampleIndex--;
             }
+            
+        
         }
         
         
-        
-        if(sampleIndex+2 > SAMPLE_LENGTH){ //0.50 seconds
+
+        if(t.read_ms()>1000){//sampleIndex+2 > SAMPLE_LENGTH){ //0.50 seconds
             
+            run = 1;
+            z.reset();
             sampleIndex = 0;
+            
+            gsm_tick();
             filteredLong = QAM(sLI, sLQ, &pc);
             filteredLongRef = QAM(sRefLI, sRefLQ, &pc);
             filteredShort = QAM(sSI, sSQ, &pc);
@@ -157,65 +182,72 @@
         }
 
 
-        if(t.read_ms()>1000){
+        if(run){
             led_red = !led_red;
-            
-            pc.printf("Long = %f\r\n", filteredLong);
-            pc.printf("LongRef = %f\r\n", filteredLongRef);
-            pc.printf("Short = %f\r\n", filteredShort);
-            pc.printf("ShortRef = %f\r\n", filteredShortRef);
-            pc.printf("Time: %d:%d:%d \r\n", myGPS.hour, myGPS.minute, myGPS.seconds);
+            run = 0;
             
             
-            if (myGPS.fix) pc.printf("Location: %5.2f%c, %5.2f%c\r\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
+            pc.printf("%f, ", filteredLong);
+            pc.printf("%f, ", filteredLongRef);
+            pc.printf("%f, ", filteredShort);
+            pc.printf("%f\r\n", filteredShortRef);
+            pc.printf("%f, ", filteredLong/filteredLongRef);
+            pc.printf("%f\r\n", filteredShort/filteredShortRef);
+            pc.printf("%d:%d:%d \r\n", myGPS.hour-6, myGPS.minute, myGPS.seconds);
+            
+            if (myGPS.fix) pc.printf("%5.2f%c, %5.2f%c\r\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
             else           pc.printf("No GPS fix\r\n");
             pc.printf("--------------------------------\r\n");
             
+            
+            
             fp = fopen("/sd/data.txt", "w");
             if (fp != NULL){
                 
-                fprintf(fp, "Long = %f\r\n", filteredLong);
-                fprintf(fp, "LongRef = %f\r\n", filteredLongRef);
-                fprintf(fp, "Short = %f\r\n", filteredShort);
-                fprintf(fp, "ShortRef = %f\r\n", filteredShortRef);
-                fprintf(fp, "Time: %d:%d:%d \r\n", myGPS.hour, myGPS.minute, myGPS.seconds);
-                if (myGPS.fix) fprintf(fp, "Location: %5.2f%c, %5.2f%c\r\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
-                else           fprintf(fp, "No GPS fix\r\n");
+                fprintf(fp, "%f, ", filteredLong);
+                fprintf(fp, "%f, ", filteredLongRef);
+                fprintf(fp, "%f, ", filteredShort);
+                fprintf(fp, "%f\r\n", filteredShortRef);
+                fprintf(fp, "%d:%d:%d\r\n", myGPS.hour, myGPS.minute, myGPS.seconds);
+                if (myGPS.fix) fprintf(fp, "%5.2f%c, %5.2f%c\r\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
+                else           fprintf(fp, "No_GPS_fix\r\n");
                 
                 fclose(fp);    
             }
             
+            snprintf(num,10,"%f, ",filteredLong);
+            strcat(message, num);
+            snprintf(num,10,"%f, ",filteredLongRef);
+            strcat(message, num);
+            snprintf(num,10,"%f, ",filteredShort);
+            strcat(message, num);
+            snprintf(num,10,"%f = ",filteredShortRef);
+            strcat(message, num);
+            
+            snprintf(num,10,"%d:%d:%d = ", myGPS.hour, myGPS.minute, myGPS.seconds);
+            strcat(message, num);
+            if (myGPS.fix){ 
+                snprintf(num,10,"%5.2f%c, %5.2f%c. ", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
+                strcat(message, num);
+            }
+            else strcat(message, "NO_GPS_FIX. ");
+            
+            //pc.printf("%s\r\n", message);
+            
+            if(gsm_ready()){
+                gsm_send_sms(message); 
+                memset(message, 0, 5000);
+                buffer = 0; 
+            }else{
+                buffer++;
+                if(buffer > 12){
+                    buffer = 0;
+                    memset(message, 0, 5000);    
+                }
+            }
+            
             t.reset();
         }
         
-        
-        
-        
-        
-        /*
-        if (sampleIndex+2 > SAMPLE_LENGTH) { // 0.25 seconds
-            
-            sampleIndex = 0;
-            pc.printf("Time: %d:%d:%d \r\n", myGPS.hour, myGPS.minute, myGPS.seconds);
-            fp = fopen("/sd/data.txt", "w");
-            if (fp != NULL){
-                fprintf(fp,"Time: %d:%d:%d.%u \r\n", myGPS.hour, myGPS.minute, myGPS.seconds, myGPS.milliseconds);
-                fclose(fp);
-            }
-
-            if (myGPS.fix) {
-                pc.printf("Location: %5.2f%c, %5.2f%c\r\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
-                led_red = !led_red;
-                fp = fopen("/sd/data.txt", "w");
-                if (fp != NULL){
-                    fprintf(fp,"Location: %5.2f%c, %5.2f%c\r\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
-                    fclose(fp);
-                }
-            }else{
-                fprintf(fp,"no gps fix\r\n");
-                fclose(fp);
-            }    
-        }
-        */
     }
 }
\ No newline at end of file
--- 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
--- a/gsmqueue.h	Fri Mar 06 22:36:44 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,43 +0,0 @@
-#ifndef GSMQUEUE_H
-#define GSMQUEUE_H
-
-/* gsmqueue.cpp
- * Contains functions to read from the DMA buffer in a queue fashion
- */
-
-//Memory block of char size alocated for DMA
-#define BUFFER_LENGTH 255 //cannot exeede an int max value
-
-#define QUEUETAIL (char*)DMA_TCD0_DADDR
-
-
-//Initialize variables 
-void queueInit();
-
-//Find an occurrence of the given string in the buffer.
-//Only advance queueHead until a matching string is found.
-bool findInQueue(char* str);
-
-//Increment queue index by 1, auxiliar function
-char* incrementIndex(char* pointerToIncrement);
-
-//will eliminate all elements form queue.
-void flushQueue();
-
-//Print queue elements
-void printQueue();   //for debugging
-
-//Parse through characters until first integer is found
-int parseInt();
-
-//Returns true if the character is numeric
-bool isNumeric(char* qPos);
-
-//Reset the GSM DMA idle bit to 0
-void resetGSMIdleBit();
-
-//Get the GSM DMA idle bit (if 1, indicates we already received a response)
-bool getGSMIdleBit();
-
-
-#endif
\ No newline at end of file
--- a/mbed.bld	Fri Mar 06 22:36:44 2015 +0000
+++ b/mbed.bld	Tue Mar 24 17:04:31 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/7e07b6fb45cf
\ No newline at end of file
--- a/param.h	Fri Mar 06 22:36:44 2015 +0000
+++ b/param.h	Tue Mar 24 17:04:31 2015 +0000
@@ -1,4 +1,4 @@
-#define SAMPLE_LENGTH       1000 
+#define SAMPLE_LENGTH       6000 
 #define SAMPLE_RATE         10000
 #define SIN_LENGTH          500
 #define OUTAVG_LENGTH       100