![Cypress EZ-BT WICED CYBT-343026-01 Скачать руководство пользователя страница 37](http://html1.mh-extra.com/html/cypress/ez-bt-wiced-cybt-343026-01/ez-bt-wiced-cybt-343026-01_getting-started_2705923037.webp)
Getting Started with EZ-BT WICED Modules
Document Number: 002-23400 Rev. **
37
Code 24. BLE GATT Write Request
wiced_bt_gatt_status_t
hello_sensor_gatts_req_write_handler
(
uint16_t
conn_id,
wiced_bt_gatt_write_t
*
p_data )
{
wiced_bt_gatt_status_t
result =
WICED_BT_GATT_SUCCESS
;
uint8_t
*p_attr = p_data->
p_val
;
uint8_t
nv_update = WICED_FALSE;
WICED_BT_TRACE(
"write_handler: conn_id:%d hdl:0x%x prep:%d offset:%d len:%d\n "
, conn_id, p_data-
>
handle
, p_data->
is_prep
, p_data->
offset
, p_data->
val_len
);
switch
( p_data->
handle
)
{
/* By writing into Characteristic Client Configuration descriptor
* peer can enable or disable notification or indication */
case
HANDLE_HSENS_SERVICE_CHAR_CFG_DESC:
if
( p_data->
val_len
!= 2 )
{
return
WICED_BT_GATT_INVALID_ATTR_LEN
;
}
hello_sensor_hostinfo.
characteristic_client_configuration
= p_attr[0] | ( p_attr[1] << 8 );
nv_update = WICED_TRUE;
break
;
case
HANDLE_HSENS_SERVICE_CHAR_BLINK_VAL:
if
( p_data->
val_len
!= 1 )
{
return
WICED_BT_GATT_INVALID_ATTR_LEN
;
}
hello_sensor_hostinfo.
number_of_blinks
= p_attr[0];
if
( hello_sensor_hostinfo.
number_of_blinks
!= 0 )
{
WICED_BT_TRACE(
"hello_sensor_write_handler:num blinks: %d\n"
,
hello_sensor_hostinfo.
number_of_blinks
);
wiced_bt_app_hal_led_blink(
WICED_PLATFORM_LED_1
, 250, 250,
hello_sensor_hostinfo.
number_of_blinks
);
nv_update = WICED_TRUE;
}
break
;
default
:
result =
WICED_BT_GATT_INVALID_HANDLE
;
break
;
}
if
( nv_update )
{
wiced_result_t
rc;
int
bytes_written = wiced_hal_write_nvram( HELLO_SENSOR_VS_ID,
sizeof
(hello_sensor_hostinfo),
(
uint8_t
*)&hello_sensor_hostinfo, &rc );
WICED_BT_TRACE(
"NVRAM write:%d rc:%d"
, bytes_written, rc);
}
return
result;
}
7.4.3.3
Indication Confirmation
If the Client chooses indications instead of notifications, which is determined by the Client configuration data received
as part of the GATT write request from the Client shown in
, the Peripheral should wait for confirmation before
sending the next indication.
Code 25. BLE Indication Confirmation
wiced_bt_gatt_status_t
hello_sensor_gatts_req_conf_handler
(
uint16_t
conn_id,
uint16_t
handle )
{
WICED_BT_TRACE(
"hello_sensor_indication_cfm, conn %d hdl %d\n"
, conn_id, handle );
if
( !hello_sensor_state.
flag_indication_sent
)
{
WICED_BT_TRACE(
"Hello: Wrong Confirmation!"
);
return
WICED_BT_GATT_SUCCESS
;
}