tester
Fork of GPRSInterface by
Diff: GPRS/modem/modem.cpp
- Revision:
- 10:698c04e25c6b
- Parent:
- 0:8ccbd963e74d
--- a/GPRS/modem/modem.cpp Fri Jul 25 10:42:42 2014 +0000 +++ b/GPRS/modem/modem.cpp Fri Sep 25 03:35:58 2015 +0000 @@ -21,7 +21,51 @@ */ #include "modem.h" +//Serial pc(USBTX,USBRX); +SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); //MOSI, MISO, SCLK, SSEL. Tested on K64F, correct pins. +AnalogIn LM35(PTB2); +// added by Noah Milam +void Modem::gprs_response() +{ + printf("\nlistening for client\n"); + char buffer[100]; + int count = 0; + + mkdir("/sd/mydir", 0777); // makes directory if needed + FILE *fp = fopen("/sd/mydir/chemData.csv", "w"); // creats new file to write + fprintf(fp,"phone Number,chem data, latitude,longitude\n"); // writes in a header for the table + fclose(fp); // closes file + + while(1) + { + if(serialModem.readable()) { + + while(serialModem.readable()) { + char c = serialModem.getc(); + buffer[count++] = c; + } + } + if(buffer[0] != '\0'){ + buffer[count] = '\0'; + FILE *fp = fopen("/sd/mydir/chemData.csv", "a"); // opens file to append it + fprintf(fp,"%s\n",buffer);//writes to file + fclose(fp); // closes file + printf("%s \n",buffer); + } + for(int i = 0; i < count+2; i++) {buffer[i] = NULL;} + count = 0; + } +} +void Modem::wait_for_sms(){ + printf("waiting for message\n"); + while(1){ + if(serialModem.readable()){ + return; + } + } +} +//end added by Noah Milam char Modem::readByte(void) { return serialModem.getc(); @@ -63,7 +107,45 @@ { serialModem.puts(cmd); } +void Modem::sendCmdResp(const char* cmd) +{ + serialModem.puts(cmd); + getResp(); +} +void Modem::getResp() +{ + char buffer[100]; + int count = 0; + timeCnt.start(); + while(timeCnt.read() < 5) + { while(serialModem.readable()) { + char c = serialModem.getc(); + buffer[count++] = c; + } + } + timeCnt.stop(); + timeCnt.reset(); + buffer[count] = '\0'; + printf("%s \n",buffer); + for(int i = 0; i < count+2; i++) { + buffer[i] = NULL; + } + count = 0; +} +void Modem::store_response() +{ + timeCnt.start(); + while(timeCnt.read() < 20) + { while(serialModem.readable()) + { + char c = serialModem.getc(); + printf(&c); + } + } + timeCnt.stop(); + timeCnt.reset(); +} void Modem::sendATTest(void) { sendCmdAndWaitForResp("AT\r\n","OK",DEFAULT_TIMEOUT,CMD);