|
|
@ -4,6 +4,31 @@ |
|
|
|
#include <lwip/sockets.h> |
|
|
|
#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); |
|
|
|
} |
|
|
|
|
|
|
|
/* 查找指令表中对应的指令 */ |
|
|
|