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 support@ccsinfo.com

Help needed regarding AT commands Response

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



Joined: 02 Dec 2010
Posts: 22

View user's profile Send private message

Help needed regarding AT commands Response
PostPosted: Sat Jun 04, 2011 5:22 am     Reply with quote

Hi all,
I am working on a project , in which i have to use GSM MODEM, i have successfully tested GSM MODEM with PIC18f252 and its working OK. Now WHAT I WANT TO DO IS TO COMPARE AT COMMAND'S RESPONSE.
e.g. if i issue AT+cmgf=1, then GSM modem will repond with OK. same as if i issue AT+CMGR=3, then GSM modem will repond with "+cmgr: message , location" etc.
I tried to do it by comparing OK with the characters 'o' and 'k'. But i need some more flexible method to do this comparision, such as by comparing strings etc.

I m using sim900D gsm modem.

Any sort of help will be highly appreciated.
Thanks.
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Sat Jun 04, 2011 8:03 am     Reply with quote

You don't describe the interface to the PIC but I suspect it might be RS232.
First, it is very hard to have a successful RS232 outcome unless you use a circular buffer fed from an ISR. Since RS232 is asynchronous there must be no expectation that the buffer contains OK. It may just have O or nothing at all. The ISR should count in consecutive O and K chars and set a one byte global flag. In your main routine you would write a parser that would find and extract the AT response from the circular buffer providing the flag is set. The time the parser takes to do this may overlap the receipt of a new char. The ISR with interrupt the parser and place the new char in the circular buffer. In this way your main routine is uncoupled from the asynchronous receipt of chars.
Second, look at the string functions in the compiler manual Ex strcmp
Ttelmah



Joined: 11 Mar 2010
Posts: 19360

View user's profile Send private message

PostPosted: Sat Jun 04, 2011 2:26 pm     Reply with quote

Or, consider a state machine.
Depends massively on how many things you are looking for, the likely lengths etc.. String comparison, becomes 'hard work', and slow, if there are more than a few options to look for;

Best Wishes
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sat Jun 04, 2011 8:12 pm     Reply with quote

Ttelmah wrote:
Or, consider a state machine.
Depends massively on how many things you are looking for, the likely lengths etc.. String comparison, becomes 'hard work', and slow, if there are more than a few options to look for;



I agree with Ttelmah here.. if you're dealing with ASCII (and AT commands definitely qualify) and the lines are terminated the same all the time (CR or CR/LF or something).

Then a state machine is very nice over the circular buffer as you don't have to scan the buffer every time a char comes in looking for a string match.

You almost KNOW with the termination of a line (with CR|LF or whatever) that the next char is the start...

I do this with GPS's (and NMEA) and it works just fine.. I also do a wait for '$' (for NMEA) since it's always the start of the line after the CR/LF sequence...

Soooooo...

I'm done rambling.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Douglas Kennedy



Joined: 07 Sep 2003
Posts: 755
Location: Florida

View user's profile Send private message AIM Address

PostPosted: Sun Jun 05, 2011 10:51 am     Reply with quote

Well rambling a bit also
For NMEA a GPS will squawk several sentences ( most do this but some allow for a master to request a certain sentence). I would in the isr use a state machine to gate a specific sentences into the circular buffer and set a flag pointer to the beginning of the sentence in the circular buffer. The main routine would parse the specific sentences and allowing for the case that if an incoming new sentence overlaps the parsing it still will be captured.
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sun Jun 05, 2011 12:35 pm     Reply with quote

In my state machine, I immediately make a copy of the string and then release the ISR to continue capturing.

While I haven't tested, it is possible the next sentence is missed during the copy of the current string into the "temp" string before the release..

A ring buffer would certainly solve that but I usually run the PIC doing the processing at 40MHz and so far, i think it's been able to keep up.

but a ring buffer would definitely solve that.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Thu Jun 09, 2011 1:32 pm     Reply with quote

...i tackled this issue some time ago..

check for my post on "Recieving text messages"

http://www.ccsinfo.com/forum/viewtopic.php?t=42527&highlight=gabriel

i use a circular buffer.. and look for strings in the responses from the modem...

its old code... not very clean... but might help...
_________________
CCS PCM 5.078 & CCS PCH 5.093
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