2018-07-09 18:17:49 +08:00
|
|
|
/*
|
|
|
|
* File : at_client_sample.c
|
|
|
|
* This file is part of RT-Thread RTOS
|
|
|
|
* COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2018-07-06 chenyong first version
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
2018-07-21 16:11:42 +08:00
|
|
|
#include <at.h>
|
2018-07-09 18:17:49 +08:00
|
|
|
|
|
|
|
/* AT+CIFSR Query local IP address and MAC */
|
|
|
|
int at_client_test(int argc, char **argv)
|
|
|
|
{
|
2018-07-21 16:11:42 +08:00
|
|
|
at_response_t resp = RT_NULL;
|
2018-07-09 18:17:49 +08:00
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
if (argc != 1)
|
|
|
|
{
|
|
|
|
LOG_E("at_client_test - AT client send commands to AT server.");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-07-21 16:11:42 +08:00
|
|
|
resp = at_create_resp(256, 0, rt_tick_from_millisecond(5000));
|
2018-07-09 18:17:49 +08:00
|
|
|
if (resp == RT_NULL)
|
|
|
|
{
|
|
|
|
LOG_E("No memory for response structure!");
|
|
|
|
return -2;
|
|
|
|
}
|
|
|
|
|
2018-07-09 20:48:22 +08:00
|
|
|
/* close echo */
|
2018-07-21 16:11:42 +08:00
|
|
|
at_exec_cmd(resp, "ATE0");
|
2018-07-09 20:48:22 +08:00
|
|
|
|
2018-07-21 16:11:42 +08:00
|
|
|
result = at_exec_cmd(resp, "AT+CIFSR");
|
2018-07-09 18:17:49 +08:00
|
|
|
if (result != RT_EOK)
|
|
|
|
{
|
|
|
|
LOG_E("AT client send commands failed or return response error!");
|
|
|
|
goto __exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print response line buffer */
|
|
|
|
{
|
|
|
|
const char *line_buffer = RT_NULL;
|
|
|
|
|
|
|
|
LOG_D("Response buffer");
|
|
|
|
|
|
|
|
for(rt_size_t line_num = 1; line_num <= resp->line_counts; line_num++)
|
|
|
|
{
|
|
|
|
if((line_buffer = at_resp_get_line(resp, line_num)) != RT_NULL)
|
|
|
|
{
|
|
|
|
LOG_D("line %d buffer : %s", line_num, line_buffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG_E("Parse line buffer error!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-07-21 16:11:42 +08:00
|
|
|
char resp_arg[AT_CMD_MAX_LEN] = { 0 };
|
2018-07-09 18:17:49 +08:00
|
|
|
const char * resp_expr = "%*[^\"]\"%[^\"]\"";
|
|
|
|
|
|
|
|
LOG_D(" Parse arguments");
|
2018-07-09 20:48:22 +08:00
|
|
|
if (at_resp_parse_line_args(resp, 1, resp_expr, resp_arg) == 1)
|
2018-07-09 18:17:49 +08:00
|
|
|
{
|
|
|
|
LOG_D("Station IP : %s", resp_arg);
|
2018-07-21 16:11:42 +08:00
|
|
|
memset(resp_arg, 0x00, AT_CMD_MAX_LEN);
|
2018-07-09 18:17:49 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG_E("Parse error, current line buff : %s", at_resp_get_line(resp, 4));
|
|
|
|
}
|
|
|
|
|
2018-07-09 20:48:22 +08:00
|
|
|
if (at_resp_parse_line_args(resp, 2, resp_expr, resp_arg) == 1)
|
2018-07-09 18:17:49 +08:00
|
|
|
{
|
|
|
|
LOG_D("Station MAC : %s", resp_arg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LOG_E("Parse error, current line buff : %s", at_resp_get_line(resp, 5));
|
|
|
|
goto __exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
__exit:
|
|
|
|
if(resp)
|
|
|
|
{
|
2018-07-21 16:11:42 +08:00
|
|
|
at_delete_resp(resp);
|
2018-07-09 18:17:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
#ifdef FINSH_USING_MSH
|
|
|
|
#include <finsh.h>
|
|
|
|
MSH_CMD_EXPORT(at_client_test, AT client send cmd and get response);
|
|
|
|
#endif
|