BLE APIs¶
BLE 简介¶
BK7238 是BLE 5.2 协议栈,同时支持master和slave 模式。
BLE API 类别¶
BLE API 可分为:
BLE common interface
BLE scan interface
BLE ADV interface
BLE connect interface
编程建议¶
重要
- 使用BLE API 的一些特别注意项:
不要在 BLE 事件回调中做太多工作,需将事件通过信号量等方式抛到您自己的应用程序任务处理.
BK7238 BLE API都是异步执行的,应用程序调用 BLE API ,需要获得 对应的BLE 事件通知。
API Reference¶
Functions¶
-
uint8_t
app_ble_get_idle_actv_idx_handle
(void)¶ Get an idle activity.
- Return
the idle activity’s index
-
ble_err_t
bk_ble_create_db
(struct bk_ble_db_cfg *ble_db_cfg)¶ Register a gatt service.
example: First we must build test_att_db test_att_db is a database for att, which used in ble discovery. reading writing and other operation is used on a att database.
TEST_IDX_SVC is nessecery, is declare a primary att service. The macro define is: which is an UUID say it is a “primary service”#define BK_ATT_DECL_PRIMARY_SERVICE_128 {0x00,0x28,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0} #define BK_ATT_DECL_CHARACTERISTIC_128 {0x03,0x28,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0} #define BK_ATT_DESC_CLIENT_CHAR_CFG_128 {0x02,0x29,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0} #define WRITE_REQ_CHARACTERISTIC_128 {0x01,0xFF,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0} #define INDICATE_CHARACTERISTIC_128 {0x02,0xFF,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0} #define NOTIFY_CHARACTERISTIC_128 {0x03,0xFF,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0} static const uint8_t test_svc_uuid[16] = {0xFF,0xFF,0,0,0x34,0x56,0,0,0,0,0x28,0x37,0,0,0,0}; enum { TEST_IDX_SVC, TEST_IDX_FF01_VAL_CHAR, TEST_IDX_FF01_VAL_VALUE, TEST_IDX_FF02_VAL_CHAR, TEST_IDX_FF02_VAL_VALUE, TEST_IDX_FF02_VAL_IND_CFG, TEST_IDX_FF03_VAL_CHAR, TEST_IDX_FF03_VAL_VALUE, TEST_IDX_FF03_VAL_NTF_CFG, TEST_IDX_NB, }; //att records database. bk_attm_desc_t test_att_db[TEST_IDX_NB] = { // Service Declaration [TEST_IDX_SVC] = {BK_ATT_DECL_PRIMARY_SERVICE_128, PROP(RD), 0}, // Level Characteristic Declaration [TEST_IDX_FF01_VAL_CHAR] = {BK_ATT_DECL_CHARACTERISTIC_128, PROP(RD), 0}, // Level Characteristic Value [TEST_IDX_FF01_VAL_VALUE] = {WRITE_REQ_CHARACTERISTIC_128, PROP(WR)|ATT_UUID(128), 128|OPT(NO_OFFSET)}, [TEST_IDX_FF02_VAL_CHAR] = {BK_ATT_DECL_CHARACTERISTIC_128, PROP(RD), 0}, // Level Characteristic Value [TEST_IDX_FF02_VAL_VALUE] = {INDICATE_CHARACTERISTIC_128, PROP(I), 128|OPT(NO_OFFSET)}, // Level Characteristic - Client Characteristic Configuration Descriptor [TEST_IDX_FF02_VAL_IND_CFG] = {BK_ATT_DESC_CLIENT_CHAR_CFG_128, PROP(RD)|PROP(WR),OPT(NO_OFFSET)}, [TEST_IDX_FF03_VAL_CHAR] = {BK_ATT_DECL_CHARACTERISTIC_128, PROP(RD), 0}, // Level Characteristic Value [TEST_IDX_FF03_VAL_VALUE] = {NOTIFY_CHARACTERISTIC_128, PROP(N), 128|OPT(NO_OFFSET)}, // Level Characteristic - Client Characteristic Configuration Descriptor [TEST_IDX_FF03_VAL_NTF_CFG] = {BK_ATT_DESC_CLIENT_CHAR_CFG_128, PROP(RD)|PROP(WR), OPT(NO_OFFSET)}, };
TEST_IDX_FF01_VAL_CHAR declare a characteristic as a element in service, it must be PROP(RD)
TEST_IDX_FF01_VAL_VALUE is the real value of TEST_IDX_FF01_VAL_CHAR,
PROP(N) Notification Access
PROP(I) Indication Access
PROP(RD) Read Access
PROP(WR) Write Request Enabled
PROP(WC) Write Command Enabled
ATT_UUID(128) set att uuid len
Secondlly, we build ble_db_cfg
prf_task_id is app handle. If you have multi att service, used prf_task_id to distinguish it. svc_perm show TEST_IDX_SVC UUID type’s len.struct bk_ble_db_cfg ble_db_cfg; ble_db_cfg.att_db = (ble_attm_desc_t *)test_att_db; ble_db_cfg.att_db_nb = TEST_IDX_NB; ble_db_cfg.prf_task_id = g_test_prf_task_id; ble_db_cfg.start_hdl = 0; ble_db_cfg.svc_perm = BK_BLE_PERM_SET(SVC_UUID_LEN, UUID_16);
- Return
ERR_SUCCESS: succeed
others: other errors.
- Parameters
ble_db_cfg:
: service param
-
void
ble_set_notice_cb
(ble_notice_cb_t func)¶ Register ble event notification callback.
User example:
void ble_notice_cb(ble_notice_t notice, void *param) { switch (notice) { case BLE_5_STACK_OK: case BLE_5_WRITE_EVENT: case BLE_5_READ_EVENT: case BLE_5_TX_DONE break; case BLE_5_CREATE_DB: //bk_ble_create_db success here break; } } ble_set_notice_cb(ble_notice_cb);
- Attention
you must regist it, otherwise you cant get any event !
you must regist it before bk_ble_create_db, otherwise you cant get BLE_5_CREATE_DB event
- Return
void
- Parameters
func:
: event callback
-
uint8_t
ble_appm_get_dev_name
(uint8_t *name, uint32_t buf_len)¶ Get device name.
- Return
length: the length of device name
- Parameters
name:
: store the device namebuf_len: the length of buf to store the device name
-
uint8_t
ble_appm_set_dev_name
(uint8_t len, uint8_t *name)¶ Set device name.
- Return
length: the length of device name
- Parameters
len:
: the length of device namename: the device name to be set
-
ble_err_t
bk_ble_adv_start
(uint8_t actv_idx, struct adv_param *adv, ble_cmd_cb_t callback)¶ Create and start a ble advertising activity.
User example:
struct adv_param adv_info; adv_info.channel_map = 7; adv_info.duration = 0; adv_info.prop = (1 << ADV_PROP_CONNECTABLE_POS) | (1 << ADV_PROP_SCANNABLE_POS); adv_info.interval_min = 160; adv_info.interval_max = 160; adv_info.advData[0] = 0x09; adv_info.advData[1] = 0x09; memcpy(&adv_info.advData[2], "7238_BLE", 8); adv_info.advDataLen = 10; adv_info.respData[0] = 0x05; adv_info.respData[1] = 0x08; memcpy(&adv_info.respData[2], "7238", 4); adv_info.respDataLen = 6; actv_idx = app_ble_get_idle_actv_idx_handle(); bk_ble_adv_start(actv_idx, &adv_info, ble_cmd_cb);
- Attention
you must wait callback status, 0 mean success.
- Return
ERR_SUCCESS: succeed
others: other errors.
- Parameters
actv_idx:
: the index of activityadv: the advertising parameter
callback: register a callback for this action, ble_cmd_t: BLE_INIT_ADV
-
ble_err_t
bk_ble_adv_stop
(uint8_t actv_idx, ble_cmd_cb_t callback)¶ Stop and delete the advertising that has been created.
- Attention
you must wait callback status, 0 mean success.
must used after bk_ble_adv_start
- Return
ERR_SUCCESS: succeed
others: other errors.
- Parameters
actv_idx:
: the index of activitycallback: register a callback for this action, ble_cmd_t: BLE_DEINIT_ADV
-
ble_err_t
bk_ble_scan_start
(uint8_t actv_idx, struct scan_param *scan, ble_cmd_cb_t callback)¶ Create and start a ble scan activity.
User example:
struct scan_param scan_info; scan_info.channel_map = 7; scan_info.interval = 100; scan_info.window = 30; actv_idx = app_ble_get_idle_actv_idx_handle(); bk_ble_scan_start(actv_idx, &scan_info, ble_cmd_cb);
- Attention
you must wait callback status, 0 mean success.
- Return
ERR_SUCCESS: succeed
others: other errors.
- Parameters
actv_idx:
: the index of activityscan: the scan parameter
callback: register a callback for this action, ble_cmd_t: BLE_INIT_SCAN
-
ble_err_t
bk_ble_scan_stop
(uint8_t actv_idx, ble_cmd_cb_t callback)¶ Stop and delete the scan that has been created.
- Attention
you must wait callback status, 0 mean success.
must used after bk_ble_scan_start
- Return
ERR_SUCCESS: succeed
others: other errors.
- Parameters
actv_idx:
: the index of activitycallback: register a callback for this action, ble_cmd_t: BLE_DEINIT_SCAN
-
ble_err_t
bk_ble_create_advertising
(uint8_t actv_idx, unsigned char chnl_map, uint32_t intv_min, uint32_t intv_max, ble_cmd_cb_t callback)¶ Create a ble advertising activity.
User example:
actv_idx = app_ble_get_idle_actv_idx_handle(); if (actv_idx != UNKNOW_ACT_IDX) { bk_ble_create_advertising(actv_idx,7,160,160, ble_cmd_cb); }
- Attention
you must wait callback status, 0 mean success.
- Return
ERR_SUCCESS: succeed
others: other errors.
- Parameters
actv_idx:
: the index of activitychnl_map: the advertising channel map
intv_min: the advertising min interval
intv_max: the advertising max interval
callback: register a callback for this action, ble_cmd_t: BLE_CREATE_ADV
-
ble_err_t
bk_ble_create_extended_advertising
(uint8_t actv_idx, unsigned char chnl_map, uint32_t intv_min, uint32_t intv_max, uint8_t scannable, uint8_t connectable, ble_cmd_cb_t callback)¶ Create a ble advertising activity.
User example:
actv_idx = app_ble_get_idle_actv_idx_handle(); if (actv_idx != UNKNOW_ACT_IDX) { bk_ble_create_extended_advertising(actv_idx,7,160,160,1,0,ble_cmd_cb); }
- Attention
you must wait callback status, 0 mean success.
- Return
ERR_SUCCESS: succeed
others: other errors.
- Parameters
actv_idx:
: the index of activitychnl_map: the advertising channel map
intv_min: the advertising min interval
intv_max: the advertising max interval
scannable: the advertising whether be scanned
connectable: the advertising whether be connected
callback: register a callback for this action, ble_cmd_t: BLE_CREATE_ADV
-
ble_err_t
bk_ble_start_advertising
(uint8_t actv_idx, uint16 duration, ble_cmd_cb_t callback)¶ Start a ble advertising.
- Attention
you must wait callback status, 0 mean success.
must used after bk_ble_create_advertising
- Return
ERR_SUCCESS: succeed
others: other errors.
- Parameters
actv_idx:
: the index of activityduration: Advertising duration (in unit of 10ms). 0 means that advertising continues
callback: register a callback for this action, ble_cmd_t: BLE_START_ADV
-
ble_err_t
bk_ble_stop_advertising
(uint8_t actv_idx, ble_cmd_cb_t callback)¶ Stop the advertising that has been started.
- Attention
you must wait callback status, 0 mean success.
must used after bk_ble_start_advertising
- Return
ERR_SUCCESS: succeed
others: other errors.
- Parameters
actv_idx:
: the index of activitycallback: register a callback for this action, ble_cmd_t: BLE_STOP_ADV
-
ble_err_t
bk_ble_delete_advertising
(uint8_t actv_idx, ble_cmd_cb_t callback)¶ Delete the advertising that has been created.
- Attention
you must wait callback status, 0 mean success.
must used after bk_ble_create_advertising
- Return
ERR_SUCCESS: succeed
others: other errors.
- Parameters
actv_idx:
: the index of activitycallback: register a callback for this action, ble_cmd_t: BLE_DELETE_ADV
-
ble_err_t
bk_ble_set_adv_data
(uint8_t actv_idx, unsigned char *adv_buff, unsigned char adv_len, ble_cmd_cb_t callback)¶ Set the advertising data.
User example:
const uint8_t adv_data[] = {0x0A, 0x09, 0x37 0x32, 0x33, 0x31, 0x4e, 0x5f, 0x42, 0x4c, 0x45}; bk_ble_set_adv_data(actv_idx, adv_data, sizeof(adv_data), ble_cmd_cb);
- Attention
you must wait callback status, 0 mean success.
must used after bk_ble_create_advertising
- Return
ERR_SUCCESS: succeed
others: other errors.
- Parameters
actv_idx:
: the index of activityadv_buff: advertising data
adv_len: the length of advertising data
callback: register a callback for this action, ble_cmd_t: BLE_SET_ADV_DATA
-
ble_err_t
bk_ble_set_ext_adv_data
(uint8_t actv_idx, unsigned char *adv_buff, uint16_t adv_len, ble_cmd_cb_t callback)¶ Set the ext advertising data.
User example:
const uint8_t adv_data[] = {0x0A, 0x09, 0x37 0x32, 0x33, 0x31, 0x4e, 0x5f, 0x42, 0x4c, 0x45}; bk_ble_set_ext_adv_data(actv_idx, adv_data, sizeof(adv_data), ble_cmd_cb);
- Attention
you must wait callback status, 0 mean success.
must used after bk_ble_create_extended_advertising
- Return
ERR_SUCCESS: succeed
others: other errors.
- Parameters
actv_idx:
: the index of activityadv_buff: advertising data
adv_len: the length of advertising data
callback: register a callback for this action, ble_cmd_t: BLE_SET_ADV_DATA
-
ble_err_t
bk_ble_set_scan_rsp_data
(uint8_t actv_idx, unsigned char *scan_buff, unsigned char scan_len, ble_cmd_cb_t callback)¶ Set the scan response data.
User example:
const uint8_t scan_data[] = {0x0A, 0x09, 0x37 0x32, 0x33, 0x31, 0x4e, 0x5f, 0x42, 0x4c, 0x45}; bk_ble_set_scan_rsp_data(actv_idx, scan_data, sizeof(scan_data), ble_cmd_cb);
- Attention
you must wait callback status, 0 mean success.
scan rsp data similaly to adv data
must used after bk_ble_create_advertising
- Return
ERR_SUCCESS: succeed
others: other errors.
- Parameters
actv_idx:
: the index of activityscan_buff: scan response data
scan_len: the length of scan response data
callback: register a callback for this action, ble_cmd_t: BLE_SET_RSP_DATA
-
ble_err_t
bk_ble_set_ext_scan_rsp_data
(uint8_t actv_idx, unsigned char *scan_buff, uint16_t scan_len, ble_cmd_cb_t callback)¶ Set the ext adv scan response data.
User example:
const uint8_t scan_data[] = {0x0A, 0x09, 0x37 0x32, 0x33, 0x31, 0x4e, 0x5f, 0x42, 0x4c, 0x45}; bk_ble_set_ext_scan_rsp_data(actv_idx, scan_data, sizeof(scan_data), ble_cmd_cb);
- Attention
you must wait callback status, 0 mean success.
scan rsp data similaly to adv data
must used after bk_ble_create_extended_advertising
- Return
ERR_SUCCESS: succeed
others: other errors.
- Parameters
actv_idx:
: the index of activityscan_buff: scan response data
scan_len: the length of scan response data
callback: register a callback for this action, ble_cmd_t: BLE_SET_RSP_DATA
-
ble_err_t
bk_ble_update_param
(uint8_t conn_idx, uint16_t intv_min, uint16_t intv_max, uint16_t latency, uint16_t sup_to, ble_cmd_cb_t callback)¶ Update connection parameters.
- Attention
you must wait callback status, 0 mean success.
must used after connected
- Return
ERR_SUCCESS: succeed
others: other errors.
- Parameters
conn_idx:
: the index of connectionintv_min: connection min interval
intv_max: connection max interval
latency: connection latency
sup_to: connection timeout
callback: register a callback for this action, ble_cmd_t: BLE_CONN_UPDATE_PARAM
-
ble_err_t
bk_ble_disconnect
(uint8_t conn_idx, ble_cmd_cb_t callback)¶ Disconnect a ble connection.
- Attention
you must wait callback status, 0 mean success.
must used after connected
- Return
ERR_SUCCESS: succeed
others: other errors.
- Parameters
conn_idx:
: the index of connectioncallback: register a callback for this action, ble_cmd_t: BLE_CONN_DIS_CONN
-
ble_err_t
bk_ble_gatt_mtu_change
(uint8_t conn_idx, ble_cmd_cb_t callback)¶ Exchange MTU.
- Attention
you must wait callback status, 0 mean success.
must used after connected
- Return
ERR_SUCCESS: succeed
others: other errors.
- Parameters
conn_idx:
: the index of connectioncallback: register a callback for this action, ble_cmd_t: BLE_CONN_UPDATE_MTU
-
ble_err_t
bk_ble_create_scaning
(uint8_t actv_idx, ble_cmd_cb_t callback)¶ Create a ble scan activity.
User exzample:
actv_idx = app_ble_get_idle_actv_idx_handle(); bk_ble_create_scaning(actv_idx, ble_at_cmd);
- Attention
you must wait callback status, 0 mean success.
- Parameters
actv_idx:
: the index of activitycallback: register a callback for this action, ble_cmd_t: BLE_CREATE_SCAN
- Return
ERR_SUCCESS: succeed
others: other errors.
-
ble_err_t
bk_ble_start_scaning
(uint8_t actv_idx, uint16_t scan_intv, uint16_t scan_wd, ble_cmd_cb_t callback)¶ Start a ble scan.
- Attention
you must wait callback status, 0 mean success.
must used after bk_ble_create_scaning
adv will report in ble_notice_cb_t as BLE_5_REPORT_ADV
- Return
ERR_SUCCESS: succeed
others: other errors.
- Parameters
actv_idx:
: the index of activityscan_intv: scan interval
scan_wd: scan window
callback: register a callback for this action, ble_cmd_t: BLE_START_SCAN
-
ble_err_t
bk_ble_stop_scaning
(uint8_t actv_idx, ble_cmd_cb_t callback)¶ Stop the scan that has been started.
- Attention
you must wait callback status, 0 mean success.
must used after bk_ble_start_scaning
- Return
ERR_SUCCESS: succeed
others: other errors.
- Parameters
actv_idx:
: the index of activitycallback: register a callback for this action, ble_cmd_t: BLE_STOP_SCAN
-
ble_err_t
bk_ble_delete_scaning
(uint8_t actv_idx, ble_cmd_cb_t callback)¶ Delete the scan that has been created.
- Attention
you must wait callback status, 0 mean success.
must used after bk_ble_create_scaning
- Return
ERR_SUCCESS: succeed
others: other errors.
- Parameters
actv_idx:
: the index of activitycallback: register a callback for this action, ble_cmd_t: BLE_DELETE_SCAN
-
ble_err_t
bk_ble_conidx_send_ntf
(uint8_t conidx, uint32_t len, uint8_t *buf, uint16_t prf_id, uint16_t att_idx)¶ As slaver, send a notification of an attribute’s value.
- Return
ERR_SUCCESS: succeed
others: other errors.
- Parameters
conidx:
: the index of connectionlen: the length of attribute’s value
buf: attribute’s value
prf_id: The id of the profile
att_idx: The index of the attribute
-
ble_err_t
bk_ble_conidx_send_ind
(uint8_t conidx, uint32_t len, uint8_t *buf, uint16_t prf_id, uint16_t att_idx)¶ As slaver, send an indication of an attribute’s value.
- Return
ERR_SUCCESS: succeed
others: other errors.
- Parameters
conidx:
: the index of connectionlen: the length of attribute’s value
buf: attribute’s value
prf_id: The id of the profile
att_idx: The index of the attribute
-
void
sdp_set_notice_cb
(sdp_notice_cb_t func)¶ Register ble master event notification callback.
you must regist it before bk_ble_create_init
- Attention
you must regist it, otherwise you cant get any master event !
- Parameters
func:
: event callback
User example:
void sdp_event_cb(sdp_notice_t notice, void *param) { switch (notice) { case SDP_CHARAC_NOTIFY_EVENT: { sdp_event_t *g_sdp = (sdp_event_t *)param; bk_printf("[SDP_CHARAC_NOTIFY_EVENT]con_idx:%d,hdl:0x%x,value_length:%d\r\n",g_sdp->con_idx,g_sdp->hdl,g_sdp->value_length); } break; case SDP_CHARAC_INDICATE_EVENT: { sdp_event_t *g_sdp = (sdp_event_t *)param; bk_printf("[SDP_CHARAC_INDICATE_EVENT]con_idx:%d,hdl:0x%x,value_length:%d\r\n",g_sdp->con_idx,g_sdp->hdl,g_sdp->value_length); } break; case SDP_CHARAC_READ: { sdp_event_t *g_sdp = (sdp_event_t *)param; bk_printf("[SDP_CHARAC_READ]con_idx:%d,hdl:0x%x,value_length:%d\r\n",g_sdp->con_idx,g_sdp->hdl,g_sdp->value_length); } break; case SDP_DISCOVER_SVR_DONE: { bk_printf("[SDP_DISCOVER_SVR_DONE]\r\n"); } break; case SDP_CHARAC_WRITE_DONE: { bk_printf("[SDP_CHARAC_WRITE_DONE]\r\n"); } break; default: bk_printf("[%s]Event:%d\r\n",__func__,notice); break; } } sdp_set_notice_cb(sdp_event_cb);
- Return
void
-
ble_err_t
bk_ble_create_init
(uint8_t con_idx, unsigned short con_interval, unsigned short con_latency, unsigned short sup_to, ble_cmd_cb_t callback)¶ Create a activity for initiating a connection.
User example:
con_interval = 0x40; //interval con_latency = 0; sup_to = 0x200;//supervision timeout bk_ble_create_init(con_idx, con_interval, con_latency,sup_to,ble_at_cmd);
- Attention
you must wait callback status, 0 mean success.
- Parameters
con_idx:
: the index of connectioncon_interval: the connection parameter
con_latency: the connection parameter
sup_to: the connection parameter
callback: register a callback for this action, ble_cmd_t: BLE_INIT_CREATE
- Return
ERR_SUCCESS: succeed
others: other errors.
-
ble_err_t
bk_ble_init_set_connect_dev_addr
(unsigned char connidx, struct bd_addr *bdaddr, unsigned char addr_type)¶ Set the address of the device to be connected.
User example:
struct bd_addr bdaddr; uint8_t mac[6]={0xc8,0x47,0x8c,0x11,0x22,0x33}; memcpy(bdaddr.addr,mac,6); addr_type = ADDR_PUBLIC; bk_ble_init_set_connect_dev_addr(actv_idx,&bdaddr,addr_type);
- Attention
must used before bk_ble_init_start_conn and used after bk_ble_create_init
addr_type must right, if wrong, cant connect
- Return
ERR_SUCCESS: succeed
others: other errors.
- Parameters
connidx:
: the index of connectionbdaddr: the address of the device to be connected
addr_type: the address type of the device to be connected, 1: public 0: random
-
ble_err_t
bk_ble_init_start_conn
(uint8_t con_idx, ble_cmd_cb_t callback)¶ start a connection
- Attention
you must wait callback status,0 mean success
must used after bk_ble_create_init and bk_ble_init_set_connect_dev_addr
when connect result, will recv BLE_5_INIT_CONNECT_EVENT in ble_notice_cb_t
- Return
ERR_SUCCESS: succeed
others: other errors.
- Parameters
con_idx:
: the index of connectioncallback: register a callback for this action, ble_cmd_t: BLE_INIT_START_CONN
-
ble_err_t
bk_ble_init_stop_conn
(uint8_t con_idx, ble_cmd_cb_t callback)¶ Stop a connection.
- Attention
you must wait callback status,0 mean success
must used after bk_ble_init_start_conn
- Return
ERR_SUCCESS: succeed
others: other errors.
- Parameters
con_idx:
: the index of connectioncallback: register a callback for this action, ble_cmd_t: BLE_INIT_STOP_CONN
-
ble_err_t
bk_ble_read_service_data_by_handle_req
(uint8_t conidx, uint16_t handle, ble_cmd_cb_t callback)¶ As master, read attribute value, the result is reported in the callback registered through bk_ble_register_app_sdp_charac_callback.
- Return
ERR_SUCCESS: succeed
others: fail
- Parameters
conidx:
: the index of connectionhandle: the handle of attribute value
callback: register a callback for this action, ble_cmd_t: BLE_INIT_READ_CHAR
-
ble_err_t
bk_ble_write_service_data_req
(uint8_t conidx, uint16_t handle, uint16_t data_len, uint8_t *data, ble_cmd_cb_t callback)¶ As master, write attribute value.
- Return
ERR_SUCCESS: succeed
others: fail
- Parameters
conidx:
: the index of connectionhandle: the handle of attribute value
data: value data
data_len: the length of attribute value
callback: register a callback for this action, ble_cmd_t: BLE_INIT_WRITE_CHAR