@@ -119,6 +119,8 @@ 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_cccd_handle = BLE_GATT_HANDLE_INVALID ;
123+ hrs_client -> handles .bsl_handle = BLE_GATT_HANDLE_INVALID ;
122124 }
123125}
124126
@@ -152,7 +154,16 @@ void ble_hrs_on_db_disc_evt(struct ble_hrs_client *hrs_client,
152154 db_char -> cccd_handle ;
153155 hrs_client_evt .discovery_complete .handles .hrm_handle =
154156 db_char -> characteristic .handle_value ;
155- break ;
157+ }
158+ else if (db_char -> characteristic .uuid .uuid == BLE_UUID_BODY_SENSOR_LOCATION_CHAR ) {
159+ hrs_client_evt .discovery_complete .handles .bsl_cccd_handle = db_char -> cccd_handle ;
160+ hrs_client_evt .discovery_complete .handles .bsl_handle = db_char -> characteristic .handle_value ;
161+ ble_gatts_value_t val = {
162+ .p_value = & hrs_client_evt .discovery_complete .body_sensor_location ,
163+ .len = sizeof (hrs_client_evt .discovery_complete .body_sensor_location ),
164+ };
165+ //LOG_INF("sd_ble_gatts_value_get returned %#x, location = %u" ,sd_ble_gatts_value_get(db_discovery_evt->conn_handle, db_char->characteristic.handle_value, &val), hrs_client_evt.discovery_complete.body_sensor_location);
166+ sd_ble_gattc_read (db_discovery_evt -> conn_handle , db_char -> characteristic .handle_value , 0 );
156167 }
157168 }
158169
@@ -194,6 +205,27 @@ uint32_t ble_hrs_client_init(struct ble_hrs_client *hrs_client,
194205 return ble_db_discovery_service_register (hrs_client_config -> db_discovery , & hrs_uuid );
195206}
196207
208+ static void on_read_rsp (struct ble_hrs_client * hrs_client , const ble_evt_t * ble_evt ) {
209+
210+ const ble_gattc_evt_read_rsp_t * read_rsp = & ble_evt -> evt .gattc_evt .params .read_rsp ;
211+ struct ble_hrs_client_evt evt = {.conn_handle = ble_evt -> evt .gattc_evt .conn_handle , .evt_type = BLE_HRS_CLIENT_EVT_BSL_UPDATE , .body_sensor_location = ble_evt -> evt .gattc_evt .params .read_rsp .data [0 ]};
212+
213+ if (hrs_client -> conn_handle != ble_evt -> evt .gattc_evt .conn_handle ) {
214+ return ;
215+ }
216+
217+ /* Check if this is a heart rate notification. */
218+ if (read_rsp -> handle != hrs_client -> handles .bsl_handle ) {
219+ return ;
220+ }
221+
222+ if (read_rsp -> len < 1 ) {
223+ return ;
224+ }
225+
226+ hrs_client -> evt_handler (hrs_client , & evt );
227+ }
228+
197229void ble_hrs_client_on_ble_evt (const ble_evt_t * ble_evt , void * hrs_client )
198230{
199231 __ASSERT (ble_evt , "BLE event is NULL" );
@@ -204,8 +236,15 @@ void ble_hrs_client_on_ble_evt(const ble_evt_t *ble_evt, void *hrs_client)
204236 on_hvx (hrs_client , ble_evt );
205237 break ;
206238 case BLE_GAP_EVT_DISCONNECTED :
239+ const ble_gap_evt_t * gap_evt = & ble_evt -> evt .gap_evt ;
240+ if (gap_evt -> params .connected .role != BLE_GAP_ROLE_CENTRAL ){
241+ return ;
242+ }
207243 on_disconnected (hrs_client , ble_evt );
208244 break ;
245+ case BLE_GATTC_EVT_READ_RSP :
246+ on_read_rsp (hrs_client , ble_evt );
247+ break ;
209248 default :
210249 break ;
211250 }
0 commit comments