?? gprs_test.c
字號:
/*********************************************************************************************
* File: gprs_test.c
* Author: embest
* Desc: gprs test program
* History:
*********************************************************************************************/
/*------------------------------------------------------------------------------------------*/
/* include files */
/*------------------------------------------------------------------------------------------*/
#include "2410lib.h"
#include "gprs_test.h"
/*------------------------------------------------------------------------------------------*/
/* global variables */
/*------------------------------------------------------------------------------------------*/
INT32T f_nSelectUart;
/*********************************************************************************************
* name: uart0_uart1_tran
* func: commnunication with the uart0 and uart1
* para: none
* ret: none
* modify:
* comment:
*********************************************************************************************/
void gprs_test(void)//uart0_uart1_tran
{
int i,nSetBaud;
char cInputChar; // user input char
char nStrWait[50] = "AT command >";
char LF[1] = {0x0A};
char CR[1] = {0x0D};
char *pPt;
unsigned char * baud_sel[][2]={
"0","1200",
"1","2400",
"2","4800",
"3","9600",
0,0};
uart_init(PCLK, 115200, UART2); // initialize the UART2 channel
uart_select(0); // select the control uart channel
uart_printf("\n GPRS Modem Communication Test Example\n");
uart_printf(" %s",__DATE__);
uart_printf(" %s\n",__TIME__);
i = 0;
while(1)
{ //display menu
uart_printf(" %s --- %s\n\r",baud_sel[i][0],baud_sel[i][1]);
i++;
if((int)(baud_sel[i][0]) == 0) break;
}
uart_printf(" Baud rate select for GPRS modem: ");
cInputChar = uart_getch_c();
uart_printf("%c\n",cInputChar);
nSetBaud = (int)(baud_sel[cInputChar-0x30][1]);
uart_change_baud(UART2,atoi(nSetBaud));
uart_printf(" %s",nStrWait);
i = 160;
pPt=nStrWait;
while(1) // SB1202/SB1203 to exit board test
{
cInputChar = uart_getch_c();
if (f_nSelectUart == UART0)
{
uart_select(2); // send to another uart
}
if (f_nSelectUart == UART2)
{
uart_select(0); // send to another uart
*pPt++ = cInputChar;
if((*(pPt-2)==0x0d)&(cInputChar==0x0A)) // Format: DATA 0xd0xa
{
pPt = nStrWait;
uart_sendbyte(cInputChar);
uart_getstring_c(pPt); // waiting for response
if(!strcmp(pPt,"OK"))
{
uart_sendstring("OK\n");
}
if(!strcmp(pPt,"RING"))
{
uart_sendstring("Someone call in...\n");
rGPBCON = rGPBCON & 0xFFFFFC|1; // output
rGPBDAT = rGPBDAT & 0xFFFFFE; // open beep
delay(1200);
rGPBDAT = rGPBDAT & 0xFFFFFE|1; // close beep
}
else // other string
{
continue;
}
}
}
uart_sendbyte(cInputChar);
}
uart_select(0);
uart_printf(" end.\n");
}
/*********************************************************************************************
* name: uart_getch_c
* func: Get a character from the uart and sign the channel
* para: none
* ret: get a char from uart channel
* modify:
* comment:
*********************************************************************************************/
char uart_getch_c(void)
{
while(1)
{
if(rUTRSTAT0 & 0x1) // if receive data ready
{
f_nSelectUart = UART0;
return RdURXH0();
}
if(rUTRSTAT2 & 0x1) // if receive data ready
{
f_nSelectUart = UART2;
return rURXH2;
}
}
}
/*********************************************************************************************
* name: uart_getstring_c
* func: Get string from uart channel and store the result to input address (*pString)
* para: pString -- input, string
* ret: none
* modify:
* comment:
*********************************************************************************************/
void uart_getstring_c(char *pString)
{
char *string2 = pString;
char c;
while((c = uart_getch_c())!='\r')
{
if(c=='\b')
{
if( (int)string2 < (int)pString )
{
// uart_printf("\b \b");
pString--;
}
}
else
{
*pString++ = c;
//uart_sendbyte(c);
}
}
*pString='\0';
//uart_sendbyte('\n');
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -