#include "cvtpxa270.h"
#include "gprs.h"
#include "gb2312-unicode.h"
int gprs_ctrl_value = 0x0;
int gprs_ctrl_value1 = 0x0;
/* 接收数据缓冲区 */
char gprs_recv_buf[GPRS_RECV_CMD_MAX_BUF];
int gprs_recv_read = 0;
int gprs_recv_write = 0;
int int_bak;
/********************************************************************
// Function name : gprs_disable_int
// Description : 关中断
// Return type : void
// Argument :
*********************************************************************/
void gprs_disable_int()
{
// SET_IF();
}
/********************************************************************
// Function name : gprs_enable_int
// Description : 开中断
// Return type : void
// Argument :
*********************************************************************/
void gprs_enable_int()
{
// CLR_IF();
}
/********************************************************************
// Function name : gprs_uart_ctrl
// Description : GPRS使用串口1,串口0用于显示,GPRS初始化之前请
// 调用该函数进行初始化
// Return type : void
// Argument : int uart = 0x01
*********************************************************************/
void gprs_uart_ctrl(int uart)
{
gprs_ctrl_value &= ~GPRS_CONTROL_MASK_UART;
gprs_ctrl_value |= uart;
*(unsigned char *)0x04001000 = gprs_ctrl_value;
}
/********************************************************************
// Function name : gprs_send_cmd
// Description : 发送GPRS命令字串
// Return type : void
// Argument : char *cmdstring
*********************************************************************/
void gprs_send_cmd(char *cmdstring)
{
// disable int
gprs_disable_int();
// select uart 1
Uart_Select(FFUART);
// send command
Uart_Printf("Send -> %s\n", cmdstring);
// select uart 1
Uart_Select(BTUART);
// send command
Uart_Printf(cmdstring);
// enable int
gprs_enable_int();
}
/********************************************************************
// Function name : gprs_recv_char
// Description : 从GPRS接收字符,只能从中断服务函数中调用
// Return type : void
// Argument :
*********************************************************************/
void gprs_recv_char()
{
char ch;
do
{
// disable int
// gprs_disable_int();
// receive command
Uart_Select(BTUART);
ch = Uart_Getkey();
// enable int
// gprs_enable_int();
if(ch == 0)
{
return;
}else
{
// select uart 1
gprs_recv_buf[gprs_recv_write] = ch;
gprs_recv_write ++;
if(gprs_recv_write >= GPRS_RECV_CMD_MAX_BUF)
gprs_recv_write = 0;
if(gprs_recv_write == gprs_recv_read)
{
// 缓冲区以满
gprs_recv_read ++;
if(gprs_recv_read >= GPRS_RECV_CMD_MAX_BUF)
gprs_recv_read = 0;
}
}
}while(1);
}
/********************************************************************
// Function name : gprs_recv_cmd
// Description :
// Return type : int:
// GPRS_OK -- 接收到命令
// GPRS_ERR -- 未接收到命令
// Argument : char *cmd:返回的命令
*********************************************************************/
int gprs_recv_cmd(char *cmd)
{
int loopcnt = 0;
int ncount = 0;
while(1)
{
if(gprs_recv_read == gprs_recv_write)
{
return GPRS_ERR;
ncount ++;
if(ncount >= 1000)
{
cmd[loopcnt++] = 0;
return GPRS_ERR;
}
continue;
}
ncount = 0;
if( (gprs_recv_buf[gprs_recv_read] == '\r') || (gprs_recv_buf[gprs_recv_read] == '\n'))
{
cmd[loopcnt ++] = 0;
gprs_recv_read ++;
if(gprs_recv_read >= GPRS_RECV_CMD_MAX_BUF)
gprs_recv_read = 0;
if(strlen(cmd))
{
TRACE("\nRecv <- ");
TRACE(cmd);
TRACE("\n");
}
return GPRS_OK;
}else
{
cmd[loopcnt ++] = gprs_recv_buf[gprs_recv_read];
gprs_recv_read ++;
if(gprs_recv_read >= GPRS_RECV_CMD_MAX_BUF)
gprs_recv_read = 0;
}
}
}
/********************************************************************
// Function name : gprs_init
// Description : GPRS初始化函数
// Return type : void
// Argument :
*********************************************************************/
void gprs_init()
{
// uart0 -> db9 uart1 -> gprs
gprs_uart_ctrl(0x4);
XsGpioSetAlternateFunction ( XS_GPIO_ID_101, XS_GPIO_ALT_FUNC_GPIO);
XsGpioSetDirection (XS_GPIO_ID_101, XS_GPIO_DIR_OUT, XS_GPIO_PIN_LEVEL_1);
}
/********************************************************************
// Function name : gprs_uninit
// Description : gprs模块退出
// Return type : void
// Argument :
*********************************************************************/
void gprs_uninit()
{
}
/********************************************************************
// Function name : gprs_pwr_on_off
// Description : GPRS复位操作
// Return type : void
// Argument : int bon
// GPRS_PWR_ON 开启
// GPRS_PWR_OFF 0 关闭
*********************************************************************/
void gprs_pwr_on_off(int bon)
{
static status_pwr = GPRS_PWR_OFF;
int loopcnt;
if(bon == GPRS_PWR_ON)
{
// if(status_pwr == GPRS_PWR_ON)
// return;
XsGpioSetLevel (XS_GPIO_ID_101, XS_GPIO_PIN_LEVEL_1);
Delay(100);
XsGpioSetLevel (XS_GPIO_ID_101, XS_GPIO_PIN_LEVEL_0);
Delay(1500);
XsGpioSetLevel (XS_GPIO_ID_101, XS_GPIO_PIN_LEVEL_1);
status_pwr = GPRS_PWR_ON;
Delay(1000);
}else
{
// if(status_pwr == GPRS_PWR_OFF)
// return;
XsGpioSetLevel (XS_GPIO_ID_101, XS_GPIO_PIN_LEVEL_1);
Delay(100);
XsGpioSetLevel (XS_GPIO_ID_101, XS_GPIO_PIN_LEVEL_1);
Delay(1500);
XsGpioSetLevel (XS_GPIO_ID_101, XS_GPIO_PIN_LEVEL_1);
status_pwr = GPRS_PWR_OFF;
}
}
/********************************************************************
// Function name : gprs_analyze_msg
// Description : 分析接收到的GPRS命令
// Return type : int
// Argument : char * message
*********************************************************************/
int gprs_analyze_msg(char * message)
{
if (strstr(message, "OK") != 0)
{
if (strstr(message, "+CMGS:") != 0)
{
// threadData.m_rmReceMsg.m_strMessage1 = message;
// ::PostMessage(threadData.m_hWnd, WM_SMS_SEND_RESPONSE, 0, 0);
}
else if (strstr(message, "+CMGR:") != 0)
{
return AT_RECV_MSG_CMGR;
}
else if (strstr(message, "+CSQ:") != 0)
{
// threadData.m_rmReceMsg.m_strMessage1 = message;
// ::PostMessage(threadData.m_hWnd, WM_SIGNAL_STRENGTH, 0, 0);
}
else if (strstr(message, "+CBC:") != 0)
{
// threadData.m_rmReceMsg.m_strMessage1 = message;
// ::PostMessage(threadData.m_hWnd, WM_BATTERY_LEVEL, 0, 0);
}
else if (strstr(message, "+CRSL:") != 0)
{
// threadData.m_rmReceMsg.m_strMessage1 = message;
// ::PostMessage(threadData.m_hWnd, WM_RINGER_LEVEL, 0, 0);
}
else if (strstr(message, "+CREG:") != 0)
{
// threadData.m_rmReceMsg.m_strMessage1 = message;
// ::PostMessage(threadData.m_hWnd, WM_NETWORK_REGISTRATION, 0, 0);
}
else if (strstr(message, "+CGMI") != 0)
{
// threadData.m_rmReceMsg.m_strMessage1 = message;
// ::PostMessage(threadData.m_hWnd, WM_MANUFACTURER_ID, 0, 0);
}
else if (strstr(message, "+CGMM") != 0)
{
// threadData.m_rmReceMsg.m_strMessage1 = message;
// ::PostMessage(threadData.m_hWnd, WM_MODEL_ID, 0, 0);
}
else if (strstr(message, "+CGMR") != 0)
{
// threadData.m_rmReceMsg.m_strMessage1 = message;
// ::PostMessage(threadData.m_hWnd, WM_REVISION_ID, 0, 0);
}
else if (strstr(message, "+CNUM") != 0)
{
// threadData.m_rmReceMsg.m_strMessage1 = message;
// ::PostMessage(threadData.m_hWnd, WM_SUBSCRIBER_NUMBER, 0, 0);
}
else if (strstr(message, "+CSCS") != 0)
{
// threadD