概述
先初始化EC20 主要有以下AT指令 可以根据需要增加 注意LWIP+EC20 PPP 只能使用软件检验
所以不能打开 CHECKSUM_BY_HARDWARE 这个宏定义
"+++" //退出透传模式
"ATE0rn" //关掉回显
"AT+CPIN?rn" //查询SIM卡的状态
"AT+CSQrn" //Signal Quality Report 检查网络信号强度和SIM卡情况
"AT+CREG?rn" //查询网络注册信息
"AT+CGREG?rn" //查询无线分组业务
"AT+QIACT?rn" //获取本地IP地址 contextID=1
"AT+QIACT=1rn" //Activate a PDP Context 激活移动场景contextID=1
"AT+CGSNrn" //Query IMEI
"AT+QCCIDrn" //Query CCID
LWIP PPP初始化流程如下
u8 lwip_PPP_comm_init(void)
{
uint8_t ctx = 0;
while(EC20_status_check())
{
sys_msleep(1000);
ctx = 0;
}
EC20_PPP(); //"ATD*99#rn"
ppp_modle=1;
tcpip_init(NULL,NULL);
netif_set_status_callback(&lwip_netif, netif_status_callback);
netif_set_link_callback(&lwip_netif, netif_link_callback);
netif_set_remove_callback(&lwip_netif, netif_remove_callback);
ppp = pppos_create( &lwip_netif, output_cb, status_cb, &ctx );
sys_thread_new("PppRead", PppRead, NULL, 1024, LWIP_GETDATA_TASK_PRIO);
if( ppp_connect(ppp, 0) != ERR_OK )
{
while(1)
{
sys_msleep(1000);
}
}
ppp_set_default(ppp);
return ctx;
}
EC20_status_check 是EC20初始化和状态检测
EC20_PPP(); //"ATD*99#rn"
uint32_t output_cb(ppp_pcb *pcb, uint8_t *data, uint32_t len, void *ctx) 写数据
uint32_t output_cb(ppp_pcb *pcb, uint8_t *data, uint32_t len, void *ctx) {
if(ppp_modle)
{
//往串口发送数据
}
return 0;
}
void status_cb(ppp_pcb *pcb, int err_code, void *ctx) 状态改变回调函数 使用LWIP文档提供的示例
void status_cb(ppp_pcb *pcb, int err_code, void *ctx) {
struct netif *pppif = ppp_netif(pcb);
LWIP_UNUSED_ARG(ctx);
switch(err_code) {
case PPPERR_NONE: {
#if LWIP_DNS
const ip_addr_t *ns;
#endif /* LWIP_DNS */
PPP_PRINT("status_cb: Connectedn");
#if PPP_IPV4_SUPPORT
PPP_PRINT(" our_ipaddr = %sn", ipaddr_ntoa(&pppif->ip_addr));
PPP_PRINT(" his_ipaddr = %sn", ipaddr_ntoa(&pppif->gw));
PPP_PRINT(" netmask = %sn", ipaddr_ntoa(&pppif->netmask));
ppp_conn_success = 1;
#if LWIP_DNS
ns = (ip_addr_t*)dns_getserver(0);
PPP_PRINT(" dns1 = %sn", ipaddr_ntoa(ns));
ns = (ip_addr_t*)dns_getserver(1);
PPP_PRINT(" dns2 = %sn", ipaddr_ntoa(ns));
ns = ns;
pppif = pppif;
#endif /* LWIP_DNS */
#endif /* PPP_IPV4_SUPPORT */
#if PPP_IPV6_SUPPORT
PPP_PRINT(" our6_ipaddr = %sn", ip6addr_ntoa(netif_ip6_addr(pppif, 0)));
#endif /* PPP_IPV6_SUPPORT */
break;
}
case PPPERR_PARAM: {
PPP_PRINT("status_cb: Invalid parametern");
break;
}
case PPPERR_OPEN: {
PPP_PRINT("status_cb: Unable to open PPP sessionn");
break;
}
case PPPERR_DEVICE: {
PPP_PRINT("status_cb: Invalid I/O device for PPPn");
break;
}
case PPPERR_ALLOC: {
PPP_PRINT("status_cb: Unable to allocate resourcesn");
break;
}
case PPPERR_USER: {
PPP_PRINT("status_cb: User interruptn");
break;
}
case PPPERR_CONNECT: {
PPP_PRINT("status_cb: Connection lostn");
break;
}
case PPPERR_AUTHFAIL: {
PPP_PRINT("status_cb: Failed authentication challengen");
break;
}
case PPPERR_PROTOCOL: {
PPP_PRINT("status_cb: Failed to meet protocoln");
break;
}
case PPPERR_PEERDEAD: {
PPP_PRINT("status_cb: Connection timeoutn");
break;
}
case PPPERR_IDLETIMEOUT: {
PPP_PRINT("status_cb: Idle Timeoutn");
break;
}
case PPPERR_CONNECTTIME: {
PPP_PRINT("status_cb: Max connect time reachedn");
break;
}
case PPPERR_LOOPBACK: {
PPP_PRINT("status_cb: Loopback detectedn");
break;
}
default: {
PPP_PRINT("status_cb: Unknown error code %dn", err_code);
break;
}
}
/*
* This should be in the switch case, this is put outside of the switch
* case for example readability.
*/
if (err_code == PPPERR_NONE) {
return;
}
/* ppp_close() was previously called, don't reconnect */
if (err_code == PPPERR_USER) {
/* ppp_free(); -- can be called here */
return;
}
ppp_conn_success = 0;
/*
* Try to reconnect in 30 seconds, if you need a modem chatscript you have
* to do a much better signaling here ;-)
*/
ppp_connect(pcb, 30);
/* OR ppp_listen(pcb); */
}
void PppRead( void * argument ) 读取串口数据给LWIP内核
void PppRead( void * argument )
{
uint8_t Readbuf[512];
uint32_t recv_size,timeout=0;
while(1)
{
if( ppp )
{
recv_size =0;
if(ppp_modle)
{
recv_size = uart_ReadData(Readbuf,sizeof(Readbuf));
if( recv_size)
{
pppos_input_tcpip(ppp, Readbuf, recv_size );//0x7e
}
}
sys_msleep(5);
}
else
{
sys_msleep(100);
}
}
}
最后
以上就是迷路皮带为你收集整理的STM32407+LWIP+EC20 PPP拨号流程的全部内容,希望文章能够帮你解决STM32407+LWIP+EC20 PPP拨号流程所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复