HUTHAIFA.N Guest
|
SMS command recognizing |
Posted: Fri Sep 12, 2008 10:04 pm |
|
|
Hi all
I want someone to help me with this.
I am new to SMS world but I learn how to use the PIC to send and receive SMS (text mode). I am preparing the code until the GSM is received from the seller.
The idea now that I want to send a command to the PIC via SMS and read it, so that if it is a predefined command a programmed action will be done.
I can simply send a command via SMS such as "ON" to the GSM connected to the PIC.
But now when received to the PIC i have 2 problems which i need to solve them simply. (I am not too good in programming).
I am using PCW 3.148.
First of all I used to save the messages received through:
Code: | #int_rda
void serial_isr()
{
rx[i++] = getch();
} |
The first problem is:
- How to know if there is a new received message ?
Should i save the "+CNMI" in a variable such as : strcpy(s,"+CNMI")
and then compare it with the first 5 characters saved in "rx" ?
Or no need for this step ?
So just try to read the first message in a loop until it is a command message ?
- The second problem is:
How to know the command received ?
Is it right to put a symbol before the command such as "$" and search the message saved in "rx" for that symbol and when find it, try to know what is the characters followed it such as :
Code: |
strcpy(cmd,"$ON") // saving the command
x=0;
flag = 1; //flag
while(1)
{
data = rx[x]; // character by character
if (data =="$") // the symbol
{
for(i = x;i<x+2;i++)
if (rx[i] != cmd[i-x+1]) // Ensure just to compare cmd[0],cmd[1]
flag = 0; // Change the flag due to condition
|
........
and continue the code...............
hope you all help me .....
thx b4 |
|