aaaa
Dependencies: SeeedStudioTFTv2 TFT_fonts mbed
Fork of Seeed_TFT_Touch_Shield by
Revision 11:575dfd388778, committed 2014-10-26
- Comitter:
- uswickra
- Date:
- Sun Oct 26 08:41:39 2014 +0000
- Parent:
- 10:5ea126441b8a
- Child:
- 12:f27b67e10b0c
- Commit message:
- working version..
Changed in this revision
--- a/Modem.cpp Sat Oct 25 23:43:01 2014 +0000 +++ b/Modem.cpp Sun Oct 26 08:41:39 2014 +0000 @@ -24,14 +24,16 @@ /*********************************************** Utility/debug Functions ***********************************************/ +void Modem::copy_msg(){ + strcpy(messageCopyBuffer, messageBuffer); + cleanBuffer(messageBuffer, SMS_MAX_LENGTH); + mTypeState = 0; + mIndex = 0; +} int Modem::updateBuffer(char c){ -// messageBuffer[mIndex] = c ; -// mIndex = (mIndex + 1) % SMS_MAX_LENGTH ; + int messageType = MESSAGE_NONE; -// if(mIndex == 0 ){ -// cleanBuffer(messageBuffer, SMS_MAX_LENGTH); -// } if(mTypeState == 0){ if(c == 'R'){ mTypeState = 01 ; @@ -65,7 +67,14 @@ if(c != ':'){ mTypeState = 0 ; }else { - mTypeState = 15 ; + mTypeState = 15 ; + messageBuffer[mIndex++] = '+'; + messageBuffer[mIndex++] = 'C'; + messageBuffer[mIndex++] = 'M'; + messageBuffer[mIndex++] = 'T'; + messageBuffer[mIndex++] = ':'; +// serial_modem.puts("AT\r\n"); +// check_AT(); } } else if (mTypeState == 15){ @@ -86,9 +95,11 @@ mTypeState = 16 ; }else { mTypeState = 0 ; + messageBuffer[mIndex] = '\0' ; messageType = MESSAGE_SMS ; - strcpy(messageCopyBuffer,messageBuffer); - cleanBuffer(messageBuffer, SMS_MAX_LENGTH); +// strcpy(messageCopyBuffer,messageBuffer); +// cleanBuffer(messageBuffer, SMS_MAX_LENGTH); + mIndex = 0 ; } } @@ -113,12 +124,108 @@ messageType = MESSAGE_RING ; } } - - return messageType; } +/* +int Modem::updateBuffer(char c){ +// messageBuffer[mIndex] = c ; +// mIndex = (mIndex + 1) % SMS_MAX_LENGTH ; + int messageType = MESSAGE_NONE; +// if(mIndex == 0 ){ +// cleanBuffer(messageBuffer, SMS_MAX_LENGTH); +// } + if(mTypeState == 0){ + if(c == 'R'){ + mTypeState = 01 ; + }else if (c == '+'){ + mTypeState = 11 ; + } + } +// Handling the SMS MESSAGE + else if (mTypeState == 11){ + if(c != 'C'){ + mTypeState = 0 ; + }else { + mTypeState = 12 ; + } + } + else if (mTypeState == 12){ + if(c != 'M'){ + mTypeState = 0 ; + }else { + mTypeState = 13 ; + } + } + else if (mTypeState == 13){ + if(c != 'T'){ + mTypeState = 0 ; + }else { + mTypeState = 14 ; + } + } + else if (mTypeState == 14){ + if(c != ':'){ + mTypeState = 0 ; + }else { + mTypeState = 15 ; + messageBuffer[mIndex++] = '+'; + messageBuffer[mIndex++] = 'C'; + messageBuffer[mIndex++] = 'M'; + messageBuffer[mIndex++] = 'T'; + messageBuffer[mIndex++] = ':'; + messageType = MESSAGE_SMS ; + } + } + else if (mTypeState == 15){ + messageBuffer[mIndex] = c ; + //next index + mIndex = (mIndex + 1) % SMS_MAX_LENGTH ; + if(c != '\n'){ + mTypeState = 15 ; + }else { + mTypeState = 16 ; + } + } + else if (mTypeState == 16){ + messageBuffer[mIndex] = c ; + //next index + mIndex = (mIndex + 1) % SMS_MAX_LENGTH ; + if(c != '\r'){ + mTypeState = 16 ; + }else { + mTypeState = 0 ; +// messageType = MESSAGE_SMS ; + } + } + +// /Handling the RING + else if (mTypeState == 01){ + if(c != 'I'){ + mTypeState = 0 ; + }else { + mTypeState = 02 ; + } + }else if (mTypeState == 02){ + if(c != 'N'){ + mTypeState = 0 ; + }else { + mTypeState = 03 ; + } + }else if (mTypeState == 03){ + if(c != 'G'){ + mTypeState = 0 ; + }else { + mTypeState = 0 ; + messageType = MESSAGE_RING ; + } + } + + + return messageType;*/ +//} + int Modem::loopHandle(void) { char gprsBuffer[100]; @@ -256,7 +363,7 @@ int ret = sendCmdWaitResp("AT+CPIN?\r\n","+CPIN: READY", 5); //debug code - debug_cmd_buffer(); +// debug_cmd_buffer(); if(ret == 0) { return -1 ; @@ -274,7 +381,7 @@ ret = sendCmdWaitResp("AT+CMGF=1\r\n","OK", 5); } //debug code - debug_cmd_buffer(); +// debug_cmd_buffer(); if(ret == 0) { return -1 ; } @@ -292,7 +399,7 @@ sendCmdWaitResp("AT+COLP=1\r\n","OK", 5); //send actual call wait(1); - debug_cmd_buffer(); +// debug_cmd_buffer(); int ret = 0 ; char temp[30]; @@ -304,7 +411,7 @@ ret = sendCmdWaitResp(temp,"OK", 5); // ret = sendCmdWaitResp("\r\nATD+13174806512;\r\n","OK", 5); //debug code - debug_cmd_buffer(); +// debug_cmd_buffer(); if(ret == 0) { return -1 ; @@ -327,7 +434,7 @@ { int ret = sendCmdWaitResp("AT+CCLK?\r\n","OK", 5); //if returned OK - debug_cmd_buffer(); +// debug_cmd_buffer(); if(ret == 1) { char *pattern = "+CCLK:"; int index = find_pattern_end(pattern, read_buffer, BUF_SIZE); @@ -346,9 +453,9 @@ int Modem::send_sms(char* number, char* msg) { char temp[60]; - while(read_device_ready()) { - char c = read_device(); - } +// while(read_device_ready()) { +// char c = read_device(); +// } if(number == NULL) { snprintf(temp, 60, "AT+CMGS=\"%s\"\r\n",default_number); @@ -357,12 +464,14 @@ } sendCmdWaitResp(temp, ">", 5); - debug_cmd_buffer(); +// debug_cmd_buffer(); wait(3); //now write the actual message - write_device_str(msg); + serial_modem.puts(msg); +// write_device_str(msg); //final ctrl+z character in ascii - write_device((char)0x1a); +// write_device((char)0x1a); + serial_modem.putc((char)0x1a); return 1 ; } @@ -376,7 +485,7 @@ read_trail = false; wait(3); - debug_cmd_buffer(); +// debug_cmd_buffer(); //if returned OK // if(ret == 1) { char *pattern = "+CMT:";
--- a/Modem.h Sat Oct 25 23:43:01 2014 +0000 +++ b/Modem.h Sun Oct 26 08:41:39 2014 +0000 @@ -31,6 +31,7 @@ char messageBuffer[SMS_MAX_LENGTH]; char messageCopyBuffer[SMS_MAX_LENGTH]; int updateBuffer(char c); + void copy_msg(); int mIndex ; int mTypeState ;
--- a/main.cpp Sat Oct 25 23:43:01 2014 +0000 +++ b/main.cpp Sun Oct 26 08:41:39 2014 +0000 @@ -40,23 +40,29 @@ #define PIN_CS_SD D4 Timer t; -Serial pc(USBTX,USBRX); +//Serial pc(USBTX,USBRX); +Serial pc(SERIAL_TX, SERIAL_RX); + SeeedStudioTFTv2 TFT(PIN_XP, PIN_XM, PIN_YP, PIN_YM, PIN_MOSI, PIN_MISO, PIN_SCLK, PIN_CS_TFT, PIN_DC_TFT, PIN_BL_TFT, PIN_CS_SD); -#define PHONE_NUMBER "+13174806512" +#define PHONE_NUMBER "+12246781239" #include "Modem.h" +void cleanBuffer(char *buffer, int count); + Modem gsm (D10, D2, 19200, PHONE_NUMBER); DigitalOut modem_power(D9); char* cmd = NULL; -int type = 0 ; -int int_state = 1 ; +volatile int type = 0 ; +volatile int disable = 0 ; +volatile int int_state = 0 ; +/* void rxCallback() { //__disable_irq(); if(gsm.serial_modem.readable()){ char c = gsm.serial_modem.getc(); type = gsm.updateBuffer(c); -// pc.putc(c); + pc.putc(c); if(int_state == 1 && type == MESSAGE_RING){ // pc.putc('R'); cmd = "Ring" ; @@ -65,6 +71,30 @@ } if(int_state == 1 && type == MESSAGE_SMS){ // pc.putc('S'); + cmd = "RecvM" ; + pc.putc('S'); + int_state = 0 ; + } + + } +//__enable_irq(); +}*/ + +void rxCallback() { +//__disable_irq(); + if(!int_state && gsm.serial_modem.readable()){ + char c = gsm.serial_modem.getc(); + type = gsm.updateBuffer(c); +// pc.putc(c); + if(type == MESSAGE_RING){ +// pc.putc('R'); + cmd = "Ring" ; + int_state = true; + } + if(type == MESSAGE_SMS){ +// pc.putc('S'); + cmd = "RecvM" ; + int_state = true; } } @@ -338,6 +368,8 @@ void init_modem(){ + modem_power = 0 ; + wait(5); modem_power = 1 ; wait(1); // gsm.serial_modem.attach(&messageHandle); @@ -352,6 +384,7 @@ int main() { point p; +// pc.baud(115200); bool isMsg = false; char numbuffer[140]; char msgbuffer[140]; @@ -362,6 +395,7 @@ TFT.cls(); //initialize the modem - may take few seconds init_modem(); + pc.printf("\r\n start \r\n"); while(true) { @@ -538,12 +572,13 @@ TFT.foreground(Red); TFT.locate(60,280); TFT.printf("Hang Up"); - int_state = 0 ; +// int_state = 0 ; while(strcmp(cmd, "Make") == 0) { if(TFT.getTouch(p) == TFT.YES && p.x >= 6300 && p.x <= 7250){ gsm.hangup_phone(); - int_state = 1 ; +// int_state = 1 ; + int_state = false ; cmd = "Back"; } @@ -557,9 +592,14 @@ TFT.foreground(White); TFT.cls(); TFT.locate(90,60); - TFT.printf("Text %s",msgbuffer); + TFT.printf("Sending number : %s ", numbuffer, msgbuffer); +// int_state = 0 ; + int_state = true ; + gsm.send_sms(numbuffer, msgbuffer); TFT.locate(90,95); - TFT.printf("Sent to %s!",numbuffer); + TFT.printf("Done Text... "); +// int_state = 1; + int_state = false ; wait(2.5); cmd = "Back"; } @@ -652,7 +692,8 @@ //hang up cmd = "Back"; gsm.hangup_phone(); - int_state = 1 ; +// int_state = 1 ; + int_state = false ; break; } @@ -676,13 +717,72 @@ if(TFT.getTouch(p) == TFT.YES && p.x >= 6300 && p.x <= 7250){ cmd = "Back"; gsm.hangup_phone(); - int_state = 1 ; +// int_state = 1 ; + int_state = false ; } } } } else if(strcmp(cmd, "RecvM") == 0) - {} + { + TFT.background(White); + TFT.foreground(Blue); + TFT.cls(); + TFT.set_font((unsigned char*) Arial24x23); + char *start_pos, *end_pos, *msg_pos; + /* + pc.putc('T'); + wait(2); +// pc.puts(gsm.messageBuffer ); + pc.putc('U'); + __disable_irq(); + gsm.copy_msg(); + __enable_irq();*/ + + pc.putc('S'); + pc.printf("[SMS] : %s : \r\n", gsm.messageBuffer); + + start_pos = strstr(gsm.messageBuffer, "+CMT: \""); + + TFT.locate(0,5); + TFT.printf("copyBuf %s \r\n",gsm.messageCopyBuffer); + + char txtnum[20]; + cleanBuffer(txtnum,20); + char recv_msg[140]; + cleanBuffer(recv_msg,140); + start_pos += 7; + if(strstr(start_pos,"\",") != NULL) + { + end_pos = strstr(start_pos,"\","); + strncpy(txtnum,start_pos,(end_pos - start_pos)); + TFT.locate(0,5); + TFT.printf("\r\nFrom: %s \r\n",txtnum); + } + if(strstr(start_pos,"\n") != NULL) + { + msg_pos = strstr(start_pos,"\n"); + if(strstr(msg_pos+1,"\n") != NULL) + { + end_pos = strstr(msg_pos+1,"\n"); + strncpy(recv_msg,msg_pos+1,(end_pos - msg_pos - 1)); + TFT.locate(0,100); + TFT.printf("Message: %s\r\n",recv_msg); + } + } + TFT.line(0,270,240,270,Red); + TFT.foreground(Blue); + TFT.locate(60,280); + TFT.set_font((unsigned char*) Arial24x23); + TFT.printf("OK"); + while(strcmp(cmd, "RecvM") == 0) + { + if(TFT.getTouch(p) == TFT.YES && p.x >= 6300 && p.x <= 7250) + cmd = "Back"; +// int_state = 1 ; + int_state = false ; + } + } } }