![Cypress EZ-BT WICED CYBT-343026-01 Скачать руководство пользователя страница 41](http://html1.mh-extra.com/html/cypress/ez-bt-wiced-cybt-343026-01/ez-bt-wiced-cybt-343026-01_getting-started_2705923041.webp)
Getting Started with EZ-BT WICED Modules
Document Number: 002-23400 Rev. **
41
Code 31. Connection Up and Connection Down Call Back Functions
/*
* SPP connection up callback
*/
void
spp_connection_up_callback
(
uint16_t
handle,
uint8_t
* bda)
{
WICED_BT_TRACE(
"%s handle:%d address:%B\n"
, __FUNCTION__, handle, bda);
spp_handle = handle;
}
/*
* SPP connection down callback
*/
void
spp_connection_down_callback
(
uint16_t
handle)
{
WICED_BT_TRACE(
"%s handle:%d\n"
, __FUNCTION__, handle);
spp_handle = 0;
}
The next function to look at is
spp_rx_data_callback.
The
Bluetooth stack triggers this callback function when data
is received from the master Bluetooth BR/EDR device over the SPP profile. The received data is sent back to the host
if the
LOOPBACK_DATA
macro is set to
‘1’. This macro is disabled in this example; so uncomment
LOOPBACK_DATA
based on application requirement.
Code 32.
spp_rx_data_callback
: Callback for Received Data over SPP Profile
wiced_bool_t
spp_rx_data_callback
(
uint16_t
handle,
uint8_t
* p_data,
uint32_t
data_len)
{
int
i;
// wiced_bt_buffer_statistics_t buffer_stats[4];
// wiced_bt_get_buffer_usage (buffer_stats, sizeof(buffer_stats));
// WICED_BT_TRACE("0:%d/%d 1:%d/%d 2:%d/%d 3:%d/%d\n", buffer_stats[0].current_allocated_count,
buffer_stats[0].max_allocated_count,
// buffer_stats[1].current_allocated_count, buffer_stats[1].max_allocated_count,
// buffer_stats[2].current_allocated_count, buffer_stats[2].max_allocated_count,
// buffer_stats[3].current_allocated_count, buffer_stats[3].max_allocated_count);
// wiced_result_t wiced_bt_get_buffer_usage (&buffer_stats, sizeof(buffer_stats));
WICED_BT_TRACE(
"%s handle:%d len:%d %02x-%02x\n"
, __FUNCTION__, handle, data_len, p_data[0],
p_data[data_len - 1]);
#if
LOOPBACK_DATA
wiced_bt_spp_send_session_data(handle, p_data, data_len);
#endif
return
WICED_TRUE;
}
The next functions to look at are read and write NVRAM. Pairing keys are stored in the NVRAM of the Peripheral/slave
Bluetooth device after successful pairing. NVRAM write and read operations are performed to store pairing keys and
to retrieve them when the Bluetooth stack triggers the
BTM_PAIRED_DEVICE_LINK_KEYS_UPDATE_EVT
and
BTM_PAIRED_DEVICE_LINK_KEYS_REQUEST_EVT
events
respectively.
Code 33. NVRAM Access Function
int
bt_write_nvram
(
int
nvram_id,
int
data_len,
void
*p_data)
{
wiced_result_t
result;
int
bytes_written = wiced_hal_write_nvram(nvram_id, data_len, (
uint8_t
*)p_data, &result);
WICED_BT_TRACE(
"NVRAM ID:%d written :%d bytes result:%d\n"
, nvram_id, bytes_written, result);
return
(bytes_written);
}
int
bt_read_nvram
(
int
nvram_id,
void
*p_data,
int
data_len)
{
uint16_t
read_bytes = 0;
wiced_result_t
result;
if
(data_len >=
sizeof
(
wiced_bt_device_link_keys_t
))