From 340919435641c486a96ea922a8759bff3fce5715 Mon Sep 17 00:00:00 2001 From: chenyong <1521761801@qq.com> Date: Mon, 23 Jul 2018 14:29:10 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E3=80=91M26=20?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=E5=9F=9F=E5=90=8D=E8=A7=A3=E6=9E=90=E5=93=8D?= =?UTF-8?q?=E5=BA=94=E6=97=B6=E9=97=B4=E4=B8=BA=2014=20=E7=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenyong <1521761801@qq.com> --- at_socket_esp8266.c | 56 ++++++++++++++++++++++++++++++--------------- at_socket_m26.c | 3 ++- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/at_socket_esp8266.c b/at_socket_esp8266.c index 0e6e416..7d8785f 100644 --- a/at_socket_esp8266.c +++ b/at_socket_esp8266.c @@ -323,7 +323,9 @@ __exit: */ static int esp8266_domain_resolve(const char *name, char ip[16]) { - int result = RT_EOK; +#define RESOLVE_RETRY 5 + + int i, result = RT_EOK; char recv_ip[16] = { 0 }; at_response_t resp = RT_NULL; @@ -339,26 +341,37 @@ static int esp8266_domain_resolve(const char *name, char ip[16]) rt_mutex_take(at_event_lock, RT_WAITING_FOREVER); -__restart: - if (at_exec_cmd(resp, "AT+CIPDOMAIN=\"%s\"", name) < 0) + for(i = 0; i < RESOLVE_RETRY; i++) { - result = -RT_ERROR; - goto __exit; + if (at_exec_cmd(resp, "AT+CIPDOMAIN=\"%s\"", name) < 0) + { + result = -RT_ERROR; + goto __exit; + } + + /* parse the third line of response data, get the IP address */ + if(at_resp_parse_line_args(resp, at_resp_get_line_num_by_kw(resp, "+CIPDOMAIN:"), + "+CIPDOMAIN:%s", recv_ip) < 0) + { + rt_thread_delay(rt_tick_from_millisecond(100)); + /* resolve failed, maybe receive an URC CRLF */ + continue; + } + + if (strlen(recv_ip) < 8) + { + rt_thread_delay(rt_tick_from_millisecond(100)); + /* resolve failed, maybe receive an URC CRLF */ + continue; + } + else + { + strncpy(ip, recv_ip, 15); + ip[15] = '\0'; + break; + } } - /* parse the third line of response data, get the IP address */ - at_resp_parse_line_args(resp, 1, "+CIPDOMAIN:%s", recv_ip); - - if (strlen(recv_ip) < 8) - { - rt_thread_delay(rt_tick_from_millisecond(100)); - /* resolve failed, maybe receive an URC CRLF */ - goto __restart; - } - - strncpy(ip, recv_ip, 15); - ip[15] = '\0'; - __exit: rt_mutex_release(at_event_lock); @@ -623,7 +636,12 @@ int esp8266_ping(int argc, char **argv) return -RT_ERROR; } - at_resp_parse_line_args(resp, 1, "+%d", &req_time); + if(at_resp_parse_line_args(resp, at_resp_get_line_num_by_kw(resp, "+"), + "+%d", &req_time) < 0) + { + continue; + } + if (req_time) { rt_kprintf("32 bytes from %s icmp_seq=%d time=%d ms\n", argv[1], icmp_seq, req_time); diff --git a/at_socket_m26.c b/at_socket_m26.c index 8c95485..858e2ea 100644 --- a/at_socket_m26.c +++ b/at_socket_m26.c @@ -384,7 +384,8 @@ static int m26_domain_resolve(const char *name, char ip[16]) RT_ASSERT(name); RT_ASSERT(ip); - resp = at_create_resp(128, 4, rt_tick_from_millisecond(5000)); + /* The maximum response time is 14 seconds, affected by network status */ + resp = at_create_resp(128, 4, rt_tick_from_millisecond(14 * 1000)); if (!resp) { LOG_E("No memory for response structure!");