From: Abhishek Chandra Date: Mon, 3 Sep 2018 12:35:46 +0000 (+0530) Subject: [HRP Sensor]Notify,Char changes fix X-Git-Tag: submit/tizen/20180910.002032~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=068c7a4417ff68a4f7923e17e552c8872b5ee876;p=platform%2Fcore%2Fapi%2Fbluetooth.git [HRP Sensor]Notify,Char changes fix This patch is clean up and fixing of Notify heartrate and read char for body sensor location char change , readvalue and notify fixed patches in BT framework. Change-Id: Ib5e94a241bf24dd8afb5df9c8292ab6fa5e1e65f Signed-off-by: Abhishek Chandra --- diff --git a/src/bluetooth-hrp.c b/src/bluetooth-hrp.c old mode 100644 new mode 100755 index 2639d33..e754b94 --- a/src/bluetooth-hrp.c +++ b/src/bluetooth-hrp.c @@ -89,7 +89,6 @@ typedef struct bt_hrp_server_info_s { bt_hrp_sensor_advertising_state_changed_cb adv_app_cb; //application callback for updating state changes bt_gatt_server_characteristic_notification_state_changed_cb notif_app_cb; //application callback for updating notification bt_body_sensor_location_e body_sensor_location; //body sensor location - bool cccd_enabled; GSList *hrs_collector_connected_list; //connected collector list , to be updated when read or write cccd request comes from client } bt_hrp_server_info_s; @@ -108,11 +107,22 @@ typedef struct { void *conn_cb_user_data; // char *hrs_service_handle; /* HRS Primary Service Handle */ char *dis_service_handle; /* DIS Primary Service Handle */ - bool cccd_enabled; /* TDS Control Point CCCD is enabled or not */ + bool cccd_enabled; /* CCCD is enabled or not */ bt_hrp_collector_heart_rate_value_changed_cb char_update_cb; bt_hrp_collector_bsl_read_completed_cb bsl_read_cb; } bt_hrp_collector_s; +static const char * const bsl_str_enum[] = { + "other", + "chest", + "wrist", + "finger", + "hand", + "earlobe", + "foot", +}; + + GSList *hrp_collector_list; static bt_adapter_le_scan_result_cb scan_cb; //le scan application callback static bt_hrp_collector_s *_bt_hrp_collector_find(const char *remote_address); @@ -128,6 +138,7 @@ static void __bt_hrp_sensor_read_value_requested_cb( bt_gatt_server_h server, bt_gatt_h gatt_handle, int offset, void *user_data) { + char *bsl_str_loc = g_strdup(bsl_str_enum[hrp_server_info_s.body_sensor_location]); BT_INFO("[HR] __bt_gatt_server_read_value_requested_cb"); BT_INFO("[HR] remote_address %s", remote_address); @@ -136,16 +147,14 @@ static void __bt_hrp_sensor_read_value_requested_cb( BT_INFO("[HR] gatt_handle %s", (char *)gatt_handle); BT_INFO("[HR] Offset %d", offset); -#if TODO - else { - /* Send Cached response*/ - bt_gatt_server_send_response(request_id, - BLUETOOTH_GATT_ATT_REQUEST_TYPE_READ, offset, - resp_status, char_value_1, 3 - offset); - } -#endif + /* Send Cached response*/ + bt_gatt_server_send_response(request_id, + BT_GATT_REQUEST_TYPE_READ, offset, + BT_ATT_ERROR_NONE, bsl_str_loc, strlen(bsl_str_loc)); + g_free(bsl_str_loc); + } @@ -460,7 +469,6 @@ static void _bt_hrp_sensor_client_info_free(gpointer object) static void _bt_hrp_sensor_initilize(void) { - hrp_server_info_s.is_notify_cb_set = false; hrp_server_info_s.hrp_sensor = NULL; hrp_server_info_s.hrp_service = NULL; hrp_server_info_s.dis_service = NULL; @@ -472,8 +480,6 @@ static void _bt_hrp_sensor_initilize(void) hrp_server_info_s.hrs_collector_connected_list = NULL; hrp_server_info_s.is_in_contact = true; - hrp_server_info_s.cccd_enabled = true; //by default - if (hrp_server_info_s.is_hr_value_init == false) hrp_server_info_s.hr_value = 0; @@ -498,11 +504,10 @@ void __bt_hrp_le_connection_state_changed_cb(int result, BT_INFO("[HR]IsConnected : %d", connected); BT_INFO("[HR]Remote Address : %s", remote_address); bool isappend = true; - int error_code = BT_ERROR_NOT_INITIALIZED; - /*To do Check for if it for sensor or collector */ /*If Sensor */ - if (hrp_server_info_s.hrp_sensor == NULL) { + if (hrp_server_info_s.hrp_sensor != NULL) { + BT_INFO("[HR] bt_hrp_le_connection_state_changed_cb Sensor!!"); GSList *iter = hrp_server_info_s.hrs_collector_connected_list; @@ -526,14 +531,6 @@ void __bt_hrp_le_connection_state_changed_cb(int result, g_slist_append(hrp_server_info_s.hrs_collector_connected_list, (gpointer)client_s); } - if (connected == true && hrp_server_info_s.is_notify_cb_set == false) { - error_code = bt_gatt_server_notify_characteristic_changed_value(hrp_server_info_s.hrs_characteristic, - __bt_hrp_notification_send_cb, NULL, NULL); - if (error_code != BT_ERROR_NONE) - BT_ERR("bt_gatt_server_notify_characteristic_changed_value : %s\n", _bt_convert_error_to_string(error_code)); - hrp_server_info_s.is_notify_cb_set = true; - } - } else { /*If Collector*/ bt_hrp_collector_s *collector_s = _bt_hrp_collector_find(remote_address); @@ -801,13 +798,18 @@ int bt_hrp_sensor_update_heartrate_value(int heartrate) return error_code; } - if (hrp_server_info_s.cccd_enabled) { - error_code = bt_gatt_set_int_value(hrp_server_info_s.hrs_characteristic, - BT_DATA_TYPE_UINT16, heartrate, 1); - if (error_code != BT_ERROR_NONE) { - BT_ERR("[HR]bt_gatt_set_int_value failed with [0x%04x]", error_code); - return error_code; - } + error_code = bt_gatt_set_int_value(hrp_server_info_s.hrs_characteristic, + BT_DATA_TYPE_UINT16, heartrate, 1); + if (error_code != BT_ERROR_NONE) { + BT_ERR("[HR]bt_gatt_set_int_value failed with [0x%04x]", error_code); + return error_code; + } + + error_code = bt_gatt_server_notify_characteristic_changed_value(hrp_server_info_s.hrs_characteristic, + __bt_hrp_notification_send_cb, NULL, NULL); + if (error_code != BT_ERROR_NONE) { + BT_ERR("bt_gatt_server_notify_characteristic_changed_value : %s\n", _bt_convert_error_to_string(error_code)); + return error_code; } return error_code; @@ -853,7 +855,6 @@ int bt_hrp_sensor_destroy() return error_code; } - hrp_server_info_s.is_notify_cb_set = false; hrp_server_info_s.is_hr_value_init = false; hrp_server_info_s.hr_value = 0; hrp_server_info_s.is_energy_supported = false; @@ -877,7 +878,6 @@ int bt_hrp_sensor_destroy() hrp_server_info_s.adv_app_cb = NULL; hrp_server_info_s.notif_app_cb = NULL; hrp_server_info_s.body_sensor_location = BT_BSL_NOTSUPPORTED; - hrp_server_info_s.cccd_enabled = false; g_slist_free_full(hrp_server_info_s.hrs_collector_connected_list, _bt_hrp_sensor_client_info_free); diff --git a/test/bt_unit_test.c b/test/bt_unit_test.c index 88043bd..f62b02d 100644 --- a/test/bt_unit_test.c +++ b/test/bt_unit_test.c @@ -9618,7 +9618,7 @@ int test_input_callback(void *data) } case BT_UNIT_TEST_FUNCTION_HR_SENSOR_NOTIFY: { TC_PRT("HR SENSOR UPDATE HR value\n"); - bt_hrp_sensor_update_heartrate_value(7); + bt_hrp_sensor_update_heartrate_value(60 + (rand()%60)); break; } case BT_UNIT_TEST_FUNCTION_HR_SENSOR_DESTORY: {