mirror of https://github.com/labapart/gattlib
parent
24ab0ea95f
commit
36e0cb4934
|
@ -192,6 +192,8 @@ int gattlib_connect(void *adapter, const char *dst,
|
||||||
connection->on_connection.callback.connection_handler = connect_cb;
|
connection->on_connection.callback.connection_handler = connect_cb;
|
||||||
connection->on_connection.user_data = user_data;
|
connection->on_connection.user_data = user_data;
|
||||||
|
|
||||||
|
GATTLIB_LOG(GATTLIB_DEBUG, "Connect bluetooth device %s", dst);
|
||||||
|
|
||||||
OrgBluezDevice1* device = org_bluez_device1_proxy_new_for_bus_sync(
|
OrgBluezDevice1* device = org_bluez_device1_proxy_new_for_bus_sync(
|
||||||
G_BUS_TYPE_SYSTEM,
|
G_BUS_TYPE_SYSTEM,
|
||||||
G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
|
G_DBUS_OBJECT_MANAGER_CLIENT_FLAGS_NONE,
|
||||||
|
@ -289,6 +291,8 @@ int gattlib_disconnect(gatt_connection_t* connection) {
|
||||||
goto EXIT;
|
goto EXIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GATTLIB_LOG(GATTLIB_DEBUG, "Disconnect bluetooth device %s", conn_context->device_object_path);
|
||||||
|
|
||||||
// Remove signal
|
// Remove signal
|
||||||
if (conn_context->on_handle_device_property_change_id != 0) {
|
if (conn_context->on_handle_device_property_change_id != 0) {
|
||||||
g_signal_handler_disconnect(conn_context->device, conn_context->on_handle_device_property_change_id);
|
g_signal_handler_disconnect(conn_context->device, conn_context->on_handle_device_property_change_id);
|
||||||
|
|
|
@ -26,6 +26,8 @@ int gattlib_adapter_open(const char* adapter_name, void** adapter) {
|
||||||
adapter_name = GATTLIB_DEFAULT_ADAPTER;
|
adapter_name = GATTLIB_DEFAULT_ADAPTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GATTLIB_LOG(GATTLIB_DEBUG, "Open bluetooth adapter %s", adapter_name);
|
||||||
|
|
||||||
snprintf(object_path, sizeof(object_path), "/org/bluez/%s", adapter_name);
|
snprintf(object_path, sizeof(object_path), "/org/bluez/%s", adapter_name);
|
||||||
|
|
||||||
adapter_proxy = org_bluez_adapter1_proxy_new_for_bus_sync(
|
adapter_proxy = org_bluez_adapter1_proxy_new_for_bus_sync(
|
||||||
|
@ -329,6 +331,7 @@ static int _gattlib_adapter_scan_enable_with_filter(void *adapter, uuid_t **uuid
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if ((gattlib_adapter == NULL) || (gattlib_adapter->adapter_proxy == NULL)) {
|
if ((gattlib_adapter == NULL) || (gattlib_adapter->adapter_proxy == NULL)) {
|
||||||
|
GATTLIB_LOG(GATTLIB_ERROR, "Could not start BLE scan. No opened bluetooth adapter");
|
||||||
return GATTLIB_NO_ADAPTER;
|
return GATTLIB_NO_ADAPTER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,6 +341,8 @@ static int _gattlib_adapter_scan_enable_with_filter(void *adapter, uuid_t **uuid
|
||||||
char uuid_str[MAX_LEN_UUID_STR + 1];
|
char uuid_str[MAX_LEN_UUID_STR + 1];
|
||||||
GVariantBuilder list_uuid_builder;
|
GVariantBuilder list_uuid_builder;
|
||||||
|
|
||||||
|
GATTLIB_LOG(GATTLIB_DEBUG, "Configure bluetooth scan with UUID");
|
||||||
|
|
||||||
g_variant_builder_init(&list_uuid_builder, G_VARIANT_TYPE ("as"));
|
g_variant_builder_init(&list_uuid_builder, G_VARIANT_TYPE ("as"));
|
||||||
|
|
||||||
for (uuid_t **uuid_ptr = uuid_list; *uuid_ptr != NULL; uuid_ptr++) {
|
for (uuid_t **uuid_ptr = uuid_list; *uuid_ptr != NULL; uuid_ptr++) {
|
||||||
|
@ -349,6 +354,7 @@ static int _gattlib_adapter_scan_enable_with_filter(void *adapter, uuid_t **uuid
|
||||||
}
|
}
|
||||||
|
|
||||||
if (enabled_filters & GATTLIB_DISCOVER_FILTER_USE_RSSI) {
|
if (enabled_filters & GATTLIB_DISCOVER_FILTER_USE_RSSI) {
|
||||||
|
GATTLIB_LOG(GATTLIB_DEBUG, "Configure bluetooth scan with RSSI");
|
||||||
GVariant *rssi_variant = g_variant_new_int16(rssi_threshold);
|
GVariant *rssi_variant = g_variant_new_int16(rssi_threshold);
|
||||||
g_variant_builder_add(&arg_properties_builder, "{sv}", "RSSI", rssi_variant);
|
g_variant_builder_add(&arg_properties_builder, "{sv}", "RSSI", rssi_variant);
|
||||||
}
|
}
|
||||||
|
@ -411,6 +417,7 @@ static int _gattlib_adapter_scan_enable_with_filter(void *adapter, uuid_t **uuid
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GATTLIB_LOG(GATTLIB_DEBUG, "Bluetooth scan started");
|
||||||
return GATTLIB_SUCCESS;
|
return GATTLIB_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -491,6 +498,8 @@ int gattlib_adapter_scan_disable(void* adapter) {
|
||||||
goto EXIT;
|
goto EXIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GATTLIB_LOG(GATTLIB_DEBUG, "Stop bluetooth scan.");
|
||||||
|
|
||||||
org_bluez_adapter1_call_stop_discovery_sync(gattlib_adapter->adapter_proxy, NULL, &error);
|
org_bluez_adapter1_call_stop_discovery_sync(gattlib_adapter->adapter_proxy, NULL, &error);
|
||||||
if (error != NULL) {
|
if (error != NULL) {
|
||||||
if (((error->domain == 238) || (error->domain == 239)) && (error->code == 36)) {
|
if (((error->domain == 238) || (error->domain == 239)) && (error->code == 36)) {
|
||||||
|
@ -539,6 +548,8 @@ int gattlib_adapter_close(void* adapter)
|
||||||
goto EXIT;
|
goto EXIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GATTLIB_LOG(GATTLIB_DEBUG, "Close bluetooth adapter %s", gattlib_adapter->adapter_name);
|
||||||
|
|
||||||
if (gattlib_adapter->ble_scan.is_scanning) {
|
if (gattlib_adapter->ble_scan.is_scanning) {
|
||||||
gattlib_adapter_scan_disable(gattlib_adapter);
|
gattlib_adapter_scan_disable(gattlib_adapter);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue