View previous topic :: View next topic |
Author |
Message |
zeeshan ahmed
Joined: 02 Dec 2010 Posts: 22
|
Help needed regarding AT commands Response |
Posted: Sat Jun 04, 2011 5:22 am |
|
|
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
|
|
Posted: Sat Jun 04, 2011 8:03 am |
|
|
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: 19516
|
|
Posted: Sat Jun 04, 2011 2:26 pm |
|
|
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: 1615 Location: Central Illinois, USA
|
|
Posted: Sat Jun 04, 2011 8:12 pm |
|
|
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
|
|
Posted: Sun Jun 05, 2011 10:51 am |
|
|
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: 1615 Location: Central Illinois, USA
|
|
Posted: Sun Jun 05, 2011 12:35 pm |
|
|
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
|
|
Posted: Thu Jun 09, 2011 1:32 pm |
|
|
...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 |
|
|
|