comparaison of data coming from a mobile phone

General discussion on mikroC.
Post Reply
Author
Message
shadyfright
Posts: 4
Joined: 21 Jun 2010 22:02

comparaison of data coming from a mobile phone

#1 Post by shadyfright » 21 Jun 2010 22:44

Hi everybody
i'm working at a project of remote control using a PIC16F877 connected to my cell phone which i receive this response from my mobile phone :

+CMGR: "REC READ","+212673811922",,"09/11/22,17:24:38+00"
Bonjour ceci est un message de test

this message contains an AT command and the phone number and the timestamp
my question now is : How can i extract the data information (bonjour ceci est un ......) and make it in an Array or Table of character for compare it with another information coming from the keypad
i'm working with MiKroC ( langage C ).

shadyfright
Posts: 4
Joined: 21 Jun 2010 22:02

Re: comparaison of data coming from a mobile phone

#2 Post by shadyfright » 22 Jun 2010 11:23

Hi Everyone
i want to know if it's possible to manipulate the data coming from the mobile phone in the PIC16F877 (extract, comparison,....)
i'm working with MikroC (langage C)

thanks in advance

User avatar
anikolic
mikroElektronika team
Posts: 1775
Joined: 17 Aug 2009 16:51
Location: Belgrade
Contact:

Re: comparaison of data coming from a mobile phone

#3 Post by anikolic » 23 Jun 2010 10:01

Hello,

Here's the example of how you could parse the string you are referring to. I've made the example that extracts everything that is contained between two quotation signs ("). Each extracted segment is then sent via RS232 for debugging:

Code: Select all

const PARAM_COUNT = 3;

unsigned char text[] = "+CMGR: \"REC READ\",\"+212673811922\",,\"09/11/22,17:24:38+00\"";
unsigned char temp[20];
unsigned char *start, *end;
unsigned short i;

void main() {
  // Extract Segments
  ADCON1 = 0x0F;
  UART1_Init(9600);
  i = 0;
  start = text;
  while (i <= PARAM_COUNT){
    start = strchr(++start, '"');
    if (start){
      end = strchr(++start, '"');
      if (end >= start){
        strncpy(temp, start, end-start);
        temp[end-start] = 0; // END WITH NULL
        UART1_Write_Text(temp);
        UART1_Write(13);UART1_Write(10); // CR+LF
        start = end;
      }
    }
    i++;
  }
}
The entire project is in the attachment, so you may test it and modify to suit your needs.

Best regards,
Aleksandar
Attachments
GSM_extract.rar
(16.99 KiB) Downloaded 132 times
Web Department Manager

shadyfright
Posts: 4
Joined: 21 Jun 2010 22:02

Re: comparaison of data coming from a mobile phone

#4 Post by shadyfright » 23 Jun 2010 11:42

thank you very much Mr aleksandar.nikolic for your collaboration :D
i will modify it to suit my needs.
there is two question please : what's mean this instruction "ADCON1 = 0x0F;"
and what's the difference between those two instruction :

strchr(++start, '"');
strchr(start, '"');

the function returns a pointer to the '"' !!

thanks

User avatar
anikolic
mikroElektronika team
Posts: 1775
Joined: 17 Aug 2009 16:51
Location: Belgrade
Contact:

Re: comparaison of data coming from a mobile phone

#5 Post by anikolic » 24 Jun 2010 10:46

what's mean this instruction "ADCON1 = 0x0F;"
It is left here with no particular implications to the rest of the code. It is used to set all analog pins of PIC16F877 as digital I/O. Read more about this register in the chip's datasheet.
and what's the difference between those two instruction :
strchr(++start, '"');
strchr(start, '"');
This is just C-basics.
1. ++var means literally: "Increment the variable by 1 first, and then give me it's value"
2. The other just returns the variable value as it is. No prior increments.
the function returns a pointer to the '"' !!
Well, this was the whole point. Remember, I've already told you that this simple-parser extracts strings between two successive quotation characters. It returns the pointer to the next quotation mark, because it is supposed to do exactly that. The return value is used as a starting (or ending) point of the new string to be extracted from original buffer.

Find more information on ANSI-C strings to make things clearer.

Best regards,
Aleksandar
Web Department Manager

shadyfright
Posts: 4
Joined: 21 Jun 2010 22:02

Re: comparaison of data coming from a mobile phone

#6 Post by shadyfright » 25 Jun 2010 10:39

ok thank you for your help i will give you feedback if anything doesn't work

Post Reply

Return to “mikroC General”