📄 gprs_handle.c
字号:
**
** 作 者: Yehaoben
** 日 期: 2005年7月1日
**-------------------------------------------------------------------------------------------------------
** 修改人:
** 日 期:
**-------------------------------------------------------------------------------------------------------
********************************************************************************************************/
uint8 GPRSAutoTakeTheCall()
{
uint8 err;
OSSemPend(GPRS_TCB.GPRSRing, OS_TICKS_PER_SEC*2, &err);
if(err == OS_NO_ERR)
{
ZLG_GPRS_SND_CMD("ATA\r\n");
return 0;
}
else
return 1;
}
/*********************************************************************************************************
** Function name: ZLG_GPRS_RVC_HANDLE
**
** Descriptions: Revice data and save into GPRSDataQ
**
** input parameters: uint8 :one data
**
** Returned value: None
**
** Used global variables: None
** Calling modules: None
**
** Created by: Yehaoben
** Created Date: 2005/06/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void ZLG_GPRS_RVC_HANDLE(uint8 i)
{
if( GPRS_TCB.Status & 0x0010 )
{
GPRS_MSG_WR_PTR
if( ( i == '>' ) || ( i == 'O' ) || (GPRS_TCB.GPRS_MSG_WR_PTR > 0) )
{
GPRS_TCB.RCVMSG[GPRS_TCB.GPRS_MSG_WR_PTR] = i;
if(i == '\n')
{
GPRS_TCB.RCVMSG[GPRS_TCB.GPRS_MSG_WR_PTR+1] = 0;
if( (GPRS_TCB.Status & 0XFFFd) )//if SENDING COMMAND BIT
if(strncmp(GPRS_TCB.RCVMSG,"OK\r\n",strlen("OK\r\n")) == 0)
{
GPRS_TCB.Status = GPRS_TCB.Status & 0XFFF8;//CLEAR COMMAND BIT
OSSemPost(GPRS_TCB.GPRSCmdOK);//send call signal;
}
GPRS_TCB.GPRS_MSG_WR_PTR = 0;
}
else if(i == '>')
{
if(GPRS_TCB.Status & 0X0020)
{
GPRS_TCB.Status = GPRS_TCB.Status & 0XFFD9;//CLEAR COMMAND BIT AND MESSAGE BIT
OSSemPost(GPRS_TCB.GPRSMsgWR);//send call signal;
GPRS_TCB.GPRS_MSG_WR_PTR = 0;
}
}
else
{
GPRS_TCB.GPRS_MSG_WR_PTR ++;
if(GPRS_TCB.GPRS_MSG_WR_PTR >= GPRS_CMDMaxSize+100)
{
GPRS_TCB.GPRS_MSG_WR_PTR = 0;
}
}
}
else if(GPRS_TCB.GPRS_MSG_WR_PTR == 0)
{
GPRS_TCB.RCVMSG[GPRS_TCB.GPRS_MSG_WR_PTR] = i;
GPRS_TCB.GPRS_MSG_WR_PTR ++;
}
}
else if( (GPRS_TCB.Status & 0x0001) == 0 )//BUZY
{
if( ( i == '>' ) || ( i == 'O' ) || (GPRS_TCB.GPRS_RCV_WR_PTR > 0) )
{
GPRS_TCB.RCVCommand[GPRS_TCB.GPRS_RCV_WR_PTR] = i;
if(i == '\n')
{
GPRS_TCB.RCVCommand[GPRS_TCB.GPRS_RCV_WR_PTR+1] = 0;
if( (GPRS_TCB.Status & 0XFFFd) )//if SENDING COMMAND BIT
if(strncmp(GPRS_TCB.RCVCommand,"OK\r\n",strlen("OK\r\n")) == 0)
{
GPRS_TCB.Status = GPRS_TCB.Status & 0XFFF8;//CLEAR COMMAND BIT
OSSemPost(GPRS_TCB.GPRSCmdOK);//send call signal;
}
GPRS_TCB.GPRS_RCV_WR_PTR = 0;
}
else if(i == '>')
{
if(GPRS_TCB.Status & 0X0020)
{
GPRS_TCB.Status = GPRS_TCB.Status & 0XFFD9;//CLEAR COMMAND BIT AND MESSAGE BIT
OSSemPost(GPRS_TCB.GPRSMsgWR);//send call signal;
GPRS_TCB.GPRS_RCV_WR_PTR = 0;
}
}
else
{
GPRS_TCB.GPRS_RCV_WR_PTR ++;
if(GPRS_TCB.GPRS_RCV_WR_PTR >= GPRS_CMDMaxSize+100)
{
GPRS_TCB.GPRS_RCV_WR_PTR = 0;
}
}
}
else if(GPRS_TCB.GPRS_RCV_WR_PTR == 0)
{
GPRS_TCB.RCVCommand[GPRS_TCB.GPRS_RCV_WR_PTR] = i;
GPRS_TCB.GPRS_RCV_WR_PTR ++;
}
}
else//idle , for ring
{
if( (i == 'r') || ( i == 'R' ) || (GPRS_TCB.GPRS_RCV_WR_PTR > 0) )
{
GPRS_TCB.RCVCommand[GPRS_TCB.GPRS_RCV_WR_PTR] = i;
if(i == '\n')
{
GPRS_TCB.RCVCommand[GPRS_TCB.GPRS_RCV_WR_PTR+1] = 0;
if(strncmp(GPRS_TCB.RCVCommand,"RING\r\n",strlen("RING\r\n")) == 0)
{
GPRS_TCB.Status = GPRS_TCB.Status | 0X0008;//SET RING BIT
OSSemPost(GPRS_TCB.GPRSRing);//send call signal;
}
GPRS_TCB.GPRS_RCV_WR_PTR = 0;
}
else
{
GPRS_TCB.GPRS_RCV_WR_PTR ++;
if(GPRS_TCB.GPRS_RCV_WR_PTR >= GPRS_CMDMaxSize+100)
{
GPRS_TCB.GPRS_RCV_WR_PTR = 0;
}
}
}
}
}
/*********************************************************************************************************
** Function name: startchar
**
** Descriptions: check the string from head to end
**
** input parameters: * str :string pointer
** endch :end char
** Returned value: char * :return the string
**
** Used global variables: None
** Calling modules: None
**
** Created by: Yehaoben
** Created Date: 2005/06/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
char * startchar(char * str,char endch )
{
uint16 i=0;
char * Ptr;
Ptr=str;
while(str[i])
{
if(str[i]==endch)
{
str[i]=0;
return Ptr;
}
i++;
if(i>30)
break;
}
return NULL;
}
/*********************************************************************************************************
** Function name: StrTOUINT
**
** Descriptions: change string to 16 bits integer
**
** input parameters: * str :string pointer
** DBits :string length
** Returned value: uint16 :changed result
**
** Used global variables: None
** Calling modules: None
**
** Created by: Yehaoben
** Created Date: 2005/06/02
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
uint16 StrTOUINT(char * str,uint8 DBits)
{
uint8 i=0;
uint16 j=0;
if( DBits <= 5 )
{
do
{
if(str[i] != '.')
{
j=(str[i]-0x30)+j*10;
DBits--;
}
i++;
}while(DBits > 0);
}
return j;
}
uint8 ZLG_GPRS_SND_CMD(char * cmdptr)
{
uint8 err;
OS_ENTER_CRITICAL();
if( (GPRS_TCB.Status & 0x0001) == 0 )
{
OS_EXIT_CRITICAL();//
return 2;//buzy
}
GPRS_TCB.Status = GPRS_TCB.Status & 0xfffe;//clear idle bit
GPRS_TCB.Status = GPRS_TCB.Status | 0x0004;//set have been sended and wait ok
OS_EXIT_CRITICAL();
do
{
ZLG_GPRS_Send_String(AT_COMMAND);//send at,
OSSemPend(GPRS_TCB.GPRSCmdOK,2*OS_TICKS_PER_SEC,&err);//wait for ok;
if(err == OS_TIMEOUT)
{
continue;//error
}
break;
}while(1);
OS_ENTER_CRITICAL();
GPRS_TCB.Status = GPRS_TCB.Status & 0xfff9; //clear have been sended and wait ok bit //clera sending command bit
GPRS_TCB.Status = GPRS_TCB.Status | 0x0004; //set have been sended and wait ok
OS_EXIT_CRITICAL();
do
{
ZLG_GPRS_Send_String(cmdptr);//send command,
OSSemPend(GPRS_TCB.GPRSCmdOK,2*OS_TICKS_PER_SEC,&err);//wait for ok;
if(err == OS_TIMEOUT)
{
continue;//error
}
break;
}while(1);
OS_ENTER_CRITICAL();
GPRS_TCB.Status = GPRS_TCB.Status | 0x0001; //set idle bit
GPRS_TCB.Status = GPRS_TCB.Status & 0xfff9; //clear have been sended and wait ok bit //clera sending command bit
OS_EXIT_CRITICAL();
return 0;//success
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -