
Getting Started with EZ-BT WICED Modules
Document Number: 002-23400 Rev. **
36
Code 23. BLE GATT Read Request
wiced_bt_gatt_status_t
hello_sensor_gatts_req_read_handler
(
uint16_t
conn_id,
wiced_bt_gatt_read_t
*
p_read_data )
{
attribute_t
*puAttribute;
int
attr_len_to_copy;
if
( ( puAttribute = hello_sensor_get_attribute(p_read_data->
handle
) ) == NULL)
{
WICED_BT_TRACE(
"read_hndlr attr not found hdl:%x\n"
, p_read_data->
handle
);
return
WICED_BT_GATT_INVALID_HANDLE
;
}
/* Dummy battery value read increment */
if
( p_read_data->
handle
== HANDLE_HSENS_BATTERY_SERVICE_CHAR_LEVEL_VAL)
{
if
( hello_sensor_state.
battery_level
++ > 5)
{
hello_sensor_state.
battery_level
= 0;
}
}
attr_len_to_copy = puAttribute->
attr_len
;
WICED_BT_TRACE(
"read_hndlr conn_id:%d hdl:%x offset:%d len:%d\n"
, conn_id, p_read_data->
handle
,
p_read_data->
offset
, attr_len_to_copy );
if
( p_read_data->
offset
>= puAttribute->
attr_len
)
{
attr_len_to_copy = 0;
}
if
( attr_len_to_copy != 0 )
{
uint8_t
*from;
int
to_copy = attr_len_to_copy - p_read_data->
offset
;
if
( to_copy > *p_read_data->
p_val_len
)
{
to_copy = *p_read_data->
p_val_len
;
}
from = ((
uint8_t
*)puAttribute->
p_attr
) + p_read_data->
offset
;
*p_read_data->
p_val_len
= to_copy;
memcpy( p_read_data->
p_val
, from, to_copy);
}
return
WICED_BT_GATT_SUCCESS
;
}
7.4.3.2
GATT Write Request
The Client can issue a write request to update the value on any characteristic which has the write property enabled in
the GATT database. The
hello_sensor_gatts_req_write_handler
function processes the GATT write request sent
by the connected remote Client device.
•
This funtion receives the Client Characterstic Configuration information on the characteristic handle (0x2B)
HANDLE_HSENS_SERVICE_CHAR_CFG_DESC
, and stores it in the nonvoltatile memory. The Client configuration
data determines the usage of notifications or indications for data transfer from a Peripheral to Central in this
example project.
•
This function also receives data on a custom characteristic handle
HANDLE_HSENS_SERVICE_CHAR_BLINK_VAL
from the connected remote Client
. A
byte value received on this
handle determines number of LED blinks on the evaluation board.