Link Kit C-SDK  4.0.0
aiot_at_api.h
浏览该文件的文档.
1 
10 #ifndef _AIOT_AT_API_H_
11 #define _AIOT_AT_API_H_
12 
13 #if defined(__cplusplus)
14 extern "C" {
15 #endif
16 
17 #include <stdint.h>
18 #include "core_list.h"
19 #include "aiot_sysdep_api.h"
20 
21 
22 #define MODULE_NAME_AT "AT"
23 
27 #define STATE_AT_BASE (-0x1000)
28 #define STATE_AT_ALREADY_INITED (-0x1003)
29 #define STATE_AT_NOT_INITED (-0x1004)
30 #define STATE_AT_UART_TX_FUNC_MISSING (-0x1005)
31 #define STATE_AT_GET_RSP_FAILED (-0x1006)
32 #define STATE_AT_RINGBUF_OVERFLOW (-0x1007)
33 #define STATE_AT_RX_TIMEOUT (-0x1008)
34 #define STATE_AT_NO_AVAILABLE_LINK (-0x1009)
35 #define STATE_AT_TX_TIMEOUT (-0x100A)
36 #define STATE_AT_TX_ERROR (-0x100B)
37 #define STATE_AT_RINGBUF_NO_DATA (-0x100C)
38 #define STATE_AT_UART_TX_FUNC_NULL (-0x100D)
39 #define STATE_AT_NO_DATA_SLOT (-0x100F)
40 #define STATE_AT_LINK_IS_DISCONN (-0x1010)
41 #define STATE_AT_UART_TX_FAILED (-0x1011)
42 
46 #define AIOT_AT_CMD_LEN_MAXIMUM (128) /* AT命令最大长度 */
47 #define AIOT_AT_RSP_LEN_MAXIMUM (64) /* AT应答最大长度 */
48 #define AIOT_AT_TX_TIMEOUT_DEFAULT (5000) /* UART默认发送超时时间 */
49 #define AIOT_AT_RX_TIMEOUT_DEFAULT (5000) /* UART默认接受等待超时时间 */
50 #define AIOT_AT_DATA_RB_SIZE_DEFAULT (5000) /* 内部网络数据接收缓冲区大小 */
51 #define AIOT_AT_RSP_RB_SIZE_DEFAULT (5000) /* 内部应答报文接受缓冲区大小 */
52 #define AIOT_AT_CMD_RETRY_TIME (3) /* AT命令发送重试最大次数 */
53 #define AIOT_AT_RINGBUF_RETRY_INTERVAL (100) /* RINGBUF数据长度检查间隔时间 */
54 #define AIOT_AT_SOCKET_NUM (1) /* 支持的数据链路数量 */
55 
56 
57 #define AIOT_UART_DISABLE_RX_IT() do {;} while(0)
58 #define AIOT_UART_ENABLE_RX_IT() do {;} while(0)
59 
64 typedef enum {
69 
82 typedef int32_t (*aiot_at_uart_tx_func_t)(const uint8_t *p_data, uint16_t len, uint32_t timeout);
83 
94 typedef int32_t (*at_rsp_handler_t)(char *rsp, void *user_data);
95 
99 typedef struct {
100  /* 要发送的AT命令 */
101  char *cmd;
102  /* AT命令的数据长度 */
103  uint32_t cmd_len;
104  /* 期望的应答数据 */
105  char *rsp;
106  /* 接受到应答数据后的用户处理回调函数 */
107  at_rsp_handler_t handler;
109 
113 typedef struct {
114  uint8_t *buf;
115  uint8_t *head;
116  uint8_t *tail;
117  uint8_t *end;
118  uint32_t size;
119  void *mutex;
121 
125 typedef enum {
131 
135 typedef struct {
136  uint8_t link_status;
137  core_ringbuf_t data_rb;
139 
140 typedef enum {
145 
146 typedef struct {
147  uint32_t curr_link_id;
148  uint32_t data_len;
149  core_at_parser_state_t state;
151 
155 typedef struct {
156  uint8_t is_init;
158  uint32_t tx_timeout;
159  uint32_t rsp_timeout;
160 
162  core_ringbuf_t rsp_rb;
163  char rsp_buf[AIOT_AT_RSP_LEN_MAXIMUM];
164  uint32_t rsp_buf_offset;
165 
166  aiot_at_uart_tx_func_t uart_tx_func;
167  void *tx_mutex;
168 
169  void *user_data;
171 
179 int32_t aiot_at_init(void);
180 
191 int32_t aiot_at_setopt(aiot_at_option_t opt, void *data);
192 
200 int32_t aiot_at_bootstrap(void);
201 
211 int32_t aiot_at_nwk_open(uint8_t *socket_id);
212 
225 int32_t aiot_at_nwk_connect(uint8_t socket_id, const char *host, uint16_t port, uint32_t timeout);
226 
239 int32_t aiot_at_nwk_send(uint8_t socket_id, const uint8_t *buffer, uint32_t len, uint32_t timeout);
240 
253 int32_t aiot_at_nwk_recv(uint8_t socket_id, uint8_t *buffer, uint32_t len, uint32_t timeout_ms);
254 
264 int32_t aiot_at_nwk_close(uint8_t socket_id);
265 
274 int32_t aiot_at_uart_reception(uint8_t data);
275 
281 int32_t aiot_at_deinit(void);
282 
283 
284 #if defined(__cplusplus)
285 }
286 #endif
287 
288 #endif
289 
int32_t aiot_at_bootstrap(void)
模组启动, 内部发送模组相关的AT命令已启动模组, 启动完成后, 模组将获取到IP地址
Definition: aiot_at_api.c:408
ringbuf结构体定义
Definition: aiot_at_api.h:189
#define AIOT_AT_SOCKET_NUM
Definition: aiot_at_api.h:54
int32_t aiot_at_nwk_recv(uint8_t socket_id, uint8_t *buffer, uint32_t len, uint32_t timeout_ms)
内部会从对应的数据ringbu中读取网络数据, 可对接到core_sysdep_network_recv网络接口
Definition: aiot_at_api.c:580
Definition: aiot_at_api.h:63
Definition: aiot_at_api.h:65
int32_t aiot_at_init(void)
初始化AT组件
Definition: aiot_at_api.c:308
aiot_at_option_t
AT组件配置选项
Definition: aiot_at_api.h:61
Definition: aiot_at_api.h:62
SDK Core系统依赖头文件, 所有Core中的系统依赖均在此文件中列出
Definition: aiot_at_api.h:133
int32_t aiot_at_deinit(void)
反初始化AT组件
Definition: aiot_at_api.c:792
AT命令请求响应结构体定义
Definition: aiot_at_api.h:110
int32_t aiot_at_setopt(aiot_at_option_t opt, void *data)
配置AT组件, 主要为配置串口发送回调函数
Definition: aiot_at_api.c:376
Definition: aiot_at_api.h:202
AT组件上下文数据结构体
Definition: aiot_at_api.h:235
Definition: aiot_at_api.h:147
Definition: aiot_at_api.h:145
Definition: aiot_at_api.h:146
Definition: aiot_at_api.h:204
int32_t aiot_at_nwk_close(uint8_t socket_id)
内部会调用模组相关的AT命令, 关闭连接链路。可对接到core_sysdep_network_deinit网络接口 ...
Definition: aiot_at_api.c:619
Definition: aiot_at_api.h:150
int32_t aiot_at_nwk_open(uint8_t *socket_id)
为对应的链路ID创建ringbuf资源
Definition: aiot_at_api.c:428
int32_t aiot_at_nwk_send(uint8_t socket_id, const uint8_t *buffer, uint32_t len, uint32_t timeout)
内部会调用模组相关的AT命令, 通过串口发送TCP数据。可对接到core_sysdep_network_send网络接口 ...
Definition: aiot_at_api.c:554
int32_t aiot_at_uart_reception(uint8_t data)
为AT组件提供串口数据
Definition: aiot_at_api.c:605
core_at_link_status_t
模组数据链路状态
Definition: aiot_at_api.h:201
int32_t aiot_at_nwk_connect(uint8_t socket_id, const char *host, uint16_t port, uint32_t timeout)
内部会调用模组相关的AT命令, 通过串口发送TCP建连命令。可对接到core_sysdep_network_establish网络接口 ...
Definition: aiot_at_api.c:484
int32_t(* aiot_at_uart_tx_func_t)(const uint8_t *p_data, uint16_t len, uint32_t timeout)
串口发送回调函数定义
Definition: aiot_at_api.h:80
Definition: aiot_at_api.h:203
core_at_parser_state_t
Definition: aiot_at_api.h:144
#define AIOT_AT_RSP_LEN_MAXIMUM
Definition: aiot_at_api.h:47
at_rsp_result_t(* at_rsp_handler_t)(char *rsp)
接受到应答数据后的用户处理回调函数原型定义
Definition: aiot_at_api.h:96