#include "hw_memmap.h"
#include "hw_uart.h"
#include "hw_memmap.h"
#include "hw_types.h"
#include "hw_sysctl.h"
#include "sysctl.h"
#include "uart.h"
#include "hw_uart.h"
#include "interrupt.h"
#include "lm3s8962.h"
#include "hw_ints.h"
#include "debug.h"
#include "interrupt.h"
#include "pwm.h"
#define picsize 15000
unsigned char targetphone[]={'+','8','6','1','5','0','5','1','8','1','5','5','7','3'};
unsigned char msgpo[]={'0','0','0','1'};
const unsigned char phnumstart[]={0x2B,0x38,0x36};
const unsigned char msgarr[]={0x2B,0x43,0x4D,0x54,0x49,0x3A,0x20,0x22,0x53,0x4D,0x22,0x2C};
const unsigned char atend[]={0x0D,0x0A};
const unsigned char RING[]={0x52,0x49,0x4E,0x47};
extern unsigned short FLAG_NEWM;
extern unsigned short FLAG_REA;
extern long FLAG_GPIO;
extern unsigned char photo_buf[];
extern unsigned long photo_len;
extern void uart0_sendbuf(const unsigned char *pucBuffer, unsigned long ulCount);
extern unsigned long uart0_getbuf(unsigned char *buf, unsigned long n);
extern void delay(unsigned long dly);
//寻找子串(从头开始)
long myStrFind(const unsigned char s1[ ], const unsigned char s2[ ],long s1length,long s2length)
{
long i, j, k;
for( i=0; i<=s1length-s2length; i++)
{
for( k=i, j=0; (s1[k]==s2[j])&&(j<s2length); k++,j++);
if(j >= s2length)
return i;
}
return -1;
}
//寻找子串(非从头开始)
long myStrFindns(const unsigned char s1[ ], const unsigned char s2[ ],long s1length,long s2length)
{
long i, j, k;
for( i=2; i<=s1length-s2length; i++)
{
for( k=i, j=0; (s1[k]==s2[j])&&(j<s2length); k++,j++);
if(j >= s2length)
return i;
}
return -1;
}
//GSM模块初始化
void GSMinit(void)
{
uart0_sendbuf((unsigned char *)"ATI\r",4);
delay(10);
uart0_sendbuf((unsigned char *)"ATI\r",4);
delay(10);
uart0_sendbuf((unsigned char *)"ATI\r",4);
delay(10);
uart0_sendbuf((unsigned char *)"AT+CMGF=1\r",10);
delay(100);
//串口零中断初始化
IntEnable(INT_UART0);
UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
}
//中断响应函数,有短信时起效
void UARTIntHandler0(void)
{
unsigned char tem[40];
short po=0;
short po1=0;
unsigned short i=0;
unsigned long ulStatus;
ulStatus = UARTIntStatus(UART0_BASE, true);
UARTIntClear(UART0_BASE, ulStatus);
uart0_getbuf(tem, 40);
//新短信到
po=myStrFind(tem,msgarr,40,12);
if(po!=-1)
{
po1=myStrFindns(tem,atend,40,2);
for(i=0;i<po1-po-12;i++)
msgpo[3-i]=tem[po1-1-i];
FLAG_NEWM=1;
goto retur;
}
//短信内容,取手机号+86xxxxxxxxxxx
po=myStrFind(tem,phnumstart,40,3);
if(po!=-1)
{
for(i=0;i<14;i++)
targetphone[i]=tem[po+i];
FLAG_NEWM=0;
goto retur;
}
//来电,停止响铃
po=myStrFind(tem,RING,40,4);
if(po!=-1)
{
PWMGenDisable(PWM0_BASE, PWM_GEN_0);
goto retur;
}
retur:
po=0;
po1=0;
}
//读短信命令
void readmsgsend(void)
{
FLAG_NEWM=0;
uart0_sendbuf("AT+CMGR=",8);
uart0_sendbuf(msgpo,4);
uart0_sendbuf("\r",1);//结束符号
}
//打电话
//此函数定义在主函数中,是一task
//发送彩信
void cmmsend(unsigned long length)
{
unsigned char tem1[5]={0};
short i=0;
//将图像长度转化为字符数组
for(i=4;i>=0;i++)
{
tem1[i]=48+(unsigned char)(length%10);
length=length/10;
}
uart0_sendbuf("at+cmmscurl=\"mmsc.monternet.com\"\r",33); //设置URL
delay(10);
uart0_sendbuf("at+cmmsnetcfg=1,\"cmwap\"\r",24);//设置APN
delay(10);
uart0_sendbuf("at+cmmsproto=1,\"10.0.0.172\",80\r",31);//设置mms协议属性
delay(10);
uart0_sendbuf("at+cmmssendcfg=6,3,0,0,2,4\r",27);//设置mms的发送参数
delay(10);
uart0_sendbuf("AT+CMMSEDIT=0\r",14);//关闭编辑状态,这样在模块的buff区的数据将被删除
delay(10);
uart0_sendbuf("AT+CMMSEDIT=1\r",14);//打开编辑状态,这个状态才可以发送mms
delay(10);
uart0_sendbuf("at+cmmsdown=\"pic\",",18);
uart0_sendbuf(tem1,5);
uart0_sendbuf(",100000\r",8);
delay(2);
uart0_sendbuf(photo_buf,photo_len);
uart0_sendbuf("\r",1);//结束符号
delay(20);
uart0_sendbuf("at+cmmsdown=\"title\",7,30000\r",28);//设置发送的mms的名字,大小,时间
delay(10);
uart0_sendbuf("picture",7);//发送名字,hua
delay(10);
uart0_sendbuf("at+cmmsdown=\"text\",7,30000\r",27);//设置发送的mms的文本内容,小于1000bytes
delay(10);
uart0_sendbuf("picture",7);//发送文本内容
delay(10);
uart0_sendbuf("at+cmmsrecp=\"",13);
uart0_sendbuf(targetphone,14);
uart0_sendbuf("\"\r",2);
delay(10);
uart0_sendbuf("at+cmmsview\r",12);//查看发送的内容是否已经存入模块
delay(10);
uart0_sendbuf("at+cmmssend\r",12);//发送mms
delay(20);
//uart0_sendbuf("at+cmmssave\r");//保存mms到模块,模块只能保存两个mms
//delay(10);
uart0_sendbuf("AT+CMMSEDIT=0\r",14);//关闭编辑状态
delay(10);
}