Link Kit C-SDK  4.0.0
aiot_coap_api.h
浏览该文件的文档.
1 
23 #ifndef __AIOT_COAP_API_H__
24 #define __AIOT_COAP_API_H__
25 
26 #if defined(__cplusplus)
27 extern "C" {
28 #endif
29 
30 #include <stdint.h>
31 
35 #define STATE_COAP_BASE (-0x0800)
36 
41 #define STATE_COAP_LOG_HEXDUMP (-0x0801)
42 
47 #define STATE_COAP_HEADER_TYPE_ERROR (-0x0802)
48 
53 #define STATE_COAP_HEADER_CODE_ERROR (-0x0802)
54 
59 #define STATE_COAP_MSG_LEN_ERROR (-0x0803)
60 
65 #define STATE_COAP_MSG_TOKEN_LEN_TOO_SHORT (-0x0804)
66 
71 #define STATE_COAP_RX_OPTION_CNT_EXCEED_LIMIT (-0x0805)
72 
77 #define STATE_COAP_OPT_DELTA_THIRTEEN_OPT_LEN_ERROR (-0x0806)
78 
83 #define STATE_COAP_OPTION_END_NOT_FOUND (-0x0807)
84 
89 #define STATE_COAP_TX_URI_OPTION_CNT_EXCEED_LIMIT (-0x0808)
90 
95 #define STATE_COAP_MALLOC_MSG_FAILED (-0x0809)
96 
101 #define STATE_COAP_MALLOC_MSG_BUFFER_FAILED (-0x080A)
102 
107 #define STATE_COAP_REQUEST_IS_NULL (-0x080B)
108 
113 #define STATE_COAP_OPT_DELTA_FOURTEEN_OPT_LEN_ERROR (-0x080C)
114 
119 #define STATE_COAP_EMPTY_MSG_PARAM_ERROR (-0x080D)
120 
125 #define STATE_COAP_EMPTY_MSG_MALLOC_FAILED (-0x080E)
126 
131 #define STATE_COAP_OPTION_NOT_IN_ORDER (-0x080F)
132 
137 #define STATE_COAP_HEADER_FORMAT_ERROR (-0x0810)
138 
143 #define STATE_COAP_OPTION_BUFFER_TOO_SHORT (-0x081A)
144 
149 #define STATE_COAP_SEND_MESSAGE_IS_NULL (-0x081B)
150 
155 #define STATE_COAP_HEADER_BUFFER_IS_TOO_SHORT (-0x081C)
156 
161 #define STATE_COAP_OPT_LEN_THIRTEEN_OPT_LEN_ERROR (-0x081D)
162 
167 #define STATE_COAP_CREATE_PSK_FAILED (-0x081E)
168 
175 #define STATE_COAP_SET_NWK_PARMS_FAILED (-0x081F)
176 
181 #define STATE_COAP_SEND_HANDLE_IS_NULL (-0x0820)
182 
187 #define STATE_COAP_SEND_TOPIC_IS_NULL (-0x0821)
188 
193 #define STATE_COAP_SEND_REQUEST_IS_NULL (-0x0822)
194 
199 #define STATE_COAP_SEND_PAYLOAD_IS_NULL (-0x0823)
200 
205 #define STATE_COAP_SET_PSK_FAILED (-0x0824)
206 
211 #define STATE_COAP_NWK_ESTABLISH_FAILED (-0x0825)
212 
217 #define STATE_COAP_RECV_HANDLE_IS_NULL (-0x0826)
218 
223 #define STATE_COAP_AUTH_HANDLE_IS_NULL (-0x0827)
224 
229 #define STATE_COAP_AUTH_DEVICE_INFO_MISSING (-0x0828)
230 
235 #define STATE_COAP_SIGN_SRC_MALLOC_FAILED (-0x0829)
236 
241 #define STATE_COAP_TX_TOTAL_OPTION_CNT_EXCEED_LIMIT (-0x082A)
242 
247 #define STATE_COAP_RECV_WITHOUT_AUTHORIZATION (-0x082B)
248 
253 #define STATE_COAP_AUTH_TIMEOUT (-0x082C)
254 
259 #define STATE_COAP_AUTH_RSP_TOKEN_IS_NULL (-0x082D)
260 
265 #define STATE_COAP_AUTH_DEBUG (-0x082E)
266 
271 #define STATE_COAP_AUTH_TOKEN_MALLOC_FAILED (-0x082F)
272 
280 #define STATE_COAP_SEND_INVALID_MSG_TYPE (-0x0830)
281 
286 #define STATE_COAP_NWK_HANDLE_IS_NULL (-0x0831)
287 
292 #define AIOT_COAP_OPT_PARAMS_INVALID (-0x0832)
293 
298 #define STATE_COAP_INVALID_OPTION (-0x0833)
299 
304 #define STATE_COAP_UNSUPPORTED_CONTENT_FORMAT (-0x0834)
305 
310 #define STATE_COAP_SEND_WITHOUT_AUTHORIZATION (-0x0835)
311 
316 #define STATE_COAP_OPT_LEN_FOURTEEN_OPT_LEN_ERROR (-0x0836)
317 
322 #define STATE_COAP_PAYLOAD_BUFFER_IS_TOO_SHORT (-0x0837)
323 
328 #define STATE_COAP_OPTION_LEN_ERROR (-0x0838)
329 
334 #define STATE_COAP_LOG_AUTH_TOKEN (-0x0839)
335 
340 #define STATE_COAP_LOG_CONTENT (-0x083A)
341 
342 
350 typedef enum {
353 
354 typedef struct {
355 
360  aiot_coap_recv_type_t type;
361 
365  struct {
366  uint8_t *payload;
367  uint32_t payload_len;
368  uint8_t rsp_code;
369  uint32_t msg_token;
370  } data;
372 
382 typedef void (*aiot_coap_recv_handler_t)(void *handle,
383  aiot_coap_recv_t *packet,
384  void *userdata);
385 
389 typedef enum {
390 
395 
401 
402 typedef struct {
403 
407  aiot_coap_event_type_t type;
409 
418 typedef void (*aiot_coap_event_handler_t)(void *handle,
419  aiot_coap_event_t *event,
420  void *userdata);
421 
422 
441 typedef enum {
442 
458 
471 
480 
489 
498 
512 
520 
529 
539 
552 
561 
574 
588 typedef enum {
598 
614 typedef enum {
615 
621 
627 
642 
649 typedef struct {
650 
655  uint8_t *payload;
656 
665 
671 
676  uint32_t *msg_token;
678 
679 
688 void *aiot_coap_init(void);
689 
724 int32_t aiot_coap_setopt(void *handle, aiot_coap_option_t option, void *data);
725 
743 int32_t aiot_coap_send(void *handle, const char *topic, aiot_coap_request_t *message);
744 
756 int32_t aiot_coap_recv(void *handle);
757 
767 int32_t aiot_coap_deinit(void **handle);
768 
783 int32_t aiot_coap_auth(void *handle);
784 
785 #if defined(__cplusplus)
786 }
787 #endif
788 
789 #endif /* __AIOT_COAP_API_H__ */
790 
aiot_coap_msg_type_t msg_type
aiot_coap_msg_type_t 中所定义的消息类型
Definition: aiot_coap_api.h:664
Definition: aiot_coap_api.h:354
aiot_coap_msg_type_t
aiot_coap_send 函数的aiot_coap_request_t参数中的msg_type字段.
Definition: aiot_coap_api.h:614
uint8_t * payload
用户要上传的数据, 其格式要和字段content_format一致.
Definition: aiot_coap_api.h:655
uint32_t * msg_token
用户传入一个指针. 在coap模块发送该请求的时候, 会对该请求生成一个独一无二的token 该指针用以存这个token...
Definition: aiot_coap_api.h:676
Definition: aiot_coap_api.h:640
void(* aiot_coap_event_handler_t)(void *handle, aiot_coap_event_t *event, void *userdata)
COAP事件回调函数
Definition: aiot_coap_api.h:418
当COAP实例所用的auth token过期(当前有效期为7天)时, 触发此事件
Definition: aiot_coap_api.h:399
Definition: aiot_coap_api.h:572
设备的device secret, 可从阿里云物联网平台控制台获取
Definition: aiot_coap_api.h:497
Definition: aiot_coap_api.h:594
aiot_coap_event_type_t
COAP内部事件类型
Definition: aiot_coap_api.h:389
confirmable消息类型
Definition: aiot_coap_api.h:620
COAP连云时, 获取auth_token的超时时间
Definition: aiot_coap_api.h:519
Definition: aiot_coap_api.h:351
not confirmable消息类型
Definition: aiot_coap_api.h:626
Definition: aiot_coap_api.h:591
int32_t aiot_coap_deinit(void **handle)
释放COAP实例句柄的资源
Definition: aiot_coap_api.c:1046
int32_t aiot_coap_send(void *handle, const char *topic, aiot_coap_request_t *message)
发送COAP报文
Definition: aiot_coap_api.c:941
aiot_coap_send 函数的aiot_coap_request_t参数
Definition: aiot_coap_api.h:649
Definition: aiot_coap_api.h:592
reset消息类型
Definition: aiot_coap_api.h:638
uint8_t * payload
Definition: aiot_coap_api.h:366
Definition: aiot_coap_api.h:595
ack消息类型
Definition: aiot_coap_api.h:632
aiot_coap_recv_type_t type
COAP报文类型, 更多信息请参考aiot_coap_recv_type_t.
Definition: aiot_coap_api.h:360
int32_t aiot_coap_setopt(void *handle, aiot_coap_option_t option, void *data)
设置coap参数
Definition: aiot_coap_api.c:727
aiot_coap_event_type_t type
COAP事件类型, 更多信息请参考aiot_coap_event_type_t.
Definition: aiot_coap_api.h:407
aiot_coap_recv_type_t
COAP报文类型
Definition: aiot_coap_api.h:350
设备的product key, 可从阿里云物联网平台控制台获取
Definition: aiot_coap_api.h:479
COAP建联时, 网络使用的安全凭据
Definition: aiot_coap_api.h:511
COAP接收数据时, 在协议栈花费的最长时间
Definition: aiot_coap_api.h:528
int32_t aiot_coap_auth(void *handle)
让coap模块与服务器通信, 并且获取auth token
Definition: aiot_coap_api.c:808
void * aiot_coap_init(void)
初始化coap实例并设置默认参数
Definition: aiot_coap_api.c:689
uint32_t msg_token
Definition: aiot_coap_api.h:369
COAP客户端内部发生的事件会从此回调函数进行通知, 如获取到token等
Definition: aiot_coap_api.h:560
从COAP服务器收取的数据从此回调函数通知用户
Definition: aiot_coap_api.h:551
aiot_coap_option_t
aiot_coap_setopt 函数的option参数. 对于下文每一个选项中的数据类型, 指的是aiot_coap_setopt 中的data参...
Definition: aiot_coap_api.h:441
Definition: aiot_coap_api.h:593
Definition: aiot_coap_api.h:596
当COAP实例从云端获取到连云需要的auth_token时, 触发此事件
Definition: aiot_coap_api.h:394
Definition: aiot_coap_api.h:590
COAP发送数据时, 在协议栈花费的最长时间
Definition: aiot_coap_api.h:538
Definition: aiot_coap_api.h:589
int32_t aiot_coap_recv(void *handle)
从网络收取COAP报文
Definition: aiot_coap_api.c:1032
uint8_t rsp_code
Definition: aiot_coap_api.h:368
aiot_coap_content_format_t content_format
aiot_coap_content_format_t 中所定义的payload的格式
Definition: aiot_coap_api.h:670
COAP 服务器的端口号
Definition: aiot_coap_api.h:470
COAP 服务器的域名地址或者ip地址
Definition: aiot_coap_api.h:457
void(* aiot_coap_recv_handler_t)(void *handle, aiot_coap_recv_t *packet, void *userdata)
COAP报文接收回调函数原型
Definition: aiot_coap_api.h:382
aiot_coap_content_format_t
aiot_coap_send 函数的aiot_coap_request_t参数中的content_format字段.
Definition: aiot_coap_api.h:588
设备的device name, 可从阿里云物联网平台控制台获取
Definition: aiot_coap_api.h:488
用户需要SDK暂存的上下文
Definition: aiot_coap_api.h:571
uint32_t payload_len
Definition: aiot_coap_api.h:367
Definition: aiot_coap_api.h:402