STM32操作GPRS模块MG2639接收AT命令

作者:fly 发布于:2014-2-17 11:06 分类:嵌入式

版权声明:本文系www.forwhat.cn原创 ,尊重作者劳动,转载请标明出处。本文转载自www.forwhat.cn谢谢

 

接上文

static TQ_U8 HW_MG2639_ProFindAT()
{
	TQ_U32 i=0;
	TQ_U32 DataLenght=0;
	TQ_U32 LastDataLenght=0;
	TQ_U32 BufferSize=0;
	while(HW_MG2639_RecPreCnt>HW_MG2639_RecOkCnt)
	{
		if((HW_MG2639_Buffer[(HW_MG2639_RecOkCnt)%MAX_LENGHT_MG2639_BUFFERSIZE]=='\0')
			||(HW_MG2639_Buffer[(HW_MG2639_RecOkCnt)%MAX_LENGHT_MG2639_BUFFERSIZE]=='\r')
			||(HW_MG2639_Buffer[(HW_MG2639_RecOkCnt)%MAX_LENGHT_MG2639_BUFFERSIZE]=='\n')
			||(HW_MG2639_Buffer[(HW_MG2639_RecOkCnt)%MAX_LENGHT_MG2639_BUFFERSIZE]==' '))
		{
			HW_MG2639_RecOkCnt++;
		}
		else
		{
			break;
		}
	}
	memset(Buffer,0,2048);
	if(HW_MG2639_Buffer[(HW_MG2639_RecOkCnt)%MAX_LENGHT_MG2639_BUFFERSIZE]=='>')
	{
		TQ_U8 perr=0;
		SYS_MESSAGE_TYPEDEF * mymsg=OSMemGet(Sys_Mem, &perr);		
		mymsg->par1=MSG_HW_MG2639_ReceiveATCommond;
		OSQPost(HW_MG2639Que,mymsg);
		HW_MG2639_RecOkCnt++;
	}
	for(i=0;i<(HW_MG2639_RecPreCnt-HW_MG2639_RecOkCnt);i++)
	{			
		Buffer[BufferSize++]=HW_MG2639_Buffer[(HW_MG2639_RecOkCnt+i)%MAX_LENGHT_MG2639_BUFFERSIZE];
		if(BufferSize>2040){HW_MG2639_RecOkCnt++;}
		if((HW_MG2639_Buffer[(HW_MG2639_RecOkCnt+i)%MAX_LENGHT_MG2639_BUFFERSIZE]=='\r')&(HW_MG2639_Buffer[(HW_MG2639_RecOkCnt+i+1)%MAX_LENGHT_MG2639_BUFFERSIZE]=='\n'))
		{
			//在提交之前检查是否为接收数据指令
			DataLenght=HW_MG2639_IsTCPorUDPReceive(Buffer,BufferSize);
			if(DataLenght)
			{
				while(1)
				{//在这里进入循环直至接收到完整的数据
					if((HW_MG2639_RecPreCnt-HW_MG2639_RecOkCnt)>=DataLenght)
					{//说明缓冲区中已经存在足否的数据
						break;
					}
					else
					{//说明缓冲区中数据不足。
						if(LastDataLenght<(HW_MG2639_RecPreCnt-HW_MG2639_RecOkCnt))
						{
							LastDataLenght=(HW_MG2639_RecPreCnt-HW_MG2639_RecOkCnt);
							OSTimeDly(1);
						}
						else
						{//已经有一段时间没有接收数据了,可能是由于通讯不可靠造成的
							break;
						}
					}
				}
				BufferSize--;
				for(;i<(HW_MG2639_RecPreCnt-HW_MG2639_RecOkCnt);i++)
				{
					Buffer[BufferSize++]=HW_MG2639_Buffer[(HW_MG2639_RecOkCnt+i)%MAX_LENGHT_MG2639_BUFFERSIZE];
					if(BufferSize>=DataLenght){break;}
				}
				HW_MG2639_RecOkCnt+=i;
				AT_MG2639_ReceiveDataCommand(Buffer,BufferSize);
			}
			else
			{
				HW_MG2639_RecOkCnt+=i;
				AT_MG2639_ReciveATCommand(Buffer,BufferSize);
			}
			break;
		}
	}
	if(HW_MG2639_RecOkCnt>=HW_MG2639_RecPreCnt)
	{
			HW_MG2639_RecPreCnt=0;
			HW_MG2639_RecOkCnt=0;
	}
	return Err_none;
}


 

发表评论:

 
Powered by emlog sitemap