u8 * Read_message(void)
{
u8 flag=1;
u8 *str;
u8 *receive;
u8 ch=0;
while(sim900a_cmd("AT\r","OK",1000) != SIM900A_TRUE);
if(flag==1)//第一次需要设置这些指令
{
flag=0;
while(sim900a_cmd("AT+CMGF=1\r","OK",1000)!= SIM900A_TRUE); //设置为文本模式
SIM900A_DELAY(100);
while(sim900a_cmd("AT+CSCS=\"GSM\"\r","OK",1000)!= SIM900A_TRUE); //"GSM"字符集
SIM900A_DELAY(100);
while(sim900a_cmd("AT+CNMI=2,1\r","OK",1000)!= SIM900A_TRUE);//"GSM"字符集
SIM900A_DELAY(100);
}
if(sim900a_cmd_check("SM")==SIM900A_TRUE)//正确接收,+CMTI: "SM",1
{
str=&uart_buff[0]; //拿到回复字符串的地址
while((*str)!=','){str++;}//到达 ,号
ch=*str;//拿到短信的序号
SIM900A_CLEAN_RX();//清空缓冲区
//while(sim900a_cmd("AT+CMGR=1\r","OK",1000)!= SIM900A_TRUE);//
sim900a_tx_printf("AT+CMGR=%d\r",ch);//发送读取指令
SIM900A_DELAY(100);
ch=0;
str=&uart_buff[0]; //得到回复+CMGR: "REC UNREAD","13632411682","","14/12/10,14:06:31+32"123aaa
while((*str)!='\0'&&ch<8)
{
if((*str)=='\&quot;') ch++;
str++;
}//到达最后的&quot;后一个字符
while((*str)!='\0')
{
*receive=*str;
receive++;
str++;
}
*receive='\0';//结束符
return receive;
}
return 0;
} |