Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-os-example-mbed5-blinky by
DuerOS-Light-SDK-v1.1.0/duer-os-light/src/iot-baidu-ca/source/baidu_ca_coap.h@47:9e361da97763, 2017-07-18 (annotated)
- Committer:
- TMBOY
- Date:
- Tue Jul 18 16:54:45 2017 +0800
- Revision:
- 47:9e361da97763
?
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| TMBOY | 47:9e361da97763 | 1 | // Copyright 2017 Baidu Inc. All Rights Reserved. |
| TMBOY | 47:9e361da97763 | 2 | // Author: Su Hao (suhao@baidu.com) |
| TMBOY | 47:9e361da97763 | 3 | // |
| TMBOY | 47:9e361da97763 | 4 | // Description: The CoAP adapter. |
| TMBOY | 47:9e361da97763 | 5 | |
| TMBOY | 47:9e361da97763 | 6 | #ifndef BAIDU_IOT_TINYDU_IOT_OS_SRC_IOT_BAIDU_CA_SOURCE_BAIDU_CA_COAP_H |
| TMBOY | 47:9e361da97763 | 7 | #define BAIDU_IOT_TINYDU_IOT_OS_SRC_IOT_BAIDU_CA_SOURCE_BAIDU_CA_COAP_H |
| TMBOY | 47:9e361da97763 | 8 | |
| TMBOY | 47:9e361da97763 | 9 | #include "baidu_ca_coap_ep.h" |
| TMBOY | 47:9e361da97763 | 10 | |
| TMBOY | 47:9e361da97763 | 11 | typedef void* bca_coap_handler; |
| TMBOY | 47:9e361da97763 | 12 | |
| TMBOY | 47:9e361da97763 | 13 | typedef bca_status_t (*bca_coap_result_f)(bca_context ctx, |
| TMBOY | 47:9e361da97763 | 14 | bca_coap_handler hdlr, |
| TMBOY | 47:9e361da97763 | 15 | const bca_msg_t* msg, |
| TMBOY | 47:9e361da97763 | 16 | const bca_addr_t* addr); |
| TMBOY | 47:9e361da97763 | 17 | |
| TMBOY | 47:9e361da97763 | 18 | #define BCA_COAP_MESSAGE_ID_INVALID (0) |
| TMBOY | 47:9e361da97763 | 19 | |
| TMBOY | 47:9e361da97763 | 20 | #ifdef __cplusplus |
| TMBOY | 47:9e361da97763 | 21 | extern "C" { |
| TMBOY | 47:9e361da97763 | 22 | #endif |
| TMBOY | 47:9e361da97763 | 23 | |
| TMBOY | 47:9e361da97763 | 24 | /* |
| TMBOY | 47:9e361da97763 | 25 | * Acquire the coap handler. |
| TMBOY | 47:9e361da97763 | 26 | * |
| TMBOY | 47:9e361da97763 | 27 | * @Param f_result, in, the callback for user handling events |
| TMBOY | 47:9e361da97763 | 28 | * @Param context, in, the user context for f_result callback |
| TMBOY | 47:9e361da97763 | 29 | * @Param ctx_context, in, the user socket context |
| TMBOY | 47:9e361da97763 | 30 | * @Return bca_coap_handler, the coap context |
| TMBOY | 47:9e361da97763 | 31 | */ |
| TMBOY | 47:9e361da97763 | 32 | BCA_INT bca_coap_handler bca_coap_acquire(bca_coap_result_f f_result, |
| TMBOY | 47:9e361da97763 | 33 | bca_context context, |
| TMBOY | 47:9e361da97763 | 34 | bca_context ctx_context); |
| TMBOY | 47:9e361da97763 | 35 | |
| TMBOY | 47:9e361da97763 | 36 | /* |
| TMBOY | 47:9e361da97763 | 37 | * Connect to remote CoAP server |
| TMBOY | 47:9e361da97763 | 38 | * |
| TMBOY | 47:9e361da97763 | 39 | * @Param hdlr, in, the CoAP context |
| TMBOY | 47:9e361da97763 | 40 | * @Param addr, in, the remote server address |
| TMBOY | 47:9e361da97763 | 41 | * @Param data, in, the security suite data |
| TMBOY | 47:9e361da97763 | 42 | * @Param size, in, the data size |
| TMBOY | 47:9e361da97763 | 43 | * @Return bca_status_t, the connect status |
| TMBOY | 47:9e361da97763 | 44 | */ |
| TMBOY | 47:9e361da97763 | 45 | BCA_INT bca_status_t bca_coap_connect(bca_coap_handler hdlr, |
| TMBOY | 47:9e361da97763 | 46 | const bca_addr_t* addr, |
| TMBOY | 47:9e361da97763 | 47 | const void* data, |
| TMBOY | 47:9e361da97763 | 48 | bca_size_t size); |
| TMBOY | 47:9e361da97763 | 49 | |
| TMBOY | 47:9e361da97763 | 50 | /* |
| TMBOY | 47:9e361da97763 | 51 | * Disconnect from remote CoAP server |
| TMBOY | 47:9e361da97763 | 52 | * |
| TMBOY | 47:9e361da97763 | 53 | * @Param hdlr, in, the CoAP context |
| TMBOY | 47:9e361da97763 | 54 | * @Return bca_status_t, the connect status |
| TMBOY | 47:9e361da97763 | 55 | */ |
| TMBOY | 47:9e361da97763 | 56 | BCA_INT bca_status_t bca_coap_disconnect(bca_coap_handler hdlr); |
| TMBOY | 47:9e361da97763 | 57 | |
| TMBOY | 47:9e361da97763 | 58 | /* |
| TMBOY | 47:9e361da97763 | 59 | * Add the resource for CoAP request from other endpoints |
| TMBOY | 47:9e361da97763 | 60 | * |
| TMBOY | 47:9e361da97763 | 61 | * @Param hdlr, in, the CoAP context |
| TMBOY | 47:9e361da97763 | 62 | * @Param res, in, the resource information |
| TMBOY | 47:9e361da97763 | 63 | * @Return bca_status_t, the result |
| TMBOY | 47:9e361da97763 | 64 | */ |
| TMBOY | 47:9e361da97763 | 65 | BCA_INT bca_status_t bca_coap_resource_add(bca_coap_handler hdlr, |
| TMBOY | 47:9e361da97763 | 66 | const bca_res_t* res); |
| TMBOY | 47:9e361da97763 | 67 | |
| TMBOY | 47:9e361da97763 | 68 | /* |
| TMBOY | 47:9e361da97763 | 69 | * Remove the resource for CoAP request from other endpoints |
| TMBOY | 47:9e361da97763 | 70 | * |
| TMBOY | 47:9e361da97763 | 71 | * @Param hdlr, in, the CoAP context |
| TMBOY | 47:9e361da97763 | 72 | * @Param path, in, the resource path |
| TMBOY | 47:9e361da97763 | 73 | * @Return bca_status_t, the result |
| TMBOY | 47:9e361da97763 | 74 | */ |
| TMBOY | 47:9e361da97763 | 75 | BCA_INT bca_status_t bca_coap_resource_remove(bca_coap_handler coap, |
| TMBOY | 47:9e361da97763 | 76 | const char* path); |
| TMBOY | 47:9e361da97763 | 77 | |
| TMBOY | 47:9e361da97763 | 78 | /* |
| TMBOY | 47:9e361da97763 | 79 | * Register endpoint by LWM2M |
| TMBOY | 47:9e361da97763 | 80 | * |
| TMBOY | 47:9e361da97763 | 81 | * @Param hdlr, in, the CoAP context |
| TMBOY | 47:9e361da97763 | 82 | * @Param ep, in, the endpoint information |
| TMBOY | 47:9e361da97763 | 83 | * @Return bca_status_t, if > 0, the result is the register message id, else is the error status |
| TMBOY | 47:9e361da97763 | 84 | */ |
| TMBOY | 47:9e361da97763 | 85 | BCA_INT bca_status_t bca_coap_register(bca_coap_handler coap, |
| TMBOY | 47:9e361da97763 | 86 | const bca_coap_ep_t* ep); |
| TMBOY | 47:9e361da97763 | 87 | |
| TMBOY | 47:9e361da97763 | 88 | /* |
| TMBOY | 47:9e361da97763 | 89 | * Unregister the endpoint by LWM2M |
| TMBOY | 47:9e361da97763 | 90 | * |
| TMBOY | 47:9e361da97763 | 91 | * @Param hdlr, in, the CoAP context |
| TMBOY | 47:9e361da97763 | 92 | * @Return bca_status_t, if > 0, the result is the unregister message id, else is the error status |
| TMBOY | 47:9e361da97763 | 93 | */ |
| TMBOY | 47:9e361da97763 | 94 | BCA_INT bca_status_t bca_coap_unregister(bca_coap_handler coap); |
| TMBOY | 47:9e361da97763 | 95 | |
| TMBOY | 47:9e361da97763 | 96 | /* |
| TMBOY | 47:9e361da97763 | 97 | * Update registration by LWM2M |
| TMBOY | 47:9e361da97763 | 98 | * |
| TMBOY | 47:9e361da97763 | 99 | * @Param hdlr, in, the CoAP context |
| TMBOY | 47:9e361da97763 | 100 | * @Param lifetime, in, the endpoint lifetime |
| TMBOY | 47:9e361da97763 | 101 | * @Return bca_status_t, if > 0, the result is the update registration message id, |
| TMBOY | 47:9e361da97763 | 102 | * else is the error status |
| TMBOY | 47:9e361da97763 | 103 | */ |
| TMBOY | 47:9e361da97763 | 104 | BCA_INT bca_status_t bca_coap_update_registration(bca_coap_handler coap, |
| TMBOY | 47:9e361da97763 | 105 | bca_u32_t lifetime); |
| TMBOY | 47:9e361da97763 | 106 | |
| TMBOY | 47:9e361da97763 | 107 | /* |
| TMBOY | 47:9e361da97763 | 108 | * Send the CoAP message |
| TMBOY | 47:9e361da97763 | 109 | * |
| TMBOY | 47:9e361da97763 | 110 | * @Param hdlr, in, the CoAP context |
| TMBOY | 47:9e361da97763 | 111 | * @Param msg, in, the CoAP message |
| TMBOY | 47:9e361da97763 | 112 | * @Return bca_status_t, the result |
| TMBOY | 47:9e361da97763 | 113 | */ |
| TMBOY | 47:9e361da97763 | 114 | BCA_INT bca_status_t bca_coap_send(bca_coap_handler coap, const bca_msg_t* msg); |
| TMBOY | 47:9e361da97763 | 115 | |
| TMBOY | 47:9e361da97763 | 116 | /* |
| TMBOY | 47:9e361da97763 | 117 | * Receive the CoAP message |
| TMBOY | 47:9e361da97763 | 118 | * |
| TMBOY | 47:9e361da97763 | 119 | * @Param hdlr, in, the CoAP context |
| TMBOY | 47:9e361da97763 | 120 | * @Return bca_status_t, the result |
| TMBOY | 47:9e361da97763 | 121 | */ |
| TMBOY | 47:9e361da97763 | 122 | BCA_INT bca_status_t bca_coap_data_available(bca_coap_handler coap); |
| TMBOY | 47:9e361da97763 | 123 | |
| TMBOY | 47:9e361da97763 | 124 | /* |
| TMBOY | 47:9e361da97763 | 125 | * Execute the cached CoAP data |
| TMBOY | 47:9e361da97763 | 126 | * |
| TMBOY | 47:9e361da97763 | 127 | * @Param hdlr, in, the CoAP context |
| TMBOY | 47:9e361da97763 | 128 | * @Param timestamp, in, the timestamp for mark the message |
| TMBOY | 47:9e361da97763 | 129 | * @Return bca_status_t, the result |
| TMBOY | 47:9e361da97763 | 130 | */ |
| TMBOY | 47:9e361da97763 | 131 | BCA_INT bca_status_t bca_coap_exec(bca_coap_handler hdlr, bca_u32_t timestamp); |
| TMBOY | 47:9e361da97763 | 132 | |
| TMBOY | 47:9e361da97763 | 133 | /* |
| TMBOY | 47:9e361da97763 | 134 | * Release the CoAP context |
| TMBOY | 47:9e361da97763 | 135 | * |
| TMBOY | 47:9e361da97763 | 136 | * @Param hdlr, in, the CoAP context |
| TMBOY | 47:9e361da97763 | 137 | * @Return bca_status_t, the result |
| TMBOY | 47:9e361da97763 | 138 | */ |
| TMBOY | 47:9e361da97763 | 139 | BCA_INT bca_status_t bca_coap_release(bca_coap_handler coap); |
| TMBOY | 47:9e361da97763 | 140 | |
| TMBOY | 47:9e361da97763 | 141 | /* |
| TMBOY | 47:9e361da97763 | 142 | * Set read timeout |
| TMBOY | 47:9e361da97763 | 143 | * |
| TMBOY | 47:9e361da97763 | 144 | * @Param hdlr, in, the CoAP context |
| TMBOY | 47:9e361da97763 | 145 | * @Param timeout, in, the timeout value by milliseconds |
| TMBOY | 47:9e361da97763 | 146 | * @Return bca_bool, if match return BCA_TRUE, else return BCA_FALSE |
| TMBOY | 47:9e361da97763 | 147 | */ |
| TMBOY | 47:9e361da97763 | 148 | BCA_INT bca_status_t bca_coap_set_read_timeout(bca_coap_handler coap, bca_u32_t timeout); |
| TMBOY | 47:9e361da97763 | 149 | |
| TMBOY | 47:9e361da97763 | 150 | #ifdef __cplusplus |
| TMBOY | 47:9e361da97763 | 151 | } |
| TMBOY | 47:9e361da97763 | 152 | #endif |
| TMBOY | 47:9e361da97763 | 153 | |
| TMBOY | 47:9e361da97763 | 154 | #endif // BAIDU_IOT_TINYDU_IOT_OS_SRC_IOT_BAIDU_CA_SOURCE_BAIDU_CA_COAP_H |
