GSM MODEM USB
/*
* Project name:
GSM RECEIVE MESSAGE WITH PHONENUMBER AUTHENTICATION
* Copyright
(c) Researchdesignlab.com
* Test configuration:
BOARD: RASPBERRY PI & BEAGLEBONE
Software: ECLIPSE
*/
#include <stdio.h>
#include <stddef.h>
#include <termios.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <string.h>
unsigned char rx_buffer[10];
unsigned char test[64];
unsigned char number[64];
unsigned char number_check[64]="+918123902188";
int count,i,flag,k;
int main()
{
FILE *ofp_uart1_tx, *ofp_uart1_rx;
termios uart1;
int fd,f;
int m,n,d,e,a,b,c,q,r,x,y,z,t,u,o;
//IN CASE OF RASPBERRY PI THE FILE NAME IS /dev/AMA0
if((fd = open("/dev/ttyO1", O_RDWR | O_NOCTTY )) < 0)
{
printf("Unable to open uart1 access.\n");
}
if(tcgetattr(fd, &uart1) < 0)
{
printf("Could not get attributes of UART1 at ttyO1\n");
}
if(cfsetospeed(&uart1, B9600) < 0)
{
printf("Could not set baud rate \n");
}
else
{
printf("Baud rate: 9600\n");
}
uart1.c_iflag = 0;
uart1.c_oflag = 0;
uart1.c_lflag = 0;
tcsetattr(fd, TCSANOW, &uart1);
tcflush(fd,TCIFLUSH);
printf("AT+CMGF=1\r\n");
d = write(fd, "AT+CMGF=1", 9);
sleep(2);
a = write(fd, "\r", 1);
b = write(fd, "\n", 1);
sleep(2);
printf("AT+CMGD=1\r\n");
x = write(fd, "AT+CMGD=1", 9);
sleep(2);
y = write(fd, "\r", 1);
z = write(fd, "\n", 1);
sleep(2);
rx_buffer[0]=0;
while(rx_buffer[0]!='I')
{
read(fd, rx_buffer, (1));
}
rx_buffer[0]=0;
sleep(2);
t = write(fd, "AT+CMGR=1", 9);
sleep(2);
o = write(fd, "\r", 1);
u = write(fd, "\n", 1);
sleep(2);
i=0;count=0;
for(int j=0;j<=7;j++)
{
count++;
while(rx_buffer[0]!='"')
{
read(fd, rx_buffer, (1));
if(count>=6)
{
if(i<13)
{
number[i]=rx_buffer[0];
i++;
}
}
}
rx_buffer[0]=0;
}
i=0;
rx_buffer[0]=0;
while(rx_buffer[0]!=13)
{
read(fd, rx_buffer, (1));
}
rx_buffer[0]=0;
while(rx_buffer[0]!=13)
{
read(fd, rx_buffer, (1));
test[i]=rx_buffer[0];
i++;
}
for(k=0;k<13;k++)
{
if(number[k]==number_check[k])
{
flag=1;
}
else
{
flag=0;
break;
}
}
if(flag==1)
printf("%s\n", test);
else
printf("%s is invalid\n", number);
sleep(1);
close(fd);
}