From ea1fe15857722b35e5f2e533a052b16b975f8f97 Mon Sep 17 00:00:00 2001 From: Olivier Martin Date: Tue, 5 Mar 2024 22:46:38 +0100 Subject: [PATCH] gattlib: Catch connectio timeout --- dbus/gattlib.c | 7 +++++-- gattlib-py/gattlib/exception.py | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/dbus/gattlib.c b/dbus/gattlib.c index d7fb884..4423682 100644 --- a/dbus/gattlib.c +++ b/dbus/gattlib.c @@ -228,11 +228,14 @@ int gattlib_connect(void *adapter, const char *dst, // pairing information about the targetted device. GATTLIB_LOG(GATTLIB_ERROR, "Device '%s' cannot be found (%d, %d)", dst, error->domain, error->code); ret = GATTLIB_NOT_FOUND; - } else { + } else if ((error->domain == 238) && (error->code == 60952)) { + GATTLIB_LOG(GATTLIB_ERROR, "Device '%s': %s", dst, error->message); + ret = GATTLIB_ERROR_TIMEOUT; + } else { GATTLIB_LOG(GATTLIB_ERROR, "Device connected error (device:%s): %s", conn_context->device_object_path, error->message); - ret = GATTLIB_ERROR_DBUS_WITH_ERROR(error);; + ret = GATTLIB_ERROR_DBUS_WITH_ERROR(error); } g_error_free(error); diff --git a/gattlib-py/gattlib/exception.py b/gattlib-py/gattlib/exception.py index 5777199..c3c29c6 100644 --- a/gattlib-py/gattlib/exception.py +++ b/gattlib-py/gattlib/exception.py @@ -60,6 +60,8 @@ class DBusError(GattlibException): def __str__(self) -> str: if self.domain == 238 and self.code == 60964: return f"DBus Error: le-connection-abort-by-local" + elif self.domain == 238 and self.code == 60952: + return f"DBus Error: Timeout was reached" elif self.domain == 238 and self.code == 60964: return f"DBus Error: Timeout was reached" else: