⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gprs.c

📁 SmartARM2400系列开发板全套资料
💻 C
📖 第 1 页 / 共 4 页
字号:
		GPRSSetQueuePosSta(pos);
    	tmp = 1;
    }
    OSSemPost(GPRSSem);
	return tmp;	//是否操作成功
}

/*********************************************************************************************************
** 函数名称: GPRSGetSimMsgNum
** 功能描述: 得到SIM卡上可以存储的短消息的数量
** 输 入: 无
**
** 输 出: SIM卡上可以存储的SMS的数量
**
** 全局变量: 
** 调用模块: 
**
** 作 者: XieLuWei
** 日 期: 2005年7月1日
**-------------------------------------------------------------------------------------------------------
** 修改人: 
** 日 期: 
**-------------------------------------------------------------------------------------------------------
********************************************************************************************************/
uint16 GPRSGetSimMsgNum(void)
{
	uint8 err;
	char pos;
	uint16 number;
	char *tmptr;	
	
	OSSemPend(GPRSSem, 0, &err);	//获取对GPRS进行操作的信号量
	GPRSFlushQueueSpec("+CMGD");
	if( GPRSSendStr("AT+CMGD=?\r", "+CMGD", &pos, OS_TICKS_PER_SEC*2))
	{	//可能的回复:+CMGD: (1-50)
		tmptr = GPRSQueuePosPtr(pos);
		tmptr = strchr(tmptr,'-') + 1 ;
		number = (uint16)atoi(tmptr);

	    OSSemPost(GPRSSem);
    	GPRSFlushQueueSpec("+CMGD");
		return number;	//是否操作成功
    }
    
    OSSemPost(GPRSSem);
   	GPRSFlushQueueSpec("+CMGD");
	return 0;	//是否操作成功
}

/*********************************************************************************************************
** 函数名称: GPRSReadMSG
** 功能描述: 读短信
** 输 入: 短信序列号,指向存放短消息的缓存的指针
**
** 输 出: 成功 0 失败1
**
** 全局变量: 
** 调用模块: 
**
** 作 者: XieLuWei
** 日 期: 2005年7月1日
**-------------------------------------------------------------------------------------------------------
** 修改人: 
** 日 期: 
**-------------------------------------------------------------------------------------------------------
********************************************************************************************************/
uint8 GPRSReadMSG(uint8 num, char *const MSG )
{	
	uint8 err;
	char pos;
	char *tmptr;
	uint16 length;
	
	GPRSFlushQueueSpec("OK");
	if( !GPRSSendStr("AT+CMGF=1\r", "OK", &pos, OS_TICKS_PER_SEC*2) )
	{
		GPRSFlushQueueSpec("+CMGF");
		return 0;
	}
	
	GPRSFlushQueueSpec("+CMGR");
	_sprintf(ShortMsg,"AT+CMGR=%d\r",num);
	
	OSSemPend(GPRSSem, 0, &err);	//开始对GPRS进行操作

	GPRSWrite(ShortMsg);
	//文本格式短消息样例
	//+CMGR: "REC READ","+8615925610242",,"07/06/15,10:34:19+00"
	//123654987
	if( GPRSCheckQueueExt("+CMGR", &pos, OS_TICKS_PER_SEC*20) )
	{
		OSTimeDly(OS_TICKS_PER_SEC/2); //这里延时的主要原因是当接收到"+CMGR"开头的字符串后,
									 //再等待短消息的实际内容传送完毕
		
		*MSG = '\0';
		tmptr = strchr(GPRSQueuePosPtr(pos),',')+2;//查找发信人号码
		length = strchr(tmptr,'\"') - tmptr;
		strncat(MSG,tmptr,length);
		strcat(MSG," ");	//中间添加一个空格
		
		tmptr = strchr(tmptr,',')+1;
		tmptr = strchr(tmptr,',')+2;	//找到发送时间的开始位置
		
		length = strchr(tmptr,'\"') - tmptr;
		strncat(MSG,tmptr,length);
		strcat(MSG," ");	//中间添加一个空格
		GPRSSetQueuePosSta(pos);	//"+CMGR已经使用过,清空标志"
		
		pos = AddItem(pos);
		
		strcat(MSG,GPRSQueuePosPtr(pos));
		GPRSSetQueuePosSta(pos);//清空短消息实际内容的标志
		
    	OSSemPost(GPRSSem);
    	return 0;
    }
    OSSemPost(GPRSSem);
	return 1;
}


/*********************************************************************************************************
** 函数名称: GPRSSendMSG
** 功能描述: 用户主动向外发送短信
** 输 入: 短信地址,短信信息
**
** 输 出: 成功 0 失败1
**
** 全局变量: 
** 调用模块: 
**
** 作 者: 
** 日 期: 
**-------------------------------------------------------------------------------------------------------
** 修改人: 
** 日 期: 
**-------------------------------------------------------------------------------------------------------
********************************************************************************************************/
uint8 GPRSSendMSG(char *num, char *MSG)
{	
	char pos;
	uint8 err;
	
	OSSemPend(GPRSSem, 0, &err);

	GPRSFlushQueueSpec("OK");
	
	OSTimeDly(OS_TICKS_PER_SEC/2);
	GPRSFlushQueueSpec("> ");
	_sprintf(ShortMsg,"AT+CMGS=\"%s\"\r",num);
	if( GPRSSendStr(ShortMsg, "> ", &pos, OS_TICKS_PER_SEC*5) )
	{	
		GPRSFlushQueueSpec("> ");
		GPRSFlushQueueSpec("+CMGS");

		strcpy(ShortMsg,MSG);
		strcat(ShortMsg,"\x1A");
		if( GPRSSendStr(ShortMsg, "+CMGS", &pos, OS_TICKS_PER_SEC*20))
		{
			GPRSSetQueuePosSta(pos);
			if(GPRSCheckQueueExt("OK", &pos, OS_TICKS_PER_SEC*30))
			{
				GPRSSetQueuePosSta(pos);
				OSSemPost(GPRSSem);
				return 1;	//短消息成功发送
			}
		}
	}
	
	OSSemPost(GPRSSem);
	return 0;	//短消息发送失败
}

/*********************************************************************************************************
** 函数名称: GPRSSetMic
** 功能描述: 设置麦克风的音量
** 输 入: 通道的值,范围0-1;音量的值,范围是0-15;
**
** 输 出: 成功 1 失败0
**
** 全局变量: 
** 调用模块: 
**
** 作 者: 
** 日 期: 
**-------------------------------------------------------------------------------------------------------
** 修改人: 
** 日 期: 
**-------------------------------------------------------------------------------------------------------
********************************************************************************************************/
uint8 GPRSSetMic(uint8 ch, uint8 volume)
{
	char buf[14];
	char pos;
	uint8 err;
	
	if(volume>15)
	{
		return 0;
	}
	
	GPRSFlushQueueSpec("OK");
	OSSemPend(GPRSSem, 0, &err);	//得到对GPRS模块进行操作的信号量
	
	_sprintf(buf,"AT+CMIC=%d,%d\r",ch,volume);
	if( GPRSSendStr(buf,"OK", &pos, OS_TICKS_PER_SEC*2) )
	{
		OSSemPost(GPRSSem);
		GPRSFlushQueueSpec("OK");
		return 1;

	}

	OSSemPost(GPRSSem);
	GPRSFlushQueueSpec("OK");
	return 0;	
}

/*********************************************************************************************************
** 函数名称: GPRSSetMic
** 功能描述: 设置麦克风的音量
** 输 入: 音量的值,输入的范围是:0-100
**
** 输 出: 成功 1 失败0
**
** 全局变量: 
** 调用模块: 
**
** 作 者: 
** 日 期: 
**-------------------------------------------------------------------------------------------------------
** 修改人: 
** 日 期: 
**-------------------------------------------------------------------------------------------------------
********************************************************************************************************/
uint8 GPRSSetSpk(uint8 volume)
{
	char buf[14];
	char pos;
	uint8 err;
	
	if(volume>100)
	{
		return 0;
	}
	
	GPRSFlushQueueSpec("OK");
	OSSemPend(GPRSSem, 0, &err);	//得到对GPRS模块进行操作的信号量
	
	_sprintf(buf,"AT+CLVL=%d\r",volume);
	if( GPRSSendStr(buf,"OK", &pos, OS_TICKS_PER_SEC*2) )
	{
		OSSemPost(GPRSSem);
		GPRSFlushQueueSpec("OK");
		return 1;

	}

	OSSemPost(GPRSSem);
	GPRSFlushQueueSpec("OK");
	return 0;	
}


void SendGpsPos(uint8 sec)
{
	static uint16 second = 0;
	
	second += 2;
	if(second >= 30)
	{
		second = 0;
		ShortMsg[0] = '\0';
		OS_ENTER_CRITICAL();
		if(strlen(GPS_DATA.Latitude)<5 || strlen(GPS_DATA.Longtitude)<5)
		{
			GPS_DATA.Latitude[0] = '\0';
			GPS_DATA.Longtitude[0] = '\0';
		}
		OS_EXIT_CRITICAL();
		strcpy(ShortMsg,GPS_DATA.Latitude);
		strcat(ShortMsg,"  ");
		strcat(ShortMsg,GPS_DATA.Longtitude);
		
		if(ShortMsg[0] != '\0')
		{
			GPRSSendMSG("13760845288",ShortMsg);
		}
	}
}



//模块主动提供的消息的处理
//char RcvMsg[140];	//模块接收到的短信息,包括发信人,时间,内容,格式为TXT格式
char MsgCenter[24];

//各种功能的测试实验
void MisceTest(uint8 number)	
{
	uint8 tmp;
	
	switch (number)
	{
		case 1:	tmp = GPRSGetSimMsgNum();	//得到SIM卡上可以存储的短消息的数量
				break;
		case 2: GPRSViewMSGCenter(MsgCenter);	//查看短信息中心
				break;		
		case 3: GPRSSetMSGCenter("+8613800571500");	//设置短信息中心
				break;		
		case 4: GPRSSendMSG("13760845288","wo shi xieluwei");	//发送一条短信息
				break;		
		case 5: GPRSReadMSG(1,ShortMsg);	//读取短消息
				break;		
		case 6: GPRSDelMSG(1);	//删除短信息
				break;		
		case 7: GPRSDialUp("13760845288");	//拨打电话
				break;		
		default: break;
	}
}

void RcvNoRequest( void )
{
	uint8 msgtype;
	uint8 tmp;
	
	msgtype = GPRSQueryQ(ShortMsg);
	if(msgtype == RECEIVED_CALL)
	{
		GPRSAnswerCall();
	}
	else if(msgtype == RECEIVED_NOCARRIER)
	{
		GPRSHangupCall();
	}
	else if(msgtype == RECEIVED_SMS)
	{
		tmp = (char)atoi(ShortMsg+12);
		GPRSReadMSG(tmp, ShortMsg);	//先读取短消息
		GPRSDelMSG(tmp);	//再删除短消息
	}
	else if(msgtype == RECEIVED_CALLREADY)
	{
		GPRSSetState(GPRS_IDLE);
	}
}


/*********************************************************************************************************
**	下面的函数是接收中断使用的向量初始化程序
**	软件设计的思路是GPRS发送的数据引起外部中断,外部中断通知接收
**  数据接收任务接收数据
**	这里使用的全局变量是OS_EVENT	*UartRcv;
*********************************************************************************************************/
/*********************************************************************************************************
**	外部中断使用LPC2131的P0.15引脚,外部中断2
*********************************************************************************************************/
void Ext2Init(void)
{
	PINSEL0 = (PINSEL0 & 0x3FFFFFFF)|0x80000000;	//选择P0.15为外部中断2功能引脚
	EXTMODE = 0x04;		//EINT2为边沿激活
	EXTPOLAR = 0x04;	//EINT2为上升边沿激活
}


/*********************************************************************************************************
**	外部中断服务程序
**	使用的全局变量: OS_EVENT	*DuartRcv;
*********************************************************************************************************/
void Ext2_Exception(void)
{
	OSSemPost(DuartRcv);
	
	EXTINT = 0x04;
	VICVectAddr = 0;
}

/*********************************************************************************************************
**	将外部中断加入到VIC中
**	1、在IRQ.s文件中添加下面三行
**		;//外部中断2中断
**		;//Ext2 Interrupt
**		Ext2_Handler  HANDLER Ext2_Exception
**	2、在target.c文件中函数VICInit中添加下面四行
**	    extern void Ext2_Handler(void);
**	    VICVectAddr1 = (uint32)Ext2_Handler;
**	    VICVectCntl1 = (0x20 | 0x10);
**	    VICIntEnable = 1 << 0x10;
**	3、在target.c文件中函数TargetInit中添加下面一行
**		Ext2Init();
*********************************************************************************************************/

/*********************************************************************************************************
**                            End Of File
********************************************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -