标签:
Using a vendor specific UUID is basically a two-step process:
1. Add your custom base UUID to the stack by using sd_ble_uuid_vs_add(). Store the value returned to you in the p_type parameter of this function call.
2. Set the type of all ble_uuid_t that should use this base to the value returned to you from sd_ble_uuid_vs_add(). When you set this field to your custom type instead of to BLE_UUID_TYPE_BLE, the value will be used on top of the custom base UUID you specified instead of on top of the Bluetooth SIG base.
Behind the scenes, sd_ble_uuid_vs_add() will add the base UUID to the softdevice‘s internal list of base UUIDs, and return the table index for this UUID in the type field. When using the type in a ble_uuid_t later, the softdevice can look up the base used in this same table by using this index.
I‘ve also attached a small pseudo-code snippet that shows the essentials of this scheme.
uint32_t sd_ble_uuid_vs_add | ( | ble_uuid128_t const *const | p_vs_uuid, |
uint8_t *const | p_uuid_type | ||
) |
This call enables the application to add a vendor specific UUID to the BLE stack‘s table, for later use all other modules and APIs. This then allows the application to use the shorter, 24-bit ble_uuid_t format when dealing with both 16-bit and 128-bit UUIDs without having to check for lengths and having split code paths. The way that this is accomplished is by extending the grouping mechanism that the Bluetooth SIG standard base UUID uses for all other 128-bit UUIDs.
[in] | p_vs_uuid | Pointer to a 16-octet (128-bit) little endian Vendor Specific UUID disregarding bytes 12 and 13. |
[out] | p_uuid_type | Pointer where the type field in ble_uuid_t corresponding to this UUID will be stored. |
service_init: uint32_t err_code; ble_uuid_t ble_uuid; ble_uuid128_t nus_base_uuid = {0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0, 0x93, 0xF3, 0xA3, 0xB5, 0x00, 0x00, 0x40, 0x6E}; // Add custom base UUID err_code = sd_ble_uuid_vs_add(&nus_base_uuid, &p_nus->uuid_type); if (err_code != NRF_SUCCESS) { return err_code; } // Add service ble_uuid.type = p_nus->uuid_type; ble_uuid.uuid = BLE_UUID_NUS_SERVICE; err_code = sd_ble_gatts_service_add(BLE_GATTS_SRVC_TYPE_PRIMARY, &ble_uuid, &p_nus->service_handle); if (err_code != NRF_SUCCESS) { return err_code; } ... char_add: ble_uuid.type = p_nus->uuid_type; ble_uuid.uuid = BLE_UUID_NUS_RX_CHARACTERISTIC; ... return sd_ble_gatts_characteristic_add(p_nus->service_handle, &char_md, &attr_char_value, &p_nus->rx_handles)
版权声明:本文为博主原创文章,未经博主允许不得转载。
nrf51822, How to use a vendor specific UUID?
标签:
原文地址:http://blog.csdn.net/zwj695535100/article/details/46862829