Skip to content

Commit

Permalink
Added new Gattlib error types
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviermartin committed Apr 3, 2024
1 parent aac4e06 commit 42c97d4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions gattlib-py/gattlib/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
GATTLIB_DEVICE_ERROR = 6
GATTLIB_DEVICE_NOT_CONNECTED = 7
GATTLIB_NO_ADAPTER = 8
GATTLIB_BUSY = 9
GATTLIB_UNEXPECTED = 10

GATTLIB_ERROR_MODULE_MASK = 0xF0000000
GATTLIB_ERROR_DBUS = 0x10000000
Expand All @@ -26,6 +28,12 @@ class GattlibException(Exception):
class NoAdapter(GattlibException):
pass

class Busy(GattlibException):
pass

class Unexpected(GattlibException):
pass

class AdapterNotOpened(GattlibException):
pass

Expand Down Expand Up @@ -84,6 +92,10 @@ def handle_return(ret):
raise NotConnected()
elif ret == GATTLIB_NO_ADAPTER:
raise NoAdapter()
elif ret == GATTLIB_BUSY:
raise Busy()
elif ret == GATTLIB_UNEXPECTED:
raise Unexpected()
elif (ret & GATTLIB_ERROR_MODULE_MASK) == GATTLIB_ERROR_DBUS:
raise DBusError((ret >> 8) & 0xFFF, ret & 0xFFFF)
elif ret == -22: # From '-EINVAL'
Expand Down
1 change: 1 addition & 0 deletions include/gattlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ extern "C" {
#define GATTLIB_DEVICE_NOT_CONNECTED 7
#define GATTLIB_NO_ADAPTER 8
#define GATTLIB_BUSY 9
#define GATTLIB_UNEXPECTED 10
#define GATTLIB_ERROR_MODULE_MASK 0xF0000000
#define GATTLIB_ERROR_DBUS 0x10000000
#define GATTLIB_ERROR_BLUEZ 0x20000000
Expand Down

0 comments on commit 42c97d4

Please sign in to comment.