CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

get SMS message from a modem using a pic

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
angel



Joined: 19 Oct 2004
Posts: 40

View user's profile Send private message

get SMS message from a modem using a pic
PostPosted: Tue Feb 21, 2006 9:42 am     Reply with quote

Hello
I am expecting a modem to send and get SMS messages.
I am preparing a test program to read SMS messages from the modem. When a SMS message will arrive to the modem, this will interrupt my PIC 200 ms before sending the message (so it would not be necessary a UART interrupt). But I don't know if the modem sends the message in 2 lines or 1 line. I mean I don't know if the message is sent using two \r. In this case, I would like to use the code :
-------------------------------------------------
if (kbhit(U12)){ //first line
delay_ms(1000);//wait for 1 second
if (kbhit(U12)){//second line
gets(message,U12);
}
}
----------------------------------------------------
has anyone experience about getting SMS messages?
is this code the best way to read a SMS message from the modem?
asmallri



Joined: 12 Aug 2004
Posts: 1636
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue Feb 21, 2006 10:32 am     Reply with quote

SMS messages are both unstructured and vendor dependant. There are no <CR> <LF> characters unless your application sent them. You will have to test it on your target modem.

Reading the messages is not enough, you must delete the message as well, if not the sms message store will eventually fill and you will not receive any more messages.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
angel



Joined: 19 Oct 2004
Posts: 40

View user's profile Send private message

example
PostPosted: Wed Feb 22, 2006 4:40 am     Reply with quote

For example
After using the command AT+CMGR=1, I hope to receive :

+CMGR: "REC READ","609","02/02/27,18:166:51+40"
Here some message

OK


So 3 lines. If there are 3 lines is because in the message there are <CR> isn't it? And I was thinking to use the CCS command kbhit because it reads a string up to a <CR> is found.
Is all that correct? do you know other better way to read "Here some message" ?
After that I will remove the message in the modem using the AT+CMGD=1 command.
asmallri



Joined: 12 Aug 2004
Posts: 1636
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Wed Feb 22, 2006 5:25 am     Reply with quote

The command acknowledgment format depends on the modem implemetation. A command echo will be depend on how the modem is configured. Similarly the 'OK <CR>' or 'OK <CR><LF>' sequence will depend on how you have configured the modem. These may be suppressed. For a commercial product you cannot rely on them being present unless you specifically send an initialization sequence to the modem every time the PIC is powered up to allow for the fact that a modem may be replaced in service.

The command format for reading an SMS message depends on the modem - it is not covered by any SMS standard therefore you will have to experiment with your modem.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
Ttelmah
Guest







PostPosted: Wed Feb 22, 2006 5:25 am     Reply with quote

You are confused over what kbhit does. Kbhit, simply tells you that there is a character waiting in the input buffer(for the hardware UART), or that the start bit has been detected (for a software UART). It does not look for the CR character.
Kbhit, also does not remove characters from the input buffer, so when it goes 'true', it will remain true, till you read the character that has been received.
Gets, will get a string up to the CR character.But you then need to ensure that the storage space allowed is enough to handle any likely string that may arrive.

Best Wishes
angel



Joined: 19 Oct 2004
Posts: 40

View user's profile Send private message

PostPosted: Wed Feb 22, 2006 5:52 am     Reply with quote

Of course in my last message I wanted to write : kbhit + gets to read a string up to a <CR> is found. I think, It could be a possiblility. In the message it is sure it will have a <CR> in the end because I will send it using other modem. But I will have to check if there are other before the message.
Any other code to get the message without using gets? Maybe reading characters individually and continously up to find 2 special characters in the message? fgetc could be a solution?
densimitre



Joined: 21 Dec 2004
Posts: 45

View user's profile Send private message

T610
PostPosted: Thu Feb 23, 2006 7:49 am     Reply with quote

Code:


#use rs232(baud=19200,bits=8,parity=n,xmit=pin_c6,rcv=pin_c7,stream=modem)
#use rs232(baud=19200,bits=8,parity=n,xmit=pin_b2,rcv=pin_b1,stream=pc)

//
*****************************************************************************
//
// #INT_RDA RS232 receive data available
// *****************************************************************************

#int_rda                                 
void rda_isr() {                            
char c;                                   
                                         
if ((c>=' ')&&(c<='~')) {                  
                                         
           buffer_gsm[len] = c;
         len++;                            }

}//rda_isr()


void clean_array( char a[], int len) {
   int i=0;
   for(i=0;i<len;i++) {
   a[i]='\0';
   }
len=0; //reset index
}//clean_array();





Code:

main() {

clean_array(buffer_gsm,len);
fprintf(,modem"at\r");
delay_ms(10);
printf(pc,"%s\n\r",buffer_gsm); //AT<CR>
clean_array(buffer_gsm,len);
fprintf(modem,"ate0\r);  //disable echo
delay_ms(10);
fprintf(pc,"%s\n\r",buffer_gsm); //OK
clean_array(buffer_gsm,len);
fprintf(modem,"at\r");  // response = <CR><LF>OK<CR><LF>
                    // but buffer_gsm={O,K}
fprintf(pc,"%s\n\r",buffer_gsm);  //OK
}


So, only " " up to "~" chars can be stored in buffer_gsm...

You muts know the answers for yor command to read it and process it..like to know the index position of each chars...a range ...etc....

p.e:

Code:

if((buffer_gsm[len-2]='O') && (buffer_gsm[len-1]='K')
fprintf(pc,"SMS read OK\n\r");
else
fprintf(pc,"SMS not read\n\r");


Simply, dont store <CR><LF> chars....

Bye
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group