我使用的是GPRS模块是BENQ的M22A,ARM是lpc2136,呜呜呜,现在要使用不带TCP/IP协议的模块上网,那当然得自己搞协议了,现在遇到的问题是我拨了ATD*99#以后吧,给板子上电,然后板子开始进行一系列AT命令的初始化,然后就开始拨ATD*99#,三次握手都通过了,我还能看到primary DNS adress和sencondary DNS adress,反正到了这一步,就是GPRS模块已经得到IP地址了,是不是啊?就说明握手成功了,那继续往下看,从串口返回:udp_estalished.表明UDP连接已经建立了,我开始用串口调试工具发数据给服务器,每发一个:串口上就显示:receive some data from user :******
send it to the modem:*******,既然已经出现这个提示了,就更证明udp连接已经成功了,否则的话会显示:receive some data from user :******, NO UDP or TCP Conection exist!drop the data!
但是连接只能维持十秒钟左右,下面就断开了,串口提示工具提示:connect time expire() Link_Down(),ipcp_close();LPC_Down等等,下面就是开始重新拨号了,重新拨号首先又得进行三次握手,但是在握手的第一步就会收到modem的信息,connect time expire,然后下面又是重新拨号,就这么反复拨号,怎么都上不了了,modem返回的一直是connect time expire 。这是怎么回事啊,请高手们给点指点,我不知咋办了?
/*
*start config GPRS Modem, such as HUAWEI GTM900, MC35i,etc.
*/
err = active_Modem(); //激活GPRS模块
if(err NEQ SYS_ERR_OK)
{
DEBUG_EVENT("Modem open failed! we must shut down system!\r\n");
shut_system();
}
DEBUG_EVENT("Modem open successful!\r\n");
DEBUG_EVENT("System block 30 seconds!\r\n");//等待30秒,等待SIM卡找到网络
/*
*wait for GPRS Modem serching network,
* initinalize: such as SMS, Telephone Book etc.
*/
second_sleep(30);
err = init_Modem(); //写一些基本的AT命令
if(err NEQ SYS_ERR_OK)
{
DEBUG_EVENT("Modem basic AT Commands initialize failed! we must shut down system\r\n");
shut_system();
}
DEBUG_EVENT("Modem basic AT Commands initialize successful!\r\n");
while(1)
{
/*
*check if one timer is overflow, if so, run it
*/
check_sys_timer();
/*
*check the receive buffer of Modem
*/
if(get_modem_datalen() > 0)//如果modem收到信息
{
DEBUG_EVENT(" Receive some data from Modem:\r\n");
len = get_modem_data(buf); //接收下来
pppInProc(pd, buf, len); //进行处理
}
/*
*check the receive buffer of User Equipment
*/
if(get_user_datalen() > 0) //如果用户向modem发信息
{
DEBUG_EVENT("Receive some data from User Eqipment!\r\n");
len = get_user_data(buf);//接收下来
if(get_Mytcpip_state() EQ UDP_ESTABLISHED)//判断存在的是哪种连接
{
if( udp_write(buf, len) NEQ ERR_OK)
{
DEBUG_ERR("Send some data to UDP Peer, but failed!\r\n");
//add you code here.
//store the data
}
}
else if(get_Mytcpip_state() EQ TCP_ESTABLISHED))//判断存在的是哪种连接
{
if( tcp_write(tcp_active_pcbs, (const void *)buf, len, 1) NEQ ERR_OK)
{
DEBUG_ERR("Send some data to TCP Peer, but failed!\r\n");
//add you code here.
//store the data
}
}
else
{
DEBUG_EVENT("No TCP or UDP Connect exist!drop the data\r\n");
}
}
/*
*check the state of ppp
*if the link is DEAD, I deal it very simple,
*do not release the source of PPP/TCP/IP/UDP etc.
*just call the function: lwip_init(). but it work.
*then goto the head of main func.
*The state of DCD should be checked here,but I will ignore it.
*/
if(ppp_dead(pd) EQ TRUE)//如果链路死去
{
lwip_init();
set_Mytcpip_state(PPP_DEAD);
goto start_tcpip; //回去重新拨号
}
/*
*check the state of my tcpip
*/
switch(get_Mytcpip_state())//检查目前的状态
{
case PPP_ESTABLISHED: //这个是刚握完手的状态
if(get_sys_err() < MAX_SYS_ERR_ALLOW)
{
tcpip_open(); //所以握完手之后要打开tcp_ip(这个函数里可以选 择是用udp还是tcp,我选的udp)
break;
}
else
set_Mytcpip_state(TCPIP_STATE_UNKNOWN);