@@ -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+
197228void 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