Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
rt-thread
提交
ed7f0cad
R
rt-thread
项目概览
BaiXuePrincess
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
ed7f0cad
编写于
8月 28, 2018
作者:
Lawlieta
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[net][at] Add AT multiple client support
上级
6d702e57
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
352 addition
and
205 deletion
+352
-205
components/net/at/Kconfig
components/net/at/Kconfig
+19
-17
components/net/at/include/at.h
components/net/at/include/at.h
+45
-21
components/net/at/src/at_cli.c
components/net/at/src/at_cli.c
+30
-14
components/net/at/src/at_client.c
components/net/at/src/at_client.c
+256
-151
components/net/at/src/at_server.c
components/net/at/src/at_server.c
+2
-2
未找到文件。
components/net/at/Kconfig
浏览文件 @
ed7f0cad
...
...
@@ -51,28 +51,30 @@ if RT_USING_AT
if AT_USING_CLIENT
config AT_CLIENT_DEVICE
string "Client device name"
default "uart2"
config AT_CLIENT_RECV_BUFF_LEN
int "The maximum length of client data accepted"
default 512
config AT_CLIENT_NUM_MAX
int "The maximum number of supported clients"
default 1
range 1 65535
config AT_USING_SOCKET
bool "
Provide similar BSD Socket API by AT
"
bool "
Enable BSD Socket API support by AT commnads
"
select RT_USING_LIBC
default n
endif
config AT_USING_CLI
bool "Enable command-line interface for AT commands"
default y
depends on FINSH_USING_MSH
config AT_PRINT_RAW_CMD
bool "Enable print RAW format AT command communication data"
default n
if AT_USING_SERVER || AT_USING_CLIENT
config AT_USING_CLI
bool "Enable CLI(Command-Line Interface) for AT commands"
default y
depends on FINSH_USING_MSH
config AT_PRINT_RAW_CMD
bool "Enable print RAW format AT command communication data"
default n
endif
endif
...
...
components/net/at/include/at.h
浏览文件 @
ed7f0cad
...
...
@@ -20,6 +20,7 @@
* Change Logs:
* Date Author Notes
* 2018-03-30 chenyong first version
* 2018-08-17 chenyong multiple client support
*/
#ifndef __AT_H__
...
...
@@ -30,7 +31,8 @@
#ifdef __cplusplus
extern
"C"
{
#endif
#define AT_SW_VERSION "0.3.0"
#define AT_SW_VERSION "1.0.0"
#define AT_SW_VERSION_NUM 0x10000
#define DBG_ENABLE
#define DBG_SECTION_NAME "AT"
...
...
@@ -67,16 +69,13 @@ extern "C" {
#define AT_SERVER_RECV_BUFF_LEN 256
#endif
#ifndef AT_CLIENT_RECV_BUFF_LEN
#define AT_CLIENT_RECV_BUFF_LEN 512
#endif
#ifndef AT_SERVER_DEVICE
#define AT_SERVER_DEVICE "uart2"
#endif
#ifndef AT_CLIENT_DEVICE
#define AT_CLIENT_DEVICE "uart2"
/* the maximum number of supported AT clients */
#ifndef AT_CLIENT_NUM_MAX
#define AT_CLIENT_NUM_MAX 1
#endif
#define AT_CMD_EXPORT(_name_, _args_expr_, _test_, _query_, _setup_, _exec_) \
...
...
@@ -137,7 +136,6 @@ struct at_server
rt_thread_t
parser
;
void
(
*
parser_entry
)(
struct
at_server
*
server
);
};
typedef
struct
at_server
*
at_server_t
;
#endif
/* AT_USING_SERVER */
...
...
@@ -183,8 +181,10 @@ struct at_client
rt_device_t
device
;
at_status_t
status
;
char
end_sign
;
char
recv_buffer
[
AT_CLIENT_RECV_BUFF_LEN
];
char
*
recv_buffer
;
rt_size_t
recv_bufsz
;
rt_size_t
cur_recv_len
;
rt_sem_t
rx_notice
;
rt_mutex_t
lock
;
...
...
@@ -198,7 +198,6 @@ struct at_client
rt_thread_t
parser
;
};
typedef
struct
at_client
*
at_client_t
;
#endif
/* AT_USING_CLIENT */
...
...
@@ -216,20 +215,33 @@ int at_req_parse_args(const char *req_args, const char *req_expr, ...);
#endif
/* AT_USING_SERVER */
#ifdef AT_USING_CLIENT
/* AT client initialize and start */
int
at_client_init
(
void
);
/* AT client initialize and start*/
int
at_client_init
(
const
char
*
dev_name
,
rt_size_t
recv_bufsz
);
/* ========================== multiple AT client function ============================ */
/* get AT client object */
at_client_t
at_client_get
(
const
char
*
dev_name
);
at_client_t
at_client_get_first
(
void
);
/* AT client wait for connection to external devices. */
int
at_client_
wait_connect
(
rt_uint32_t
timeout
);
int
at_client_
obj_wait_connect
(
at_client_t
client
,
rt_uint32_t
timeout
);
/* AT client send commands to AT server and waiter response */
int
at_exec_cmd
(
at_response_t
resp
,
const
char
*
cmd_expr
,
...);
/* AT client send or receive data */
rt_size_t
at_client_obj_send
(
at_client_t
client
,
const
char
*
buf
,
rt_size_t
size
);
rt_size_t
at_client_obj_recv
(
at_client_t
client
,
char
*
buf
,
rt_size_t
size
);
/* AT Client send or receive data */
rt_size_t
at_client_send
(
const
char
*
buf
,
rt_size_t
size
);
rt_size_t
at_client_recv
(
char
*
buf
,
rt_size_t
size
);
/* set AT client a line end sign */
void
at_obj_set_end_sign
(
at_client_t
client
,
char
ch
);
/* AT response structure create and delete */
/* Set URC(Unsolicited Result Code) table */
void
at_obj_set_urc_table
(
at_client_t
client
,
const
struct
at_urc
*
table
,
rt_size_t
size
);
/* AT client send commands to AT server and waiter response */
int
at_obj_exec_cmd
(
at_client_t
client
,
at_response_t
resp
,
const
char
*
cmd_expr
,
...);
/* AT response object create and delete */
at_response_t
at_create_resp
(
rt_size_t
buf_size
,
rt_size_t
line_num
,
rt_int32_t
timeout
);
void
at_delete_resp
(
at_response_t
resp
);
at_response_t
at_resp_set_info
(
at_response_t
resp
,
rt_size_t
buf_size
,
rt_size_t
line_num
,
rt_int32_t
timeout
);
...
...
@@ -240,8 +252,20 @@ const char *at_resp_get_line_by_kw(at_response_t resp, const char *keyword);
int
at_resp_parse_line_args
(
at_response_t
resp
,
rt_size_t
resp_line
,
const
char
*
resp_expr
,
...);
int
at_resp_parse_line_args_by_kw
(
at_response_t
resp
,
const
char
*
keyword
,
const
char
*
resp_expr
,
...);
/* Set URC(Unsolicited Result Code) table */
void
at_set_urc_table
(
const
struct
at_urc
*
table
,
rt_size_t
size
);
/* ========================== single AT client function ============================ */
/**
* NOTE: These functions can be used directly when there is only one AT client.
* If there are multiple AT Client in the program, these functions can operate on the first initialized AT client.
*/
#define at_exec_cmd(resp, ...) at_obj_exec_cmd(at_client_get_first(), resp, __VA_ARGS__)
#define at_client_wait_connect(timeout) at_client_obj_wait_connect(at_client_get_first(), timeout)
#define at_client_send(buf, size) at_client_obj_send(at_client_get_first(), buf, size)
#define at_client_recv(buf, size) at_client_obj_recv(at_client_get_first(), buf, size)
#define at_set_end_sign(ch) at_obj_set_end_sign(at_client_get_first(), ch)
#define at_set_urc_table(urc_table, table_sz) at_obj_set_urc_table(at_client_get_first(), urc_table, table_sz)
#endif
/* AT_USING_CLIENT */
/* ========================== User port function ============================ */
...
...
components/net/at/src/at_cli.c
浏览文件 @
ed7f0cad
...
...
@@ -76,7 +76,7 @@ void at_cli_init(void)
rt_base_t
int_lvl
;
rt_device_t
console
;
rt_sem_init
(
&
console_rx_notice
,
"
at_cli_notice
"
,
0
,
RT_IPC_FLAG_FIFO
);
rt_sem_init
(
&
console_rx_notice
,
"
cli_c
"
,
0
,
RT_IPC_FLAG_FIFO
);
/* create RX FIFO */
console_rx_fifo
=
rt_ringbuffer_create
(
AT_CLI_FIFO_SIZE
);
...
...
@@ -209,14 +209,12 @@ static rt_err_t client_getchar_rx_ind(rt_device_t dev, rt_size_t size)
return
RT_EOK
;
}
static
void
client_cli_parser
(
void
)
static
void
client_cli_parser
(
at_client_t
client
)
{
#define ESC_KEY 0x1B
#define BACKSPACE_KEY 0x08
#define DELECT_KEY 0x7F
extern
at_client_t
rt_at_get_client
(
void
);
at_client_t
client
=
rt_at_get_client
();
char
ch
;
char
cur_line
[
FINSH_CMD_SIZE
]
=
{
0
};
rt_size_t
cur_line_len
=
0
;
...
...
@@ -234,10 +232,10 @@ static void client_cli_parser(void)
rt_hw_interrupt_enable
(
int_lvl
);
}
rt_sem_init
(
&
client_rx_notice
,
"
at_cli_client_notice
"
,
0
,
RT_IPC_FLAG_FIFO
);
rt_sem_init
(
&
client_rx_notice
,
"
cli_r
"
,
0
,
RT_IPC_FLAG_FIFO
);
client_rx_fifo
=
rt_ringbuffer_create
(
AT_CLI_FIFO_SIZE
);
at_client
=
rt_thread_create
(
"at_cli
_client
"
,
at_client_entry
,
RT_NULL
,
512
,
8
,
8
);
at_client
=
rt_thread_create
(
"at_cli"
,
at_client_entry
,
RT_NULL
,
512
,
8
,
8
);
if
(
client_rx_fifo
&&
at_client
)
{
rt_kprintf
(
"======== Welcome to using RT-Thread AT command client cli ========
\n
"
);
...
...
@@ -261,7 +259,7 @@ static void client_cli_parser(void)
if
(
cur_line_len
)
{
rt_kprintf
(
"
\n
"
);
at_
exec_cmd
(
RT_NULL
,
"%.*s"
,
cur_line_len
,
cur_line
);
at_
obj_exec_cmd
(
client
,
RT_NULL
,
"%.*s"
,
cur_line_len
,
cur_line
);
}
cur_line_len
=
0
;
}
...
...
@@ -297,9 +295,10 @@ static void client_cli_parser(void)
static
void
at
(
int
argc
,
char
**
argv
)
{
if
(
argc
<
2
)
if
(
argc
!=
2
&&
argc
!=
3
)
{
rt_kprintf
(
"Please input '
at <server|client
>'
\n
"
);
rt_kprintf
(
"Please input '
<server|client [dev_name]
>'
\n
"
);
return
;
}
...
...
@@ -311,23 +310,40 @@ static void at(int argc, char **argv)
server_cli_parser
();
#else
rt_kprintf
(
"Not support AT server, please check your configure!
\n
"
);
#endif
#endif
/* AT_USING_SERVER */
}
else
if
(
!
strcmp
(
argv
[
1
],
"client"
))
{
#ifdef AT_USING_CLIENT
client_cli_parser
();
at_client_t
client
=
RT_NULL
;
if
(
argc
==
2
)
{
client_cli_parser
(
at_client_get_first
());
}
else
if
(
argc
==
3
)
{
client
=
at_client_get
(
argv
[
2
]);
if
(
client
==
RT_NULL
)
{
rt_kprintf
(
"input AT client device name(%s) error.
\n
"
,
argv
[
2
]);
}
else
{
client_cli_parser
(
client
);
}
}
#else
rt_kprintf
(
"Not support AT client, please check your configure!
\n
"
);
#endif
#endif
/* AT_USING_CLIENT */
}
else
{
rt_kprintf
(
"Please input '
at <server|client
>'
\n
"
);
rt_kprintf
(
"Please input '
<server|client [dev_name]
>'
\n
"
);
}
at_cli_deinit
();
}
MSH_CMD_EXPORT
(
at
,
RT
-
Thread
AT
component
cli
:
at
<
server
|
client
>
);
MSH_CMD_EXPORT
(
at
,
RT
-
Thread
AT
component
cli
:
at
<
server
|
client
[
dev_name
]
>
);
#endif
/* AT_USING_CLI */
components/net/at/src/at_client.c
浏览文件 @
ed7f0cad
此差异已折叠。
点击以展开。
components/net/at/src/at_server.c
浏览文件 @
ed7f0cad
...
...
@@ -485,7 +485,7 @@ int at_server_init(void)
memset
(
at_server_local
->
recv_buffer
,
0x00
,
AT_SERVER_RECV_BUFF_LEN
);
at_server_local
->
cur_recv_len
=
0
;
at_server_local
->
rx_notice
=
rt_sem_create
(
"at_s
erver_notice
"
,
0
,
RT_IPC_FLAG_FIFO
);
at_server_local
->
rx_notice
=
rt_sem_create
(
"at_s
vr
"
,
0
,
RT_IPC_FLAG_FIFO
);
if
(
!
at_server_local
->
rx_notice
)
{
LOG_E
(
"AT server session initialize failed! at_rx_notice semaphore create failed!"
);
...
...
@@ -521,7 +521,7 @@ int at_server_init(void)
memcpy
(
at_server_local
->
end_mark
,
AT_CMD_END_MARK
,
sizeof
(
AT_CMD_END_MARK
));
at_server_local
->
parser_entry
=
server_parser
;
at_server_local
->
parser
=
rt_thread_create
(
"at_s
erve
r"
,
at_server_local
->
parser
=
rt_thread_create
(
"at_s
v
r"
,
(
void
(
*
)(
void
*
parameter
))
server_parser
,
at_server_local
,
2
*
1024
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录