<pre class="prettyprint">
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");
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;
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;
}
</pre>
</li>
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);
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);
</li>
<li>Read the value of the given attribute handle:
<pre class="prettyprint">
-{
- 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);
+ }
</pre>
<p>After the reading operation is complete, use the <span style="font-family: Courier New,Courier,monospace;">bt_gatt_client_read_complete_cb()</span> callback to handle values:</p>
<pre class="prettyprint">
g_free(uuid);
if (result != BT_ERROR_NONE)
-
return;
- __bt_gatt_client_print_value(gatt_handle);
return;
}
<li>Set a value for the given attribute handle:
<pre class="prettyprint">
-{
- 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;
}
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;
}
}
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;
}
{
dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_client_write_value is failed : %d", ret);
}
- __bt_free_test_param(&g_test_param);
-}
</pre>
<p>After the writing operation is complete, use the <span style="font-family: Courier New,Courier,monospace;">bt_gatt_client_write_complete_cb()</span> callback to finish the task:</p>
<pre class="prettyprint">
<li>Register a callback function to be invoked when the characteristic value changes on the remote device:
<pre class="prettyprint">
-{
- 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;
}
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 (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);
}
-}
</pre>
<p>After registering the callback operation, use the <span style="font-family: Courier New,Courier,monospace;">__bt_gatt_client_value_changed_cb()</span> callback to display the changed value:</p>
<pre class="prettyprint">
<pre class="prettyprint">
{
- 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;
}
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 (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);
}
}
</pre>
<ul>
<li>Get the type of a service, characteristic, or descriptor handle:
<pre class="prettyprint">
-{
int ret = 0;
bt_gatt_h gatt_handle = NULL;
bt_gatt_type_e gatt_type;
{
dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_get_type is failed : %d", ret);
}
-}
</pre></li>
<li>Get the UUID of a service, characteristic, or descriptor handle:
<pre class="prettyprint">
-{
int ret = 0;
bt_gatt_h gatt_handle = NULL;
char *uuid = NULL;
{
dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_get_uuid is failed : %d", ret);
}
-}
</pre></li>
<li>Get the value of a characteristic or descriptor handle:
<pre class="prettyprint">
-{
int ret = 0;
int len = 0;
bt_gatt_h gatt_handle = NULL;
{
dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_get_value is failed : %d", ret);
}
-}
</pre></li>
<li>Get the value of a characteristic or descriptor handle as an <span style="font-family: Courier New,Courier,monospace;">integer</span> type:
<pre class="prettyprint">
-{
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;
{
dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_get_int_value is failed : %d", ret);
}
-}
</pre></li>
<li>Get the value of a characteristic or descriptor handle as a <span style="font-family: Courier New,Courier,monospace;">float</span> type:
<pre class="prettyprint">
-{
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;
{
dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_get_float_value is failed : %d", ret);
}
-}
</pre></li>
<li>Get a service handle with a specific UUID:
<pre class="prettyprint">
-{
- 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);
}
-}
</pre></li>
<li>Get a characteristic handle with a specific UUID:
<pre class="prettyprint">
-{
- 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;
}
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);
}
-}
</pre></li>
<li>Get a descriptor handle with a specific UUID:
<pre class="prettyprint">
-{
- 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;
}
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);
+ }
</pre></li>
<li>Get the properties using the characteristic handle:
<pre class="prettyprint">
-{
bt_gatt_h chr = NULL;
int properties;
{
dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_characteristic_get_properties is failed : %d", ret);
}
-}
</pre></li>
<li>Get the service handle to which the specified characteristic belongs:
<pre class="prettyprint">
-{
bt_gatt_h svc = NULL;
bt_gatt_h chr = NULL;
// chr = Assuming characteristic handle is already available
{
dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_characteristic_get_service is failed : %d", ret);
}
-}
</pre></li>
<li>Get the characteristic handle to which the specified descriptor belongs:
<pre class="prettyprint">
-{
bt_gatt_h chr = NULL;
bt_gatt_h dsc = NULL;
// dsc = Assuming descriptor handle is already available
{
dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_descriptor_get_characteristic is failed : %d", ret);
}
-}
</pre></li>
<li>Get the client handle to which the specified service belongs:
<pre class="prettyprint">
-{
bt_gatt_h svc = NULL;
bt_gatt_client_h client = NULL;
// svc = Assuming service handle is already available
{
dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_service_get_client is failed : %d", ret);
}
-}
</pre></li>
<li>Get the write type of the specified characteristic:
<pre class="prettyprint">
-{
bt_gatt_h chr = NULL;
bt_gatt_write_type_e write_type = NULL;
// svc = Assuming characteristic handle is already available
{
dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_characteristic_get_write_type is failed : %d", ret);
}
-}
</pre></li>
<li>Get an included service's handle with a specific UUID:
<pre class="prettyprint">
-{
bt_gatt_h svc = NULL;
bt_gatt_h included_svc = NULL;
char *uuid = NULL;
{
dlog_print(DLOG_INFO, LOG_TAG, "bt_gatt_service_get_included_service is failed : %d", ret);
}
-}
</pre></li>
</ul>
<pre class="prettyprint">
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()
<pre class="prettyprint">
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()
<li>Set or update the characteristic value (<span style="font-family: Courier New,Courier,monospace">float</span> type value):
<pre class="prettyprint">
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()
<li>Set the characteristic write type:
<pre class="prettyprint">
-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;
+}
</pre></li>
</ol>
<p>To handle the scan result:</p>
<pre class="prettyprint">
-int ret;
+int ret, i;
void
__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;
}
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);
{
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);
}
<p>To start the BLE discovery operation:</p>
<pre class="prettyprint">
-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();
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;
}
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
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)
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;
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);
}
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);
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);
<p>To start advertising with the given advertiser and advertising parameters information, use the <span style="font-family: Courier New,Courier,monospace;">bt_adapter_le_start_advertising_new()</span> function:</p>
<pre class="prettyprint">
+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);
+}
+
+</pre>
+
+<pre class="prettyprint">
bt_adapter_le_advertising_state_changed_cb cb;
if (advertiser_index == 0) cb = __bt_adapter_le_advertising_state_changed_cb;
<p class="footer">Except as noted, this content - excluding the Code Examples - is licensed under <a href="http://creativecommons.org/licenses/by/3.0/legalcode" target="_blank">Creative Commons Attribution 3.0</a> and all of the Code Examples contained herein are licensed under <a href="https://www.tizen.org/bsd-3-clause-license" target="_blank">BSD-3-Clause</a>.<br/>For details, see the <a href="https://www.tizen.org/content-license" target="_blank">Content License</a>.</p>
</div>
- <script type="text/javascript">\r
-var _gaq = _gaq || [];\r
-_gaq.push(['_setAccount', 'UA-25976949-1']);\r
-_gaq.push(['_trackPageview']);\r
-(function() {\r
-var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\r
-ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\r
-var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\r
-})();\r
+ <script type="text/javascript">
+var _gaq = _gaq || [];
+_gaq.push(['_setAccount', 'UA-25976949-1']);
+_gaq.push(['_trackPageview']);
+(function() {
+var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+})();
</script>
</body>
-</html>
\ No newline at end of file
+</html>