27 {

28 LOG_E(“AT client send commands failed, response error or timeout !”);

29 return -1;

30 }

31

32 /* 命令发送成功 */

33 rt_kprintf(“AT Client send commands to AT Server success!

”);

34 if(at_resp_get_line_by_kw(resp,“UART”)!= NULL)

35 {

36 /* 解析获取串口配置信息AT+UART?,1 表示解析响应数据第一行 */

37 at_resp_parse_line_args(resp, 1,“+UART:%s”, uartdata);

38 rt_kprintf(“+UART:%s

”,uartdata);

39 }

40 /* 删除响应结构体 */

41 at_delete_resp(resp);

42

43 return RT_EOK;

44}

45/* 输出 at_Client_send 函数到 msh 中 */

46MSH_CMD_EXPORT(user_at_client_send, AT Client send commands to AT Server and get response data);

3.2.4 AT Client URC数据处理

URC 数据的处理是 AT Client 另一个重要功能,URC 数据为服务器主动下发的数据,不能通过上述数据发送接收函数接收,并且对于不同设备 URC 数据格式和功能不一样,所以 URC 数据处理的方式也是需要用户自定义实现的。

每种 URC 数据都有一个结构体控制块,用于定义判断 URC 数据的前缀和后缀,以及 URC 数据的执行函数。一段数据只有完全匹配 URC 的前缀和后缀才能定义为 URC 数据,获取到匹配的 URC 数据后会立刻执行 URC 数据执行函数。所以开发者添加一个 URC 数据需要自定义匹配的前缀、后缀和执行函数。

URC 数据列表初始化:

1void at_set_urc_table(const struct at_urc *table, rt_size_t size);

AT Client 移植具体示例:

1static void urc_conn_func(const char *data, rt_size_t size)

2{

3 /* WIFI 连接成功信息 */

4 LOG_D(“AT Server device WIFI connect success!”);

5}

6

7static void urc_recv_func(const char *data, rt_size_t size)

8{

9 /* 接收到服务器发送数据 */

10 LOG_D(“AT Client receive AT Server data!”);

11}

12

13static void urc_func(const char *data, rt_size_t size)

14{

15 /* 设备启动信息 */

16 LOG_D(“AT Server device startup!”);

17}

18

19static struct at_urc urc_table[] = {

20 {“WIFI CONNECTED”, “

”, urc_conn_func},

21 {“+RECV”, “:”, urc_recv_func},

22 {“RDY”, “

”, urc_func},

23};

24

25int at_client_port_init(void)

26{

27 /* 添加多种 URC 数据至 URC 列表中,当接收到同时匹配 URC 前缀和后缀的数据,执行 URC 函数 */

28 at_set_urc_table(urc_table, sizeof(urc_table) / sizeof(urc_table[0]));

29 return RT_EOK;