From 8eee831bf92d8fe23725a77eb9bcf12333f319b3 Mon Sep 17 00:00:00 2001 From: tianjialong Date: Thu, 2 Mar 2023 16:30:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=81=E8=A3=85=E4=BA=86at=E6=8C=87=E4=BB=A4?= =?UTF-8?q?=E4=B8=AD=E5=85=B1=E7=94=A8=E7=9A=84=E6=A8=A1=E6=9D=BF=EF=BC=8C?= =?UTF-8?q?=E8=AE=BE=E7=BD=AEip=EF=BC=8C=E8=AE=BE=E7=BD=AE=E7=BD=91?= =?UTF-8?q?=E5=85=B3=EF=BC=8C=E8=AE=BE=E7=BD=AE=E5=AD=90=E7=BD=91=E6=8E=A9?= =?UTF-8?q?=E7=A0=81=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MDK-ARM/LWIP.uvguix.29643 | 6 ++--- usersrc/atcmd.c | 63 +++++++++++++++++++++++++++-------------------- usersrc/atcmd.h | 2 ++ 3 files changed, 41 insertions(+), 30 deletions(-) diff --git a/MDK-ARM/LWIP.uvguix.29643 b/MDK-ARM/LWIP.uvguix.29643 index ef808a8..3bdc5dc 100644 --- a/MDK-ARM/LWIP.uvguix.29643 +++ b/MDK-ARM/LWIP.uvguix.29643 @@ -3705,9 +3705,9 @@ ..\usersrc\atcmd.c - 41 - 71 - 85 + 0 + 37 + 47 1 0 diff --git a/usersrc/atcmd.c b/usersrc/atcmd.c index 36a4085..f51e7f8 100644 --- a/usersrc/atcmd.c +++ b/usersrc/atcmd.c @@ -4,6 +4,31 @@ #include #include "config.h" +#define at_address_cmd_template(_config_get) \ + { \ + ip4_addr_t int_addr; \ + char ip_address[16]; \ + if (*p == '?') \ + { \ + printf("config ip address:%s\r\n", inet_ntoa(_config_get)); \ + } \ + else \ + { \ + if (len >= sizeof(ip_address)) \ + { /* 长度判断 */ \ + printf("AT+ERR\r\n"); \ + return AT_ERR; \ + } /* 拷贝len有效字符长度的字符串到ip_address中 */ \ + strncpy(ip_address, (const char *)p, len); \ + ip_address[len] = 0; /* 这个必须要加,否则转换会出错 */ \ + inet_aton(ip_address, &int_addr); \ + _config_get = int_addr.addr; \ + config_dump_config(); \ + printf("AT+OK\r\n"); \ + } \ + return AT_SUCCESS; \ + } + #define at_processer_rx_buf_size 128 #define at_processer_tx_buf_size 128 @@ -19,8 +44,8 @@ static uint8_t at_rx_buf[at_processer_rx_buf_size]; const AT_cmd_func at_cmd_func[] = { {AT_CMD_TEST, "AT", at_cmd_test}, {AT_CMD_IP, "AT+IP=", at_cmd_ip}, - {AT_CMD_GW, "AT+GW=", NULL}, - {AT_CMD_NETMASK, "AT+NETMASK=", NULL}, + {AT_CMD_GW, "AT+GW=", at_cmd_gw}, + {AT_CMD_NETMASK, "AT+NETMASK=", at_cmd_netmask}, {AT_CMD_NETMODULE, "AT+NETMODULE=", NULL}, {AT_END, NULL, NULL}}; @@ -64,33 +89,17 @@ AT_STATUS at_cmd_test(unsigned char *p, unsigned char len) AT_STATUS at_cmd_ip(unsigned char *p, unsigned char len) { - ip4_addr_t int_addr; - char ip_address[16]; - - if (*p == '?') - { - printf("config ip address:%s\r\n", inet_ntoa(config_get()->ip)); - } - else - { - if (len >= sizeof(ip_address)) - { - /* 长度判断 */ - printf("AT+ERR\r\n"); - return AT_ERR; - } - /* 拷贝len有效字符长度的字符串到ip_address中 */ - strncpy(ip_address, (const char *)p, len); - ip_address[len] = 0; /* 这个必须要加,否则转换会出错 */ - inet_aton(ip_address, &int_addr); - - config_get()->ip = int_addr.addr; + at_address_cmd_template(config_get()->ip); +} - config_dump_config(); +AT_STATUS at_cmd_gw(unsigned char *p, unsigned char len) +{ + at_address_cmd_template(config_get()->gw); +} - printf("AT+OK\r\n"); - } - return AT_SUCCESS; +AT_STATUS at_cmd_netmask(unsigned char *p, unsigned char len) +{ + at_address_cmd_template(config_get()->netmask); } /* 查找指令表中对应的指令 */ diff --git a/usersrc/atcmd.h b/usersrc/atcmd.h index a174d68..3bb5505 100644 --- a/usersrc/atcmd.h +++ b/usersrc/atcmd.h @@ -35,6 +35,8 @@ unsigned int mstrlen(const char *s); int mstrncmp(const char *s1, const char *s2, int n); AT_STATUS at_cmd_test(unsigned char *p, unsigned char len); AT_STATUS at_cmd_ip(unsigned char *p, unsigned char len); +AT_STATUS at_cmd_gw(unsigned char *p, unsigned char len); +AT_STATUS at_cmd_netmask(unsigned char *p, unsigned char len); unsigned char AT_cmd_search(unsigned char *p, unsigned char len); AT_STATUS at_cmd_parse(unsigned char *p, unsigned char len); void at_cmd_processer_push_data(uint8_t rxdata);