?? gprs_modem.c
字號(hào):
RING_COU++;
if(RING_COU>3) //三次鈴聲后,掛斷電話,并復(fù)位。
{
uartWrite(UART2,(uint8 *)("ATH\r\n"),strlen("ATH\r\n"),NULL);
OSTimeDlyHMSM(0,0,1,300);
RING_COU=1;
WDTC = 0x0; //Reset();//系統(tǒng)復(fù)位
}
}
*/
}
return FALSE;
#endif
#if 0
if ( nRtnStatus==1 )
return TRUE;
else
return FALSE;
#endif
}
#else
// Old version: 2009.05.11, Chad
uint8 RING_COU=0; //ring鈴聲次數(shù)
uint8 LoadUart2(uint32 uiId,uint8 * GPRS_data,uint16 * puiNum)
{
char * str=",\"";
char * str1="\"\r\n";
char * p=NULL;
char * p1=NULL;
UART_read(UART2,GPRS_data,puiNum);
if (*puiNum>0)
{
uartWrite(UART3,GPRS_data,*puiNum,NULL); //測(cè)試
if((p=strstr((char *)GPRS_data,"+CLIP"))!=NULL)
{
MotormanLoadingOrExit(GPRS_data,puiNum); //駕駛員登陸或退出
}
//else
if(strstr((char *)GPRS_data,"+CMTI")!=NULL)
{
char strAT[30];
char * str="\r\nAT+CMGR=";
memset(strAT,0,sizeof(strAT));
if((p=strstr((char *)GPRS_data,"\","))!=NULL)
{
//取短信標(biāo)號(hào)
char * p2=NULL;
p+=strlen("\",");
if((p2=strstr(p,"\r\n"))!=NULL)
{
memset(MsgNum,0,sizeof(MsgNum));
memcpy(MsgNum,p,p2-p);
strcat(strAT,str);
memcpy(strAT+strlen(str),p,p2-p);
strcat(strAT,"\r\n");
uartWrite(UART2,(uint8 *)("\r\nAT+CMGF=1\r\n\0"),strlen("\r\nAT+CMGF=1\r\n\0"),NULL);
OSTimeDlyHMSM(0,0,0,300);
uartWrite(UART2,(uint8 *)strAT,strlen(strAT),NULL);
}
}
return FALSE;
}
//else
if((p=strstr((char *)GPRS_data,"+CMGR"))!=NULL)
{
MsgWatchOrSet(GPRS_data,puiNum); //手機(jī)調(diào)度及自定義手機(jī)查詢?cè)O(shè)置
}
//else
if((p=strstr((char *)GPRS_data,"+AIPRUDP"))!=NULL) //"+AIPRTCP"
{
if((p=strstr((char *)p,str))!=NULL)
{
if((p1=strstr((char *)p,str1))!=NULL)
{
*puiNum=p1-(p+2);
memmove(GPRS_data,p+2,*puiNum);
return TRUE;
}
}
}
//else
if((p=strstr((char *)GPRS_data,"+AIPRTCP: 1"))!=NULL) //"+AIPRTCP"
{
//uartWrite(UART3,GPRS_data,*puiNum,NULL); //測(cè)試
if((p=strstr((char *)p,str))!=NULL)
{
if((p1=strstr((char *)p,str1))!=NULL)
{
*puiNum=p1-(p+2);
memmove(GPRS_data,p+2,*puiNum);
return TRUE;
}
}
}
//else
/*
if((p=strstr((char *)GPRS_data,"+AIPC"))!=NULL) //AIPCI
{
//表示服務(wù)器主動(dòng)斷開連接。
Connect_OK=FALSE;
ReConnect_OK=0;
FTP_UPGRADE_FLAG=0; //返回UDP連接程序
return FALSE;
}*/
//else
if((p=strstr((char *)GPRS_data,"+CSQ: "))!=NULL)
{
char temp[2];
memset(temp,0,sizeof(temp));
p+=strlen("+CSQ: ");
if((*(p+1)>=0x30)&&(*(p+1)<=0x39))
{
temp[0]=*p;
temp[1]=*(p+1);
}
else
temp[0]=*p;
CSQVal=(uint8)atoi(temp);
return FALSE;
}
/*
else if((p=strstr((char *)GPRS_data,"RING"))!=NULL)
{
char paramValue[20];
memset(paramValue,0,sizeof(paramValue));
GetParamValue(0x0101,(uint8 *)paramValue);
RING_COU++;
if(RING_COU>3) //三次鈴聲后,掛斷電話,并復(fù)位。
{
uartWrite(UART2,(uint8 *)("ATH\r\n"),strlen("ATH\r\n"),NULL);
OSTimeDlyHMSM(0,0,1,300);
RING_COU=1;
WDTC = 0x0; //Reset();//系統(tǒng)復(fù)位
}
}
*/
}
return FALSE;
}
#endif // end of Chad defined
/*******************************************************************************
*功能:GPRS鏈接時(shí)的延時(shí)
*參數(shù):INT8U time --->
*說明:GPRS_Link_time(1) 表示延時(shí)一秒
*INPUT:INT8U time
*******************************************************************************/
void GPRS_Link_time(INT8U time)
{
uint8 i;
for(i=0;i<time;i++)
{
OSTimeDly(OS_TICKS_PER_SEC);
}
}
/*******************************************************************************
*功能:GPRS鏈接時(shí)發(fā)所有指令都出現(xiàn)ERROR
*參數(shù):
*說明:發(fā)送AT+AIPA=0.因?yàn)槎季图由螦T+AIPA=0的指令連接時(shí)間會(huì)變長(zhǎng)
*INPUT:
*******************************************************************************/
uint8 AT_AIPA0(char * socketID)
{
char buff[700];
uint16 len;
static char * GPRS_cmd[]={ "\r\nAT+AIPC=", //關(guān)閉鏈路1
"\r\nAT+AIPA=0\r\n\0", //關(guān)閉gprs鏈路
}; //GPRS連接AT指令集
memset(buff,0,sizeof(buff));
strcat(buff,GPRS_cmd[0]);
strcat(buff,socketID);
strcat(buff,"\r\n\0");
uartWrite(UART2,(uint8 *)buff,strlen(buff),NULL);
OSTimeDlyHMSM(0,0,3,0);
//LoadUart2(UART2,(uint8 *)buff,&len);
GPRSLoadData(UART2, (uint8 *)buff, &len, 2);
uartWrite(UART2,(uint8 *)GPRS_cmd[1],strlen(GPRS_cmd[1]),NULL); //關(guān)閉gprs鏈路
// Chad
#if 1
// code block for wait some valid result
{
unsigned short shContDlyTime = 0 ;
unsigned short shContTimeout = 20*600; // 0.1 seconds * 600 = 60.0 seconds
unsigned short len = 0;
// first, wait 5 seconds
GPRS_Link_time(5);
memset(buff,0,sizeof(buff));
do {
//LoadUart2(UART2,(uint8 *)buff,&len);
GPRSLoadData(UART2, (uint8 *)buff, &len, 2);
if ( len > 0 )
break;
OSTimeDly(20); // 20 ticks == 100 milliseconds == 0.1 seconds
shContDlyTime += 20; // OS_TICKS_PER_SEC: 200 ticks == 1 second
} while ( shContDlyTime < shContTimeout );
}
#else
GPRS_Link_time(17);
#endif
return TRUE;
}
/*******************************************************************************
*函數(shù)名:GprsModemInit
*功能: GPRS鏈接函數(shù)
*參數(shù): 通信端口uart2
*說明: 鏈接時(shí)間大約10s
*******************************************************************************/
// Chad
uint8 cFirstBoot=1;
uint8 ReConnect_Cou=0; //重連次數(shù)
uint8 Connect_OK=FALSE;
uint8 ReConnect_OK=0;
uint8 Rec_OK=0;
uint8 GprsModemInit(uint32 uiId,Communi_Stru * pCommuni,char * strTCPUDP)
{ //"\r\nAT+AIPO=1,9201,\"58.217.210.249\",9202,0\r\n\0",
static char * GPRS_cmd[]={ "\r\nAT+AIPA=1\r\n\0", //選擇鏈路
"\r\nAT+AIPO=1,,\"", //打開鏈路,并鏈接,IP地址,端口號(hào)
"\r\nAT+AIPC=1\r\n\0", //關(guān)閉鏈路1
"\r\nAT+AIPDCONT=\"",
}; //GPRS連接AT指令集
//"221.231.140.211\",9987,1\r\n\0", AT+AIPO=1,,"WWW.GTTGPS.CN",9987,1,,1,0
uint16 len;
char buff[TRANSINFOLEN];
char * str="OKOKERROR\0";
char gw_szUartBuffer[700];
if(ReConnect_OK==1)
{
memset(buff,0,sizeof(buff));
//首先關(guān)閉存在的鏈路
uartWrite(UART2,(uint8 *)GPRS_cmd[2],strlen(GPRS_cmd[2]),NULL);
OSTimeDlyHMSM(0,0,3,0);
UART_read(UART2,(uint8 *)buff,&len);
//uartWrite(UART3,(uint8 *)buff,len,NULL); //測(cè)試
__DBG2_printf2(buff,len);
}
if(ReConnect_OK==0)
{
UART_read(UART2,(uint8 *)buff,&len);
//uartWrite(UART3,(uint8 *)buff,len,NULL); //測(cè)試
__DBG2_printf2(buff,len);
memset(buff,0,sizeof(buff));
// Chad
//strcat(buff,GPRS_cmd[3]);
strcpy(buff,GPRS_cmd[3]);
//strcat(buff,pCommuni->strAPN);
if ( pCommuni->strAPN[0]=='\0' ) {
// Chad display message
//uartWrite(UART3,(uint8 *)"\r\n== Get APN emplty ===\r\n",strlen("\r\n== Get APN emplty ===\r\n"),NULL);
__DBG2_printf1("\r\n== Get APN emplty ===\r\n");
#if defined(_TW_)
strcat(buff,"INTERNET");
#else
strcat(buff,"CMNET");
#endif // #if defined(_TW_)
} else {
strcat(buff,pCommuni->strAPN);
}
strcat(buff,"\"\r\n\0");
uartWrite(UART2,(uint8 *)buff,strlen(buff),NULL); //設(shè)置APN
OSTimeDlyHMSM(0,0,2,0);
memset(buff,0,sizeof(buff));
LoadUart2(UART2,(uint8 *)buff,&len);
memset(buff,0,sizeof(buff));
uartWrite(UART2,(uint8 *)GPRS_cmd[0],strlen(GPRS_cmd[0]),NULL); //選擇鏈路
// Chad
#if 1
// code block for wait some valid result
{
unsigned short shContDlyTime = 0 ;
unsigned short shContTimeout = 20*600; // 0.1 seconds * 600 = 60.0 seconds
unsigned short len = 0;
// first, wait 5 seconds
GPRS_Link_time(5);
memset(buff,0,sizeof(buff));
do {
LoadUart2(UART2,(uint8 *)buff,&len);
if ( len > 0 )
break;
OSTimeDly(20); // 20 ticks == 100 milliseconds == 0.1 seconds
shContDlyTime += 20; // OS_TICKS_PER_SEC: 200 ticks == 1 second
} while ( shContDlyTime < shContTimeout );
}
#else
GPRS_Link_time(5);
LoadUart2(UART2,(uint8 *)buff,&len);
#endif
} // end of if(ReConnect_OK==0)
str=(char *)buff;
//如出錯(cuò)則GPRS連接問題,1.SIM問題,2.天線問題,3
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -