works through pushing box to log data to google spreadsheet

Dependencies:   MBed_Adafruit-GPS-Library SDFileSystem mbed

Fork of GPR_Interface by DCS_TEAM

Files at this revision

API Documentation at this revision

Comitter:
DeWayneDennis
Date:
Wed Oct 21 19:41:42 2015 +0000
Parent:
10:8c55dfcc9a7c
Commit message:
Changed GPR Interface to work with pushingbox

Changed in this revision

GPRS/GPRS.cpp Show annotated file Show diff for this revision Revisions of this file
GPRS/GPRS.h Show annotated file Show diff for this revision Revisions of this file
GPRS/modem/modem.cpp Show annotated file Show diff for this revision Revisions of this file
GPRS/modem/modem.h Show annotated file Show diff for this revision Revisions of this file
GSMLibrary.h Show annotated file Show diff for this revision Revisions of this file
MBed_Adafruit-GPS-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
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file 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
diff -r 8c55dfcc9a7c -r 045cb766d9a5 GPRS/GPRS.cpp
--- a/GPRS/GPRS.cpp	Fri Sep 25 04:10:56 2015 +0000
+++ b/GPRS/GPRS.cpp	Wed Oct 21 19:41:42 2015 +0000
@@ -32,6 +32,7 @@
     _userName = userName;
     _passWord = passWord;
     socketID = -1;
+    _phoneNumber = "12345678910";
 }
 
 bool GPRS::preInit()
@@ -61,13 +62,13 @@
     sendCmdAndWaitForResp("AT+CMGF=1\r\n","OK",DEFAULT_TIMEOUT,CMD);
     wait(2);
      //printf("\032\n");
-    sendCmdAndWaitForResp("AT+CMGS=\"+18183977481\"\r\n",">",DEFAULT_TIMEOUT,CMD);
+    sendCmdAndWaitForResp("AT+CMGS=\"+17066311506\"\r\n",">",DEFAULT_TIMEOUT,CMD);
     printf("sent at cmgf\n");
     wait(2);
     //printf("032");
     sendCmd(IPAdress); // sends the address 
     sendCmd("\x1a");  // this is like pressing control - z to end the send command
-    wait(10);  // giving the send enough time to do its thing
+        wait(10);  // giving the send enough time to do its thing
     printf("should have been received");
 }
 
@@ -82,28 +83,31 @@
     wait(10);  
     sendCmd("AT+CMGR=1\r\n");
     storeResp();
-    char temp[30];
     return get_server_IP();
 }
 
 // end of what Noah Milam added
 bool GPRS::checkSIMStatus(void)
 {
+    printf("Checking SIM Status...\r\n");
     char gprsBuffer[32];
     int count = 0;
-    cleanBuffer(gprsBuffer,32);
+    
     while(count < 3) {
+        cleanBuffer(gprsBuffer,32);
         sendCmd("AT+CPIN?\r\n");
         readBuffer(gprsBuffer,32,DEFAULT_TIMEOUT);
         if((NULL != strstr(gprsBuffer,"+CPIN: READY"))) {
             break;
         }
+        printf("SIM Not Ready..Try Again\r\n");
         count++;
         wait(1);
     }
     if(count == 3) {
         return false;
     }
+    printf("SIM Status GOOD!\r\n");
     return true;
 }
 
@@ -111,26 +115,114 @@
 {
     char cmd[64];
     char ipAddr[32];
+    char resp[96];
+    //get the phone number
+    printf(">>>>AT+CNUM\r\n");
+    sendCmd("AT+CNUM\r\n");
+    cleanBuffer(resp,96);
+    readBuffer(resp,96,DEFAULT_TIMEOUT);
+    if(NULL != strstr(resp,"+CNUM:")) {
+        //if(storePhoneNumber(resp)){
+            printf("Successfull stored the phone number!\r\n");     
+        //}   
+    }
+    else{
+        return false;    
+    }
+    
+    printf(">>>>AT+CREG\r\n");
+    sendCmd("AT+CREG?\r\n");
+    cleanBuffer(resp,96);
+    readBuffer(resp,96,DEFAULT_TIMEOUT);
+    if(NULL != strstr(resp,"+CREG:")) {
+    }
+    else{
+        return false;    
+    }
+    //close any existing connections
+    printf(">>>>AT+CIPSHUT\r\n");
+    sendCmd("AT+CIPSHUT\r\n");
+    cleanBuffer(resp,96);
+    readBuffer(resp,96,DEFAULT_TIMEOUT);
+    if(NULL != strstr(resp,"OK")) {
+    }
+    else{
+        return false;    
+    }
     //Select multiple connection
-    sendCmdAndWaitForResp("AT+CIPMUX=1\r\n","OK",DEFAULT_TIMEOUT,CMD);
-
+    printf(">>>>AT+CIPMUX=0\r\n");
+    sendCmd("AT+CIPMUX=0\r\n");
+    cleanBuffer(resp,96);
+    readBuffer(resp,96,DEFAULT_TIMEOUT);
+    if(NULL != strstr(resp,"CIPMUX")) {
+    }
+    else{
+        return false;    
+    }
+    //get signal strength
+    printf(">>>>AT+CSQ\r\n");
+    sendCmd("AT+CSQ\r\n");
+    cleanBuffer(resp,96);
+    readBuffer(resp,96,DEFAULT_TIMEOUT);
+    if(NULL != strstr(resp,"+CSQ:")) {
+    }
+    else{
+        return false;    
+    }
+    
+    //attach the device
+    printf(">>>>AT+CGATT=1\r\n");
+    sendCmd("AT+CGATT=1\r\n");
+    cleanBuffer(resp,96);
+    readBuffer(resp,96,DEFAULT_TIMEOUT);
+    if(NULL != strstr(resp,"OK")) {
+    }
+    else{
+        return false;    
+    }
+    
     //set APN
     snprintf(cmd,sizeof(cmd),"AT+CSTT=\"%s\",\"%s\",\"%s\"\r\n",_apn,_userName,_passWord);
-    sendCmdAndWaitForResp(cmd, "OK", DEFAULT_TIMEOUT,CMD);
-
+    printf(">>>>%s",cmd);
+    //sendCmdAndWaitForRes  p(cmd, "OK", DEFAULT_TIMEOUT,CMD);
+    sendCmd(cmd);
+    cleanBuffer(resp,96);
+    readBuffer(resp,96,DEFAULT_TIMEOUT);
+    if(NULL != strstr(resp,"OK")) {
+    }
+    else{
+        return false;    
+    }
     //Brings up wireless connection
-    sendCmdAndWaitForResp("AT+CIICR\r\n","OK",DEFAULT_TIMEOUT,CMD);
-
+    printf(">>>>AT+CIICR\r\n");
+    sendCmd("AT+CIICR\r\n");
+    cleanBuffer(resp,96);
+    readBuffer(resp,96,DEFAULT_TIMEOUT);
+    if(NULL != strstr(resp,"OK")) {
+    }
+    else{
+        return false;    
+    } 
+    
     //Get local IP address
+    printf(">>>>AT+CIFSR\r\n");
     sendCmd("AT+CIFSR\r\n");
     readBuffer(ipAddr,32,2);
-
+    printf(">>>>AT+CIFSR returns: %s\r\n", ipAddr);
     if(NULL != strstr(ipAddr,"AT+CIFSR")) {
         _ip = str_to_ip(ipAddr+12);
         if(_ip != 0) {
-            return true;
+            //set to quick sending mode
+            printf(">>>>AT+CIPQSEND=1\r\n");
+            sendCmd("AT+CIPQSEND=1\r\n");
+            cleanBuffer(resp,96);
+            readBuffer(resp,96,DEFAULT_TIMEOUT);
+            if(NULL != strstr(resp,"OK")) {
+                return true;
+            }
         }
     }
+    
     return false;
 }
 
@@ -151,14 +243,15 @@
         return false;
     }
     if(ptl == TCP) {
-        sprintf(cmd, "AT+CIPSTART=%d,\"TCP\",\"%s\",%d\r\n",socket, host, port);
+        sprintf(cmd, "AT+CIPSTART=\"TCP\",\"%s\",\"%d\"\r\n", host, port);
     } else if(ptl == UDP) {
         sprintf(cmd, "AT+CIPSTART=%d,\"UDP\",\"%s\",%d\r\n",socket, host, port);
     } else {
         return false;
     }
+    
     sendCmd(cmd);
-    readBuffer(resp,96,2*DEFAULT_TIMEOUT);
+    readBuffer(resp,96,DEFAULT_TIMEOUT);
     if(NULL != strstr(resp,"CONNECT")) { //ALREADY CONNECT or CONNECT OK
         return true;
     }
@@ -185,24 +278,23 @@
 
 bool GPRS::is_connected(int socket)
 {
+    
     char cmd[16];
     char resp[96];
-    snprintf(cmd,16,"AT+CIPSTATUS=%d\r\n",socket);
-    sendCmd(cmd);
-    readBuffer(resp,sizeof(resp),DEFAULT_TIMEOUT);
-    if(NULL != strstr(resp,"CONNECTED")) {
-        //+CIPSTATUS: 1,0,"TCP","216.52.233.120","80","CONNECTED"
-        return true;
-    } else {
-        //+CIPSTATUS: 1,0,"TCP","216.52.233.120","80","CLOSED"
-        //+CIPSTATUS: 0,,"","","","INITIAL"
-        return false;
+    while(1){
+        snprintf(cmd,16,"AT+CIPSTATUS\r\n");
+        sendCmd(cmd);
+        readBuffer(resp,sizeof(resp),DEFAULT_TIMEOUT);
+        if(NULL != strstr(resp,"CONNECTED")) {
+            return true;
+        } else {
+            return false;
+        }
     }
 }
 
 void GPRS::reset()
 {
-
 }
 
 bool GPRS::close(int socket)
@@ -271,12 +363,15 @@
     char cmd[32];
     wait(1);
     if(len > 0){
-        snprintf(cmd,sizeof(cmd),"AT+CIPSEND=%d\r\n",socket);
-        if(0 != sendCmdAndWaitForResp(cmd,">",2,CMD)) {
+        snprintf(cmd,sizeof(cmd),"AT+CIPSEND\r\n");
+        if(0 != sendCmdAndWaitForResp(cmd,">",1,CMD)) {
+            
             return false;
         }
         sendCmd(str);
+        printf("Sending: %s\r\n", str);
         serialModem.putc((char)0x1a);
+        
     }
     return len;
 }
@@ -320,3 +415,30 @@
     }
     return ip;
 }
+bool GPRS::storePhoneNumber(char* atCNumValue){
+    char* leftDelimiter = "+";
+    char* rightDelimiter = "\"";
+    // find the left delimiter and use it as the beginning of the substring
+    const char* beginning = strstr(atCNumValue, leftDelimiter);
+    if(beginning == NULL)
+        return 1; // left delimiter not found
+
+    // find the right delimiter
+    const char* end = strstr(atCNumValue, rightDelimiter);
+    if(end == NULL)
+        return 2; // right delimiter not found
+
+    // offset the beginning by the length of the left delimiter, so beginning points _after_ the left delimiter
+    beginning += strlen(leftDelimiter);
+
+    // get the length of the substring
+    ptrdiff_t segmentLength = end - beginning;
+
+    // allocate memory and copy the substring there
+    //*_phoneNumber = (char*)malloc(segmentLength + 1);
+    strncpy(_phoneNumber, beginning, segmentLength);
+    (_phoneNumber)[segmentLength] = 0;
+    
+    printf("Phone Number: %s\r\n", _phoneNumber);
+    return 0; // success!
+}
\ No newline at end of file
diff -r 8c55dfcc9a7c -r 045cb766d9a5 GPRS/GPRS.h
--- a/GPRS/GPRS.h	Fri Sep 25 04:10:56 2015 +0000
+++ b/GPRS/GPRS.h	Wed Oct 21 19:41:42 2015 +0000
@@ -144,7 +144,13 @@
      *  @returns true if successful
      */
     bool gethostbyname(const char* host, uint32_t* ip);
-
+	
+	/** Parse the phone number from the AT command return value and store it
+	 *	@param atCNumValue the return value from the AT+CNUM AT Command
+	 * 	@return true if successful
+	 */
+	bool storePhoneNumber(char* atCNumValue);
+	
     int new_socket();
     uint16_t new_port();
     uint32_t _ip;
@@ -159,6 +165,7 @@
     const char* _apn;
     const char* _userName;
     const char* _passWord;
+    char* _phoneNumber;
 };
 
 #endif
diff -r 8c55dfcc9a7c -r 045cb766d9a5 GPRS/modem/modem.cpp
--- a/GPRS/modem/modem.cpp	Fri Sep 25 04:10:56 2015 +0000
+++ b/GPRS/modem/modem.cpp	Wed Oct 21 19:41:42 2015 +0000
@@ -161,7 +161,6 @@
 void Modem::sendCmdResp(const char* cmd)
 {
     serialModem.puts(cmd);
-    getResp();
 }
 void Modem::getResp()
 {
@@ -177,7 +176,7 @@
        timeCnt.stop();
        timeCnt.reset();
        buffer[count] = '\0';
-       printf("%s \n",buffer);
+       printf("Response:--%s--\r\n",buffer);
         for(int i = 0; i < count+2; i++) {
                 buffer[i] = NULL;
             }
@@ -221,7 +220,7 @@
 
     while(1) {
         if(serialModem.readable()) {
-            char c = serialModem.getc();
+            char c = serialModem.getc();         
             sum = (c==resp[sum]) ? sum+1 : 0;
             if(sum == len)break;
         }
@@ -231,15 +230,16 @@
             return -1;
         }
     }
+    
     timeCnt.stop();
     timeCnt.reset();
-
+    
     if(type == CMD) {
         while(serialModem.readable()) {
             char c = serialModem.getc();
         }
+        
     }
-
     return 0;
 }
 
diff -r 8c55dfcc9a7c -r 045cb766d9a5 GPRS/modem/modem.h
--- a/GPRS/modem/modem.h	Fri Sep 25 04:10:56 2015 +0000
+++ b/GPRS/modem/modem.h	Wed Oct 21 19:41:42 2015 +0000
@@ -25,7 +25,7 @@
 
 #include "mbed.h"
 #include "SDFileSystem.h"
-#define DEFAULT_TIMEOUT   	5
+#define DEFAULT_TIMEOUT 5
 
 enum DataType {
     CMD		= 0,
diff -r 8c55dfcc9a7c -r 045cb766d9a5 GSMLibrary.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GSMLibrary.h	Wed Oct 21 19:41:42 2015 +0000
@@ -0,0 +1,46 @@
+#ifndef GSMLIBRARY_H
+#define GSMLIBRARY_H
+
+#include "mbed.h"
+
+#define TIME_CONST 1    //Specify length of each GSM tick (currently 1 seconds in our debugger)
+#define SECONDS_TIMEOUT 30
+#define SMS_END_CHAR "\x1A"     //Character that must be appended to end of text message before it will be sent
+#define SMS_ESCAPE_CHAR "\x1A"  //Character that can be appended to end of text message to abort sending it
+
+enum gsm_states{GSM_INITIALIZE, 
+                    GSM_AT_OK,      //Make sure communication is established with GSM
+                    GSM_AT_CSQ,     //Check signal strength
+                    GSM_AT_CREG,    //Check if phone is connected to network
+                    GSM_AT_CNMI,    //Turn off incoming SMS notifications
+                    GSM_AT_CMGF,    //Change to text message mode
+                    GSM_READ_MSG,   //Check for new messages.
+                    GSM_AT_CMGS,    //Input phone number and indicate beginning of SMS message body
+                    GSM_AT_SENDSMS, //Write message, finish with SMS_END_CHAR
+                    GSM_DEL_R_MSGS  //Delete unread messages (if present)   
+                };
+
+//GSM state machine
+void gsm_tick();
+bool gsm_timeOut();
+void gsm_printState();
+void gsm_nextStateLogic();
+void gsm_mealyOutputs();
+
+//Initialize DMA data transfer, and UART3.
+void gsm_initialize();
+
+//returns 1 for ready to send again, 0 for busy.
+bool gsm_ready();
+
+//Have the GSM send data - L = long, S = short, hh/mm/ss for time, "lat ns" for latitute, "lon we" for longitude
+void gsm_send_data(float L, float Lref, float S, float Sref, int hh, int mm, int ss, float lat, char ns, float lon, char we);
+
+//Brings state machine back to initialize state (notice this is a bit different than the initialize function)
+//This will set flags to their initial values and prepare gsm to start anew.
+void gsm_reset();
+
+//For debugging: print registers related to DMA and UART setup
+void print_registers();
+
+#endif
\ No newline at end of file
diff -r 8c55dfcc9a7c -r 045cb766d9a5 MBed_Adafruit-GPS-Library.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MBed_Adafruit-GPS-Library.lib	Wed Oct 21 19:41:42 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mlee350/code/MBed_Adafruit-GPS-Library/#a23e3099bb0a
diff -r 8c55dfcc9a7c -r 045cb766d9a5 QAM.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/QAM.h	Wed Oct 21 19:41:42 2015 +0000
@@ -0,0 +1,33 @@
+#include "mbed.h"
+#include "math.h"
+#include "param.h"
+
+
+float LPF[FILTER_LENGTH] = {-0.0144708808511496,-0.000385188817745075,-0.000390533183235675,-0.000394742906792089,-0.000399769196519628,-0.000403738202294335,-0.000408404623158276,-0.000412113149650395,-0.000416462833527476,-0.000419815012719482,-0.000423797959228978,-0.000426739337854087,-0.000430334330303594,-0.000432832690421492,-0.000436010304838419,-0.000438015762483701,-0.000440725998487324,-0.000442176271462813,-0.000444366451120004,-0.000445200741523877,-0.000446824764367193,-0.000446985068265349,-0.000448006554506719,-0.000447442784206942,-0.000447849219199270,-0.000446533842477948,-0.000446356250904501,-0.000444298930233344,-0.000443635712144896,-0.000440904172137380,-0.000439959781942889,-0.000436697184341028,-0.000435806956375018,-0.000432172615546733,-0.000431753345765173,-0.000427687598858029,-0.000428156810812652,-0.000422747252741829,-0.000424187630414963,-0.000407818792155013,-0.000395501352613792,-0.000405744503950700,-0.000392851507058367,-0.000390382687328383,-0.000381121528334916,-0.000376496114768088,-0.000367538945283741,-0.000361525919288397,-0.000352310773450881,-0.000345231412211433,-0.000335566815920174,-0.000327541463775560,-0.000317294849082828,-0.000308353744912893,-0.000297429505735636,-0.000287581380689517,-0.000275914761004970,-0.000265156646491960,-0.000252692261710763,-0.000241008558077738,-0.000227700089453720,-0.000215083331568167,-0.000200913782464340,-0.000187389392522164,-0.000172384694451466,-0.000158020178787410,-0.000142244665767066,-0.000127136823721230,-0.000110658475023229,-9.48790548136458e-05,-7.76831002440304e-05,-6.11819123150781e-05,-4.30660620622803e-05,-2.56168041232741e-05,-6.17332989349961e-06,1.25088872664492e-05,3.37927012878936e-05,5.35608705831692e-05,7.59589602239430e-05,9.15368291316554e-05,0.000115204777102917,0.000138069211971015,0.000159190880367532,0.000182373449206352,0.000205067466595210,0.000228860953939147,0.000252562953392044,0.000277043582173064,0.000301679014228284,0.000326937646605074,0.000352496019331738,0.000378568482119590,0.000405024475185201,0.000431919761467725,0.000459260045317933,0.000486996257677674,0.000515223422553390,0.000543812348041683,0.000572911638300866,0.000602328160312027,0.000632248178590089,0.000662431004457176,0.000693100970238447,0.000723983335774392,0.000755351502448320,0.000786905176937580,0.000818981905467808,0.000851254211738706,0.000884129083715379,0.000917225959710777,0.000951002817600966,0.000984976999461651,0.00101962720509619,0.00105433282442391,0.00108958012424409,0.00112464418634772,0.00115993840154260,0.00119539198931307,0.00123186816927046,0.00127036077901721,0.00130541180260479,0.00134335225448012,0.00138072879053652,0.00141863315366209,0.00145663029979914,0.00149499706458300,0.00153361610136926,0.00157251046039164,0.00161168223712593,0.00165107252541929,0.00169074663426727,0.00173062458634377,0.00177079136483371,0.00181115593295544,0.00185179221443832,0.00189260160550475,0.00193364149890840,0.00197481806389987,0.00201618182472885,0.00205765641294420,0.00209929421544075,0.00214104214683175,0.00218295189552009,0.00222499505616725,0.00226720655336976,0.00230957893654704,0.00235209893435240,0.00239478098228574,0.00243752682581544,0.00248040445148945,0.00252320826984942,0.00256614456884563,0.00260887923650444,0.00265189493075013,0.00269464123994112,0.00273811141960323,0.00278127146884799,0.00282487273216248,0.00286725582554936,0.00291011668741703,0.00295400852337480,0.00299631315283477,0.00303968228399754,0.00308228214271367,0.00312544335611165,0.00316800503060222,0.00321092060767114,0.00325335212983191,0.00329604768194258,0.00333833065815270,0.00338080571964383,0.00342287984676659,0.00346506666392088,0.00350683252327144,0.00354864820837975,0.00359002966433764,0.00363143184222281,0.00367240631021559,0.00371339474804699,0.00375396921299398,0.00379455066286027,0.00383471907116473,0.00387486722320318,0.00391457835212350,0.00395421450957656,0.00399336963891983,0.00403239345178008,0.00407090689986944,0.00410927413031459,0.00414714356884360,0.00418491195887327,0.00422220071777701,0.00425944291055203,0.00429609837010503,0.00433271517977119,0.00436816038563848,0.00440392829477787,0.00443863216787577,0.00447419332340360,0.00450790720060468,0.00454199779778719,0.00457557942718267,0.00460866745561361,0.00464128935709596,0.00467348005622625,0.00470521813258529,0.00473655480891466,0.00476738158613443,0.00479778554290533,0.00482760230079293,0.00485697947442532,0.00488572614267468,0.00491404812783003,0.00494172982871532,0.00496901245787740,0.00499565014615655,0.00502189761027694,0.00504747871309519,0.00507265469059348,0.00509712658822537,0.00512116774916649,0.00514446385204792,0.00516731571406126,0.00518939504399896,0.00521104829385877,0.00523192156106234,0.00525241391733289,0.00527210766449571,0.00529145309701562,0.00530992168933153,0.00532803731039166,0.00534513592720032,0.00536190019920468,0.00537753105163574,0.00539305759593844,0.00540779717266560,0.00542178330942988,0.00543520553037524,0.00544764194637537,0.00546016823500395,0.00547122210264206,0.00548202730715275,0.00549201155081391,0.00550147471949458,0.00551019050180912,0.00551821896806359,0.00552552472800016,0.00553208775818348,0.00553797790780664,0.00554313324391842,0.00554766040295363,0.00555146159604192,0.00555464252829552,0.00555708399042487,0.00555888703092933,0.00555992824956775,0.00556031381711364,0.00555992824956775,0.00555888703092933,0.00555708399042487,0.00555464252829552,0.00555146159604192,0.00554766040295363,0.00554313324391842,0.00553797790780664,0.00553208775818348,0.00552552472800016,0.00551821896806359,0.00551019050180912,0.00550147471949458,0.00549201155081391,0.00548202730715275,0.00547122210264206,0.00546016823500395,0.00544764194637537,0.00543520553037524,0.00542178330942988,0.00540779717266560,0.00539305759593844,0.00537753105163574,0.00536190019920468,0.00534513592720032,0.00532803731039166,0.00530992168933153,0.00529145309701562,0.00527210766449571,0.00525241391733289,0.00523192156106234,0.00521104829385877,0.00518939504399896,0.00516731571406126,0.00514446385204792,0.00512116774916649,0.00509712658822537,0.00507265469059348,0.00504747871309519,0.00502189761027694,0.00499565014615655,0.00496901245787740,0.00494172982871532,0.00491404812783003,0.00488572614267468,0.00485697947442532,0.00482760230079293,0.00479778554290533,0.00476738158613443,0.00473655480891466,0.00470521813258529,0.00467348005622625,0.00464128935709596,0.00460866745561361,0.00457557942718267,0.00454199779778719,0.00450790720060468,0.00447419332340360,0.00443863216787577,0.00440392829477787,0.00436816038563848,0.00433271517977119,0.00429609837010503,0.00425944291055203,0.00422220071777701,0.00418491195887327,0.00414714356884360,0.00410927413031459,0.00407090689986944,0.00403239345178008,0.00399336963891983,0.00395421450957656,0.00391457835212350,0.00387486722320318,0.00383471907116473,0.00379455066286027,0.00375396921299398,0.00371339474804699,0.00367240631021559,0.00363143184222281,0.00359002966433764,0.00354864820837975,0.00350683252327144,0.00346506666392088,0.00342287984676659,0.00338080571964383,0.00333833065815270,0.00329604768194258,0.00325335212983191,0.00321092060767114,0.00316800503060222,0.00312544335611165,0.00308228214271367,0.00303968228399754,0.00299631315283477,0.00295400852337480,0.00291011668741703,0.00286725582554936,0.00282487273216248,0.00278127146884799,0.00273811141960323,0.00269464123994112,0.00265189493075013,0.00260887923650444,0.00256614456884563,0.00252320826984942,0.00248040445148945,0.00243752682581544,0.00239478098228574,0.00235209893435240,0.00230957893654704,0.00226720655336976,0.00222499505616725,0.00218295189552009,0.00214104214683175,0.00209929421544075,0.00205765641294420,0.00201618182472885,0.00197481806389987,0.00193364149890840,0.00189260160550475,0.00185179221443832,0.00181115593295544,0.00177079136483371,0.00173062458634377,0.00169074663426727,0.00165107252541929,0.00161168223712593,0.00157251046039164,0.00153361610136926,0.00149499706458300,0.00145663029979914,0.00141863315366209,0.00138072879053652,0.00134335225448012,0.00130541180260479,0.00127036077901721,0.00123186816927046,0.00119539198931307,0.00115993840154260,0.00112464418634772,0.00108958012424409,0.00105433282442391,0.00101962720509619,0.000984976999461651,0.000951002817600966,0.000917225959710777,0.000884129083715379,0.000851254211738706,0.000818981905467808,0.000786905176937580,0.000755351502448320,0.000723983335774392,0.000693100970238447,0.000662431004457176,0.000632248178590089,0.000602328160312027,0.000572911638300866,0.000543812348041683,0.000515223422553390,0.000486996257677674,0.000459260045317933,0.000431919761467725,0.000405024475185201,0.000378568482119590,0.000352496019331738,0.000326937646605074,0.000301679014228284,0.000277043582173064,0.000252562953392044,0.000228860953939147,0.000205067466595210,0.000182373449206352,0.000159190880367532,0.000138069211971015,0.000115204777102917,9.15368291316554e-05,7.59589602239430e-05,5.35608705831692e-05,3.37927012878936e-05,1.25088872664492e-05,-6.17332989349961e-06,-2.56168041232741e-05,-4.30660620622803e-05,-6.11819123150781e-05,-7.76831002440304e-05,-9.48790548136458e-05,-0.000110658475023229,-0.000127136823721230,-0.000142244665767066,-0.000158020178787410,-0.000172384694451466,-0.000187389392522164,-0.000200913782464340,-0.000215083331568167,-0.000227700089453720,-0.000241008558077738,-0.000252692261710763,-0.000265156646491960,-0.000275914761004970,-0.000287581380689517,-0.000297429505735636,-0.000308353744912893,-0.000317294849082828,-0.000327541463775560,-0.000335566815920174,-0.000345231412211433,-0.000352310773450881,-0.000361525919288397,-0.000367538945283741,-0.000376496114768088,-0.000381121528334916,-0.000390382687328383,-0.000392851507058367,-0.000405744503950700,-0.000395501352613792,-0.000407818792155013,-0.000424187630414963,-0.000422747252741829,-0.000428156810812652,-0.000427687598858029,-0.000431753345765173,-0.000432172615546733,-0.000435806956375018,-0.000436697184341028,-0.000439959781942889,-0.000440904172137380,-0.000443635712144896,-0.000444298930233344,-0.000446356250904501,-0.000446533842477948,-0.000447849219199270,-0.000447442784206942,-0.000448006554506719,-0.000446985068265349,-0.000446824764367193,-0.000445200741523877,-0.000444366451120004,-0.000442176271462813,-0.000440725998487324,-0.000438015762483701,-0.000436010304838419,-0.000432832690421492,-0.000430334330303594,-0.000426739337854087,-0.000423797959228978,-0.000419815012719482,-0.000416462833527476,-0.000412113149650395,-0.000408404623158276,-0.000403738202294335,-0.000399769196519628,-0.000394742906792089,-0.000390533183235675,-0.000385188817745075,-0.0144708808511496};
+
+
+float QAM(float *sI, float *sQ){
+    
+    float total = 0.0;
+    float I = 0.0;
+    float Q = 0.0;
+    
+    for ( int i = 0; i < SAMPLE_LENGTH; i+=DEC_FACTOR){
+        I = 0.0;
+        Q = 0.0;
+        for (int j = 0; j < FILTER_LENGTH; j++){
+            if(i-j > 0 && i > 0 && j > 0){
+                I = I + (sI[ i - j] * LPF[ j ]);
+                Q = Q + (sQ[ i - j] * LPF[ j ]);
+            }       
+        }
+        
+        total = total + (I*I + Q*Q); 
+    
+    }
+
+    total = total/3000;
+        
+    return total;
+}
+
diff -r 8c55dfcc9a7c -r 045cb766d9a5 SDFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Wed Oct 21 19:41:42 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/SDFileSystem/#7b35d1709458
diff -r 8c55dfcc9a7c -r 045cb766d9a5 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Oct 21 19:41:42 2015 +0000
@@ -0,0 +1,352 @@
+/* Copyright (c) 2010-2011 mbed.org, MIT License
+*
+* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
+* and associated documentation files (the "Software"), to deal in the Software without
+* restriction, including without limitation the rights to use, copy, modify, merge, publish,
+* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice shall be included in all copies or
+* substantial portions of the Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
+* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+#pragma once
+#include "mbed.h"
+#include "math.h"
+#include "MBed_Adafruit_GPS.h"
+#include "SDFileSystem.h"
+#include "QAM.h"
+#include "GPRSInterface.h"
+#include "param.h"
+#include "stdlib.h"
+
+#define NUM_SIZE 250
+/** On many platforms USBTX/USBRX overlap with serial on D1/D0 pins and enabling the below will interrupt the communication.
+ *  You can use an LCD display to print the values or store them on an SD card etc.
+ */
+DigitalOut led_red(LED_RED);
+Serial pc(USBTX, USBRX);
+//Serial gsm(D1,D0);
+
+/**************************************************
+ **          SD FILE SYSTEM                       **
+ **************************************************/
+//SDFileSystem sdModem(PTE3, PTE1, PTE2, PTE4, "sd"); //MOSI, MISO, SCLK, SSEL. Tested on K64F, correct pins.
+FILE *fpData;
+FILE *fpLog;
+
+/**************************************************
+ **          GPS                                 **
+ **************************************************/
+Serial * gps_Serial;
+
+/**************************************************
+ **          GPRS                                 **
+ **************************************************/
+/**
+ * D1 - TX pin (RX on the WiFi side)
+ * D0 - RX pin (TX on the WiFi side)
+ * 19200 - Baud rate
+ * "apn" - APN name
+ * "username" - APN username
+ * "password" - APN passowrd
+ */
+GPRSInterface eth(D1,D0, 19200, "ndo","","");
+/**************************************************
+ **          SENSOR INPUTS                       **
+ **************************************************/
+AnalogIn An(A0);
+AnalogIn AnRef(A2);
+Ticker sample_tick;
+bool takeSample = false;
+void tick(){takeSample = true;}
+
+/**************************************************
+ **          SIN OUTPUT                          **
+ **************************************************/
+AnalogOut dac0(DAC0_OUT);
+int sinRes = (int)1/(CARRIER_FREQ*TIME_CONST);
+float sinWave[SIN_LENGTH] = {};
+int sinIndex = 0;
+
+
+/**************************************************
+ **          QAM                                 **
+ **************************************************/
+float sQ[SAMPLE_LENGTH] = {};
+float sI[SAMPLE_LENGTH] = {};
+float sRefQ[SAMPLE_LENGTH] = {};
+float sRefI[SAMPLE_LENGTH] = {};
+
+float Iarray[SAMPLE_LENGTH] = {};
+float Qarray[SAMPLE_LENGTH] = {};
+int sampleIndex = 0;
+float I = 0;
+float Q = 0;
+float lon = 0;
+float lonRef = 0;
+
+/*Global Variables */
+char c;
+int s;
+bool run = 0;
+bool fil = 0;
+float filtered = 0;
+float filteredRef = 0;
+char gsm_header[250]; //String storing SMS message that will be sent (add 250 length to give leeway)
+char gsm_msg[250];
+char num[NUM_SIZE];   //Temporary string storage to help with concatenation of strings
+   
+void buildIQ(){
+    for(int i = 0; i < SAMPLE_LENGTH; i++){
+        Iarray[i] = cos(2*PI*CARRIER_FREQ*i*TIME_CONST);
+        Qarray[i] = -sin(2*PI*CARRIER_FREQ*i*TIME_CONST);
+    }
+}
+
+void create_sinWave(){
+    int i = 0;
+    for(i = 0; i < SIN_LENGTH; i++){
+        sinWave[i] = 0.25 * sin(2.0*PI*i/sinRes) + 0.75;
+    }
+}
+void init(Adafruit_GPS myGPS){
+    
+    //fprintf(fpLog, "%s\r\n", ":)\r\n");
+ 
+    //fprintf(fpLog, "%s\r\n", "Initializing the GPS\r\n");
+
+    myGPS.begin(9600);
+    myGPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
+    myGPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);
+    myGPS.sendCommand(PGCMD_ANTENNA);
+    //fprintf(fpLog, "%s\r\n", "GPS Initialized\r\n");
+    
+    // Initialize filtering structures.
+    buildIQ();
+    create_sinWave();
+    
+    
+    
+    //Intialize the dhcp (or die trying)
+    s = eth.init();
+    if (s != NULL) {
+        printf(">>> Could not initialise. Halting!\n");
+        exit(0);
+    }
+    
+    //Check the SIM card
+    s= eth.preInit();
+    if(s == true) {
+        //fprintf(fpLog, "%s\r\n", "SIM Card is good!\r\n");
+    } else {
+        //fprintf(fpLog, "%s\r\n", "check your baud rate\r\n");
+    }
+}
+void gatherData(Adafruit_GPS myGPS){     
+        //sample
+        if(takeSample){
+            
+            dac0 = sinWave[sinIndex];
+            
+            lon = An.read();
+            lonRef = AnRef.read();
+            
+            I = Iarray[sampleIndex];
+            Q = Qarray[sampleIndex];
+            sI[sampleIndex] = lon*I;
+            sQ[sampleIndex] = lon*Q;
+            sRefI[sampleIndex] = lonRef*I;
+            sRefQ[sampleIndex] = lonRef*Q;
+            
+            takeSample = false;
+            sinIndex++;
+            if((sinIndex+1) > SIN_LENGTH){
+                sinIndex = 0;
+            }
+            
+            sampleIndex++;
+            if(sampleIndex+1 > SAMPLE_LENGTH){
+                fil = 1;
+            }
+        }
+        //Filter
+        if(fil==1){
+            
+            fil = 0;
+            run = 1;
+            sampleIndex = 0;
+            filtered = 15*QAM(sI, sQ);
+            filteredRef = QAM(sRefI, sRefQ);
+        }  
+        
+        c = myGPS.read();
+        if ( myGPS.newNMEAreceived() ) {
+            if ( !myGPS.parse(myGPS.lastNMEA()) ) {
+                //fprintf(fpLog, "%s\r\n", "Couldn't parse the GPS Data\r\n");
+            }
+        }
+        if(run){
+            run = 0;
+            printf("Logged Data\r\n");
+            /*fprintf(fpLog, "15CM: %f, ", filtered);
+            fprintf(fpLog, "15CM Reference: %f\r\n", filteredRef);
+            fprintf(fpLog, "15CM / 15CM Refernce: %f\r\n", (filteredRef ? (filtered/filteredRef) : 0));
+            fprintf(fpLog, "GPS TIME: %d:%d:%d \r\n", myGPS.hour-6, myGPS.minute, myGPS.seconds);*/
+            
+            if (myGPS.fix){
+               printf("Lat: %5.2f%c, Long: %5.2f%c\r\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
+               //fprintf(fpLog, "Lat: %5.2f%c, Long: %5.2f%c\r\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
+            }
+            else{
+                printf("No GPS FIX\r\n");
+                /*fprintf(fpLog, "%s\r\n", "No GPS fix\r\n");
+                fprintf(fpLog, "%s\r\n", "--------------------------------\r\n");*/
+            }
+            
+            /*fpData = fopen("/sd/data.txt", "a");
+            if (fpData != NULL){
+                
+                fprintf(fpData, "%f, ", filtered);
+                fprintf(fpData, "%f, ", filteredRef);
+                fprintf(fpData, "%d:%d:%d\r\n", myGPS.hour-6, myGPS.minute, myGPS.seconds);
+                if (myGPS.fix) fprintf(fpData, "%5.2f%c, %5.2f%c\r\n", myGPS.latitude, myGPS.lat, myGPS.longitude, myGPS.lon);
+                else           fprintf(fpData, "No_GPS_fix\r\n");
+                
+                fclose(fpData);    
+            }*/
+            
+        }
+    
+}
+int main()
+{
+    //set the baud rates
+    //gsm.baud(19200);
+    
+    gps_Serial = new Serial(PTC4,PTC3); ////Serial gsm(D1,D0);
+    Adafruit_GPS myGPS(gps_Serial);
+    
+    //Initialize SD Card with log and data
+    /*fpLog = fopen("/sd/log.txt", "a");
+    if (fpLog != NULL){
+        fprintf(fpLog, "%s\r\n", "--------------- DCS LOG ------------------");
+    }
+    fpData = fopen("/sd/data.txt", "a");
+    if (fpData != NULL){
+        fprintf(fpData, "%s", "--------------- DCS DATA ------------------");
+    }
+    
+    //Successful Connection Message
+    fprintf(fpLog, "%s\r\n", "---DPG Connection Successful!---\r\n");*/
+    
+    //initialize gps, gprs, sd card etc...
+    init(myGPS);
+    
+    //fprintf(fpLog, "%s\r\n", ">>> Get IP address...\r\n");
+    while (1) {
+        s = eth.connect(); // Connect to network
+        if (s == false || s < 0) {
+            printf(">>> Could not connect to network. Retrying!\r\n");
+            wait(3);
+        } else {
+            break;
+        }
+    }
+    //fprintf(fpLog, ">>> Got IP address: %s\r\n", eth.getIPAddress());
+    
+    //fprintf(fpLog, "%s\r\n", ">>> Create a TCP Socket Connection\r\n");
+    TCPSocketConnection sock;
+    sock.set_blocking(true,5000);
+     
+    sock.connect("api.pushingbox.com",80);
+    
+    //fprintf(fpLog, "%s\r\n", "Gathering Data...\r\n");
+    while(1){
+        
+        //take a sample
+        tick();
+        gatherData(myGPS);
+        //if(!myGPS.fix){
+            printf("Done Gathering Data\r\n");
+            
+            //fprintf(fpLog, "%s\r\n", "Begin Sending data...\r\n");
+            //Concatenate data
+            gsm_msg[0] = NULL;
+            gsm_header[0] = NULL;
+            int contentLength = 0;
+            snprintf(num, NUM_SIZE, "&phone=%s", "3852368101");
+            contentLength += strlen(num);
+            strcat(gsm_msg, num);
+            snprintf(num, NUM_SIZE, "&data=%f", filtered);
+            contentLength += strlen(num);
+            strcat(gsm_msg, num);
+            snprintf(num, NUM_SIZE, "&dataRef=%f", filteredRef);
+            contentLength += strlen(num);
+            strcat(gsm_msg, num);
+            snprintf(num, NUM_SIZE, "&dataRatio=%f", (filteredRef ? (filtered/filteredRef) : 0));
+            contentLength += strlen(num);
+            strcat(gsm_msg, num);
+            snprintf(num, NUM_SIZE, "&time=%02d:%02d:%02d", myGPS.hour, myGPS.minute, myGPS.seconds);   //If there is no data from GPS, the time will just be "00:00:00" (that is okay)
+            contentLength += strlen(num);
+            strcat(gsm_msg, num);
+            if (myGPS.lat != NULL) //If there is a gps fix (i.e. the gps has data on our location), ns will be set
+            { 
+                snprintf(num, NUM_SIZE, "&latitude=%.4f&longitude=%.4f", (myGPS.lat == 'N') ? myGPS.latitude : -myGPS.latitude, (myGPS.lon == 'E') ? myGPS.longitude : -myGPS.longitude);   //Use + or - rather than N/S, E/W
+                contentLength += strlen(num);
+                strcat(gsm_msg, num);
+            }
+            else {
+                snprintf(num, NUM_SIZE,"&latitude=0&longitude=0");
+                strcat(gsm_msg, num);    //Otherwise just send 0's for latitude and longitude
+                contentLength += strlen(num);
+            }
+        
+            
+            //header information    
+            snprintf(num, NUM_SIZE, "%s", "POST /pushingbox?devid=v941C443DE0C7B14");
+            strcat(gsm_header, num);
+            strcat(gsm_header, gsm_msg);
+            snprintf(num, NUM_SIZE, "%s\r\n"," HTTP/1.1");
+            strcat(gsm_header, num);
+            snprintf(num, NUM_SIZE, "%s\r\n","Host: api.pushingbox.com");
+            strcat(gsm_header, num);
+            snprintf(num, NUM_SIZE, "%s\r\n","Connection: Keep-Alive");
+            strcat(gsm_header, num);
+            snprintf(num, NUM_SIZE, "%s\r\n","User-Agent: FRDM-KD64");
+            strcat(gsm_header, num);
+            //must have two blank lines after so the server knows that this is the end of headers
+            snprintf(num, NUM_SIZE, "Content-Length: %d\r\n\r\n\r\n", contentLength);
+            strcat(gsm_header, num);
+            
+            //fprintf(fpLog, "%s\r\n", ">>> Sending data to the server: %s\r\n",gsm_header);
+            int result = sock.send_all(gsm_header, contentLength);
+            //sock.set_blocking(false);
+            if (result > 0) {
+                //fprintf(fpLog, "%s\r\n", ">>> Successfully Sent Data to Server\r\n");
+                printf("Successfully send data\r\n");
+            } else {
+                //fprintf(fpLog, "%s\r\n", ">>> Failed to Send Data, Error Code: %d \r\n",result);
+                printf("Data Not Sent!! Content-Length:%d\r\n", contentLength);
+            }
+            
+            //check that we are still connected (if not reconnect)
+            //sock.close();
+            //printf("end of program\n");
+            // Disconnect from network
+            eth.disconnect();
+            //return 0;
+            /*}
+        else{
+                fprintf(fpLog, "%s\r\n", ">>>No GPS Fix\r\n");
+        }*/
+        //wait(4);
+    }
+    
+}
+
diff -r 8c55dfcc9a7c -r 045cb766d9a5 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Oct 21 19:41:42 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9ad691361fac
\ No newline at end of file
diff -r 8c55dfcc9a7c -r 045cb766d9a5 param.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/param.h	Wed Oct 21 19:41:42 2015 +0000
@@ -0,0 +1,9 @@
+#define SAMPLE_LENGTH       6000 
+#define SAMPLE_RATE         10000
+#define SIN_LENGTH          500
+#define OUTAVG_LENGTH       100
+#define CARRIER_FREQ        220
+#define TIME_CONST          0.0001
+#define PI                  3.14159265
+#define FILTER_LENGTH       513
+#define DEC_FACTOR          2 
\ No newline at end of file