2020 * Change Logs:
2121 * Date Author Notes
2222 * 2018-03-30 chenyong first version
23+ * 2018-08-17 chenyong multiple client support
2324 */
2425
2526#ifndef __AT_H__
3031#ifdef __cplusplus
3132extern "C" {
3233#endif
33- #define AT_SW_VERSION "0.3.0"
34+ #define AT_SW_VERSION "1.0.0"
35+ #define AT_SW_VERSION_NUM 0x10000
3436
3537#define DBG_ENABLE
3638#define DBG_SECTION_NAME "AT"
@@ -67,16 +69,13 @@ extern "C" {
6769#define AT_SERVER_RECV_BUFF_LEN 256
6870#endif
6971
70- #ifndef AT_CLIENT_RECV_BUFF_LEN
71- #define AT_CLIENT_RECV_BUFF_LEN 512
72- #endif
73-
7472#ifndef AT_SERVER_DEVICE
7573#define AT_SERVER_DEVICE "uart2"
7674#endif
7775
78- #ifndef AT_CLIENT_DEVICE
79- #define AT_CLIENT_DEVICE "uart2"
76+ /* the maximum number of supported AT clients */
77+ #ifndef AT_CLIENT_NUM_MAX
78+ #define AT_CLIENT_NUM_MAX 1
8079#endif
8180
8281#define AT_CMD_EXPORT (_name_ , _args_expr_ , _test_ , _query_ , _setup_ , _exec_ ) \
@@ -137,7 +136,6 @@ struct at_server
137136 rt_thread_t parser ;
138137 void (* parser_entry )(struct at_server * server );
139138};
140-
141139typedef struct at_server * at_server_t ;
142140#endif /* AT_USING_SERVER */
143141
@@ -183,8 +181,10 @@ struct at_client
183181 rt_device_t device ;
184182
185183 at_status_t status ;
184+ char end_sign ;
186185
187- char recv_buffer [AT_CLIENT_RECV_BUFF_LEN ];
186+ char * recv_buffer ;
187+ rt_size_t recv_bufsz ;
188188 rt_size_t cur_recv_len ;
189189 rt_sem_t rx_notice ;
190190 rt_mutex_t lock ;
@@ -198,7 +198,6 @@ struct at_client
198198
199199 rt_thread_t parser ;
200200};
201-
202201typedef struct at_client * at_client_t ;
203202#endif /* AT_USING_CLIENT */
204203
@@ -216,20 +215,33 @@ int at_req_parse_args(const char *req_args, const char *req_expr, ...);
216215#endif /* AT_USING_SERVER */
217216
218217#ifdef AT_USING_CLIENT
219- /* AT client initialize and start */
220- int at_client_init (void );
218+
219+ /* AT client initialize and start*/
220+ int at_client_init (const char * dev_name , rt_size_t recv_bufsz );
221+
222+ /* ========================== multiple AT client function ============================ */
223+
224+ /* get AT client object */
225+ at_client_t at_client_get (const char * dev_name );
226+ at_client_t at_client_get_first (void );
221227
222228/* AT client wait for connection to external devices. */
223- int at_client_wait_connect ( rt_uint32_t timeout );
229+ int at_client_obj_wait_connect ( at_client_t client , rt_uint32_t timeout );
224230
225- /* AT client send commands to AT server and waiter response */
226- int at_exec_cmd (at_response_t resp , const char * cmd_expr , ...);
231+ /* AT client send or receive data */
232+ rt_size_t at_client_obj_send (at_client_t client , const char * buf , rt_size_t size );
233+ rt_size_t at_client_obj_recv (at_client_t client , char * buf , rt_size_t size );
227234
228- /* AT Client send or receive data */
229- rt_size_t at_client_send (const char * buf , rt_size_t size );
230- rt_size_t at_client_recv (char * buf , rt_size_t size );
235+ /* set AT client a line end sign */
236+ void at_obj_set_end_sign (at_client_t client , char ch );
231237
232- /* AT response structure create and delete */
238+ /* Set URC(Unsolicited Result Code) table */
239+ void at_obj_set_urc_table (at_client_t client , const struct at_urc * table , rt_size_t size );
240+
241+ /* AT client send commands to AT server and waiter response */
242+ int at_obj_exec_cmd (at_client_t client , at_response_t resp , const char * cmd_expr , ...);
243+
244+ /* AT response object create and delete */
233245at_response_t at_create_resp (rt_size_t buf_size , rt_size_t line_num , rt_int32_t timeout );
234246void at_delete_resp (at_response_t resp );
235247at_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);
240252int at_resp_parse_line_args (at_response_t resp , rt_size_t resp_line , const char * resp_expr , ...);
241253int at_resp_parse_line_args_by_kw (at_response_t resp , const char * keyword , const char * resp_expr , ...);
242254
243- /* Set URC(Unsolicited Result Code) table */
244- void at_set_urc_table (const struct at_urc * table , rt_size_t size );
255+ /* ========================== single AT client function ============================ */
256+
257+ /**
258+ * NOTE: These functions can be used directly when there is only one AT client.
259+ * If there are multiple AT Client in the program, these functions can operate on the first initialized AT client.
260+ */
261+
262+ #define at_exec_cmd (resp , ...) at_obj_exec_cmd(at_client_get_first(), resp, __VA_ARGS__)
263+ #define at_client_wait_connect (timeout ) at_client_obj_wait_connect(at_client_get_first(), timeout)
264+ #define at_client_send (buf , size ) at_client_obj_send(at_client_get_first(), buf, size)
265+ #define at_client_recv (buf , size ) at_client_obj_recv(at_client_get_first(), buf, size)
266+ #define at_set_end_sign (ch ) at_obj_set_end_sign(at_client_get_first(), ch)
267+ #define at_set_urc_table (urc_table , table_sz ) at_obj_set_urc_table(at_client_get_first(), urc_table, table_sz)
268+
245269#endif /* AT_USING_CLIENT */
246270
247271/* ========================== User port function ============================ */
0 commit comments