Skip to content

Commit 4a1fef8

Browse files
sondrepasilz
andcommitted
bluetooth: services: ble_hrs_client: add bsl event
Add body sensor location event. Signed-off-by: Sondre Pettersen <sondre.pettersen@nordicsemi.no> Co-authored-by: Asil Zogby <asil.zogby@nordicsemi.no>
1 parent 18e59b5 commit 4a1fef8

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

include/bm/bluetooth/services/ble_hrs_client.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ enum ble_hrs_client_evt_type {
5656
* received from the peer.
5757
*/
5858
BLE_HRS_CLIENT_EVT_HRM_NOTIFICATION,
59+
/** Event indicating that the Body Sensor Location characteristic was received from the peer */
60+
BLE_HRS_CLIENT_EVT_BSL_UPDATE,
5961
/** Error. */
6062
BLE_HRS_CLIENT_EVT_ERROR,
6163
};
@@ -80,6 +82,8 @@ struct ble_hrs_handles {
8082
uint16_t hrm_cccd_handle;
8183
/** Handle of the Heart Rate Measurement characteristic, as provided by the SoftDevice. */
8284
uint16_t hrm_handle;
85+
/** Handle of the Body Sensor Location characteristic, as provided by the SoftDevice */
86+
uint16_t bsl_handle;
8387
};
8488

8589
/**
@@ -98,6 +102,8 @@ struct ble_hrs_client_evt {
98102
} discovery_complete;
99103
/** @ref BLE_HRS_CLIENT_EVT_HRM_NOTIFICATION event data. */
100104
struct ble_hrs_measurement hrm_notification;
105+
/** @ref BLE_HRS_CLIENT_EVT_BSL_UPDATE event data. */
106+
uint8_t body_sensor_location;
101107
/** @ref BLE_HRS_CLIENT_EVT_ERROR event data. */
102108
struct {
103109
/** Error reason */

subsys/bluetooth/services/ble_hrs_client/ble_hrs_client.c

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ static void on_disconnected(struct ble_hrs_client *hrs_client, const ble_evt_t *
119119
hrs_client->conn_handle = BLE_CONN_HANDLE_INVALID;
120120
hrs_client->handles.hrm_cccd_handle = BLE_GATT_HANDLE_INVALID;
121121
hrs_client->handles.hrm_handle = BLE_GATT_HANDLE_INVALID;
122+
hrs_client->handles.bsl_handle = BLE_GATT_HANDLE_INVALID;
122123
}
123124
}
124125

@@ -152,7 +153,12 @@ void ble_hrs_on_db_disc_evt(struct ble_hrs_client *hrs_client,
152153
db_char->cccd_handle;
153154
hrs_client_evt.discovery_complete.handles.hrm_handle =
154155
db_char->characteristic.handle_value;
155-
break;
156+
} else if (db_char->characteristic.uuid.uuid ==
157+
BLE_UUID_BODY_SENSOR_LOCATION_CHAR) {
158+
hrs_client_evt.discovery_complete.handles.bsl_handle =
159+
db_char->characteristic.handle_value;
160+
sd_ble_gattc_read(db_discovery_evt->conn_handle,
161+
db_char->characteristic.handle_value, 0);
156162
}
157163
}
158164

@@ -194,18 +200,52 @@ uint32_t ble_hrs_client_init(struct ble_hrs_client *hrs_client,
194200
return ble_db_discovery_service_register(hrs_client_config->db_discovery, &hrs_uuid);
195201
}
196202

203+
static void on_read_rsp(struct ble_hrs_client *hrs_client, const ble_evt_t *ble_evt)
204+
{
205+
const ble_gattc_evt_read_rsp_t *read_rsp = &ble_evt->evt.gattc_evt.params.read_rsp;
206+
struct ble_hrs_client_evt evt = {
207+
.conn_handle = ble_evt->evt.gattc_evt.conn_handle,
208+
.evt_type = BLE_HRS_CLIENT_EVT_BSL_UPDATE,
209+
.body_sensor_location = ble_evt->evt.gattc_evt.params.read_rsp.data[0],
210+
};
211+
212+
if (hrs_client->conn_handle != ble_evt->evt.gattc_evt.conn_handle) {
213+
return;
214+
}
215+
216+
/* Check if this is a body sensor location response. */
217+
if (read_rsp->handle != hrs_client->handles.bsl_handle) {
218+
return;
219+
}
220+
221+
if (read_rsp->len < 1) {
222+
return;
223+
}
224+
225+
hrs_client->evt_handler(hrs_client, &evt);
226+
}
227+
197228
void ble_hrs_client_on_ble_evt(const ble_evt_t *ble_evt, void *hrs_client)
198229
{
199230
__ASSERT(ble_evt, "BLE event is NULL");
200231
__ASSERT(hrs_client, "HRS central instance is NULL");
201232

233+
if (ble_evt->header.evt_id >= BLE_GAP_EVT_BASE &&
234+
ble_evt->header.evt_id <= BLE_GAP_EVT_LAST &&
235+
ble_evt->evt.gap_evt.params.connected.role != BLE_GAP_ROLE_CENTRAL) {
236+
return;
237+
}
238+
202239
switch (ble_evt->header.evt_id) {
203240
case BLE_GATTC_EVT_HVX:
204241
on_hvx(hrs_client, ble_evt);
205242
break;
206243
case BLE_GAP_EVT_DISCONNECTED:
207244
on_disconnected(hrs_client, ble_evt);
208245
break;
246+
case BLE_GATTC_EVT_READ_RSP:
247+
on_read_rsp(hrs_client, ble_evt);
248+
break;
209249
default:
210250
break;
211251
}

0 commit comments

Comments
 (0)