From cb7ea72565144b7670a8a6c836bdc539391c2d6e Mon Sep 17 00:00:00 2001 From: chenyong <1521761801@qq.com> Date: Thu, 7 Mar 2019 16:35:28 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=B7=BB=E5=8A=A0=E3=80=91esp8266=20a?= =?UTF-8?q?t=5Fifconfig=20=E5=8A=9F=E8=83=BD?= 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 | 76 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/at_socket_esp8266.c b/at_socket_esp8266.c index 008b647..1a88147 100644 --- a/at_socket_esp8266.c +++ b/at_socket_esp8266.c @@ -668,10 +668,86 @@ int esp8266_ping(int argc, char **argv) return RT_EOK; } +int esp8266_ifconfig(int argc, char **argv) +{ +#define AT_ADDR_LEN 128 + int result = RT_EOK; + at_response_t resp = RT_NULL; + char ip[AT_ADDR_LEN], mac[AT_ADDR_LEN]; + char gateway[AT_ADDR_LEN], netmask[AT_ADDR_LEN]; + const char *resp_expr = "%*[^\"]\"%[^\"]\""; + + if (argc != 1) + { + rt_kprintf("Please input: at_ifconfig\n"); + return -RT_ERROR; + } + + rt_memset(ip, 0x00, sizeof(ip)); + rt_memset(mac, 0x00, sizeof(mac)); + rt_memset(gateway, 0x00, sizeof(gateway)); + rt_memset(netmask, 0x00, sizeof(netmask)); + + resp = at_create_resp(512, 0, rt_tick_from_millisecond(300)); + if (!resp) + { + rt_kprintf("No memory for response structure!\n"); + return -RT_ENOMEM; + } + + rt_mutex_take(at_event_lock, RT_WAITING_FOREVER); + if (at_exec_cmd(resp, "AT+CIFSR") < 0) + { + rt_kprintf("AT send \"AT+CIFSR\" commands error!\n"); + result = -RT_ERROR; + goto __exit; + } + + if (at_resp_parse_line_args(resp, 2, resp_expr, mac) <= 0) + { + rt_kprintf("Parse error, current line buff : %s\n", at_resp_get_line(resp, 2)); + result = -RT_ERROR; + goto __exit; + } + + if (at_exec_cmd(resp, "AT+CIPSTA?") < 0) + { + rt_kprintf("AT send \"AT+CIPSTA?\" commands error!\n"); + result = -RT_ERROR; + goto __exit; + } + + if (at_resp_parse_line_args(resp, 1, resp_expr, ip) <= 0 || + at_resp_parse_line_args(resp, 2, resp_expr, gateway) <= 0 || + at_resp_parse_line_args(resp, 3, resp_expr, netmask) <= 0) + { + rt_kprintf("Prase \"AT+CIPSTA?\" commands resposne data error!"); + result = -RT_ERROR; + goto __exit; + } + + rt_kprintf("network interface: esp8266\n"); + rt_kprintf("MAC: %s\n", mac); + rt_kprintf("ip address: %s\n", ip); + rt_kprintf("gw address: %s\n", gateway); + rt_kprintf("net mask : %s\n", netmask); + +__exit: + rt_mutex_release(at_event_lock); + + if (resp) + { + at_delete_resp(resp); + } + + return result; +} + #ifdef FINSH_USING_MSH #include MSH_CMD_EXPORT_ALIAS(esp8266_net_init, at_net_init, initialize AT network); MSH_CMD_EXPORT_ALIAS(esp8266_ping, at_ping, AT ping network host); +MSH_CMD_EXPORT_ALIAS(esp8266_ifconfig, at_ifconfig, list the information of network interfaces); #endif static const struct at_device_ops esp8266_socket_ops = {