From ca36ca950b5a3e06a4f57d1502ffbc680e6c5c5d Mon Sep 17 00:00:00 2001 From: Taejin Woo Date: Wed, 23 Sep 2015 21:32:29 +0900 Subject: [PATCH] Fix the jira issue about bluetooth tutorial : TNEF-5539, TNEF-5540, TNEF-5447, TNEF-5446 Change-Id: I631d6386d74e921088c3265ecec507c39b729556 Signed-off-by: Taejin Woo --- .../html/native/network/bluetooth_tutorial_n.htm | 440 ++++++++------------- 1 file changed, 164 insertions(+), 276 deletions(-) diff --git a/org.tizen.tutorials/html/native/network/bluetooth_tutorial_n.htm b/org.tizen.tutorials/html/native/network/bluetooth_tutorial_n.htm index b0c7c50..7fe7293 100644 --- a/org.tizen.tutorials/html/native/network/bluetooth_tutorial_n.htm +++ b/org.tizen.tutorials/html/native/network/bluetooth_tutorial_n.htm @@ -871,7 +871,7 @@ break;
 int ret = 0;
 
-ret = bt_gatt_client_foreach_services(client, __bt_gatt_client_foreach_svc_cb, (void *)test_id);
+ret = bt_gatt_client_foreach_services(client, __bt_gatt_client_foreach_svc_cb, NULL);
 if (ret != BT_ERROR_NONE) 
 {
    dlog_print(DLOG_INFO, LOG_TAG, "fail");
@@ -884,7 +884,6 @@ break;
 bool 
 __bt_gatt_client_foreach_svc_cb(int total, int index, bt_gatt_h svc_handle, void *data)
 {
-   int test_id = (int)data;
    int ret;
    char *uuid = NULL;
 
@@ -892,18 +891,14 @@ __bt_gatt_client_foreach_svc_cb(int total, int index, bt_gatt_h svc_handle, void
    dlog_print(DLOG_INFO, LOG_TAG, "[%d / %d] uuid : (%s)", index, total, uuid);
 
    g_free(uuid);
-
-   if (test_id == BT_UNIT_TEST_FUNCTION_GATT_CLIENT_PRINT_ALL) 
+   ret = bt_gatt_service_foreach_characteristics(svc_handle,
+                                                __bt_gatt_client_foreach_chr_cb, 
+                                                 NULL);
+   if (ret != BT_ERROR_NONE)
    {
-      ret = bt_gatt_service_foreach_characteristics(svc_handle,
-                                                    __bt_gatt_client_foreach_chr_cb, 
-                                                    (void *)test_id);
-      if (ret != BT_ERROR_NONE) 
-      {
-         dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_service_foreach_characteristics is failed : %d", ret);
-      }
-      return true;
+      dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_service_foreach_characteristics is failed : %d", ret);
    }
+   return true;
 }
 
@@ -918,7 +913,6 @@ __bt_gatt_client_foreach_chr_cb(int total, int index, bt_gatt_h chr_handle, void    bt_gatt_get_uuid(chr_handle, &uuid);    dlog_print(DLOG_INFO, LOG_TAG, "\t[%d / %d] uuid : (%s)", index, total, uuid); -   __bt_gatt_client_print_value(chr_handle);    g_free(uuid); @@ -941,7 +935,6 @@ __bt_gatt_client_foreach_desc_cb(int total, int index, bt_gatt_h desc_handle, vo    bt_gatt_get_uuid(desc_handle, &uuid);    dlog_print(DLOG_INFO, LOG_TAG, "\t\t[%d / %d] uuid : (%s)", index, total, uuid); -   __bt_gatt_client_print_value(desc_handle);    g_free(uuid); @@ -953,64 +946,46 @@ __bt_gatt_client_foreach_desc_cb(int total, int index, bt_gatt_h desc_handle, vo
  • Read the value of the given attribute handle:
    -{
    -   char *svc_uuid = NULL;
    -   char *chr_uuid = NULL;
    -   char *desc_uuid = NULL;
    -   bt_gatt_h svc = NULL;
    -   bt_gatt_h chr = NULL;
    -   bt_gatt_h desc = NULL;
    -
    -   if (g_test_param.param_count < 2) 
    -   {
    -      dlog_print(DLOG_INFO, LOG_TAG, "Input parameters first");
    -      break;
    -   }
    -
    -   svc_uuid = g_test_param.params[0];
    -   chr_uuid = g_test_param.params[1];
    -
    -   ret = bt_gatt_client_get_service(client, svc_uuid, &svc);
    -   if (ret != BT_ERROR_NONE) 
    -   {
    -      dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_client_get_service is failed : %d", ret);
    -      __bt_free_test_param(&g_test_param);
    -      break;
    -   }
    -
    -   ret = bt_gatt_service_get_characteristic(svc, chr_uuid, &chr);
    -   if (ret != BT_ERROR_NONE) 
    -   {
    -      dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_service_get_characteristic is failed : %d", ret);
    -      __bt_free_test_param(&g_test_param);
    -      break;
    -   }
    -
    -   if (g_test_param.param_count > 2) 
    -   {
    -      desc_uuid = g_test_param.params[2];
    -      ret = bt_gatt_characteristic_get_descriptor(chr, desc_uuid, &desc);
    -      if (ret != BT_ERROR_NONE) 
    -      {
    -         dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_characteristic_get_descriptor is failed : %d", ret);
    -         __bt_free_test_param(&g_test_param);
    -         break;
    -      }
    -      ret = bt_gatt_client_read_value(desc,
    -                                       __bt_gatt_client_read_complete_cb, NULL);
    -   } 
    -   else 
    -   {
    -      ret = bt_gatt_client_read_value(chr,
    -                                       __bt_gatt_client_read_complete_cb, NULL);
    -   }
    -
    -   if (ret != BT_ERROR_NONE) 
    -   {
    -      dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_client_read_value is failed : %d", ret);
    -   }
    -   __bt_free_test_param(&g_test_param);
    -}
    +  char *svc_uuid = "0000180f-0000-1000-8000-00805f9b34fb"; /* Battery Service */
    +  char *chr_uuid = "00002a19-0000-1000-8000-00805f9b34fb"; /* Battery Level */
    +  char *desc_uuid = "00002902-0000-1000-8000-00805f9b34fb"; /* Client Characteristic Configuration */
    +  bt_gatt_h svc = NULL;
    +  bt_gatt_h chr = NULL;
    +  bt_gatt_h desc = NULL;
    +
    +  ret = bt_gatt_client_get_service(client, svc_uuid, &svc);
    +  if (ret != BT_ERROR_NONE)
    +  {
    +     dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_client_get_service is failed : %d", ret);
    +     break;
    +  }
    +
    +  ret = bt_gatt_service_get_characteristic(svc, chr_uuid, &chr);
    +  if (ret != BT_ERROR_NONE)
    +  {
    +     dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_service_get_characteristic is failed : %d", ret);
    +     break;
    +  }
    +
    +     ret = bt_gatt_characteristic_get_descriptor(chr, desc_uuid, &desc);
    +     if (ret != BT_ERROR_NONE)
    +     {
    +        dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_characteristic_get_descriptor is failed : %d", ret);
    +        break;
    +     }
    +     ret = bt_gatt_client_read_value(desc,
    +                                      __bt_gatt_client_read_complete_cb, NULL);
    +  }
    +  else
    +  {
    +     ret = bt_gatt_client_read_value(chr,
    +                                      __bt_gatt_client_read_complete_cb, NULL);
    +  }
    +
    +  if (ret != BT_ERROR_NONE)
    +  {
    +     dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_client_read_value is failed : %d", ret);
    +  }
     

    After the reading operation is complete, use the bt_gatt_client_read_complete_cb() callback to handle values:

    @@ -1027,10 +1002,8 @@ __bt_gatt_client_read_complete_cb(int result, bt_gatt_h gatt_handle, void *data)
        g_free(uuid);
     
        if (result != BT_ERROR_NONE)
    -
           return;
     
    -   __bt_gatt_client_print_value(gatt_handle);
     
        return;
     }
    @@ -1039,28 +1012,17 @@ __bt_gatt_client_read_complete_cb(int result, bt_gatt_h gatt_handle, void *data)
     
  • Set a value for the given attribute handle:
    -{
    -   char *svc_uuid = NULL;
    -   char *chr_uuid = NULL;
    -   char *desc_uuid = NULL;
    +   char *svc_uuid = "0000180f-0000-1000-8000-00805f9b34fb"; /* Battery Service */
    +   char *chr_uuid = "00002a19-0000-1000-8000-00805f9b34fb"; /* Battery Level */
    +   char *desc_uuid = "00002902-0000-1000-8000-00805f9b34fb"; /* Client Characteristic Configuration */
        bt_gatt_h svc = NULL;
        bt_gatt_h chr = NULL;
        bt_gatt_h desc = NULL;
     
    -   if (g_test_param.param_count < 2) 
    -   {
    -      dlog_print(DLOG_INFO, LOG_TAG, "Input parameters first");
    -      break;
    -   }
    -
    -   svc_uuid = g_test_param.params[0];
    -   chr_uuid = g_test_param.params[1];
    -
        ret = bt_gatt_client_get_service(client, svc_uuid, &svc);
        if (ret != BT_ERROR_NONE) 
        {
           dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_client_get_service is failed : %d", ret);
    -      __bt_free_test_param(&g_test_param);
        break;
        }
     
    @@ -1068,27 +1030,21 @@ __bt_gatt_client_read_complete_cb(int result, bt_gatt_h gatt_handle, void *data)
        if (ret != BT_ERROR_NONE) 
        {
           dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_service_get_characteristic is failed : %d", ret);
    -      __bt_free_test_param(&g_test_param);
           break;
        }
     
    -   if (g_test_param.param_count > 2) 
    -   {
    -      desc_uuid = g_test_param.params[2];
           ret = bt_gatt_characteristic_get_descriptor(chr, desc_uuid, &desc);
           if (ret != BT_ERROR_NONE) 
           {
              dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_characteristic_get_descriptor is failed : %d", ret);
    -         __bt_free_test_param(&g_test_param);
              break;
           }
     
    -      ret = __bt_gatt_client_set_value(g_test_param.params[3],
    -                                       g_test_param.params[4], desc);
    +      ret = __bt_gatt_client_set_value("int32",
    +                                       "1234", desc);
           if (ret != BT_ERROR_NONE) 
           {
              dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_set_value is failed : %d", ret);
    -         __bt_free_test_param(&g_test_param);
              break;
           }
     
    @@ -1097,12 +1053,11 @@ __bt_gatt_client_read_complete_cb(int result, bt_gatt_h gatt_handle, void *data)
        } 
        else 
        {
    -      ret = __bt_gatt_client_set_value(g_test_param.params[2], 
    -                                       g_test_param.params[3], chr);
    +      ret = __bt_gatt_client_set_value(desc_uuid, 
    +                                       "int32", chr);
           if (ret != BT_ERROR_NONE) 
           {
              dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_set_value is failed : %d", ret);
    -         __bt_free_test_param(&g_test_param);
              break;
           }
     
    @@ -1114,8 +1069,6 @@ __bt_gatt_client_read_complete_cb(int result, bt_gatt_h gatt_handle, void *data)
        {
           dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_client_write_value is failed : %d", ret);
        }
    -   __bt_free_test_param(&g_test_param);
    -}
     

    After the writing operation is complete, use the bt_gatt_client_write_complete_cb() callback to finish the task:

    @@ -1138,26 +1091,15 @@ __bt_gatt_client_write_complete_cb(int result, bt_gatt_h gatt_handle, void *data
     
  • Register a callback function to be invoked when the characteristic value changes on the remote device:
    -{
    -   char *svc_uuid = NULL;
    -   char *chr_uuid = NULL;
    +   char *svc_uuid = "0000180f-0000-1000-8000-00805f9b34fb";
    +   char *chr_uuid = "00002a19-0000-1000-8000-00805f9b34fb";
        bt_gatt_h svc = NULL;
        bt_gatt_h chr = NULL;
     
    -   if (g_test_param.param_count < 2)
    -   {
    -      dlog_print(DLOG_INFO, LOG_TAG, "Input parameters first");
    -      break;
    -   }
    -
    -   svc_uuid = g_test_param.params[0];
    -   chr_uuid = g_test_param.params[1];
    -
        ret = bt_gatt_client_get_service(client, svc_uuid, &svc);
        if (ret != BT_ERROR_NONE)
        {
           dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_client_get_service is failed : %d", ret);
    -      __bt_free_test_param(&g_test_param);
           break;
        }
     
    @@ -1165,7 +1107,6 @@ __bt_gatt_client_write_complete_cb(int result, bt_gatt_h gatt_handle, void *data
        if (ret != BT_ERROR_NONE)
        {
           dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_service_get_characteristic is failed : %d", ret);
    -      __bt_free_test_param(&g_test_param);
           break;
        }
     
    @@ -1173,9 +1114,7 @@ __bt_gatt_client_write_complete_cb(int result, bt_gatt_h gatt_handle, void *data
        if (ret != BT_ERROR_NONE)
        {
           dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_client_set_characteristic_value_changed_cb is failed : %d", ret);
    -      __bt_free_test_param(&g_test_param);
        }
    -}
     

    After registering the callback operation, use the __bt_gatt_client_value_changed_cb() callback to display the changed value:

    @@ -1204,25 +1143,15 @@ __bt_gatt_client_value_changed_cb(bt_gatt_h chr, char *value, int len, void *use
     
     
     {
    -   char *svc_uuid = NULL;
    -   char *chr_uuid = NULL;
    +   char *svc_uuid = "0000180f-0000-1000-8000-00805f9b34fb"; /* Battery Service */
    +   char *chr_uuid = "00002a19-0000-1000-8000-00805f9b34fb"; /* Battery Level */
        bt_gatt_h svc = NULL;
        bt_gatt_h chr = NULL;
     
    -   if (g_test_param.param_count < 2)
    -   {
    -      dlog_print(DLOG_INFO, LOG_TAG, "Input parameters first");
    -      break;
    -   }
    -
    -   svc_uuid = g_test_param.params[0];
    -   chr_uuid = g_test_param.params[1];
    -
        ret = bt_gatt_client_get_service(client, svc_uuid, &svc);
        if (ret != BT_ERROR_NONE)
        {
           dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_client_get_service is failed : %d", ret);
    -      __bt_free_test_param(&g_test_param);
           break;
        }
     
    @@ -1230,7 +1159,6 @@ __bt_gatt_client_value_changed_cb(bt_gatt_h chr, char *value, int len, void *use
        if (ret != BT_ERROR_NONE)
        {
           dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_service_get_characteristic is failed : %d", ret);
    -      __bt_free_test_param(&g_test_param);
           break;
        }
     
    @@ -1238,7 +1166,6 @@ __bt_gatt_client_value_changed_cb(bt_gatt_h chr, char *value, int len, void *use
        if (ret != BT_ERROR_NONE)
        {
           dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_client_unset_characteristic_value_changed_cb is failed : %d", ret);
    -      __bt_free_test_param(&g_test_param);
        }
     }
     
    @@ -1263,7 +1190,6 @@ break;
    • Get the type of a service, characteristic, or descriptor handle:
      -{
          int ret = 0;
          bt_gatt_h gatt_handle = NULL;
          bt_gatt_type_e gatt_type;
      @@ -1275,12 +1201,10 @@ break;
          {
             dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_get_type is failed : %d", ret);
          }
      -}
       
    • Get the UUID of a service, characteristic, or descriptor handle:
      -{
          int ret = 0;
          bt_gatt_h gatt_handle = NULL;
          char *uuid = NULL;
      @@ -1292,12 +1216,10 @@ break;
          {
             dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_get_uuid is failed : %d", ret);
          }
      -}
       
    • Get the value of a characteristic or descriptor handle:
      -{
          int ret = 0;
          int len = 0;
          bt_gatt_h gatt_handle = NULL;
      @@ -1310,15 +1232,13 @@ break;
          {
             dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_get_value is failed : %d", ret);
          }
      -}
       
    • Get the value of a characteristic or descriptor handle as an integer type:
      -{
          int ret = 0;
          int offset = 0;
      -   bt_data_type_int_e type,;
      +   bt_data_type_int_e type;
          bt_gatt_h gatt_handle = NULL;
          int value;
       
      @@ -1329,15 +1249,13 @@ break;
          {
             dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_get_int_value is failed : %d", ret);
          }
      -}
       
    • Get the value of a characteristic or descriptor handle as a float type:
      -{
          int ret = 0;
          int offset = 0;
      -   bt_data_type_float_e type,;
      +   bt_data_type_float_e type;
          bt_gatt_h gatt_handle = NULL;
          float value;
       
      @@ -1348,54 +1266,31 @@ break;
          {
             dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_get_float_value is failed : %d", ret);
          }
      -}
       
    • Get a service handle with a specific UUID:
      -{
      -   char *svc_uuid = NULL;
      +   char *svc_uuid = "0000180f-0000-1000-8000-00805f9b34fb"; /* Battery Service */
          bt_gatt_h svc = NULL;
       
      -   if (g_test_param.param_count < 2)
      -   {
      -      dlog_print(DLOG_INFO, LOG_TAG, "Input parameters first");
      -      break;
      -   }
      -
      -   svc_uuid = g_test_param.params[0];
      -
          ret = bt_gatt_client_get_service(client, svc_uuid, &svc);
          if (ret != BT_ERROR_NONE)
          {
             dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_client_get_service is failed : %d", ret);
      -      __bt_free_test_param(&g_test_param);
          }
      -}
       
    • Get a characteristic handle with a specific UUID:
      -{
      -   char *svc_uuid = NULL;
      -   char *chr_uuid = NULL;
      +   char *svc_uuid = "0000180f-0000-1000-8000-00805f9b34fb"; /* Battery Service */
      +   char *chr_uuid = "00002a19-0000-1000-8000-00805f9b34fb"; /* Battery Level */
          bt_gatt_h svc = NULL;
          bt_gatt_h chr = NULL;
       
      -   if (g_test_param.param_count < 2)
      -   {
      -      dlog_print(DLOG_INFO, LOG_TAG, "Input parameters first");
      -      break;
      -   }
      -
      -   svc_uuid = g_test_param.params[0];
      -   chr_uuid = g_test_param.params[1];
      -
          ret = bt_gatt_client_get_service(client, svc_uuid, &svc);
          if (ret != BT_ERROR_NONE)
          {
             dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_client_get_service is failed : %d", ret);
      -      __bt_free_test_param(&g_test_param);
             break;
          }
       
      @@ -1403,35 +1298,22 @@ break;
          if (ret != BT_ERROR_NONE)
          {
             dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_service_get_characteristic is failed : %d", ret);
      -      __bt_free_test_param(&g_test_param);
          }
      -}
       
    • Get a descriptor handle with a specific UUID:
      -{
      -   char *svc_uuid = NULL;
      -   char *chr_uuid = NULL;
      -   char *desc_uuid = NULL;
      +   char *svc_uuid = "0000180f-0000-1000-8000-00805f9b34fb"; /* Battery Service */
      +   char *chr_uuid = "00002a19-0000-1000-8000-00805f9b34fb"; /* Battery Level */
      +   char *desc_uuid = "00002902-0000-1000-8000-00805f9b34fb"; /* Client Characteristic Configuration */
          bt_gatt_h svc = NULL;
          bt_gatt_h chr = NULL;
          bt_gatt_h desc = NULL;
       
      -   if (g_test_param.param_count < 2)
      -   {
      -      dlog_print(DLOG_INFO, LOG_TAG, "Input parameters first");
      -      break;
      -   }
      -
      -   svc_uuid = g_test_param.params[0];
      -   chr_uuid = g_test_param.params[1];
      -
          ret = bt_gatt_client_get_service(client, svc_uuid, &svc);
          if (ret != BT_ERROR_NONE)
          {
             dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_client_get_service is failed : %d", ret);
      -      __bt_free_test_param(&g_test_param);
             break;
          }
       
      @@ -1439,25 +1321,18 @@ break;
          if (ret != BT_ERROR_NONE)
          {
             dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_service_get_characteristic is failed : %d", ret);
      -      __bt_free_test_param(&g_test_param);
             break;
          }
       
      -   if (g_test_param.param_count > 2)
      +   ret = bt_gatt_characteristic_get_descriptor(chr, desc_uuid, &desc);
      +   if (ret != BT_ERROR_NONE)
          {
      -      desc_uuid = g_test_param.params[2];
      -      ret = bt_gatt_characteristic_get_descriptor(chr, desc_uuid, &desc);
      -      if (ret != BT_ERROR_NONE)
      -      {
      -         dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_characteristic_get_descriptor is failed : %d", ret);
      -         __bt_free_test_param(&g_test_param);
      -      }
      -}
      +      dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_characteristic_get_descriptor is failed : %d", ret);
      +   }
       
    • Get the properties using the characteristic handle:
      -{
          bt_gatt_h chr = NULL;
          int properties;
       
      @@ -1468,12 +1343,10 @@ break;
          {
             dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_characteristic_get_properties is failed : %d", ret);
          }
      -}
       
    • Get the service handle to which the specified characteristic belongs:
      -{
          bt_gatt_h svc = NULL;
          bt_gatt_h chr = NULL;
          // chr = Assuming characteristic handle is already available
      @@ -1483,12 +1356,10 @@ break;
          {
             dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_characteristic_get_service is failed : %d", ret);
          }
      -}
       
    • Get the characteristic handle to which the specified descriptor belongs:
      -{
          bt_gatt_h chr = NULL;
          bt_gatt_h dsc = NULL;
          // dsc = Assuming descriptor handle is already available
      @@ -1498,12 +1369,10 @@ break;
          {
             dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_descriptor_get_characteristic is failed : %d", ret);
          }
      -}
       
    • Get the client handle to which the specified service belongs:
      -{
          bt_gatt_h svc = NULL;
          bt_gatt_client_h client = NULL;
          // svc = Assuming service handle is already available
      @@ -1513,12 +1382,10 @@ break;
          {
             dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_service_get_client is failed : %d", ret);
          }
      -}
       
    • Get the write type of the specified characteristic:
      -{
          bt_gatt_h chr = NULL;
          bt_gatt_write_type_e write_type = NULL;
          // svc = Assuming characteristic handle is already available
      @@ -1528,12 +1395,10 @@ break;
          {
             dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_characteristic_get_write_type is failed : %d", ret);
          }
      -}
       
    • Get an included service's handle with a specific UUID:
      -{
          bt_gatt_h svc = NULL;
          bt_gatt_h included_svc = NULL;
          char *uuid = NULL;
      @@ -1545,7 +1410,6 @@ break;
          {
             dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_service_get_included_service is failed : %d", ret);
          }
      -}
       
    @@ -1561,6 +1425,7 @@ break;
     int ret = 0;
     char char_value[1] = {1 + (rand()%100)};
    +bt_gatt_h characteristic_handle = NULL;
     
     // For client, the characteristic handle is retrieved from the client created using gatt_client_create()
     // by using bt_gatt_service_get_characteristic()
    @@ -1574,6 +1439,7 @@ if (ret == BT_ERROR_NONE)
     
     int ret = 0;
     int char_value = 60 + (rand()%60);
    +bt_gatt_h characteristic_handle = NULL;
     
     // For client, the characteristic handle is retrieved from the client created using gatt_client_create()
     // by using bt_gatt_service_get_characteristic()
    @@ -1586,6 +1452,7 @@ if (ret == BT_ERROR_NONE)
     
  • Set or update the characteristic value (float type value):
     int ret = 0;
    +bt_gatt_h characteristic_handle = NULL;
     
     // For client, the characteristic handle is retrieved from the client created using gatt_client_create()
     // by using bt_gatt_service_get_characteristic()
    @@ -1598,37 +1465,43 @@ if (ret == BT_ERROR_NONE)
     
     
  • Set the characteristic write type:
    -int ret = 0;
    -bt_gatt_h svc = NULL;
    -bt_gatt_h control_point = NULL;
    -char *svc_uuid = "000018f2-0000-1000-8000-00805f9b34fb";
    -char *chr_uuid = "00002af6-0000-1000-8000-00805f9b34fb";
    +void __write_completed_cb(int result, bt_gatt_h request_handle, void *user_data)
    +{
     
    -ret = bt_gatt_client_get_service(client, svc_uuid, &ancs_svc);
    -if (ret == BT_ERROR_NONE)
    -   dlog_print(DLOG_INFO, LOG_TAG, "Success");
    +}
     
    -ret = bt_gatt_service_get_characteristic(svc, chr_uuid, &control_point);
    -if (ret == BT_ERROR_NONE)
    -   dlog_print(DLOG_INFO, LOG_TAG, "Success");
    +int main()
    +{
    +    int ret = 0;
    +    bt_gatt_h svc = NULL;
    +    bt_gatt_h battery_svc = NULL;
    +    bt_gatt_h control_point = NULL;
    +    char *svc_uuid = "0000180f-0000-1000-8000-00805f9b34fb"; /* Battery Service */
    +    char *chr_uuid = "00002a19-0000-1000-8000-00805f9b34fb"; /* Battery Level */
     
    -ret = bt_gatt_characteristic_set_write_type(control_point,
    -                                            BT_GATT_WRITE_TYPE_WRITE);
    -if (ret == BT_ERROR_NONE)
    -   dlog_print(DLOG_INFO, LOG_TAG, "Success");
    +    ret = bt_gatt_client_get_service(client, svc_uuid, &battery_svc);
    +    if (ret == BT_ERROR_NONE)
    +       dlog_print(DLOG_INFO, LOG_TAG, "Success");
     
    -ret = bt_gatt_set_value(control_point, value, len);
    -if (ret == BT_ERROR_NONE)
    -   dlog_print(DLOG_INFO, LOG_TAG, "Success");
    +    ret = bt_gatt_service_get_characteristic(svc, chr_uuid, &control_point);
    +    if (ret == BT_ERROR_NONE)
    +       dlog_print(DLOG_INFO, LOG_TAG, "Success");
     
    -ret = bt_gatt_client_write_value(control_point, __write_completed_cb, NULL);
    -if (ret == BT_ERROR_NONE)
    -   dlog_print(DLOG_INFO, LOG_TAG, "Success");
    +    ret = bt_gatt_characteristic_set_write_type(control_point,
    +                                                BT_GATT_WRITE_TYPE_WRITE);
    +    if (ret == BT_ERROR_NONE)
    +       dlog_print(DLOG_INFO, LOG_TAG, "Success");
     
    -return ret;
    +    ret = bt_gatt_set_value(control_point, value, len);
    +    if (ret == BT_ERROR_NONE)
    +       dlog_print(DLOG_INFO, LOG_TAG, "Success");
     
    -if (ret == BT_ERROR_NONE)
    -   dlog_print(DLOG_INFO, LOG_TAG, "Success");
    +    ret = bt_gatt_client_write_value(control_point, __write_completed_cb, NULL);
    +    if (ret == BT_ERROR_NONE)
    +       dlog_print(DLOG_INFO, LOG_TAG, "Success");
    +
    +    return ret;
    +}
     
  • @@ -1840,7 +1713,7 @@ main()

    To handle the scan result:

    -int ret;
    +int ret, i;
     
     void 
     __bt_adapter_le_scan_result_cb(int result,
    @@ -1851,7 +1724,7 @@ __bt_adapter_le_scan_result_cb(int result,
     
        if (info == NULL) 
        {
    -      dlog_print T(DLOG_INFO, LOG_TAG, "No discovery_info!");
    +      dlog_print (DLOG_INFO, LOG_TAG, "No discovery_info!");
     
           return;
        }
    @@ -1886,26 +1759,26 @@ __bt_adapter_le_scan_result_cb(int result,
              int i;
              for (i = 0; i < count; i++) 
              {
    -            DLOG_PRINT(DLOG_INFO, LOG_TAG, "UUID[%d] = %s", i + 1, uuids[i]);
    +            dlog_print(DLOG_INFO, LOG_TAG, "UUID[%d] = %s", i + 1, uuids[i]);
                 g_free(uuids[i]);
              }
              g_free(uuids);
           }
           if (bt_adapter_le_get_scan_result_device_name(info, pkt_type, &device_name) == BT_ERROR_NONE) 
           {
    -         DLOG_PRINT(DLOG_INFO, LOG_TAG, "Device name = %s", device_name);
    +         dlog_print(DLOG_INFO, LOG_TAG, "Device name = %s", device_name);
              g_free(device_name);
           }
           if (bt_adapter_le_get_scan_result_tx_power_level(info, pkt_type, &tx_power_level) == BT_ERROR_NONE) 
           {
    -         DLOG_PRINT(DLOG_INFO, LOG_TAG, "TX Power level = %d", tx_power_level);
    +         dlog_print(DLOG_INFO, LOG_TAG, "TX Power level = %d", tx_power_level);
           }
           if (bt_adapter_le_get_scan_result_service_solicitation_uuids(info, pkt_type, &uuids, &count) == BT_ERROR_NONE) 
           {
              int i;
              for (i = 0; i < count; i++) 
              {
    -            DLOG_PRINT(DLOG_INFO, LOG_TAG, "Solicitation UUID[%d] = %s", i + 1, uuids[i]);
    +            dlog_print(DLOG_INFO, LOG_TAG, "Solicitation UUID[%d] = %s", i + 1, uuids[i]);
                 g_free(uuids[i]);
              }
              g_free(uuids);
    @@ -1914,18 +1787,18 @@ __bt_adapter_le_scan_result_cb(int result,
           {
              int i;
              for (i = 0; i < count; i++)
    -         DLOG_PRINT(DLOG_INFO, LOG_TAG, "Service Data[%d] = [0x%2.2X%2.2X:0x%.2X...]", i + 1, 
    +         dlog_print(DLOG_INFO, LOG_TAG, "Service Data[%d] = [0x%2.2X%2.2X:0x%.2X...]", i + 1, 
                         data_list[i].service_uuid[0], data_list[i].service_uuid[1], data_list[i].service_data[0]);
              bt_adapter_le_free_service_data_list(data_list, count);
           }
           if (bt_adapter_le_get_scan_result_appearance(info, pkt_type, &appearance) == BT_ERROR_NONE) 
           {
    -         DLOG_PRINT(DLOG_INFO, LOG_TAG, "Appearance = %d", appearance);
    +         dlog_print(DLOG_INFO, LOG_TAG, "Appearance = %d", appearance);
           }
           if (bt_adapter_le_get_scan_result_manufacturer_data(info, pkt_type, &manufacturer_id, 
                                                               &manufacturer_data, &manufacturer_data_len) == BT_ERROR_NONE) 
           {
    -         DLOG_PRINT(DLOG_INFO, LOG_TAG, "Manufacturer data[ID:%.4X, 0x%.2X%.2X...(len:%d)]", 
    +         dlog_print(DLOG_INFO, LOG_TAG, "Manufacturer data[ID:%.4X, 0x%.2X%.2X...(len:%d)]", 
                         manufacturer_id, manufacturer_data[0], manufacturer_data[1], manufacturer_data_len);
              g_free(manufacturer_data);
           }
    @@ -1972,12 +1845,16 @@ main()
     

    To start the BLE discovery operation:

    -int 
    -main()
    +static void __bt_adapter_le_device_discovery_state_changed_cb(int result, bt_adapter_le_device_discovery_state_e discovery_state, bt_adapter_le_device_discovery_info_s *discovery_info, void *user_data);
    +{
    +
    +}
    +
    +int main()
     {
        int ret = BT_ERROR_NONE;
     
    -   ret = bt_adapter_le_set_device_discovery_state_changed_cb(bt_adapter_le_device_discovery_state_changed_cb, NULL);
    +   ret = bt_adapter_le_set_device_discovery_state_changed_cb(__bt_adapter_le_device_discovery_state_changed_cb, NULL);
     
        ret = bt_adapter_le_start_device_discovery();
     
    @@ -1986,7 +1863,7 @@ main()
           dlog_print(DLOG_ERROR, LOG_TAG, "[bt_adapter_le_start_device_discovery] Failed.");
        }
        // To unset the LE device discovery state change callback
    -   ret = bt_adapter_le_unset_device_discovery_state_changed_cb
    +   ret = bt_adapter_le_unset_device_discovery_state_changed_cb()
     
        return;
     }
    @@ -2041,12 +1918,6 @@ le_add_advertising_data()
              dlog_print(DLOG_INFO, LOG_TAG, "clear scan response data [0x%04x]", ret);
        }
     
    -   if (g_test_param.param_count > 0) 
    -   {
    -      adv_data_type = atoi(g_test_param.params[0]);
    -      __bt_free_test_param(&g_test_param);
    -   }
    -
        switch (adv_data_type) 
        {
           case 0: // Service UUID
    @@ -2124,7 +1995,7 @@ le_add_advertising_data()
              manufacture = manufacture_3;
              break;
     
    -      case 4: // ANCS
    +      case 4: // ANCS {
              ret = bt_adapter_le_add_advertising_service_solicitation_uuid(advertiser, BT_ADAPTER_LE_PACKET_ADVERTISING, 
                                                                            time_svc_uuid_16);
              if (ret != BT_ERROR_NONE)
    @@ -2138,9 +2009,8 @@ le_add_advertising_data()
              ret = bt_adapter_le_set_advertising_device_name(advertiser, BT_ADAPTER_LE_PACKET_SCAN_RESPONSE, true);
              if (ret != BT_ERROR_NONE)
                 dlog_print (DLOG_INFO, LOG_TAG, "set device name [0x%04x]", ret);
    -
    -      return 0;
    -
    +       return 0;
    +      }
           default:
              dlog_print(DLOG_INFO, LOG_TAG, "No adv data");
              break;
    @@ -2157,7 +2027,7 @@ le_add_advertising_data()
           dlog_print(DLOG_INFO, LOG_TAG, "set device name [0x%04x]", ret);
     
        ret = bt_adapter_le_add_advertising_manufacturer_data(advertiser, BT_ADAPTER_LE_PACKET_SCAN_RESPONSE, 
    -                                                         manufacturer_id, ;manufacture, sizeof(manufacture_0));
    +                                                         manufacturer_id, manufacture, sizeof(manufacture_0));
        if (ret != BT_ERROR_NONE)
           dlog_print(DLOG_INFO, LOG_TAG, "add manufacturer data [0x%04x]", ret);
     }
    @@ -2199,12 +2069,6 @@ if (advertiser == NULL)
        advertiser_list[advertiser_index] = advertiser;
     }
     
    -if (g_test_param.param_count > 0) 
    -{
    -   type = atoi(g_test_param.params[0]);
    -   __bt_free_test_param(&g_test_param);
    -}
    -
     ret = bt_adapter_le_set_advertising_connectable(advertiser, type);
     if (ret != BT_ERROR_NONE)
        dlog_print(DLOG_INFO, LOG_TAG, "add scan response data [0x%04x]", ret);
    @@ -2233,12 +2097,6 @@ if (advertiser == NULL)
        advertiser_list[advertiser_index] = advertiser;
     }
     
    -if (g_test_param.param_count > 0) 
    -{
    -   mode = atoi(g_test_param.params[0]);
    -   __bt_free_test_param(&g_test_param);
    -}
    -
     ret = bt_adapter_le_set_advertising_mode(advertiser, mode);
     if (ret != BT_ERROR_NONE)
        dlog_print(DLOG_INFO, LOG_TAG, "add scan response data [0x%04x]", ret);
    @@ -2251,6 +2109,36 @@ if (ret != BT_ERROR_NONE)
     

    To start advertising with the given advertiser and advertising parameters information, use the bt_adapter_le_start_advertising_new() function:

    +static void __bt_adapter_le_advertising_state_changed_cb(int result,
    +                bt_advertiser_h advertiser, bt_adapter_le_advertising_state_e adv_state, void *user_data)
    +{
    +        dlog_print(DLOG_INFO, LOG_TAG, "Result : %d", result);
    +            dlog_print(DLOG_INFO, LOG_TAG, "Advertiser : %p", advertiser);
    +                dlog_print(DLOG_INFO, LOG_TAG, "Advertising %s [%d]", adv_state == BT_ADAPTER_LE_ADVERTISING_STARTED ?
    +                                        "started" : "stopped", adv_state);
    +}
    +
    +static void __bt_adapter_le_advertising_state_changed_cb_2(int result,
    +                bt_advertiser_h advertiser, bt_adapter_le_advertising_state_e adv_state, void *user_data)
    +{
    +        dlog_print(DLOG_INFO, LOG_TAG, "Result : %d", result);
    +            dlog_print(DLOG_INFO, LOG_TAG, "Advertiser : %p", advertiser);
    +                dlog_print(DLOG_INFO, LOG_TAG, "Advertising %s [%d]", adv_state == BT_ADAPTER_LE_ADVERTISING_STARTED ?
    +                                        "started" : "stopped", adv_state);
    +}
    +
    +static void __bt_adapter_le_advertising_state_changed_cb_3(int result,
    +                bt_advertiser_h advertiser, bt_adapter_le_advertising_state_e adv_state, void *user_data)
    +{
    +        dlog_print(DLOG_INFO, LOG_TAG, "Result : %d", result);
    +            dlog_print(DLOG_INFO, LOG_TAG, "Advertiser : %p", advertiser);
    +                dlog_print(DLOG_INFO, LOG_TAG, "Advertising %s [%d]", adv_state == BT_ADAPTER_LE_ADVERTISING_STARTED ?
    +                                        "started" : "stopped", adv_state);
    +}
    +
    +
    + +
     bt_adapter_le_advertising_state_changed_cb cb;
     
     if (advertiser_index == 0) cb = __bt_adapter_le_advertising_state_changed_cb;
    @@ -2318,16 +2206,16 @@ if (ret != BT_ERROR_NONE)
     
     
     
    -  
     
      
    -
    \ No newline at end of file
    +
    -- 
    2.7.4