![Cypress EZ-BT WICED CYBT-343026-01 Скачать руководство пользователя страница 20](http://html1.mh-extra.com/html/cypress/ez-bt-wiced-cybt-343026-01/ez-bt-wiced-cybt-343026-01_getting-started_2705923020.webp)
Getting Started with EZ-BT WICED Modules
Document Number: 002-23400 Rev. **
20
7 . 3 . 3
Ad d B L E - r e l a t e d I n i t i a l i z a t i o n a n d O t h e r C a l l b a c k F u n c t i o n s i n t h e s p p . c F i l e
3. As we are merging two projects, initialization of both SPP and Hello Sensor projects should occur in one call back
function,
app_management_callback()
, of
spp.c
. Add the
hello_sensor_application_init()
function in the
app_management_callback()
function.
Code 3.
spp.c
: Add
hello_sensor_appplication_init
Funtion
case
BTM_ENABLED_EVT
:
application_init();
hello_sensor_application_init();
WICED_BT_TRACE(
"Free mem:%d"
, wiced_memory_get_free_bytes());
break
;
4. Add the following BLE stack events in the
app_management_callback()
function for BLE operation:
Because both BLE and Bluetooth BR/EDR events are consolidated in one callback function, it is
required to define additional events for BLE that are missing in spp Bluetooth BR/EDR project file.
Note:
Declare
wiced_bt_ble_advert_mode_t *p_mode
at the beginning of
app_management_callback()
.
▪
BTM_SECURITY_REQUEST_EVT
: To grant access to BLE device pairing.
▪
BTM_BLE_ADVERT_STATE_CHANGED_EVT
: To start BLE advertisement if advertisement is stopped after a
timeout.
▪
BTM_PAIRING_IO_CAPABILITIES_BLE_REQUEST_EVT
: To configure I/O capabilities of the BLE device which
are exchanged during the pairing process with the remote Central device.
Code 4.
spp.c
: Add
wiced_bt_ble_security_grant
API
case
BTM_SECURITY_REQUEST_EVT
:
wiced_bt_ble_security_grant( p_event_data->
security_request
.
bd_addr
,
WICED_BT_SUCCESS
);
break
;
case
BTM_BLE_ADVERT_STATE_CHANGED_EVT
:
p_mode = &p_event_data->
ble_advert_state_changed
;
WICED_BT_TRACE(
"Advertisement State Change: %d\n"
, *p_mode);
if
( *p_mode ==
BTM_BLE_ADVERT_OFF
)
{
hello_sensor_advertisement_stopped();
}
break
;
case
BTM_PAIRING_IO_CAPABILITIES_BLE_REQUEST_EVT
:
p_event_data->
pairing_io_capabilities_ble_request
.
local_io_cap
=
BTM_IO_CAPABILITIES_NONE
;
p_event_data->
pairing_io_capabilities_ble_request
.
oob_data
=
BTM_OOB_NONE
;
p_event_data->
pairing_io_capabilities_ble_request
.
auth_req
=
BTM_LE_AUTH_REQ_SC_BOND
;
p_event_data->
pairing_io_capabilities_ble_request
.
max_key_size
= 0x10;
p_event_data->
pairing_io_capabilities_ble_request
.
init_keys
=
BTM_LE_KEY_PENC
|
BTM_LE_KEY_PID
|
BTM_LE_KEY_PCSRK
|
BTM_LE_KEY_LENC
;
p_event_data->
pairing_io_capabilities_ble_request
.
resp_keys
=
BTM_LE_KEY_PENC
|
BTM_LE_KEY_PID
|
BTM_LE_KEY_PCSRK
|
BTM_LE_KEY_LENC
;
break
;
5. Add the hello_sensor_encryption_changed function in BTM_ENCRYPTION_STATUS_EVT.
Code 5.
spp.c
: Add
hello_sensor_encryption_changed
API
case
BTM_ENCRYPTION_STATUS_EVT
:
p_encryption_status = &p_event_data->
encryption_status
;
WICED_BT_TRACE(
"Encryption Status Event: bd (%B) res %d\n"
, p_encryption_status->
bd_addr
,
p_encryption_status->
result
);
hello_sensor_encryption_changed( p_encryption_status->
result
, p_encryption_status->
bd_addr
);
break
;