Getting Started with EZ-BT WICED Modules
Document Number: 002-23400 Rev. **
35
// indications, we can send only one and need to wait for ack.
while
( ( hello_sensor_state.
num_to_write
!= 0 ) && !hello_sensor_state.
flag_indication_sent
)
{
hello_sensor_state.
num_to_write
--;
hello_sensor_send_message();
}
// If configured to disconnect after delivering data, start idle timeout
// to do disconnection
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 );
}
}
After security-related events, the
hello_sensor_gatts_req_cb
function shown in
GATT_ATTRIBUTE_REQUEST_EVT
event from the connected remote client.
hello_sensor_gatts_req_cb
processes
GATT read, GATT write, GATT write execute, MTU request, and indication confirmation actions.
Code 22.
hello_sensor_gatts_req_cb
: Top-Level GATT Function
wiced_bt_gatt_status_t
hello_sensor_gatts_req_cb
(
wiced_bt_gatt_attribute_request_t
*p_data )
{
wiced_result_t
result =
WICED_BT_GATT_INVALID_PDU
;
WICED_BT_TRACE(
"hello_sensor_gatts_req_cb. conn %d, type %d\n"
, p_data->
conn_id
, p_data->
request_type
);
switch
( p_data->
request_type
)
{
case
GATTS_REQ_TYPE_READ
:
result = hello_sensor_gatts_req_read_handler( p_data->
conn_id
, &(p_data->
data
.
read_req
) );
break
;
case
GATTS_REQ_TYPE_WRITE
:
result = hello_sensor_gatts_req_write_handler( p_data->
conn_id
, &(p_data->
data
.
write_req
) );
break
;
case
GATTS_REQ_TYPE_WRITE_EXEC
:
result = hello_sensor_gatts_req_write_exec_handler( p_data->
conn_id
, p_data->
data
.
exec_write
);
break
;
case
GATTS_REQ_TYPE_MTU
:
result = hello_sensor_gatts_req_mtu_handler( p_data->
conn_id
, p_data->
data
.
mtu
);
break
;
case
GATTS_REQ_TYPE_CONF
:
result = hello_sensor_gatts_req_conf_handler( p_data->
conn_id
, p_data->
data
.
handle
);
break
;
default
:
break
;
}
}
For this application,
hello_sensor_gatts_req_read_handler
,
hello_sensor_gatts_req_write_handler
,
and
hello_sensor_gatts_req_conf_handler
are used to process read, write, and indication confirmation requests.
7.4.3.1
GATT Read Request
The Client can issue a read request to retreive data from any charactersitic which has read property enabled in the
GATT database. The
hello_sensor_gatts_req_read_handler
function processes the read request command from
the connected remote Client device. In this example, this funtion sends dummy battery level data when the remote
Client
issues
a
read
request
to
the
battery
level
charactersitc
handle(0x62),
HANDLE_HSENS_BATTERY_SERVICE_CHAR_LEVEL_VAL
.
Valid characteritic handler verification is done at the beginning
of the funtion; a negative response is sent for read requests wtih invalid characteristic handles. Reqeusted data is
packaged into an appropriate form and passed for further processing to the stack.