Getting Started with EZ-BT WICED Modules
Document Number: 002-23400 Rev. **
31
/* Tell stack to use our GATT databse */
gatt_status = wiced_bt_gatt_db_init( hello_sensor_gatt_database,
sizeof
(hello_sensor_gatt_database) );
WICED_BT_TRACE(
"wiced_bt_gatt_db_init %d\n"
, gatt_status);
/* Allow peer to pair */
wiced_bt_set_pairable_mode(WICED_TRUE, 0);
#ifdef
ENABLE_HCI_TRACE
/* Register callback for receiving hci traces */
wiced_bt_dev_register_hci_trace( hello_sensor_hci_trace_cback );
#endif
/* Starting the app timers , seconds timer and the ms timer */
wiced_bt_app_start_timer( HELLO_SENSOR_APP_TIMEOUT_IN_SECONDS, HELLO_SENSOR_APP_FINE_TIMEOUT_IN_MS,
hello_sensor_timeout, hello_sensor_fine_timeout );
/* Enable privacy to advertise with RPA */
// wiced_bt_ble_enable_privacy ( WICED_TRUE );
/* Load the address resolution DB with the keys stored in the NVRAM */
// hello_sensor_load_keys_for_address_resolution();
/* Set the advertising params and make the device discoverable */
hello_sensor_set_advertisement_data();
result = wiced_bt_start_advertisements(
BTM_BLE_ADVERT_UNDIRECTED_HIGH
, 0, NULL );
WICED_BT_TRACE(
"wiced_bt_start_advertisements %d\n"
, result );
/*
* Set flag_stay_connected to remain connected after all messages are sent
* Reset flag to 0, to disconnect
*/
hello_sensor_state.
flag_stay_connected
= 1;
}
Take note of how the
application_init()
initialization function ends, which occurs right before the stack gets
execution control again.
For BLE operation,
sets the advertisement data and begins fast undirected and connectable advertisements.
A remote device is able to scan the peripheral device and issue a connect request, which will trigger the callback
hello_sensor_gatts_callback
(the
hello_sensor_gatts_callback
event handler registered in
) and
allow further application-specific behavior for BLE operation.
For Bluetooth BR/EDR operation, the code sets the inquiry response data and makes the device discoverable. A remote
host device performs inquiry and paging process, and issues a connect request to the Bluetooth device which triggers
spp_connection_up_callback
, and allows further application-specific behavior for Bluetooth BR/EDR operation.
7 . 4 . 2
B l u e t o o t h S t a c k E ve n t H a n d l e r s
A single Bluetooth event handler function
app_management_callback
is registered to receive stack callback events
for both Bluetooth BR/EDR and BLE connections. The Bluetooth stack initialization complete event is triggered by the
BTM_ENABLED_EVT
event. Application features are initialized, and necessary callbacks are registered in
BTM_ENABLED_EVT
. Security/ pairing capabilities are exchanged and link keys are stored after appropriate events are
triggered by the stack in
app_management_callback
.
Code 17.
App_manangement_callback
: Bluetooth Stack Event Handler
wiced_result_t
app_management_callback
(
wiced_bt_management_evt_t
event,
wiced_bt_management_evt_data_t
*p_event_data)
{
wiced_result_t
result = WICED_BT_SUCCESS;
wiced_bt_dev_status_t
dev_status;
wiced_bt_dev_pairing_info_t
* p_pairing_info;
wiced_bt_dev_encryption_status_t
* p_encryption_status;
int
bytes_written, bytes_read;
wiced_bt_power_mgmt_notification_t
* p_power_mgmt_notification;
wiced_bt_ble_advert_mode_t
*p_mode;