Getting Started with EZ-BT WICED Modules
Document Number: 002-23400 Rev. **
38
hello_sensor_state.
flag_indication_sent
= 0;
/* We might need to send more indications */
if
( hello_sensor_state.
num_to_write
)
{
hello_sensor_state.
num_to_write
--;
hello_sensor_send_message();
}
/* if we sent all messages, start connection idle timer to disconnect */
if
( !hello_sensor_state.
flag_stay_connected
&& !hello_sensor_state.
flag_indication_sent
)
{
wiced_bt_app_start_conn_idle_timer( HELLO_SENSOR_CONN_IDLE_TIMEOUT_IN_SECONDS,
hello_sensor_conn_idle_timeout );
}
return
WICED_BT_GATT_SUCCESS
;
}
Two other callbacks remain in
hello_sensor_gatts_req_cb
,
which are not absolutely necessary for this example.
Place holders for the rest of two funtions are provided in this file,
hello_sensor_gatts_req_write_exec_handler
and
hello_sensor_gatts_req_mtu_handler
.
The next funtion to look at is
hello_sensor_gatts_conn_status_cb
. This callback funtion is registered in the
hello_sensor_application_init
during the intialization phase. The Bluetooth stack triggers this callback funtion
on BLE connection or disconnection.
Code 26.
hello_sensor_gatts_callback
wiced_bt_gatt_status_t
hello_sensor_gatts_callback
(
wiced_bt_gatt_evt_t
event,
wiced_bt_gatt_event_data_t
*p_data)
{
wiced_bt_gatt_status_t
result =
WICED_BT_GATT_INVALID_PDU
;
switch
(event)
{
case
GATT_CONNECTION_STATUS_EVT
:
result = hello_sensor_gatts_conn_status_cb( &p_data->
connection_status
);
break
;
case
GATT_ATTRIBUTE_REQUEST_EVT
:
result = hello_sensor_gatts_req_cb( &p_data->
attribute_request
);
break
;
default
:
break
;
}
return
result;
}
7.4.3.4
Connection Up
In the connection up funtion
hello_sensor_gatts_connection_up
,
the BD Address of the remote Client and
connection ID are copied into the local RAM and also saved in NVRAM. Advertisement is stopped as the Peripheral
device is now connected with the remote Central device.
Code 27.
hello_sensor_gatts_connection_up
wiced_bt_gatt_status_t
hello_sensor_gatts_connection_up
(
wiced_bt_gatt_connection_status_t
*p_status )
{
wiced_result_t
result;
uint8_t
bytes_written = 0;
WICED_BT_TRACE(
"hello_sensor_conn_up %B id:%d\n:"
, p_status->
bd_addr
, p_status->
conn_id
);
/* Update the connection handler. Save address of the connected device. */
hello_sensor_state.
conn_id
= p_status->
conn_id
;
memcpy(hello_sensor_state.
remote_addr
, p_status->
bd_addr
,
sizeof
(
BD_ADDR
));
/* Stop advertising */
result = wiced_bt_start_advertisements(
BTM_BLE_ADVERT_OFF
, 0, NULL );