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 (1200) /* 内部网络数据接收缓冲区大小 */
51 #define AIOT_AT_RSP_RB_SIZE_DEFAULT (50) /* 内部应答报文接受缓冲区大小 */
52 #define AIOT_AT_CMD_RETRY_TIME (3) /* AT命令发送重试最大次数 */
53 #define AIOT_AT_RINGBUF_RETRY_INTERVAL (100) /* RINGBUF数据长度检查间隔时间 */
54 #define AIOT_AT_SOCKET_NUM (5) /* 支持的数据链路数量 */
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;
108  /* has deleyed response */
109  char *delay_rsp;
110  /* has expected len*/
111  uint32_t expected_len;
113 
117 typedef struct {
118  uint8_t *buf;
119  uint8_t *head;
120  uint8_t *tail;
121  uint8_t *end;
122  uint32_t size;
123  void *mutex;
125 
129 typedef enum {
135 
139 typedef struct {
140  uint8_t link_status;
141  core_ringbuf_t data_rb;
143 
144 typedef enum {
149 
150 typedef struct {
151  uint32_t curr_link_id;
152  uint32_t data_len;
153  core_at_parser_state_t state;
155 
159 typedef struct {
160  uint8_t is_init;
162  uint32_t tx_timeout;
163  uint32_t rsp_timeout;
164 
166  core_ringbuf_t rsp_rb;
167  char rsp_buf[AIOT_AT_RSP_LEN_MAXIMUM];
168  uint32_t rsp_buf_offset;
169 
170  aiot_at_uart_tx_func_t uart_tx_func;
171  void *tx_mutex;
172 
173  void *user_data;
175 
183 int32_t aiot_at_init(void);
184 
195 int32_t aiot_at_setopt(aiot_at_option_t opt, void *data);
196 
204 int32_t aiot_at_bootstrap(void);
205 
215 int32_t aiot_at_nwk_open(uint8_t *socket_id);
216 
229 int32_t aiot_at_nwk_connect(uint8_t socket_id, const char *host, uint16_t port, uint32_t timeout);
230 
243 int32_t aiot_at_nwk_send(uint8_t socket_id, const uint8_t *buffer, uint32_t len, uint32_t timeout);
244 
257 int32_t aiot_at_nwk_recv(uint8_t socket_id, uint8_t *buffer, uint32_t len, uint32_t timeout_ms);
258 
268 int32_t aiot_at_nwk_close(uint8_t socket_id);
269 
278 int32_t aiot_at_uart_reception(uint8_t data);
279 
285 int32_t aiot_at_deinit(void);
286 
287 
288 #if defined(__cplusplus)
289 }
290 #endif
291 
292 #endif
293 
int32_t aiot_at_bootstrap(void)
模组启动, 内部发送模组相关的AT命令已启动模组, 启动完成后, 模组将获取到IP地址
Definition: aiot_at_api.c:408
ringbuf结构体定义
Definition: aiot_at_api.h:189
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
core_at_parse_sm_t sm
Definition: aiot_at_api.h:165
aiot_at_option_t
AT组件配置选项
Definition: aiot_at_api.h:61
Definition: aiot_at_api.h:62
SDK Core系统依赖头文件, 所有Core中的系统依赖均在此文件中列出
uint32_t data_len
Definition: aiot_at_api.h:152
Definition: aiot_at_api.h:133
char * delay_rsp
Definition: aiot_at_api.h:109
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
core_at_parser_state_t state
Definition: aiot_at_api.h:153
void * tx_mutex
Definition: aiot_at_api.h:171
Definition: aiot_at_api.h:145
uint32_t rsp_timeout
Definition: aiot_at_api.h:163
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
#define AIOT_AT_RSP_LEN_MAXIMUM
Definition: aiot_at_api.h:47
#define AIOT_AT_SOCKET_NUM
Definition: aiot_at_api.h:54
uint32_t curr_link_id
Definition: aiot_at_api.h:151
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
uint32_t expected_len
Definition: aiot_at_api.h:111
at_rsp_result_t(* at_rsp_handler_t)(char *rsp)
接受到应答数据后的用户处理回调函数原型定义
Definition: aiot_at_api.h:96